commit a78d136fc225d0182257e87f0242b1053d7d2e56
parent d72d22d08d0e14594545e2116910a53a9ba182a3
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Thu, 12 Jan 2017 10:08:01 +0100
Add a test that check the receivers fileformat
Diffstat:
3 files changed, 67 insertions(+), 3 deletions(-)
diff --git a/cmake/receivers/CMakeLists.txt b/cmake/receivers/CMakeLists.txt
@@ -40,7 +40,7 @@ if(CMAKE_COMPILER_IS_GNUCC)
endif()
add_library(solreceivers STATIC ${SOLRECEIVERS_FILES_SRC} ${SOLRECEIVERS_FILES_INC})
-target_link_libraries(solreceivers ${MATH_LIB})
+target_link_libraries(solreceivers LibYAML ${MATH_LIB})
################################################################################
# Tests
@@ -50,7 +50,7 @@ if(NOT NO_TEST)
add_executable(${_name}
${SOLRECEIVERS_SOURCE_DIR}/${_name}.c
${SOLRECEIVERS_SOURCE_DIR}/../test_solstice_utils.h)
- target_link_libraries(${_name} LibYAML ${MATH_LIB} RSys solparser)
+ target_link_libraries(${_name} LibYAML ${MATH_LIB} RSys solreceivers)
endfunction()
function(new_test _name)
@@ -58,6 +58,8 @@ if(NOT NO_TEST)
add_test(${_name} ${_name})
endfunction()
+ build_test(test_solreceivers)
+
endif()
diff --git a/src/receivers/solreceivers.c b/src/receivers/solreceivers.c
@@ -44,7 +44,7 @@ log_err
...)
{
va_list vargs_list;
- ASSERT(parser && node && fmt);
+ ASSERT(receivers && node && fmt);
fprintf(stderr, "%s:%lu:%lu: ",
str_cget(&receivers->stream_name),
diff --git a/src/receivers/test_solreceivers.c b/src/receivers/test_solreceivers.c
@@ -0,0 +1,62 @@
+/* Copyright (C) CNRS 2016-2017
+ *
+ * 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 "solreceivers.h"
+#include "test_solstice_utils.h"
+
+int
+main(int argc, char** argv)
+{
+ struct mem_allocator allocator;
+ struct solreceivers* receivers;
+ int ifile = 1;
+ int i;
+ res_T load_res = RES_OK;
+ (void)argc, (void)argv;
+
+ CHECK(mem_init_proxy_allocator(&allocator, &mem_default_allocator), RES_OK);
+ solreceivers_create(&allocator, &receivers);
+
+ CHECK(solreceivers_setup_stream(receivers, NULL, tmpfile()), RES_OK);
+ CHECK(solreceivers_setup_stream(receivers, "yop", tmpfile()), RES_OK);
+ CHECK(solreceivers_load(receivers), RES_BAD_OP); /* Empty stream */
+
+ FOR_EACH(i, ifile, argc) {
+ FILE* file = fopen(argv[i], "rb");
+ int count = 0;
+ NCHECK(file, NULL);
+ CHECK(solreceivers_setup_stream(receivers, argv[i], file), RES_OK);
+ for(;;) {
+ const res_T res = solreceivers_load(receivers);
+ if(count == 0 && load_res == RES_OK) {
+ CHECK(res, RES_OK);
+ } else if(res == RES_BAD_OP) {
+ break;
+ }
+ CHECK(res, load_res);
+ ++count;
+ }
+ fclose(file);
+ }
+ solreceivers_ref_get(receivers);
+ solreceivers_ref_put(receivers);
+ solreceivers_ref_put(receivers);
+
+ check_memory_allocator(&allocator);
+ mem_shutdown_proxy_allocator(&allocator);
+ CHECK(mem_allocated_size(), 0);
+ return 0;
+}
+