]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/22_locale/locale/cons/unicode.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 22_locale / locale / cons / unicode.cc
CommitLineData
52066eae 1// { dg-do run { target c++11 } }
684211e1 2// { dg-require-iconv "ISO-8859-1" }
4ffe6e87 3
99dee823 4// Copyright (C) 2006-2021 Free Software Foundation, Inc.
4ffe6e87
BK
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
748086b7 9// Free Software Foundation; either version 3, or (at your option)
4ffe6e87
BK
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
748086b7
JJ
18// with this library; see the file COPYING3. If not see
19// <http://www.gnu.org/licenses/>.
4ffe6e87
BK
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>
3b476281 26#include <typeinfo>
4ffe6e87
BK
27#include <testsuite_hooks.h>
28#include <ext/codecvt_specializations.h>
29
30typedef std::codecvt<char, char, std::mbstate_t> c_codecvt;
31
32#ifdef _GLIBCXX_USE_WCHAR_T
33typedef std::codecvt<wchar_t, char, std::mbstate_t> w_codecvt;
34#endif
35
bb93f35d
JW
36#ifdef _GLIBCXX_USE_C99_STDINT_TR1
37typedef std::codecvt<char16_t, char, std::mbstate_t> u16_codecvt;
38typedef std::codecvt<char32_t, char, std::mbstate_t> u32_codecvt;
59019b42
TH
39#ifdef _GLIBCXX_USE_CHAR8_T
40typedef std::codecvt<char16_t, char8_t, std::mbstate_t> u16u8_codecvt;
41typedef std::codecvt<char32_t, char8_t, std::mbstate_t> u32u8_codecvt;
42#endif
bb93f35d
JW
43#endif
44
4ffe6e87
BK
45class gnu_facet: public std::locale::facet
46{
47public:
48 static std::locale::id id;
49};
50
51std::locale::id gnu_facet::id;
52
53void test01()
54{
55 using namespace std;
56 typedef unsigned short int_type;
57 typedef char ext_type;
58 typedef __gnu_cxx::encoding_state state_type;
59 typedef codecvt<int_type, ext_type, state_type> unicode_codecvt;
60
4ffe6e87
BK
61 // unicode_codecvt
62 locale loc01(locale::classic());
63 locale loc13(locale::classic(), new unicode_codecvt);
64 VERIFY( loc01 != loc13 );
65 VERIFY( loc13.name() == "*" );
66 try
67 {
68 VERIFY( has_facet<c_codecvt>(loc13) );
69#ifdef _GLIBCXX_USE_WCHAR_T
70 VERIFY( has_facet<w_codecvt>(loc13) );
bb93f35d
JW
71#endif
72#ifdef _GLIBCXX_USE_C99_STDINT_TR1
73 VERIFY( has_facet<u16_codecvt>(loc13) );
74 VERIFY( has_facet<u32_codecvt>(loc13) );
59019b42
TH
75#ifdef _GLIBCXX_USE_CHAR8_T
76 VERIFY( has_facet<u16u8_codecvt>(loc13) );
77 VERIFY( has_facet<u32u8_codecvt>(loc13) );
78#endif
4ffe6e87
BK
79#endif
80 VERIFY( has_facet<unicode_codecvt>(loc13) );
81 }
82 catch(...)
83 { VERIFY( false ); }
84
85 try
86 { use_facet<gnu_facet>(loc13); }
87 catch(bad_cast& obj)
88 { VERIFY( true ); }
89 catch(...)
90 { VERIFY( false ); }
91}
92
93int main()
94{
95 test01();
96 return 0;
97}