[PowerPC][NFC] Cleanup PPCCTRLoopsVerify pass
[llvm-project.git] / libcxx / test / std / localization / locale.stdcvt / codecvt_utf16_length.pass.cpp
blobcaec8ea7347133aa1310888b4bf92fef1efe026a
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 // <codecvt>
11 // template <class Elem, unsigned long Maxcode = 0x10ffff,
12 // codecvt_mode Mode = (codecvt_mode)0>
13 // class codecvt_utf16
14 // : public codecvt<Elem, char, mbstate_t>
15 // {
16 // // unspecified
17 // };
19 // int length(stateT& state, const externT* from, const externT* from_end,
20 // size_t max) const;
22 #include <codecvt>
23 #include <cassert>
25 #include "test_macros.h"
27 int main(int, char**)
30 typedef std::codecvt_utf16<wchar_t> C;
31 C c;
32 char n[4] = {char(0xD8), char(0xC0), char(0xDC), char(0x03)};
33 std::mbstate_t m;
34 int r = c.length(m, n, n+4, 2);
35 assert(r == 4);
37 n[0] = char(0x10);
38 n[1] = char(0x05);
39 r = c.length(m, n, n+2, 2);
40 assert(r == 2);
42 n[0] = char(0x04);
43 n[1] = char(0x53);
44 r = c.length(m, n, n+2, 2);
45 assert(r == 2);
47 n[0] = char(0x00);
48 n[1] = char(0x56);
49 r = c.length(m, n, n+2, 2);
50 assert(r == 2);
53 typedef std::codecvt_utf16<wchar_t, 0x1000> C;
54 C c;
55 char n[4] = {char(0xD8), char(0xC0), char(0xDC), char(0x03)};
56 std::mbstate_t m;
57 int r = c.length(m, n, n+4, 2);
58 assert(r == 0);
60 n[0] = char(0x10);
61 n[1] = char(0x05);
62 r = c.length(m, n, n+2, 2);
63 assert(r == 0);
65 n[0] = char(0x04);
66 n[1] = char(0x53);
67 r = c.length(m, n, n+2, 2);
68 assert(r == 2);
70 n[0] = char(0x00);
71 n[1] = char(0x56);
72 r = c.length(m, n, n+2, 2);
73 assert(r == 2);
76 typedef std::codecvt_utf16<wchar_t, 0x10ffff, std::consume_header> C;
77 C c;
78 char n[6] = {char(0xFE), char(0xFF), char(0xD8), char(0xC0), char(0xDC), char(0x03)};
79 std::mbstate_t m;
80 int r = c.length(m, n, n+6, 2);
81 assert(r == 6);
83 n[0] = char(0x10);
84 n[1] = char(0x05);
85 r = c.length(m, n, n+2, 2);
86 assert(r == 2);
88 n[0] = char(0x04);
89 n[1] = char(0x53);
90 r = c.length(m, n, n+2, 2);
91 assert(r == 2);
93 n[0] = char(0x00);
94 n[1] = char(0x56);
95 r = c.length(m, n, n+2, 2);
96 assert(r == 2);
99 typedef std::codecvt_utf16<wchar_t, 0x10ffff, std::little_endian> C;
100 C c;
101 char n[4] = {char(0xC0), char(0xD8), char(0x03), char(0xDC)};
102 std::mbstate_t m;
103 int r = c.length(m, n, n+4, 2);
104 assert(r == 4);
106 n[1] = char(0x10);
107 n[0] = char(0x05);
108 r = c.length(m, n, n+2, 2);
109 assert(r == 2);
111 n[1] = char(0x04);
112 n[0] = char(0x53);
113 r = c.length(m, n, n+2, 2);
114 assert(r == 2);
116 n[1] = char(0x00);
117 n[0] = char(0x56);
118 r = c.length(m, n, n+2, 2);
119 assert(r == 2);
122 typedef std::codecvt_utf16<wchar_t, 0x1000, std::little_endian> C;
123 C c;
124 char n[4] = {char(0xC0), char(0xD8), char(0x03), char(0xDC)};
125 std::mbstate_t m;
126 int r = c.length(m, n, n+4, 2);
127 assert(r == 0);
129 n[1] = char(0x10);
130 n[0] = char(0x05);
131 r = c.length(m, n, n+2, 2);
132 assert(r == 0);
134 n[1] = char(0x04);
135 n[0] = char(0x53);
136 r = c.length(m, n, n+2, 2);
137 assert(r == 2);
139 n[1] = char(0x00);
140 n[0] = char(0x56);
141 r = c.length(m, n, n+2, 2);
142 assert(r == 2);
145 typedef std::codecvt_utf16<wchar_t, 0x10ffff, std::codecvt_mode(
146 std::consume_header |
147 std::little_endian)> C;
148 C c;
149 char n[6] = {char(0xFF), char(0xFE), char(0xC0), char(0xD8), char(0x03), char(0xDC)};
150 std::mbstate_t m;
151 int r = c.length(m, n, n+6, 2);
152 assert(r == 6);
154 n[1] = char(0x10);
155 n[0] = char(0x05);
156 r = c.length(m, n, n+2, 2);
157 assert(r == 2);
159 n[1] = char(0x04);
160 n[0] = char(0x53);
161 r = c.length(m, n, n+2, 2);
162 assert(r == 2);
164 n[1] = char(0x00);
165 n[0] = char(0x56);
166 r = c.length(m, n, n+2, 2);
167 assert(r == 2);
170 typedef std::codecvt_utf16<char32_t> C;
171 C c;
172 char n[4] = {char(0xD8), char(0xC0), char(0xDC), char(0x03)};
173 std::mbstate_t m;
174 int r = c.length(m, n, n+4, 2);
175 assert(r == 4);
177 n[0] = char(0x10);
178 n[1] = char(0x05);
179 r = c.length(m, n, n+2, 2);
180 assert(r == 2);
182 n[0] = char(0x04);
183 n[1] = char(0x53);
184 r = c.length(m, n, n+2, 2);
185 assert(r == 2);
187 n[0] = char(0x00);
188 n[1] = char(0x56);
189 r = c.length(m, n, n+2, 2);
190 assert(r == 2);
193 typedef std::codecvt_utf16<char32_t, 0x1000> C;
194 C c;
195 char n[4] = {char(0xD8), char(0xC0), char(0xDC), char(0x03)};
196 std::mbstate_t m;
197 int r = c.length(m, n, n+4, 2);
198 assert(r == 0);
200 n[0] = char(0x10);
201 n[1] = char(0x05);
202 r = c.length(m, n, n+2, 2);
203 assert(r == 0);
205 n[0] = char(0x04);
206 n[1] = char(0x53);
207 r = c.length(m, n, n+2, 2);
208 assert(r == 2);
210 n[0] = char(0x00);
211 n[1] = char(0x56);
212 r = c.length(m, n, n+2, 2);
213 assert(r == 2);
216 typedef std::codecvt_utf16<char32_t, 0x10ffff, std::consume_header> C;
217 C c;
218 char n[6] = {char(0xFE), char(0xFF), char(0xD8), char(0xC0), char(0xDC), char(0x03)};
219 std::mbstate_t m;
220 int r = c.length(m, n, n+6, 2);
221 assert(r == 6);
223 n[0] = char(0x10);
224 n[1] = char(0x05);
225 r = c.length(m, n, n+2, 2);
226 assert(r == 2);
228 n[0] = char(0x04);
229 n[1] = char(0x53);
230 r = c.length(m, n, n+2, 2);
231 assert(r == 2);
233 n[0] = char(0x00);
234 n[1] = char(0x56);
235 r = c.length(m, n, n+2, 2);
236 assert(r == 2);
239 typedef std::codecvt_utf16<char32_t, 0x10ffff, std::little_endian> C;
240 C c;
241 char n[4] = {char(0xC0), char(0xD8), char(0x03), char(0xDC)};
242 std::mbstate_t m;
243 int r = c.length(m, n, n+4, 2);
244 assert(r == 4);
246 n[1] = char(0x10);
247 n[0] = char(0x05);
248 r = c.length(m, n, n+2, 2);
249 assert(r == 2);
251 n[1] = char(0x04);
252 n[0] = char(0x53);
253 r = c.length(m, n, n+2, 2);
254 assert(r == 2);
256 n[1] = char(0x00);
257 n[0] = char(0x56);
258 r = c.length(m, n, n+2, 2);
259 assert(r == 2);
262 typedef std::codecvt_utf16<char32_t, 0x1000, std::little_endian> C;
263 C c;
264 char n[4] = {char(0xC0), char(0xD8), char(0x03), char(0xDC)};
265 std::mbstate_t m;
266 int r = c.length(m, n, n+4, 2);
267 assert(r == 0);
269 n[1] = char(0x10);
270 n[0] = char(0x05);
271 r = c.length(m, n, n+2, 2);
272 assert(r == 0);
274 n[1] = char(0x04);
275 n[0] = char(0x53);
276 r = c.length(m, n, n+2, 2);
277 assert(r == 2);
279 n[1] = char(0x00);
280 n[0] = char(0x56);
281 r = c.length(m, n, n+2, 2);
282 assert(r == 2);
285 typedef std::codecvt_utf16<char32_t, 0x10ffff, std::codecvt_mode(
286 std::consume_header |
287 std::little_endian)> C;
288 C c;
289 char n[6] = {char(0xFF), char(0xFE), char(0xC0), char(0xD8), char(0x03), char(0xDC)};
290 std::mbstate_t m;
291 int r = c.length(m, n, n+6, 2);
292 assert(r == 6);
294 n[1] = char(0x10);
295 n[0] = char(0x05);
296 r = c.length(m, n, n+2, 2);
297 assert(r == 2);
299 n[1] = char(0x04);
300 n[0] = char(0x53);
301 r = c.length(m, n, n+2, 2);
302 assert(r == 2);
304 n[1] = char(0x00);
305 n[0] = char(0x56);
306 r = c.length(m, n, n+2, 2);
307 assert(r == 2);
311 typedef std::codecvt_utf16<char16_t> C;
312 C c;
313 char n[4] = {char(0xD8), char(0xC0), char(0xDC), char(0x03)};
314 std::mbstate_t m;
315 int r = c.length(m, n, n+4, 2);
316 assert(r == 0);
318 n[0] = char(0x10);
319 n[1] = char(0x05);
320 r = c.length(m, n, n+2, 2);
321 assert(r == 2);
323 n[0] = char(0x04);
324 n[1] = char(0x53);
325 r = c.length(m, n, n+2, 2);
326 assert(r == 2);
328 n[0] = char(0x00);
329 n[1] = char(0x56);
330 r = c.length(m, n, n+2, 2);
331 assert(r == 2);
334 typedef std::codecvt_utf16<char16_t, 0x1000> C;
335 C c;
336 char n[4] = {char(0xD8), char(0xC0), char(0xDC), char(0x03)};
337 std::mbstate_t m;
338 int r = c.length(m, n, n+4, 2);
339 assert(r == 0);
341 n[0] = char(0x10);
342 n[1] = char(0x05);
343 r = c.length(m, n, n+2, 2);
344 assert(r == 0);
346 n[0] = char(0x04);
347 n[1] = char(0x53);
348 r = c.length(m, n, n+2, 2);
349 assert(r == 2);
351 n[0] = char(0x00);
352 n[1] = char(0x56);
353 r = c.length(m, n, n+2, 2);
354 assert(r == 2);
357 typedef std::codecvt_utf16<char16_t, 0x10ffff, std::consume_header> C;
358 C c;
359 char n[6] = {char(0xFE), char(0xFF), char(0xD8), char(0xC0), char(0xDC), char(0x03)};
360 std::mbstate_t m;
361 int r = c.length(m, n, n+6, 2);
362 assert(r == 2);
364 n[0] = char(0x10);
365 n[1] = char(0x05);
366 r = c.length(m, n, n+2, 2);
367 assert(r == 2);
369 n[0] = char(0x04);
370 n[1] = char(0x53);
371 r = c.length(m, n, n+2, 2);
372 assert(r == 2);
374 n[0] = char(0x00);
375 n[1] = char(0x56);
376 r = c.length(m, n, n+2, 2);
377 assert(r == 2);
380 typedef std::codecvt_utf16<char16_t, 0x10ffff, std::little_endian> C;
381 C c;
382 char n[4] = {char(0xC0), char(0xD8), char(0x03), char(0xDC)};
383 std::mbstate_t m;
384 int r = c.length(m, n, n+4, 2);
385 assert(r == 0);
387 n[1] = char(0x10);
388 n[0] = char(0x05);
389 r = c.length(m, n, n+2, 2);
390 assert(r == 2);
392 n[1] = char(0x04);
393 n[0] = char(0x53);
394 r = c.length(m, n, n+2, 2);
395 assert(r == 2);
397 n[1] = char(0x00);
398 n[0] = char(0x56);
399 r = c.length(m, n, n+2, 2);
400 assert(r == 2);
403 typedef std::codecvt_utf16<char16_t, 0x1000, std::little_endian> C;
404 C c;
405 char n[4] = {char(0xC0), char(0xD8), char(0x03), char(0xDC)};
406 std::mbstate_t m;
407 int r = c.length(m, n, n+4, 2);
408 assert(r == 0);
410 n[1] = char(0x10);
411 n[0] = char(0x05);
412 r = c.length(m, n, n+2, 2);
413 assert(r == 0);
415 n[1] = char(0x04);
416 n[0] = char(0x53);
417 r = c.length(m, n, n+2, 2);
418 assert(r == 2);
420 n[1] = char(0x00);
421 n[0] = char(0x56);
422 r = c.length(m, n, n+2, 2);
423 assert(r == 2);
426 typedef std::codecvt_utf16<char16_t, 0x10ffff, std::codecvt_mode(
427 std::consume_header |
428 std::little_endian)> C;
429 C c;
430 char n[6] = {char(0xFF), char(0xFE), char(0xC0), char(0xD8), char(0x03), char(0xDC)};
431 std::mbstate_t m;
432 int r = c.length(m, n, n+6, 2);
433 assert(r == 2);
435 n[1] = char(0x10);
436 n[0] = char(0x05);
437 r = c.length(m, n, n+2, 2);
438 assert(r == 2);
440 n[1] = char(0x04);
441 n[0] = char(0x53);
442 r = c.length(m, n, n+2, 2);
443 assert(r == 2);
445 n[1] = char(0x00);
446 n[0] = char(0x56);
447 r = c.length(m, n, n+2, 2);
448 assert(r == 2);
451 return 0;