1 // Copyright (C) 2015-2021 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-do run { target c++11 } }
19 
20 #include <codecvt>
21 #include <testsuite_hooks.h>
22 
23 using namespace std;
24 
25 void
test01()26 test01()
27 {
28   constexpr auto mode = generate_header;
29   codecvt_utf16<char32_t, 0x10ffff, mode> cvt;
30   mbstate_t state{};
31   const char32_t* from = U"ABC";
32   const char32_t* from_next;
33   char to[100];
34   char* to_next;
35 
36   cvt.out(state, from, from + 3, from_next, to, to + 100, to_next);
37 
38   VERIFY((unsigned char)to[0] == 0xfe);
39   VERIFY((unsigned char)to[1] == 0xff);
40   VERIFY(to[2] == 0x00);
41   VERIFY(to[3] == 0x41);
42   VERIFY(to[4] == 0x00);
43   VERIFY(to[5] == 0x42);
44   VERIFY(to[6] == 0x00);
45   VERIFY(to[7] == 0x43);
46 }
47 
48 void
test02()49 test02()
50 {
51   constexpr auto mode = codecvt_mode(generate_header|little_endian);
52   codecvt_utf16<char32_t, 0x10ffff, mode> cvt;
53   mbstate_t state{};
54   const char32_t* from = U"ABC";
55   const char32_t* from_next;
56   char to[100];
57   char* to_next;
58 
59   cvt.out(state, from, from + 3, from_next, to, to + 100, to_next);
60 
61   VERIFY((unsigned char)to[0] == 0xff);
62   VERIFY((unsigned char)to[1] == 0xfe);
63   VERIFY(to[2] == 0x41);
64   VERIFY(to[3] == 0x00);
65   VERIFY(to[4] == 0x42);
66   VERIFY(to[5] == 0x00);
67   VERIFY(to[6] == 0x43);
68   VERIFY(to[7] == 0x00);
69 }
70 
71 int
main()72 main()
73 {
74   test01();
75   test02();
76 }
77