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 // ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS
13 // template <class Elem, unsigned long Maxcode = 0x10ffff,
14 // codecvt_mode Mode = (codecvt_mode)0>
15 // class codecvt_utf16
16 // : public codecvt<Elem, char, mbstate_t>
23 // const externT* from, const externT* from_end, const externT*& from_next,
24 // internT* to, internT* to_end, internT*& to_next) const;
29 #include "test_macros.h"
34 typedef std::codecvt_utf16
<char32_t
> C
;
37 char n
[4] = {char(0xD8), char(0xC0), char(0xDC), char(0x03)};
38 char32_t
* wp
= nullptr;
40 const char* np
= nullptr;
41 std::codecvt_base::result r
= c
.in(m
, n
, n
+4, np
, &w
, &w
+1, wp
);
42 assert(r
== std::codecvt_base::ok
);
49 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
50 assert(r
== std::codecvt_base::ok
);
57 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
58 assert(r
== std::codecvt_base::ok
);
66 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
67 assert(r
== std::codecvt_base::ok
);
73 typedef std::codecvt_utf16
<char32_t
, 0x1000> C
;
76 char n
[4] = {char(0xD8), char(0xC0), char(0xDC), char(0x03)};
77 char32_t
* wp
= nullptr;
79 const char* np
= nullptr;
80 std::codecvt_base::result r
= c
.in(m
, n
, n
+4, np
, &w
, &w
+1, wp
);
81 assert(r
== std::codecvt_base::error
);
88 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
89 assert(r
== std::codecvt_base::error
);
96 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
97 assert(r
== std::codecvt_base::ok
);
105 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
106 assert(r
== std::codecvt_base::ok
);
112 typedef std::codecvt_utf16
<char32_t
, 0x10ffff, std::consume_header
> C
;
115 char n
[6] = {char(0xFE), char(0xFF), char(0xD8), char(0xC0), char(0xDC), char(0x03)};
116 char32_t
* wp
= nullptr;
118 const char* np
= nullptr;
119 std::codecvt_base::result r
= c
.in(m
, n
, n
+6, np
, &w
, &w
+1, wp
);
120 assert(r
== std::codecvt_base::ok
);
123 assert(w
== 0x40003);
127 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
128 assert(r
== std::codecvt_base::ok
);
135 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
136 assert(r
== std::codecvt_base::ok
);
144 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
145 assert(r
== std::codecvt_base::ok
);
151 typedef std::codecvt_utf16
<char32_t
, 0x10ffff, std::little_endian
> C
;
154 char n
[4] = {char(0xC0), char(0xD8), char(0x03), char(0xDC)};
155 char32_t
* wp
= nullptr;
157 const char* np
= nullptr;
158 std::codecvt_base::result r
= c
.in(m
, n
, n
+4, np
, &w
, &w
+1, wp
);
159 assert(r
== std::codecvt_base::ok
);
162 assert(w
== 0x40003);
166 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
167 assert(r
== std::codecvt_base::ok
);
174 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
175 assert(r
== std::codecvt_base::ok
);
183 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
184 assert(r
== std::codecvt_base::ok
);
190 typedef std::codecvt_utf16
<char32_t
, 0x1000, std::little_endian
> C
;
193 char n
[4] = {char(0xC0), char(0xD8), char(0x03), char(0xDC)};
194 char32_t
* wp
= nullptr;
196 const char* np
= nullptr;
197 std::codecvt_base::result r
= c
.in(m
, n
, n
+4, np
, &w
, &w
+1, wp
);
198 assert(r
== std::codecvt_base::error
);
205 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
206 assert(r
== std::codecvt_base::error
);
213 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
214 assert(r
== std::codecvt_base::ok
);
222 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
223 assert(r
== std::codecvt_base::ok
);
229 typedef std::codecvt_utf16
<char32_t
, 0x10ffff,
230 std::codecvt_mode(std::consume_header
| std::little_endian
)> C
;
234 char n
[6] = {char(0xFF), char(0xFE), char(0xC0), char(0xD8), char(0x03), char(0xDC)};
235 char32_t
* wp
= nullptr;
237 const char* np
= nullptr;
238 std::codecvt_base::result r
= c
.in(m
, n
, n
+6, np
, &w
, &w
+1, wp
);
239 assert(r
== std::codecvt_base::ok
);
242 assert(w
== 0x40003);
246 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
247 assert(r
== std::codecvt_base::ok
);
254 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
255 assert(r
== std::codecvt_base::ok
);
263 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
264 assert(r
== std::codecvt_base::ok
);
270 typedef std::codecvt_utf16
<char32_t
> C
;
273 char n
[4] = {char(0xD8), char(0xC0), char(0xDC), char(0x03)};
274 char32_t
* wp
= nullptr;
276 const char* np
= nullptr;
277 std::codecvt_base::result r
= c
.in(m
, n
, n
+4, np
, &w
, &w
+1, wp
);
278 assert(r
== std::codecvt_base::ok
);
281 assert(w
== 0x40003);
285 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
286 assert(r
== std::codecvt_base::ok
);
293 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
294 assert(r
== std::codecvt_base::ok
);
302 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
303 assert(r
== std::codecvt_base::ok
);
309 typedef std::codecvt_utf16
<char32_t
, 0x1000> C
;
312 char n
[4] = {char(0xD8), char(0xC0), char(0xDC), char(0x03)};
313 char32_t
* wp
= nullptr;
315 const char* np
= nullptr;
316 std::codecvt_base::result r
= c
.in(m
, n
, n
+4, np
, &w
, &w
+1, wp
);
317 assert(r
== std::codecvt_base::error
);
324 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
325 assert(r
== std::codecvt_base::error
);
332 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
333 assert(r
== std::codecvt_base::ok
);
341 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
342 assert(r
== std::codecvt_base::ok
);
348 typedef std::codecvt_utf16
<char32_t
, 0x10ffff, std::consume_header
> C
;
351 char n
[6] = {char(0xFE), char(0xFF), char(0xD8), char(0xC0), char(0xDC), char(0x03)};
352 char32_t
* wp
= nullptr;
354 const char* np
= nullptr;
355 std::codecvt_base::result r
= c
.in(m
, n
, n
+6, np
, &w
, &w
+1, wp
);
356 assert(r
== std::codecvt_base::ok
);
359 assert(w
== 0x40003);
363 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
364 assert(r
== std::codecvt_base::ok
);
371 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
372 assert(r
== std::codecvt_base::ok
);
380 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
381 assert(r
== std::codecvt_base::ok
);
387 typedef std::codecvt_utf16
<char32_t
, 0x10ffff, std::little_endian
> C
;
390 char n
[4] = {char(0xC0), char(0xD8), char(0x03), char(0xDC)};
391 char32_t
* wp
= nullptr;
393 const char* np
= nullptr;
394 std::codecvt_base::result r
= c
.in(m
, n
, n
+4, np
, &w
, &w
+1, wp
);
395 assert(r
== std::codecvt_base::ok
);
398 assert(w
== 0x40003);
402 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
403 assert(r
== std::codecvt_base::ok
);
410 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
411 assert(r
== std::codecvt_base::ok
);
419 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
420 assert(r
== std::codecvt_base::ok
);
426 typedef std::codecvt_utf16
<char32_t
, 0x1000, std::little_endian
> C
;
429 char n
[4] = {char(0xC0), char(0xD8), char(0x03), char(0xDC)};
430 char32_t
* wp
= nullptr;
432 const char* np
= nullptr;
433 std::codecvt_base::result r
= c
.in(m
, n
, n
+4, np
, &w
, &w
+1, wp
);
434 assert(r
== std::codecvt_base::error
);
441 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
442 assert(r
== std::codecvt_base::error
);
449 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
450 assert(r
== std::codecvt_base::ok
);
458 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
459 assert(r
== std::codecvt_base::ok
);
465 typedef std::codecvt_utf16
<char32_t
, 0x10ffff, std::codecvt_mode(
466 std::consume_header
|
467 std::little_endian
)> C
;
470 char n
[6] = {char(0xFF), char(0xFE), char(0xC0), char(0xD8), char(0x03), char(0xDC)};
471 char32_t
* wp
= nullptr;
473 const char* np
= nullptr;
474 std::codecvt_base::result r
= c
.in(m
, n
, n
+6, np
, &w
, &w
+1, wp
);
475 assert(r
== std::codecvt_base::ok
);
478 assert(w
== 0x40003);
482 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
483 assert(r
== std::codecvt_base::ok
);
490 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
491 assert(r
== std::codecvt_base::ok
);
499 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
500 assert(r
== std::codecvt_base::ok
);
507 typedef std::codecvt_utf16
<char16_t
> C
;
510 char n
[4] = {char(0xD8), char(0xC0), char(0xDC), char(0x03)};
511 char16_t
* wp
= nullptr;
513 const char* np
= nullptr;
514 std::codecvt_base::result r
= c
.in(m
, n
, n
+4, np
, &w
, &w
+1, wp
);
515 assert(r
== std::codecvt_base::error
);
522 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
523 assert(r
== std::codecvt_base::ok
);
530 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
531 assert(r
== std::codecvt_base::ok
);
539 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
540 assert(r
== std::codecvt_base::ok
);
546 typedef std::codecvt_utf16
<char16_t
, 0x1000> C
;
549 char n
[4] = {char(0xD8), char(0xC0), char(0xDC), char(0x03)};
550 char16_t
* wp
= nullptr;
552 const char* np
= nullptr;
553 std::codecvt_base::result r
= c
.in(m
, n
, n
+4, np
, &w
, &w
+1, wp
);
554 assert(r
== std::codecvt_base::error
);
561 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
562 assert(r
== std::codecvt_base::error
);
569 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
570 assert(r
== std::codecvt_base::ok
);
578 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
579 assert(r
== std::codecvt_base::ok
);
585 typedef std::codecvt_utf16
<char16_t
, 0x10ffff, std::consume_header
> C
;
588 char n
[6] = {char(0xFE), char(0xFF), char(0xD8), char(0xC0), char(0xDC), char(0x03)};
589 char16_t
* wp
= nullptr;
591 const char* np
= nullptr;
592 std::codecvt_base::result r
= c
.in(m
, n
, n
+6, np
, &w
, &w
+1, wp
);
593 assert(r
== std::codecvt_base::error
);
600 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
601 assert(r
== std::codecvt_base::ok
);
608 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
609 assert(r
== std::codecvt_base::ok
);
617 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
618 assert(r
== std::codecvt_base::ok
);
624 typedef std::codecvt_utf16
<char16_t
, 0x10ffff, std::little_endian
> C
;
627 char n
[4] = {char(0xC0), char(0xD8), char(0x03), char(0xDC)};
628 char16_t
* wp
= nullptr;
630 const char* np
= nullptr;
631 std::codecvt_base::result r
= c
.in(m
, n
, n
+4, np
, &w
, &w
+1, wp
);
632 assert(r
== std::codecvt_base::error
);
639 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
640 assert(r
== std::codecvt_base::ok
);
647 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
648 assert(r
== std::codecvt_base::ok
);
656 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
657 assert(r
== std::codecvt_base::ok
);
663 typedef std::codecvt_utf16
<char16_t
, 0x1000, std::little_endian
> C
;
666 char n
[4] = {char(0xC0), char(0xD8), char(0x03), char(0xDC)};
667 char16_t
* wp
= nullptr;
669 const char* np
= nullptr;
670 std::codecvt_base::result r
= c
.in(m
, n
, n
+4, np
, &w
, &w
+1, wp
);
671 assert(r
== std::codecvt_base::error
);
678 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
679 assert(r
== std::codecvt_base::error
);
686 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
687 assert(r
== std::codecvt_base::ok
);
695 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
696 assert(r
== std::codecvt_base::ok
);
702 typedef std::codecvt_utf16
<char16_t
, 0x10ffff, std::codecvt_mode(
703 std::consume_header
|
704 std::little_endian
)> C
;
707 char n
[6] = {char(0xFF), char(0xFE), char(0xC0), char(0xD8), char(0x03), char(0xDC)};
708 char16_t
* wp
= nullptr;
710 const char* np
= nullptr;
711 std::codecvt_base::result r
= c
.in(m
, n
, n
+6, np
, &w
, &w
+1, wp
);
712 assert(r
== std::codecvt_base::error
);
719 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
720 assert(r
== std::codecvt_base::ok
);
727 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
728 assert(r
== std::codecvt_base::ok
);
736 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
737 assert(r
== std::codecvt_base::ok
);