5 #include <UTF8String.h>
8 check(int expect_length, char *buf, int buflen) {
12 if(buflen < 0) buflen = strlen(buf);
14 st.buf = (uint8_t *)buf;
18 for(ret = 0; ret < buflen; ret++)
19 printf("%c", buf[ret]);
20 ret = UTF8String_length(&st);
21 printf("]: size=%d, expect=%d, got=%d\n",
22 buflen, expect_length, ret);
23 assert(ret == expect_length);
33 "a\303\237a\303\237a\303\237a\303\237"
34 "a\303\237a\303\237a\303\237a\303\237"
35 "a\303\237a\303\237a\303\237a\303\237"
36 "a\303\237a\303\237a\303\237a\303\237"
37 "a\303\237a\303\237a\303\237a\303\237";
41 st.buf = (uint8_t *)long_test;
42 st.size = sizeof(long_test) - 1;
44 ret = UTF8String_length(&st);
46 printf("Now wait a bit...\n");
49 start = tv.tv_sec + tv.tv_usec / 1000000.0;
50 for(i = 0; i < cycles; i++) {
51 ret += UTF8String_length(&st);
54 stop = tv.tv_sec + tv.tv_usec / 1000000.0;
56 printf("%d cycles in %.3fms\n", cycles, stop - start);
69 assert(sizeof("a\303\237cd") == 6);
70 check(4, "a\303\237cd", 5);
71 check(3, "a\370\211\200\201\257c", 7);
72 check(3, "\320\273\320\265\320\262", 6);
74 check(-1, "a\303", 2); /* Truncated */
75 check(-2, "\377", 1); /* Invalid UTF-8 sequence start */
77 check(-2, "\320\273\265\320\262", 5);
78 check(-3, "\320c", 2); /* Not continuation */
79 check(-3, "a\370\200\200\200c", 6);
80 check(-4, "a\370\200\200\200\257c", 7);
81 check(-4, "\320\273\320\265\340\200\262", 7);