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 -D_LIBCPP_ENABLE_CXX26_REMOVED_CODECVT
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>
21 // int length(stateT& state, const externT* from, const externT* from_end,
27 #include "test_macros.h"
29 template <class CharT
, std::size_t = sizeof(CharT
)>
32 template <class CharT
>
33 struct TestHelper
<CharT
, 2> {
37 template <class CharT
>
38 struct TestHelper
<CharT
, 4> {
42 template <class CharT
>
43 void TestHelper
<CharT
, 2>::test() {
45 typedef std::codecvt_utf16
<char16_t
> C
;
47 char n
[4] = {char(0xD8), char(0xC0), char(0xDC), char(0x03)};
49 int r
= c
.length(m
, n
, n
+ 4, 2);
54 r
= c
.length(m
, n
, n
+ 2, 2);
59 r
= c
.length(m
, n
, n
+ 2, 2);
64 r
= c
.length(m
, n
, n
+ 2, 2);
68 typedef std::codecvt_utf16
<char16_t
, 0x1000> C
;
70 char n
[4] = {char(0xD8), char(0xC0), char(0xDC), char(0x03)};
72 int r
= c
.length(m
, n
, n
+ 4, 2);
77 r
= c
.length(m
, n
, n
+ 2, 2);
82 r
= c
.length(m
, n
, n
+ 2, 2);
87 r
= c
.length(m
, n
, n
+ 2, 2);
91 typedef std::codecvt_utf16
<char16_t
, 0x10ffff, std::consume_header
> C
;
93 char n
[6] = {char(0xFE), char(0xFF), char(0xD8), char(0xC0), char(0xDC), char(0x03)};
95 int r
= c
.length(m
, n
, n
+ 6, 2);
100 r
= c
.length(m
, n
, n
+ 2, 2);
105 r
= c
.length(m
, n
, n
+ 2, 2);
110 r
= c
.length(m
, n
, n
+ 2, 2);
114 typedef std::codecvt_utf16
<char16_t
, 0x10ffff, std::little_endian
> C
;
116 char n
[4] = {char(0xC0), char(0xD8), char(0x03), char(0xDC)};
118 int r
= c
.length(m
, n
, n
+ 4, 2);
123 r
= c
.length(m
, n
, n
+ 2, 2);
128 r
= c
.length(m
, n
, n
+ 2, 2);
133 r
= c
.length(m
, n
, n
+ 2, 2);
137 typedef std::codecvt_utf16
<char16_t
, 0x1000, std::little_endian
> C
;
139 char n
[4] = {char(0xC0), char(0xD8), char(0x03), char(0xDC)};
141 int r
= c
.length(m
, n
, n
+ 4, 2);
146 r
= c
.length(m
, n
, n
+ 2, 2);
151 r
= c
.length(m
, n
, n
+ 2, 2);
156 r
= c
.length(m
, n
, n
+ 2, 2);
160 typedef std::codecvt_utf16
<char16_t
, 0x10ffff, std::codecvt_mode(std::consume_header
| std::little_endian
)> C
;
162 char n
[6] = {char(0xFF), char(0xFE), char(0xC0), char(0xD8), char(0x03), char(0xDC)};
164 int r
= c
.length(m
, n
, n
+ 6, 2);
169 r
= c
.length(m
, n
, n
+ 2, 2);
174 r
= c
.length(m
, n
, n
+ 2, 2);
179 r
= c
.length(m
, n
, n
+ 2, 2);
184 template <class CharT
>
185 void TestHelper
<CharT
, 4>::test() {
187 typedef std::codecvt_utf16
<char32_t
> C
;
189 char n
[4] = {char(0xD8), char(0xC0), char(0xDC), char(0x03)};
191 int r
= c
.length(m
, n
, n
+ 4, 2);
196 r
= c
.length(m
, n
, n
+ 2, 2);
201 r
= c
.length(m
, n
, n
+ 2, 2);
206 r
= c
.length(m
, n
, n
+ 2, 2);
210 typedef std::codecvt_utf16
<char32_t
, 0x1000> C
;
212 char n
[4] = {char(0xD8), char(0xC0), char(0xDC), char(0x03)};
214 int r
= c
.length(m
, n
, n
+ 4, 2);
219 r
= c
.length(m
, n
, n
+ 2, 2);
224 r
= c
.length(m
, n
, n
+ 2, 2);
229 r
= c
.length(m
, n
, n
+ 2, 2);
233 typedef std::codecvt_utf16
<char32_t
, 0x10ffff, std::consume_header
> C
;
235 char n
[6] = {char(0xFE), char(0xFF), char(0xD8), char(0xC0), char(0xDC), char(0x03)};
237 int r
= c
.length(m
, n
, n
+ 6, 2);
242 r
= c
.length(m
, n
, n
+ 2, 2);
247 r
= c
.length(m
, n
, n
+ 2, 2);
252 r
= c
.length(m
, n
, n
+ 2, 2);
256 typedef std::codecvt_utf16
<char32_t
, 0x10ffff, std::little_endian
> C
;
258 char n
[4] = {char(0xC0), char(0xD8), char(0x03), char(0xDC)};
260 int r
= c
.length(m
, n
, n
+ 4, 2);
265 r
= c
.length(m
, n
, n
+ 2, 2);
270 r
= c
.length(m
, n
, n
+ 2, 2);
275 r
= c
.length(m
, n
, n
+ 2, 2);
279 typedef std::codecvt_utf16
<char32_t
, 0x1000, std::little_endian
> C
;
281 char n
[4] = {char(0xC0), char(0xD8), char(0x03), char(0xDC)};
283 int r
= c
.length(m
, n
, n
+ 4, 2);
288 r
= c
.length(m
, n
, n
+ 2, 2);
293 r
= c
.length(m
, n
, n
+ 2, 2);
298 r
= c
.length(m
, n
, n
+ 2, 2);
302 typedef std::codecvt_utf16
<char32_t
, 0x10ffff, std::codecvt_mode(std::consume_header
| std::little_endian
)> C
;
304 char n
[6] = {char(0xFF), char(0xFE), char(0xC0), char(0xD8), char(0x03), char(0xDC)};
306 int r
= c
.length(m
, n
, n
+ 6, 2);
311 r
= c
.length(m
, n
, n
+ 2, 2);
316 r
= c
.length(m
, n
, n
+ 2, 2);
321 r
= c
.length(m
, n
, n
+ 2, 2);
326 int main(int, char**) {
327 TestHelper
<wchar_t>::test();
328 TestHelper
<char16_t
>::test();
329 TestHelper
<char32_t
>::test();