commit 99218331988e128925b764063bd396861145b9a7
parent 3164f1eb3721ef4030f054e04bb68e4ed698e788
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Wed, 7 Sep 2016 15:28:52 +0200
Test the ssf_bsdf API
Diffstat:
3 files changed, 124 insertions(+), 1 deletion(-)
diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt
@@ -84,7 +84,7 @@ if(NOT NO_TEST)
add_test(${_name} ${_name})
endfunction()
- # new_test(test_ssf_XXX)
+ new_test(test_ssf_bsdf)
endif()
################################################################################
diff --git a/src/test_ssf_bsdf.c b/src/test_ssf_bsdf.c
@@ -0,0 +1,89 @@
+/* Copyright (C) |Meso|Star> 2016 (contact@meso-star.com)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include "ssf.h"
+#include "test_ssf_utils.h"
+
+#include <rsys/double3.h>
+
+int
+main(int argc, char** argv)
+{
+ struct mem_allocator allocator;
+ struct ssf_bsdf* bsdf;
+ struct ssf_bxdf* bxdf;
+ double w[3];
+ double N[3];
+ double dir[4];
+ double rad;
+ (void)argc, (void)argv;
+
+ mem_init_proxy_allocator(&allocator, &mem_default_allocator);
+
+ CHECK(ssf_bsdf_create(NULL, NULL), RES_BAD_ARG);
+ CHECK(ssf_bsdf_create(&allocator, NULL), RES_BAD_ARG);
+ CHECK(ssf_bsdf_create(NULL, &bsdf), RES_OK);
+
+ CHECK(ssf_bsdf_ref_get(NULL), RES_BAD_ARG);
+ CHECK(ssf_bsdf_ref_get(bsdf), RES_OK);
+ CHECK(ssf_bsdf_ref_put(NULL), RES_BAD_ARG);
+ CHECK(ssf_bsdf_ref_put(bsdf), RES_OK);
+ CHECK(ssf_bsdf_ref_put(bsdf), RES_OK);
+
+ CHECK(ssf_bsdf_create(&allocator, &bsdf), RES_OK);
+ CHECK(ssf_specular_reflection_create(&allocator, &bxdf), RES_OK);
+ CHECK(ssf_specular_reflection_setup(bxdf, 2.0), RES_OK);
+
+ CHECK(ssf_bsdf_add(NULL, NULL), RES_BAD_ARG);
+ CHECK(ssf_bsdf_add(bsdf, NULL), RES_BAD_ARG);
+ CHECK(ssf_bsdf_add(NULL, bxdf), RES_BAD_ARG);
+ CHECK(ssf_bsdf_add(bsdf, bxdf), RES_OK);
+
+ d3_normalize(w, d3(w, -1, -1, 0));
+ d3(N, 0.0, 1.0, 0.0);
+ CHECK(ssf_bsdf_sample(NULL, 0, 0, w, N, dir, &rad), RES_BAD_ARG);
+ CHECK(ssf_bsdf_sample(bsdf, 0, -1, w, N, dir, &rad), RES_BAD_ARG);
+ CHECK(ssf_bsdf_sample(bsdf, 1, 0, w, N, dir, &rad), RES_BAD_ARG);
+ CHECK(ssf_bsdf_sample(bsdf, 0, 0, NULL, N, dir, &rad), RES_BAD_ARG);
+ CHECK(ssf_bsdf_sample(bsdf, 0, 0, w, NULL, dir, &rad), RES_BAD_ARG);
+ CHECK(ssf_bsdf_sample(bsdf, 0, 0, w, N, NULL, &rad), RES_BAD_ARG);
+ CHECK(ssf_bsdf_sample(bsdf, 0, 0, w, N, dir, NULL), RES_BAD_ARG);
+ CHECK(ssf_bsdf_sample(bsdf, 0, 0, w, N, dir, &rad), RES_OK);
+ CHECK(rad, 2.0);
+ CHECK(ssf_bsdf_sample(bsdf, 0.5, 0.5, w, N, dir, &rad), RES_OK);
+ CHECK(rad, 2.0);
+
+ CHECK(ssf_bsdf_clear(NULL), RES_BAD_ARG);
+ CHECK(ssf_bsdf_clear(bsdf), RES_OK);
+ CHECK(ssf_bsdf_sample(bsdf, 0, 0, w, N, dir, &rad), RES_OK);
+ CHECK(rad, 0.0);
+
+ d3(w, -1, -1, 0);
+ CHECK(ssf_bsdf_sample(bsdf, 0.5, 0.5, w, N, dir, &rad), RES_BAD_ARG);
+ d3_normalize(w, w);
+ d3(N, 0.0, 2.0, 1.0);
+ CHECK(ssf_bsdf_sample(bsdf, 0.5, 0.5, w, N, dir, &rad), RES_BAD_ARG);
+ d3_normalize(N, N);
+ CHECK(ssf_bsdf_sample(bsdf, 0.5, 0.5, w, N, dir, &rad), RES_OK);
+
+ CHECK(ssf_bsdf_ref_put(bsdf), RES_OK);
+ CHECK(ssf_bxdf_ref_put(bxdf), RES_OK);
+
+ check_memory_allocator(&allocator);
+ mem_shutdown_proxy_allocator(&allocator);
+ CHECK(mem_allocated_size(), 0);
+
+ return 0;
+}
diff --git a/src/test_ssf_utils.h b/src/test_ssf_utils.h
@@ -0,0 +1,34 @@
+/* Copyright (C) |Meso|Star> 2016 (contact@meso-star.com)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef TEST_SSF_UTILS_H
+#define TEST_SSF_UTILS_H
+
+#include <rsys/mem_allocator.h>
+#include <stdio.h>
+
+static void
+check_memory_allocator(struct mem_allocator* allocator)
+{
+ if(MEM_ALLOCATED_SIZE(allocator)) {
+ char dump[512];
+ MEM_DUMP(allocator, dump, sizeof(dump)/sizeof(char));
+ fprintf(stderr, "%s\n", dump);
+ FATAL("Memory leaks\n");
+ }
+}
+
+#endif /* TEST_SSF_UTILS_H */
+