]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/22_locale/ctor_copy_dtor.cc
1 // 2000-09-13 Benjamin Kosnik <bkoz@redhat.com>
3 // Copyright (C) 2000, 2001 Free Software Foundation
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 2, or (at your option)
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING. If not, write to the Free
18 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
21 // 22.1.1.2 locale constructors and destructors [lib.locale.cons]
23 #include <cwchar> // for mbstate_t
26 #include <debug_assert.h>
28 #if _GLIBCPP_USE_WCHAR_T
29 typedef std::codecvt
<char, char, std::mbstate_t> c_codecvt
;
30 typedef std::codecvt_byname
<char, char, std::mbstate_t> c_codecvt_byname
;
31 typedef std::codecvt
<wchar_t, char, std::mbstate_t> w_codecvt
;
32 typedef std::codecvt_byname
<wchar_t, char, std::mbstate_t> w_codecvt_byname
;
34 class gnu_codecvt
: public c_codecvt
{ };
36 class gnu_facet
: public std::locale::facet
39 static std::locale::id id
;
42 std::locale::id
gnu_facet::id
;
48 typedef unsigned short unicode_t
;
49 typedef unicode_t int_type
;
50 typedef char ext_type
;
51 typedef __enc_traits enc_type
;
52 typedef codecvt
<int_type
, ext_type
, enc_type
> unicode_codecvt
;
57 // construct a locale object with the C facet
58 const locale
& loc01
= locale::classic();
61 // template <class Facet> locale(const locale& other, Facet* f)
62 // construct a locale object with the specialized facet.
63 locale
loc02(locale::classic(), new gnu_codecvt
);
64 VERIFY (loc01
!= loc02
);
65 VERIFY (loc02
.name() == "*");
68 VERIFY (has_facet
<gnu_codecvt
>(loc02
));
69 VERIFY (has_facet
<c_codecvt
>(loc02
));
70 VERIFY (has_facet
<w_codecvt
>(loc02
));
76 { use_facet
<gnu_facet
>(loc02
); }
83 locale
loc13(locale::classic(), new unicode_codecvt
);
84 VERIFY (loc01
!= loc13
);
85 VERIFY (loc13
.name() == "*");
88 VERIFY (has_facet
<c_codecvt
>(loc13
));
89 VERIFY (has_facet
<w_codecvt
>(loc13
));
90 VERIFY (has_facet
<unicode_codecvt
>(loc13
));
96 { use_facet
<gnu_facet
>(loc13
); }
105 VERIFY (loc03
== loc01
);
106 VERIFY (loc03
.name() == "C");
107 locale loc04
= locale::global(loc02
);
109 VERIFY (loc05
!= loc03
);
110 VERIFY (loc05
== loc02
);
113 // explicit locale(const char* std_name)
114 locale
loc06("fr_FR");
115 VERIFY (loc06
!= loc01
);
116 VERIFY (loc06
!= loc02
);
117 VERIFY (loc06
.name() == "fr_FR");
119 VERIFY (loc07
!= loc01
);
120 VERIFY (loc07
!= loc02
);
121 VERIFY (loc07
.name() == "");
123 { locale
loc08(static_cast<const char*>(NULL
)); }
124 catch(runtime_error
& obj
)
130 // locale(const locale& other, const char* std_name, category)
132 // This is the same as 5 only use "C" for loc("C")
133 locale
loc09(loc06
, "C", locale::ctype
);
134 VERIFY (loc09
.name() != "fr_FR");
135 VERIFY (loc09
.name() != "C");
136 VERIFY (loc09
.name() != "*");
137 VERIFY (loc09
!= loc01
);
138 VERIFY (loc09
!= loc06
);
140 locale
loc10(loc02
, "C", locale::ctype
);
141 VERIFY (loc10
.name() == "*");
142 VERIFY (loc10
!= loc01
); // As not named, even tho facets same...
143 VERIFY (loc10
!= loc02
);
145 locale
loc11(loc01
, "C", locale::ctype
);
146 VERIFY (loc11
.name() == "C");
147 VERIFY (loc11
== loc01
);
150 { locale
loc12(loc01
, static_cast<const char*>(NULL
), locale::ctype
); }
151 catch(runtime_error
& obj
)
157 { locale
loc13(loc01
, "localized by the wu-tang clan", locale::ctype
); }
158 catch(runtime_error
& obj
)
163 locale
loc14(loc06
, "C", locale::none
);
164 VERIFY (loc14
.name() == "fr_FR");
165 VERIFY (loc14
== loc06
);
167 locale
loc15(loc06
, "C", locale::collate
);
168 VERIFY (loc15
.name() != "fr_FR");
169 VERIFY (loc15
.name() != "C");
170 VERIFY (loc15
.name() != "*");
171 VERIFY (loc15
.name() != loc09
.name());
172 VERIFY (loc15
!= loc01
);
173 VERIFY (loc15
!= loc06
);
174 VERIFY (loc15
!= loc09
);
178 // locale(const locale& other, const locale& one, category)
180 // This is the exact same as 4, with locale("C") for "C"
181 locale
loc09(loc06
, loc01
, locale::ctype
);
182 VERIFY (loc09
.name() != "fr_FR");
183 VERIFY (loc09
.name() != "C");
184 VERIFY (loc09
.name() != "*");
185 VERIFY (loc09
!= loc01
);
186 VERIFY (loc09
!= loc06
);
188 locale
loc10(loc02
, loc01
, locale::ctype
);
189 VERIFY (loc10
.name() == "*");
190 VERIFY (loc10
!= loc01
); // As not named, even tho facets same...
191 VERIFY (loc10
!= loc02
);
193 locale
loc11(loc01
, loc01
, locale::ctype
);
194 VERIFY (loc11
.name() == "C");
195 VERIFY (loc11
== loc01
);
198 { locale
loc12(loc01
, static_cast<const char*>(NULL
), locale::ctype
); }
199 catch(runtime_error
& obj
)
205 { locale
loc13(loc01
, locale("wu-tang clan"), locale::ctype
); }
206 catch(runtime_error
& obj
)
211 locale
loc14(loc06
, loc01
, locale::none
);
212 VERIFY (loc14
.name() == "fr_FR");
213 VERIFY (loc14
== loc06
);
215 locale
loc15(loc06
, loc01
, locale::collate
);
216 VERIFY (loc15
.name() != "fr_FR");
217 VERIFY (loc15
.name() != "C");
218 VERIFY (loc15
.name() != "*");
219 VERIFY (loc15
.name() != loc09
.name());
220 VERIFY (loc15
!= loc01
);
221 VERIFY (loc15
!= loc06
);
222 VERIFY (loc15
!= loc09
);
225 #endif /* !defined(_GLIBCPP_USE_WCHAR_T) */
229 #if _GLIBCPP_USE_WCHAR_T