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_utf8_utf16
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"
31 template <class CharT
, std::size_t = sizeof(CharT
)>
33 template <class CharT
>
34 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_utf8_utf16
<CharT
, 0x1000> C
;
48 char n
[4] = {char(0xF1), char(0x80), char(0x80), char(0x83)};
51 const char* np
= nullptr;
52 std::codecvt_base::result r
= c
.in(m
, n
, n
+ 4, np
, w
, w
+ 2, wp
);
53 assert(r
== std::codecvt_base::error
);
60 r
= c
.in(m
, n
, n
+ 3, np
, w
, w
+ 2, wp
);
61 assert(r
== std::codecvt_base::error
);
67 r
= c
.in(m
, n
, n
+ 2, np
, w
, w
+ 2, wp
);
68 assert(r
== std::codecvt_base::ok
);
71 assert(w
[0] == 0x0453);
74 r
= c
.in(m
, n
, n
+ 1, np
, w
, w
+ 2, wp
);
75 assert(r
== std::codecvt_base::ok
);
78 assert(w
[0] == 0x0056);
81 typedef std::codecvt_utf8_utf16
<CharT
, 0x10ffff, std::consume_header
> C
;
84 char n
[7] = {char(0xEF), char(0xBB), char(0xBF), char(0xF1),
85 char(0x80), char(0x80), char(0x83)};
88 const char* np
= nullptr;
89 std::codecvt_base::result r
= c
.in(m
, n
, n
+ 7, np
, w
, w
+ 2, wp
);
90 assert(r
== std::codecvt_base::ok
);
93 assert(w
[0] == 0xD8C0);
94 assert(w
[1] == 0xDC03);
99 r
= c
.in(m
, n
, n
+ 3, np
, w
, w
+ 2, wp
);
100 assert(r
== std::codecvt_base::ok
);
103 assert(w
[0] == 0x1005);
107 r
= c
.in(m
, n
, n
+ 2, np
, w
, w
+ 2, wp
);
108 assert(r
== std::codecvt_base::ok
);
111 assert(w
[0] == 0x0453);
114 r
= c
.in(m
, n
, n
+ 1, np
, w
, w
+ 2, wp
);
115 assert(r
== std::codecvt_base::ok
);
118 assert(w
[0] == 0x0056);
122 template <class CharT
>
123 void TestHelper
<CharT
, 4>::test() {
125 typedef std::codecvt_utf8_utf16
<CharT
> C
;
128 char n
[4] = {char(0xF1), char(0x80), char(0x80), char(0x83)};
131 const char* np
= nullptr;
132 std::codecvt_base::result r
= c
.in(m
, n
, n
+ 4, np
, w
, w
+ 2, wp
);
133 assert(r
== std::codecvt_base::ok
);
136 assert(w
[0] == 0xD8C0);
137 assert(w
[1] == 0xDC03);
142 r
= c
.in(m
, n
, n
+ 3, np
, w
, w
+ 2, wp
);
143 assert(r
== std::codecvt_base::ok
);
146 assert(w
[0] == 0x1005);
150 r
= c
.in(m
, n
, n
+ 2, np
, w
, w
+ 2, wp
);
151 assert(r
== std::codecvt_base::ok
);
154 assert(w
[0] == 0x0453);
157 r
= c
.in(m
, n
, n
+ 1, np
, w
, w
+ 2, wp
);
158 assert(r
== std::codecvt_base::ok
);
161 assert(w
[0] == 0x0056);
164 typedef std::codecvt_utf8_utf16
<CharT
, 0x1000> C
;
167 char n
[4] = {char(0xF1), char(0x80), char(0x80), char(0x83)};
170 const char* np
= nullptr;
171 std::codecvt_base::result r
= c
.in(m
, n
, n
+ 4, np
, w
, w
+ 2, wp
);
172 assert(r
== std::codecvt_base::error
);
179 r
= c
.in(m
, n
, n
+ 3, np
, w
, w
+ 2, wp
);
180 assert(r
== std::codecvt_base::error
);
186 r
= c
.in(m
, n
, n
+ 2, np
, w
, w
+ 2, wp
);
187 assert(r
== std::codecvt_base::ok
);
190 assert(w
[0] == 0x0453);
193 r
= c
.in(m
, n
, n
+ 1, np
, w
, w
+ 2, wp
);
194 assert(r
== std::codecvt_base::ok
);
197 assert(w
[0] == 0x0056);
200 typedef std::codecvt_utf8_utf16
<CharT
, 0x10ffff, std::consume_header
> C
;
203 char n
[7] = {char(0xEF), char(0xBB), char(0xBF), char(0xF1),
204 char(0x80), char(0x80), char(0x83)};
207 const char* np
= nullptr;
208 std::codecvt_base::result r
= c
.in(m
, n
, n
+ 7, np
, w
, w
+ 2, wp
);
209 assert(r
== std::codecvt_base::ok
);
212 assert(w
[0] == 0xD8C0);
213 assert(w
[1] == 0xDC03);
218 r
= c
.in(m
, n
, n
+ 3, np
, w
, w
+ 2, wp
);
219 assert(r
== std::codecvt_base::ok
);
222 assert(w
[0] == 0x1005);
226 r
= c
.in(m
, n
, n
+ 2, np
, w
, w
+ 2, wp
);
227 assert(r
== std::codecvt_base::ok
);
230 assert(w
[0] == 0x0453);
233 r
= c
.in(m
, n
, n
+ 1, np
, w
, w
+ 2, wp
);
234 assert(r
== std::codecvt_base::ok
);
237 assert(w
[0] == 0x0056);
241 int main(int, char**) {
242 #if !defined(_WIN32) && !defined(TEST_HAS_NO_WIDE_CHARACTERS)
243 TestHelper
<wchar_t>::test();
245 TestHelper
<char32_t
>::test();
246 TestHelper
<char16_t
>::test();