]>
Commit | Line | Data |
---|---|---|
818ab71a | 1 | // Copyright (C) 2015-2016 Free Software Foundation, Inc. |
795038b7 JW |
2 | // |
3 | // This file is part of the GNU ISO C++ Library. This library is free | |
4 | // software; you can redistribute it and/or modify it under the | |
5 | // terms of the GNU General Public License as published by the | |
6 | // Free Software Foundation; either version 3, or (at your option) | |
7 | // any later version. | |
8 | ||
9 | // This library is distributed in the hope that it will be useful, | |
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | // GNU General Public License for more details. | |
13 | ||
14 | // You should have received a copy of the GNU General Public License along | |
15 | // with this library; see the file COPYING3. If not see | |
16 | // <http://www.gnu.org/licenses/>. | |
17 | ||
52066eae | 18 | // { dg-do run { target c++11 } } |
795038b7 JW |
19 | |
20 | #include <codecvt> | |
21 | #include <testsuite_hooks.h> | |
22 | ||
23 | void | |
24 | test01() | |
25 | { | |
26 | std::codecvt_utf8_utf16<char16_t> cvt; | |
27 | char16_t utf16[] = u"\ub098\ub294\ud0dc\uc624"; | |
28 | const char16_t* nf16; | |
29 | char utf8[16]; | |
30 | char* nt8; | |
31 | std::mbstate_t st{}; | |
32 | auto res = cvt.out(st, utf16, utf16+4, nf16, utf8, utf8+16, nt8); | |
33 | VERIFY( res == std::codecvt_base::ok ); | |
34 | ||
35 | st = {}; | |
36 | char16_t buf[4] = {}; | |
37 | const char* nf8 = nt8; | |
38 | char16_t* nt16; | |
39 | res = cvt.in(st, utf8, nf8, nf8, buf, buf+4, nt16); | |
40 | VERIFY( res == std::codecvt_base::ok ); | |
41 | VERIFY( nt16 == buf+4 ); | |
42 | VERIFY( buf[0] == utf16[0] ); | |
43 | VERIFY( buf[1] == utf16[1] ); | |
44 | VERIFY( buf[2] == utf16[2] ); | |
45 | VERIFY( buf[3] == utf16[3] ); | |
46 | } | |
47 | ||
29ca91f7 JW |
48 | void |
49 | test02() | |
50 | { | |
51 | // Endianness flag should make no difference. | |
52 | std::codecvt_utf8_utf16<char16_t, 0x10ffff, std::little_endian> cvt; | |
53 | char16_t utf16[] = u"\ub098\ub294\ud0dc\uc624"; | |
54 | const char16_t* nf16; | |
55 | char utf8[16]; | |
56 | char* nt8; | |
57 | std::mbstate_t st{}; | |
58 | auto res = cvt.out(st, utf16, utf16+4, nf16, utf8, utf8+16, nt8); | |
59 | VERIFY( res == std::codecvt_base::ok ); | |
60 | ||
61 | st = {}; | |
62 | char16_t buf[4] = {}; | |
63 | const char* nf8 = nt8; | |
64 | char16_t* nt16; | |
65 | res = cvt.in(st, utf8, nf8, nf8, buf, buf+4, nt16); | |
66 | VERIFY( res == std::codecvt_base::ok ); | |
67 | VERIFY( nt16 == buf+4 ); | |
68 | VERIFY( buf[0] == utf16[0] ); | |
69 | VERIFY( buf[1] == utf16[1] ); | |
70 | VERIFY( buf[2] == utf16[2] ); | |
71 | VERIFY( buf[3] == utf16[3] ); | |
72 | } | |
73 | ||
795038b7 JW |
74 | int |
75 | main() | |
76 | { | |
77 | test01(); | |
29ca91f7 | 78 | test02(); |
795038b7 | 79 | } |