1
0
mirror of https://github.com/TREX-CoE/trexio.git synced 2024-12-22 12:23:54 +01:00

add unit tests for delete_group functionality

This commit is contained in:
q-posev 2022-01-24 10:12:44 +01:00
parent 8c157454d3
commit 7ba6924a8a
4 changed files with 182 additions and 0 deletions

View File

@ -94,6 +94,7 @@ TESTS_C = \
tests/io_safe_dset_float_text \
tests/io_str_text \
tests/io_dset_str_text \
tests/delete_group_text \
tests/overwrite_all_text \
tests/io_all
@ -107,6 +108,7 @@ TESTS_C += \
tests/io_safe_dset_float_hdf5 \
tests/io_str_hdf5 \
tests/io_dset_str_hdf5 \
tests/delete_group_hdf5 \
tests/overwrite_all_hdf5
endif

View File

@ -11,6 +11,7 @@ set(Tests_text
io_dset_int_text
io_num_text
io_str_text
delete_group_text
overwrite_all_text
)
@ -25,6 +26,7 @@ if(ENABLE_HDF5)
io_dset_int_hdf5
io_num_hdf5
io_str_hdf5
delete_group_hdf5
overwrite_all_hdf5
)

89
tests/delete_group_hdf5.c Normal file
View File

@ -0,0 +1,89 @@
#include "trexio.h"
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#define TEST_BACKEND TREXIO_HDF5
#define TREXIO_FILE "test_del.h5"
#define RM_COMMAND "rm -f -- " TREXIO_FILE
static int test_write_delete_group (const char* file_name, const back_end_t backend) {
/* Try to write a dimensioning attribute (num variable) into the TREXIO file */
trexio_t* file = NULL;
trexio_exit_code rc;
// parameters to be written
int num = 12;
double coord[36] = {
0.00000000 , 1.39250319 , 0.00000000 ,
-1.20594314 , 0.69625160 , 0.00000000 ,
-1.20594314 , -0.69625160 , 0.00000000 ,
0.00000000 , -1.39250319 , 0.00000000 ,
1.20594314 , -0.69625160 , 0.00000000 ,
1.20594314 , 0.69625160 , 0.00000000 ,
-2.14171677 , 1.23652075 , 0.00000000 ,
-2.14171677 , -1.23652075 , 0.00000000 ,
0.00000000 , -2.47304151 , 0.00000000 ,
2.14171677 , -1.23652075 , 0.00000000 ,
2.14171677 , 1.23652075 , 0.00000000 ,
0.00000000 , 2.47304151 , 0.00000000 ,
};
/*================= START OF TEST ==================*/
// open file in 'write' mode
file = trexio_open(file_name, 'w', backend, &rc);
assert (file != NULL);
// write numerical attribute in an empty file
rc = trexio_write_nucleus_num(file, num);
assert (rc == TREXIO_SUCCESS);
// write numerical dataset in a file
rc = trexio_write_nucleus_coord(file, coord);
assert (rc == TREXIO_SUCCESS);
// write numerical attribute ao_cartesian as 0
rc = trexio_write_ao_cartesian(file, 0);
assert (rc == TREXIO_SUCCESS);
// close current session
rc = trexio_close(file);
assert (rc == TREXIO_SUCCESS);
// open file in 'unsafe' mode
file = trexio_open(file_name, 'u', backend, &rc);
assert (file != NULL);
// delete a previously written group
rc = trexio_delete_nucleus(file);
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_COMMAND);
assert (rc == 0);
test_write_delete_group (TREXIO_FILE, TEST_BACKEND);
rc = system(RM_COMMAND);
assert (rc == 0);
return 0;
}

89
tests/delete_group_text.c Normal file
View File

@ -0,0 +1,89 @@
#include "trexio.h"
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#define TEST_BACKEND TREXIO_TEXT
#define TREXIO_FILE "test_del.dir"
#define RM_COMMAND "rm -rf " TREXIO_FILE
static int test_write_delete_group (const char* file_name, const back_end_t backend) {
/* Try to write a dimensioning attribute (num variable) into the TREXIO file */
trexio_t* file = NULL;
trexio_exit_code rc;
// parameters to be written
int num = 12;
double coord[36] = {
0.00000000 , 1.39250319 , 0.00000000 ,
-1.20594314 , 0.69625160 , 0.00000000 ,
-1.20594314 , -0.69625160 , 0.00000000 ,
0.00000000 , -1.39250319 , 0.00000000 ,
1.20594314 , -0.69625160 , 0.00000000 ,
1.20594314 , 0.69625160 , 0.00000000 ,
-2.14171677 , 1.23652075 , 0.00000000 ,
-2.14171677 , -1.23652075 , 0.00000000 ,
0.00000000 , -2.47304151 , 0.00000000 ,
2.14171677 , -1.23652075 , 0.00000000 ,
2.14171677 , 1.23652075 , 0.00000000 ,
0.00000000 , 2.47304151 , 0.00000000 ,
};
/*================= START OF TEST ==================*/
// open file in 'write' mode
file = trexio_open(file_name, 'w', backend, &rc);
assert (file != NULL);
// write numerical attribute in an empty file
rc = trexio_write_nucleus_num(file, num);
assert (rc == TREXIO_SUCCESS);
// write numerical dataset in a file
rc = trexio_write_nucleus_coord(file, coord);
assert (rc == TREXIO_SUCCESS);
// write numerical attribute ao_cartesian as 0
rc = trexio_write_ao_cartesian(file, 0);
assert (rc == TREXIO_SUCCESS);
// close current session
rc = trexio_close(file);
assert (rc == TREXIO_SUCCESS);
// open file in 'unsafe' mode
file = trexio_open(file_name, 'u', backend, &rc);
assert (file != NULL);
// delete a previously written group
rc = trexio_delete_nucleus(file);
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_COMMAND);
assert (rc == 0);
test_write_delete_group (TREXIO_FILE, TEST_BACKEND);
rc = system(RM_COMMAND);
assert (rc == 0);
return 0;
}