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>
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_utf8
<char32_t
> C
;
37 char n
[4] = {char(0xF1), char(0x80), char(0x80), char(0x83)};
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
);
50 r
= c
.in(m
, n
, n
+3, np
, &w
, &w
+1, wp
);
51 assert(r
== std::codecvt_base::ok
);
58 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
59 assert(r
== std::codecvt_base::ok
);
66 r
= c
.in(m
, n
, n
+1, np
, &w
, &w
+1, wp
);
67 assert(r
== std::codecvt_base::ok
);
73 typedef std::codecvt_utf8
<char32_t
, 0x1000> C
;
76 char n
[4] = {char(0xF1), char(0x80), char(0x80), char(0x83)};
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
);
89 r
= c
.in(m
, n
, n
+3, np
, &w
, &w
+1, wp
);
90 assert(r
== std::codecvt_base::error
);
97 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
98 assert(r
== std::codecvt_base::ok
);
105 r
= c
.in(m
, n
, n
+1, np
, &w
, &w
+1, wp
);
106 assert(r
== std::codecvt_base::ok
);
112 typedef std::codecvt_utf8
<char32_t
, 0xFFFFFFFF, std::consume_header
> C
;
115 char n
[7] = {char(0xEF), char(0xBB), char(0xBF), char(0xF1), char(0x80), char(0x80), char(0x83)};
116 char32_t
* wp
= nullptr;
118 const char* np
= nullptr;
119 std::codecvt_base::result r
= c
.in(m
, n
, n
+7, np
, &w
, &w
+1, wp
);
120 assert(r
== std::codecvt_base::ok
);
123 assert(w
== 0x40003);
128 r
= c
.in(m
, n
, n
+3, np
, &w
, &w
+1, wp
);
129 assert(r
== std::codecvt_base::ok
);
139 r
= c
.in(m
, n
, n
+5, np
, &w
, &w
+1, wp
);
140 assert(r
== std::codecvt_base::ok
);
147 r
= c
.in(m
, n
, n
+1, np
, &w
, &w
+1, wp
);
148 assert(r
== std::codecvt_base::ok
);
154 typedef std::codecvt_utf8
<char32_t
> C
;
157 char n
[4] = {char(0xF1), char(0x80), char(0x80), char(0x83)};
158 char32_t
* wp
= nullptr;
160 const char* np
= nullptr;
161 std::codecvt_base::result r
= c
.in(m
, n
, n
+4, np
, &w
, &w
+1, wp
);
162 assert(r
== std::codecvt_base::ok
);
165 assert(w
== 0x40003);
170 r
= c
.in(m
, n
, n
+3, np
, &w
, &w
+1, wp
);
171 assert(r
== std::codecvt_base::ok
);
178 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
179 assert(r
== std::codecvt_base::ok
);
186 r
= c
.in(m
, n
, n
+1, np
, &w
, &w
+1, wp
);
187 assert(r
== std::codecvt_base::ok
);
193 typedef std::codecvt_utf8
<char32_t
, 0x1000> C
;
196 char n
[4] = {char(0xF1), char(0x80), char(0x80), char(0x83)};
197 char32_t
* wp
= nullptr;
199 const char* np
= nullptr;
200 std::codecvt_base::result r
= c
.in(m
, n
, n
+4, np
, &w
, &w
+1, wp
);
201 assert(r
== std::codecvt_base::error
);
209 r
= c
.in(m
, n
, n
+3, np
, &w
, &w
+1, wp
);
210 assert(r
== std::codecvt_base::error
);
217 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
218 assert(r
== std::codecvt_base::ok
);
225 r
= c
.in(m
, n
, n
+1, np
, &w
, &w
+1, wp
);
226 assert(r
== std::codecvt_base::ok
);
232 typedef std::codecvt_utf8
<char32_t
, 0xFFFFFFFF, std::consume_header
> C
;
235 char n
[7] = {char(0xEF), char(0xBB), char(0xBF), char(0xF1), char(0x80), char(0x80), char(0x83)};
236 char32_t
* wp
= nullptr;
238 const char* np
= nullptr;
239 std::codecvt_base::result r
= c
.in(m
, n
, n
+7, np
, &w
, &w
+1, wp
);
240 assert(r
== std::codecvt_base::ok
);
243 assert(w
== 0x40003);
248 r
= c
.in(m
, n
, n
+3, np
, &w
, &w
+1, wp
);
249 assert(r
== std::codecvt_base::ok
);
259 r
= c
.in(m
, n
, n
+5, np
, &w
, &w
+1, wp
);
260 assert(r
== std::codecvt_base::ok
);
267 r
= c
.in(m
, n
, n
+1, np
, &w
, &w
+1, wp
);
268 assert(r
== std::codecvt_base::ok
);
274 typedef std::codecvt_utf8
<char16_t
> C
;
277 char n
[3] = {char(0xE1), char(0x80), char(0x85)};
278 char16_t
* wp
= nullptr;
280 const char* np
= nullptr;
281 std::codecvt_base::result r
= c
.in(m
, n
, n
+3, np
, &w
, &w
+1, wp
);
282 assert(r
== std::codecvt_base::ok
);
289 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
290 assert(r
== std::codecvt_base::ok
);
297 r
= c
.in(m
, n
, n
+1, np
, &w
, &w
+1, wp
);
298 assert(r
== std::codecvt_base::ok
);
304 typedef std::codecvt_utf8
<char16_t
, 0x1000> C
;
307 char n
[3] = {char(0xE1), char(0x80), char(0x85)};
308 char16_t
* wp
= nullptr;
310 const char* np
= nullptr;
311 std::codecvt_base::result r
= c
.in(m
, n
, n
+3, np
, &w
, &w
+1, wp
);
312 assert(r
== std::codecvt_base::error
);
319 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
320 assert(r
== std::codecvt_base::ok
);
327 r
= c
.in(m
, n
, n
+1, np
, &w
, &w
+1, wp
);
328 assert(r
== std::codecvt_base::ok
);
334 typedef std::codecvt_utf8
<char16_t
, 0xFFFFFFFF, std::consume_header
> C
;
337 char n
[6] = {char(0xEF), char(0xBB), char(0xBF), char(0xE1), char(0x80), char(0x85)};
338 char16_t
* wp
= nullptr;
340 const char* np
= nullptr;
341 std::codecvt_base::result r
= c
.in(m
, n
, n
+6, np
, &w
, &w
+1, wp
);
342 assert(r
== std::codecvt_base::ok
);
349 r
= c
.in(m
, n
, n
+2, np
, &w
, &w
+1, wp
);
350 assert(r
== std::codecvt_base::ok
);
357 r
= c
.in(m
, n
, n
+1, np
, &w
, &w
+1, wp
);
358 assert(r
== std::codecvt_base::ok
);