summaryrefslogtreecommitdiff
path: root/test/source
diff options
context:
space:
mode:
Diffstat (limited to 'test/source')
-rw-r--r--test/source/main.c103
-rw-r--r--test/source/test/bool.i9
-rw-r--r--test/source/test/cmp.i11
-rw-r--r--test/source/test/fndbyte.i33
-rw-r--r--test/source/test/fndchr.i12
-rw-r--r--test/source/test/foreach.i23
-rw-r--r--test/source/test/memcat.i43
-rw-r--r--test/source/test/memcp.i18
-rw-r--r--test/source/test/memeq.i24
-rw-r--r--test/source/test/memfill.i23
-rw-r--r--test/source/test/memgen.i29
-rw-r--r--test/source/test/nullptr.i7
-rw-r--r--test/source/test/strcat.i19
-rw-r--r--test/source/test/strcp.i42
-rw-r--r--test/source/test/streq.i21
-rw-r--r--test/source/test/strfill.i18
-rw-r--r--test/source/test/strlen.i13
-rw-r--r--test/source/test/utf8dec.i43
-rw-r--r--test/source/test/utf8enc.i42
-rw-r--r--test/source/test/win1252dec.i76
-rw-r--r--test/source/test/win1252enc.i76
21 files changed, 685 insertions, 0 deletions
diff --git a/test/source/main.c b/test/source/main.c
new file mode 100644
index 0000000..38c9f68
--- /dev/null
+++ b/test/source/main.c
@@ -0,0 +1,103 @@
+#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/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_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",
+ "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);}
+}
diff --git a/test/source/test/bool.i b/test/source/test/bool.i
new file mode 100644
index 0000000..adacf85
--- /dev/null
+++ b/test/source/test/bool.i
@@ -0,0 +1,9 @@
+#include <inttypes.h>
+#include <stdbool.h>
+
+static bool zaptest_test_bool(void) {
+ zaptest_log(zap_true,uintmax_t,"%" PRIXMAX)
+ zaptest_chk(zap_false,0x0u,unsigned char,"%hhX")
+ zaptest_chk(zap_true > zap_false,0x1u,unsigned char,"%hhX")
+ return false;
+}
diff --git a/test/source/test/cmp.i b/test/source/test/cmp.i
new file mode 100644
index 0000000..fbb7d5c
--- /dev/null
+++ b/test/source/test/cmp.i
@@ -0,0 +1,11 @@
+#include <inttypes.h>
+#include <stdbool.h>
+
+static bool zaptest_test_cmp(void) {
+ zaptest_log(zap_lt,intmax_t,"%" PRIiMAX)
+ zaptest_log(zap_gt,intmax_t,"%" PRIiMAX)
+ zaptest_chk(zap_eq,0x0u,signed char,"%hhi")
+ zaptest_chk(zap_lt < zap_eq,0x1u,unsigned char,"%hhX")
+ zaptest_chk(zap_gt > zap_eq,0x1u,unsigned char,"%hhX")
+ return false;
+}
diff --git a/test/source/test/fndbyte.i b/test/source/test/fndbyte.i
new file mode 100644
index 0000000..56231ac
--- /dev/null
+++ b/test/source/test/fndbyte.i
@@ -0,0 +1,33 @@
+#include <stdbool.h>
+
+static bool zaptest_test_fndbyte(void) {
+ unsigned char const arr[] = {
+ 0x1u,
+ 0x3u,
+ 0x7u,
+ 0xFu,
+ 0x1Fu,
+ 0x3Fu,
+ 0x7Fu,
+ 0xFFu,
+ };
+ zap_sz pos = zap_fndbyte(arr,sizeof (arr),0x1u);
+ zaptest_chk(pos,0x0u,zap_sz,"%zX");
+ pos = zap_fndbyte(arr,sizeof (arr),0x3u);
+ zaptest_chk(pos,0x1u,zap_sz,"%zX");
+ pos = zap_fndbyte(arr,sizeof (arr),0x7u);
+ zaptest_chk(pos,0x2u,zap_sz,"%zX");
+ pos = zap_fndbyte(arr,sizeof (arr),0xFu);
+ zaptest_chk(pos,0x3u,zap_sz,"%zX");
+ pos = zap_fndbyte(arr,sizeof (arr),0x1Fu);
+ zaptest_chk(pos,0x4u,zap_sz,"%zX");
+ pos = zap_fndbyte(arr,sizeof (arr),0x3Fu);
+ zaptest_chk(pos,0x5u,zap_sz,"%zX");
+ pos = zap_fndbyte(arr,sizeof (arr),0x7Fu);
+ zaptest_chk(pos,0x6u,zap_sz,"%zX");
+ pos = zap_fndbyte(arr,sizeof (arr),0xFFu);
+ zaptest_chk(pos,0x7u,zap_sz,"%zX");
+ pos = zap_fndbyte(arr,sizeof (arr),0xFEu);
+ zaptest_chk(pos,zap_nopos,zap_sz,"%zX");
+ return false;
+}
diff --git a/test/source/test/fndchr.i b/test/source/test/fndchr.i
new file mode 100644
index 0000000..8fb670a
--- /dev/null
+++ b/test/source/test/fndchr.i
@@ -0,0 +1,12 @@
+#include <stdbool.h>
+
+static bool zaptest_test_fndchr(void) {
+ char const str[] = "What the drake doing?";
+ zap_sz pos = zap_fndchr(str,'?');
+ zaptest_chk(pos,0x14u,zap_sz,"%zX");
+ pos = zap_fndchr(str,'t');
+ zaptest_chk(pos,0x3u,zap_sz,"%zX");
+ pos = zap_fndchr(str,'!');
+ zaptest_chk(pos,zap_nopos,zap_sz,"%zX");
+ return false;
+}
diff --git a/test/source/test/foreach.i b/test/source/test/foreach.i
new file mode 100644
index 0000000..e7b933d
--- /dev/null
+++ b/test/source/test/foreach.i
@@ -0,0 +1,23 @@
+#include <stdbool.h>
+
+static void foreachfn(void * const _ptr) {
+ unsigned int * ptr = _ptr;
+ unsigned int val = *ptr;
+ val %= 0x2;
+ *ptr = val;
+}
+
+static bool zaptest_test_foreach(void) {
+ unsigned int arr[] = {
+ 0x0u,
+ 0x1u,
+ 0x2u,
+ 0x3u,
+ };
+ zap_foreach(arr,sizeof (arr[0x0u]),sizeof (arr) / sizeof (arr[0x0u]),foreachfn);
+ zaptest_chk(arr[0x0u],0x0u,unsigned int,"%X");
+ zaptest_chk(arr[0x1u],0x1u,unsigned int,"%X");
+ zaptest_chk(arr[0x2u],0x0u,unsigned int,"%X");
+ zaptest_chk(arr[0x3u],0x1u,unsigned int,"%X");
+ return false;
+}
diff --git a/test/source/test/memcat.i b/test/source/test/memcat.i
new file mode 100644
index 0000000..f16faef
--- /dev/null
+++ b/test/source/test/memcat.i
@@ -0,0 +1,43 @@
+#include <stdbool.h>
+
+static bool zaptest_test_memcat(void) {
+ unsigned short const arr0[] = {
+ 0x1u,
+ 0x3u,
+ 0x7u,
+ 0xFu,
+ 0x1Fu,
+ 0x3Fu,
+ 0x7Fu,
+ 0xFFu,
+ };
+ unsigned short const arr1[] = {
+ 0x1FFu,
+ 0x3FFu,
+ 0x7FFu,
+ 0xFFFu,
+ 0x1FFFu,
+ 0x3FFFu,
+ 0x7FFFu,
+ 0xFFFFu,
+ };
+ unsigned short buf[(sizeof (arr0) + sizeof (arr1)) / sizeof (arr0[0x0u])];
+ zap_memcat(arr0,sizeof (arr0),arr1,sizeof (arr1),buf);
+ zaptest_chk(buf[0x0u],0x1u, unsigned int,"%X");
+ zaptest_chk(buf[0x1u],0x3u, unsigned int,"%X");
+ zaptest_chk(buf[0x2u],0x7u, unsigned int,"%X");
+ zaptest_chk(buf[0x3u],0xFu, unsigned int,"%X");
+ zaptest_chk(buf[0x4u],0x1F, unsigned int,"%X");
+ zaptest_chk(buf[0x5u],0x3Fu, unsigned int,"%X");
+ zaptest_chk(buf[0x6u],0x7Fu, unsigned int,"%X");
+ zaptest_chk(buf[0x7u],0xFFu, unsigned int,"%X");
+ zaptest_chk(buf[0x8u],0x1FFu, unsigned int,"%X");
+ zaptest_chk(buf[0x9u],0x3FFu, unsigned int,"%X");
+ zaptest_chk(buf[0xAu],0x7FFu, unsigned int,"%X");
+ zaptest_chk(buf[0xBu],0xFFFu, unsigned int,"%X");
+ zaptest_chk(buf[0xCu],0x1FFFu,unsigned int,"%X");
+ zaptest_chk(buf[0xDu],0x3FFFu,unsigned int,"%X");
+ zaptest_chk(buf[0xEu],0x7FFFu,unsigned int,"%X");
+ zaptest_chk(buf[0xFu],0xFFFFu,unsigned int,"%X");
+ return false;
+}
diff --git a/test/source/test/memcp.i b/test/source/test/memcp.i
new file mode 100644
index 0000000..4cfc17c
--- /dev/null
+++ b/test/source/test/memcp.i
@@ -0,0 +1,18 @@
+#include <inttypes.h>
+#include <stdbool.h>
+
+static bool zaptest_test_memcp(void) {
+ unsigned int arr[] = {
+ 0xA5D0u,
+ 0x98FFu,
+ 0xA29Au,
+ 0x910Cu,
+ };
+ unsigned int buf[sizeof (arr) / sizeof (arr[0x0u])];
+ zap_memcp(arr,sizeof (arr),buf);
+ zaptest_chk(buf[0x0u],0xA5D0u,unsigned int,"%X");
+ zaptest_chk(buf[0x1u],0x98FFu,unsigned int,"%X");
+ zaptest_chk(buf[0x2u],0xA29Au,unsigned int,"%X");
+ zaptest_chk(buf[0x3u],0x910Cu,unsigned int,"%X");
+ return false;
+}
diff --git a/test/source/test/memeq.i b/test/source/test/memeq.i
new file mode 100644
index 0000000..d9de72f
--- /dev/null
+++ b/test/source/test/memeq.i
@@ -0,0 +1,24 @@
+#include <stdbool.h>
+
+static bool zaptest_test_memeq(void) {
+ unsigned char const arr0[] = {
+ 0xFFu,
+ 0x7Fu,
+ 0x3Fu,
+ };
+ unsigned char const arr1[] = {
+ 0xFFu,
+ 0x7Fu,
+ 0xFFu,
+ };
+ unsigned char const arr2[] = {
+ 0xFFu,
+ 0x7Fu,
+ 0x3Fu,
+ };
+ zap_cmp eq = zap_memeq(arr0,sizeof (arr0),arr1);
+ zaptest_chk(eq,zap_false,unsigned char,"%hhX")
+ eq = zap_memeq(arr0,sizeof (arr0),arr2);
+ zaptest_chk(eq,zap_true,unsigned char,"%hhX")
+ return false;
+}
diff --git a/test/source/test/memfill.i b/test/source/test/memfill.i
new file mode 100644
index 0000000..9cb4d6e
--- /dev/null
+++ b/test/source/test/memfill.i
@@ -0,0 +1,23 @@
+#include <stdbool.h>
+
+static bool zaptest_test_memfill(void) {
+ unsigned long arr[0x4u];
+ zap_memfill(arr,sizeof (arr),0x7Fu);
+ arr[0x0u] &= 0xFFFFFFFFFFFFFFFFu;
+ arr[0x1u] &= 0xFFFFFFFFFFFFFFFFu;
+ arr[0x2u] &= 0xFFFFFFFFFFFFFFFFu;
+ arr[0x3u] &= 0xFFFFFFFFFFFFFFFFu;
+ zaptest_chk(arr[0x0u],0x7F7F7F7F7F7F7F7Fu,unsigned long,"%lX");
+ zaptest_chk(arr[0x1u],0x7F7F7F7F7F7F7F7Fu,unsigned long,"%lX");
+ zaptest_chk(arr[0x2u],0x7F7F7F7F7F7F7F7Fu,unsigned long,"%lX");
+ zaptest_chk(arr[0x3u],0x7F7F7F7F7F7F7F7Fu,unsigned long,"%lX");
+ zap_memfill(arr + 0x1u,sizeof (arr) - sizeof (arr[0x0u]),0x3Fu);
+ arr[0x1u] &= 0xFFFFFFFFFFFFFFFFu;
+ arr[0x2u] &= 0xFFFFFFFFFFFFFFFFu;
+ arr[0x3u] &= 0xFFFFFFFFFFFFFFFFu;
+ zaptest_chk(arr[0x0u],0x7F7F7F7F7F7F7F7Fu,unsigned long,"%lX");
+ zaptest_chk(arr[0x1u],0x3F3F3F3F3F3F3F3Fu,unsigned long,"%lX");
+ zaptest_chk(arr[0x2u],0x3F3F3F3F3F3F3F3Fu,unsigned long,"%lX");
+ zaptest_chk(arr[0x3u],0x3F3F3F3F3F3F3F3Fu,unsigned long,"%lX");
+ return false;
+}
diff --git a/test/source/test/memgen.i b/test/source/test/memgen.i
new file mode 100644
index 0000000..dcc7c69
--- /dev/null
+++ b/test/source/test/memgen.i
@@ -0,0 +1,29 @@
+#include <stdbool.h>
+#include <stddef.h>
+
+static unsigned long zaptest_fib(zap_sz const _num) {
+ if (_num <= 0x1u) {
+ if (_num == 0x0u) {return 0x0u;}
+ return 0x1u;
+ }
+ return zaptest_fib(_num - 0x1u) + zaptest_fib(_num - 0x2u);
+}
+
+static void zatest_memgenfn(zap_sz const _num,void * const _ptr) {
+ unsigned long * ptr = _ptr;
+ *ptr = zaptest_fib(_num);
+}
+
+static bool zaptest_test_memgen(void) {
+ unsigned long arr[0x8u];
+ zap_memgen(arr,sizeof (arr[0x0u]),sizeof (arr) / sizeof (arr[0x0u]),zatest_memgenfn);
+ zaptest_chk(arr[0x0u],0x0u,unsigned long,"%lX");
+ zaptest_chk(arr[0x1u],0x1u,unsigned long,"%lX");
+ zaptest_chk(arr[0x2u],0x1u,unsigned long,"%lX");
+ zaptest_chk(arr[0x3u],0x2u,unsigned long,"%lX");
+ zaptest_chk(arr[0x4u],0x3u,unsigned long,"%lX");
+ zaptest_chk(arr[0x5u],0x5u,unsigned long,"%lX");
+ zaptest_chk(arr[0x6u],0x8u,unsigned long,"%lX");
+ zaptest_chk(arr[0x7u],0xDu,unsigned long,"%lX");
+ return false;
+}
diff --git a/test/source/test/nullptr.i b/test/source/test/nullptr.i
new file mode 100644
index 0000000..00b49bd
--- /dev/null
+++ b/test/source/test/nullptr.i
@@ -0,0 +1,7 @@
+#include <stdbool.h>
+#include <stddef.h>
+
+static bool zaptest_test_nullptr(void) {
+ zaptest_chk((void *)zap_nullptr,(void *)NULL,void *,"%p")
+ return false;
+}
diff --git a/test/source/test/strcat.i b/test/source/test/strcat.i
new file mode 100644
index 0000000..e037b88
--- /dev/null
+++ b/test/source/test/strcat.i
@@ -0,0 +1,19 @@
+#include <stdbool.h>
+
+static bool zaptest_test_strcat(void) {
+ char const str0[] = "u r ";
+ char const str1[] = "mr gay";
+ char buf[sizeof (str0) + sizeof (str1)];
+ zap_strcat(str0,str1,buf);
+ zaptest_chk(buf[0x0u],'u',char,"'%c'");
+ zaptest_chk(buf[0x1u],' ',char,"'%c'");
+ zaptest_chk(buf[0x2u],'r',char,"'%c'");
+ zaptest_chk(buf[0x3u],' ',char,"'%c'");
+ zaptest_chk(buf[0x4u],'m',char,"'%c'");
+ zaptest_chk(buf[0x5u],'r',char,"'%c'");
+ zaptest_chk(buf[0x6u],' ',char,"'%c'");
+ zaptest_chk(buf[0x7u],'g',char,"'%c'");
+ zaptest_chk(buf[0x8u],'a',char,"'%c'");
+ zaptest_chk(buf[0x9u],'y',char,"'%c'");
+ return false;
+}
diff --git a/test/source/test/strcp.i b/test/source/test/strcp.i
new file mode 100644
index 0000000..cd878c9
--- /dev/null
+++ b/test/source/test/strcp.i
@@ -0,0 +1,42 @@
+#include <stdbool.h>
+
+static bool zaptest_test_strcp(void) {
+ char const str[] = "What in the world are you doing?";
+ zaptest_log(str,char const *,"%s")
+ char buf[sizeof (str)];
+ zap_strcp(str,buf);
+ zaptest_chk(buf[0x0u], 'W', char,"'%c'")
+ zaptest_chk(buf[0x1u], 'h', char,"'%c'")
+ zaptest_chk(buf[0x2u], 'a', char,"'%c'")
+ zaptest_chk(buf[0x3u], 't', char,"'%c'")
+ zaptest_chk(buf[0x4u], ' ', char,"'%c'")
+ zaptest_chk(buf[0x5u], 'i', char,"'%c'")
+ zaptest_chk(buf[0x6u], 'n', char,"'%c'")
+ zaptest_chk(buf[0x7u], ' ', char,"'%c'")
+ zaptest_chk(buf[0x8u], 't', char,"'%c'")
+ zaptest_chk(buf[0x9u], 'h', char,"'%c'")
+ zaptest_chk(buf[0xAu], 'e', char,"'%c'")
+ zaptest_chk(buf[0xBu], ' ', char,"'%c'")
+ zaptest_chk(buf[0xCu], 'w', char,"'%c'")
+ zaptest_chk(buf[0xDu], 'o', char,"'%c'")
+ zaptest_chk(buf[0xEu], 'r', char,"'%c'")
+ zaptest_chk(buf[0xFu], 'l', char,"'%c'")
+ zaptest_chk(buf[0x10u],'d', char,"'%c'")
+ zaptest_chk(buf[0x11u],' ', char,"'%c'")
+ zaptest_chk(buf[0x12u],'a', char,"'%c'")
+ zaptest_chk(buf[0x13u],'r', char,"'%c'")
+ zaptest_chk(buf[0x14u],'e', char,"'%c'")
+ zaptest_chk(buf[0x15u],' ', char,"'%c'")
+ zaptest_chk(buf[0x16u],'y', char,"'%c'")
+ zaptest_chk(buf[0x17u],'o', char,"'%c'")
+ zaptest_chk(buf[0x18u],'u', char,"'%c'")
+ zaptest_chk(buf[0x19u],' ', char,"'%c'")
+ zaptest_chk(buf[0x1Au],'d', char,"'%c'")
+ zaptest_chk(buf[0x1Bu],'o', char,"'%c'")
+ zaptest_chk(buf[0x1Cu],'i', char,"'%c'")
+ zaptest_chk(buf[0x1Du],'n', char,"'%c'")
+ zaptest_chk(buf[0x1Eu],'g', char,"'%c'")
+ zaptest_chk(buf[0x1Fu],'?', char,"'%c'")
+ zaptest_chk(buf[0x20u],'\x0',char,"'%c'")
+ return false;
+}
diff --git a/test/source/test/streq.i b/test/source/test/streq.i
new file mode 100644
index 0000000..62ed186
--- /dev/null
+++ b/test/source/test/streq.i
@@ -0,0 +1,21 @@
+#include <stdbool.h>
+
+static bool zaptest_test_streq(void) {
+ char const str0[] = "What's up, my guy?";
+ char const str1[] = "What's up, my guy?";
+ char const str2[] = "I don't know you!";
+ char const str3[] = "I don't know you! Or do I?";
+ zaptest_log(str0,char const *,"%s")
+ zaptest_log(str1,char const *,"%s")
+ zaptest_log(str2,char const *,"%s")
+ zaptest_log(str3,char const *,"%s")
+ zap_bool eq0 = zap_streq(str0,str1);
+ zap_bool eq1 = zap_streq(str0,str2);
+ zap_bool eq2 = zap_streq(str1,str2);
+ zap_bool eq3 = zap_streq(str2,str3);
+ zaptest_chk(eq0,zap_true, unsigned char,"%hhX");
+ zaptest_chk(eq1,zap_false,unsigned char,"%hhX");
+ zaptest_chk(eq2,zap_false,unsigned char,"%hhX");
+ zaptest_chk(eq3,zap_false,unsigned char,"%hhX");
+ return false;
+}
diff --git a/test/source/test/strfill.i b/test/source/test/strfill.i
new file mode 100644
index 0000000..1e2764c
--- /dev/null
+++ b/test/source/test/strfill.i
@@ -0,0 +1,18 @@
+#include <stdbool.h>
+
+static bool zaptest_test_strfill(void) {
+ char str[] = {
+ 'H',
+ 'e',
+ 'y',
+ '!',
+ '\x0',
+ };
+ zap_strfill(str,'&');
+ zaptest_chk(str[0x0u],'&', char,"'%c'");
+ zaptest_chk(str[0x1u],'&', char,"'%c'");
+ zaptest_chk(str[0x2u],'&', char,"'%c'");
+ zaptest_chk(str[0x3u],'&', char,"'%c'");
+ zaptest_chk(str[0x4u],'\x0',char,"'%c'");
+ return false;
+}
diff --git a/test/source/test/strlen.i b/test/source/test/strlen.i
new file mode 100644
index 0000000..93bec76
--- /dev/null
+++ b/test/source/test/strlen.i
@@ -0,0 +1,13 @@
+#include <stdbool.h>
+
+bool zaptest_test_strlen(void) {
+ char const str0[] = "Hello there! General Kenobi?";
+ char const str1[] = "Hello there! General Gayballs?";
+ zaptest_log(str0,char const *,"%s")
+ zaptest_log(str1,char const *,"%s")
+ zap_sz const len0 = zap_strlen(str0);
+ zap_sz const len1 = zap_strlen(str1);
+ zaptest_chk(len0,0x1Cu,zap_sz,"%zX")
+ zaptest_chk(len1,0x1Eu,zap_sz,"%zX")
+ return false;
+}
diff --git a/test/source/test/utf8dec.i b/test/source/test/utf8dec.i
new file mode 100644
index 0000000..fdea169
--- /dev/null
+++ b/test/source/test/utf8dec.i
@@ -0,0 +1,43 @@
+#include <inttypes.h>
+#include <stdbool.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+static bool zaptest_test_utf8dec(void) {
+ zap_chr8 const utf8[] = {
+ 0x26u,
+ 0xC3u,
+ 0xB0u,
+ 0xE0u,
+ 0xB6u,
+ 0x9Eu,
+ 0xE2u,
+ 0x86u,
+ 0x8Au,
+ 0xE2u,
+ 0x86u,
+ 0x8Bu,
+ 0xF0u,
+ 0x9Fu,
+ 0x97u,
+ 0xBFu,
+ 0x0u,
+ };
+ zap_sz const enclen = zap_utf8declen(utf8);
+ zaptest_chk(enclen,0x6u,zap_sz,"%zX")
+ zap_chr20 * const utf20 = malloc(sizeof (zap_chr20) * (enclen + 0x1u));
+ if (utf20 == NULL) {
+ fputs("test.utf8dec: Memory allocation failed!\n\n",stderr);
+ return true;
+ }
+ zap_utf8dec(utf8,utf20);
+ zaptest_chk(utf20[0x0u],0x26u, zap_chr20,"%" PRIXLEAST32)
+ zaptest_chk(utf20[0x1u],0xF0u, zap_chr20,"%" PRIXLEAST32)
+ zaptest_chk(utf20[0x2u],0xD9Eu, zap_chr20,"%" PRIXLEAST32)
+ zaptest_chk(utf20[0x3u],0x218Au, zap_chr20,"%" PRIXLEAST32)
+ zaptest_chk(utf20[0x4u],0x218Bu, zap_chr20,"%" PRIXLEAST32)
+ zaptest_chk(utf20[0x5u],0x1F5FFu,zap_chr20,"%" PRIXLEAST32)
+ zaptest_chk(utf20[0x6u],0x0u, zap_chr20,"%" PRIXLEAST32)
+ free(utf20);
+ return false;
+}
diff --git a/test/source/test/utf8enc.i b/test/source/test/utf8enc.i
new file mode 100644
index 0000000..8bc7abb
--- /dev/null
+++ b/test/source/test/utf8enc.i
@@ -0,0 +1,42 @@
+#include <stdbool.h>
+#include <stdlib.h>
+
+static bool zaptest_test_utf8enc(void) {
+ zap_chr20 const utf20[] = {
+ 0x26u,
+ 0xF0u,
+ 0xD9Eu,
+ 0x218Au,
+ 0x218Bu,
+ 0x1F5FFu,
+ 0x0u,
+ };
+ zap_sz const enclen = zap_utf8enclen(utf20);
+ zaptest_chk(enclen,0x10u,zap_sz,"%zX")
+ zap_chr8 * const utf8 = malloc(enclen + 0x1u);
+ if (utf8 == NULL) {
+ fputs("test.utf8enc: Memory allocation failed!\n\n",stderr);
+ return true;
+ }
+ zap_utf8enc(utf20,utf8);
+ zaptest_log(utf8,char const *,"%s") /* UB? */
+ zaptest_chk(utf8[0x0u], 0x26u,unsigned char,"%hhX")
+ zaptest_chk(utf8[0x1u], 0xC3u,unsigned char,"%hhX")
+ zaptest_chk(utf8[0x2u], 0xB0u,unsigned char,"%hhX")
+ zaptest_chk(utf8[0x3u], 0xE0u,unsigned char,"%hhX")
+ zaptest_chk(utf8[0x4u], 0xB6u,unsigned char,"%hhX")
+ zaptest_chk(utf8[0x5u], 0x9Eu,unsigned char,"%hhX")
+ zaptest_chk(utf8[0x6u], 0xE2u,unsigned char,"%hhX")
+ zaptest_chk(utf8[0x7u], 0x86u,unsigned char,"%hhX")
+ zaptest_chk(utf8[0x8u], 0x8Au,unsigned char,"%hhX")
+ zaptest_chk(utf8[0x9u], 0xE2u,unsigned char,"%hhX")
+ zaptest_chk(utf8[0xAu], 0x86u,unsigned char,"%hhX")
+ zaptest_chk(utf8[0xBu], 0x8Bu,unsigned char,"%hhX")
+ zaptest_chk(utf8[0xCu], 0xF0u,unsigned char,"%hhX")
+ zaptest_chk(utf8[0xDu], 0x9Fu,unsigned char,"%hhX")
+ zaptest_chk(utf8[0xEu], 0x97u,unsigned char,"%hhX")
+ zaptest_chk(utf8[0xFu], 0xBFu,unsigned char,"%hhX")
+ zaptest_chk(utf8[0x10u],0x0u, unsigned char,"%hhX")
+ free(utf8);
+ return false;
+}
diff --git a/test/source/test/win1252dec.i b/test/source/test/win1252dec.i
new file mode 100644
index 0000000..23fbe2b
--- /dev/null
+++ b/test/source/test/win1252dec.i
@@ -0,0 +1,76 @@
+#include <inttypes.h>
+#include <stdbool.h>
+
+static bool zaptest_test_win1252dec(void) {
+ zap_chr8 const win1252[] = {
+ 0x26u,
+ 0xF0u,
+ 0x80u,
+ 0x82u,
+ 0x83u,
+ 0x84u,
+ 0x85u,
+ 0x86u,
+ 0x87u,
+ 0x88u,
+ 0x89u,
+ 0x8Au,
+ 0x8Bu,
+ 0x8Cu,
+ 0x8Eu,
+ 0x91u,
+ 0x92u,
+ 0x93u,
+ 0x94u,
+ 0x95u,
+ 0x96u,
+ 0x97u,
+ 0x98u,
+ 0x99u,
+ 0x9Au,
+ 0x9Bu,
+ 0x9Cu,
+ 0x9Eu,
+ 0x9Fu,
+ 0x0u,
+ };
+ zap_sz const enclen = sizeof (win1252) - 0x1u;
+ zaptest_chk(enclen,0x1Du,zap_sz,"%zX")
+ zap_chr20 * const utf20 = malloc(sizeof (zap_chr20) * (enclen + 0x1u));
+ if (utf20 == NULL) {
+ fputs("test.win1252dec: Memory allocation failed!\n\n",stderr);
+ return true;
+ }
+ zap_win1252dec(win1252,utf20);
+ zaptest_chk(utf20[0x0u], 0x26u, zap_chr20,"%" PRIXLEAST32);
+ zaptest_chk(utf20[0x1u], 0xF0u, zap_chr20,"%" PRIXLEAST32);
+ zaptest_chk(utf20[0x2u], 0x20ACu,zap_chr20,"%" PRIXLEAST32);
+ zaptest_chk(utf20[0x3u], 0x201Au,zap_chr20,"%" PRIXLEAST32);
+ zaptest_chk(utf20[0x4u], 0x192u, zap_chr20,"%" PRIXLEAST32);
+ zaptest_chk(utf20[0x5u], 0x201Eu,zap_chr20,"%" PRIXLEAST32);
+ zaptest_chk(utf20[0x6u], 0x2026u,zap_chr20,"%" PRIXLEAST32);
+ zaptest_chk(utf20[0x7u], 0x2020u,zap_chr20,"%" PRIXLEAST32);
+ zaptest_chk(utf20[0x8u], 0x2021u,zap_chr20,"%" PRIXLEAST32);
+ zaptest_chk(utf20[0x9u], 0x2C6u, zap_chr20,"%" PRIXLEAST32);
+ zaptest_chk(utf20[0xAu], 0x2030u,zap_chr20,"%" PRIXLEAST32);
+ zaptest_chk(utf20[0xBu], 0x160u, zap_chr20,"%" PRIXLEAST32);
+ zaptest_chk(utf20[0xCu], 0x2039u,zap_chr20,"%" PRIXLEAST32);
+ zaptest_chk(utf20[0xDu], 0x152u, zap_chr20,"%" PRIXLEAST32);
+ zaptest_chk(utf20[0xEu], 0x17Du, zap_chr20,"%" PRIXLEAST32);
+ zaptest_chk(utf20[0xFu], 0x2018u,zap_chr20,"%" PRIXLEAST32);
+ zaptest_chk(utf20[0x10u],0x2019u,zap_chr20,"%" PRIXLEAST32);
+ zaptest_chk(utf20[0x11u],0x201Cu,zap_chr20,"%" PRIXLEAST32);
+ zaptest_chk(utf20[0x12u],0x201Du,zap_chr20,"%" PRIXLEAST32);
+ zaptest_chk(utf20[0x13u],0x2022u,zap_chr20,"%" PRIXLEAST32);
+ zaptest_chk(utf20[0x14u],0x2013u,zap_chr20,"%" PRIXLEAST32);
+ zaptest_chk(utf20[0x15u],0x2014u,zap_chr20,"%" PRIXLEAST32);
+ zaptest_chk(utf20[0x16u],0x2DCu, zap_chr20,"%" PRIXLEAST32);
+ zaptest_chk(utf20[0x17u],0x2122u,zap_chr20,"%" PRIXLEAST32);
+ zaptest_chk(utf20[0x18u],0x161u, zap_chr20,"%" PRIXLEAST32);
+ zaptest_chk(utf20[0x19u],0x203Au,zap_chr20,"%" PRIXLEAST32);
+ zaptest_chk(utf20[0x1Au],0x153u, zap_chr20,"%" PRIXLEAST32);
+ zaptest_chk(utf20[0x1Bu],0x17Eu, zap_chr20,"%" PRIXLEAST32);
+ zaptest_chk(utf20[0x1Cu],0x178u, zap_chr20,"%" PRIXLEAST32);
+ zaptest_chk(utf20[0x1Du],0x0u, zap_chr20,"%" PRIXLEAST32);
+ return false;
+}
diff --git a/test/source/test/win1252enc.i b/test/source/test/win1252enc.i
new file mode 100644
index 0000000..2bfa211
--- /dev/null
+++ b/test/source/test/win1252enc.i
@@ -0,0 +1,76 @@
+#include <stdbool.h>
+
+static bool zaptest_test_win1252enc(void) {
+ zap_chr20 const utf20[] = {
+ 0x26u,
+ 0xF0u,
+ 0x20ACu,
+ 0x201Au,
+ 0x192u,
+ 0x201Eu,
+ 0x2026u,
+ 0x2020u,
+ 0x2021u,
+ 0x2C6u,
+ 0x2030u,
+ 0x160u,
+ 0x2039u,
+ 0x152u,
+ 0x17Du,
+ 0x2018u,
+ 0x2019u,
+ 0x201Cu,
+ 0x201Du,
+ 0x2022u,
+ 0x2013u,
+ 0x2014u,
+ 0x2DCu,
+ 0x2122u,
+ 0x161u,
+ 0x203Au,
+ 0x153u,
+ 0x17Eu,
+ 0x178u,
+ 0x0u,
+ };
+ zap_sz const enclen = sizeof (utf20) / sizeof (utf20[0x0u]) - 0x1u;
+ zaptest_chk(enclen,0x1Du,zap_sz,"%zX")
+ zap_chr8 * const win1252 = malloc(enclen + 0x1u);
+ if (win1252 == NULL) {
+ fputs("test.win1252enc: Memory allocation failed!\n\n",stderr);
+ return true;
+ }
+ zap_win1252enc(utf20,win1252);
+ zaptest_log(win1252,char const *,"%s"); /* UB? */
+ zaptest_chk(win1252[0x0u], 0x26u,unsigned char,"%hhX");
+ zaptest_chk(win1252[0x1u], 0xF0u,unsigned char,"%hhX");
+ zaptest_chk(win1252[0x2u], 0x80u,unsigned char,"%hhX");
+ zaptest_chk(win1252[0x3u], 0x82u,unsigned char,"%hhX");
+ zaptest_chk(win1252[0x4u], 0x83u,unsigned char,"%hhX");
+ zaptest_chk(win1252[0x5u], 0x84u,unsigned char,"%hhX");
+ zaptest_chk(win1252[0x6u], 0x85u,unsigned char,"%hhX");
+ zaptest_chk(win1252[0x7u], 0x86u,unsigned char,"%hhX");
+ zaptest_chk(win1252[0x8u], 0x87u,unsigned char,"%hhX");
+ zaptest_chk(win1252[0x9u], 0x88u,unsigned char,"%hhX");
+ zaptest_chk(win1252[0xAu], 0x89u,unsigned char,"%hhX");
+ zaptest_chk(win1252[0xBu], 0x8Au,unsigned char,"%hhX");
+ zaptest_chk(win1252[0xCu], 0x8Bu,unsigned char,"%hhX");
+ zaptest_chk(win1252[0xDu], 0x8Cu,unsigned char,"%hhX");
+ zaptest_chk(win1252[0xEu], 0x8Eu,unsigned char,"%hhX");
+ zaptest_chk(win1252[0xFu], 0x91u,unsigned char,"%hhX");
+ zaptest_chk(win1252[0x10u],0x92u,unsigned char,"%hhX");
+ zaptest_chk(win1252[0x11u],0x93u,unsigned char,"%hhX");
+ zaptest_chk(win1252[0x12u],0x94u,unsigned char,"%hhX");
+ zaptest_chk(win1252[0x13u],0x95u,unsigned char,"%hhX");
+ zaptest_chk(win1252[0x14u],0x96u,unsigned char,"%hhX");
+ zaptest_chk(win1252[0x15u],0x97u,unsigned char,"%hhX");
+ zaptest_chk(win1252[0x16u],0x98u,unsigned char,"%hhX");
+ zaptest_chk(win1252[0x17u],0x99u,unsigned char,"%hhX");
+ zaptest_chk(win1252[0x18u],0x9Au,unsigned char,"%hhX");
+ zaptest_chk(win1252[0x19u],0x9Bu,unsigned char,"%hhX");
+ zaptest_chk(win1252[0x1Au],0x9Cu,unsigned char,"%hhX");
+ zaptest_chk(win1252[0x1Bu],0x9Eu,unsigned char,"%hhX");
+ zaptest_chk(win1252[0x1Cu],0x9Fu,unsigned char,"%hhX");
+ zaptest_chk(win1252[0x1Du],0x0u, unsigned char,"%hhX");
+ return false;
+}