mirror of
https://github.com/TREX-CoE/trexio.git
synced 2024-08-24 22:21:43 +02:00
[WIP] unit testing for C API
This commit is contained in:
parent
e937b76062
commit
fd424c2149
39
Makefile.am
39
Makefile.am
@ -72,26 +72,37 @@ ORG_FILES = \
|
||||
|
||||
src_libtrexio_la_SOURCES = $(SOURCES)
|
||||
|
||||
TESTS = tests/test_c tests/test_f
|
||||
# section related to tests
|
||||
|
||||
TESTS_C = \
|
||||
tests/io_all \
|
||||
tests/io_num_hdf5 \
|
||||
tests/io_num_text
|
||||
|
||||
TESTS_F = \
|
||||
tests/test_f
|
||||
|
||||
TESTS_ALL = $(TESTS_C) $(TESTS_F)
|
||||
|
||||
TESTS = $(TESTS_ALL)
|
||||
check_PROGRAMS = $(TESTS)
|
||||
|
||||
tests_test_c_DEPENDENCIES = $(trexio_h)
|
||||
tests_test_c_SOURCES = tests/test.c $(trexio_h)
|
||||
tests_test_c_LDADD = src/libtrexio.la
|
||||
tests_test_c_LDFLAGS = -no-install
|
||||
# specify common options for all tests
|
||||
LDADD = src/libtrexio.la
|
||||
|
||||
# in principal, specifying -no-install (see example below) for each test provides better
|
||||
# and faster (?) `make check` but becomes tedious as the number of tests increases
|
||||
|
||||
#tests_io_all_LDFLAGS = -no-install
|
||||
|
||||
test_trexio_f = $(srcdir)/tests/trexio_f.f90
|
||||
|
||||
tests_test_f_DEPENDENCIES = $(test_trexio_f)
|
||||
tests_test_f_SOURCES = $(test_trexio_f) tests/test_f.f90
|
||||
tests_test_f_LDADD = src/libtrexio.la
|
||||
tests_test_f_LDFLAGS = -no-install
|
||||
|
||||
$(test_trexio_f): $(trexio_f)
|
||||
cp $(trexio_f) $(test_trexio_f)
|
||||
|
||||
clean-local:
|
||||
-rm -rf -- test_write.dir/ test_write_f.dir/ test_write.h5 test_write_f.h5
|
||||
|
||||
tests_test_f_SOURCES = $(test_trexio_f) tests/test_f.f90
|
||||
|
||||
|
||||
if TREXIO_DEVEL
|
||||
|
||||
@ -118,3 +129,7 @@ cppcheck.out: $(trexio_h)
|
||||
.PHONY: cppcheck
|
||||
|
||||
endif
|
||||
|
||||
clean-local:
|
||||
-rm -rf -- *.dir/ *.h5
|
||||
|
||||
|
52
tests/io_num_hdf5.c
Normal file
52
tests/io_num_hdf5.c
Normal file
@ -0,0 +1,52 @@
|
||||
#include "trexio.h"
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
static int test_write_num (const char* file_name, const back_end_t backend) {
|
||||
|
||||
/* Try to write dimensioning attribute (num variable) into the HDF5 file */
|
||||
|
||||
trexio_t* file = NULL;
|
||||
trexio_exit_code rc;
|
||||
|
||||
// parameters to be written
|
||||
int num = 12;
|
||||
|
||||
/*================= START OF TEST ==================*/
|
||||
|
||||
// open file in 'write' mode
|
||||
file = trexio_open(file_name, 'w', backend);
|
||||
assert (file != NULL);
|
||||
|
||||
|
||||
// write numerical attribute in an empty file
|
||||
rc = trexio_write_nucleus_num(file,num);
|
||||
assert (rc == TREXIO_SUCCESS);
|
||||
|
||||
|
||||
// close current session
|
||||
rc = trexio_close(file);
|
||||
assert (rc == TREXIO_SUCCESS);
|
||||
|
||||
/*================= END OF TEST ==================*/
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
|
||||
/*============== Test launcher ================*/
|
||||
|
||||
int rc;
|
||||
rc = system("rm -rf test_write_num.h5");
|
||||
assert (rc == 0);
|
||||
test_write_num("test_write_num.h5", TREXIO_HDF5);
|
||||
rc = system("rm -rf test_write_num.h5");
|
||||
assert (rc == 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
52
tests/io_num_text.c
Normal file
52
tests/io_num_text.c
Normal file
@ -0,0 +1,52 @@
|
||||
#include "trexio.h"
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
static int test_write_num (const char* file_name, const back_end_t backend) {
|
||||
|
||||
/* Try to write dimensioning attribute (num variable) into the TEXT file */
|
||||
|
||||
trexio_t* file = NULL;
|
||||
trexio_exit_code rc;
|
||||
|
||||
// parameters to be written
|
||||
int num = 12;
|
||||
|
||||
/*================= START OF TEST ==================*/
|
||||
|
||||
// open file in 'write' mode
|
||||
file = trexio_open(file_name, 'w', backend);
|
||||
assert (file != NULL);
|
||||
|
||||
|
||||
// write numerical attribute in an empty file
|
||||
rc = trexio_write_nucleus_num(file,num);
|
||||
assert (rc == TREXIO_SUCCESS);
|
||||
|
||||
|
||||
// close current session
|
||||
rc = trexio_close(file);
|
||||
assert (rc == TREXIO_SUCCESS);
|
||||
|
||||
/*================= END OF TEST ==================*/
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
|
||||
/*============== Test launcher ================*/
|
||||
|
||||
int rc;
|
||||
rc = system("rm -rf test_write_num.dir");
|
||||
assert (rc == 0);
|
||||
test_write_num("test_write_num.dir", TREXIO_TEXT);
|
||||
rc = system("rm -rf test_write_num.dir");
|
||||
assert (rc == 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user