aboutsummaryrefslogtreecommitdiff
path: root/tests/driver.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/driver.c')
-rw-r--r--tests/driver.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/tests/driver.c b/tests/driver.c
new file mode 100644
index 0000000..235d598
--- /dev/null
+++ b/tests/driver.c
@@ -0,0 +1,46 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <sys/types.h>
+#define USE_SECURE_MEM
+#include "../src/extlib.h"
+#include "test_driver.h"
+
+const char* success = "\033[1;32m";
+const char* fail = " \033[1;31m";
+const char *reset = "\033[0m";
+
+int tests_count;
+struct test_t** registered_tests;
+
+int
+test_runner (struct test_t *test, int n)
+{
+ printf ("Test Case %d: %s -- %s\n", n, test->test_name, test->test_desc);
+ int test_result = test->test_func();
+ if (test_result == 0)
+ printf ("Test Case %d: %s -- %sSUCCESS%s\n\n", n, test->test_name, success, reset);
+ else
+ printf ("Test Case %d: %s -- %sFAIL %d%s\n\n", n, test->test_name, test_result, fail, reset);
+}
+
+void
+register_test (struct test_t *test)
+{
+ tests_count += 1;
+ registered_tests = reallocarray (registered_tests, sizeof (struct test_t), tests_count);
+
+ registered_tests[tests_count-1] = test;
+}
+
+int
+main (int argc, char *argv[])
+{
+ registered_tests = malloc (8);
+ tests_entrypoint();
+ for (int i = 0; i < tests_count; i++)
+ {
+ test_runner(registered_tests[i], i+1);
+ }
+ return 0;
+}