summaryrefslogtreecommitdiff
path: root/test/src/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'test/src/main.c')
-rw-r--r--test/src/main.c106
1 files changed, 106 insertions, 0 deletions
diff --git a/test/src/main.c b/test/src/main.c
new file mode 100644
index 0000000..79bf0ce
--- /dev/null
+++ b/test/src/main.c
@@ -0,0 +1,106 @@
+#include <inttypes.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <zap/mem.h>
+
+#define zaptest_log(_expr,_typ,_fmtspec) (fprintf(stderr,"(" #_expr "): " _fmtspec "\n\n",(_typ)(_expr)));
+
+#define zaptest_chk(_lexpr,_rexpr,_typ,_fmtspec) { \
+ fprintf(stderr,"(" #_lexpr "): " _fmtspec "\n",(_typ)(_lexpr)); \
+ fprintf(stderr,"(" #_rexpr "): " _fmtspec "\n\n",(_typ)(_rexpr)); \
+ if ((_typ)(_lexpr) != (_typ)(_rexpr)) { \
+ fprintf(stderr,"Mismatch!\n"); \
+ return true; \
+ } \
+}
+
+typedef bool (* zaptest_testtyp)(void);
+
+#include "test/bool.i"
+#include "test/cmp.i"
+#include "test/fndbyte.i"
+#include "test/fndchr.i"
+#include "test/foreach.i"
+#include "test/memcat.i"
+#include "test/memcmp.i"
+#include "test/memcp.i"
+#include "test/memeq.i"
+#include "test/memfill.i"
+#include "test/memgen.i"
+#include "test/nullptr.i"
+#include "test/strcat.i"
+#include "test/strcp.i"
+#include "test/streq.i"
+#include "test/strfill.i"
+#include "test/strlen.i"
+#include "test/utf8dec.i"
+#include "test/utf8enc.i"
+#include "test/win1252dec.i"
+#include "test/win1252enc.i"
+
+static zaptest_testtyp zaptest_tests[] = {
+ zaptest_test_bool,
+ zaptest_test_cmp,
+ zaptest_test_fndbyte,
+ zaptest_test_fndchr,
+ zaptest_test_foreach,
+ zaptest_test_memcat,
+ zaptest_test_memcmp,
+ zaptest_test_memcp,
+ zaptest_test_memeq,
+ zaptest_test_memfill,
+ zaptest_test_memgen,
+ zaptest_test_nullptr,
+ zaptest_test_strcat,
+ zaptest_test_strcp,
+ zaptest_test_streq,
+ zaptest_test_strfill,
+ zaptest_test_strlen,
+ zaptest_test_utf8dec,
+ zaptest_test_utf8enc,
+ zaptest_test_win1252dec,
+ zaptest_test_win1252enc,
+};
+
+static char const * zaptest_testnms[] = {
+ "bool",
+ "cmp",
+ "fndbyte",
+ "fndchr",
+ "foreach",
+ "memcat",
+ "memcmp",
+ "memcp",
+ "memeq",
+ "memfill",
+ "memgen",
+ "nullptr",
+ "strcat",
+ "strcp",
+ "streq",
+ "strfill",
+ "strlen",
+ "utf8dec",
+ "utf8enc",
+ "win1252dec",
+ "win1252enc",
+};
+
+static void zaptest_dotest(zap_sz const _n) {
+ fprintf(stderr,":: \x1B[94mTesting\x1B[0m %s...\n\n",zaptest_testnms[_n]);
+ if (zaptest_tests[_n]()) {
+ fprintf(stderr,":: \x1B[91mError\x1B[0m in %s! Aborting...\n\n",zaptest_testnms[_n]);
+ exit(EXIT_FAILURE);
+ }
+ fprintf(stderr,":: \x1B[92mSuccess\x1B[0m with %s!\n\n",zaptest_testnms[_n]);
+}
+
+int main(void) {
+ fprintf(stderr,"Zap Test\n\n");
+ fprintf(stderr,"Version: %lX\n",zap_ver);
+ fprintf(stderr,"\n");
+ zaptest_log(zap_nopos,zap_sz,"%zX")
+ zaptest_log((void *)zap_nullptr,uintptr_t,"%" PRIXPTR)
+ for (zap_sz n = 0x0u;n < sizeof (zaptest_tests) / sizeof (zaptest_tests[0x0u]);++n) {zaptest_dotest(n);}
+}