diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/lib/color.c | 175 | ||||
-rw-r--r-- | test/lib/dir.c | 95 | ||||
-rw-r--r-- | test/lib/time.c | 61 | ||||
-rw-r--r-- | test/test.c | 30 |
4 files changed, 361 insertions, 0 deletions
diff --git a/test/lib/color.c b/test/lib/color.c new file mode 100644 index 0000000..69ce97b --- /dev/null +++ b/test/lib/color.c @@ -0,0 +1,175 @@ +#include <test/lib/color.h> + +const uint8_t test_rgba[4] = {0,0,0,0}; +const uint8_t test_Rgba[4] = {1,0,0,0}; +const uint8_t test_rGba[4] = {0,1,0,0}; +const uint8_t test_rgBa[4] = {0,0,1,0}; +const uint8_t test_rgbA[4] = {0,0,0,1}; + +bool_t test_color_zero(const uint8_t* color1, size_t channels, bool_t result) +{ + bool_t fcall_result = color_zero(color1, channels); + if (fcall_result == result) { + return TRUE; + } + return FALSE; +} + +void _TEST_color_zero(bool_t* result, uint16_t* test_count, uint16_t* test_pass) +{ + bool_t sub_result; + // Test 1: 1 channel zero color + // Should result: True + sub_result = test_color_zero(test_rgba, 1, TRUE); + *result &= sub_result; + TEST_RESULT("COLOR_ZERO",sub_result, *test_count, (*test_pass)); + + // Test 2: 1 channel non-zero color + // Should result: False + sub_result = test_color_zero(test_Rgba, 1, FALSE); + *result &= sub_result; + TEST_RESULT("COLOR_ZERO",sub_result, *test_count, (*test_pass)); + + // Test 3: 2 channel zero color + // Should result: True + sub_result = test_color_zero(test_rgba, 2, TRUE); + *result &= sub_result; + TEST_RESULT("COLOR_ZERO",sub_result, *test_count, (*test_pass)); + + // Test 4: 2 channel non-zero color + // Should result: False + sub_result = test_color_zero(test_rGba, 2, FALSE); + *result &= sub_result; + TEST_RESULT("COLOR_ZERO",sub_result, *test_count, (*test_pass)); + + // Test 5: 3 channel zero color + // Should result: True + sub_result = test_color_zero(test_rgba, 3, TRUE); + *result &= sub_result; + TEST_RESULT("COLOR_ZERO",sub_result, *test_count, (*test_pass)); + + // Test 6: 3 channel non-zero color + // Should result: False + sub_result = test_color_zero(test_rgBa, 3, FALSE); + *result &= sub_result; + TEST_RESULT("COLOR_ZERO",sub_result, *test_count, (*test_pass)); + + // Test 7: 4 channel zero color + // Should result: True + sub_result = test_color_zero(test_rgba, 4, TRUE); + *result &= sub_result; + TEST_RESULT("COLOR_ZERO",sub_result, *test_count, (*test_pass)); + + // Test 8: 4 channel non-zero color + // Should result: False + sub_result = test_color_zero(test_rgBa, 4, FALSE); + *result &= sub_result; + TEST_RESULT("COLOR_ZERO",sub_result, *test_count, (*test_pass)); + + // Test 9: 4 channel non-zero color (Alpha non-zero) + // Should result: True + sub_result = test_color_zero(test_rgbA, 4, TRUE); + *result &= sub_result; + TEST_RESULT("COLOR_ZERO",sub_result, *test_count, (*test_pass)); +} + +bool_t test_color_equal(const uint8_t* color1, const uint8_t* color2, size_t channels, bool_t result) +{ + bool_t fcall_result = color_equal(color1, color2, channels); + if (fcall_result == result) { + return TRUE; + } + return FALSE; +} + +void _TEST_color_equal(bool_t* result, uint16_t* test_count, uint16_t* test_pass) +{ + bool_t sub_result; + // Test 1: 1 channel equal (zero) + // Should result: True + sub_result = test_color_equal(test_rgba, test_rgba, 1, TRUE); + *result &= sub_result; + TEST_RESULT("COLOR_EQUAL",sub_result, *test_count, (*test_pass)); + + // Test 2: 1 channel equal (nonzero) + // Should result: True + sub_result = test_color_equal(test_Rgba, test_Rgba, 1, TRUE); + *result &= sub_result; + TEST_RESULT("COLOR_EQUAL",sub_result, *test_count, (*test_pass)); + + // Test 3: 1 channel nonequal + // Should result: True + sub_result = test_color_equal(test_rgba, test_Rgba, 1, FALSE); + *result &= sub_result; + TEST_RESULT("COLOR_EQUAL",sub_result, *test_count, (*test_pass)); + + // Test 4: 2 channel equal (zero) + // Should result: True + sub_result = test_color_equal(test_rgba, test_rgba, 2, TRUE); + *result &= sub_result; + TEST_RESULT("COLOR_EQUAL",sub_result, *test_count, (*test_pass)); + + // Test 5: 2 channel equal (nonzero) + // Should result: True + sub_result = test_color_equal(test_rGba, test_rGba, 2, TRUE); + *result &= sub_result; + TEST_RESULT("COLOR_EQUAL",sub_result, *test_count, (*test_pass)); + + // Test 6: 2 channel nonequal + // Should result: False + sub_result = test_color_equal(test_Rgba, test_rGba, 2, FALSE); + *result &= sub_result; + TEST_RESULT("COLOR_EQUAL",sub_result, *test_count, (*test_pass)); + + // Test 7: 3 channel equal (zero) + // Should result: True + sub_result = test_color_equal(test_rgba, test_rgba, 3, TRUE); + *result &= sub_result; + TEST_RESULT("COLOR_EQUAL",sub_result, *test_count, (*test_pass)); + + // Test 8: 3 channel equal (nonzero) + // Should result: True + sub_result = test_color_equal(test_rgBa, test_rgBa, 3, TRUE); + *result &= sub_result; + TEST_RESULT("COLOR_EQUAL",sub_result, *test_count, (*test_pass)); + + // Test 9: 3 channel nonequal + // Should result: False + sub_result = test_color_equal(test_Rgba, test_rgBa, 3, FALSE); + *result &= sub_result; + TEST_RESULT("COLOR_EQUAL",sub_result, *test_count, (*test_pass)); + + // Test 7: 4 channel equal (zero) + // Should result: True + sub_result = test_color_equal(test_rgba, test_rgba, 4, TRUE); + *result &= sub_result; + TEST_RESULT("COLOR_EQUAL",sub_result, *test_count, (*test_pass)); + + // Test 8: 4 channel equal (nonzero) + // Should result: True + sub_result = test_color_equal(test_rgbA, test_rgbA, 4, TRUE); + *result &= sub_result; + TEST_RESULT("COLOR_EQUAL",sub_result, *test_count, (*test_pass)); + + // Test 9: 4 channel nonequal + // Should result: False + sub_result = test_color_equal(test_Rgba, test_rgbA, 4, FALSE); + *result &= sub_result; + TEST_RESULT("COLOR_EQUAL",sub_result, *test_count, (*test_pass)); +} + +// Meta test function +bool_t TEST_lib_color() +{ + uint16_t test_count = 0; + uint16_t test_pass = 0; + bool_t result = TRUE; + + // Testing color_zero + _TEST_color_zero(&result, &test_count, &test_pass); + + // Testing color_equal + _TEST_color_equal(&result, &test_count, &test_pass); + + return test_count == test_pass; +} diff --git a/test/lib/dir.c b/test/lib/dir.c new file mode 100644 index 0000000..66ce672 --- /dev/null +++ b/test/lib/dir.c @@ -0,0 +1,95 @@ +#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; + // Test 1: sample_data/ (TRUE) [On clean git folder] + sub_result = test_is_directory("sample_data", TRUE); + *result &= sub_result; + TEST_RESULT("IS_DIRECTORY",sub_result, *test_count, (*test_pass)); + + // Test 2: asdf/ (FALSE) [On clean git folder] + 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; + // Test 1: sample_data/small + small.tif = sample_data/small/small.tif + 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; + // Test 1: sample_data/small/small.tif (TRUE) + 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)); + + // Test 2: data/test.tif (TRUE) + sub_result = test_is_tif_ext("data/test.tif", TRUE); + *result &= sub_result; + TEST_RESULT("IS_TIF_EXT",sub_result, *test_count, (*test_pass)); + + // Test 3: sample_data/small/small (FALSE) + 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; +} diff --git a/test/lib/time.c b/test/lib/time.c new file mode 100644 index 0000000..5c29bbc --- /dev/null +++ b/test/lib/time.c @@ -0,0 +1,61 @@ +#include <test/lib/time.h> + +const struct timespec zero = {0,0}; +const struct timespec one_s = {1,0}; +const struct timespec one_ns = {0,1}; +const struct timespec one_s_ns = {1,1}; + +bool_t test_diff_time(const struct timespec *time1, const struct timespec *time0, double result) +{ + double fcall_result = diff_time(time1, time0); + if (fcall_result == result) { + return TRUE; + } + return FALSE; +} + +void _TEST_diff_time(bool_t* result, uint16_t* test_count, uint16_t* test_pass) +{ + bool_t sub_result; + // Test 1: 0-0=0 + sub_result = test_diff_time(&zero, &zero, 0.0); + *result &= sub_result; + TEST_RESULT("DIFF_TIME",sub_result, *test_count, (*test_pass)); + + // Test 2: 1s-0=1s + sub_result = test_diff_time(&one_s, &zero, 1.0); + *result &= sub_result; + TEST_RESULT("DIFF_TIME",sub_result, *test_count, (*test_pass)); + + // Test 3: 1ns-0=1ns + sub_result = test_diff_time(&one_ns, &zero, 0.000000001); + *result &= sub_result; + TEST_RESULT("DIFF_TIME",sub_result, *test_count, (*test_pass)); + + // Test 4: 1s1ns-0=1s1ns + sub_result = test_diff_time(&one_s_ns, &zero, 1.000000001); + *result &= sub_result; + TEST_RESULT("DIFF_TIME",sub_result, *test_count, (*test_pass)); + + // Test 5: 1s1ns-1ns=1s + sub_result = test_diff_time(&one_s_ns, &one_ns, 1.0); + *result &= sub_result; + TEST_RESULT("DIFF_TIME",sub_result, *test_count, (*test_pass)); + + // Test 6: 1s1ns-1s=1ns + sub_result = test_diff_time(&one_s_ns, &one_s, 0.000000001); + *result &= sub_result; + TEST_RESULT("DIFF_TIME",sub_result, *test_count, (*test_pass)); +} + +bool_t TEST_lib_time() +{ + uint16_t test_count = 0; + uint16_t test_pass = 0; + bool_t result = TRUE; + + // Testing directory existence + _TEST_diff_time(&result, &test_count, &test_pass); + + return test_count == test_pass; +} diff --git a/test/test.c b/test/test.c new file mode 100644 index 0000000..40e2d6f --- /dev/null +++ b/test/test.c @@ -0,0 +1,30 @@ +#include <test/lib/color.h> +#include <test/lib/dir.h> +#include <test/lib/time.h> + +#define _META_TEST_RESULT(name,result) if (result) { fprintf(stderr, " \x1b[92mPASS\x1b[0m %s\n", name);} else { fprintf(stderr, "%s: \x1b[91mFAIL\x1b[0m\n", name);} + +int main() +{ + bool_t all_success = TRUE; + bool_t test_success; + // lib/color.c Test + test_success = TEST_lib_color(); + all_success &= test_success; + _META_TEST_RESULT("LIB/COLOR", test_success) + + // lib/dir.c Test + test_success = TEST_lib_dir(); + all_success &= test_success; + _META_TEST_RESULT("LIB/DIR", test_success) + + // lib/time.c Test + test_success = TEST_lib_time(); + all_success &= test_success; + _META_TEST_RESULT("LIB/TIME", test_success) + + if (all_success == TRUE) { + return 0; + } + return 1; +} |