star-hitran

Load line-by-line data from the HITRAN database
git clone git://git.meso-star.fr/star-hitran.git
Log | Files | Refs | README | LICENSE

commit 818b197f8e47232d2fd283b6ceafc90dc2c8c14f
parent 93ea6c1b77accf850264b88fcba2140d9b22c9ef
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Fri,  4 Feb 2022 12:16:45 +0100

Test the shitran API

Diffstat:
Mcmake/CMakeLists.txt | 6+++---
Msrc/shitran.c | 6+++---
Asrc/test_shitran.c | 73+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 79 insertions(+), 6 deletions(-)

diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt @@ -74,9 +74,7 @@ rcmake_setup_devel(shitran StarHITRAN ${VERSION} star/shitran_version.h) ################################################################################ if(NOT NO_TEST) function(build_test _name) - add_executable(${_name} - ${SHITRAN_SOURCE_DIR}/${_name}.c - ${SHITRAN_SOURCE_DIR}/test_shitran_utils.h) + add_executable(${_name} ${SHITRAN_SOURCE_DIR}/${_name}.c) target_link_libraries(${_name} shitran RSys ${ARGN}) endfunction() @@ -85,6 +83,8 @@ if(NOT NO_TEST) add_test(${_name} ${_name}) endfunction() + new_test(test_shitran) + endif() ################################################################################ diff --git a/src/shitran.c b/src/shitran.c @@ -48,7 +48,7 @@ shitran_create struct shitran* shitran = NULL; res_T res = RES_OK; - if(out_shitran) { res = RES_BAD_ARG; goto error; } + if(!out_shitran) { res = RES_BAD_ARG; goto error; } res = check_shitran_create_args(args); if(res != RES_OK) goto error; @@ -85,7 +85,7 @@ error: res_T shitran_ref_get(struct shitran* shitran) { - if(shitran) return RES_BAD_ARG; + if(!shitran) return RES_BAD_ARG; ref_get(&shitran->ref); return RES_OK; } @@ -93,7 +93,7 @@ shitran_ref_get(struct shitran* shitran) res_T shitran_ref_put(struct shitran* shitran) { - if(shitran) return RES_BAD_ARG; + if(!shitran) return RES_BAD_ARG; ref_put(&shitran->ref, release_shitran); return RES_OK; } diff --git a/src/test_shitran.c b/src/test_shitran.c @@ -0,0 +1,73 @@ +/* Copyright (C) 2022 CNRS - LMD + * Copyright (C) 2022 |Meso|Star> (contact@meso-star.com) + * Copyright (C) 2022 Université Paul Sabatier - IRIT/Laplace + * + * 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 "shitran.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 mem_allocator allocator; + struct logger logger; + struct shitran* shitran; + struct shitran_create_args args = SHITRAN_CREATE_ARGS_DEFAULT; + (void)argc, (void)argv; + + CHK(shitran_create(NULL, &shitran) == RES_BAD_ARG); + CHK(shitran_create(&args, NULL) == RES_BAD_ARG); + CHK(shitran_create(&args, &shitran) == RES_OK); + + CHK(shitran_ref_get(NULL) == RES_BAD_ARG); + CHK(shitran_ref_get(shitran) == RES_OK); + CHK(shitran_ref_put(NULL) == RES_BAD_ARG); + CHK(shitran_ref_put(shitran) == RES_OK); + CHK(shitran_ref_put(shitran) == RES_OK); + + CHK(mem_init_proxy_allocator(&allocator, &mem_default_allocator) == RES_OK); + args.allocator = &allocator; + args.verbose = 1; + CHK(shitran_create(&args, &shitran) == RES_OK); + CHK(MEM_ALLOCATED_SIZE(&allocator) != 0); + CHK(shitran_ref_put(shitran) == RES_OK); + + CHK(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); + + args.logger = &logger; + CHK(shitran_create(&args, &shitran) == RES_OK); + CHK(shitran_ref_put(shitran) == RES_OK); + args.allocator = NULL; + CHK(shitran_create(&args, &shitran) == RES_OK); + CHK(shitran_ref_put(shitran) == RES_OK); + + logger_release(&logger); + CHK(MEM_ALLOCATED_SIZE(&allocator) == 0); + mem_shutdown_proxy_allocator(&allocator); + CHK(mem_allocated_size() == 0); + return 0; +}