[RISCV] Fix mgather -> riscv.masked.strided.load combine not extending indices (...
[llvm-project.git] / libcxx / test / std / localization / locale.stdcvt / codecvt_utf8_utf16_out.pass.cpp
blob006d9839689f8e651a2b1e5f00230f9e9ee73f80
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_utf8_utf16
16 // : public codecvt<Elem, char, mbstate_t>
17 // {
18 // // unspecified
19 // };
21 // result
22 // out(stateT& state,
23 // const internT* from, const internT* from_end, const internT*& from_next,
24 // externT* to, externT* to_end, externT*& to_next) const;
26 #include <codecvt>
27 #include <cassert>
29 #include "test_macros.h"
31 template <class CharT, std::size_t = sizeof(CharT)>
32 struct TestHelper;
33 template <class CharT>
34 struct TestHelper<CharT, 2> {
35 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_utf8_utf16<CharT> C;
46 C c;
47 CharT w[2] = {0xD8C0, 0xDC03};
48 char n[4] = {0};
49 const CharT* wp = nullptr;
50 std::mbstate_t m;
51 char* np = nullptr;
52 std::codecvt_base::result r = c.out(m, w, w + 2, wp, n, n + 4, np);
53 assert(r == std::codecvt_base::ok);
54 assert(wp == w + 2);
55 assert(np == n + 4);
56 assert(n[0] == char(0xF1));
57 assert(n[1] == char(0x80));
58 assert(n[2] == char(0x80));
59 assert(n[3] == char(0x83));
61 w[0] = 0x1005;
62 r = c.out(m, w, w + 1, wp, n, n + 4, np);
63 assert(r == std::codecvt_base::ok);
64 assert(wp == w + 1);
65 assert(np == n + 3);
66 assert(n[0] == char(0xE1));
67 assert(n[1] == char(0x80));
68 assert(n[2] == char(0x85));
70 w[0] = 0x453;
71 r = c.out(m, w, w + 1, wp, n, n + 4, np);
72 assert(r == std::codecvt_base::ok);
73 assert(wp == w + 1);
74 assert(np == n + 2);
75 assert(n[0] == char(0xD1));
76 assert(n[1] == char(0x93));
78 w[0] = 0x56;
79 r = c.out(m, w, w + 1, wp, n, n + 4, np);
80 assert(r == std::codecvt_base::ok);
81 assert(wp == w + 1);
82 assert(np == n + 1);
83 assert(n[0] == char(0x56));
86 typedef std::codecvt_utf8_utf16<CharT, 0x1000> C;
87 C c;
88 CharT w[2] = {0xD8C0, 0xDC03};
89 char n[4] = {0};
90 const CharT* wp = nullptr;
91 std::mbstate_t m;
92 char* np = nullptr;
93 std::codecvt_base::result r = c.out(m, w, w + 2, wp, n, n + 4, np);
94 assert(r == std::codecvt_base::error);
95 assert(wp == w);
96 assert(np == n);
98 w[0] = 0x1005;
99 r = c.out(m, w, w + 1, wp, n, n + 4, np);
100 assert(r == std::codecvt_base::error);
101 assert(wp == w);
102 assert(np == n);
104 w[0] = 0x453;
105 r = c.out(m, w, w + 1, wp, n, n + 4, np);
106 assert(r == std::codecvt_base::ok);
107 assert(wp == w + 1);
108 assert(np == n + 2);
109 assert(n[0] == char(0xD1));
110 assert(n[1] == char(0x93));
112 w[0] = 0x56;
113 r = c.out(m, w, w + 1, wp, n, n + 4, np);
114 assert(r == std::codecvt_base::ok);
115 assert(wp == w + 1);
116 assert(np == n + 1);
117 assert(n[0] == char(0x56));
120 typedef std::codecvt_utf8_utf16<CharT, 0x10ffff, std::generate_header> C;
121 C c;
122 CharT w[2] = {0xD8C0, 0xDC03};
123 char n[7] = {0};
124 const CharT* wp = nullptr;
125 std::mbstate_t m;
126 char* np = nullptr;
127 std::codecvt_base::result r = c.out(m, w, w + 2, wp, n, n + 7, np);
128 assert(r == std::codecvt_base::ok);
129 assert(wp == w + 2);
130 assert(np == n + 7);
131 assert(n[0] == char(0xEF));
132 assert(n[1] == char(0xBB));
133 assert(n[2] == char(0xBF));
134 assert(n[3] == char(0xF1));
135 assert(n[4] == char(0x80));
136 assert(n[5] == char(0x80));
137 assert(n[6] == char(0x83));
139 w[0] = 0x1005;
140 r = c.out(m, w, w + 1, wp, n, n + 7, np);
141 assert(r == std::codecvt_base::ok);
142 assert(wp == w + 1);
143 assert(np == n + 6);
144 assert(n[0] == char(0xEF));
145 assert(n[1] == char(0xBB));
146 assert(n[2] == char(0xBF));
147 assert(n[3] == char(0xE1));
148 assert(n[4] == char(0x80));
149 assert(n[5] == char(0x85));
151 w[0] = 0x453;
152 r = c.out(m, w, w + 1, wp, n, n + 7, np);
153 assert(r == std::codecvt_base::ok);
154 assert(wp == w + 1);
155 assert(np == n + 5);
156 assert(n[0] == char(0xEF));
157 assert(n[1] == char(0xBB));
158 assert(n[2] == char(0xBF));
159 assert(n[3] == char(0xD1));
160 assert(n[4] == char(0x93));
162 w[0] = 0x56;
163 r = c.out(m, w, w + 1, wp, n, n + 7, np);
164 assert(r == std::codecvt_base::ok);
165 assert(wp == w + 1);
166 assert(np == n + 4);
167 assert(n[0] == char(0xEF));
168 assert(n[1] == char(0xBB));
169 assert(n[2] == char(0xBF));
170 assert(n[3] == char(0x56));
174 template <class CharT>
175 void TestHelper<CharT, 4>::test() {
177 typedef std::codecvt_utf8_utf16<CharT> C;
178 C c;
179 CharT w[2] = {0xD8C0, 0xDC03};
180 char n[4] = {0};
181 const CharT* wp = nullptr;
182 std::mbstate_t m;
183 char* np = nullptr;
184 std::codecvt_base::result r = c.out(m, w, w + 2, wp, n, n + 4, np);
185 assert(r == std::codecvt_base::ok);
186 assert(wp == w + 2);
187 assert(np == n + 4);
188 assert(n[0] == char(0xF1));
189 assert(n[1] == char(0x80));
190 assert(n[2] == char(0x80));
191 assert(n[3] == char(0x83));
193 w[0] = 0x1005;
194 r = c.out(m, w, w + 1, wp, n, n + 4, np);
195 assert(r == std::codecvt_base::ok);
196 assert(wp == w + 1);
197 assert(np == n + 3);
198 assert(n[0] == char(0xE1));
199 assert(n[1] == char(0x80));
200 assert(n[2] == char(0x85));
202 w[0] = 0x453;
203 r = c.out(m, w, w + 1, wp, n, n + 4, np);
204 assert(r == std::codecvt_base::ok);
205 assert(wp == w + 1);
206 assert(np == n + 2);
207 assert(n[0] == char(0xD1));
208 assert(n[1] == char(0x93));
210 w[0] = 0x56;
211 r = c.out(m, w, w + 1, wp, n, n + 4, np);
212 assert(r == std::codecvt_base::ok);
213 assert(wp == w + 1);
214 assert(np == n + 1);
215 assert(n[0] == char(0x56));
218 typedef std::codecvt_utf8_utf16<CharT, 0x1000> C;
219 C c;
220 CharT w[2] = {0xD8C0, 0xDC03};
221 char n[4] = {0};
222 const CharT* wp = nullptr;
223 std::mbstate_t m;
224 char* np = nullptr;
225 std::codecvt_base::result r = c.out(m, w, w + 2, wp, n, n + 4, np);
226 assert(r == std::codecvt_base::error);
227 assert(wp == w);
228 assert(np == n);
230 w[0] = 0x1005;
231 r = c.out(m, w, w + 1, wp, n, n + 4, np);
232 assert(r == std::codecvt_base::error);
233 assert(wp == w);
234 assert(np == n);
236 w[0] = 0x453;
237 r = c.out(m, w, w + 1, wp, n, n + 4, np);
238 assert(r == std::codecvt_base::ok);
239 assert(wp == w + 1);
240 assert(np == n + 2);
241 assert(n[0] == char(0xD1));
242 assert(n[1] == char(0x93));
244 w[0] = 0x56;
245 r = c.out(m, w, w + 1, wp, n, n + 4, np);
246 assert(r == std::codecvt_base::ok);
247 assert(wp == w + 1);
248 assert(np == n + 1);
249 assert(n[0] == char(0x56));
252 typedef std::codecvt_utf8_utf16<CharT, 0x10ffff, std::generate_header> C;
253 C c;
254 CharT w[2] = {0xD8C0, 0xDC03};
255 char n[7] = {0};
256 const CharT* wp = nullptr;
257 std::mbstate_t m;
258 char* np = nullptr;
259 std::codecvt_base::result r = c.out(m, w, w + 2, wp, n, n + 7, np);
260 assert(r == std::codecvt_base::ok);
261 assert(wp == w + 2);
262 assert(np == n + 7);
263 assert(n[0] == char(0xEF));
264 assert(n[1] == char(0xBB));
265 assert(n[2] == char(0xBF));
266 assert(n[3] == char(0xF1));
267 assert(n[4] == char(0x80));
268 assert(n[5] == char(0x80));
269 assert(n[6] == char(0x83));
271 w[0] = 0x1005;
272 r = c.out(m, w, w + 1, wp, n, n + 7, np);
273 assert(r == std::codecvt_base::ok);
274 assert(wp == w + 1);
275 assert(np == n + 6);
276 assert(n[0] == char(0xEF));
277 assert(n[1] == char(0xBB));
278 assert(n[2] == char(0xBF));
279 assert(n[3] == char(0xE1));
280 assert(n[4] == char(0x80));
281 assert(n[5] == char(0x85));
283 w[0] = 0x453;
284 r = c.out(m, w, w + 1, wp, n, n + 7, np);
285 assert(r == std::codecvt_base::ok);
286 assert(wp == w + 1);
287 assert(np == n + 5);
288 assert(n[0] == char(0xEF));
289 assert(n[1] == char(0xBB));
290 assert(n[2] == char(0xBF));
291 assert(n[3] == char(0xD1));
292 assert(n[4] == char(0x93));
294 w[0] = 0x56;
295 r = c.out(m, w, w + 1, wp, n, n + 7, np);
296 assert(r == std::codecvt_base::ok);
297 assert(wp == w + 1);
298 assert(np == n + 4);
299 assert(n[0] == char(0xEF));
300 assert(n[1] == char(0xBB));
301 assert(n[2] == char(0xBF));
302 assert(n[3] == char(0x56));
306 int main(int, char**) {
307 #if !defined(_WIN32) && !defined(TEST_HAS_NO_WIDE_CHARACTERS)
308 TestHelper<wchar_t>::test();
309 #endif
310 TestHelper<char32_t>::test();
311 TestHelper<char16_t>::test();
313 return 0;