-
Notifications
You must be signed in to change notification settings - Fork 150
/
test_base16.c
50 lines (46 loc) · 1.17 KB
/
test_base16.c
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
#include <stddef.h>
#include <stdint.h>
#include "types.h"
#include "base16.h"
#include <string.h>
#include <assert.h>
#include <stdio.h>
/*
BASE16("") = ""
BASE16("f") = "66"
BASE16("fo") = "666F"
BASE16("foo") = "666F6F"
BASE16("foob") = "666F6F62"
BASE16("fooba") = "666F6F6261"
BASE16("foobar") = "666F6F626172"
*/
struct texttestcase {
const char *in;
const char *out;
const char *rev;
} tests0[] = {
{"", "", ""},
{"f", "66", "f"},
{"fo", "666F", "fo"},
{"foo", "666F6F", "foo"},
{"foob", "666F6F62", "foob"},
{"fooba", "666F6F6261", "fooba"},
{"foobar", "666F6F626172", "foobar"},
};
int main(void)
{
char buf[1024], buf2[1024], mask;
size_t r;
for (size_t i = 0; i < sizeof(tests0)/sizeof(tests0[0]); ++i) {
base16_to(buf, (const u8 *)tests0[i].in, strlen(tests0[i].in));
assert(strcmp(buf, tests0[i].out) == 0);
r = base16_from((u8 *)buf2, (u8 *)&mask, buf);
buf2[r] = 0;
//fprintf(stderr, "r:%d, mask:%02X\n", (int)r, ((unsigned int)mask) & 0xFF);
//assert(r == strlen(buf2));
//assert(r == strlen(tests0[i].rev));
//fprintf(stderr, "%s -- %s\n", buf2, tests0[i].rev);
assert(strcmp(buf2, tests0[i].rev) == 0);
}
return 0;
}