1 // { dg-require-namedlocale "" }
3 // 2000-09-13 Benjamin Kosnik <bkoz@redhat.com>
5 // Copyright (C) 2000, 2001, 2002, 2003, 2005 Free Software Foundation
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 2, 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 COPYING. If not, write to the Free
20 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
23 // 22.1.1.2 locale constructors and destructors [lib.locale.cons]
25 #include <cwchar> // for mbstate_t
28 #include <testsuite_hooks.h>
30 #if _GLIBCXX_USE___ENC_TRAITS
31 typedef std::codecvt
<char, char, std::mbstate_t> c_codecvt
;
32 typedef std::codecvt_byname
<char, char, std::mbstate_t> c_codecvt_byname
;
33 typedef std::codecvt
<wchar_t, char, std::mbstate_t> w_codecvt
;
34 typedef std::codecvt_byname
<wchar_t, char, std::mbstate_t> w_codecvt_byname
;
36 class gnu_codecvt
: public c_codecvt
{ };
38 class gnu_facet
: public std::locale::facet
41 static std::locale::id id
;
44 std::locale::id
gnu_facet::id
;
46 // Need some char_traits specializations for this to work.
47 typedef unsigned short unicode_t
;
52 struct char_traits
<unicode_t
>
54 typedef unicode_t char_type
;
55 // Unsigned as wint_t is unsigned.
56 typedef unsigned long int_type
;
57 typedef streampos pos_type
;
58 typedef streamoff off_type
;
59 typedef mbstate_t state_type
;
62 assign(char_type
& __c1
, const char_type
& __c2
);
65 eq(const char_type
& __c1
, const char_type
& __c2
);
68 lt(const char_type
& __c1
, const char_type
& __c2
);
71 compare(const char_type
* __s1
, const char_type
* __s2
, size_t __n
)
72 { return memcmp(__s1
, __s2
, __n
); }
75 length(const char_type
* __s
);
77 static const char_type
*
78 find(const char_type
* __s
, size_t __n
, const char_type
& __a
);
81 move(char_type
* __s1
, const char_type
* __s2
, size_t __n
);
84 copy(char_type
* __s1
, const char_type
* __s2
, size_t __n
)
85 { return static_cast<char_type
*>(memcpy(__s1
, __s2
, __n
)); }
88 assign(char_type
* __s
, size_t __n
, char_type __a
);
91 to_char_type(const int_type
& __c
);
94 to_int_type(const char_type
& __c
);
97 eq_int_type(const int_type
& __c1
, const int_type
& __c2
);
103 not_eof(const int_type
& __c
);
110 typedef unicode_t int_type
;
111 typedef char ext_type
;
112 typedef __enc_traits enc_type
;
113 typedef codecvt
<int_type
, ext_type
, enc_type
> unicode_codecvt
;
115 bool test
__attribute__((unused
)) = true;
118 // construct a locale object with the C facet
119 const locale loc01
= locale::classic();
122 // template <class Facet> locale(const locale& other, Facet* f)
123 // construct a locale object with the specialized facet.
124 locale
loc02(locale::classic(), new gnu_codecvt
);
125 VERIFY (loc01
!= loc02
);
126 VERIFY (loc02
.name() == "*");
129 VERIFY (has_facet
<gnu_codecvt
>(loc02
));
130 VERIFY (has_facet
<c_codecvt
>(loc02
));
131 VERIFY (has_facet
<w_codecvt
>(loc02
));
137 { use_facet
<gnu_facet
>(loc02
); }
144 locale
loc13(locale::classic(), new unicode_codecvt
);
145 VERIFY (loc01
!= loc13
);
146 VERIFY (loc13
.name() == "*");
149 VERIFY (has_facet
<c_codecvt
>(loc13
));
150 VERIFY (has_facet
<w_codecvt
>(loc13
));
151 VERIFY (has_facet
<unicode_codecvt
>(loc13
));
157 { use_facet
<gnu_facet
>(loc13
); }
166 VERIFY (loc03
== loc01
);
167 VERIFY (loc03
.name() == "C");
168 locale loc04
= locale::global(loc02
);
170 VERIFY (loc05
!= loc03
);
171 VERIFY (loc05
== loc02
);
174 // explicit locale(const char* std_name)
175 locale loc06
= locale("fr_FR");
176 VERIFY (loc06
!= loc01
);
177 VERIFY (loc06
!= loc02
);
178 VERIFY (loc06
.name() == "fr_FR");
180 VERIFY (loc07
!= loc02
);
181 VERIFY (loc07
.name() != "");
183 { locale
loc08(static_cast<const char*>(NULL
)); }
184 catch(runtime_error
& obj
)
190 { locale
loc08("saturn_SUN*RA"); }
191 catch(runtime_error
& obj
)
197 // locale(const locale& other, const char* std_name, category)
199 // This is the same as 5 only use "C" for loc("C")
200 locale
loc09(loc06
, "C", locale::ctype
);
201 VERIFY (loc09
.name() != "fr_FR");
202 VERIFY (loc09
.name() != "C");
203 VERIFY (loc09
.name() != "*");
204 VERIFY (loc09
!= loc01
);
205 VERIFY (loc09
!= loc06
);
207 locale
loc10(loc02
, "C", locale::ctype
);
208 VERIFY (loc10
.name() == "*");
209 VERIFY (loc10
!= loc01
); // As not named, even tho facets same...
210 VERIFY (loc10
!= loc02
);
212 locale
loc11(loc01
, "C", locale::ctype
);
213 VERIFY (loc11
.name() == "C");
214 VERIFY (loc11
== loc01
);
217 { locale
loc12(loc01
, static_cast<const char*>(NULL
), locale::ctype
); }
218 catch(runtime_error
& obj
)
224 { locale
loc13(loc01
, "localized by the wu-tang clan", locale::ctype
); }
225 catch(runtime_error
& obj
)
230 locale
loc14(loc06
, "C", locale::none
);
231 VERIFY (loc14
.name() == "fr_FR");
232 VERIFY (loc14
== loc06
);
234 locale
loc15(loc06
, "C", locale::collate
);
235 VERIFY (loc15
.name() != "fr_FR");
236 VERIFY (loc15
.name() != "C");
237 VERIFY (loc15
.name() != "*");
238 VERIFY (loc15
.name() != loc09
.name());
239 VERIFY (loc15
!= loc01
);
240 VERIFY (loc15
!= loc06
);
241 VERIFY (loc15
!= loc09
);
245 // locale(const locale& other, const locale& one, category)
247 // This is the exact same as 4, with locale("C") for "C"
248 locale
loc09(loc06
, loc01
, locale::ctype
);
249 VERIFY (loc09
.name() != "fr_FR");
250 VERIFY (loc09
.name() != "C");
251 VERIFY (loc09
.name() != "*");
252 VERIFY (loc09
!= loc01
);
253 VERIFY (loc09
!= loc06
);
255 locale
loc10(loc02
, loc01
, locale::ctype
);
256 VERIFY (loc10
.name() == "*");
257 VERIFY (loc10
!= loc01
); // As not named, even tho facets same...
258 VERIFY (loc10
!= loc02
);
260 locale
loc11(loc01
, loc01
, locale::ctype
);
261 VERIFY (loc11
.name() == "C");
262 VERIFY (loc11
== loc01
);
265 { locale
loc12(loc01
, static_cast<const char*>(NULL
), locale::ctype
); }
266 catch(runtime_error
& obj
)
272 { locale
loc13(loc01
, locale("wu-tang clan"), locale::ctype
); }
273 catch(runtime_error
& obj
)
278 locale
loc14(loc06
, loc01
, locale::none
);
279 VERIFY (loc14
.name() == "fr_FR");
280 VERIFY (loc14
== loc06
);
282 locale
loc15(loc06
, loc01
, locale::collate
);
283 VERIFY (loc15
.name() != "fr_FR");
284 VERIFY (loc15
.name() != "C");
285 VERIFY (loc15
.name() != "*");
286 VERIFY (loc15
.name() != loc09
.name());
287 VERIFY (loc15
!= loc01
);
288 VERIFY (loc15
!= loc06
);
289 VERIFY (loc15
!= loc09
);
292 #endif // _GLIBCXX_USE___ENC_TRAITS
296 #if _GLIBCXX_USE___ENC_TRAITS