]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/22_locale/codecvt/codecvt_utf16/80041.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 22_locale / codecvt / codecvt_utf16 / 80041.cc
CommitLineData
8d9254fc 1// Copyright (C) 2017-2020 Free Software Foundation, Inc.
a4c687d6
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
18// { dg-do run { target c++11 } }
19
20#include <codecvt>
21#include <testsuite_hooks.h>
22
23void
24test01()
25{
26#ifdef _GLIBCXX_USE_WCHAR_T
27 std::codecvt_utf16<wchar_t> conv;
28 const wchar_t wc = 0x6557;
29 char bytes[2] = {0};
30 const wchar_t* wcnext;
31 std::mbstate_t st{};
32 char* next = nullptr;
33 auto res = conv.out(st, &wc, &wc+ 1, wcnext, bytes, std::end(bytes), next);
34 VERIFY( res == std::codecvt_base::ok );
35 VERIFY( wcnext == &wc + 1 );
36 VERIFY( next == std::end(bytes) );
37 VERIFY( bytes[0] == 0x65 );
38 VERIFY( bytes[1] == 0x57 );
39 VERIFY( conv.length(st, bytes, next, 1) == (next - bytes) );
40
41 wchar_t w;
42 wchar_t* wnext;
43 const char* cnext;
44 st = {};
45 res = conv.in(st, bytes, next, cnext, &w, &w + 1, wnext);
46 VERIFY( res == std::codecvt_base::ok );
47 VERIFY( wnext == &w + 1 );
48 VERIFY( cnext == next );
49 VERIFY( w == wc );
50#endif
51}
52
53void
54test02()
55{
56#ifdef _GLIBCXX_USE_WCHAR_T
57 std::codecvt_utf16<wchar_t, 0x10FFFF, std::little_endian> conv;
58 wchar_t wc = 0x6557;
59 char bytes[2] = {0};
60 const wchar_t* wcnext;
61 std::mbstate_t st{};
62 char* next = nullptr;
63 auto res = conv.out(st, &wc, &wc+ 1, wcnext, bytes, std::end(bytes), next);
64 VERIFY( res == std::codecvt_base::ok );
65 VERIFY( wcnext == &wc + 1 );
66 VERIFY( next == std::end(bytes) );
67 VERIFY( bytes[0] == 0x57 );
68 VERIFY( bytes[1] == 0x65 );
69 VERIFY( conv.length(st, bytes, next, 1) == (next - bytes) );
70
71 wchar_t w;
72 wchar_t* wnext;
73 const char* cnext;
74 st = {};
75 res = conv.in(st, bytes, next, cnext, &w, &w + 1, wnext);
76 VERIFY( res == std::codecvt_base::ok );
77 VERIFY( wnext == &w + 1 );
78 VERIFY( cnext == next );
79 VERIFY( w == wc );
80#endif
81}
82
83int main()
84{
85 test01();
86 test02();
87}