diff options
author | Christian C <cc@localhost> | 2025-03-08 00:28:15 -0800 |
---|---|---|
committer | Christian C <cc@localhost> | 2025-03-08 00:28:15 -0800 |
commit | 140754bc0f265696b4d76e674bf580cfb544d897 (patch) | |
tree | 602088151f40de018f0d919cb1f2147f3d1a88ce /test/lib/dir.c | |
parent | 9be81ef43c8cfabe72fba16651dbfe62ed0f1123 (diff) |
Lib/Dir testing
Diffstat (limited to 'test/lib/dir.c')
-rw-r--r-- | test/lib/dir.c | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/test/lib/dir.c b/test/lib/dir.c new file mode 100644 index 0000000..975b05e --- /dev/null +++ b/test/lib/dir.c @@ -0,0 +1,87 @@ +#include <test/lib/dir.h> +#include <string.h> +#include <stdio.h> +#include <stdlib.h> + +bool_t test_is_directory(char* dirname, bool_t result) +{ + bool_t fcall_result = is_directory(dirname); + if (fcall_result == result) { + return TRUE; + } + return FALSE; +} + +void _TEST_is_directory(bool_t* result, uint16_t* test_count, uint16_t* test_pass) +{ + bool_t sub_result; + sub_result = test_is_directory("sample_data", TRUE); + *result &= sub_result; + TEST_RESULT("IS_DIRECTORY",sub_result, *test_count, (*test_pass)); + + sub_result = test_is_directory("asdf", FALSE); + *result &= sub_result; + TEST_RESULT("IS_DIRECTORY",sub_result, *test_count, (*test_pass)); +} + +bool_t test_full_path(char* dirname, char* file, char* result) +{ + char* fpath = full_path(dirname, file); + bool_t cmp_result = strcmp(result, fpath); + free(fpath); + if (cmp_result == 0) { + return TRUE; + } + return FALSE; +} + +void _TEST_full_path(bool_t* result, uint16_t* test_count, uint16_t* test_pass) +{ + bool_t sub_result; + sub_result = test_full_path("sample_data/small", "small.tif", "sample_data/small/small.tif"); + *result &= sub_result; + TEST_RESULT("FULL_PATH",sub_result, *test_count, (*test_pass)); +} + +bool_t test_is_tif_ext(char* file_name, bool_t result) +{ + size_t file_name_len = strlen(file_name); + file_name_len -= 3; + bool_t cmp_result = strcmp(file_name+file_name_len, "tif"); + if (cmp_result == 0) { + return TRUE == result; + } + return FALSE == result; +} + +void _TEST_is_tif_ext(bool_t* result, uint16_t* test_count, uint16_t* test_pass) +{ + bool_t sub_result; + sub_result = test_is_tif_ext("sample_data/small/small.tif", TRUE); + *result &= sub_result; + TEST_RESULT("IS_TIF_EXT",sub_result, *test_count, (*test_pass)); + sub_result = test_is_tif_ext("data/test.tif", TRUE); + *result &= sub_result; + TEST_RESULT("IS_TIF_EXT",sub_result, *test_count, (*test_pass)); + sub_result = test_is_tif_ext("sample_data/small/small", FALSE); + *result &= sub_result; + TEST_RESULT("IS_TIF_EXT",sub_result, *test_count, (*test_pass)); +} + +bool_t TEST_lib_dir() +{ + uint16_t test_count = 0; + uint16_t test_pass = 0; + bool_t result = TRUE; + + // Testing directory existence + _TEST_is_directory(&result, &test_count, &test_pass); + + // Testing full path + _TEST_full_path(&result, &test_count, &test_pass); + + // Testing full path + _TEST_is_tif_ext(&result, &test_count, &test_pass); + + return test_count == test_pass; +} |