commit 20b90a457c28bc2d3fd7958ecc824e70d074552f
parent 99218331988e128925b764063bd396861145b9a7
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Wed, 7 Sep 2016 15:29:12 +0200
Test the ssf_specular_reflection API
Diffstat:
2 files changed, 97 insertions(+), 0 deletions(-)
diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt
@@ -85,6 +85,7 @@ if(NOT NO_TEST)
endfunction()
new_test(test_ssf_bsdf)
+ new_test(test_ssf_specular_reflection)
endif()
################################################################################
diff --git a/src/test_ssf_specular_reflection.c b/src/test_ssf_specular_reflection.c
@@ -0,0 +1,96 @@
+/* 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* brdf;
+ 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_specular_reflection_create(NULL, NULL), RES_BAD_ARG);
+ CHECK(ssf_specular_reflection_create(&allocator, NULL), RES_BAD_ARG);
+ CHECK(ssf_specular_reflection_create(NULL, &brdf), RES_OK);
+
+ CHECK(ssf_bxdf_ref_get(NULL), RES_BAD_ARG);
+ CHECK(ssf_bxdf_ref_get(brdf), RES_OK);
+ CHECK(ssf_bxdf_ref_put(NULL), RES_BAD_ARG);
+ CHECK(ssf_bxdf_ref_put(brdf), RES_OK);
+ CHECK(ssf_bxdf_ref_put(brdf), RES_OK);
+
+ CHECK(ssf_specular_reflection_create(&allocator, &brdf), RES_OK);
+
+ CHECK(ssf_specular_reflection_setup(NULL, -1.0), RES_BAD_ARG);
+ CHECK(ssf_specular_reflection_setup(brdf, -1.0), RES_BAD_ARG);
+ CHECK(ssf_specular_reflection_setup(NULL, 1.0), RES_BAD_ARG);
+ CHECK(ssf_specular_reflection_setup(brdf, 1.0), RES_OK);
+ CHECK(ssf_specular_reflection_setup(brdf, 0.0), RES_OK);
+
+ CHECK(ssf_bsdf_create(&allocator, &bsdf), RES_OK);
+ CHECK(ssf_bsdf_add(bsdf, brdf), RES_OK);
+
+ d3(N, 0.0, 1.0, 0.0);
+
+ d3_normalize(w, d3(w, -1.0, -1.0, 0.0));
+ CHECK(ssf_bsdf_sample(bsdf, 0, 0, w, N, dir, &rad), RES_OK);
+ CHECK(rad, 0.0);
+
+ d3_normalize(w, d3(w, -1.0, -1.0, 0.0));
+ CHECK(ssf_specular_reflection_setup(brdf, 1.23), RES_OK);
+ CHECK(ssf_bsdf_sample(bsdf, 0, 0, w, N, dir, &rad), RES_OK);
+ CHECK(rad, 1.23);
+ CHECK(d3_eq_eps(d3(w, w[0], -w[1], 0.0), dir, 1.e-6), 1);
+
+ d3(w, 0.0, -1.0, 0.0);
+ CHECK(ssf_bsdf_sample(bsdf, 0, 0, w, N, dir, &rad), RES_OK);
+ CHECK(rad, 1.23);
+ CHECK(d3_eq_eps(d3(w, 0.0, 1.0, 0.0), dir, 1.e-6), 1);
+
+ d3_normalize(w, d3(w, -1.0, 1.0, 0.0));
+ CHECK(ssf_bsdf_sample(bsdf, 0, 0, w, N, dir, &rad), RES_OK);
+ CHECK(rad, 1.23);
+ CHECK(d3_eq_eps(d3(w, w[0], -w[1], 0.0), dir, 1.e-6), 1);
+
+ d3(w, 0.0, 1.0, 0.0);
+ CHECK(ssf_bsdf_sample(bsdf, 0, 0, w, N, dir, &rad), RES_OK);
+ CHECK(rad, 1.23);
+ CHECK(d3_eq_eps(d3(w, 0.0, -1.0, 0.0), dir, 1.e-6), 1);
+
+ d3(w, -1.0, 0.0, 0.0);
+ CHECK(ssf_bsdf_sample(bsdf, 0, 0, w, N, dir, &rad), RES_OK);
+ CHECK(rad, 1.23);
+ CHECK(d3_eq_eps(w, dir, 1.e-6), 1);
+
+ CHECK(ssf_bxdf_ref_put(brdf), RES_OK);
+ CHECK(ssf_bsdf_ref_put(bsdf), RES_OK);
+
+ check_memory_allocator(&allocator);
+ mem_shutdown_proxy_allocator(&allocator);
+ CHECK(mem_allocated_size(), 0);
+
+ return 0;
+}