commit 77d3e43d661487f4e017ca1ecb4220ac2c2433e1
parent c7fc6864d35b1b8c7995696277b58d46645d1e06
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Thu, 1 Jul 2021 13:30:10 +0200
Test the creation of a pinhole camera
Diffstat:
2 files changed, 98 insertions(+), 0 deletions(-)
diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt
@@ -79,6 +79,8 @@ if(NOT NO_TEST)
build_test(${_name})
add_test(${_name}_${_palette} ${_name})
endfunction()
+
+ new_test(test_scam_pinhole)
endif()
################################################################################
diff --git a/src/test_scam_pinhole.c b/src/test_scam_pinhole.c
@@ -0,0 +1,96 @@
+/* Copyright (C) 2021 |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/>. */
+
+#define _POSIX_C_SOURCE 200112L /* nextafter */
+
+#include "scam.h"
+
+#include <rsys/double3.h>
+#include <rsys/logger.h>
+#include <rsys/mem_allocator.h>
+
+#include <math.h>
+
+static void
+log_stream(const char* msg, void* ctx)
+{
+ ASSERT(msg);
+ (void)msg, (void)ctx;
+ printf("%s", msg);
+}
+
+int
+main(int argc, char** argv)
+{
+ struct logger logger;
+ struct scam_pinhole_args args = SCAM_PINHOLE_ARGS_DEFAULT;
+ struct scam* cam = NULL;
+ enum scam_type type = SCAM_NONE;
+ (void)argc, (void)argv;
+
+ CHK(scam_create_pinhole(NULL, NULL, 0, NULL, &cam) == RES_BAD_ARG);
+ CHK(scam_create_pinhole(NULL, NULL, 0, &args, NULL) == RES_BAD_ARG);
+ CHK(scam_create_pinhole(NULL, NULL, 0, &args, &cam) == RES_OK);
+
+ CHK(scam_get_type(NULL, &type) == RES_BAD_ARG);
+ CHK(scam_get_type(cam, NULL) == RES_BAD_ARG);
+ CHK(scam_get_type(cam, &type) == RES_OK);
+ CHK(type == SCAM_PINHOLE);
+
+ CHK(scam_ref_get(NULL) == RES_BAD_ARG);
+ CHK(scam_ref_get(cam) == RES_OK);
+ CHK(scam_ref_put(NULL) == RES_BAD_ARG);
+ CHK(scam_ref_put(cam) == RES_OK);
+ CHK(scam_ref_put(cam) == RES_OK);
+
+ CHK(logger_init(&mem_default_allocator, &logger) == RES_OK);
+ logger_set_stream(&logger, LOG_OUTPUT, log_stream, NULL);
+ logger_set_stream(&logger, LOG_ERROR, log_stream, NULL);
+ logger_set_stream(&logger, LOG_WARNING, log_stream, NULL);
+
+ CHK(scam_create_pinhole(&logger, NULL, 0, &args, &cam) == RES_OK);
+ CHK(scam_ref_put(cam) == RES_OK);
+
+ CHK(scam_create_pinhole(NULL, &mem_default_allocator, 0, &args, &cam) == RES_OK);
+ CHK(scam_ref_put(cam) == RES_OK);
+
+ d3_set(args.target, args.position);
+ CHK(scam_create_pinhole(NULL, NULL, 1, &args, &cam) == RES_BAD_ARG);
+
+ d3(args.position, 0, 0, 0);
+ d3(args.target, 0, 1, 0);
+ d3(args.up, 0, 1, 0);
+ CHK(scam_create_pinhole(NULL, NULL, 1, &args, &cam) == RES_BAD_ARG);
+
+ args = SCAM_PINHOLE_ARGS_DEFAULT;
+ args.aspect_ratio = 0;
+ CHK(scam_create_pinhole(NULL, NULL, 1, &args, &cam) == RES_BAD_ARG);
+
+ args = SCAM_PINHOLE_ARGS_DEFAULT;
+ args.field_of_view = 0;
+ CHK(scam_create_pinhole(NULL, NULL, 1, &args, &cam) == RES_BAD_ARG);
+ args.field_of_view = PI;
+ CHK(scam_create_pinhole(NULL, NULL, 1, &args, &cam) == RES_BAD_ARG);
+ args.field_of_view = nextafter(0, PI);
+ CHK(scam_create_pinhole(NULL, NULL, 1, &args, &cam) == RES_OK);
+ CHK(scam_ref_put(cam) == RES_OK);
+ args.field_of_view = nextafter(PI, 0);
+ CHK(scam_create_pinhole(NULL, NULL, 1, &args, &cam) == RES_OK);
+ CHK(scam_ref_put(cam) == RES_OK);
+
+ logger_release(&logger);
+ CHK(mem_allocated_size() == 0);
+ return 0;
+}