aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian C <cc@localhost>2025-03-07 23:05:12 -0800
committerChristian C <cc@localhost>2025-03-07 23:05:12 -0800
commitafad16ce636dd54fa1fdedd100eb93f1d7b508d6 (patch)
tree075739eb47cf62fd59ea92e988d0d7d033eef771
parentfb290d22289f9c29eef504a538f7a293844a624d (diff)
Test suite start
-rw-r--r--Makefile17
-rw-r--r--include/test/__meta__.h14
-rw-r--r--include/test/lib/color.h17
-rw-r--r--src/test/test.c13
-rw-r--r--test/lib/color.c52
5 files changed, 111 insertions, 2 deletions
diff --git a/Makefile b/Makefile
index d25d150..e535feb 100644
--- a/Makefile
+++ b/Makefile
@@ -21,6 +21,15 @@ LIB_OBJS=$(LIB_OBJS_sub:.c=.o)
LIB_OBJ_DIRS_sub=$(shell find $(LIB_DIR) -type d)
LIB_OBJ_DIRS=$(subst $(LIB_DIR),$(LIB_OBJ_DIR),$(LIB_OBJ_DIRS_sub))
+# Library files
+TEST_DIR=test/
+TEST_OBJ_DIR=$(BUILD_DIR)obj/$(TEST_DIR)
+TEST_SRCS=$(shell find $(TEST_DIR) -iname \*.c)
+TEST_OBJS_sub=$(subst $(TEST_DIR),$(TEST_OBJ_DIR),$(TEST_SRCS))
+TEST_OBJS=$(TEST_OBJS_sub:.c=.o)
+TEST_OBJ_DIRS_sub=$(shell find $(TEST_DIR) -type d)
+TEST_OBJ_DIRS=$(subst $(TEST_DIR),$(TEST_OBJ_DIR),$(TEST_OBJ_DIRS_sub))
+
# Programs
PROG_DIR=
PROG_OUT_DIR=$(BUILD_DIR)$(PROG_DIR)
@@ -66,7 +75,7 @@ default: clean build
build: $(PROGS)
-$(BUILD_DIR)$(PROG_DIR)%: $(SRC_OBJ_DIR)%.o $(LIB_OBJS)
+$(BUILD_DIR)$(PROG_DIR)%: $(SRC_OBJ_DIR)%.o $(LIB_OBJS) $(TEST_OBJS)
@echo LD --\> $@
@gcc -o $@ $(LDFLAGS) $^
@@ -78,7 +87,11 @@ $(LIB_OBJ_DIR)%.o: $(LIB_DIR)%.c
@echo CC $< --\> $@
@gcc -o $@ $(CFLAGS) -c $<
+$(TEST_OBJ_DIR)%.o: $(TEST_DIR)%.c
+ @echo CC $< --\> $@
+ @gcc -o $@ $(CFLAGS) -c $<
+
clean:
@echo Cleaning build files...
@-rm -rf $(OBJ_DIR) $(BUILD_DIR)
- @mkdir -p $(BUILD_DIR) $(SRC_OBJ_DIRS) $(LIB_OBJ_DIRS) $(PROG_DIRS)
+ @mkdir -p $(BUILD_DIR) $(SRC_OBJ_DIRS) $(LIB_OBJ_DIRS) $(TEST_OBJ_DIRS) $(PROG_DIRS)
diff --git a/include/test/__meta__.h b/include/test/__meta__.h
new file mode 100644
index 0000000..05a202f
--- /dev/null
+++ b/include/test/__meta__.h
@@ -0,0 +1,14 @@
+#ifndef INC_TEST___META___H
+#define INC_TEST___META___H
+
+#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)
+
+#ifndef _TEST_RESULT
+#define _TEST_RESULT(docstring,result,n,n_success) if (!result) {_TEST_FAIL(docstring, n);} else {_TEST_PASS(docstring,n);n_success++;}
+#endif
+
+#endif
diff --git a/include/test/lib/color.h b/include/test/lib/color.h
new file mode 100644
index 0000000..835cb0a
--- /dev/null
+++ b/include/test/lib/color.h
@@ -0,0 +1,17 @@
+#ifndef INC_TEST_LIB_COLOR_H
+#define INC_TEST_LIB_COLOR_H
+
+#include <test/__meta__.h>
+#ifndef TEST_RESULT
+#define TEST_RESULT(result,n,n_success) _TEST_RESULT("LIB/COLOR",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);
+
+// Meta test function
+bool_t TEST_lib_color();
+
+#endif
diff --git a/src/test/test.c b/src/test/test.c
new file mode 100644
index 0000000..95b4154
--- /dev/null
+++ b/src/test/test.c
@@ -0,0 +1,13 @@
+#include <test/lib/color.h>
+
+int main()
+{
+ bool_t all_success = TRUE;
+ // lib/color.c Test
+ all_success &= TEST_lib_color();
+
+ if (all_success == TRUE) {
+ return 0;
+ }
+ return 1;
+}
diff --git a/test/lib/color.c b/test/lib/color.c
new file mode 100644
index 0000000..191972d
--- /dev/null
+++ b/test/lib/color.c
@@ -0,0 +1,52 @@
+#include <test/lib/color.h>
+
+bool_t test_color_zero(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;
+}
+bool_t test_color_equal(uint8_t* color1, uint8_t* color2, size_t channels, bool_t result)
+{
+ bool_t fcall_result = color_zero(color1, channels);
+ if (fcall_result == result) {
+ return TRUE;
+ }
+ return FALSE;
+}
+
+// Meta test function
+bool_t TEST_lib_color()
+{
+ uint8_t test_count = 0;
+ uint8_t test_pass = 0;
+ bool_t result;
+
+ // Test 1: 1 channel zero color
+ // 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);
+
+ // Test 2: 1 channel non-zero color
+ // 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);
+
+ // Test 3: 2 channel zero color
+ // 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);
+
+ // Test 4: 2 channel non-zero color
+ // 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);
+
+ return test_count == test_pass;
+}