1 // { dg-do run { target c++11 } }
3 // 2014-04-24 RĂ¼diger Sonderfeld
5 // Copyright (C) 2015-2025 Free Software Foundation, Inc.
7 // This file is part of the GNU ISO C++ Library. This library is free
8 // software; you can redistribute it and/or modify it under the
9 // terms of the GNU General Public License as published by the
10 // Free Software Foundation; either version 3, or (at your option)
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License along
19 // with this library; see the file COPYING3. If not see
20 // <http://www.gnu.org/licenses/>.
22 // [locale.codecvt], C++11 22.4.1.4. specialization.
26 #include <testsuite_hooks.h>
32 typedef codecvt
<char32_t
, char, mbstate_t> codecvt_c32
;
33 locale loc_c
= locale::classic();
34 VERIFY(has_facet
<codecvt_c32
>(loc_c
));
35 const codecvt_c32
* const cvt
= &use_facet
<codecvt_c32
>(loc_c
);
37 VERIFY(!cvt
->always_noconv());
38 VERIFY(cvt
->max_length() == 4);
39 VERIFY(cvt
->encoding() == 0);
41 #ifndef _GLIBCXX_USE_CHAR8_T
44 const char8_t u8dat_
[] = u8
"H\U000000E4ll\U000000F6 \U0001F63F \U000056FD "
45 u8
"\U0000222B f(\U000003BA) exp(-2\U000003C0\U000003C9) d\U000003BA "
46 u8
"\U0001F6BF \U0001F6BF \U0001F648 \U00000413\U00000435\U0000043E"
47 u8
"\U00000433\U00000440\U00000430\U00000444\U00000438\U0000044F \U0000FB05";
48 const char* const u8dat
= (const char*)u8dat_
;
49 const char* const u8dat_end
= (const char*)std::end(u8dat_
);
51 const char32_t u32dat
[] = U
"H\U000000E4ll\U000000F6 \U0001F63F \U000056FD "
52 U
"\U0000222B f(\U000003BA) exp(-2\U000003C0\U000003C9) d\U000003BA "
53 U
"\U0001F6BF \U0001F6BF \U0001F648 \U00000413\U00000435\U0000043E"
54 U
"\U00000433\U00000440\U00000430\U00000444\U00000438\U0000044F \U0000FB05";
55 const char32_t
* const u32dat_end
= std::end(u32dat
);
58 const size_t len
= u32dat_end
- u32dat
+ 1;
59 char32_t
* const buffer
= new char32_t
[len
];
60 char32_t
* const buffer_end
= buffer
+ len
;
62 const char* from_next
;
65 codecvt_c32::state_type state01
;
67 codecvt_base::result res
= cvt
->in(state01
, u8dat
, u8dat_end
, from_next
,
68 buffer
, buffer_end
, to_next
);
70 VERIFY(res
== codecvt_base::ok
);
71 VERIFY(from_next
== u8dat_end
);
72 VERIFY(std::memcmp((void*)buffer
, (void*)u32dat
, sizeof(u32dat
)) == 0);
78 const size_t len
= u8dat_end
- u8dat
+ 1;
79 char* const buffer
= new char[len
];
80 char* const buffer_end
= buffer
+ len
;
82 const char32_t
* from_next
;
85 codecvt_c32::state_type state01
;
87 codecvt_base::result res
= cvt
->out(state01
, u32dat
, u32dat_end
, from_next
,
88 buffer
, buffer_end
, to_next
);
90 VERIFY(res
== codecvt_base::ok
);
91 VERIFY(from_next
== u32dat_end
);
92 VERIFY(std::memcmp((void*)buffer
, (void*)u8dat_
, sizeof(u8dat_
)) == 0);