1 // Copyright (C) 2016-2020 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 void
test01()24 test01()
25 {
26   const char out[] = "abc";
27   char16_t in[4];
28   std::codecvt_utf8<char16_t> cvt;
29   std::mbstate_t st;
30   const char* no;
31   char16_t* ni;
32   auto res = cvt.in(st, out, out+3, no, in, in+3, ni);
33   VERIFY( res == std::codecvt_base::ok );
34   VERIFY( in[0] == u'a' );
35   VERIFY( in[1] == u'b' );
36   VERIFY( in[2] == u'c' );
37 }
38 
39 void
test02()40 test02()
41 {
42   const char out[] = "abc";
43   char16_t in[4];
44   std::codecvt_utf8<char16_t, 0x10ffff, std::little_endian> cvt;
45   std::mbstate_t st;
46   const char* no;
47   char16_t* ni;
48   auto res = cvt.in(st, out, out+3, no, in, in+3, ni);
49   VERIFY( res == std::codecvt_base::ok );
50   VERIFY( in[0] == u'a' );
51   VERIFY( in[1] == u'b' );
52   VERIFY( in[2] == u'c' );
53 }
54 
55 void
test03()56 test03()
57 {
58   const char out[] = "abc";
59   char32_t in[4];
60   std::codecvt_utf8<char32_t> cvt;
61   std::mbstate_t st;
62   const char* no;
63   char32_t* ni;
64   auto res = cvt.in(st, out, out+3, no, in, in+3, ni);
65   VERIFY( res == std::codecvt_base::ok );
66   VERIFY( in[0] == U'a' );
67   VERIFY( in[1] == U'b' );
68   VERIFY( in[2] == U'c' );
69 }
70 
71 void
test04()72 test04()
73 {
74   const char out[] = "abc";
75   char32_t in[4];
76   std::codecvt_utf8<char32_t, 0x10ffff, std::little_endian> cvt;
77   std::mbstate_t st;
78   const char* no;
79   char32_t* ni;
80   auto res = cvt.in(st, out, out+3, no, in, in+3, ni);
81   VERIFY( res == std::codecvt_base::ok );
82   VERIFY( in[0] == U'a' );
83   VERIFY( in[1] == U'b' );
84   VERIFY( in[2] == U'c' );
85 }
86 
87 int
main()88 main()
89 {
90   test01();
91   test02();
92   test03();
93   test04();
94 }
95