star-line

Structure for accelerating line importance sampling
git clone git://git.meso-star.fr/star-line.git
Log | Files | Refs | README | LICENSE

commit 01d181392ad464a22a1270c1d8a296a2ce0457bb
parent 8a53e62700c906ef970742a29fd16aaef8930cda
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Wed,  4 Feb 2026 18:00:49 +0100

Test how loading reacts with invalid molecule definitions

Diffstat:
Msrc/test_sln_mixture.c | 107+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 105 insertions(+), 2 deletions(-)

diff --git a/src/test_sln_mixture.c b/src/test_sln_mixture.c @@ -16,6 +16,8 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ +#define _POSIX_C_SOURCE 200809L /* fmemopen */ + #include "test_sln_lines.h" #include "sln.h" @@ -23,6 +25,9 @@ #include <rsys/math.h> #include <rsys/mem_allocator.h> +#include <stdio.h> +#include <string.h> + /******************************************************************************* * Helper function ******************************************************************************/ @@ -122,6 +127,103 @@ test_api CHK(fclose(fp) == 0); } +static void +test_invalid_molecule + (struct sln_device* sln, + struct shtr_isotope_metadata* molparam) +{ + struct sln_mixture_load_args args = SLN_MIXTURE_LOAD_ARGS_NULL; + struct sln_mixture* mixture = NULL; + + char buf[1024] = {0}; + FILE* fp; + + + /* Note that the comment char will be added as the last character written to + * the file in order to fill the rest of the file with a comment */ + CHK(fp = fmemopen(buf, sizeof(buf), "w+")); + + args.filename = "memstream"; + args.molparam = molparam; + args.file = fp; + + #define RESET { memset(buf, 0, sizeof(buf)); rewind(fp); } (void)0 + + /* Name is missing */ + RESET; + fprintf(fp, "0.3 25\n#"); + rewind(fp); + CHK(sln_mixture_load(sln, &args, &mixture) == RES_BAD_ARG); + + /* Name is invalid */ + RESET; + fprintf(fp, "Water 0.3 25\n#"); + rewind(fp); + CHK(sln_mixture_load(sln, &args, &mixture) == RES_BAD_ARG); + + /* Name is valid but is not in the isotope metadata */ + RESET; + fprintf(fp, "O2 0.1 25\n#"); + rewind(fp); + CHK(sln_mixture_load(sln, &args, &mixture) == RES_BAD_ARG); + + /* Definition of duplicate molecule */ + RESET; + fprintf(fp, "H2O 0.3 25\n"); + fprintf(fp, "H2O 0.1 50\n"); + rewind(fp); + CHK(sln_mixture_load(sln, &args, &mixture) == RES_BAD_ARG); + + /* Concentration is missing */ + RESET; + fprintf(fp, "H2O 25\n#"); + rewind(fp); + CHK(sln_mixture_load(sln, &args, &mixture) == RES_BAD_ARG); + + /* Invalid concentration */ + RESET; + fprintf(fp, "H2O -0.1 25\n#"); + rewind(fp); + CHK(sln_mixture_load(sln, &args, &mixture) == RES_BAD_ARG); + RESET; + fprintf(fp, "H2O 1.1 25\n#"); + rewind(fp); + CHK(sln_mixture_load(sln, &args, &mixture) == RES_BAD_ARG); + + /* Missing cutoff */ + RESET; + fprintf(fp, "H2O 0.3\n#"); + rewind(fp); + CHK(sln_mixture_load(sln, &args, &mixture) == RES_BAD_ARG); + + /* Invalid cutoff */ + RESET; + fprintf(fp, "H2O 0.3 0\n#"); + rewind(fp); + CHK(sln_mixture_load(sln, &args, &mixture) == RES_BAD_ARG); + + /* Invalid overall cocentration */ + RESET; + fprintf(fp, "H2O 0.3 25\n"); + fprintf(fp, "CO2 0.7 50\n"); + fprintf(fp, "O3 0.1 25\n#"); + rewind(fp); + CHK(sln_mixture_load(sln, &args, &mixture) == RES_BAD_ARG); + + /* An overall concentration < 1 is valid */ + RESET; + fprintf(fp, "H2O 0.2 25\n"); + fprintf(fp, "CO2 0.3 50\n"); + fprintf(fp, "O3 0.4 25\n#"); + rewind(fp); + CHK(sln_mixture_load(sln, &args, &mixture) == RES_OK); + CHK(sln_mixture_ref_put(mixture) == RES_OK); + + #undef RESET + + CHK(fclose(fp) == 0); +} + static struct shtr_isotope_metadata* load_isotope_metadata(struct shtr* shtr) { @@ -155,15 +257,16 @@ main(void) struct shtr* shtr = NULL; struct shtr_isotope_metadata* molparam = NULL; - shtr_args.verbose = 1; + shtr_args.verbose = 3; CHK(shtr_create(&shtr_args, &shtr) == RES_OK); - sln_args.verbose = 1; + sln_args.verbose = 3; CHK(sln_device_create(&sln_args, &sln) == RES_OK); molparam = load_isotope_metadata(shtr); test_api(sln, molparam); + test_invalid_molecule(sln, molparam); CHK(sln_device_ref_put(sln) == RES_OK); CHK(shtr_ref_put(shtr) == RES_OK);