[PowerPC][NFC] Cleanup PPCCTRLoopsVerify pass
[llvm-project.git] / libcxx / test / std / localization / locale.stdcvt / codecvt_utf8_utf16_length.pass.cpp
blob2dc4ce5bef7061c44f9f8506a01d09dd8573fd96
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 // template <class Elem, unsigned long Maxcode = 0x10ffff,
12 // codecvt_mode Mode = (codecvt_mode)0>
13 // class codecvt_utf8_utf16
14 // : public codecvt<Elem, char, mbstate_t>
15 // {
16 // // unspecified
17 // };
19 // int length(stateT& state, const externT* from, const externT* from_end,
20 // size_t max) const;
22 #include <codecvt>
23 #include <cassert>
25 #include "test_macros.h"
27 int main(int, char**)
30 typedef std::codecvt_utf8_utf16<wchar_t> C;
31 C c;
32 char n[4] = {char(0xF1), char(0x80), char(0x80), char(0x83)};
33 std::mbstate_t m;
34 int r = c.length(m, n, n+4, 2);
35 assert(r == 4);
37 n[0] = char(0xE1);
38 n[1] = char(0x80);
39 n[2] = char(0x85);
40 r = c.length(m, n, n+3, 2);
41 assert(r == 3);
43 n[0] = char(0xD1);
44 n[1] = char(0x93);
45 r = c.length(m, n, n+2, 2);
46 assert(r == 2);
48 n[0] = char(0x56);
49 r = c.length(m, n, n+1, 2);
50 assert(r == 1);
53 typedef std::codecvt_utf8_utf16<wchar_t, 0x1000> C;
54 C c;
55 char n[4] = {char(0xF1), char(0x80), char(0x80), char(0x83)};
56 std::mbstate_t m;
57 int r = c.length(m, n, n+4, 2);
58 assert(r == 0);
60 n[0] = char(0xE1);
61 n[1] = char(0x80);
62 n[2] = char(0x85);
63 r = c.length(m, n, n+3, 2);
64 assert(r == 0);
66 n[0] = char(0xD1);
67 n[1] = char(0x93);
68 r = c.length(m, n, n+2, 2);
69 assert(r == 2);
71 n[0] = char(0x56);
72 r = c.length(m, n, n+1, 2);
73 assert(r == 1);
76 typedef std::codecvt_utf8_utf16<wchar_t, 0x10ffff, std::consume_header> C;
77 C c;
78 char n[7] = {char(0xEF), char(0xBB), char(0xBF), char(0xF1), char(0x80), char(0x80), char(0x83)};
79 std::mbstate_t m;
80 int r = c.length(m, n, n+7, 2);
81 assert(r == 7);
83 n[0] = char(0xE1);
84 n[1] = char(0x80);
85 n[2] = char(0x85);
86 r = c.length(m, n, n+3, 2);
87 assert(r == 3);
89 n[0] = char(0xD1);
90 n[1] = char(0x93);
91 r = c.length(m, n, n+2, 2);
92 assert(r == 2);
94 n[0] = char(0x56);
95 r = c.length(m, n, n+1, 2);
96 assert(r == 1);
99 typedef std::codecvt_utf8_utf16<char32_t> C;
100 C c;
101 char n[4] = {char(0xF1), char(0x80), char(0x80), char(0x83)};
102 std::mbstate_t m;
103 int r = c.length(m, n, n+4, 2);
104 assert(r == 4);
106 n[0] = char(0xE1);
107 n[1] = char(0x80);
108 n[2] = char(0x85);
109 r = c.length(m, n, n+3, 2);
110 assert(r == 3);
112 n[0] = char(0xD1);
113 n[1] = char(0x93);
114 r = c.length(m, n, n+2, 2);
115 assert(r == 2);
117 n[0] = char(0x56);
118 r = c.length(m, n, n+1, 2);
119 assert(r == 1);
122 typedef std::codecvt_utf8_utf16<char32_t, 0x1000> C;
123 C c;
124 char n[4] = {char(0xF1), char(0x80), char(0x80), char(0x83)};
125 std::mbstate_t m;
126 int r = c.length(m, n, n+4, 2);
127 assert(r == 0);
129 n[0] = char(0xE1);
130 n[1] = char(0x80);
131 n[2] = char(0x85);
132 r = c.length(m, n, n+3, 2);
133 assert(r == 0);
135 n[0] = char(0xD1);
136 n[1] = char(0x93);
137 r = c.length(m, n, n+2, 2);
138 assert(r == 2);
140 n[0] = char(0x56);
141 r = c.length(m, n, n+1, 2);
142 assert(r == 1);
145 typedef std::codecvt_utf8_utf16<char32_t, 0x10ffff, std::consume_header> C;
146 C c;
147 char n[7] = {char(0xEF), char(0xBB), char(0xBF), char(0xF1), char(0x80), char(0x80), char(0x83)};
148 std::mbstate_t m;
149 int r = c.length(m, n, n+7, 2);
150 assert(r == 7);
152 n[0] = char(0xE1);
153 n[1] = char(0x80);
154 n[2] = char(0x85);
155 r = c.length(m, n, n+3, 2);
156 assert(r == 3);
158 n[0] = char(0xD1);
159 n[1] = char(0x93);
160 r = c.length(m, n, n+2, 2);
161 assert(r == 2);
163 n[0] = char(0x56);
164 r = c.length(m, n, n+1, 2);
165 assert(r == 1);
168 typedef std::codecvt_utf8_utf16<char16_t> C;
169 C c;
170 char n[4] = {char(0xF1), char(0x80), char(0x80), char(0x83)};
171 std::mbstate_t m;
172 int r = c.length(m, n, n+4, 2);
173 assert(r == 4);
175 n[0] = char(0xE1);
176 n[1] = char(0x80);
177 n[2] = char(0x85);
178 r = c.length(m, n, n+3, 2);
179 assert(r == 3);
181 n[0] = char(0xD1);
182 n[1] = char(0x93);
183 r = c.length(m, n, n+2, 2);
184 assert(r == 2);
186 n[0] = char(0x56);
187 r = c.length(m, n, n+1, 2);
188 assert(r == 1);
191 typedef std::codecvt_utf8_utf16<char16_t, 0x1000> C;
192 C c;
193 char n[4] = {char(0xF1), char(0x80), char(0x80), char(0x83)};
194 std::mbstate_t m;
195 int r = c.length(m, n, n+4, 2);
196 assert(r == 0);
198 n[0] = char(0xE1);
199 n[1] = char(0x80);
200 n[2] = char(0x85);
201 r = c.length(m, n, n+3, 2);
202 assert(r == 0);
204 n[0] = char(0xD1);
205 n[1] = char(0x93);
206 r = c.length(m, n, n+2, 2);
207 assert(r == 2);
209 n[0] = char(0x56);
210 r = c.length(m, n, n+1, 2);
211 assert(r == 1);
214 typedef std::codecvt_utf8_utf16<char16_t, 0x10ffff, std::consume_header> C;
215 C c;
216 char n[7] = {char(0xEF), char(0xBB), char(0xBF), char(0xF1), char(0x80), char(0x80), char(0x83)};
217 std::mbstate_t m;
218 int r = c.length(m, n, n+7, 2);
219 assert(r == 7);
221 n[0] = char(0xE1);
222 n[1] = char(0x80);
223 n[2] = char(0x85);
224 r = c.length(m, n, n+3, 2);
225 assert(r == 3);
227 n[0] = char(0xD1);
228 n[1] = char(0x93);
229 r = c.length(m, n, n+2, 2);
230 assert(r == 2);
232 n[0] = char(0x56);
233 r = c.length(m, n, n+1, 2);
234 assert(r == 1);
237 return 0;