1 #include <ccan/str/hex/hex.h>
2 /* Include the C files directly. */
3 #include <ccan/str/hex/hex.c>
4 #include <ccan/tap/tap.h>
9 const char teststr[] = "0123456789abcdefABCDEF";
10 const char bad_teststr[] = "0123456789abcdefABCDEF1O";
11 const unsigned char testdata[] = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab,
12 0xcd, 0xef, 0xAB, 0xCD, 0xEF };
13 unsigned char data[11];
17 plan_tests(10 + sizeof(str));
19 ok1(hex_str_size(sizeof(testdata)) == sizeof(teststr));
20 /* This gives right result with or without nul included */
21 ok1(hex_data_size(strlen(teststr)) == sizeof(testdata));
22 ok1(hex_data_size(sizeof(teststr)) == sizeof(testdata));
24 ok1(hex_decode(teststr, strlen(teststr), data, sizeof(data)));
25 ok1(memcmp(data, testdata, sizeof(testdata)) == 0);
26 ok1(hex_encode(testdata, sizeof(testdata), str, sizeof(str)));
27 ok1(strcmp(str, "0123456789abcdefabcdef") == 0);
30 ok1(!hex_decode(bad_teststr, strlen(bad_teststr), data, sizeof(data)));
31 /* Bad hex string len */
32 ok1(!hex_decode(teststr, strlen(teststr) - 1, data, sizeof(data)));
34 ok1(!hex_decode(teststr, strlen(teststr), data, sizeof(data) - 1));
36 /* Bad deststring size. */
37 for (i = 1; i <= sizeof(str); i++)
38 ok1(!hex_encode(testdata, sizeof(testdata), str, sizeof(str)-i));
40 /* This exits depending on whether all tests passed */