]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/22_locale/locale/cons/unicode.cc
Alphabetize my entry in MAINTAINER's DCO list.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 22_locale / locale / cons / unicode.cc
1 // { dg-do run { target c++11 } }
2 // { dg-require-iconv "ISO-8859-1" }
3
4 // Copyright (C) 2006-2024 Free Software Foundation, Inc.
5 //
6 // This file is part of the GNU ISO C++ Library. This library is free
7 // software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the
9 // Free Software Foundation; either version 3, or (at your option)
10 // any later version.
11
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16
17 // You should have received a copy of the GNU General Public License along
18 // with this library; see the file COPYING3. If not see
19 // <http://www.gnu.org/licenses/>.
20
21 // 22.1.1.2 locale constructors and destructors [lib.locale.cons]
22
23 #include <cwchar> // for mbstate_t
24 #include <locale>
25 #include <stdexcept>
26 #include <typeinfo>
27 #include <testsuite_hooks.h>
28 #include <ext/codecvt_specializations.h>
29
30 typedef std::codecvt<char, char, std::mbstate_t> c_codecvt;
31
32 #ifdef _GLIBCXX_USE_WCHAR_T
33 typedef std::codecvt<wchar_t, char, std::mbstate_t> w_codecvt;
34 #endif
35
36 typedef std::codecvt<char16_t, char, std::mbstate_t> u16_codecvt;
37 typedef std::codecvt<char32_t, char, std::mbstate_t> u32_codecvt;
38 #ifdef _GLIBCXX_USE_CHAR8_T
39 typedef std::codecvt<char16_t, char8_t, std::mbstate_t> u16u8_codecvt;
40 typedef std::codecvt<char32_t, char8_t, std::mbstate_t> u32u8_codecvt;
41 #endif
42
43 class gnu_facet: public std::locale::facet
44 {
45 public:
46 static std::locale::id id;
47 };
48
49 std::locale::id gnu_facet::id;
50
51 void test01()
52 {
53 using namespace std;
54 typedef unsigned short int_type;
55 typedef char ext_type;
56 typedef __gnu_cxx::encoding_state state_type;
57 typedef codecvt<int_type, ext_type, state_type> unicode_codecvt;
58
59 // unicode_codecvt
60 locale loc01(locale::classic());
61 locale loc13(locale::classic(), new unicode_codecvt);
62 VERIFY( loc01 != loc13 );
63 VERIFY( loc13.name() == "*" );
64 try
65 {
66 VERIFY( has_facet<c_codecvt>(loc13) );
67 #ifdef _GLIBCXX_USE_WCHAR_T
68 VERIFY( has_facet<w_codecvt>(loc13) );
69 #endif
70 VERIFY( has_facet<u16_codecvt>(loc13) );
71 VERIFY( has_facet<u32_codecvt>(loc13) );
72 #ifdef _GLIBCXX_USE_CHAR8_T
73 VERIFY( has_facet<u16u8_codecvt>(loc13) );
74 VERIFY( has_facet<u32u8_codecvt>(loc13) );
75 #endif
76 VERIFY( has_facet<unicode_codecvt>(loc13) );
77 }
78 catch(...)
79 { VERIFY( false ); }
80
81 try
82 { (void) use_facet<gnu_facet>(loc13); }
83 catch(bad_cast& obj)
84 { VERIFY( true ); }
85 catch(...)
86 { VERIFY( false ); }
87 }
88
89 int main()
90 {
91 test01();
92 return 0;
93 }