05e5bc68f2304ab0750b3d60010064125b568c5b
[gcc.git] / libstdc++-v3 / testsuite / 22_locale / codecvt / codecvt_utf8_utf16 / 66855.cc
1 // Copyright (C) 2015-2016 Free Software Foundation, Inc.
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
18 // { dg-options "-std=gnu++11" }
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
48 int
49 main()
50 {
51 test01();
52 }