summaryrefslogtreecommitdiff
path: root/test/source/main.c
blob: 25246cfddadfa44491255a15767e347fc8b0c894 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#include <inttypes.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <zap/mem.h>
#include <zap/mth.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/abs.i"
#include "test/bool.i"
#include "test/cmp.i"
#include "test/memcnt.i"
#include "test/memcp.i"
#include "test/memeq.i"
#include "test/memfill.i"
#include "test/memfnd.i"
#include "test/memfor.i"
#include "test/memgen.i"
#include "test/nullptr.i"
#include "test/strcp.i"
#include "test/streq.i"
#include "test/strfill.i"
#include "test/strfnd.i"
#include "test/strlen.i"
#include "test/utf20len.i"
#include "test/utf8dec.i"
#include "test/utf8enc.i"
#include "test/win1252dec.i"
#include "test/win1252enc.i"

static zaptest_testtyp zaptest_tests[] = {
	zaptest_test_abs,
	zaptest_test_bool,
	zaptest_test_cmp,
	zaptest_test_memcnt,
	zaptest_test_memcp,
	zaptest_test_memeq,
	zaptest_test_memfill,
	zaptest_test_memfnd,
	zaptest_test_memfor,
	zaptest_test_memgen,
	zaptest_test_nullptr,
	zaptest_test_strcp,
	zaptest_test_streq,
	zaptest_test_strfill,
	zaptest_test_strfnd,
	zaptest_test_strlen,
	zaptest_test_utf20len,
	zaptest_test_utf8dec,
	zaptest_test_utf8enc,
	zaptest_test_win1252dec,
	zaptest_test_win1252enc,
};

static char const * zaptest_testnms[] = {
	"abs",
	"add",
	"bool",
	"cmp",
	"memcnt",
	"memcp",
	"memeq",
	"memfill",
	"memfnd",
	"memfor",
	"memgen",
	"nullptr",
	"strcp",
	"streq",
	"strfill",
	"strfnd",
	"strlen",
	"utf20len",
	"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);}
}