Revert "[libc] Use best-fit binary trie to make malloc logarithmic" (#117065)
[llvm-project.git] / libcxx / test / std / localization / locale.stdcvt / codecvt_utf8_utf16_length.pass.cpp
blob3fcf8e5b2dc522d060b5e95317b85b1cf890f2c7
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 // 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 int main(int, char**)
31 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
33 typedef std::codecvt_utf8_utf16<wchar_t> C;
34 C c;
35 char n[4] = {char(0xF1), char(0x80), char(0x80), char(0x83)};
36 std::mbstate_t m;
37 int r = c.length(m, n, n+4, 2);
38 assert(r == 4);
40 n[0] = char(0xE1);
41 n[1] = char(0x80);
42 n[2] = char(0x85);
43 r = c.length(m, n, n+3, 2);
44 assert(r == 3);
46 n[0] = char(0xD1);
47 n[1] = char(0x93);
48 r = c.length(m, n, n+2, 2);
49 assert(r == 2);
51 n[0] = char(0x56);
52 r = c.length(m, n, n+1, 2);
53 assert(r == 1);
56 typedef std::codecvt_utf8_utf16<wchar_t, 0x1000> C;
57 C c;
58 char n[4] = {char(0xF1), char(0x80), char(0x80), char(0x83)};
59 std::mbstate_t m;
60 int r = c.length(m, n, n+4, 2);
61 assert(r == 0);
63 n[0] = char(0xE1);
64 n[1] = char(0x80);
65 n[2] = char(0x85);
66 r = c.length(m, n, n+3, 2);
67 assert(r == 0);
69 n[0] = char(0xD1);
70 n[1] = char(0x93);
71 r = c.length(m, n, n+2, 2);
72 assert(r == 2);
74 n[0] = char(0x56);
75 r = c.length(m, n, n+1, 2);
76 assert(r == 1);
79 typedef std::codecvt_utf8_utf16<wchar_t, 0x10ffff, std::consume_header> C;
80 C c;
81 char n[7] = {char(0xEF), char(0xBB), char(0xBF), char(0xF1), char(0x80), char(0x80), char(0x83)};
82 std::mbstate_t m;
83 int r = c.length(m, n, n+7, 2);
84 assert(r == 7);
86 n[0] = char(0xE1);
87 n[1] = char(0x80);
88 n[2] = char(0x85);
89 r = c.length(m, n, n+3, 2);
90 assert(r == 3);
92 n[0] = char(0xD1);
93 n[1] = char(0x93);
94 r = c.length(m, n, n+2, 2);
95 assert(r == 2);
97 n[0] = char(0x56);
98 r = c.length(m, n, n+1, 2);
99 assert(r == 1);
101 #endif // TEST_HAS_NO_WIDE_CHARACTERS
103 typedef std::codecvt_utf8_utf16<char32_t> C;
104 C c;
105 char n[4] = {char(0xF1), char(0x80), char(0x80), char(0x83)};
106 std::mbstate_t m;
107 int r = c.length(m, n, n+4, 2);
108 assert(r == 4);
110 n[0] = char(0xE1);
111 n[1] = char(0x80);
112 n[2] = char(0x85);
113 r = c.length(m, n, n+3, 2);
114 assert(r == 3);
116 n[0] = char(0xD1);
117 n[1] = char(0x93);
118 r = c.length(m, n, n+2, 2);
119 assert(r == 2);
121 n[0] = char(0x56);
122 r = c.length(m, n, n+1, 2);
123 assert(r == 1);
126 typedef std::codecvt_utf8_utf16<char32_t, 0x1000> C;
127 C c;
128 char n[4] = {char(0xF1), char(0x80), char(0x80), char(0x83)};
129 std::mbstate_t m;
130 int r = c.length(m, n, n+4, 2);
131 assert(r == 0);
133 n[0] = char(0xE1);
134 n[1] = char(0x80);
135 n[2] = char(0x85);
136 r = c.length(m, n, n+3, 2);
137 assert(r == 0);
139 n[0] = char(0xD1);
140 n[1] = char(0x93);
141 r = c.length(m, n, n+2, 2);
142 assert(r == 2);
144 n[0] = char(0x56);
145 r = c.length(m, n, n+1, 2);
146 assert(r == 1);
149 typedef std::codecvt_utf8_utf16<char32_t, 0x10ffff, std::consume_header> C;
150 C c;
151 char n[7] = {char(0xEF), char(0xBB), char(0xBF), char(0xF1), char(0x80), char(0x80), char(0x83)};
152 std::mbstate_t m;
153 int r = c.length(m, n, n+7, 2);
154 assert(r == 7);
156 n[0] = char(0xE1);
157 n[1] = char(0x80);
158 n[2] = char(0x85);
159 r = c.length(m, n, n+3, 2);
160 assert(r == 3);
162 n[0] = char(0xD1);
163 n[1] = char(0x93);
164 r = c.length(m, n, n+2, 2);
165 assert(r == 2);
167 n[0] = char(0x56);
168 r = c.length(m, n, n+1, 2);
169 assert(r == 1);
172 typedef std::codecvt_utf8_utf16<char16_t> C;
173 C c;
174 char n[4] = {char(0xF1), char(0x80), char(0x80), char(0x83)};
175 std::mbstate_t m;
176 int r = c.length(m, n, n+4, 2);
177 assert(r == 4);
179 n[0] = char(0xE1);
180 n[1] = char(0x80);
181 n[2] = char(0x85);
182 r = c.length(m, n, n+3, 2);
183 assert(r == 3);
185 n[0] = char(0xD1);
186 n[1] = char(0x93);
187 r = c.length(m, n, n+2, 2);
188 assert(r == 2);
190 n[0] = char(0x56);
191 r = c.length(m, n, n+1, 2);
192 assert(r == 1);
195 typedef std::codecvt_utf8_utf16<char16_t, 0x1000> C;
196 C c;
197 char n[4] = {char(0xF1), char(0x80), char(0x80), char(0x83)};
198 std::mbstate_t m;
199 int r = c.length(m, n, n+4, 2);
200 assert(r == 0);
202 n[0] = char(0xE1);
203 n[1] = char(0x80);
204 n[2] = char(0x85);
205 r = c.length(m, n, n+3, 2);
206 assert(r == 0);
208 n[0] = char(0xD1);
209 n[1] = char(0x93);
210 r = c.length(m, n, n+2, 2);
211 assert(r == 2);
213 n[0] = char(0x56);
214 r = c.length(m, n, n+1, 2);
215 assert(r == 1);
218 typedef std::codecvt_utf8_utf16<char16_t, 0x10ffff, std::consume_header> C;
219 C c;
220 char n[7] = {char(0xEF), char(0xBB), char(0xBF), char(0xF1), char(0x80), char(0x80), char(0x83)};
221 std::mbstate_t m;
222 int r = c.length(m, n, n+7, 2);
223 assert(r == 7);
225 n[0] = char(0xE1);
226 n[1] = char(0x80);
227 n[2] = char(0x85);
228 r = c.length(m, n, n+3, 2);
229 assert(r == 3);
231 n[0] = char(0xD1);
232 n[1] = char(0x93);
233 r = c.length(m, n, n+2, 2);
234 assert(r == 2);
236 n[0] = char(0x56);
237 r = c.length(m, n, n+1, 2);
238 assert(r == 1);
241 return 0;