[RISCV] Fix mgather -> riscv.masked.strided.load combine not extending indices (...
[llvm-project.git] / libcxx / test / std / localization / locale.stdcvt / codecvt_utf16_length.pass.cpp
blob68898957599f3d18259551db6e81ef80ef101d26
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 // 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>
17 // {
18 // // unspecified
19 // };
21 // int length(stateT& state, const externT* from, const externT* from_end,
22 // size_t max) const;
24 #include <codecvt>
25 #include <cassert>
27 #include "test_macros.h"
29 template <class CharT, std::size_t = sizeof(CharT)>
30 struct TestHelper;
32 template <class CharT>
33 struct TestHelper<CharT, 2> {
34 static void test();
37 template <class CharT>
38 struct TestHelper<CharT, 4> {
39 static void test();
42 template <class CharT>
43 void TestHelper<CharT, 2>::test() {
45 typedef std::codecvt_utf16<char16_t> C;
46 C c;
47 char n[4] = {char(0xD8), char(0xC0), char(0xDC), char(0x03)};
48 std::mbstate_t m;
49 int r = c.length(m, n, n + 4, 2);
50 assert(r == 0);
52 n[0] = char(0x10);
53 n[1] = char(0x05);
54 r = c.length(m, n, n + 2, 2);
55 assert(r == 2);
57 n[0] = char(0x04);
58 n[1] = char(0x53);
59 r = c.length(m, n, n + 2, 2);
60 assert(r == 2);
62 n[0] = char(0x00);
63 n[1] = char(0x56);
64 r = c.length(m, n, n + 2, 2);
65 assert(r == 2);
68 typedef std::codecvt_utf16<char16_t, 0x1000> C;
69 C c;
70 char n[4] = {char(0xD8), char(0xC0), char(0xDC), char(0x03)};
71 std::mbstate_t m;
72 int r = c.length(m, n, n + 4, 2);
73 assert(r == 0);
75 n[0] = char(0x10);
76 n[1] = char(0x05);
77 r = c.length(m, n, n + 2, 2);
78 assert(r == 0);
80 n[0] = char(0x04);
81 n[1] = char(0x53);
82 r = c.length(m, n, n + 2, 2);
83 assert(r == 2);
85 n[0] = char(0x00);
86 n[1] = char(0x56);
87 r = c.length(m, n, n + 2, 2);
88 assert(r == 2);
91 typedef std::codecvt_utf16<char16_t, 0x10ffff, std::consume_header> C;
92 C c;
93 char n[6] = {char(0xFE), char(0xFF), char(0xD8), char(0xC0), char(0xDC), char(0x03)};
94 std::mbstate_t m;
95 int r = c.length(m, n, n + 6, 2);
96 assert(r == 2);
98 n[0] = char(0x10);
99 n[1] = char(0x05);
100 r = c.length(m, n, n + 2, 2);
101 assert(r == 2);
103 n[0] = char(0x04);
104 n[1] = char(0x53);
105 r = c.length(m, n, n + 2, 2);
106 assert(r == 2);
108 n[0] = char(0x00);
109 n[1] = char(0x56);
110 r = c.length(m, n, n + 2, 2);
111 assert(r == 2);
114 typedef std::codecvt_utf16<char16_t, 0x10ffff, std::little_endian> C;
115 C c;
116 char n[4] = {char(0xC0), char(0xD8), char(0x03), char(0xDC)};
117 std::mbstate_t m;
118 int r = c.length(m, n, n + 4, 2);
119 assert(r == 0);
121 n[1] = char(0x10);
122 n[0] = char(0x05);
123 r = c.length(m, n, n + 2, 2);
124 assert(r == 2);
126 n[1] = char(0x04);
127 n[0] = char(0x53);
128 r = c.length(m, n, n + 2, 2);
129 assert(r == 2);
131 n[1] = char(0x00);
132 n[0] = char(0x56);
133 r = c.length(m, n, n + 2, 2);
134 assert(r == 2);
137 typedef std::codecvt_utf16<char16_t, 0x1000, std::little_endian> C;
138 C c;
139 char n[4] = {char(0xC0), char(0xD8), char(0x03), char(0xDC)};
140 std::mbstate_t m;
141 int r = c.length(m, n, n + 4, 2);
142 assert(r == 0);
144 n[1] = char(0x10);
145 n[0] = char(0x05);
146 r = c.length(m, n, n + 2, 2);
147 assert(r == 0);
149 n[1] = char(0x04);
150 n[0] = char(0x53);
151 r = c.length(m, n, n + 2, 2);
152 assert(r == 2);
154 n[1] = char(0x00);
155 n[0] = char(0x56);
156 r = c.length(m, n, n + 2, 2);
157 assert(r == 2);
160 typedef std::codecvt_utf16<char16_t, 0x10ffff, std::codecvt_mode(std::consume_header | std::little_endian)> C;
161 C c;
162 char n[6] = {char(0xFF), char(0xFE), char(0xC0), char(0xD8), char(0x03), char(0xDC)};
163 std::mbstate_t m;
164 int r = c.length(m, n, n + 6, 2);
165 assert(r == 2);
167 n[1] = char(0x10);
168 n[0] = char(0x05);
169 r = c.length(m, n, n + 2, 2);
170 assert(r == 2);
172 n[1] = char(0x04);
173 n[0] = char(0x53);
174 r = c.length(m, n, n + 2, 2);
175 assert(r == 2);
177 n[1] = char(0x00);
178 n[0] = char(0x56);
179 r = c.length(m, n, n + 2, 2);
180 assert(r == 2);
184 template <class CharT>
185 void TestHelper<CharT, 4>::test() {
187 typedef std::codecvt_utf16<char32_t> C;
188 C c;
189 char n[4] = {char(0xD8), char(0xC0), char(0xDC), char(0x03)};
190 std::mbstate_t m;
191 int r = c.length(m, n, n + 4, 2);
192 assert(r == 4);
194 n[0] = char(0x10);
195 n[1] = char(0x05);
196 r = c.length(m, n, n + 2, 2);
197 assert(r == 2);
199 n[0] = char(0x04);
200 n[1] = char(0x53);
201 r = c.length(m, n, n + 2, 2);
202 assert(r == 2);
204 n[0] = char(0x00);
205 n[1] = char(0x56);
206 r = c.length(m, n, n + 2, 2);
207 assert(r == 2);
210 typedef std::codecvt_utf16<char32_t, 0x1000> C;
211 C c;
212 char n[4] = {char(0xD8), char(0xC0), char(0xDC), char(0x03)};
213 std::mbstate_t m;
214 int r = c.length(m, n, n + 4, 2);
215 assert(r == 0);
217 n[0] = char(0x10);
218 n[1] = char(0x05);
219 r = c.length(m, n, n + 2, 2);
220 assert(r == 0);
222 n[0] = char(0x04);
223 n[1] = char(0x53);
224 r = c.length(m, n, n + 2, 2);
225 assert(r == 2);
227 n[0] = char(0x00);
228 n[1] = char(0x56);
229 r = c.length(m, n, n + 2, 2);
230 assert(r == 2);
233 typedef std::codecvt_utf16<char32_t, 0x10ffff, std::consume_header> C;
234 C c;
235 char n[6] = {char(0xFE), char(0xFF), char(0xD8), char(0xC0), char(0xDC), char(0x03)};
236 std::mbstate_t m;
237 int r = c.length(m, n, n + 6, 2);
238 assert(r == 6);
240 n[0] = char(0x10);
241 n[1] = char(0x05);
242 r = c.length(m, n, n + 2, 2);
243 assert(r == 2);
245 n[0] = char(0x04);
246 n[1] = char(0x53);
247 r = c.length(m, n, n + 2, 2);
248 assert(r == 2);
250 n[0] = char(0x00);
251 n[1] = char(0x56);
252 r = c.length(m, n, n + 2, 2);
253 assert(r == 2);
256 typedef std::codecvt_utf16<char32_t, 0x10ffff, std::little_endian> C;
257 C c;
258 char n[4] = {char(0xC0), char(0xD8), char(0x03), char(0xDC)};
259 std::mbstate_t m;
260 int r = c.length(m, n, n + 4, 2);
261 assert(r == 4);
263 n[1] = char(0x10);
264 n[0] = char(0x05);
265 r = c.length(m, n, n + 2, 2);
266 assert(r == 2);
268 n[1] = char(0x04);
269 n[0] = char(0x53);
270 r = c.length(m, n, n + 2, 2);
271 assert(r == 2);
273 n[1] = char(0x00);
274 n[0] = char(0x56);
275 r = c.length(m, n, n + 2, 2);
276 assert(r == 2);
279 typedef std::codecvt_utf16<char32_t, 0x1000, std::little_endian> C;
280 C c;
281 char n[4] = {char(0xC0), char(0xD8), char(0x03), char(0xDC)};
282 std::mbstate_t m;
283 int r = c.length(m, n, n + 4, 2);
284 assert(r == 0);
286 n[1] = char(0x10);
287 n[0] = char(0x05);
288 r = c.length(m, n, n + 2, 2);
289 assert(r == 0);
291 n[1] = char(0x04);
292 n[0] = char(0x53);
293 r = c.length(m, n, n + 2, 2);
294 assert(r == 2);
296 n[1] = char(0x00);
297 n[0] = char(0x56);
298 r = c.length(m, n, n + 2, 2);
299 assert(r == 2);
302 typedef std::codecvt_utf16<char32_t, 0x10ffff, std::codecvt_mode(std::consume_header | std::little_endian)> C;
303 C c;
304 char n[6] = {char(0xFF), char(0xFE), char(0xC0), char(0xD8), char(0x03), char(0xDC)};
305 std::mbstate_t m;
306 int r = c.length(m, n, n + 6, 2);
307 assert(r == 6);
309 n[1] = char(0x10);
310 n[0] = char(0x05);
311 r = c.length(m, n, n + 2, 2);
312 assert(r == 2);
314 n[1] = char(0x04);
315 n[0] = char(0x53);
316 r = c.length(m, n, n + 2, 2);
317 assert(r == 2);
319 n[1] = char(0x00);
320 n[0] = char(0x56);
321 r = c.length(m, n, n + 2, 2);
322 assert(r == 2);
326 int main(int, char**) {
327 TestHelper<wchar_t>::test();
328 TestHelper<char16_t>::test();
329 TestHelper<char32_t>::test();
330 return 0;