From 140754bc0f265696b4d76e674bf580cfb544d897 Mon Sep 17 00:00:00 2001
From: Christian C <cc@localhost>
Date: Sat, 8 Mar 2025 00:28:15 -0800
Subject: Lib/Dir testing

---
 Makefile                |  2 +-
 include/test/__meta__.h |  4 +--
 include/test/lib/dir.h  | 18 ++++++++++
 src/test/test.c         |  6 ++++
 test/lib/color.c        | 75 +++++++++++++++++++++++++++---------------
 test/lib/dir.c          | 87 +++++++++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 163 insertions(+), 29 deletions(-)
 create mode 100644 include/test/lib/dir.h
 create mode 100644 test/lib/dir.c

diff --git a/Makefile b/Makefile
index 8bc7d4b..01e8fb4 100644
--- a/Makefile
+++ b/Makefile
@@ -55,7 +55,7 @@ endif
 
 # Suppress Test Passings
 ifdef TEST_SHOW_PASS
-$(info Hiding test pass results)
+$(info Showing test pass results)
 DEFINES+=-DTEST_SHOW_PASS
 endif
 
diff --git a/include/test/__meta__.h b/include/test/__meta__.h
index b4cc360..436e305 100644
--- a/include/test/__meta__.h
+++ b/include/test/__meta__.h
@@ -5,12 +5,12 @@
 #include <stdio.h>
 
 #ifdef TEST_SHOW_PASS
-#define _TEST_PASS(s,sub,n) fprintf(stderr, "%s/%s/%02X: \x1b[92mPASS\x1b[0m\n", s, sub, ++n)
+#define _TEST_PASS(s,sub,n) fprintf(stderr, "(%04X) \x1b[92mPASS\x1b[0m %s/%s\n", ++n, s, sub)
 #else
 #define _TEST_PASS(s,sub,n) ++n
 #endif
 
-#define _TEST_FAIL(s,sub,n) fprintf(stderr, "%s%s/%02X: \x1b[91mFAIL\x1b[0m\n", s, sub, ++n)
+#define _TEST_FAIL(s,sub,n) fprintf(stderr, "(%04X) \x1b[91mFAIL\x1b[0m %s/%s\n", ++n, s, sub)
 
 #ifndef _TEST_RESULT
 #define _TEST_RESULT(main_string,subtest_string,result,n,n_success) if (!result) {_TEST_FAIL(main_string,subtest_string, n);} else {_TEST_PASS(main_string,subtest_string,n);n_success++;}
diff --git a/include/test/lib/dir.h b/include/test/lib/dir.h
new file mode 100644
index 0000000..64482df
--- /dev/null
+++ b/include/test/lib/dir.h
@@ -0,0 +1,18 @@
+#ifndef INC_TEST_LIB_DIR_H
+#define INC_TEST_LIB_DIR_H
+
+#include <test/__meta__.h>
+#ifndef TEST_RESULT
+#define TEST_RESULT(subtest,result,n,n_success) _TEST_RESULT("LIB/DIR",subtest,result,n,n_success)
+#endif
+
+#include <lib/dir.h>
+
+bool_t test_is_directory(char* dirname, bool_t result);
+bool_t test_full_path(char* dirname, char* file, char* result);
+bool_t test_is_tif_ext(char* file_name, bool_t result);
+
+// Meta test function
+bool_t TEST_lib_dir();
+
+#endif
diff --git a/src/test/test.c b/src/test/test.c
index 2f42e17..5c30c98 100644
--- a/src/test/test.c
+++ b/src/test/test.c
@@ -1,4 +1,5 @@
 #include <test/lib/color.h>
+#include <test/lib/dir.h>
 
 #define _META_TEST_RESULT(name,result) if (result) { fprintf(stderr, "%s: \x1b[92mPASS\x1b[0m\n", name);} else { fprintf(stderr, "%s: \x1b[91mFAIL\x1b[0m\n", name);}
 
@@ -11,6 +12,11 @@ int main()
   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)
+
   if (all_success == TRUE) {
     return 0;
   }
