some tweaks
[mkp224o.git] / test_base16.c
blob7116a7788ca11569ac0d0e7bc9dbc2ecf8e6f3e8
1 #include <stddef.h>
2 #include <stdint.h>
3 #include "types.h"
4 #include "base16.h"
5 #include <string.h>
6 #include <assert.h>
7 #include <stdio.h>
9 /*
10 BASE16("") = ""
11 BASE16("f") = "66"
12 BASE16("fo") = "666F"
13 BASE16("foo") = "666F6F"
14 BASE16("foob") = "666F6F62"
15 BASE16("fooba") = "666F6F6261"
16 BASE16("foobar") = "666F6F626172"
19 struct texttestcase {
20 const char *in;
21 const char *out;
22 const char *rev;
23 } tests0[] = {
24 {"", "", ""},
25 {"f", "66", "f"},
26 {"fo", "666F", "fo"},
27 {"foo", "666F6F", "foo"},
28 {"foob", "666F6F62", "foob"},
29 {"fooba", "666F6F6261", "fooba"},
30 {"foobar", "666F6F626172", "foobar"},
33 int main(void)
35 char buf[1024], buf2[1024], mask;
36 size_t r;
37 for (size_t i = 0; i < sizeof(tests0)/sizeof(tests0[0]); ++i) {
38 base16_to(buf, (const u8 *)tests0[i].in, strlen(tests0[i].in));
39 assert(strcmp(buf, tests0[i].out) == 0);
40 r = base16_from((u8 *)buf2, (u8 *)&mask, buf);
41 buf2[r] = 0;
42 //fprintf(stderr, "r:%d, mask:%02X\n", (int)r, ((unsigned int)mask) & 0xFF);
43 //assert(r == strlen(buf2));
44 //assert(r == strlen(tests0[i].rev));
45 //fprintf(stderr, "%s -- %s\n", buf2, tests0[i].rev);
46 assert(strcmp(buf2, tests0[i].rev) == 0);
49 return 0;