1
0
mirror of https://github.com/TREX-CoE/trexio.git synced 2025-01-03 10:06:01 +01:00

add tests

This commit is contained in:
q-posev 2022-01-19 14:08:38 +01:00
parent 550c5c3954
commit e9db0c66d4
4 changed files with 56 additions and 6 deletions

View File

@ -40,6 +40,7 @@ except:
# create TREXIO file and open it for writing # create TREXIO file and open it for writing
test_file = trexio.File(output_filename, mode='w', back_end=TEST_TREXIO_BACKEND) test_file = trexio.File(output_filename, mode='w', back_end=TEST_TREXIO_BACKEND)
assert test_file.exists
# Print docstring of the trexio.open function # Print docstring of the trexio.open function
#print(trexio.open.__doc__) #print(trexio.open.__doc__)
@ -153,6 +154,7 @@ del test_file
# open previously created TREXIO file, now in 'read' mode # open previously created TREXIO file, now in 'read' mode
test_file2 = trexio.File(output_filename, 'r', TEST_TREXIO_BACKEND) test_file2 = trexio.File(output_filename, 'r', TEST_TREXIO_BACKEND)
assert test_file2.exists
# check for existence of some of the previously written variables # check for existence of some of the previously written variables
assert trexio.has_nucleus_num assert trexio.has_nucleus_num

View File

@ -85,7 +85,7 @@ static int test_open_errors (const back_end_t backend) {
fprintf(stderr, "%s \n", trexio_string_of_error(rc)); fprintf(stderr, "%s \n", trexio_string_of_error(rc));
// open existing file with non-supported back end, should return TREXIO_INVALID_ARG_3 // open existing file with non-supported back end, should return TREXIO_INVALID_ARG_3
file = trexio_open(TREXIO_VOID, 'w', 666, &rc); file = trexio_open(TREXIO_FILE, 'w', 666, &rc);
assert (file == NULL); assert (file == NULL);
assert (rc == TREXIO_INVALID_ARG_3); assert (rc == TREXIO_INVALID_ARG_3);
fprintf(stderr, "%s \n", trexio_string_of_error(rc)); fprintf(stderr, "%s \n", trexio_string_of_error(rc));
@ -96,6 +96,28 @@ static int test_open_errors (const back_end_t backend) {
} }
static int test_inquire (const back_end_t backend) {
/* Try to call trexio_inquire function */
trexio_exit_code rc;
/*================= START OF TEST ==================*/
// inquire non-existing file
rc = trexio_inquire(TREXIO_VOID);
assert (rc == TREXIO_FAILURE);
// inquire existing file
rc = trexio_inquire(TREXIO_FILE);
assert (rc == TREXIO_SUCCESS);
/*================= END OF TEST ==================*/
return 0;
}
int main(void) { int main(void) {
/*============== Test launcher ================*/ /*============== Test launcher ================*/
@ -107,11 +129,10 @@ int main(void) {
test_open_w (TREXIO_FILE, TEST_BACKEND); test_open_w (TREXIO_FILE, TEST_BACKEND);
test_open_r (TREXIO_FILE, TEST_BACKEND); test_open_r (TREXIO_FILE, TEST_BACKEND);
test_open_errors(TEST_BACKEND); test_open_errors(TEST_BACKEND);
test_inquire (TEST_BACKEND);
rc = system(RM_COMMAND); rc = system(RM_COMMAND);
assert (rc == 0); assert (rc == 0);
return 0; return 0;
} }

View File

@ -85,7 +85,7 @@ static int test_open_errors (const back_end_t backend) {
fprintf(stderr, "%s \n", trexio_string_of_error(rc)); fprintf(stderr, "%s \n", trexio_string_of_error(rc));
// open existing file with non-supported back end, should return TREXIO_INVALID_ARG_3 // open existing file with non-supported back end, should return TREXIO_INVALID_ARG_3
file = trexio_open(TREXIO_VOID, 'w', 666, &rc); file = trexio_open(TREXIO_FILE, 'w', 666, &rc);
assert (file == NULL); assert (file == NULL);
assert (rc == TREXIO_INVALID_ARG_3); assert (rc == TREXIO_INVALID_ARG_3);
fprintf(stderr, "%s \n", trexio_string_of_error(rc)); fprintf(stderr, "%s \n", trexio_string_of_error(rc));
@ -96,6 +96,28 @@ static int test_open_errors (const back_end_t backend) {
} }
static int test_inquire (const back_end_t backend) {
/* Try to call trexio_inquire function */
trexio_exit_code rc;
/*================= START OF TEST ==================*/
// inquire non-existing file
rc = trexio_inquire(TREXIO_VOID);
assert (rc == TREXIO_FAILURE);
// inquire existing file
rc = trexio_inquire(TREXIO_FILE);
assert (rc == TREXIO_SUCCESS);
/*================= END OF TEST ==================*/
return 0;
}
int main(void) { int main(void) {
/*============== Test launcher ================*/ /*============== Test launcher ================*/
@ -107,11 +129,10 @@ int main(void) {
test_open_w (TREXIO_FILE, TEST_BACKEND); test_open_w (TREXIO_FILE, TEST_BACKEND);
test_open_r (TREXIO_FILE, TEST_BACKEND); test_open_r (TREXIO_FILE, TEST_BACKEND);
test_open_errors(TEST_BACKEND); test_open_errors(TEST_BACKEND);
test_inquire (TEST_BACKEND);
rc = system(RM_COMMAND); rc = system(RM_COMMAND);
assert (rc == 0); assert (rc == 0);
return 0; return 0;
} }

View File

@ -103,6 +103,9 @@ subroutine test_write(file_name, back_end)
! ================= START OF TEST ===================== ! ! ================= START OF TEST ===================== !
rc = trexio_inquire(file_name)
call trexio_assert(rc, TREXIO_FAILURE)
trex_file = trexio_open(file_name, 'w', back_end, rc) trex_file = trexio_open(file_name, 'w', back_end, rc)
call trexio_assert(rc, TREXIO_SUCCESS) call trexio_assert(rc, TREXIO_SUCCESS)
@ -217,6 +220,9 @@ subroutine test_read(file_name, back_end)
! ================= START OF TEST ===================== ! ! ================= START OF TEST ===================== !
rc = trexio_inquire(file_name)
call trexio_assert(rc, TREXIO_SUCCESS)
trex_file = trexio_open(file_name, 'r', back_end, rc) trex_file = trexio_open(file_name, 'r', back_end, rc)
call trexio_assert(rc, TREXIO_SUCCESS) call trexio_assert(rc, TREXIO_SUCCESS)