diff --git a/test/lib/color.c b/test/lib/color.c
index 2b2ed68..7b2a238 100644
--- a/test/lib/color.c
+++ b/test/lib/color.c
@@ -15,51 +15,61 @@ bool_t test_color_zero(const uint8_t* color1, size_t channels, bool_t result)
   return FALSE;
 }
 
-void _TEST_color_zero(bool_t* result, uint8_t* test_count, uint8_t* test_pass)
+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
-  *result = test_color_zero(test_rgba, 1, TRUE);
+  sub_result = test_color_zero(test_rgba, 1, TRUE);
+  *result &= sub_result;
   TEST_RESULT("COLOR_ZERO",*result, *test_count, (*test_pass));
 
   // Test 2: 1 channel non-zero color
   //  Should result: False
-  *result = test_color_zero(test_Rgba, 1, FALSE);
+  sub_result = test_color_zero(test_Rgba, 1, FALSE);
+  *result &= sub_result;
   TEST_RESULT("COLOR_ZERO",*result, *test_count, (*test_pass));
 
   // Test 3: 2 channel zero color
   //  Should result: True
-  *result = test_color_zero(test_rgba, 2, TRUE);
+  sub_result = test_color_zero(test_rgba, 2, TRUE);
+  *result &= sub_result;
   TEST_RESULT("COLOR_ZERO",*result, *test_count, (*test_pass));
 
   // Test 4: 2 channel non-zero color
   //  Should result: False
-  *result = test_color_zero(test_rGba, 2, FALSE);
+  sub_result = test_color_zero(test_rGba, 2, FALSE);
+  *result &= sub_result;
   TEST_RESULT("COLOR_ZERO",*result, *test_count, (*test_pass));
 
   // Test 5: 3 channel zero color
   //  Should result: True
-  *result = test_color_zero(test_rgba, 3, TRUE);
+  sub_result = test_color_zero(test_rgba, 3, TRUE);
+  *result &= sub_result;
   TEST_RESULT("COLOR_ZERO",*result, *test_count, (*test_pass));
 
   // Test 6: 3 channel non-zero color
   //  Should result: False
-  *result = test_color_zero(test_rgBa, 3, FALSE);
+  sub_result = test_color_zero(test_rgBa, 3, FALSE);
+  *result &= sub_result;
   TEST_RESULT("COLOR_ZERO",*result, *test_count, (*test_pass));
 
   // Test 7: 4 channel zero color
   //  Should result: True
-  *result = test_color_zero(test_rgba, 4, TRUE);
+  sub_result = test_color_zero(test_rgba, 4, TRUE);
+  *result &= sub_result;
   TEST_RESULT("COLOR_ZERO",*result, *test_count, (*test_pass));
 
   // Test 8: 4 channel non-zero color
   //  Should result: False
-  *result = test_color_zero(test_rgBa, 4, FALSE);
+  sub_result = test_color_zero(test_rgBa, 4, FALSE);
+  *result &= sub_result;
   TEST_RESULT("COLOR_ZERO",*result, *test_count, (*test_pass));
 
   // Test 9: 4 channel non-zero color (Alpha non-zero)
   //  Should result: True
-  *result = test_color_zero(test_rgbA, 4, TRUE);
+  sub_result = test_color_zero(test_rgbA, 4, TRUE);
+  *result &= sub_result;
   TEST_RESULT("COLOR_ZERO",*result, *test_count, (*test_pass));
 }
 
@@ -72,75 +82,88 @@ bool_t test_color_equal(const uint8_t* color1, const uint8_t* color2, size_t cha
   return FALSE;
 }
 
-void _TEST_color_equal(bool_t* result, uint8_t* test_count, uint8_t* test_pass)
+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
-  *result = test_color_equal(test_rgba, test_rgba, 1, TRUE);
+  sub_result = test_color_equal(test_rgba, test_rgba, 1, TRUE);
+  *result &= sub_result;
   TEST_RESULT("COLOR_EQUAL",*result, *test_count, (*test_pass));
 
   // Test 2: 1 channel equal (nonzero)
   //  Should result: True
