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