1
0
mirror of https://github.com/TREX-CoE/trexio.git synced 2024-11-03 20:54:07 +01:00

complete num attribute testing

This commit is contained in:
q-posev 2021-06-18 12:53:00 +02:00
parent fd424c2149
commit dfa2604820
2 changed files with 150 additions and 16 deletions

View File

@ -3,9 +3,13 @@
#include <stdio.h>
#include <stdlib.h>
#define TEST_BACKEND TREXIO_HDF5
#define TREXIO_FILE "test_num.h5"
#define RM_COMMAND "rm -rf " TREXIO_FILE
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 */
/* Try to write a dimensioning attribute (num variable) into the TREXIO file */
trexio_t* file = NULL;
trexio_exit_code rc;
@ -19,12 +23,10 @@ static int test_write_num (const char* file_name, const back_end_t backend) {
file = trexio_open(file_name, 'w', backend);
assert (file != NULL);
// write numerical attribute in an empty file
rc = trexio_write_nucleus_num(file,num);
rc = trexio_write_nucleus_num(file, num);
assert (rc == TREXIO_SUCCESS);
// close current session
rc = trexio_close(file);
assert (rc == TREXIO_SUCCESS);
@ -32,18 +34,83 @@ static int test_write_num (const char* file_name, const back_end_t backend) {
/*================= END OF TEST ==================*/
return 0;
}
static int test_has_num (const char* file_name, const back_end_t backend) {
/* Try to check the existence of a dimensioning attribute (num variable) in the TREXIO file */
trexio_t* file = NULL;
trexio_exit_code rc;
/*================= START OF TEST ==================*/
// open file in 'write' mode
file = trexio_open(file_name, 'r', backend);
assert (file != NULL);
// check that the previously written num variable exists
rc = trexio_has_nucleus_num(file);
assert (rc == TREXIO_SUCCESS);
// check that the num variable does not exist
rc = trexio_has_mo_num(file);
assert (rc == TREXIO_HAS_NOT);
// close current session
rc = trexio_close(file);
assert (rc == TREXIO_SUCCESS);
/*================= END OF TEST ==================*/
return 0;
}
static int test_read_num (const char* file_name, const back_end_t backend) {
/* Try to read a dimensioning attribute (num variable) from the TREXIO file */
trexio_t* file = NULL;
trexio_exit_code rc;
// parameters to be read
int num;
/*================= START OF TEST ==================*/
// open file in 'write' mode
file = trexio_open(file_name, 'w', backend);
assert (file != NULL);
// read numerical attribute from the file
rc = trexio_read_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");
rc = system(RM_COMMAND);
assert (rc == 0);
test_write_num("test_write_num.h5", TREXIO_HDF5);
rc = system("rm -rf test_write_num.h5");
test_write_num (TREXIO_FILE, TEST_BACKEND);
test_has_num (TREXIO_FILE, TEST_BACKEND);
test_read_num (TREXIO_FILE, TEST_BACKEND);
rc = system(RM_COMMAND);
assert (rc == 0);
return 0;

View File

@ -3,9 +3,13 @@
#include <stdio.h>
#include <stdlib.h>
#define TEST_BACKEND TREXIO_TEXT
#define TREXIO_FILE "test_num.dir"
#define RM_COMMAND "rm -rf " TREXIO_FILE
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 */
/* Try to write a dimensioning attribute (num variable) into the TREXIO file */
trexio_t* file = NULL;
trexio_exit_code rc;
@ -19,12 +23,10 @@ static int test_write_num (const char* file_name, const back_end_t backend) {
file = trexio_open(file_name, 'w', backend);
assert (file != NULL);
// write numerical attribute in an empty file
rc = trexio_write_nucleus_num(file,num);
rc = trexio_write_nucleus_num(file, num);
assert (rc == TREXIO_SUCCESS);
// close current session
rc = trexio_close(file);
assert (rc == TREXIO_SUCCESS);
@ -32,18 +34,83 @@ static int test_write_num (const char* file_name, const back_end_t backend) {
/*================= END OF TEST ==================*/
return 0;
}
static int test_has_num (const char* file_name, const back_end_t backend) {
/* Try to check the existence of a dimensioning attribute (num variable) in the TREXIO file */
trexio_t* file = NULL;
trexio_exit_code rc;
/*================= START OF TEST ==================*/
// open file in 'write' mode
file = trexio_open(file_name, 'r', backend);
assert (file != NULL);
// check that the previously written num variable exists
rc = trexio_has_nucleus_num(file);
assert (rc == TREXIO_SUCCESS);
// check that the num variable does not exist
rc = trexio_has_mo_num(file);
assert (rc == TREXIO_HAS_NOT);
// close current session
rc = trexio_close(file);
assert (rc == TREXIO_SUCCESS);
/*================= END OF TEST ==================*/
return 0;
}
static int test_read_num (const char* file_name, const back_end_t backend) {
/* Try to read a dimensioning attribute (num variable) from the TREXIO file */
trexio_t* file = NULL;
trexio_exit_code rc;
// parameters to be read
int num;
/*================= START OF TEST ==================*/
// open file in 'write' mode
file = trexio_open(file_name, 'w', backend);
assert (file != NULL);
// read numerical attribute from the file
rc = trexio_read_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");
rc = system(RM_COMMAND);
assert (rc == 0);
test_write_num("test_write_num.dir", TREXIO_TEXT);
rc = system("rm -rf test_write_num.dir");
test_write_num (TREXIO_FILE, TEST_BACKEND);
test_has_num (TREXIO_FILE, TEST_BACKEND);
test_read_num (TREXIO_FILE, TEST_BACKEND);
rc = system(RM_COMMAND);
assert (rc == 0);
return 0;