aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian C <cc@localhost>2025-03-07 23:48:17 -0800
committerChristian C <cc@localhost>2025-03-07 23:48:17 -0800
commit9be81ef43c8cfabe72fba16651dbfe62ed0f1123 (patch)
treee767747b5fd49b3bb2c2693328844b5ea0368b52
parentafad16ce636dd54fa1fdedd100eb93f1d7b508d6 (diff)
Testing suite
-rw-r--r--Makefile6
-rw-r--r--include/lib/color.h4
-rw-r--r--include/test/__meta__.h11
-rw-r--r--include/test/lib/color.h6
-rw-r--r--lib/color.c4
-rw-r--r--src/test/test.c7
-rw-r--r--test/lib/color.c148
7 files changed, 151 insertions, 35 deletions
diff --git a/Makefile b/Makefile
index e535feb..8bc7d4b 100644
--- a/Makefile
+++ b/Makefile
@@ -53,6 +53,12 @@ $(info Including AVL Dump)
DEFINES+=-DAVL_INFO
endif
+# Suppress Test Passings
+ifdef TEST_SHOW_PASS
+$(info Hiding test pass results)
+DEFINES+=-DTEST_SHOW_PASS
+endif
+
ifeq ($(shell uname -s),Linux)
PKGCONF=pkgconf
endif
diff --git a/include/lib/color.h b/include/lib/color.h
index 5e7128b..1bc9393 100644
--- a/include/lib/color.h
+++ b/include/lib/color.h
@@ -7,11 +7,11 @@
// Color Equal to Background
// Background: zeros in RGB, alpha can be whatever
-bool_t color_zero(uint8_t* color1, size_t channels);
+bool_t color_zero(const uint8_t* color1, size_t channels);
// Color Equality
// Determine if two colors are identical
-bool_t color_equal(uint8_t* color1, uint8_t* color2, size_t channels);
+bool_t color_equal(const uint8_t* color1, const uint8_t* color2, size_t channels);
// Print out the `channels` length color vector
void print_color(uint8_t* color, size_t channels);
diff --git a/include/test/__meta__.h b/include/test/__meta__.h
index 05a202f..b4cc360 100644
--- a/include/test/__meta__.h
+++ b/include/test/__meta__.h
@@ -4,11 +4,16 @@
#include <lib/bool.h>
#include <stdio.h>
-#define _TEST_PASS(s,n) fprintf(stderr, "%s/%02X: \x1b[92mPASS\x1b[0m\n", s, ++n)
-#define _TEST_FAIL(s,n) fprintf(stderr, "%s/%02X: \x1b[91mFAIL\x1b[0m\n", s, ++n)
+#ifdef TEST_SHOW_PASS
+#define _TEST_PASS(s,sub,n) fprintf(stderr, "%s/%s/%02X: \x1b[92mPASS\x1b[0m\n", s, sub, ++n)
+#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)
#ifndef _TEST_RESULT
-#define _TEST_RESULT(docstring,result,n,n_success) if (!result) {_TEST_FAIL(docstring, n);} else {_TEST_PASS(docstring,n);n_success++;}
+#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++;}
#endif
#endif
diff --git a/include/test/lib/color.h b/include/test/lib/color.h
index 835cb0a..be0d62f 100644
--- a/include/test/lib/color.h
+++ b/include/test/lib/color.h
@@ -3,13 +3,13 @@
#include <test/__meta__.h>
#ifndef TEST_RESULT
-#define TEST_RESULT(result,n,n_success) _TEST_RESULT("LIB/COLOR",result,n,n_success)
+#define TEST_RESULT(subtest,result,n,n_success) _TEST_RESULT("LIB/COLOR",subtest,result,n,n_success)
#endif
#include <lib/color.h>
-bool_t test_color_zero(uint8_t* color1, size_t channels, bool_t result);
-bool_t test_color_equal(uint8_t* color1, uint8_t* color2, size_t channels, bool_t result);
+bool_t test_color_zero(const uint8_t* color1, size_t channels, bool_t result);
+bool_t test_color_equal(const uint8_t* color1, const uint8_t* color2, size_t channels, bool_t result);
// Meta test function
bool_t TEST_lib_color();
diff --git a/lib/color.c b/lib/color.c
index 902a93d..a0a50fd 100644
--- a/lib/color.c
+++ b/lib/color.c
@@ -4,7 +4,7 @@
// Color Equal to Background
// Background: zeros in RGB, alpha can be whatever
-bool_t color_zero(uint8_t* color1, size_t channels) {
+bool_t color_zero(const uint8_t* color1, size_t channels) {
for (size_t idx = 0; idx < channels; idx++) {
if (idx == 3) {
break;
@@ -18,7 +18,7 @@ bool_t color_zero(uint8_t* color1, size_t channels) {
// Color Equality
// Determine if two colors are identical
-bool_t color_equal(uint8_t* color1, uint8_t* color2, size_t channels) {
+bool_t color_equal(const uint8_t* color1, const uint8_t* color2, size_t channels) {
for (size_t idx = 0; idx < channels; idx++) {
if (color1[idx] != color2[idx]) {
return FALSE;
diff --git a/src/test/test.c b/src/test/test.c
index 95b4154..2f42e17 100644
--- a/src/test/test.c
+++ b/src/test/test.c
@@ -1,10 +1,15 @@
#include <test/lib/color.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);}
+
int main()
{
bool_t all_success = TRUE;
+ bool_t test_success;
// lib/color.c Test
- all_success &= TEST_lib_color();
+ test_success = TEST_lib_color();
+ all_success &= test_success;
+ _META_TEST_RESULT("LIB/COLOR", test_success)
if (all_success == TRUE) {
return 0;
diff --git a/test/lib/color.c b/test/lib/color.c
index 191972d..2b2ed68 100644
--- a/test/lib/color.c
+++ b/test/lib/color.c
@@ -1,6 +1,12 @@
#include <test/lib/color.h>
-bool_t test_color_zero(uint8_t* color1, size_t channels, bool_t result)
+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) {
@@ -8,45 +14,139 @@ bool_t test_color_zero(uint8_t* color1, size_t channels, bool_t result)
}
return FALSE;
}
-bool_t test_color_equal(uint8_t* color1, uint8_t* color2, size_t channels, bool_t result)
+
+void _TEST_color_zero(bool_t* result, uint8_t* test_count, uint8_t* test_pass)
{
- bool_t fcall_result = color_zero(color1, channels);
+ // Test 1: 1 channel zero color
+ // Should result: True
+ *result = test_color_zero(test_rgba, 1, TRUE);
+ 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);
+ 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);
+ 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);
+ 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);
+ 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);
+ 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);
+ 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);
+ 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);
+ TEST_RESULT("COLOR_ZERO",*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;
}
-// Meta test function
-bool_t TEST_lib_color()
+void _TEST_color_equal(bool_t* result, uint8_t* test_count, uint8_t* test_pass)
{
- uint8_t test_count = 0;
- uint8_t test_pass = 0;
- bool_t result;
+ // Test 1: 1 channel equal (zero)
+ // Should result: True
+ *result = test_color_equal(test_rgba, test_rgba, 1, TRUE);
+ TEST_RESULT("COLOR_EQUAL",*result, *test_count, (*test_pass));
- // Test 1: 1 channel zero color
+ // Test 2: 1 channel equal (nonzero)
// Should result: True
- uint8_t test_1_color1[1] = {0};
- result = test_color_zero(test_1_color1, 1, TRUE);
- TEST_RESULT(result, test_count, test_pass);
+ *result = test_color_equal(test_Rgba, test_Rgba, 1, TRUE);
+ TEST_RESULT("COLOR_EQUAL",*result, *test_count, (*test_pass));
- // Test 2: 1 channel non-zero color
+ // Test 3: 1 channel nonequal
+ // Should result: True
+ *result = test_color_equal(test_rgba, test_Rgba, 1, FALSE);
+ 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);
+ 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);
+ TEST_RESULT("COLOR_EQUAL",*result, *test_count, (*test_pass));
+
+ // Test 6: 2 channel nonequal
// Should result: False
- uint8_t test_2_color1[1] = {1};
- result = test_color_zero(test_2_color1, 1, FALSE);
- TEST_RESULT(result, test_count, test_pass);
+ *result = test_color_equal(test_Rgba, test_rGba, 2, FALSE);
+ TEST_RESULT("COLOR_EQUAL",*result, *test_count, (*test_pass));
- // Test 3: 2 channel zero color
+ // Test 7: 3 channel equal (zero)
// Should result: True
- uint8_t test_3_color1[2] = {0,0};
- result = test_color_zero(test_3_color1, 2, TRUE);
- TEST_RESULT(result, test_count, test_pass);
+ *result = test_color_equal(test_rgba, test_rgba, 3, TRUE);
+ TEST_RESULT("COLOR_EQUAL",*result, *test_count, (*test_pass));
- // Test 4: 2 channel non-zero color
+ // Test 8: 3 channel equal (nonzero)
+ // Should result: True
+ *result = test_color_equal(test_rgBa, test_rgBa, 3, TRUE);
+ 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);
+ 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);
+ 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);
+ TEST_RESULT("COLOR_EQUAL",*result, *test_count, (*test_pass));
+
+ // Test 9: 4 channel nonequal
// Should result: False
- uint8_t test_4_color1[2] = {0,1};
- result = test_color_zero(test_4_color1, 2, FALSE);
- TEST_RESULT(result, test_count, test_pass);
+ *result = test_color_equal(test_Rgba, test_rgbA, 4, FALSE);
+ 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;
+
+ // 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;
}