1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 // <codecvt>
11 
12 // template <class Elem, unsigned long Maxcode = 0x10ffff,
13 //           codecvt_mode Mode = (codecvt_mode)0>
14 // class codecvt_utf16
15 //     : public codecvt<Elem, char, mbstate_t>
16 // {
17 //     // unspecified
18 // };
19 
20 // result
21 //     in(stateT& state,
22 //        const externT* from, const externT* from_end, const externT*& from_next,
23 //        internT* to, internT* to_end, internT*& to_next) const;
24 
25 #include <codecvt>
26 #include <cassert>
27 
main()28 int main()
29 {
30     {
31         typedef std::codecvt_utf16<wchar_t> C;
32         C c;
33         wchar_t w = 0;
34         char n[4] = {char(0xD8), char(0xC0), char(0xDC), char(0x03)};
35         wchar_t* wp = nullptr;
36         std::mbstate_t m;
37         const char* np = nullptr;
38         std::codecvt_base::result r = c.in(m, n, n+4, np, &w, &w+1, wp);
39         assert(r == std::codecvt_base::ok);
40         assert(wp == &w+1);
41         assert(np == n+4);
42         assert(w == 0x40003);
43 
44         n[0] = char(0x10);
45         n[1] = char(0x05);
46         r = c.in(m, n, n+2, np, &w, &w+1, wp);
47         assert(r == std::codecvt_base::ok);
48         assert(wp == &w+1);
49         assert(np == n+2);
50         assert(w == 0x1005);
51 
52         n[0] = char(0x04);
53         n[1] = char(0x53);
54         r = c.in(m, n, n+2, np, &w, &w+1, wp);
55         assert(r == std::codecvt_base::ok);
56         assert(wp == &w+1);
57         assert(np == n+2);
58         assert(w == 0x453);
59 
60         w = 0x56;
61         n[0] = char(0x00);
62         n[1] = char(0x56);
63         r = c.in(m, n, n+2, np, &w, &w+1, wp);
64         assert(r == std::codecvt_base::ok);
65         assert(wp == &w+1);
66         assert(np == n+2);
67         assert(w == 0x56);
68     }
69     {
70         typedef std::codecvt_utf16<wchar_t, 0x1000> C;
71         C c;
72         wchar_t w = 0;
73         char n[4] = {char(0xD8), char(0xC0), char(0xDC), char(0x03)};
74         wchar_t* wp = nullptr;
75         std::mbstate_t m;
76         const char* np = nullptr;
77         std::codecvt_base::result r = c.in(m, n, n+4, np, &w, &w+1, wp);
78         assert(r == std::codecvt_base::error);
79         assert(wp == &w);
80         assert(np == n);
81         assert(w == 0);
82 
83         n[0] = char(0x10);
84         n[1] = char(0x05);
85         r = c.in(m, n, n+2, np, &w, &w+1, wp);
86         assert(r == std::codecvt_base::error);
87         assert(wp == &w);
88         assert(np == n);
89         assert(w == 0);
90 
91         n[0] = char(0x04);
92         n[1] = char(0x53);
93         r = c.in(m, n, n+2, np, &w, &w+1, wp);
94         assert(r == std::codecvt_base::ok);
95         assert(wp == &w+1);
96         assert(np == n+2);
97         assert(w == 0x453);
98 
99         w = 0x56;
100         n[0] = char(0x00);
101         n[1] = char(0x56);
102         r = c.in(m, n, n+2, np, &w, &w+1, wp);
103         assert(r == std::codecvt_base::ok);
104         assert(wp == &w+1);
105         assert(np == n+2);
106         assert(w == 0x56);
107     }
108     {
109         typedef std::codecvt_utf16<wchar_t, 0x10ffff, std::consume_header> C;
110         C c;
111         wchar_t w = 0;
112         char n[6] = {char(0xFE), char(0xFF), char(0xD8), char(0xC0), char(0xDC), char(0x03)};
113         wchar_t* wp = nullptr;
114         std::mbstate_t m;
115         const char* np = nullptr;
116         std::codecvt_base::result r = c.in(m, n, n+6, np, &w, &w+1, wp);
117         assert(r == std::codecvt_base::ok);
118         assert(wp == &w+1);
119         assert(np == n+6);
120         assert(w == 0x40003);
121 
122         n[0] = char(0x10);
123         n[1] = char(0x05);
124         r = c.in(m, n, n+2, np, &w, &w+1, wp);
125         assert(r == std::codecvt_base::ok);
126         assert(wp == &w+1);
127         assert(np == n+2);
128         assert(w == 0x1005);
129 
130         n[0] = char(0x04);
131         n[1] = char(0x53);
132         r = c.in(m, n, n+2, np, &w, &w+1, wp);
133         assert(r == std::codecvt_base::ok);
134         assert(wp == &w+1);
135         assert(np == n+2);
136         assert(w == 0x453);
137 
138         w = 0x56;
139         n[0] = char(0x00);
140         n[1] = char(0x56);
141         r = c.in(m, n, n+2, np, &w, &w+1, wp);
142         assert(r == std::codecvt_base::ok);
143         assert(wp == &w+1);
144         assert(np == n+2);
145         assert(w == 0x56);
146     }
147     {
148         typedef std::codecvt_utf16<wchar_t, 0x10ffff, std::little_endian> C;
149         C c;
150         wchar_t w = 0;
151         char n[4] = {char(0xC0), char(0xD8), char(0x03), char(0xDC)};
152         wchar_t* wp = nullptr;
153         std::mbstate_t m;
154         const char* np = nullptr;
155         std::codecvt_base::result r = c.in(m, n, n+4, np, &w, &w+1, wp);
156         assert(r == std::codecvt_base::ok);
157         assert(wp == &w+1);
158         assert(np == n+4);
159         assert(w == 0x40003);
160 
161         n[1] = char(0x10);
162         n[0] = char(0x05);
163         r = c.in(m, n, n+2, np, &w, &w+1, wp);
164         assert(r == std::codecvt_base::ok);
165         assert(wp == &w+1);
166         assert(np == n+2);
167         assert(w == 0x1005);
168 
169         n[1] = char(0x04);
170         n[0] = char(0x53);
171         r = c.in(m, n, n+2, np, &w, &w+1, wp);
172         assert(r == std::codecvt_base::ok);
173         assert(wp == &w+1);
174         assert(np == n+2);
175         assert(w == 0x453);
176 
177         w = 0x56;
178         n[1] = char(0x00);
179         n[0] = char(0x56);
180         r = c.in(m, n, n+2, np, &w, &w+1, wp);
181         assert(r == std::codecvt_base::ok);
182         assert(wp == &w+1);
183         assert(np == n+2);
184         assert(w == 0x56);
185     }
186     {
187         typedef std::codecvt_utf16<wchar_t, 0x1000, std::little_endian> C;
188         C c;
189         wchar_t w = 0;
190         char n[4] = {char(0xC0), char(0xD8), char(0x03), char(0xDC)};
191         wchar_t* wp = nullptr;
192         std::mbstate_t m;
193         const char* np = nullptr;
194         std::codecvt_base::result r = c.in(m, n, n+4, np, &w, &w+1, wp);
195         assert(r == std::codecvt_base::error);
196         assert(wp == &w);
197         assert(np == n);
198         assert(w == 0);
199 
200         n[1] = char(0x10);
201         n[0] = char(0x05);
202         r = c.in(m, n, n+2, np, &w, &w+1, wp);
203         assert(r == std::codecvt_base::error);
204         assert(wp == &w);
205         assert(np == n);
206         assert(w == 0);
207 
208         n[1] = char(0x04);
209         n[0] = char(0x53);
210         r = c.in(m, n, n+2, np, &w, &w+1, wp);
211         assert(r == std::codecvt_base::ok);
212         assert(wp == &w+1);
213         assert(np == n+2);
214         assert(w == 0x453);
215 
216         w = 0x56;
217         n[1] = char(0x00);
218         n[0] = char(0x56);
219         r = c.in(m, n, n+2, np, &w, &w+1, wp);
220         assert(r == std::codecvt_base::ok);
221         assert(wp == &w+1);
222         assert(np == n+2);
223         assert(w == 0x56);
224     }
225     {
226         typedef std::codecvt_utf16<wchar_t, 0x10ffff, std::codecvt_mode(
227                                                          std::consume_header |
228                                                          std::little_endian)> C;
229         C c;
230         wchar_t w = 0;
231         char n[6] = {char(0xFF), char(0xFE), char(0xC0), char(0xD8), char(0x03), char(0xDC)};
232         wchar_t* wp = nullptr;
233         std::mbstate_t m;
234         const char* np = nullptr;
235         std::codecvt_base::result r = c.in(m, n, n+6, np, &w, &w+1, wp);
236         assert(r == std::codecvt_base::ok);
237         assert(wp == &w+1);
238         assert(np == n+6);
239         assert(w == 0x40003);
240 
241         n[1] = char(0x10);
242         n[0] = char(0x05);
243         r = c.in(m, n, n+2, np, &w, &w+1, wp);
244         assert(r == std::codecvt_base::ok);
245         assert(wp == &w+1);
246         assert(np == n+2);
247         assert(w == 0x1005);
248 
249         n[1] = char(0x04);
250         n[0] = char(0x53);
251         r = c.in(m, n, n+2, np, &w, &w+1, wp);
252         assert(r == std::codecvt_base::ok);
253         assert(wp == &w+1);
254         assert(np == n+2);
255         assert(w == 0x453);
256 
257         w = 0x56;
258         n[1] = char(0x00);
259         n[0] = char(0x56);
260         r = c.in(m, n, n+2, np, &w, &w+1, wp);
261         assert(r == std::codecvt_base::ok);
262         assert(wp == &w+1);
263         assert(np == n+2);
264         assert(w == 0x56);
265     }
266     {
267         typedef std::codecvt_utf16<char32_t> C;
268         C c;
269         char32_t w = 0;
270         char n[4] = {char(0xD8), char(0xC0), char(0xDC), char(0x03)};
271         char32_t* wp = nullptr;
272         std::mbstate_t m;
273         const char* np = nullptr;
274         std::codecvt_base::result r = c.in(m, n, n+4, np, &w, &w+1, wp);
275         assert(r == std::codecvt_base::ok);
276         assert(wp == &w+1);
277         assert(np == n+4);
278         assert(w == 0x40003);
279 
280         n[0] = char(0x10);
281         n[1] = char(0x05);
282         r = c.in(m, n, n+2, np, &w, &w+1, wp);
283         assert(r == std::codecvt_base::ok);
284         assert(wp == &w+1);
285         assert(np == n+2);
286         assert(w == 0x1005);
287 
288         n[0] = char(0x04);
289         n[1] = char(0x53);
290         r = c.in(m, n, n+2, np, &w, &w+1, wp);
291         assert(r == std::codecvt_base::ok);
292         assert(wp == &w+1);
293         assert(np == n+2);
294         assert(w == 0x453);
295 
296         w = 0x56;
297         n[0] = char(0x00);
298         n[1] = char(0x56);
299         r = c.in(m, n, n+2, np, &w, &w+1, wp);
300         assert(r == std::codecvt_base::ok);
301         assert(wp == &w+1);
302         assert(np == n+2);
303         assert(w == 0x56);
304     }
305     {
306         typedef std::codecvt_utf16<char32_t, 0x1000> C;
307         C c;
308         char32_t w = 0;
309         char n[4] = {char(0xD8), char(0xC0), char(0xDC), char(0x03)};
310         char32_t* wp = nullptr;
311         std::mbstate_t m;
312         const char* np = nullptr;
313         std::codecvt_base::result r = c.in(m, n, n+4, np, &w, &w+1, wp);
314         assert(r == std::codecvt_base::error);
315         assert(wp == &w);
316         assert(np == n);
317         assert(w == 0);
318 
319         n[0] = char(0x10);
320         n[1] = char(0x05);
321         r = c.in(m, n, n+2, np, &w, &w+1, wp);
322         assert(r == std::codecvt_base::error);
323         assert(wp == &w);
324         assert(np == n);
325         assert(w == 0);
326 
327         n[0] = char(0x04);
328         n[1] = char(0x53);
329         r = c.in(m, n, n+2, np, &w, &w+1, wp);
330         assert(r == std::codecvt_base::ok);
331         assert(wp == &w+1);
332         assert(np == n+2);
333         assert(w == 0x453);
334 
335         w = 0x56;
336         n[0] = char(0x00);
337         n[1] = char(0x56);
338         r = c.in(m, n, n+2, np, &w, &w+1, wp);
339         assert(r == std::codecvt_base::ok);
340         assert(wp == &w+1);
341         assert(np == n+2);
342         assert(w == 0x56);
343     }
344     {
345         typedef std::codecvt_utf16<char32_t, 0x10ffff, std::consume_header> C;
346         C c;
347         char32_t w = 0;
348         char n[6] = {char(0xFE), char(0xFF), char(0xD8), char(0xC0), char(0xDC), char(0x03)};
349         char32_t* wp = nullptr;
350         std::mbstate_t m;
351         const char* np = nullptr;
352         std::codecvt_base::result r = c.in(m, n, n+6, np, &w, &w+1, wp);
353         assert(r == std::codecvt_base::ok);
354         assert(wp == &w+1);
355         assert(np == n+6);
356         assert(w == 0x40003);
357 
358         n[0] = char(0x10);
359         n[1] = char(0x05);
360         r = c.in(m, n, n+2, np, &w, &w+1, wp);
361         assert(r == std::codecvt_base::ok);
362         assert(wp == &w+1);
363         assert(np == n+2);
364         assert(w == 0x1005);
365 
366         n[0] = char(0x04);
367         n[1] = char(0x53);
368         r = c.in(m, n, n+2, np, &w, &w+1, wp);
369         assert(r == std::codecvt_base::ok);
370         assert(wp == &w+1);
371         assert(np == n+2);
372         assert(w == 0x453);
373 
374         w = 0x56;
375         n[0] = char(0x00);
376         n[1] = char(0x56);
377         r = c.in(m, n, n+2, np, &w, &w+1, wp);
378         assert(r == std::codecvt_base::ok);
379         assert(wp == &w+1);
380         assert(np == n+2);
381         assert(w == 0x56);
382     }
383     {
384         typedef std::codecvt_utf16<char32_t, 0x10ffff, std::little_endian> C;
385         C c;
386         char32_t w = 0;
387         char n[4] = {char(0xC0), char(0xD8), char(0x03), char(0xDC)};
388         char32_t* wp = nullptr;
389         std::mbstate_t m;
390         const char* np = nullptr;
391         std::codecvt_base::result r = c.in(m, n, n+4, np, &w, &w+1, wp);
392         assert(r == std::codecvt_base::ok);
393         assert(wp == &w+1);
394         assert(np == n+4);
395         assert(w == 0x40003);
396 
397         n[1] = char(0x10);
398         n[0] = char(0x05);
399         r = c.in(m, n, n+2, np, &w, &w+1, wp);
400         assert(r == std::codecvt_base::ok);
401         assert(wp == &w+1);
402         assert(np == n+2);
403         assert(w == 0x1005);
404 
405         n[1] = char(0x04);
406         n[0] = char(0x53);
407         r = c.in(m, n, n+2, np, &w, &w+1, wp);
408         assert(r == std::codecvt_base::ok);
409         assert(wp == &w+1);
410         assert(np == n+2);
411         assert(w == 0x453);
412 
413         w = 0x56;
414         n[1] = char(0x00);
415         n[0] = char(0x56);
416         r = c.in(m, n, n+2, np, &w, &w+1, wp);
417         assert(r == std::codecvt_base::ok);
418         assert(wp == &w+1);
419         assert(np == n+2);
420         assert(w == 0x56);
421     }
422     {
423         typedef std::codecvt_utf16<char32_t, 0x1000, std::little_endian> C;
424         C c;
425         char32_t w = 0;
426         char n[4] = {char(0xC0), char(0xD8), char(0x03), char(0xDC)};
427         char32_t* wp = nullptr;
428         std::mbstate_t m;
429         const char* np = nullptr;
430         std::codecvt_base::result r = c.in(m, n, n+4, np, &w, &w+1, wp);
431         assert(r == std::codecvt_base::error);
432         assert(wp == &w);
433         assert(np == n);
434         assert(w == 0);
435 
436         n[1] = char(0x10);
437         n[0] = char(0x05);
438         r = c.in(m, n, n+2, np, &w, &w+1, wp);
439         assert(r == std::codecvt_base::error);
440         assert(wp == &w);
441         assert(np == n);
442         assert(w == 0);
443 
444         n[1] = char(0x04);
445         n[0] = char(0x53);
446         r = c.in(m, n, n+2, np, &w, &w+1, wp);
447         assert(r == std::codecvt_base::ok);
448         assert(wp == &w+1);
449         assert(np == n+2);
450         assert(w == 0x453);
451 
452         w = 0x56;
453         n[1] = char(0x00);
454         n[0] = char(0x56);
455         r = c.in(m, n, n+2, np, &w, &w+1, wp);
456         assert(r == std::codecvt_base::ok);
457         assert(wp == &w+1);
458         assert(np == n+2);
459         assert(w == 0x56);
460     }
461     {
462         typedef std::codecvt_utf16<char32_t, 0x10ffff, std::codecvt_mode(
463                                                          std::consume_header |
464                                                          std::little_endian)> C;
465         C c;
466         char32_t w = 0;
467         char n[6] = {char(0xFF), char(0xFE), char(0xC0), char(0xD8), char(0x03), char(0xDC)};
468         char32_t* wp = nullptr;
469         std::mbstate_t m;
470         const char* np = nullptr;
471         std::codecvt_base::result r = c.in(m, n, n+6, np, &w, &w+1, wp);
472         assert(r == std::codecvt_base::ok);
473         assert(wp == &w+1);
474         assert(np == n+6);
475         assert(w == 0x40003);
476 
477         n[1] = char(0x10);
478         n[0] = char(0x05);
479         r = c.in(m, n, n+2, np, &w, &w+1, wp);
480         assert(r == std::codecvt_base::ok);
481         assert(wp == &w+1);
482         assert(np == n+2);
483         assert(w == 0x1005);
484 
485         n[1] = char(0x04);
486         n[0] = char(0x53);
487         r = c.in(m, n, n+2, np, &w, &w+1, wp);
488         assert(r == std::codecvt_base::ok);
489         assert(wp == &w+1);
490         assert(np == n+2);
491         assert(w == 0x453);
492 
493         w = 0x56;
494         n[1] = char(0x00);
495         n[0] = char(0x56);
496         r = c.in(m, n, n+2, np, &w, &w+1, wp);
497         assert(r == std::codecvt_base::ok);
498         assert(wp == &w+1);
499         assert(np == n+2);
500         assert(w == 0x56);
501     }
502 
503     {
504         typedef std::codecvt_utf16<char16_t> C;
505         C c;
506         char16_t w = 0;
507         char n[4] = {char(0xD8), char(0xC0), char(0xDC), char(0x03)};
508         char16_t* wp = nullptr;
509         std::mbstate_t m;
510         const char* np = nullptr;
511         std::codecvt_base::result r = c.in(m, n, n+4, np, &w, &w+1, wp);
512         assert(r == std::codecvt_base::error);
513         assert(wp == &w);
514         assert(np == n);
515         assert(w == 0);
516 
517         n[0] = char(0x10);
518         n[1] = char(0x05);
519         r = c.in(m, n, n+2, np, &w, &w+1, wp);
520         assert(r == std::codecvt_base::ok);
521         assert(wp == &w+1);
522         assert(np == n+2);
523         assert(w == 0x1005);
524 
525         n[0] = char(0x04);
526         n[1] = char(0x53);
527         r = c.in(m, n, n+2, np, &w, &w+1, wp);
528         assert(r == std::codecvt_base::ok);
529         assert(wp == &w+1);
530         assert(np == n+2);
531         assert(w == 0x453);
532 
533         w = 0x56;
534         n[0] = char(0x00);
535         n[1] = char(0x56);
536         r = c.in(m, n, n+2, np, &w, &w+1, wp);
537         assert(r == std::codecvt_base::ok);
538         assert(wp == &w+1);
539         assert(np == n+2);
540         assert(w == 0x56);
541     }
542     {
543         typedef std::codecvt_utf16<char16_t, 0x1000> C;
544         C c;
545         char16_t w = 0;
546         char n[4] = {char(0xD8), char(0xC0), char(0xDC), char(0x03)};
547         char16_t* wp = nullptr;
548         std::mbstate_t m;
549         const char* np = nullptr;
550         std::codecvt_base::result r = c.in(m, n, n+4, np, &w, &w+1, wp);
551         assert(r == std::codecvt_base::error);
552         assert(wp == &w);
553         assert(np == n);
554         assert(w == 0);
555 
556         n[0] = char(0x10);
557         n[1] = char(0x05);
558         r = c.in(m, n, n+2, np, &w, &w+1, wp);
559         assert(r == std::codecvt_base::error);
560         assert(wp == &w);
561         assert(np == n);
562         assert(w == 0);
563 
564         n[0] = char(0x04);
565         n[1] = char(0x53);
566         r = c.in(m, n, n+2, np, &w, &w+1, wp);
567         assert(r == std::codecvt_base::ok);
568         assert(wp == &w+1);
569         assert(np == n+2);
570         assert(w == 0x453);
571 
572         w = 0x56;
573         n[0] = char(0x00);
574         n[1] = char(0x56);
575         r = c.in(m, n, n+2, np, &w, &w+1, wp);
576         assert(r == std::codecvt_base::ok);
577         assert(wp == &w+1);
578         assert(np == n+2);
579         assert(w == 0x56);
580     }
581     {
582         typedef std::codecvt_utf16<char16_t, 0x10ffff, std::consume_header> C;
583         C c;
584         char16_t w = 0;
585         char n[6] = {char(0xFE), char(0xFF), char(0xD8), char(0xC0), char(0xDC), char(0x03)};
586         char16_t* wp = nullptr;
587         std::mbstate_t m;
588         const char* np = nullptr;
589         std::codecvt_base::result r = c.in(m, n, n+6, np, &w, &w+1, wp);
590         assert(r == std::codecvt_base::error);
591         assert(wp == &w);
592         assert(np == n+2);
593         assert(w == 0);
594 
595         n[0] = char(0x10);
596         n[1] = char(0x05);
597         r = c.in(m, n, n+2, np, &w, &w+1, wp);
598         assert(r == std::codecvt_base::ok);
599         assert(wp == &w+1);
600         assert(np == n+2);
601         assert(w == 0x1005);
602 
603         n[0] = char(0x04);
604         n[1] = char(0x53);
605         r = c.in(m, n, n+2, np, &w, &w+1, wp);
606         assert(r == std::codecvt_base::ok);
607         assert(wp == &w+1);
608         assert(np == n+2);
609         assert(w == 0x453);
610 
611         w = 0x56;
612         n[0] = char(0x00);
613         n[1] = char(0x56);
614         r = c.in(m, n, n+2, np, &w, &w+1, wp);
615         assert(r == std::codecvt_base::ok);
616         assert(wp == &w+1);
617         assert(np == n+2);
618         assert(w == 0x56);
619     }
620     {
621         typedef std::codecvt_utf16<char16_t, 0x10ffff, std::little_endian> C;
622         C c;
623         char16_t w = 0;
624         char n[4] = {char(0xC0), char(0xD8), char(0x03), char(0xDC)};
625         char16_t* wp = nullptr;
626         std::mbstate_t m;
627         const char* np = nullptr;
628         std::codecvt_base::result r = c.in(m, n, n+4, np, &w, &w+1, wp);
629         assert(r == std::codecvt_base::error);
630         assert(wp == &w);
631         assert(np == n);
632         assert(w == 0);
633 
634         n[1] = char(0x10);
635         n[0] = char(0x05);
636         r = c.in(m, n, n+2, np, &w, &w+1, wp);
637         assert(r == std::codecvt_base::ok);
638         assert(wp == &w+1);
639         assert(np == n+2);
640         assert(w == 0x1005);
641 
642         n[1] = char(0x04);
643         n[0] = char(0x53);
644         r = c.in(m, n, n+2, np, &w, &w+1, wp);
645         assert(r == std::codecvt_base::ok);
646         assert(wp == &w+1);
647         assert(np == n+2);
648         assert(w == 0x453);
649 
650         w = 0x56;
651         n[1] = char(0x00);
652         n[0] = char(0x56);
653         r = c.in(m, n, n+2, np, &w, &w+1, wp);
654         assert(r == std::codecvt_base::ok);
655         assert(wp == &w+1);
656         assert(np == n+2);
657         assert(w == 0x56);
658     }
659     {
660         typedef std::codecvt_utf16<char16_t, 0x1000, std::little_endian> C;
661         C c;
662         char16_t w = 0;
663         char n[4] = {char(0xC0), char(0xD8), char(0x03), char(0xDC)};
664         char16_t* wp = nullptr;
665         std::mbstate_t m;
666         const char* np = nullptr;
667         std::codecvt_base::result r = c.in(m, n, n+4, np, &w, &w+1, wp);
668         assert(r == std::codecvt_base::error);
669         assert(wp == &w);
670         assert(np == n);
671         assert(w == 0);
672 
673         n[1] = char(0x10);
674         n[0] = char(0x05);
675         r = c.in(m, n, n+2, np, &w, &w+1, wp);
676         assert(r == std::codecvt_base::error);
677         assert(wp == &w);
678         assert(np == n);
679         assert(w == 0);
680 
681         n[1] = char(0x04);
682         n[0] = char(0x53);
683         r = c.in(m, n, n+2, np, &w, &w+1, wp);
684         assert(r == std::codecvt_base::ok);
685         assert(wp == &w+1);
686         assert(np == n+2);
687         assert(w == 0x453);
688 
689         w = 0x56;
690         n[1] = char(0x00);
691         n[0] = char(0x56);
692         r = c.in(m, n, n+2, np, &w, &w+1, wp);
693         assert(r == std::codecvt_base::ok);
694         assert(wp == &w+1);
695         assert(np == n+2);
696         assert(w == 0x56);
697     }
698     {
699         typedef std::codecvt_utf16<char16_t, 0x10ffff, std::codecvt_mode(
700                                                          std::consume_header |
701                                                          std::little_endian)> C;
702         C c;
703         char16_t w = 0;
704         char n[6] = {char(0xFF), char(0xFE), char(0xC0), char(0xD8), char(0x03), char(0xDC)};
705         char16_t* wp = nullptr;
706         std::mbstate_t m;
707         const char* np = nullptr;
708         std::codecvt_base::result r = c.in(m, n, n+6, np, &w, &w+1, wp);
709         assert(r == std::codecvt_base::error);
710         assert(wp == &w);
711         assert(np == n+2);
712         assert(w == 0);
713 
714         n[1] = char(0x10);
715         n[0] = char(0x05);
716         r = c.in(m, n, n+2, np, &w, &w+1, wp);
717         assert(r == std::codecvt_base::ok);
718         assert(wp == &w+1);
719         assert(np == n+2);
720         assert(w == 0x1005);
721 
722         n[1] = char(0x04);
723         n[0] = char(0x53);
724         r = c.in(m, n, n+2, np, &w, &w+1, wp);
725         assert(r == std::codecvt_base::ok);
726         assert(wp == &w+1);
727         assert(np == n+2);
728         assert(w == 0x453);
729 
730         w = 0x56;
731         n[1] = char(0x00);
732         n[0] = char(0x56);
733         r = c.in(m, n, n+2, np, &w, &w+1, wp);
734         assert(r == std::codecvt_base::ok);
735         assert(wp == &w+1);
736         assert(np == n+2);
737         assert(w == 0x56);
738     }
739 }
740