summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile31
-rw-r--r--tests/pke-test-dummy.c22
-rw-r--r--tests/pke-test-dummy.h8
-rw-r--r--tests/pke-test-types.h30
-rw-r--r--tests/pke-test.c57
5 files changed, 148 insertions, 0 deletions
diff --git a/Makefile b/Makefile
index 2017b25..f7b4542 100644
--- a/Makefile
+++ b/Makefile
@@ -56,6 +56,8 @@ SRC = \
src/vendor-stb-image-include.c \
src/vendor-tinyfiledialogs.c \
src/window.cpp \
+ tests/pke-test.c \
+ tests/pke-test-dummy.c \
DST_SHADERS = \
$(DIR_OBJ)/shaders/vertex.vert.spv \
@@ -142,6 +144,14 @@ $(DIR_OBJ)/%.o : src/%.cpp
$(cxx-bin-command) $(FLG_PKE)
$(DIR_OBJ)/%.so : src/%.cpp
$(cxx-dbg-command) $(FLG_PKE)
+$(DIR_OBJ)/%.o : tests/%.c
+ $(cc-bin-command) $(FLG_PKE)
+$(DIR_OBJ)/%.so : tests/%.c
+ $(cc-dbg-command) $(FLG_PKE)
+$(DIR_OBJ)/%.o : tests/%.cpp
+ $(cxx-bin-command) $(FLG_PKE)
+$(DIR_OBJ)/%.so : tests/%.cpp
+ $(cxx-dbg-command) $(FLG_PKE)
$(DIR_OBJ)/%.o : editor/%.cpp
$(cxx-bin-command) $(FLG_EDT)
$(DIR_OBJ)/%.so : editor/%.cpp
@@ -213,6 +223,14 @@ $(DIR_DBG)/libpke-example.a: $(DIR_OBJ)/example.so
ar rc $@ $(filter %.so,$^)
ranlib $@
+$(DIR_BIN)/libpke-test.a: $(DIR_OBJ)/pke-test-dummy.o
+ ar rc $@ $(filter %.o,$^)
+ ranlib $@
+
+$(DIR_DBG)/libpke-test.a: $(DIR_OBJ)/pke-test-dummy.so
+ ar rc $@ $(filter %.so,$^)
+ ranlib $@
+
$(DIR_BIN)/pke-editor: $(DIR_BIN)/libpke.a $(DIR_BIN)/libImgui.a $(DIR_BIN)/libBullet3.a
$(DIR_BIN)/pke-editor: $(DIR_OBJ)/editor-main.o $(DIR_OBJ)/editor.o
$(CXX) -v -std=c++23 $(INCS) /home/pikum/build/msdfgen/dbg/msdfgen.a /home/pikum/build/msdf-atlas-gen/dbg/msdf-atlas-gen.a $^ $(LDFLAGS) $(CXXFLAGS) -g -O0 -o $@
@@ -232,6 +250,19 @@ $(DIR_DBG)/pke-runtime: $(DIR_OBJ)/runtime.so
@echo $^
$(CXX) -v -std=c++23 $(INCS) $^ $(LDFLAGS) $(CXXFLAGS) -g -O0 -o $@
+$(DIR_BIN)/test-pke: $(DIR_BIN)/libpke.a $(DIR_BIN)/libImgui.a $(DIR_BIN)/libBullet3.a
+$(DIR_DBG)/test-pke: $(DIR_BIN)/libpke-test.a
+$(DIR_BIN)/test-pke: $(DIR_OBJ)/pke-test.o
+$(DIR_BIN)/test-pke:
+ @echo $^
+ $(CC) -std=c2x -v $(INCS) $^ $(LDFLAGS) $(CXXFLAGS) -g -O0 -o $@
+
+$(DIR_DBG)/test-pke: $(DIR_DBG)/libpke.a $(DIR_DBG)/libImgui.a $(DIR_DBG)/libBullet3.a
+$(DIR_DBG)/test-pke: $(DIR_DBG)/libpke-test.a
+$(DIR_DBG)/test-pke: $(DIR_OBJ)/pke-test.so
+ @echo $^
+ $(CC) -std=c2x -v $(INCS) $^ $(LDFLAGS) $(CXXFLAGS) -g -O0 -o $@
+
.PHONY: print
print:
@echo $(DST_SHADERS)
diff --git a/tests/pke-test-dummy.c b/tests/pke-test-dummy.c
new file mode 100644
index 0000000..ea92c34
--- /dev/null
+++ b/tests/pke-test-dummy.c
@@ -0,0 +1,22 @@
+
+#include "./pke-test-dummy.h"
+
+int pke_test_dummy_001() {
+ return 0;
+}
+
+struct pke_test_group *pke_test_dummy_get_group() {
+ static struct pke_test tests[1] = {
+ {
+ .title = "test 001",
+ .func = pke_test_dummy_001,
+ .expected_result = 0,
+ }
+ };
+ static struct pke_test_group group = {0};
+ group.title = "dummy test";
+ group.n_tests = 1;
+ group.tests = &tests[0];
+
+ return &group;
+}
diff --git a/tests/pke-test-dummy.h b/tests/pke-test-dummy.h
new file mode 100644
index 0000000..b69609e
--- /dev/null
+++ b/tests/pke-test-dummy.h
@@ -0,0 +1,8 @@
+#ifndef PKE_PKE_TEST_DUMMY_H
+#define PKE_PKE_TEST_DUMMY_H
+
+#include "pke-test-types.h"
+
+struct pke_test_group *pke_test_dummy_get_group();
+
+#endif /* PKE_PKE_TEST_DUMMY_H */
diff --git a/tests/pke-test-types.h b/tests/pke-test-types.h
new file mode 100644
index 0000000..5278eae
--- /dev/null
+++ b/tests/pke-test-types.h
@@ -0,0 +1,30 @@
+#ifndef PKE_PKE_TEST_TYPES_H
+#define PKE_PKE_TEST_TYPES_H
+
+#include <setjmp.h>
+#include <stdint.h>
+
+struct pke_test_long_jump {
+ uint8_t expected_exit;
+ uint8_t caught;
+ jmp_buf jump_env;
+};
+extern struct pke_test_long_jump lj;
+
+typedef int (pke_test_func)();
+struct pke_test_group;
+typedef struct pke_test_group *(pke_test_get_group)();
+
+struct pke_test {
+ const char *title;
+ pke_test_func *func;
+ int expected_result;
+};
+
+struct pke_test_group {
+ const char *title;
+ struct pke_test *tests;
+ uint32_t n_tests;
+};
+
+#endif /* PKE_PKE_TEST_TYPES_H */
diff --git a/tests/pke-test.c b/tests/pke-test.c
new file mode 100644
index 0000000..4f88dbf
--- /dev/null
+++ b/tests/pke-test.c
@@ -0,0 +1,57 @@
+
+#include "./pke-test-types.h"
+
+#include "./pke-test-dummy.h"
+
+#include "unistd.h"
+#include <stdio.h>
+
+#define CLR_WHITE "\033[0m"
+#define CLR_GREEN "\033[92m"
+#define CLR_RED "\033[31m"
+
+// https://stackoverflow.com/questions/64190847/how-to-catch-a-call-to-exit-for-unit-testing
+struct pke_test_long_jump lj;
+void exit(int code) {
+ if (lj.expected_exit) {
+ lj.caught = 1;
+ longjmp(lj.jump_env, 1);
+ }
+ _exit(code);
+}
+
+int main(int argc, char *argv[])
+{
+ (void)argc;
+ (void)argv;
+ int i = 0;
+ uint32_t k, pass_count;
+
+ pke_test_get_group *group_fns[] = {
+ pke_test_dummy_get_group,
+ NULL,
+ };
+
+ pke_test_get_group *fn = group_fns[i];
+ while (fn != NULL) {
+ pass_count = 0;
+ struct pke_test_group *group = (fn)();
+ fprintf(stdout, "[pke-test]:[%s] Begin.\n", group->title);
+ for (k = 0; k < group->n_tests; ++k) {
+ fprintf(stdout, "[pke-test]:[%s]:[%s] Begin.\n", group->title, group->tests[k].title);
+ lj.expected_exit = 0;
+ lj.caught = 0;
+ if (group->tests[k].expected_result == (group->tests[k].func)()){
+ pass_count += 1;
+ fprintf(stdout, "[pke-test]:[%s]:[%s] %sPassed.%s\n", group->title, group->tests[k].title, CLR_GREEN, CLR_WHITE);
+ } else {
+ fprintf(stdout, "[pke-test]:[%s]:[%s] %sFailed.%s\n", group->title, group->tests[k].title, CLR_RED, CLR_WHITE);
+ }
+ }
+ fprintf(stdout, "[pke-test]:[%s] End. ( %s%03d%s / %03d ) Tests Completed.\n\n", group->title, pass_count == group->n_tests ? CLR_GREEN : CLR_RED, pass_count, CLR_WHITE, group->n_tests);
+ i += 1;
+ fn = group_fns[i];
+ }
+
+ return 0;
+}