commit 4a01818cc2ae2f98684d03211f7ff2fcaa140f38
parent eacc4ca0fa0af0d658218960a65cc5a9ca5f88d2
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date: Tue, 13 Feb 2018 14:59:05 +0100
Add new test.
Diffstat:
2 files changed, 118 insertions(+), 0 deletions(-)
diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt
@@ -112,6 +112,7 @@ if(NOT NO_TEST)
new_test(test_senc_cube_behind_cube)
new_test(test_senc_cube_in_cube)
+ new_test(test_senc_cube_on_cube)
new_test(test_senc_descriptor)
new_test(test_senc_device)
new_test(test_senc_enclosure)
diff --git a/src/test_senc_cube_on_cube.c b/src/test_senc_cube_on_cube.c
@@ -0,0 +1,117 @@
+/* Copyright (C) |Meso|Star> 2016-2018 (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 "senc.h"
+#include "test_senc_utils.h"
+
+#include <rsys/double3.h>
+
+/*
+ Z
+ ^
+4 | +-----------------------+
+ | | |
+3 | | +-----+ 3
+ | m2 | m1 | m0 2 |
+ | | | | |
+2 | | +-----+ |
+ | | | m0 1 |
+ | | | | |
+1 | | +-----+ |
+ | | |
+0 - +-----------------------+
+
+ |--------------------------> X / Y
+ 0 1 2 3 4
+*/
+int
+main(int argc, char** argv)
+{
+ struct mem_allocator allocator;
+ struct senc_descriptor* desc = NULL;
+ struct senc_device* dev = NULL;
+ struct senc_scene* scn = NULL;
+ struct context ctx;
+ unsigned count;
+ (void)argc, (void)argv;
+
+ CHK(mem_init_proxy_allocator(&allocator, &mem_default_allocator) == RES_OK);
+ CHK(senc_device_create
+ (NULL, &allocator, SENC_NTHREADS_DEFAULT, 1, &dev) == RES_OK);
+
+ /* Create the scene */
+ CHK(senc_scene_create(dev, 3, &scn) == RES_OK);
+
+ ctx.positions = box_vertices;
+ ctx.indices = box_indices;
+ ctx.scale = 1;
+ ctx.reverse_vrtx = 0;
+ ctx.reverse_med = 0;
+ d3(ctx.offset, 1, 1, 2);
+ /* Small cube #1 exterior is medium 1,
+ * except for the top face where it is 0 */
+ ctx.front_mediums = medium1_front0;
+ /* Smallest cube interior is medium 0 */
+ ctx.back_mediums = medium0;
+
+ /* Add cube #1 */
+ CHK(senc_scene_add_geometry(scn, box_ntriangles, get_indices, get_mediums,
+ box_nvertices, get_position, &ctx) == RES_OK);
+
+ d3(ctx.offset, 1, 1, 1);
+ ctx.scale = 1;
+ /* Small cube #2 exterior is medium 1,
+ * except for the bottom face where it is 0 */
+ ctx.front_mediums = medium1_back0;
+ /* Smallest cube interior is medium 0 */
+ ctx.back_mediums = medium0;
+
+ /* Add cube #2 (has a duplicate face with cube #1) */
+ CHK(senc_scene_add_geometry(scn, box_ntriangles, get_indices, get_mediums,
+ box_nvertices, get_position, &ctx) == RES_OK);
+
+ d3(ctx.offset, 0, 0, 0);
+ ctx.scale = 4;
+ ctx.reverse_vrtx = 1;
+ ctx.reverse_med = 1;
+ /* Big cube #3 exterior is medium 2 */
+ ctx.front_mediums = medium2;
+ /* Big cube #3 interior is medium 1 */
+ ctx.back_mediums = medium1;
+
+ /* Add cube #3 */
+ CHK(senc_scene_add_geometry(scn, box_ntriangles, get_indices, get_mediums,
+ box_nvertices, get_position, &ctx) == RES_OK);
+
+ CHK(senc_scene_analyze(scn, &desc) == RES_OK);
+
+ CHK(senc_descriptor_get_enclosure_count(desc, &count) == RES_OK);
+ CHK(count == 4);
+
+ CHK(senc_descriptor_get_global_vertices_count(desc, &count) == RES_OK);
+ CHK(count == 20);
+
+ CHK(senc_descriptor_get_global_triangle_count(desc, &count) == RES_OK);
+ CHK(count == 34);
+
+ CHK(senc_scene_ref_put(scn) == RES_OK);
+ CHK(senc_device_ref_put(dev) == RES_OK);
+ if(desc) CHK(senc_descriptor_ref_put(desc) == RES_OK);
+
+ check_memory_allocator(&allocator);
+ mem_shutdown_proxy_allocator(&allocator);
+ CHK(mem_allocated_size() == 0);
+ return 0;
+}