From b8c569f9a346f7b1fbce2b108a74ae7eed8f0059 Mon Sep 17 00:00:00 2001 From: q-posev Date: Wed, 3 Mar 2021 13:19:47 +0100 Subject: [PATCH] add test to read/append non-existing files --- src/test.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/test.c b/src/test.c index f8dcbba..c65e088 100644 --- a/src/test.c +++ b/src/test.c @@ -91,6 +91,7 @@ int test_h5read() { int64_t num; double* coord; + // test reading existing file [created by test_h5write()], should work file = trexio_open(file_name, 'r', TREXIO_HDF5); assert (file != NULL); @@ -112,6 +113,23 @@ int test_h5read() { rc = trexio_close(file); assert (rc == TREXIO_SUCCESS); + // test reading non-existing file, should fail and return NULL + const char* file_name2 = "test_nonexisting.h5"; + trexio_t* file2 = NULL; + + file2 = trexio_open(file_name2, 'r', TREXIO_HDF5); + assert (file2 == NULL); + + // test appending non-existing file, should create it + const char* file_name3 = "test_append.h5"; + trexio_t* file3 = NULL; + + file3 = trexio_open(file_name3, 'a', TREXIO_HDF5); + assert (file3 != NULL); + + rc = trexio_close(file3); + assert (rc == TREXIO_SUCCESS); + free(coord); return 0;