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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
/* See LICENSE file for copyright and license details. */
#include "common.h"
#ifndef TEST
extern inline int libsimple_strnisutf8(const char *, size_t, int);
#else
#include "test.h"
int
main(void)
{
#define ASSERT(STRING, GOOD)\
do {\
assert(libsimple_strnisutf8(STRING, sizeof(STRING) - 1, i) == (GOOD));\
assert(libsimple_strnisutf8(STRING "\xFF", sizeof(STRING) - 1, i) == (GOOD));\
assert(libsimple_strnisutf8(STRING "\x00", sizeof(STRING) - 1, i) == (GOOD));\
} while (0)
int i;
for (i = 0; i < 2; i++) {
ASSERT("", 1);
ASSERT("a", 1);
ASSERT("abc", 1);
ASSERT("123", 1);
ASSERT("åäö", 1);
ASSERT("𝖆𝖇𝖈", 1);
ASSERT("\x1b", 1);
ASSERT("\n\r\t\f", 1);
ASSERT("\xFF", 0);
ASSERT("\x01", 1);
ASSERT("\x7F", 1);
ASSERT("\x80", 0);
ASSERT("\xC0", 0);
ASSERT("\xC0\x80", i);
ASSERT("\xC0\x81", 0);
ASSERT("\xCF", 0);
ASSERT("\xEF", 0);
ASSERT("\xEF\x8F", 0);
ASSERT("\xF7", 0);
ASSERT("\xF7\x8F", 0);
ASSERT("\xF7\x8F\x8F", 0);
ASSERT("\xFA", 0);
ASSERT("\xFA\x8F", 0);
ASSERT("\xFA\x8F\x8F", 0);
ASSERT("\xFA\x8F\x8F\x8F", 0);
ASSERT("\xFD", 0);
ASSERT("\xFD\x8F", 0);
ASSERT("\xFD\x8F\x8F", 0);
ASSERT("\xFD\x8F\x8F\x8F", 0);
ASSERT("\xFD\x8F\x8F\x8F\x8F", 0);
ASSERT("\xFE", 0);
ASSERT("\xFE\x8F", 0);
ASSERT("\xFE\x8F\x8F", 0);
ASSERT("\xFE\x8F\x8F\x8F", 0);
ASSERT("\xFE\x8F\x8F\x8F\x8F", 0);
ASSERT("\xFE\x8F\x8F\x8F\x8F\x8F", 0);
ASSERT("\xFF", 0);
ASSERT("\xFF\x8F", 0);
ASSERT("\xFF\x8F\x8F", 0);
ASSERT("\xFF\x8F\x8F\x8F", 0);
ASSERT("\xFF\x8F\x8F\x8F\x8F", 0);
ASSERT("\xFF\x8F\x8F\x8F\x8F\x8F", 0);
ASSERT("\xFF\x8F\x8F\x8F\x8F\x8F\x8F", 0);
ASSERT("\xC1\x80", 0);
ASSERT("\xC2\x80", 1);
ASSERT("\xE1\x80\x80\x80", 0);
ASSERT("\xE1\x80\xC0\x80", 0);
ASSERT("\xE1\x80\x00\x80", 0);
ASSERT("\xF1\x80\x80\x80", 1);
ASSERT("\xFF\x80\x80\x80\x80\x80\x80\x80", 0);
}
return 0;
}
#endif
|