1 // { dg-require-namedlocale "" }
3 // 2000-09-13 Benjamin Kosnik <bkoz@redhat.com>
5 // Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009
6 // Free Software Foundation
8 // This file is part of the GNU ISO C++ Library. This library is free
9 // software; you can redistribute it and/or modify it under the
10 // terms of the GNU General Public License as published by the
11 // Free Software Foundation; either version 3, or (at your option)
14 // This library is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 // GNU General Public License for more details.
19 // You should have received a copy of the GNU General Public License along
20 // with this library; see the file COPYING3. If not see
21 // <http://www.gnu.org/licenses/>.
23 // 22.1.1.2 locale constructors and destructors [lib.locale.cons]
25 #include <cwchar> // for mbstate_t
29 #include <testsuite_hooks.h>
31 typedef std::codecvt<char, char, std::mbstate_t> c_codecvt;
33 #ifdef _GLIBCXX_USE_WCHAR_T
34 typedef std::codecvt<wchar_t, char, std::mbstate_t> w_codecvt;
37 class gnu_codecvt: public c_codecvt { };
39 class gnu_facet: public std::locale::facet
42 static std::locale::id id;
45 std::locale::id gnu_facet::id;
50 bool test __attribute__((unused)) = true;
52 // construct a locale object with the C facet
53 const locale loc01 = locale::classic();
56 // template <class Facet> locale(const locale& other, Facet* f)
57 // construct a locale object with the specialized facet.
58 locale loc02(locale::classic(), new gnu_codecvt);
59 VERIFY( loc01 != loc02 );
60 VERIFY( loc02.name() == "*" );
63 VERIFY( has_facet<gnu_codecvt>(loc02) );
64 VERIFY( has_facet<c_codecvt>(loc02) );
65 #ifdef _GLIBCXX_USE_WCHAR_T
66 VERIFY( has_facet<w_codecvt>(loc02) );
73 { use_facet<gnu_facet>(loc02); }
82 VERIFY( loc03 == loc01 );
83 VERIFY( loc03.name() == "C" );
84 locale loc04 = locale::global(loc02);
86 VERIFY( loc05 != loc03 );
87 VERIFY( loc05 == loc02 );
90 // explicit locale(const char* std_name)
91 locale loc06 = locale("fr_FR");
92 VERIFY( loc06 != loc01 );
93 VERIFY( loc06 != loc02 );
94 VERIFY( loc06.name() == "fr_FR");
96 VERIFY( loc07 != loc02 );
97 VERIFY( loc07.name() != "" );
99 { locale loc08(static_cast<const char*>(NULL)); }
100 catch(runtime_error& obj)
106 { locale loc08("saturn_SUN*RA"); }
107 catch(runtime_error& obj)
113 // locale(const locale& other, const char* std_name, category)
115 // This is the same as 5 only use "C" for loc("C")
116 locale loc09(loc06, "C", locale::ctype);
117 VERIFY( loc09.name() != "fr_FR" );
118 VERIFY( loc09.name() != "C" );
119 VERIFY( loc09.name() != "*" );
120 VERIFY( loc09 != loc01 );
121 VERIFY( loc09 != loc06 );
123 locale loc10(loc02, "C", locale::ctype);
124 VERIFY( loc10.name() == "*" );
125 VERIFY( loc10 != loc01 ); // As not named, even tho facets same...
126 VERIFY( loc10 != loc02 );
128 locale loc11(loc01, "C", locale::ctype);
129 VERIFY( loc11.name() == "C" );
130 VERIFY( loc11 == loc01 );
133 { locale loc12(loc01, static_cast<const char*>(NULL), locale::ctype); }
134 catch(runtime_error& obj)
140 { locale loc13(loc01, "localized by the wu-tang clan", locale::ctype); }
141 catch(runtime_error& obj)
146 locale loc14(loc06, "C", locale::none);
147 VERIFY( loc14.name() == "fr_FR" );
148 VERIFY( loc14 == loc06 );
150 locale loc15(loc06, "C", locale::collate );
151 VERIFY( loc15.name() != "fr_FR" );
152 VERIFY( loc15.name() != "C" );
153 VERIFY( loc15.name() != "*" );
154 VERIFY( loc15.name() != loc09.name() );
155 VERIFY( loc15 != loc01 );
156 VERIFY( loc15 != loc06 );
157 VERIFY( loc15 != loc09 );
161 // locale(const locale& other, const locale& one, category)
163 // This is the exact same as 4, with locale("C") for "C"
164 locale loc09(loc06, loc01, locale::ctype);
165 VERIFY( loc09.name() != "fr_FR" );
166 VERIFY( loc09.name() != "C" );
167 VERIFY( loc09.name() != "*" );
168 VERIFY( loc09 != loc01 );
169 VERIFY( loc09 != loc06 );
171 locale loc10(loc02, loc01, locale::ctype);
172 VERIFY( loc10.name() == "*" );
173 VERIFY( loc10 != loc01 ); // As not named, even tho facets same...
174 VERIFY( loc10 != loc02 );
176 locale loc11(loc01, loc01, locale::ctype);
177 VERIFY( loc11.name() == "C" );
178 VERIFY( loc11 == loc01 );
181 { locale loc12(loc01, static_cast<const char*>(NULL), locale::ctype); }
182 catch(runtime_error& obj)
188 { locale loc13(loc01, locale("wu-tang clan"), locale::ctype); }
189 catch(runtime_error& obj)
194 locale loc14(loc06, loc01, locale::none);
195 VERIFY( loc14.name() == "fr_FR" );
196 VERIFY( loc14 == loc06 );
198 locale loc15(loc06, loc01, locale::collate);
199 VERIFY( loc15.name() != "fr_FR" );
200 VERIFY( loc15.name() != "C" );
201 VERIFY( loc15.name() != "*" );
202 VERIFY( loc15.name() != loc09.name() );
203 VERIFY( loc15 != loc01 );
204 VERIFY( loc15 != loc06 );
205 VERIFY( loc15 != loc09 );