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 47b05af5ed5bb064aa0f7e4b9b4aab1014a934aa
parent ae4e7fcebfca51049896bb2f7bbc341d6c208f2d
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Mon, 23 May 2022 12:20:18 +0200

Test the line list [de]serialization

Diffstat:
Msrc/test_shtr_lines.c | 82+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 82 insertions(+), 0 deletions(-)

diff --git a/src/test_shtr_lines.c b/src/test_shtr_lines.c @@ -237,6 +237,87 @@ test_load_failures(struct shtr* shtr) } static void +check_lines_equality + (const struct shtr_line* line1, + const struct shtr_line* line2) +{ + CHK(line1 && line2); + CHK(line1->wavenumber == line2->wavenumber); + CHK(line1->intensity == line2->intensity); + CHK(line1->gamma_air == line2->gamma_air); + CHK(line1->gamma_self == line2->gamma_self); + CHK(line1->lower_state_energy == line2->lower_state_energy); + CHK(line1->n_air == line2->n_air); + CHK(line1->delta_air == line2->delta_air); + CHK(line1->molecule_id == line2->molecule_id); + CHK(line1->isotope_id_local == line2->isotope_id_local); +} + +static void +check_lines_list_equality + (const struct shtr_lines_list* list1, + const struct shtr_lines_list* list2) +{ + const struct shtr_line* lines1 = NULL; + const struct shtr_line* lines2 = NULL; + size_t n1, n2; + size_t iline, nlines; + CHK(list1 && list2); + + CHK(shtr_lines_list_get_size(list1, &n1) == RES_OK); + CHK(shtr_lines_list_get_size(list2, &n2) == RES_OK); + CHK(n1 == n2); + nlines = n1; + + CHK(shtr_lines_list_get(list1, &lines1) == RES_OK); + CHK(shtr_lines_list_get(list2, &lines2) == RES_OK); + FOR_EACH(iline, 0, nlines) { + check_lines_equality(lines1+iline, lines2+iline); + } +} + +static void +test_serialization(struct shtr* shtr) +{ + const struct shtr_line l[] = { + {0.000134, 2.672E-38, 0.0533, 0.410, 608.4727, 0.79, 0.000060, 1, 4}, + {0.000379, 1.055E-39, 0.0418, 0.329,1747.9686, 0.79, 0.000110, 1, 5}, + {0.000448, 5.560E-38, 0.0490, 0.364,1093.0269, 0.79, 0.000060, 1, 4}, + {0.000686, 1.633E-36, 0.0578, 0.394, 701.1162, 0.79, 0.000180, 1, 4}, + {0.000726, 6.613E-33, 0.0695, 0.428, 402.3295, 0.79, 0.000240, 1, 3} + }; + const size_t nlines = sizeof(l) / sizeof(struct shtr_line); + + struct shtr_lines_list* list1 = NULL; + struct shtr_lines_list* list2 = NULL; + FILE* fp = NULL; + + CHK(fp = tmpfile()); + print_lines(fp, l, nlines); + rewind(fp); + + CHK(shtr_lines_list_load_stream(shtr, fp, NULL, &list1) == RES_OK); + fclose(fp); + + CHK(fp = tmpfile()); + CHK(shtr_lines_list_write(NULL, fp) == RES_BAD_ARG); + CHK(shtr_lines_list_write(list1, NULL) == RES_BAD_ARG); + CHK(shtr_lines_list_write(list1, fp) == RES_OK); + rewind(fp); + + CHK(shtr_lines_list_create_from_stream(NULL, fp, &list2) == RES_BAD_ARG); + CHK(shtr_lines_list_create_from_stream(shtr, NULL, &list2) == RES_BAD_ARG); + CHK(shtr_lines_list_create_from_stream(shtr, fp, NULL) == RES_BAD_ARG); + CHK(shtr_lines_list_create_from_stream(shtr, fp, &list2) == RES_OK); + fclose(fp); + + check_lines_list_equality(list1, list2); + + CHK(shtr_lines_list_ref_put(list1) == RES_OK); + CHK(shtr_lines_list_ref_put(list2) == RES_OK); +} + +static void check_view (const struct shtr_lines_list* list, const struct shtr_lines_view* view, @@ -593,6 +674,7 @@ main(int argc, char** argv) test_line_eq(); test_load(shtr); test_load_failures(shtr); + test_serialization(shtr); test_view(shtr); FOR_EACH(i, 1, argc) {