This source file includes following definitions.
- test_safe_function
- main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 #include <config.h>
20
21 #include "unistr.h"
22
23 #include "macros.h"
24
25 #include "test-u8-mbtouc.h"
26
27 static void
28 test_safe_function (int (*my_u8_mbtouc) (ucs4_t *, const uint8_t *, size_t))
29 {
30 ucs4_t uc;
31 int ret;
32
33
34
35
36
37
38
39
40
41
42
43 {
44 static const uint8_t input[] = { '"', 0x80, 0xBF, 0x80, 0xBF, '"' };
45 uc = 0xBADFACE;
46 ret = my_u8_mbtouc (&uc, input, 6);
47 ASSERT (ret == 1);
48 ASSERT (uc == 0x0022);
49 uc = 0xBADFACE;
50 ret = my_u8_mbtouc (&uc, input + 1, 5);
51 ASSERT (ret == 1);
52 ASSERT (uc == 0xFFFD);
53 uc = 0xBADFACE;
54 ret = my_u8_mbtouc (&uc, input + 2, 4);
55 ASSERT (ret == 1);
56 ASSERT (uc == 0xFFFD);
57 uc = 0xBADFACE;
58 ret = my_u8_mbtouc (&uc, input + 3, 3);
59 ASSERT (ret == 1);
60 ASSERT (uc == 0xFFFD);
61 uc = 0xBADFACE;
62 ret = my_u8_mbtouc (&uc, input + 4, 2);
63 ASSERT (ret == 1);
64 ASSERT (uc == 0xFFFD);
65 uc = 0xBADFACE;
66 ret = my_u8_mbtouc (&uc, input + 5, 1);
67 ASSERT (ret == 1);
68 ASSERT (uc == 0x0022);
69 }
70
71 {
72 ucs4_t c;
73 uint8_t input[2];
74
75 for (c = 0xC0; c <= 0xFF; c++)
76 {
77 input[0] = c;
78 input[1] = ' ';
79
80 uc = 0xBADFACE;
81 ret = my_u8_mbtouc (&uc, input, 2);
82 ASSERT (ret == 1);
83 ASSERT (uc == 0xFFFD);
84 }
85 }
86
87
88 {
89 static const uint8_t input[] = { '"', 0xC0, '"' };
90 uc = 0xBADFACE;
91 ret = my_u8_mbtouc (&uc, input, 3);
92 ASSERT (ret == 1);
93 ASSERT (uc == 0x0022);
94 uc = 0xBADFACE;
95 ret = my_u8_mbtouc (&uc, input + 1, 2);
96 ASSERT (ret == 1);
97 ASSERT (uc == 0xFFFD);
98 uc = 0xBADFACE;
99 ret = my_u8_mbtouc (&uc, input + 2, 1);
100 ASSERT (ret == 1);
101 ASSERT (uc == 0x0022);
102 }
103
104 {
105 static const uint8_t input[] = { '"', 0xDF, '"' };
106 uc = 0xBADFACE;
107 ret = my_u8_mbtouc (&uc, input, 3);
108 ASSERT (ret == 1);
109 ASSERT (uc == 0x0022);
110 uc = 0xBADFACE;
111 ret = my_u8_mbtouc (&uc, input + 1, 2);
112 ASSERT (ret == 1);
113 ASSERT (uc == 0xFFFD);
114 uc = 0xBADFACE;
115 ret = my_u8_mbtouc (&uc, input + 2, 1);
116 ASSERT (ret == 1);
117 ASSERT (uc == 0x0022);
118 }
119
120 {
121 static const uint8_t input[] = { '"', 0xE0, 0x80, '"' };
122 uc = 0xBADFACE;
123 ret = my_u8_mbtouc (&uc, input, 4);
124 ASSERT (ret == 1);
125 ASSERT (uc == 0x0022);
126 uc = 0xBADFACE;
127 ret = my_u8_mbtouc (&uc, input + 1, 3);
128 ASSERT (ret == 2);
129 ASSERT (uc == 0xFFFD);
130 uc = 0xBADFACE;
131 ret = my_u8_mbtouc (&uc, input + 3, 1);
132 ASSERT (ret == 1);
133 ASSERT (uc == 0x0022);
134 }
135
136 {
137 static const uint8_t input[] = { '"', 0xEF, 0xBF, '"' };
138 uc = 0xBADFACE;
139 ret = my_u8_mbtouc (&uc, input, 4);
140 ASSERT (ret == 1);
141 ASSERT (uc == 0x0022);
142 uc = 0xBADFACE;
143 ret = my_u8_mbtouc (&uc, input + 1, 3);
144 ASSERT (ret == 2);
145 ASSERT (uc == 0xFFFD);
146 uc = 0xBADFACE;
147 ret = my_u8_mbtouc (&uc, input + 3, 1);
148 ASSERT (ret == 1);
149 ASSERT (uc == 0x0022);
150 }
151
152 {
153 static const uint8_t input[] = { '"', 0xF0, 0x80, 0x80, '"' };
154 uc = 0xBADFACE;
155 ret = my_u8_mbtouc (&uc, input, 5);
156 ASSERT (ret == 1);
157 ASSERT (uc == 0x0022);
158 uc = 0xBADFACE;
159 ret = my_u8_mbtouc (&uc, input + 1, 4);
160 ASSERT (ret == 3);
161 ASSERT (uc == 0xFFFD);
162 uc = 0xBADFACE;
163 ret = my_u8_mbtouc (&uc, input + 4, 1);
164 ASSERT (ret == 1);
165 ASSERT (uc == 0x0022);
166 }
167
168 {
169 static const uint8_t input[] = { '"', 0xF7, 0xBF, 0xBF, '"' };
170 uc = 0xBADFACE;
171 ret = my_u8_mbtouc (&uc, input, 5);
172 ASSERT (ret == 1);
173 ASSERT (uc == 0x0022);
174 uc = 0xBADFACE;
175 ret = my_u8_mbtouc (&uc, input + 1, 4);
176 ASSERT (ret == 3);
177 ASSERT (uc == 0xFFFD);
178 uc = 0xBADFACE;
179 ret = my_u8_mbtouc (&uc, input + 4, 1);
180 ASSERT (ret == 1);
181 ASSERT (uc == 0x0022);
182 }
183 }
184
185 int
186 main ()
187 {
188 test_function (u8_mbtouc);
189 test_safe_function (u8_mbtouc);
190
191 return 0;
192 }