commit 7b7695523c25f2464e2681fe4954c9d3b0abc4c4
parent 51ab689139d5750e9d2275ef4b9b5f7dddbb9e2a
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Tue, 12 Aug 2025 12:02:13 +0200
Check the loading of a file with a single time interval
Diffstat:
1 file changed, 78 insertions(+), 0 deletions(-)
diff --git a/src/test_smeteo_load.c b/src/test_smeteo_load.c
@@ -13,12 +13,15 @@
* 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 200112L /* strcasecmp */
+
#include "smeteo.h"
#include <rsys/math.h>
#include <rsys/mem_allocator.h>
#include <string.h>
+#include <strings.h> /* strcasecmp */
/*******************************************************************************
* Helper functions
@@ -77,6 +80,80 @@ check_api(struct smeteo* smeteo)
CHK(fclose(fp) == 0);
}
+static void
+check_one_entry(struct smeteo* smeteo)
+{
+ struct smeteo_desc desc = SMETEO_DESC_NULL;
+
+ char buf[32];
+ const char* date = "01-JAN-1850 01:30:00";
+
+ /* Header */
+ const double albedo = 1;
+ const double longitude = 91.1; /* [deg] */
+ const double latitude = 46.2; /* [deg] */
+
+ /* Time interval data */
+ const double Tsrf = 287.85; /* [K] */
+ const double Tatm = 289.62; /* [K] */
+ const double Ahum = 4.23; /* [g(water)/kg(air)] */
+ const double Rhum = 12.28;
+ const double SWdn_direct = 175.08; /* [W/m^2] */
+ const double SWdn_diffuse = 0; /* [W/m^2] */
+ const double SWdn = SWdn_direct + SWdn_diffuse; /* [W/m^2] */
+ const double SWup = 55.43; /* [W/m^2] */
+ const double Trad = 271.21; /* [K] */
+ const double H = 12.60; /* [W/K/m^2] */
+ const double LE = 0.51; /* [W/m^2] */
+ const double day_1850 = 0.0625;
+
+ FILE* fp = NULL;
+
+ CHK((fp = tmpfile()) != NULL);
+
+ CHK(fprintf(fp, "%g # albedo\n", albedo) > 0);
+ CHK(fprintf(fp, "%g # longitude [deg]\n", longitude) > 0);
+ CHK(fprintf(fp, "%g # latitude [deg]\n", latitude) > 0);
+ CHK(fprintf(fp, "1 # Date count\n") > 0);
+ CHK(fprintf(fp, "%s %g %g %g %g %g %g %g %g %g %g %g %g\n",
+ date, Tsrf, Tatm, Ahum, Rhum, SWdn, SWdn_direct, SWdn_diffuse, SWup,
+ Trad, H, LE, day_1850) > 0);
+
+ rewind(fp);
+
+ CHK(smeteo_load_stream(smeteo, fp, "One entry") == RES_OK);
+ CHK(smeteo_get_desc(smeteo, &desc) == RES_OK);
+
+ /* Check header */
+ #define CHK_HEADER(Var) CHK(eq_eps(Var, desc.Var, Var*1e-6))
+ CHK_HEADER(albedo);
+ CHK_HEADER(longitude);
+ CHK_HEADER(latitude);
+ CHK(desc.nentries == 1);
+ #undef CHK_HEADER
+
+ /* Check entry time */
+ CHK(strftime(buf, sizeof(buf), "%d-%b-%Y %H:%M:%S", &desc.entries[0].time));
+ CHK(strcasecmp(buf, date) == 0);
+
+ /* Check entry data */
+ #define CHK_ENTRY(Var) CHK(eq_eps(Var, desc.entries[0].Var, Var*1e-6))
+ CHK_ENTRY(Tsrf);
+ CHK_ENTRY(Tatm);
+ CHK_ENTRY(Ahum);
+ CHK_ENTRY(Rhum);
+ CHK_ENTRY(SWdn_direct);
+ CHK_ENTRY(SWdn_diffuse);
+ CHK_ENTRY(SWup);
+ CHK_ENTRY(Trad);
+ CHK_ENTRY(H);
+ CHK_ENTRY(LE);
+ CHK_ENTRY(day_1850);
+ #undef CHK_ENTRY
+
+ CHK(fclose(fp) == 0);
+}
+
/*******************************************************************************
* The test
******************************************************************************/
@@ -90,6 +167,7 @@ main(void)
CHK(smeteo_create(&args, &smeteo) == RES_OK);
check_api(smeteo);
+ check_one_entry(smeteo);
CHK(smeteo_ref_put(smeteo) == RES_OK);
CHK(mem_allocated_size() == 0);