star-phor-input

File format for describing photoreactor configurations
git clone https://www.edstar.cnrs.fr/git/star-phor-input.git
Log | Files | Refs | README | LICENSE

commit c8befaacbbb940e655d5b81ee85a58ed00321fc3
parent 626f7604c074eee33127620c024fa146c3ac8d43
Author: Eduardo Fontana Lazzari <edufonlaz@gmail.com>
Date:   Fri,  7 Mar 2025 18:10:02 +0100

Expand sphin library tests

Diffstat:
M.gitignore | 4+++-
MMakefile | 4++++
Asrc/test_sphin_load_geometry.c | 238+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/test_sphin_load_source.c | 247+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/test_sphin_load_surface.c | 89++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
Msrc/test_sphin_load_volume.c | 40++++++++++++++++++++++++++++++++++------
6 files changed, 614 insertions(+), 8 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -9,5 +9,7 @@ file.txt *.stl tags test_sphin -test_sphin_load_volume +test_sphin_load_geometry +test_sphin_load_source test_sphin_load_surface +test_sphin_load_volume diff --git a/Makefile b/Makefile @@ -121,6 +121,8 @@ clean: clean_test ################################################################################ TEST_SRC =\ src/test_sphin.c\ + src/test_sphin_load_geometry.c\ + src/test_sphin_load_source.c\ src/test_sphin_load_surface.c\ src/test_sphin_load_volume.c TEST_OBJ = $(TEST_SRC:.c=.o) @@ -170,6 +172,8 @@ $(TEST_OBJ): config.mk sphin-local.pc $(CC) $(CFLAGS_TEST) -c $(@:.o=.c) -o $@ test_sphin \ +test_sphin_load_geometry \ +test_sphin_load_source \ test_sphin_load_surface \ test_sphin_load_volume \ : config.mk sphin-local.pc $(LIBNAME) diff --git a/src/test_sphin_load_geometry.c b/src/test_sphin_load_geometry.c @@ -0,0 +1,238 @@ +/* Copyright (C) 2024-2025 Centre National de la Recherche Scientifique + + * Copyright (C) 2024-2025 Clermont Auvergne INP + * Copyright (C) 2024-2025 INSA Lyon + * Copyright (C) 2024-2025 Institut Mines Télécom Albi-Carmaux + * Copyright (C) 2024-2025 Institut National Polytechnique de Toulouse + * Copyright (C) 2024-2025 |Méso|Star> (contact@meso-star.com) + * Copyright (C) 2024-2025 PhotonLyX (info@photonlyx.com) + * Copyright (C) 2024-2025 Université de Lorraine + * Copyright (C) 2024-2025 Université Paul Sabatier + * Copyright (C) 2024-2025 Université Toulouse - Jean Jaurès + * + * 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 "sphin.h" +#include "test_sphin_utils.h" + +#include <rsys/mem_allocator.h> +#include <string.h> + +static void +write_stl_test_files + (void) +{ + FILE* file; + static const char* test0 = + "solid\n" + " facet normal 0.0 -1.0 0.0\n" + " outer loop\n" + " vertex 0.0 0.0 0.0\n" + " vertex 1.0 0.0 0.0\n" + " vertex 0.0 0.0 1.0\n" + " endloop\n" + " endfacet\n" + "endsolid"; + static const char* test1 = + "solid\n" + " facet normal 0.0 0.0 -1.0\n" + " outer loop\n" + " vertex 0.0 0.0 0.0\n" + " vertex 1.0 0.0 0.0\n" + " vertex 0.0 1.0 0.0\n" + " endloop\n" + " endfacet\n" + "endsolid"; + file = fopen("test_0.stl", "w"); + CHK(file != NULL); + fwrite(test0, sizeof(char), strlen(test0), file); + fclose(file); + file = fopen("test_1.stl", "w"); + CHK(file != NULL); + fwrite(test1, sizeof(char), strlen(test1), file); + fclose(file); + file = fopen("test_2.stl", "w"); + CHK(file != NULL); + fprintf(file, "solid cube\n"); + fprintf(file, "facet normal 0.0 0.0 1.0\n"); + fprintf(file, " outer loop\n"); + fprintf(file, " vertex -1 -1 -1\n"); + fprintf(file, " vertex 1 -1 -1\n"); + fprintf(file, " vertex 1 1 -1\n"); + fprintf(file, " endloop\n"); + fprintf(file, "endfacet\n"); + fprintf(file, "facet normal 0.0 0.0 1.0\n"); + fprintf(file, " outer loop\n"); + fprintf(file, " vertex -1 -1 -1\n"); + fprintf(file, " vertex 1 1 -1\n"); + fprintf(file, " vertex -1 1 -1\n"); + fprintf(file, " endloop\n"); + fprintf(file, "endfacet\n"); + fprintf(file, "facet normal 0.0 0.0 1.0\n"); + fprintf(file, " outer loop\n"); + fprintf(file, " vertex -1 -1 1\n"); + fprintf(file, " vertex 1 -1 1\n"); + fprintf(file, " vertex 1 1 1\n"); + fprintf(file, " endloop\n"); + fprintf(file, "endfacet\n"); + fprintf(file, "facet normal 0.0 0.0 1.0\n"); + fprintf(file, " outer loop\n"); + fprintf(file, " vertex -1 -1 1\n"); + fprintf(file, " vertex 1 1 1\n"); + fprintf(file, " vertex -1 1 1\n"); + fprintf(file, " endloop\n"); + fprintf(file, "endfacet\n"); + fprintf(file, "facet normal 0.0 -1.0 0.0\n"); + fprintf(file, " outer loop\n"); + fprintf(file, " vertex -1 -1 -1\n"); + fprintf(file, " vertex 1 -1 -1\n"); + fprintf(file, " vertex 1 -1 1\n"); + fprintf(file, " endloop\n"); + fprintf(file, "endfacet\n"); + fprintf(file, "facet normal 0.0 -1.0 0.0\n"); + fprintf(file, " outer loop\n"); + fprintf(file, " vertex -1 -1 -1\n"); + fprintf(file, " vertex 1 -1 1\n"); + fprintf(file, " vertex -1 -1 1\n"); + fprintf(file, " endloop\n"); + fprintf(file, "endfacet\n"); + fprintf(file, "facet normal 0.0 1.0 0.0\n"); + fprintf(file, " outer loop\n"); + fprintf(file, " vertex 1 1 -1\n"); + fprintf(file, " vertex -1 1 -1\n"); + fprintf(file, " vertex -1 1 1\n"); + fprintf(file, " endloop\n"); + fprintf(file, "endfacet\n"); + fprintf(file, "facet normal 0.0 1.0 0.0\n"); + fprintf(file, " outer loop\n"); + fprintf(file, " vertex 1 1 -1\n"); + fprintf(file, " vertex -1 1 1\n"); + fprintf(file, " vertex 1 1 1\n"); + fprintf(file, " endloop\n"); + fprintf(file, "endfacet\n"); + fprintf(file, "facet normal 1.0 0.0 0.0\n"); + fprintf(file, " outer loop\n"); + fprintf(file, " vertex -1 -1 -1\n"); + fprintf(file, " vertex -1 1 -1\n"); + fprintf(file, " vertex -1 1 1\n"); + fprintf(file, " endloop\n"); + fprintf(file, "endfacet\n"); + fprintf(file, "facet normal 1.0 0.0 0.0\n"); + fprintf(file, " outer loop\n"); + fprintf(file, " vertex -1 -1 -1\n"); + fprintf(file, " vertex -1 1 1\n"); + fprintf(file, " vertex -1 -1 1\n"); + fprintf(file, " endloop\n"); + fprintf(file, "endfacet\n"); + fprintf(file, "facet normal 1.0 0.0 0.0\n"); + fprintf(file, " outer loop\n"); + fprintf(file, " vertex 1 -1 -1\n"); + fprintf(file, " vertex 1 1 -1\n"); + fprintf(file, " vertex 1 1 1\n"); + fprintf(file, " endloop\n"); + fprintf(file, "endfacet\n"); + fprintf(file, "facet normal 1.0 0.0 0.0\n"); + fprintf(file, " outer loop\n"); + fprintf(file, " vertex 1 -1 -1\n"); + fprintf(file, " vertex 1 1 1\n"); + fprintf(file, " vertex 1 -1 1\n"); + fprintf(file, " endloop\n"); + fprintf(file, "endfacet\n"); + fprintf(file, "endsolid cube\n"); + fclose(file); +} + +static void +test_geometry_api + (struct sphin* sphin) +{ + const char* path = "file.txt"; + size_t nsurfaces, ngeometries, igeometry; + struct sphin_config* config = NULL; + struct sphin_surface* surface = NULL; + struct sphin_geometry* geom = NULL; + struct sphin_geometry_descriptor desc = SPHIN_GEOMETRY_DESCRIPTOR_NULL; + + FILE* fp = NULL; + + CHK(fp = fopen(path, "w+")); + fprintf(fp, "\t\t surface : \"surface name\"\n"); + fprintf(fp, "\tgeometry: FRONT test_0.stl\t\n"); + fprintf(fp, "\tgeometry: BACK test_1.stl \t\n"); + fprintf(fp, "\tgeometry: BACK test_2.stl\n"); + fclose(fp); + + CHK(sphin_load(sphin, path, &config) == RES_OK); + CHK(sphin_config_get_surface_count(config, &nsurfaces) == RES_OK); + CHK(nsurfaces == 1); + CHK(sphin_config_get_surface(config, 0, &surface) == RES_OK); + CHK(sphin_surface_get_geometry_count(NULL, &ngeometries) == RES_BAD_ARG); + CHK(sphin_surface_get_geometry_count(surface, &ngeometries) == RES_OK); + CHK(ngeometries == 3); + + igeometry = 0; + CHK(sphin_surface_get_geometry(surface, igeometry, &geom) == RES_OK); + CHK(sphin_geometry_get_desc(geom, &desc) == RES_OK); + CHK(strcmp(desc.filename, "test_0.stl") == 0); + CHK(desc.side == SPHIN_SIDE_FRONT); + CHK(desc.mesh.triangle_count == 1); + CHK(desc.mesh.vertex_count == 3); + + igeometry++; + CHK(sphin_surface_get_geometry(surface, igeometry, &geom) == RES_OK); + CHK(sphin_geometry_get_desc(geom, &desc) == RES_OK); + CHK(desc.side == SPHIN_SIDE_BACK); + CHK(desc.mesh.triangle_count == 1); + CHK(desc.mesh.vertex_count == 3); + CHK(strcmp(desc.filename, "test_1.stl") == 0); + + igeometry++; + CHK(sphin_surface_get_geometry(surface, igeometry, &geom) == RES_OK); + CHK(sphin_geometry_get_desc(geom, &desc) == RES_OK); + CHK(desc.side == SPHIN_SIDE_BACK); + CHK(desc.mesh.triangle_count == 12); + CHK(desc.mesh.vertex_count == 8); + CHK(strcmp(desc.filename, "test_2.stl") == 0); + + CHK(sphin_geometry_ref_get(NULL) == RES_BAD_ARG); + CHK(sphin_geometry_ref_put(NULL) == RES_BAD_ARG); + CHK(sphin_geometry_ref_get(geom) == RES_OK); + CHK(sphin_geometry_ref_put(geom) == RES_OK); + CHK(sphin_config_ref_put(config) == RES_OK); +} + +int +main(int argc, char** argv) +{ + struct mem_allocator allocator; + struct sphin* sphin; + struct sphin_create_args args = SPHIN_CREATE_ARGS_DEFAULT; + + (void)argc; + (void)argv; + args.verbose = 1; + + mem_init_proxy_allocator(&allocator, &mem_default_allocator); + sphin_create(&args, &sphin); + + write_stl_test_files(); + test_geometry_api(sphin); + + CHK(sphin_ref_put(sphin) == RES_OK); + + check_memory_allocator(&allocator); + mem_shutdown_proxy_allocator(&allocator); + CHK(mem_allocated_size() == 0); + return 0; +} diff --git a/src/test_sphin_load_source.c b/src/test_sphin_load_source.c @@ -0,0 +1,247 @@ + +/* Copyright (C) 2024-2025 Centre National de la Recherche Scientifique + + * Copyright (C) 2024-2025 Clermont Auvergne INP + * Copyright (C) 2024-2025 INSA Lyon + * Copyright (C) 2024-2025 Institut Mines Télécom Albi-Carmaux + * Copyright (C) 2024-2025 Institut National Polytechnique de Toulouse + * Copyright (C) 2024-2025 |Méso|Star> (contact@meso-star.com) + * Copyright (C) 2024-2025 PhotonLyX (info@photonlyx.com) + * Copyright (C) 2024-2025 Université de Lorraine + * Copyright (C) 2024-2025 Université Paul Sabatier + * Copyright (C) 2024-2025 Université Toulouse - Jean Jaurès + * + * 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 "sphin.h" +#include "test_sphin_utils.h" + +#include <math.h> +#include <rsys/mem_allocator.h> +#include <string.h> + +static void +write_stl_test_files + (void) +{ + FILE* file; + static const char* test0 = + "solid\n" + " facet normal 0.0 -1.0 0.0\n" + " outer loop\n" + " vertex 0.0 0.0 0.0\n" + " vertex 1.0 0.0 0.0\n" + " vertex 0.0 0.0 1.0\n" + " endloop\n" + " endfacet\n" + "endsolid"; + file = fopen("test_0.stl", "w"); + CHK(file != NULL); + fwrite(test0, sizeof(char), strlen(test0), file); + fclose(file); +} + +static void +test_source_api + (struct sphin* sphin) +{ + const char* path = "file.txt"; + size_t nsurfaces, ngeometries; + struct sphin_config* config = NULL; + struct sphin_surface* surface = NULL; + struct sphin_source* source = NULL; + struct sphin_source_direction_distribution dir_dist = SPHIN_SOURCE_DIRECTION_DISTRIBUTION_NULL; + struct sphin_source_flux_density flux_density = SPHIN_SOURCE_FLUX_DENSITY_NULL; + + FILE* fp = NULL; + + CHK(fp = fopen(path, "w+")); + fprintf(fp, "\t\t surface : \"surface name\"\n"); + fprintf(fp, "\tgeometry: FRONT test_0.stl\t\n"); + fprintf(fp, "\tsource:\t #commentaire\n"); + fprintf(fp, "\tflux_density: 200e-6 mol/m^2/s\t\n"); + fprintf(fp, "\tdirection: LAMBERT\n"); + fprintf(fp, "\t\t surface : \"surface name 2\"\n"); + fprintf(fp, "\tgeometry: BACK test_0.stl\t\n"); + fprintf(fp, "\tsource:\t #commentaire\n"); + fprintf(fp, "\tflux_density: 1e3 umol/m^2/s\t\n"); + fprintf(fp, "\tdirection: COLLIM NORMAL\n"); + fprintf(fp, "\t\t surface : \"surface name 2\"\n"); + fprintf(fp, "\tgeometry: BACK test_0.stl\t\n"); + fprintf(fp, "\tsource:\t #commentaire\n"); + fprintf(fp, "\tflux_density: 200e3 mW/m^2\t\n"); + fprintf(fp, "\tdirection: COS_POW_N 1\n"); + fclose(fp); + + CHK(sphin_load(sphin, path, &config) == RES_OK); + CHK(sphin_config_get_surface_count(config, &nsurfaces) == RES_OK); + CHK(nsurfaces == 3); + + CHK(sphin_config_get_surface(config, 0, &surface) == RES_OK); + CHK(sphin_surface_get_geometry_count(NULL, &ngeometries) == RES_BAD_ARG); + CHK(sphin_surface_get_geometry_count(surface, &ngeometries) == RES_OK); + CHK(sphin_surface_get_source(surface, &source) == RES_OK); + CHK(sphin_source_get_direction_distribution(NULL, &dir_dist) == RES_BAD_ARG); + CHK(sphin_source_get_direction_distribution(source, NULL) == RES_BAD_ARG); + CHK(sphin_source_get_direction_distribution(source, &dir_dist) == RES_OK); + CHK(dir_dist.type == SPHIN_SOURCE_DIRECTION_ISOTROPIC); + CHK(dir_dist.cos_pow_n.collimation_degree == SPHIN_SOURCE_DIRECTION_DISTRIBUTION_COS_POW_N_NULL.collimation_degree); + CHK(dir_dist.collim.direction[0] == SPHIN_SOURCE_DIRECTION_DISTRIBUTION_COLLIM_NULL.direction[0]); + CHK(dir_dist.collim.direction[1] == SPHIN_SOURCE_DIRECTION_DISTRIBUTION_COLLIM_NULL.direction[1]); + CHK(dir_dist.collim.direction[2] == SPHIN_SOURCE_DIRECTION_DISTRIBUTION_COLLIM_NULL.direction[2]); + CHK(sphin_source_surface_get_flux_density(NULL, &flux_density) == RES_BAD_ARG); + CHK(sphin_source_surface_get_flux_density(source, NULL) == RES_BAD_ARG); + CHK(sphin_source_surface_get_flux_density(source, &flux_density) == RES_OK); + CHK(fabs(flux_density.flux_density - 200) < 1e-15); + CHK(flux_density.unit == SPHIN_PHOTON_UNIT_MOL); + CHK(sphin_source_ref_get(NULL) == RES_BAD_ARG); + CHK(sphin_source_ref_put(NULL) == RES_BAD_ARG); + CHK(sphin_source_ref_get(source) == RES_OK); + CHK(sphin_source_ref_put(source) == RES_OK); + + CHK(sphin_config_get_surface(config, 1, &surface) == RES_OK); + CHK(sphin_surface_get_source(surface, &source) == RES_OK); + CHK(sphin_source_get_direction_distribution(source, &dir_dist) == RES_OK); + CHK(dir_dist.type == SPHIN_SOURCE_DIRECTION_COLLIM); + CHK(dir_dist.cos_pow_n.collimation_degree == SPHIN_SOURCE_DIRECTION_DISTRIBUTION_COS_POW_N_NULL.collimation_degree); + CHK(dir_dist.collim.direction[0] == 0); + CHK(dir_dist.collim.direction[1] == 0); + CHK(dir_dist.collim.direction[2] == 0); + CHK(sphin_source_surface_get_flux_density(source, &flux_density) == RES_OK); + CHK(fabs(flux_density.flux_density - 1000) < 1e-15); + CHK(flux_density.unit == SPHIN_PHOTON_UNIT_MOL); + + CHK(sphin_config_get_surface(config, 2, &surface) == RES_OK); + CHK(sphin_surface_get_source(surface, &source) == RES_OK); + CHK(sphin_source_get_direction_distribution(source, &dir_dist) == RES_OK); + CHK(dir_dist.type == SPHIN_SOURCE_DIRECTION_COS_POW_N); + CHK(fabs(dir_dist.cos_pow_n.collimation_degree - 1) < 1e-15); + CHK(dir_dist.collim.direction[0] == SPHIN_SOURCE_DIRECTION_DISTRIBUTION_COLLIM_NULL.direction[0]); + CHK(dir_dist.collim.direction[1] == SPHIN_SOURCE_DIRECTION_DISTRIBUTION_COLLIM_NULL.direction[1]); + CHK(dir_dist.collim.direction[2] == SPHIN_SOURCE_DIRECTION_DISTRIBUTION_COLLIM_NULL.direction[2]); + CHK(sphin_source_surface_get_flux_density(source, &flux_density) == RES_OK); + CHK(fabs(flux_density.flux_density - 200) < 1e-15); + CHK(flux_density.unit == SPHIN_PHOTON_UNIT_JOULE); + + CHK(sphin_config_ref_put(config) == RES_OK); +} + +static void +test_source_api_bad_flux_density + (struct sphin* sphin) +{ + const char* path = "file.txt"; + struct sphin_config* config = NULL; + + FILE* fp = NULL; + + CHK(fp = fopen(path, "w+")); + fprintf(fp, "\t\t surface : \"surface name\"\n"); + fprintf(fp, "\tgeometry: FRONT test_0.stl\t\n"); + fprintf(fp, "\tsource:\t #commentaire\n"); + fprintf(fp, "\tflux_density: 200e-6 mol /m^2/s\t\n"); + fprintf(fp, "\tdirection: LAMBERT\n"); + fclose(fp); + + CHK(sphin_load(sphin, path, &config) == RES_BAD_ARG); +} + +static void +test_source_api_bad_flux_density_value + (struct sphin* sphin) +{ + const char* path = "file.txt"; + struct sphin_config* config = NULL; + + FILE* fp = NULL; + + CHK(fp = fopen(path, "w+")); + fprintf(fp, "\t\t surface : \"surface name\"\n"); + fprintf(fp, "\tgeometry: FRONT test_0.stl\t\n"); + fprintf(fp, "\tsource:\t #commentaire\n"); + fprintf(fp, "\tflux_density: -200e-6 mol/m^2/s\t\n"); + fprintf(fp, "\tdirection: LAMBERT\n"); + fclose(fp); + + CHK(sphin_load(sphin, path, &config) == RES_BAD_ARG); +} + +static void +test_source_api_bad_direction + (struct sphin* sphin) +{ + const char* path = "file.txt"; + struct sphin_config* config = NULL; + + FILE* fp = NULL; + + CHK(fp = fopen(path, "w+")); + fprintf(fp, "\t\t surface : \"surface name\"\n"); + fprintf(fp, "\tgeometry: FRONT test_0.stl\t\n"); + fprintf(fp, "\tsource:\t #commentaire\n"); + fprintf(fp, "\tflux_density: 200e-6 mol/m^2/s\t\n"); + fprintf(fp, "\tdirection: LAMBRET\n"); + fclose(fp); + + CHK(sphin_load(sphin, path, &config) == RES_BAD_ARG); +} + +static void +test_source_api_bad_collimation_degree + (struct sphin* sphin) +{ + const char* path = "file.txt"; + struct sphin_config* config = NULL; + + FILE* fp = NULL; + + CHK(fp = fopen(path, "w+")); + fprintf(fp, "\t\t surface : \"surface name\"\n"); + fprintf(fp, "\tgeometry: FRONT test_0.stl\t\n"); + fprintf(fp, "\tsource:\t #commentaire\n"); + fprintf(fp, "\tflux_density: 200e-6 mol/m^2/s\t\n"); + fprintf(fp, "\tdirection: COS_POW_N -100\n"); + fclose(fp); + + CHK(sphin_load(sphin, path, &config) == RES_BAD_ARG); +} + +int +main(int argc, char** argv) +{ + struct mem_allocator allocator; + struct sphin* sphin; + struct sphin_create_args args = SPHIN_CREATE_ARGS_DEFAULT; + + (void)argc; + (void)argv; + args.verbose = 1; + + mem_init_proxy_allocator(&allocator, &mem_default_allocator); + sphin_create(&args, &sphin); + + write_stl_test_files(); + test_source_api(sphin); + test_source_api_bad_flux_density(sphin); + test_source_api_bad_flux_density_value(sphin); + test_source_api_bad_collimation_degree(sphin); + test_source_api_bad_direction(sphin); + + CHK(sphin_ref_put(sphin) == RES_OK); + + check_memory_allocator(&allocator); + mem_shutdown_proxy_allocator(&allocator); + CHK(mem_allocated_size() == 0); + return 0; +} diff --git a/src/test_sphin_load_surface.c b/src/test_sphin_load_surface.c @@ -93,7 +93,9 @@ test_load_surface { struct sphin_config* config = NULL; const char* path = "file.txt"; + double reflectivity; struct sphin_surface* surface = NULL; + struct sphin_brdf* brdf = NULL; size_t nsurfaces; FILE* fp = NULL; @@ -107,21 +109,103 @@ test_load_surface fprintf(fp, " # A line with a comment\n"); fprintf(fp, " \n"); fprintf(fp, "surface: \"other_tube walls\"\n"); - fprintf(fp, "\tbrdf\t : SPECULAR 0.5\n"); + fprintf(fp, "\tbrdf\t : SPECULAR 0.5 \n"); fclose(fp); CHK(sphin_load(sphin, path, &config) == RES_OK); + /* Test surface 0 and all possible arg values */ + CHK(sphin_config_get_surface_count(NULL, NULL) == RES_BAD_ARG); + CHK(sphin_config_get_surface_count(NULL, &nsurfaces) == RES_BAD_ARG); + CHK(sphin_config_get_surface_count(config, NULL) == RES_BAD_ARG); CHK(sphin_config_get_surface_count(config, &nsurfaces) == RES_OK); CHK(nsurfaces == 2); + CHK(sphin_config_get_surface(NULL, 0,NULL) == RES_BAD_ARG); + CHK(sphin_config_get_surface(NULL, 0, &surface) == RES_BAD_ARG); + CHK(sphin_config_get_surface(config, 0, NULL) == RES_BAD_ARG); + CHK(sphin_config_get_surface(config, 10, &surface) == RES_BAD_ARG); + CHK(sphin_config_get_surface(config, (size_t)-1, &surface) == RES_BAD_ARG); CHK(sphin_config_get_surface(config, 0, &surface) == RES_OK); + CHK(sphin_surface_get_brdf(NULL, NULL) == RES_BAD_ARG); + CHK(sphin_surface_get_brdf(surface, NULL) == RES_BAD_ARG); + CHK(sphin_surface_get_brdf(NULL, &brdf) == RES_BAD_ARG); + CHK(sphin_surface_get_brdf(surface, &brdf) == RES_OK); + CHK(sphin_brdf_lambertian_get_reflectivity(NULL, NULL) == RES_BAD_ARG); + CHK(sphin_brdf_lambertian_get_reflectivity(NULL, &reflectivity) == RES_BAD_ARG); + CHK(sphin_brdf_specular_get_reflectivity(brdf, &reflectivity) == RES_BAD_ARG); + CHK(sphin_brdf_lambertian_get_reflectivity(NULL, NULL) == RES_BAD_ARG); + CHK(sphin_brdf_lambertian_get_reflectivity(NULL, &reflectivity) == RES_BAD_ARG); + CHK(sphin_brdf_lambertian_get_reflectivity(brdf, NULL) == RES_BAD_ARG); + CHK(sphin_brdf_lambertian_get_reflectivity(brdf, &reflectivity) == RES_OK); + CHK(fabs(reflectivity) < 1e-15); + + /* Test surface 1 */ CHK(sphin_config_get_surface(config, 1, &surface) == RES_OK); + CHK(sphin_surface_get_brdf(surface, &brdf) == RES_OK); + CHK(sphin_brdf_lambertian_get_reflectivity(brdf, &reflectivity) == RES_BAD_ARG); + CHK(sphin_brdf_specular_get_reflectivity(NULL, NULL) == RES_BAD_ARG); + CHK(sphin_brdf_specular_get_reflectivity(brdf, NULL) == RES_BAD_ARG); + CHK(sphin_brdf_specular_get_reflectivity(NULL, &reflectivity) == RES_BAD_ARG); + CHK(sphin_brdf_specular_get_reflectivity(brdf, &reflectivity) == RES_OK); + CHK(fabs(reflectivity - 0.5) < 1e-15); + CHK(sphin_brdf_ref_get(brdf) == RES_OK); + CHK(sphin_brdf_ref_put(brdf) == RES_OK); CHK(sphin_surface_ref_get(surface) == RES_OK); CHK(sphin_surface_ref_get(surface) == RES_OK); CHK(sphin_surface_ref_put(surface) == RES_OK); CHK(sphin_config_ref_put(config) == RES_OK); CHK(surface != NULL); + CHK(sphin_surface_ref_put(surface) == RES_OK); +} + +static void +test_load_surface_bad_brdf_key + (struct sphin* sphin) +{ + struct sphin_config* config = NULL; + const char* path = "file.txt"; + FILE* fp = NULL; + + CHK(fp = fopen(path, "w+")); + fprintf(fp, "#Mot Clé Nom\n"); + fprintf(fp, " surface\t: \"tube_walls\" blabla\n"); + fprintf(fp, "\tbrdf\t : SPETACULAR 0.5\n"); + fclose(fp); + + CHK(sphin_load(sphin, path, &config) == RES_BAD_ARG); +} + +static void +test_load_surface_bad_brdf_value + (struct sphin* sphin) +{ + struct sphin_config* config = NULL; + const char* path = "file.txt"; + FILE* fp = NULL; + + CHK(fp = fopen(path, "w+")); + fprintf(fp, "#Mot Clé Nom\n"); + fprintf(fp, " surface\t: \"tube_walls\" blabla\n"); + fprintf(fp, "\tbrdf\t : SPECULAR x\n"); + fclose(fp); + CHK(sphin_load(sphin, path, &config) == RES_BAD_ARG); +} + +static void +test_load_surface_bad_name + (struct sphin* sphin) +{ + struct sphin_config* config = NULL; + const char* path = "file.txt"; + FILE* fp = NULL; + + CHK(fp = fopen(path, "w+")); + fprintf(fp, "#Mot Clé Nom\n"); + fprintf(fp, " surface\t: \"tube_walls\" blabla\n"); + fclose(fp); + + CHK(sphin_load(sphin, path, &config) == RES_BAD_ARG); } static void @@ -157,6 +241,9 @@ main(int argc, char** argv) write_stl_test_files(); test_load_surface(sphin); + test_load_surface_bad_brdf_key(sphin); + test_load_surface_bad_brdf_value(sphin); + test_load_surface_bad_name(sphin); test_load_surface_bad_geometry(sphin); CHK(sphin_ref_put(sphin) == RES_OK); diff --git a/src/test_sphin_load_volume.c b/src/test_sphin_load_volume.c @@ -109,31 +109,59 @@ test_load_volume fprintf(fp, " # A line with a comment\n"); fprintf(fp, " \n"); fprintf(fp, "volume: \"my reaction volume\"\n"); - fprintf(fp, "\tka: 1 cm^-1\n"); + fprintf(fp, "\tka: 1e-1 cm^-1\n"); fprintf(fp, "volume: \"my last volume\"\n"); - fprintf(fp, "\tka: 1 cm^-1\n"); + fprintf(fp, "\tka: 1 mm^-1\n"); fclose(fp); CHK(sphin_load(sphin, path, &config) == RES_OK); + /* Test volume 0 and all possible arg values */ + CHK(sphin_config_get_volume_count(NULL, NULL) == RES_BAD_ARG); + CHK(sphin_config_get_volume_count(NULL, &nvolumes) == RES_BAD_ARG); + CHK(sphin_config_get_volume_count(config, NULL) == RES_BAD_ARG); CHK(sphin_config_get_volume_count(config, &nvolumes) == RES_OK); CHK(nvolumes == 3); + CHK(sphin_config_get_volume(NULL, 0, NULL) == RES_BAD_ARG); + CHK(sphin_config_get_volume(NULL, 0, &volume) == RES_BAD_ARG); + CHK(sphin_config_get_volume(config, 0, NULL) == RES_BAD_ARG); + CHK(sphin_config_get_volume(config, 10, &volume) == RES_BAD_ARG); + CHK(sphin_config_get_volume(config, (size_t)-1, &volume) == RES_BAD_ARG); CHK(sphin_config_get_volume(config, 0, &volume) == RES_OK); + CHK(sphin_volume_get_ka(NULL, NULL) == RES_BAD_ARG); + CHK(sphin_volume_get_ka(NULL, &ka) == RES_BAD_ARG); + CHK(sphin_volume_get_ka(volume, NULL) == RES_BAD_ARG); CHK(sphin_volume_get_ka(volume, &ka) == RES_OK); CHK(fabs(ka-1) < 1e-15); + CHK(sphin_volume_get_sensor(NULL, NULL) == RES_BAD_ARG); + CHK(sphin_volume_get_sensor(NULL, &sensor) == RES_BAD_ARG); + CHK(sphin_volume_get_sensor(volume, NULL) == RES_BAD_ARG); CHK(sphin_volume_get_sensor(volume, &sensor) == RES_OK); + CHK(sphin_sensor_get_response_function(NULL, NULL) == RES_BAD_ARG); + CHK(sphin_sensor_get_response_function(NULL, &response_function) == RES_BAD_ARG); + CHK(sphin_sensor_get_response_function(sensor, NULL) == RES_BAD_ARG); CHK(sphin_sensor_get_response_function(sensor, &response_function) == RES_OK); CHK(fabs(response_function-1) < 1e-15); - CHK(sphin_config_get_volume(config, 1, &volume) == RES_OK); - CHK(sphin_volume_ref_get(volume) == RES_OK); CHK(sphin_volume_ref_get(volume) == RES_OK); CHK(sphin_volume_ref_put(volume) == RES_OK); + + /* Test volume 1 */ + CHK(sphin_config_get_volume(config, 1, &volume) == RES_OK); CHK(sphin_volume_get_ka(volume, &ka) == RES_OK); - CHK(fabs(ka-1e-2) < 1e-5); + CHK(fabs(ka-10) < 1e-15); + CHK(sphin_volume_get_sensor(volume, &sensor) == RES_BAD_ARG); /* Volume has no sensor */ + CHK(fabs(response_function-1) < 1e-15); + + /* Test volume 2 */ + CHK(sphin_config_get_volume(config, 2, &volume) == RES_OK); + CHK(sphin_volume_get_ka(volume, &ka) == RES_OK); + CHK(fabs(ka-1000) < 1e-15); + CHK(sphin_config_get_volume(config, 1, &volume) == RES_OK); + + CHK(sphin_volume_ref_get(volume) == RES_OK); CHK(sphin_config_ref_put(config) == RES_OK); CHK(volume != NULL); CHK(sphin_volume_ref_put(volume) == RES_OK); - /* TODO Test mesh consistency once sphin_mesh is implemented */ } static void