commit 59ba02a6f604e099b888b976e4d9520e2d1c8ea2
parent d3f57d495c3a457ae1e6020310556c742f9ef229
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date: Fri, 20 Dec 2019 18:18:48 +0100
Transpose a test from star-enclosures
Diffstat:
2 files changed, 96 insertions(+), 0 deletions(-)
diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt
@@ -119,6 +119,7 @@ if(NOT NO_TEST)
register_test(${_name} ${_name})
endfunction()
+ new_test(test_sg3_cube_behind_cube)
new_test(test_sg3_device)
new_test(test_sg3_geometry)
new_test(test_sg3_geometry_2)
diff --git a/src/test_sg3_cube_behind_cube.c b/src/test_sg3_cube_behind_cube.c
@@ -0,0 +1,94 @@
+/* Copyright (C) 2016-2019 |Meso|Star> (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 "sg3.h"
+#include "test_sg3_utils.h"
+
+#include <rsys/double3.h>
+
+#include <stdio.h>
+
+int
+main(int argc, char** argv)
+{
+ struct mem_allocator allocator;
+ struct sg3_device* dev;
+ struct sg3_geometry* geom;
+ struct context ctx = CONTEXT_NULL__;
+ struct sg3_geometry_add_callbacks callbacks = SG3_ADD_CALLBACKS_NULL__;
+ unsigned count;
+ (void)argc, (void)argv;
+
+ OK(mem_init_proxy_allocator(&allocator, &mem_default_allocator));
+ OK(sg3_device_create(NULL, &allocator, 1, &dev));
+ OK(sg3_geometry_create(dev, &geom));
+ SG3(device_ref_put(dev));
+
+ callbacks.get_indices = get_indices;
+ callbacks.get_properties = get_properties;
+ callbacks.get_position = get_position;
+
+ ctx.positions = box_vertices;
+ ctx.indices = cube_indices;
+ ctx.front_media = medium0;
+ ctx.back_media = medium1;
+ ctx.intface = intface0;
+
+ /* First cube */
+ OK(sg3_geometry_add(geom, ntriangles, nvertices, &callbacks, &ctx));
+
+ /* +Z from the first cube,
+ * big enough to prevent rays from the first cube to miss this one */
+ d3(ctx.offset, -2, -2, 20);
+ ctx.scale = 5;
+
+ /* Second cube */
+ OK(sg3_geometry_add(geom, ntriangles, nvertices, &callbacks, &ctx));
+
+ OK(sg3_geometry_get_merge_conflict_count(geom, &count));
+ CHK(count == 0);
+ OK(sg3_geometry_get_triangle_with_undefined_interface_count(geom, &count));
+ CHK(count == 0);
+ OK(sg3_geometry_get_triangle_with_undefined_side_count(geom, &count));
+ CHK(count == 0);
+ OK(sg3_geometry_dump_as_C_code(geom, stdout, "cube_behind_cube_2",
+ SG3_CDUMP_CONST | SG3_CDUMP_STATIC));
+
+ /* Even further in +Z, even bigger */
+ d3(ctx.offset, -3, -3, 30);
+ ctx.scale = 7;
+ /* Front/back media have been exchanged: external enclosure shows 2 media */
+ ctx.front_media = medium1;
+ ctx.back_media = medium0;
+
+ /* Third cube */
+ OK(sg3_geometry_add(geom, ntriangles, nvertices, &callbacks, &ctx));
+
+ OK(sg3_geometry_get_merge_conflict_count(geom, &count));
+ CHK(count == 0);
+ OK(sg3_geometry_get_triangle_with_undefined_interface_count(geom, &count));
+ CHK(count == 0);
+ OK(sg3_geometry_get_triangle_with_undefined_side_count(geom, &count));
+ CHK(count == 0);
+ OK(sg3_geometry_dump_as_C_code(geom, stdout, "cube_behind_cube_3",
+ SG3_CDUMP_CONST | SG3_CDUMP_STATIC));
+
+ SG3(geometry_ref_put(geom));
+
+ check_memory_allocator(&allocator);
+ mem_shutdown_proxy_allocator(&allocator);
+ CHK(mem_allocated_size() == 0);
+ return 0;
+}
+\ No newline at end of file