1 // { dg-require-namedlocale "" }
3 // 2000-09-13 Benjamin Kosnik <bkoz@redhat.com>
5 // Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
7 // Free Software Foundation
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 // 22.1.1.2 locale constructors and destructors [lib.locale.cons]
26 #include <cwchar> // for mbstate_t
30 #include <testsuite_hooks.h>
32 typedef std::codecvt
<char, char, std::mbstate_t> c_codecvt
;
34 #ifdef _GLIBCXX_USE_WCHAR_T
35 typedef std::codecvt
<wchar_t, char, std::mbstate_t> w_codecvt
;
38 class gnu_codecvt
: public c_codecvt
{ };
40 class gnu_facet
: public std::locale::facet
43 static std::locale::id id
;
46 std::locale::id
gnu_facet::id
;
51 bool test
__attribute__((unused
)) = true;
53 // construct a locale object with the C facet
54 const locale loc01
= locale::classic();
57 // template <class Facet> locale(const locale& other, Facet* f)
58 // construct a locale object with the specialized facet.
59 locale
loc02(locale::classic(), new gnu_codecvt
);
60 VERIFY( loc01
!= loc02
);
61 VERIFY( loc02
.name() == "*" );
64 VERIFY( has_facet
<gnu_codecvt
>(loc02
) );
65 VERIFY( has_facet
<c_codecvt
>(loc02
) );
66 #ifdef _GLIBCXX_USE_WCHAR_T
67 VERIFY( has_facet
<w_codecvt
>(loc02
) );
74 { use_facet
<gnu_facet
>(loc02
); }
83 VERIFY( loc03
== loc01
);
84 VERIFY( loc03
.name() == "C" );
85 locale loc04
= locale::global(loc02
);
87 VERIFY( loc05
!= loc03
);
88 VERIFY( loc05
== loc02
);
91 // explicit locale(const char* std_name)
92 locale loc06
= locale("fr_FR");
93 VERIFY( loc06
!= loc01
);
94 VERIFY( loc06
!= loc02
);
95 VERIFY( loc06
.name() == "fr_FR");
97 VERIFY( loc07
!= loc02
);
98 VERIFY( loc07
.name() != "" );
100 { locale
loc08(static_cast<const char*>(0)); }
101 catch(runtime_error
& obj
)
107 { locale
loc08("saturn_SUN*RA"); }
108 catch(runtime_error
& obj
)
114 // locale(const locale& other, const char* std_name, category)
116 // This is the same as 5 only use "C" for loc("C")
117 locale
loc09(loc06
, "C", locale::ctype
);
118 VERIFY( loc09
.name() != "fr_FR" );
119 VERIFY( loc09
.name() != "C" );
120 VERIFY( loc09
.name() != "*" );
121 VERIFY( loc09
!= loc01
);
122 VERIFY( loc09
!= loc06
);
124 locale
loc10(loc02
, "C", locale::ctype
);
125 VERIFY( loc10
.name() == "*" );
126 VERIFY( loc10
!= loc01
); // As not named, even tho facets same...
127 VERIFY( loc10
!= loc02
);
129 locale
loc11(loc01
, "C", locale::ctype
);
130 VERIFY( loc11
.name() == "C" );
131 VERIFY( loc11
== loc01
);
134 { locale
loc12(loc01
, static_cast<const char*>(0), locale::ctype
); }
135 catch(runtime_error
& obj
)
141 { locale
loc13(loc01
, "localized by the wu-tang clan", locale::ctype
); }
142 catch(runtime_error
& obj
)
147 locale
loc14(loc06
, "C", locale::none
);
148 VERIFY( loc14
.name() == "fr_FR" );
149 VERIFY( loc14
== loc06
);
151 locale
loc15(loc06
, "C", locale::collate
);
152 VERIFY( loc15
.name() != "fr_FR" );
153 VERIFY( loc15
.name() != "C" );
154 VERIFY( loc15
.name() != "*" );
155 VERIFY( loc15
.name() != loc09
.name() );
156 VERIFY( loc15
!= loc01
);
157 VERIFY( loc15
!= loc06
);
158 VERIFY( loc15
!= loc09
);
162 // locale(const locale& other, const locale& one, category)
164 // This is the exact same as 4, with locale("C") for "C"
165 locale
loc09(loc06
, loc01
, locale::ctype
);
166 VERIFY( loc09
.name() != "fr_FR" );
167 VERIFY( loc09
.name() != "C" );
168 VERIFY( loc09
.name() != "*" );
169 VERIFY( loc09
!= loc01
);
170 VERIFY( loc09
!= loc06
);
172 locale
loc10(loc02
, loc01
, locale::ctype
);
173 VERIFY( loc10
.name() == "*" );
174 VERIFY( loc10
!= loc01
); // As not named, even tho facets same...
175 VERIFY( loc10
!= loc02
);
177 locale
loc11(loc01
, loc01
, locale::ctype
);
178 VERIFY( loc11
.name() == "C" );
179 VERIFY( loc11
== loc01
);
182 { locale
loc12(loc01
, static_cast<const char*>(0), locale::ctype
); }
183 catch(runtime_error
& obj
)
189 { locale
loc13(loc01
, locale("wu-tang clan"), locale::ctype
); }
190 catch(runtime_error
& obj
)
195 locale
loc14(loc06
, loc01
, locale::none
);
196 VERIFY( loc14
.name() == "fr_FR" );
197 VERIFY( loc14
== loc06
);
199 locale
loc15(loc06
, loc01
, locale::collate
);
200 VERIFY( loc15
.name() != "fr_FR" );
201 VERIFY( loc15
.name() != "C" );
202 VERIFY( loc15
.name() != "*" );
203 VERIFY( loc15
.name() != loc09
.name() );
204 VERIFY( loc15
!= loc01
);
205 VERIFY( loc15
!= loc06
);
206 VERIFY( loc15
!= loc09
);