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>
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_utf8
<char32_t
> C
;
35 char n
[4] = {char(0xF1), char(0x80), char(0x80), char(0x83)};
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
);
48 r
= c
.in(m
, n
, n
+3, np
, &w
, &w
+1, wp
);
49 assert(r
== std::codecvt_base::ok
);
56 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
57 assert(r
== std::codecvt_base::ok
);
64 r
= c
.in(m
, n
, n
+1, np
, &w
, &w
+1, wp
);
65 assert(r
== std::codecvt_base::ok
);
71 typedef std::codecvt_utf8
<char32_t
, 0x1000> C
;
74 char n
[4] = {char(0xF1), char(0x80), char(0x80), char(0x83)};
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
);
87 r
= c
.in(m
, n
, n
+3, np
, &w
, &w
+1, wp
);
88 assert(r
== std::codecvt_base::error
);
95 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
96 assert(r
== std::codecvt_base::ok
);
103 r
= c
.in(m
, n
, n
+1, np
, &w
, &w
+1, wp
);
104 assert(r
== std::codecvt_base::ok
);
110 typedef std::codecvt_utf8
<char32_t
, 0xFFFFFFFF, std::consume_header
> C
;
113 char n
[7] = {char(0xEF), char(0xBB), char(0xBF), char(0xF1), char(0x80), char(0x80), char(0x83)};
114 char32_t
* wp
= nullptr;
116 const char* np
= nullptr;
117 std::codecvt_base::result r
= c
.in(m
, n
, n
+7, np
, &w
, &w
+1, wp
);
118 assert(r
== std::codecvt_base::ok
);
121 assert(w
== 0x40003);
126 r
= c
.in(m
, n
, n
+3, np
, &w
, &w
+1, wp
);
127 assert(r
== std::codecvt_base::ok
);
137 r
= c
.in(m
, n
, n
+5, np
, &w
, &w
+1, wp
);
138 assert(r
== std::codecvt_base::ok
);
145 r
= c
.in(m
, n
, n
+1, np
, &w
, &w
+1, wp
);
146 assert(r
== std::codecvt_base::ok
);
152 typedef std::codecvt_utf8
<char32_t
> C
;
155 char n
[4] = {char(0xF1), char(0x80), char(0x80), char(0x83)};
156 char32_t
* wp
= nullptr;
158 const char* np
= nullptr;
159 std::codecvt_base::result r
= c
.in(m
, n
, n
+4, np
, &w
, &w
+1, wp
);
160 assert(r
== std::codecvt_base::ok
);
163 assert(w
== 0x40003);
168 r
= c
.in(m
, n
, n
+3, np
, &w
, &w
+1, wp
);
169 assert(r
== std::codecvt_base::ok
);
176 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
177 assert(r
== std::codecvt_base::ok
);
184 r
= c
.in(m
, n
, n
+1, np
, &w
, &w
+1, wp
);
185 assert(r
== std::codecvt_base::ok
);
191 typedef std::codecvt_utf8
<char32_t
, 0x1000> C
;
194 char n
[4] = {char(0xF1), char(0x80), char(0x80), char(0x83)};
195 char32_t
* wp
= nullptr;
197 const char* np
= nullptr;
198 std::codecvt_base::result r
= c
.in(m
, n
, n
+4, np
, &w
, &w
+1, wp
);
199 assert(r
== std::codecvt_base::error
);
207 r
= c
.in(m
, n
, n
+3, np
, &w
, &w
+1, wp
);
208 assert(r
== std::codecvt_base::error
);
215 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
216 assert(r
== std::codecvt_base::ok
);
223 r
= c
.in(m
, n
, n
+1, np
, &w
, &w
+1, wp
);
224 assert(r
== std::codecvt_base::ok
);
230 typedef std::codecvt_utf8
<char32_t
, 0xFFFFFFFF, std::consume_header
> C
;
233 char n
[7] = {char(0xEF), char(0xBB), char(0xBF), char(0xF1), char(0x80), char(0x80), char(0x83)};
234 char32_t
* wp
= nullptr;
236 const char* np
= nullptr;
237 std::codecvt_base::result r
= c
.in(m
, n
, n
+7, np
, &w
, &w
+1, wp
);
238 assert(r
== std::codecvt_base::ok
);
241 assert(w
== 0x40003);
246 r
= c
.in(m
, n
, n
+3, np
, &w
, &w
+1, wp
);
247 assert(r
== std::codecvt_base::ok
);
257 r
= c
.in(m
, n
, n
+5, np
, &w
, &w
+1, wp
);
258 assert(r
== std::codecvt_base::ok
);
265 r
= c
.in(m
, n
, n
+1, np
, &w
, &w
+1, wp
);
266 assert(r
== std::codecvt_base::ok
);
272 typedef std::codecvt_utf8
<char16_t
> C
;
275 char n
[3] = {char(0xE1), char(0x80), char(0x85)};
276 char16_t
* wp
= nullptr;
278 const char* np
= nullptr;
279 std::codecvt_base::result r
= c
.in(m
, n
, n
+3, np
, &w
, &w
+1, wp
);
280 assert(r
== std::codecvt_base::ok
);
287 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
288 assert(r
== std::codecvt_base::ok
);
295 r
= c
.in(m
, n
, n
+1, np
, &w
, &w
+1, wp
);
296 assert(r
== std::codecvt_base::ok
);
302 typedef std::codecvt_utf8
<char16_t
, 0x1000> C
;
305 char n
[3] = {char(0xE1), char(0x80), char(0x85)};
306 char16_t
* wp
= nullptr;
308 const char* np
= nullptr;
309 std::codecvt_base::result r
= c
.in(m
, n
, n
+3, np
, &w
, &w
+1, wp
);
310 assert(r
== std::codecvt_base::error
);
317 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
318 assert(r
== std::codecvt_base::ok
);
325 r
= c
.in(m
, n
, n
+1, np
, &w
, &w
+1, wp
);
326 assert(r
== std::codecvt_base::ok
);
332 typedef std::codecvt_utf8
<char16_t
, 0xFFFFFFFF, std::consume_header
> C
;
335 char n
[6] = {char(0xEF), char(0xBB), char(0xBF), char(0xE1), char(0x80), char(0x85)};
336 char16_t
* wp
= nullptr;
338 const char* np
= nullptr;
339 std::codecvt_base::result r
= c
.in(m
, n
, n
+6, np
, &w
, &w
+1, wp
);
340 assert(r
== std::codecvt_base::ok
);
347 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
348 assert(r
== std::codecvt_base::ok
);
355 r
= c
.in(m
, n
, n
+1, np
, &w
, &w
+1, wp
);
356 assert(r
== std::codecvt_base::ok
);