star-stl

Load STereo Lithography (StL) file format
git clone git://git.meso-star.fr/star-stl.git
Log | Files | Refs | README | LICENSE

commit 62833bc63bc69a1121d26a5f67f178366470198e
parent ebfa4c3ae1c5ca3acc38debb8609c681429aece0
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Fri, 18 Dec 2015 11:49:41 +0100

Test the sstl creation/deletion API

Diffstat:
Mcmake/CMakeLists.txt | 10+++++-----
Msrc/sstl.c | 2+-
Asrc/test_sstl.c | 87+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/test_sstl_utils.h | 46++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 139 insertions(+), 6 deletions(-)

diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt @@ -69,7 +69,7 @@ set(VERSION_MINOR 3) set(VERSION_PATCH 0) set(VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}) set_target_properties(sstl PROPERTIES - DEFINE_SYMBOL AW_SHARED_BUILD + DEFINE_SYMBOL SSTL_SHARED_BUILD VERSION ${VERSION} SOVERSION ${VERSION_MAJOR}) @@ -85,10 +85,10 @@ rcmake_setup_devel(sstl StarSTL ${VERSION} sstl_version.h) # Define tests ################################################################################ if(NOT NO_TEST) -# add_executable(test_sstl ${SSTL_SOURCE_DIR}/test_sstl.c) -# target_link_libraries(test_sstl sstl) -# add_test(test_sstl test_sstl) -# rcmake_set_test_runtime_dirs(test_sstl _runtime_dirs) + add_executable(test_sstl ${SSTL_SOURCE_DIR}/test_sstl.c) + target_link_libraries(test_sstl sstl) + add_test(test_sstl test_sstl) + rcmake_set_test_runtime_dirs(test_sstl _runtime_dirs) endif(NOT NO_TEST) ################################################################################ diff --git a/src/sstl.c b/src/sstl.c @@ -74,7 +74,7 @@ sstl_create allocator = mem_allocator ? mem_allocator : &mem_default_allocator; logger = log ? log : LOGGER_DEFAULT; - sstl = MEM_CALLOC(mem_allocator, 1, sizeof(struct sstl)); + sstl = MEM_CALLOC(allocator, 1, sizeof(struct sstl)); if(!sstl) { if(verbose) { logger_print(logger, LOG_ERROR, diff --git a/src/test_sstl.c b/src/test_sstl.c @@ -0,0 +1,87 @@ +/* Copyright (C) |Meso|Star> 2015 (contact@meso-star.com) + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. */ + +#include "sstl.h" +#include "test_sstl_utils.h" + +#include <rsys/logger.h> + +static void +log_stream(const char* msg, void* ctx) +{ + ASSERT(msg); + (void)msg, (void)ctx; + printf("%s\n", msg); +} + +int +main(int argc, char** argv) +{ + struct logger logger; + struct mem_allocator allocator; + struct sstl* sstl; + (void)argc, (void)argv; + + CHECK(sstl_create(NULL, NULL, 0, NULL), RES_BAD_ARG); + CHECK(sstl_create(NULL, NULL, 0, &sstl), RES_OK); + + CHECK(sstl_ref_get(NULL), RES_BAD_ARG); + CHECK(sstl_ref_get(sstl), RES_OK); + CHECK(sstl_ref_put(NULL), RES_BAD_ARG); + CHECK(sstl_ref_put(sstl), RES_OK); + CHECK(sstl_ref_put(sstl), RES_OK); + + mem_init_proxy_allocator(&allocator, &mem_default_allocator); + + CHECK(sstl_create(NULL, &allocator, 0, NULL), RES_BAD_ARG); + CHECK(sstl_create(NULL, &allocator, 0, &sstl), RES_OK); + CHECK(sstl_ref_put(sstl), RES_OK); + + CHECK(logger_init(&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); + + CHECK(sstl_create(&logger, NULL, 0, NULL), RES_BAD_ARG); + CHECK(sstl_create(&logger, NULL, 0, &sstl), RES_OK); + CHECK(sstl_ref_put(sstl), RES_OK); + CHECK(sstl_create(&logger, &allocator, 0, NULL), RES_BAD_ARG); + CHECK(sstl_create(&logger, &allocator, 0, &sstl), RES_OK); + CHECK(sstl_ref_put(sstl), RES_OK); + + CHECK(sstl_create(&logger, &allocator, 1, NULL), RES_BAD_ARG); + CHECK(sstl_create(&logger, &allocator, 1, &sstl), RES_OK); + CHECK(sstl_ref_put(sstl), RES_OK); + + logger_release(&logger); + check_memory_allocator(&allocator); + mem_shutdown_proxy_allocator(&allocator); + CHECK(mem_allocated_size(), 0); + return 0; +} + diff --git a/src/test_sstl_utils.h b/src/test_sstl_utils.h @@ -0,0 +1,46 @@ +/* Copyright (C) |Meso|Star> 2015 (contact@meso-star.com) + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. */ + +#ifndef TEST_SSTL_UTILS_H +#define TEST_SSTL_UTILS_H + +#include <rsys/mem_allocator.h> + +static INLINE void +check_memory_allocator(struct mem_allocator* allocator) +{ + if(MEM_ALLOCATED_SIZE(allocator)) { + char dump[512]; + MEM_DUMP(allocator, dump, sizeof(dump)/sizeof(char)); + fprintf(stderr, "%s\n", dump); + FATAL("Memory leaks\n"); + } +} + +#endif /* TEST_SSTL_UTILS_H */ +