mrumtl

Describe materials that vary spectrally
git clone git://git.meso-star.fr/mrumtl.git
Log | Files | Refs | README | LICENSE

commit f18e65484f065e94fc3a51debaeb184054927e1d
parent dc9ac231011a87383dbbfabd3858c2f0a7f3964d
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Fri, 28 Feb 2020 16:11:28 +0100

Basic tests of the mrumtl API

Diffstat:
Mcmake/CMakeLists.txt | 2+-
Msrc/mrumtl.c | 2+-
Asrc/test_mrumtl.c | 81+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 83 insertions(+), 2 deletions(-)

diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt @@ -80,7 +80,7 @@ if(NOT NO_TEST) add_test(${_name} ${_name}) endfunction() - # TODO add tests + new_test(test_mrumtl) endif() diff --git a/src/mrumtl.c b/src/mrumtl.c @@ -726,7 +726,7 @@ mrumtl_load(struct mrumtl* mrumtl, const char* filename) FILE* fp = NULL; res_T res = RES_OK; - if(!mrumtl || filename) { + if(!mrumtl || !filename) { res = RES_BAD_ARG; goto error; } diff --git a/src/test_mrumtl.c b/src/test_mrumtl.c @@ -0,0 +1,81 @@ +/* Copyright (C) 2020 |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/>. */ + +#include "mrumtl.h" +#include <rsys/logger.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 mrumtl* mrumtl; + FILE* fp; + (void)argc, (void)argv; + + CHK(fp = fopen("my_mat.mrumtl", "w+")); + + fprintf(fp, "# Comment\n"); + fprintf(fp, "wavelengths 5 # Comment at the end of a line\n"); + fprintf(fp, "0 lambertian 1\n"); + fprintf(fp, "0.1 specular 0.4\n"); + fprintf(fp, "0.2 lambertian 0.2\n"); + fprintf(fp, "3 lambertian 0.314\n"); + fprintf(fp, "4 specular 0.01\n"); + + CHK(mrumtl_create(NULL, NULL, 0, NULL) == RES_BAD_ARG); + CHK(mrumtl_create(NULL, NULL, 0, &mrumtl) == RES_OK); + + CHK(mrumtl_ref_get(NULL) == RES_BAD_ARG); + CHK(mrumtl_ref_get(mrumtl) == RES_OK); + CHK(mrumtl_ref_put(NULL) == RES_BAD_ARG); + CHK(mrumtl_ref_put(mrumtl) == RES_OK); + CHK(mrumtl_ref_put(mrumtl) == RES_OK); + + CHK(mrumtl_create(NULL, &mem_default_allocator, 1, &mrumtl) == RES_OK); + CHK(mrumtl_ref_put(mrumtl) == 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(mrumtl_create(&logger, &mem_default_allocator, 0, &mrumtl) == RES_OK); + CHK(mrumtl_load(NULL, "my_mat.mrumtl") == RES_BAD_ARG); + CHK(mrumtl_load(mrumtl, NULL) == RES_BAD_ARG); + CHK(mrumtl_load(mrumtl, "undefined_file") == RES_IO_ERR); + CHK(mrumtl_load(mrumtl, "my_mat.mrumtl") == RES_OK); + CHK(mrumtl_ref_put(mrumtl) == RES_OK); + + rewind(fp); + CHK(mrumtl_create(NULL, &mem_default_allocator, 1, &mrumtl) == RES_OK); + CHK(mrumtl_load_stream(NULL, fp, NULL) == RES_BAD_ARG); + CHK(mrumtl_load_stream(mrumtl, NULL, NULL) == RES_BAD_ARG); + CHK(mrumtl_load_stream(mrumtl, fp, NULL) == RES_OK); + + CHK(mrumtl_ref_put(mrumtl) == RES_OK); + + fclose(fp); + logger_release(&logger); + CHK(mem_allocated_size() == 0); + return 0; +}