-  *result = test_color_equal(test_Rgba, test_Rgba, 1, TRUE);
+  sub_result = test_color_equal(test_Rgba, test_Rgba, 1, TRUE);
+  *result &= sub_result;
   TEST_RESULT("COLOR_EQUAL",*result, *test_count, (*test_pass));
 
   // Test 3: 1 channel nonequal
   //  Should result: True
-  *result = test_color_equal(test_rgba, test_Rgba, 1, FALSE);
+  sub_result = test_color_equal(test_rgba, test_Rgba, 1, FALSE);
+  *result &= sub_result;
   TEST_RESULT("COLOR_EQUAL",*result, *test_count, (*test_pass));
 
   // Test 4: 2 channel equal (zero)
   //  Should result: True
-  *result = test_color_equal(test_rgba, test_rgba, 2, TRUE);
+  sub_result = test_color_equal(test_rgba, test_rgba, 2, TRUE);
+  *result &= sub_result;
   TEST_RESULT("COLOR_EQUAL",*result, *test_count, (*test_pass));
 
   // Test 5: 2 channel equal (nonzero)
   //  Should result: True
-  *result = test_color_equal(test_rGba, test_rGba, 2, TRUE);
+  sub_result = test_color_equal(test_rGba, test_rGba, 2, TRUE);
+  *result &= sub_result;
   TEST_RESULT("COLOR_EQUAL",*result, *test_count, (*test_pass));
 
   // Test 6: 2 channel nonequal
   //  Should result: False
-  *result = test_color_equal(test_Rgba, test_rGba, 2, FALSE);
+  sub_result = test_color_equal(test_Rgba, test_rGba, 2, FALSE);
+  *result &= sub_result;
   TEST_RESULT("COLOR_EQUAL",*result, *test_count, (*test_pass));
 
   // Test 7: 3 channel equal (zero)
   //  Should result: True
-  *result = test_color_equal(test_rgba, test_rgba, 3, TRUE);
+  sub_result = test_color_equal(test_rgba, test_rgba, 3, TRUE);
+  *result &= sub_result;
   TEST_RESULT("COLOR_EQUAL",*result, *test_count, (*test_pass));
 
   // Test 8: 3 channel equal (nonzero)
   //  Should result: True
-  *result = test_color_equal(test_rgBa, test_rgBa, 3, TRUE);
+  sub_result = test_color_equal(test_rgBa, test_rgBa, 3, TRUE);
+  *result &= sub_result;
   TEST_RESULT("COLOR_EQUAL",*result, *test_count, (*test_pass));
 
   // Test 9: 3 channel nonequal
   //  Should result: False
-  *result = test_color_equal(test_Rgba, test_rgBa, 3, FALSE);
+  sub_result = test_color_equal(test_Rgba, test_rgBa, 3, FALSE);
+  *result &= sub_result;
   TEST_RESULT("COLOR_EQUAL",*result, *test_count, (*test_pass));
 
   // Test 7: 4 channel equal (zero)
   //  Should result: True
-  *result = test_color_equal(test_rgba, test_rgba, 4, TRUE);
+  sub_result = test_color_equal(test_rgba, test_rgba, 4, TRUE);
+  *result &= sub_result;
   TEST_RESULT("COLOR_EQUAL",*result, *test_count, (*test_pass));
 
   // Test 8: 4 channel equal (nonzero)
   //  Should result: True
-  *result = test_color_equal(test_rgbA, test_rgbA, 4, TRUE);
+  sub_result = test_color_equal(test_rgbA, test_rgbA, 4, TRUE);
+  *result &= sub_result;
   TEST_RESULT("COLOR_EQUAL",*result, *test_count, (*test_pass));
 
   // Test 9: 4 channel nonequal
   //  Should result: False
-  *result = test_color_equal(test_Rgba, test_rgbA, 4, FALSE);
+  sub_result = test_color_equal(test_Rgba, test_rgbA, 4, FALSE);
+  *result &= sub_result;
   TEST_RESULT("COLOR_EQUAL",*result, *test_count, (*test_pass));
 }
 
 // Meta test function
 bool_t TEST_lib_color()
 {
-  uint8_t test_count = 0;
-  uint8_t test_pass = 0;
-  bool_t result;
+  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);
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;
+}
-- 
cgit v1.2.1