ccan: make tal_dump() format more regular.
[ccan] / ccan / utf8 / test / run-encode-decode.c
1 #include <ccan/utf8/utf8.h>
2 /* Include the C files directly. */
3 #include <ccan/utf8/utf8.c>
4 #include <ccan/tap/tap.h>
5 #include <assert.h>
6
7 static bool utf8_check(const char *src, size_t len)
8 {
9         bool decoded = false;
10         struct utf8_state utf8_state = UTF8_STATE_INIT;
11         size_t i;
12
13         for (i = 0; i < len; i++) {
14                 decoded = utf8_decode(&utf8_state, src[i]);
15                 if (decoded) {
16                         if (errno != 0)
17                                 return false;
18                 }
19         }
20         if (!decoded)
21                 return false;
22         return true;
23 }
24
25 int main(int argc, char **argv)
26 {
27         int i;
28         char dest[UTF8_MAX_LEN];
29         
30         plan_tests(0x10FFFF - (0xDFFF - 0xD7FF + 2));
31
32         for (i = 1; i < 0x10FFFF; i++) {
33                 int len;
34                 if (i >= 0xD7FF && i <= 0xDFFF)
35                         continue;
36                 len = utf8_encode(i, dest);
37                 assert(len != 0);
38                 ok1(utf8_check(dest, len));
39         }
40
41         return exit_status();
42 }