solstice

Compute collected power and efficiencies of a solar plant
git clone git://git.meso-star.com/solstice.git
Log | Files | Refs | README | LICENSE

commit fa7f0c45ff4dc4b8219b91a4f97b744164aa54c0
parent c32ed3872c6fbd7dae40ebe6dfc7756820efbf3c
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Wed,  9 Nov 2016 17:18:23 +0100

Begin to test the solstice parser

Diffstat:
Mcmake/CMakeLists.txt | 20+++++++++++++-------
Asrc/test_solstice_parser.c | 74++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/test_solstice_utils.h | 34++++++++++++++++++++++++++++++++++
Asrc/yaml/test_ko_0.yaml | 83+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/yaml/test_ok_0.yaml | 31+++++++++++++++++++++++++++++++
5 files changed, 235 insertions(+), 7 deletions(-)

diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt @@ -75,13 +75,19 @@ rcmake_copy_runtime_libraries(solstice) # Tests ################################################################################ if(NOT NO_TEST) - function(new_test _name) - set(_files "") - foreach(_file ${ARGN}) - list(APPEND _files ${SOLSTICE_SOURCE_DIR}/${_file}) - endforeach() - add_executable(${_name} ${SOLSTICE_SOURCE_DIR}/${_name}.c ${_files}) - endfunction() + set(_test_files + solstice_parser.h + solstice_parser.c + test_solstice_parser.c + test_solstice_utils.h) + rcmake_prepend_path(_test_files ${SOLSTICE_SOURCE_DIR}) + add_executable(test_solstice_parser ${_test_files}) + target_link_libraries(test_solstice_parser LibYAML ${MATH_LIB} RSys) + + add_test(test_solstice_parser_ok_0 test_solstice_parser + ${SOLSTICE_SOURCE_DIR}/yaml/test_ok_0.yaml) + add_test(test_solstice_parser_ko_0 test_solstice_parser -e + ${SOLSTICE_SOURCE_DIR}/yaml/test_ko_0.yaml) endif() ################################################################################ diff --git a/src/test_solstice_parser.c b/src/test_solstice_parser.c @@ -0,0 +1,74 @@ +/* Copyright (C) CNRS 2016 + * + * 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 "solstice_parser.h" +#include "test_solstice_utils.h" + +#include <string.h> + +int +main(int argc, char** argv) +{ + struct mem_allocator allocator; + struct solstice_parser* parser; + int ifile = 1; + int i; + res_T load_res = RES_OK; + (void)argc, (void)argv; + + if(argc > 1) { + if(!strcmp(argv[1], "-e")) { + load_res = RES_BAD_ARG; + ifile = 2; + } else if(!strcmp(argv[1], "-h")) { + printf("Usage: %s [OPTIONS] [FILE ... ]\n", argv[0]); + printf( +"Check the parser API and that the submitted FILEs are valid. Use the `-e'\n" +"option to check that the FILEs are invalid.\n\n"); + printf("OPTIONS:\n"); + printf(" -h print this help and exit.\n"); + printf(" -e check that the submitted FILEs has errors.\n"); + return 0; + } + } + + CHECK(mem_init_proxy_allocator(&allocator, &mem_default_allocator), RES_OK); + solstice_parser_create(&allocator, &parser); + + CHECK(solstice_parser_setup(parser, NULL, tmpfile()), RES_OK); + CHECK(solstice_parser_setup(parser, "yop", tmpfile()), RES_OK); + CHECK(solstice_parser_load(parser), RES_BAD_OP); /* Empty stream */ + + FOR_EACH(i, ifile, argc) { + FILE* file = fopen(argv[i], "rb"); + NCHECK(file, NULL); + CHECK(solstice_parser_setup(parser, argv[i], file), RES_OK); + for(;;) { + const res_T res = solstice_parser_load(parser); + if(res == RES_BAD_OP) break; + CHECK(res, load_res); + } + fclose(file); + } + + solstice_parser_ref_get(parser); + solstice_parser_ref_put(parser); + solstice_parser_ref_put(parser); + + check_memory_allocator(&allocator); + mem_shutdown_proxy_allocator(&allocator); + CHECK(mem_allocated_size(), 0); + return 0; +} diff --git a/src/test_solstice_utils.h b/src/test_solstice_utils.h @@ -0,0 +1,34 @@ +/* Copyright (C) CNRS 2016 + * + * 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/>. */ + +#ifndef TEST_SOLSTICE_UTILS_H +#define TEST_SOLSTICE_UTILS_H + +#include <rsys/mem_allocator.h> +#include <stdio.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_SOLSTICE_UTILS_H */ + diff --git a/src/yaml/test_ko_0.yaml b/src/yaml/test_ko_0.yaml @@ -0,0 +1,83 @@ +instance: + object: + material: { matte: { reflectivity: -1 } } + cuboid: { size: [1, 2, 3] } +--- +- instance: + object: + material: { matte: { reflectivity: -1 } } + cuboid: { size: [1, 2, 3] } +--- +- instance: + object: + cuboid: { size: [1, 2, 3] } +--- +- instance: + object: + material: { matte: { reflectivity: 1 } } +--- +- instance: + object: + material: { matte: { reflectivity: 1 } } + cuboid: { size: [1, 2, 3] } + sphere: { radius: 1 } +--- +- instance: + object: + transform: + material: { matte: { reflectivity: 1 } } + cuboid: { size: [1, 2, 3] } +--- +- instance: + object: + material: { matte: } + cuboid: { size: [1, 2, 3] } +--- +- instance: + object: + material: + cuboid: { size: [1, 2, 3] } +--- +- instance: + object: + material: { matte: { reflectivity: 1 } } + cuboid: { size: { x: 0, y: 1, z: 2} } +--- +- instance: + object: + material: { matte: { reflectivity: 1 } } + cuboid: { size: } +--- +- instance: + object: + material: { matte: { reflectivity: 1 } } + cuboid: +--- +- instance: + object: + material: { matte: { reflectivity: 1 } } + cuboid: { size: [ 0, 1 ] } +--- +- instance: + object: + material: { matte: { reflectivity: 1 } } + cuboid: { size: [ 0, 1, 3, 4 ] } +--- +- instance: + object: + material: { matte: { reflectivity: 1 } } + cuboid: { size: [ 0, 1, 3 ] } + object: + material: { matte: { reflectivity: 1 } } + cuboid: { size: [ 0, 1, 3 ] } +--- +- instance: + transform: { translation: [ 1, 2, 0 ] } + transform: { translation: [ 3, 4, 4 ] } + object: + material: { matte: { reflectivity: 1 } } + cuboid: { size: [1, 2, 3] } + +--- +- instance: + transform: { translation: [ 3, 4, 4 ] } diff --git a/src/yaml/test_ok_0.yaml b/src/yaml/test_ok_0.yaml @@ -0,0 +1,31 @@ +- instance: + object: + transform: + rotation: [ 0, 1, 2 ] + translation: [ -4, 5.2, -6.5 ] + material: { matte: { reflectivity: 1 } } + cuboid: { size: [1, 2, 3] } + +--- +- instance: + transform: { translation: [ 1, 2, 0 ] } + object: + transform: + rotation: [ 0, 1, 2 ] + material: { matte: { reflectivity: 1 } } + cuboid: { size: [1, 2, 3] } + +--- +- instance: + object: + material: { matte: { reflectivity: 1 } } + cuboid: { size: [1, 2, 3] } + +--- +- material: &lambertian + matte: { reflectivity: 1 } + +- instance: + object: + material: *lambertian + cuboid: { size: [1, 2, 3] }