star-meteo

Time varying meteorological data
git clone git://git.meso-star.fr/star-meteo.git
Log | Files | Refs | README | LICENSE

commit 36e30a029220fd41999badc18748ad234bc8d3cd
parent 4d48e70bd2ce64ac6108cc32d44bd3f4a1ed0e26
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Wed, 14 May 2025 17:17:31 +0200

First load tests

Checking the API when loading an empty file.

Diffstat:
MMakefile | 3++-
Asrc/test_smeteo_load.c | 75+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 77 insertions(+), 1 deletion(-)

diff --git a/Makefile b/Makefile @@ -112,7 +112,7 @@ clean: clean_test ################################################################################ # Tests ################################################################################ -TEST_SRC = src/test_smeteo.c +TEST_SRC = src/test_smeteo.c src/test_smeteo_load.c TEST_OBJ = $(TEST_SRC:.c=.o) TEST_DEP = $(TEST_SRC:.c=.d) TEST_BIN = $(TEST_SRC:.c=.b) @@ -144,6 +144,7 @@ $(TEST_OBJ): config.mk smeteo-local.pc $(CC) $(CFLAGS_TEST) -c $(@:.o=.c) -o $@ test_smeteo \ +test_smeteo_load \ : config.mk smeteo-local.pc $(LIBNAME) $(CC) $(CFLAGS_TEST) -o $@ src/$@.o $(LDFLAGS_TEST) diff --git a/src/test_smeteo_load.c b/src/test_smeteo_load.c @@ -0,0 +1,75 @@ +/* Copyright (C) 2025 |Méso|Star> (contact@meso-star.com) + * + * This program is free software: you can redismeteobute 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 dismeteobuted 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 "smeteo.h" + +#include <rsys/mem_allocator.h> + +#include <string.h> + +/******************************************************************************* + * Helper functions + ******************************************************************************/ +static void +check_api(struct smeteo* smeteo) +{ + struct smeteo_desc desc = SMETEO_DESC_NULL; + const char* filename = "test.txt"; + FILE* fp = NULL; + + CHK((fp = fopen(filename, "w+")) != NULL); + + #define CHECK_EMPTY_FILE(Name) { \ + CHK(smeteo_get_desc(smeteo, &desc) == RES_OK); \ + CHK(!strcmp(desc.filename, Name)); \ + CHK(desc.entries == NULL); \ + CHK(desc.nentries == 0); \ + } (void)0 + + CHK(smeteo_load(smeteo, NULL) == RES_BAD_ARG); + CHK(smeteo_load(NULL, filename) == RES_BAD_ARG); + CHK(smeteo_load(smeteo, "none.txt") == RES_IO_ERR); + CHK(smeteo_load(smeteo, filename) == RES_OK); /* Empty file should be OK */ + CHECK_EMPTY_FILE(filename); + + CHK(smeteo_load_stream(NULL, fp, "foo") == RES_BAD_ARG); + CHK(smeteo_load_stream(smeteo, NULL, "foo") == RES_BAD_ARG); + CHK(smeteo_load_stream(smeteo, fp, NULL) == RES_BAD_ARG); + CHK(smeteo_load_stream(smeteo, fp, "foo") == RES_OK); + CHECK_EMPTY_FILE("foo"); + + #undef CHECK_EMPTY_FILE + + CHK(fclose(fp) == 0); +} + +/******************************************************************************* + * The test + ******************************************************************************/ +int +main(void) +{ + struct smeteo* smeteo = NULL; + struct smeteo_create_args args = SMETEO_CREATE_ARGS_DEFAULT; + + args.verbose = 3; + CHK(smeteo_create(&args, &smeteo) == RES_OK); + + check_api(smeteo); + + CHK(smeteo_ref_put(smeteo) == RES_OK); + CHK(mem_allocated_size() == 0); + return 0; +}