commit 7ceb37f296d7c1e4a7500a6c4a0605b0508e9ee4
parent f44e25c4ba4056602880bc100d136290b8aee921
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Wed, 19 Oct 2016 10:46:25 +0200
Test the sgf_scene3d API
Diffstat:
3 files changed, 73 insertions(+), 3 deletions(-)
diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt
@@ -89,6 +89,7 @@ if(NOT NO_TEST)
new_test(test_sgf_cube)
new_test(test_sgf_device)
new_test(test_sgf_estimator)
+ new_test(test_sgf_scene3d)
new_test(test_sgf_shape3d)
new_test(test_sgf_square)
new_test(test_sgf_tetrahedron)
diff --git a/src/sgf_scene.c b/src/sgf_scene.c
@@ -83,6 +83,7 @@ sgf_scene3d_create(struct sgf_device* dev, struct sgf_scene** out_scn)
exit:
if(out_scn) *out_scn = scn;
+ return res;
error:
if(scn) {
SGF(scene_ref_put(scn));
@@ -116,9 +117,6 @@ sgf_scene_attach_shape(struct sgf_scene* scn, struct sgf_shape* shape)
if(!scn || !shape) return RES_BAD_ARG;
- res = s3d_scene_attach_shape(scn->s3d_scn, shape->s3d_shape);
- if(res != RES_OK) return res;
-
S3D(shape_get_id(shape->s3d_shape, &id));
pshape = htable_shape_find(&scn->shapes, &id);
if(pshape) { /* Already attached */
@@ -128,6 +126,9 @@ sgf_scene_attach_shape(struct sgf_scene* scn, struct sgf_shape* shape)
return RES_OK;
}
+ res = s3d_scene_attach_shape(scn->s3d_scn, shape->s3d_shape);
+ if(res != RES_OK) return res;
+
res = htable_shape_set(&scn->shapes, &id, &shape);
if(res != RES_OK) {
S3D(scene_detach_shape(scn->s3d_scn, shape->s3d_shape));
diff --git a/src/test_sgf_scene3d.c b/src/test_sgf_scene3d.c
@@ -0,0 +1,68 @@
+/* Copyright (C) 2015-2016 EDF S.A., France (syrthes-support@edf.fr)
+ *
+ * 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 "sgf.h"
+#include "test_sgf_utils.h"
+
+int
+main(int argc, char** argv)
+{
+ struct mem_allocator allocator;
+ struct sgf_device* sgf;
+ struct sgf_shape* shape;
+ struct sgf_scene* scn;
+ (void)argc, (void)argv;
+
+ mem_init_proxy_allocator(&allocator, &mem_default_allocator);
+
+ CHECK(sgf_device_create(NULL, &allocator, 1, &sgf), RES_OK);
+ CHECK(sgf_shape3d_create(sgf, &shape), RES_OK);
+
+ CHECK(sgf_scene3d_create(NULL, NULL), RES_BAD_ARG);
+ CHECK(sgf_scene3d_create(sgf, NULL), RES_BAD_ARG);
+ CHECK(sgf_scene3d_create(NULL, &scn), RES_BAD_ARG);
+ CHECK(sgf_scene3d_create(sgf, &scn), RES_OK);
+
+ CHECK(sgf_scene_attach_shape(NULL, NULL), RES_BAD_ARG);
+ CHECK(sgf_scene_attach_shape(scn, NULL), RES_BAD_ARG);
+ CHECK(sgf_scene_attach_shape(NULL, shape), RES_BAD_ARG);
+ CHECK(sgf_scene_attach_shape(scn, shape), RES_OK);
+ CHECK(sgf_scene_attach_shape(scn, shape), RES_OK);
+
+ CHECK(sgf_scene_detach_shape(NULL, NULL), RES_BAD_ARG);
+ CHECK(sgf_scene_detach_shape(scn, NULL), RES_BAD_ARG);
+ CHECK(sgf_scene_detach_shape(NULL, shape), RES_BAD_ARG);
+ CHECK(sgf_scene_detach_shape(scn, shape), RES_OK);
+ CHECK(sgf_scene_detach_shape(scn, shape), RES_BAD_ARG);
+
+ CHECK(sgf_scene_attach_shape(scn, shape), RES_OK);
+ CHECK(sgf_scene_clear(NULL), RES_BAD_ARG);
+ CHECK(sgf_scene_clear(scn), RES_OK);
+ CHECK(sgf_scene_detach_shape(scn, shape), RES_BAD_ARG);
+
+ CHECK(sgf_scene_ref_get(NULL), RES_BAD_ARG);
+ CHECK(sgf_scene_ref_get(scn), RES_OK);
+ CHECK(sgf_scene_ref_put(NULL), RES_BAD_ARG);
+ CHECK(sgf_scene_ref_put(scn), RES_OK);
+ CHECK(sgf_scene_ref_put(scn), RES_OK);
+
+ CHECK(sgf_shape_ref_put(shape), RES_OK);
+ CHECK(sgf_device_ref_put(sgf), RES_OK);
+
+ check_memory_allocator(&allocator);
+ mem_shutdown_proxy_allocator(&allocator);
+ CHECK(mem_allocated_size(), 0);
+ return RES_OK;
+}