1 // { dg-do run { target c++11 } }
2 // { dg-require-cstdint "" }
3 // { dg-options "-fchar8_t" }
5 // 2014-04-24 RĂ¼diger Sonderfeld
7 // Copyright (C) 2015-2025 Free Software Foundation, Inc.
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)
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.
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/>.
24 // [locale.codecvt], C++11 22.4.1.4. specialization.
28 #include <testsuite_hooks.h>
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
);
39 VERIFY(!cvt
->always_noconv());
40 VERIFY(cvt
->max_length() == 4);
41 VERIFY(cvt
->encoding() == 0);
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
);
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
);
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
;
60 const char8_t
* from_next
;
63 codecvt_c32::state_type state01
;
65 codecvt_base::result res
= cvt
->in(state01
, u8dat
, u8dat_end
, from_next
,
66 buffer
, buffer_end
, to_next
);
68 VERIFY(res
== codecvt_base::ok
);
69 VERIFY(from_next
== u8dat_end
);
70 VERIFY(std::memcmp((void*)buffer
, (void*)u32dat
, sizeof(u32dat
)) == 0);
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
;
80 const char32_t
* from_next
;
83 codecvt_c32::state_type state01
;
85 codecvt_base::result res
= cvt
->out(state01
, u32dat
, u32dat_end
, from_next
,
86 buffer
, buffer_end
, to_next
);
88 VERIFY(res
== codecvt_base::ok
);
89 VERIFY(from_next
== u32dat_end
);
90 VERIFY(std::memcmp((void*)buffer
, (void*)u8dat
, sizeof(u8dat
)) == 0);