commit ae9564fc0aaceb4134e94f71ca950c79abf186b1
parent 2d8d5f24e1a686cab7edb3ae4c2dfea93bb727ab
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date: Thu, 18 Jul 2024 10:26:43 +0200
Add a new test
This test illustrates a typical situation where the topology does not
allow to force normals, and an error must be triggerred.
Diffstat:
2 files changed, 104 insertions(+), 0 deletions(-)
diff --git a/Makefile b/Makefile
@@ -128,6 +128,7 @@ lint:
TEST_SRC =\
src/test_api.c\
src/test_export.c\
+ src/test_export2.c\
src/test_lifetime.c\
src/test_partition.c
TEST_OBJ = $(TEST_SRC:.c=.o)
@@ -176,6 +177,7 @@ $(TEST_OBJ): config.mk scad-local.pc
test_api \
test_export \
+test_export2 \
test_lifetime \
test_partition \
: config.mk scad-local.pc $(LIBNAME)
diff --git a/src/test_export2.c b/src/test_export2.c
@@ -0,0 +1,102 @@
+/* Copyright (C) 2022-2024 |Méso|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 "scad.h"
+#include "scad_geometry.h"
+#include "test_common.h"
+
+#include <rsys/rsys.h>
+#include <rsys/math.h>
+#include <rsys/dynamic_array_double.h>
+#include <rsys/mem_allocator.h>
+
+#include <stdlib.h>
+
+/*
+ * +-------------------+
+ * | |
+ * | +-------------+ |
+ * | | | |
+ * | | +-------+ | |
+ * | | | | | |
+ * | | | | | |
+ * | | | | | |
+ * | | +-------+ | |
+ * | | | |
+ * | +-------------+ |
+ * | |
+ * +-------------------+
+ */
+
+int
+main(int argc, char* argv[])
+{
+ res_T res = RES_OK;
+ double p1[3] = {0, 0, 0};
+ double p2[3] = {2, 2, 2};
+ double p3[3] = {4, 4, 4};
+ double d1[3] = {10, 10, 10};
+ double d2[3] = {6, 6, 6};
+ double d3[3] = {2, 2, 2};
+ struct darray_double array;
+ struct scad_geometry* cube1 = NULL;
+ struct scad_geometry* cube2 = NULL;
+ struct scad_geometry* cube3 = NULL;
+ struct mem_allocator allocator;
+
+ (void)argc; (void)argv;
+
+ OK(mem_init_proxy_allocator(&allocator, &mem_default_allocator));
+ darray_double_init(&allocator, &array);
+ OK(scad_initialize(NULL, &allocator, 3));
+
+ OK(scad_add_box("cube1", p1, d1, &cube1));
+ OK(scad_add_box("cube2", p2, d2, &cube2));
+ OK(scad_add_box("cube3", p3, d3, &cube3));
+
+ OK(scad_scene_mesh());
+
+ /* Check that all three cubes can be exported whith forced normals */
+ OK(scad_stl_export(cube1, NULL, Scad_force_normals_outward, 0));
+ OK(scad_stl_export(cube2, NULL, Scad_force_normals_outward, 0));
+ OK(scad_stl_export(cube3, "bin_cube3", Scad_force_normals_outward, 1));
+
+ /* Check that 2 cubes as a single model can be exported whith forced normals */
+ OK(scad_stl_get_data(cube1, &array));
+ OK(scad_stl_get_data(cube2, &array));
+ OK(scad_stl_data_write(&array, "2cubes.stl", Scad_force_normals_outward, 0));
+
+ /* Check that with 3 cubes as a single model, the model cannot be exported
+ * whith forced normals... */
+ OK(scad_stl_get_data(cube3, &array));
+ BAD(scad_stl_data_write(&array, "3cubes.stl", Scad_force_normals_outward, 0));
+ /* ...but can be exported anyway without forcing normals... */
+ OK(scad_stl_data_write(&array, "3cubes.stl", Scad_keep_normals_unchanged, 0));
+ /* ...and can still be exported if some triangles are duplicated */
+ OK(scad_stl_get_data(cube1, &array));
+ OK(scad_stl_data_write(&array, "3cubesd.stl", Scad_keep_normals_unchanged, 0));
+
+ OK(scad_geometry_ref_put(cube1));
+ OK(scad_geometry_ref_put(cube2));
+ OK(scad_geometry_ref_put(cube3));
+ OK(scad_finalize());
+
+ darray_double_release(&array);
+ check_memory_allocator(&allocator);
+ mem_shutdown_proxy_allocator(&allocator);
+ CHK(mem_allocated_size() == 0);
+
+ return (res == RES_OK) ? EXIT_SUCCESS : EXIT_FAILURE;
+}