1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
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>
21 // const externT* from, const externT* from_end, const externT*& from_next,
22 // internT* to, internT* to_end, internT*& to_next) const;
27 #include "test_macros.h"
32 typedef std::codecvt_utf16
<char32_t
> C
;
35 char n
[4] = {char(0xD8), char(0xC0), char(0xDC), char(0x03)};
36 char32_t
* wp
= nullptr;
38 const char* np
= nullptr;
39 std::codecvt_base::result r
= c
.in(m
, n
, n
+4, np
, &w
, &w
+1, wp
);
40 assert(r
== std::codecvt_base::ok
);
47 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
48 assert(r
== std::codecvt_base::ok
);
55 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
56 assert(r
== std::codecvt_base::ok
);
64 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
65 assert(r
== std::codecvt_base::ok
);
71 typedef std::codecvt_utf16
<char32_t
, 0x1000> C
;
74 char n
[4] = {char(0xD8), char(0xC0), char(0xDC), char(0x03)};
75 char32_t
* wp
= nullptr;
77 const char* np
= nullptr;
78 std::codecvt_base::result r
= c
.in(m
, n
, n
+4, np
, &w
, &w
+1, wp
);
79 assert(r
== std::codecvt_base::error
);
86 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
87 assert(r
== std::codecvt_base::error
);
94 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
95 assert(r
== std::codecvt_base::ok
);
103 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
104 assert(r
== std::codecvt_base::ok
);
110 typedef std::codecvt_utf16
<char32_t
, 0x10ffff, std::consume_header
> C
;
113 char n
[6] = {char(0xFE), char(0xFF), char(0xD8), char(0xC0), char(0xDC), char(0x03)};
114 char32_t
* wp
= nullptr;
116 const char* np
= nullptr;
117 std::codecvt_base::result r
= c
.in(m
, n
, n
+6, np
, &w
, &w
+1, wp
);
118 assert(r
== std::codecvt_base::ok
);
121 assert(w
== 0x40003);
125 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
126 assert(r
== std::codecvt_base::ok
);
133 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
134 assert(r
== std::codecvt_base::ok
);
142 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
143 assert(r
== std::codecvt_base::ok
);
149 typedef std::codecvt_utf16
<char32_t
, 0x10ffff, std::little_endian
> C
;
152 char n
[4] = {char(0xC0), char(0xD8), char(0x03), char(0xDC)};
153 char32_t
* wp
= nullptr;
155 const char* np
= nullptr;
156 std::codecvt_base::result r
= c
.in(m
, n
, n
+4, np
, &w
, &w
+1, wp
);
157 assert(r
== std::codecvt_base::ok
);
160 assert(w
== 0x40003);
164 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
165 assert(r
== std::codecvt_base::ok
);
172 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
173 assert(r
== std::codecvt_base::ok
);
181 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
182 assert(r
== std::codecvt_base::ok
);
188 typedef std::codecvt_utf16
<char32_t
, 0x1000, std::little_endian
> C
;
191 char n
[4] = {char(0xC0), char(0xD8), char(0x03), char(0xDC)};
192 char32_t
* wp
= nullptr;
194 const char* np
= nullptr;
195 std::codecvt_base::result r
= c
.in(m
, n
, n
+4, np
, &w
, &w
+1, wp
);
196 assert(r
== std::codecvt_base::error
);
203 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
204 assert(r
== std::codecvt_base::error
);
211 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
212 assert(r
== std::codecvt_base::ok
);
220 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
221 assert(r
== std::codecvt_base::ok
);
227 typedef std::codecvt_utf16
<char32_t
, 0x10ffff,
228 std::codecvt_mode(std::consume_header
| std::little_endian
)> C
;
232 char n
[6] = {char(0xFF), char(0xFE), char(0xC0), char(0xD8), char(0x03), char(0xDC)};
233 char32_t
* wp
= nullptr;
235 const char* np
= nullptr;
236 std::codecvt_base::result r
= c
.in(m
, n
, n
+6, np
, &w
, &w
+1, wp
);
237 assert(r
== std::codecvt_base::ok
);
240 assert(w
== 0x40003);
244 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
245 assert(r
== std::codecvt_base::ok
);
252 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
253 assert(r
== std::codecvt_base::ok
);
261 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
262 assert(r
== std::codecvt_base::ok
);
268 typedef std::codecvt_utf16
<char32_t
> C
;
271 char n
[4] = {char(0xD8), char(0xC0), char(0xDC), char(0x03)};
272 char32_t
* wp
= nullptr;
274 const char* np
= nullptr;
275 std::codecvt_base::result r
= c
.in(m
, n
, n
+4, np
, &w
, &w
+1, wp
);
276 assert(r
== std::codecvt_base::ok
);
279 assert(w
== 0x40003);
283 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
284 assert(r
== std::codecvt_base::ok
);
291 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
292 assert(r
== std::codecvt_base::ok
);
300 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
301 assert(r
== std::codecvt_base::ok
);
307 typedef std::codecvt_utf16
<char32_t
, 0x1000> C
;
310 char n
[4] = {char(0xD8), char(0xC0), char(0xDC), char(0x03)};
311 char32_t
* wp
= nullptr;
313 const char* np
= nullptr;
314 std::codecvt_base::result r
= c
.in(m
, n
, n
+4, np
, &w
, &w
+1, wp
);
315 assert(r
== std::codecvt_base::error
);
322 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
323 assert(r
== std::codecvt_base::error
);
330 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
331 assert(r
== std::codecvt_base::ok
);
339 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
340 assert(r
== std::codecvt_base::ok
);
346 typedef std::codecvt_utf16
<char32_t
, 0x10ffff, std::consume_header
> C
;
349 char n
[6] = {char(0xFE), char(0xFF), char(0xD8), char(0xC0), char(0xDC), char(0x03)};
350 char32_t
* wp
= nullptr;
352 const char* np
= nullptr;
353 std::codecvt_base::result r
= c
.in(m
, n
, n
+6, np
, &w
, &w
+1, wp
);
354 assert(r
== std::codecvt_base::ok
);
357 assert(w
== 0x40003);
361 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
362 assert(r
== std::codecvt_base::ok
);
369 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
370 assert(r
== std::codecvt_base::ok
);
378 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
379 assert(r
== std::codecvt_base::ok
);
385 typedef std::codecvt_utf16
<char32_t
, 0x10ffff, std::little_endian
> C
;
388 char n
[4] = {char(0xC0), char(0xD8), char(0x03), char(0xDC)};
389 char32_t
* wp
= nullptr;
391 const char* np
= nullptr;
392 std::codecvt_base::result r
= c
.in(m
, n
, n
+4, np
, &w
, &w
+1, wp
);
393 assert(r
== std::codecvt_base::ok
);
396 assert(w
== 0x40003);
400 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
401 assert(r
== std::codecvt_base::ok
);
408 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
409 assert(r
== std::codecvt_base::ok
);
417 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
418 assert(r
== std::codecvt_base::ok
);
424 typedef std::codecvt_utf16
<char32_t
, 0x1000, std::little_endian
> C
;
427 char n
[4] = {char(0xC0), char(0xD8), char(0x03), char(0xDC)};
428 char32_t
* wp
= nullptr;
430 const char* np
= nullptr;
431 std::codecvt_base::result r
= c
.in(m
, n
, n
+4, np
, &w
, &w
+1, wp
);
432 assert(r
== std::codecvt_base::error
);
439 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
440 assert(r
== std::codecvt_base::error
);
447 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
448 assert(r
== std::codecvt_base::ok
);
456 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
457 assert(r
== std::codecvt_base::ok
);
463 typedef std::codecvt_utf16
<char32_t
, 0x10ffff, std::codecvt_mode(
464 std::consume_header
|
465 std::little_endian
)> C
;
468 char n
[6] = {char(0xFF), char(0xFE), char(0xC0), char(0xD8), char(0x03), char(0xDC)};
469 char32_t
* wp
= nullptr;
471 const char* np
= nullptr;
472 std::codecvt_base::result r
= c
.in(m
, n
, n
+6, np
, &w
, &w
+1, wp
);
473 assert(r
== std::codecvt_base::ok
);
476 assert(w
== 0x40003);
480 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
481 assert(r
== std::codecvt_base::ok
);
488 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
489 assert(r
== std::codecvt_base::ok
);
497 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
498 assert(r
== std::codecvt_base::ok
);
505 typedef std::codecvt_utf16
<char16_t
> C
;
508 char n
[4] = {char(0xD8), char(0xC0), char(0xDC), char(0x03)};
509 char16_t
* wp
= nullptr;
511 const char* np
= nullptr;
512 std::codecvt_base::result r
= c
.in(m
, n
, n
+4, np
, &w
, &w
+1, wp
);
513 assert(r
== std::codecvt_base::error
);
520 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
521 assert(r
== std::codecvt_base::ok
);
528 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
529 assert(r
== std::codecvt_base::ok
);
537 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
538 assert(r
== std::codecvt_base::ok
);
544 typedef std::codecvt_utf16
<char16_t
, 0x1000> C
;
547 char n
[4] = {char(0xD8), char(0xC0), char(0xDC), char(0x03)};
548 char16_t
* wp
= nullptr;
550 const char* np
= nullptr;
551 std::codecvt_base::result r
= c
.in(m
, n
, n
+4, np
, &w
, &w
+1, wp
);
552 assert(r
== std::codecvt_base::error
);
559 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
560 assert(r
== std::codecvt_base::error
);
567 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
568 assert(r
== std::codecvt_base::ok
);
576 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
577 assert(r
== std::codecvt_base::ok
);
583 typedef std::codecvt_utf16
<char16_t
, 0x10ffff, std::consume_header
> C
;
586 char n
[6] = {char(0xFE), char(0xFF), char(0xD8), char(0xC0), char(0xDC), char(0x03)};
587 char16_t
* wp
= nullptr;
589 const char* np
= nullptr;
590 std::codecvt_base::result r
= c
.in(m
, n
, n
+6, np
, &w
, &w
+1, wp
);
591 assert(r
== std::codecvt_base::error
);
598 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
599 assert(r
== std::codecvt_base::ok
);
606 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
607 assert(r
== std::codecvt_base::ok
);
615 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
616 assert(r
== std::codecvt_base::ok
);
622 typedef std::codecvt_utf16
<char16_t
, 0x10ffff, std::little_endian
> C
;
625 char n
[4] = {char(0xC0), char(0xD8), char(0x03), char(0xDC)};
626 char16_t
* wp
= nullptr;
628 const char* np
= nullptr;
629 std::codecvt_base::result r
= c
.in(m
, n
, n
+4, np
, &w
, &w
+1, wp
);
630 assert(r
== std::codecvt_base::error
);
637 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
638 assert(r
== std::codecvt_base::ok
);
645 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
646 assert(r
== std::codecvt_base::ok
);
654 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
655 assert(r
== std::codecvt_base::ok
);
661 typedef std::codecvt_utf16
<char16_t
, 0x1000, std::little_endian
> C
;
664 char n
[4] = {char(0xC0), char(0xD8), char(0x03), char(0xDC)};
665 char16_t
* wp
= nullptr;
667 const char* np
= nullptr;
668 std::codecvt_base::result r
= c
.in(m
, n
, n
+4, np
, &w
, &w
+1, wp
);
669 assert(r
== std::codecvt_base::error
);
676 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
677 assert(r
== std::codecvt_base::error
);
684 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
685 assert(r
== std::codecvt_base::ok
);
693 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
694 assert(r
== std::codecvt_base::ok
);
700 typedef std::codecvt_utf16
<char16_t
, 0x10ffff, std::codecvt_mode(
701 std::consume_header
|
702 std::little_endian
)> C
;
705 char n
[6] = {char(0xFF), char(0xFE), char(0xC0), char(0xD8), char(0x03), char(0xDC)};
706 char16_t
* wp
= nullptr;
708 const char* np
= nullptr;
709 std::codecvt_base::result r
= c
.in(m
, n
, n
+6, np
, &w
, &w
+1, wp
);
710 assert(r
== std::codecvt_base::error
);
717 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
718 assert(r
== std::codecvt_base::ok
);
725 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
726 assert(r
== std::codecvt_base::ok
);
734 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
735 assert(r
== std::codecvt_base::ok
);