]> gcc.gnu.org Git - gcc.git/blob - libstdc++-v3/testsuite/22_locale/codecvt/char32_t-char8_t.cc
Update copyright years.
[gcc.git] / libstdc++-v3 / testsuite / 22_locale / codecvt / char32_t-char8_t.cc
1 // { dg-do run { target c++11 } }
2 // { dg-require-cstdint "" }
3 // { dg-options "-fchar8_t" }
4
5 // 2014-04-24 RĂ¼diger Sonderfeld
6
7 // Copyright (C) 2015-2020 Free Software Foundation, Inc.
8 //
9 // This file is part of the GNU ISO C++ Library. This library is free
10 // software; you can redistribute it and/or modify it under the
11 // terms of the GNU General Public License as published by the
12 // Free Software Foundation; either version 3, or (at your option)
13 // any later version.
14
15 // This library is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
19
20 // You should have received a copy of the GNU General Public License along
21 // with this library; see the file COPYING3. If not see
22 // <http://www.gnu.org/licenses/>.
23
24 // [locale.codecvt], C++11 22.4.1.4. specialization.
25
26 #include <locale>
27 #include <cstring>
28 #include <testsuite_hooks.h>
29
30 void
31 test01()
32 {
33 using namespace std;
34 typedef codecvt<char32_t, char8_t, mbstate_t> codecvt_c32;
35 locale loc_c = locale::classic();
36 VERIFY(has_facet<codecvt_c32>(loc_c));
37 const codecvt_c32* const cvt = &use_facet<codecvt_c32>(loc_c);
38
39 VERIFY(!cvt->always_noconv());
40 VERIFY(cvt->max_length() == 4);
41 VERIFY(cvt->encoding() == 0);
42
43 const char8_t u8dat[] = u8"H\U000000E4ll\U000000F6 \U0001F63F \U000056FD "
44 u8"\U0000222B f(\U000003BA) exp(-2\U000003C0\U000003C9) d\U000003BA "
45 u8"\U0001F6BF \U0001F6BF \U0001F648 \U00000413\U00000435\U0000043E"
46 u8"\U00000433\U00000440\U00000430\U00000444\U00000438\U0000044F \U0000FB05";
47 const char8_t* const u8dat_end = std::end(u8dat);
48
49 const char32_t u32dat[] = U"H\U000000E4ll\U000000F6 \U0001F63F \U000056FD "
50 U"\U0000222B f(\U000003BA) exp(-2\U000003C0\U000003C9) d\U000003BA "
51 U"\U0001F6BF \U0001F6BF \U0001F648 \U00000413\U00000435\U0000043E"
52 U"\U00000433\U00000440\U00000430\U00000444\U00000438\U0000044F \U0000FB05";
53 const char32_t* const u32dat_end = std::end(u32dat);
54
55 {
56 const size_t len = u32dat_end - u32dat + 1;
57 char32_t* const buffer = new char32_t[len];
58 char32_t* const buffer_end = buffer + len;
59
60 const char8_t* from_next;
61 char32_t* to_next;
62
63 codecvt_c32::state_type state01;
64 state01 = {};
65 codecvt_base::result res = cvt->in(state01, u8dat, u8dat_end, from_next,
66 buffer, buffer_end, to_next);
67
68 VERIFY(res == codecvt_base::ok);
69 VERIFY(from_next == u8dat_end);
70 VERIFY(std::memcmp((void*)buffer, (void*)u32dat, sizeof(u32dat)) == 0);
71
72 delete[] buffer;
73 }
74
75 {
76 const size_t len = u8dat_end - u8dat + 1;
77 char8_t* const buffer = new char8_t[len];
78 char8_t* const buffer_end = buffer + len;
79
80 const char32_t* from_next;
81 char8_t* to_next;
82
83 codecvt_c32::state_type state01;
84 state01 = {};
85 codecvt_base::result res = cvt->out(state01, u32dat, u32dat_end, from_next,
86 buffer, buffer_end, to_next);
87
88 VERIFY(res == codecvt_base::ok);
89 VERIFY(from_next == u32dat_end);
90 VERIFY(std::memcmp((void*)buffer, (void*)u8dat, sizeof(u8dat)) == 0);
91
92 delete[] buffer;
93 }
94 }
95
96 int
97 main()
98 {
99 test01();
100 }
This page took 0.050969 seconds and 5 git commands to generate.