]>
Commit | Line | Data |
---|---|---|
0479a462 BK |
1 | // 2000-08-31 Benjamin Kosnik <bkoz@redhat.com> |
2 | ||
3 | // Copyright (C) 2000 Free Software Foundation | |
4 | // | |
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) | |
9 | // any later version. | |
10 | ||
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. | |
15 | ||
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, | |
19 | // USA. | |
20 | ||
21 | // 22.1.1.1.2 - class locale::facet [lib.locale.facet] | |
22 | ||
4bc95009 | 23 | #include <cwchar> // for mbstate_t |
0479a462 | 24 | #include <locale> |
0214010c BK |
25 | #include <stdexcept> |
26 | #include <string> | |
0479a462 | 27 | #include <iterator> |
fe413112 | 28 | #include <testsuite_hooks.h> |
0479a462 BK |
29 | |
30 | // 1 a class if a facet if it is publicly derived from another facet | |
3e80ddc7 BK |
31 | typedef std::istreambuf_iterator<char> input_iterator; |
32 | typedef std::ostreambuf_iterator<char> output_iterator; | |
0479a462 BK |
33 | |
34 | class gnu_collate: public std::collate<char> { }; | |
35 | class gnu_ctype: public std::ctype<char> { }; | |
4bc95009 | 36 | class gnu_codecvt: public std::codecvt<char, char, std::mbstate_t> { }; |
0479a462 BK |
37 | class gnu_moneypunct: public std::moneypunct<char> { }; |
38 | class gnu_moneypunct_true: public std::moneypunct<char, true> { }; | |
39 | class gnu_money_get: public std::money_get<char> { }; | |
40 | class gnu_money_put: public std::money_put<char> { }; | |
41 | class gnu_numpunct: public std::numpunct<char> { }; | |
42 | class gnu_num_get: public std::num_get<char> { }; | |
43 | class gnu_num_put: public std::num_put<char> { }; | |
44 | class gnu_time_get: public std::time_get<char> { }; | |
45 | class gnu_time_put: public std::time_put<char> { }; | |
46 | class gnu_messages: public std::messages<char> { }; | |
47 | ||
48 | class gnu_collate_byname: public std::collate_byname<char> | |
49 | { | |
50 | public: | |
51 | explicit | |
52 | gnu_collate_byname(const char* c, size_t refs = 0) | |
53 | : std::collate_byname<char>(c, refs) { } | |
54 | }; | |
55 | ||
56 | class gnu_ctype_byname: public std::ctype_byname<char> | |
57 | { | |
58 | public: | |
59 | explicit | |
60 | gnu_ctype_byname(const char* c, size_t refs = 0) | |
61 | : std::ctype_byname<char>(c, refs) { } | |
62 | }; | |
63 | ||
64 | class gnu_moneypunct_byname_true: public std::moneypunct_byname<char, true> | |
65 | { | |
66 | public: | |
67 | explicit | |
68 | gnu_moneypunct_byname_true(const char* c, size_t refs = 0) | |
69 | : std::moneypunct_byname<char, true>(c, refs) { } | |
70 | }; | |
71 | ||
72 | class gnu_moneypunct_byname_false: public std::moneypunct_byname<char, false> | |
73 | { | |
74 | public: | |
75 | explicit | |
76 | gnu_moneypunct_byname_false(const char* c, size_t refs = 0) | |
77 | : std::moneypunct_byname<char, false>(c, refs) { } | |
78 | }; | |
79 | ||
80 | ||
3e80ddc7 | 81 | class gnu_money_get_in: public std::money_get<char, input_iterator> |
0479a462 BK |
82 | { |
83 | public: | |
84 | explicit | |
85 | gnu_money_get_in(size_t refs = 0) | |
3e80ddc7 | 86 | : std::money_get<char, input_iterator>(refs) { } |
0479a462 BK |
87 | }; |
88 | ||
3e80ddc7 | 89 | class gnu_money_put_out: public std::money_put<char, output_iterator> |
0479a462 BK |
90 | { |
91 | public: | |
92 | explicit | |
93 | gnu_money_put_out(size_t refs = 0) | |
3e80ddc7 | 94 | : std::money_put<char, output_iterator>(refs) { } |
0479a462 BK |
95 | }; |
96 | ||
97 | class gnu_numpunct_byname: public std::numpunct_byname<char> | |
98 | { | |
99 | public: | |
100 | explicit | |
101 | gnu_numpunct_byname(const char* c, size_t refs = 0) | |
102 | : std::numpunct_byname<char>(c, refs) { } | |
103 | }; | |
104 | ||
3e80ddc7 | 105 | class gnu_num_get_in: public std::num_get<char, input_iterator> |
0479a462 BK |
106 | { |
107 | public: | |
108 | explicit | |
109 | gnu_num_get_in(size_t refs = 0) | |
3e80ddc7 | 110 | : std::num_get<char, input_iterator>(refs) { } |
0479a462 BK |
111 | }; |
112 | ||
3e80ddc7 | 113 | class gnu_num_put_out: public std::num_put<char, output_iterator> |
0479a462 BK |
114 | { |
115 | public: | |
116 | explicit | |
117 | gnu_num_put_out(size_t refs = 0) | |
3e80ddc7 | 118 | : std::num_put<char, output_iterator>(refs) { } |
0479a462 BK |
119 | }; |
120 | ||
121 | class gnu_time_get_byname: public std::time_get_byname<char> | |
122 | { | |
123 | public: | |
124 | explicit | |
125 | gnu_time_get_byname(const char* c, size_t refs = 0) | |
126 | : std::time_get_byname<char>(c, refs) { } | |
127 | }; | |
128 | ||
3e80ddc7 | 129 | class gnu_time_get_in: public std::time_get<char, input_iterator> |
0479a462 BK |
130 | { |
131 | public: | |
132 | explicit | |
133 | gnu_time_get_in(size_t refs = 0) | |
3e80ddc7 | 134 | : std::time_get<char, input_iterator>(refs) { } |
0479a462 BK |
135 | }; |
136 | ||
137 | class gnu_time_put_byname: public std::time_put_byname<char> | |
138 | { | |
139 | public: | |
140 | explicit | |
141 | gnu_time_put_byname(const char* c, size_t refs = 0) | |
142 | : std::time_put_byname<char>(c, refs) { } | |
143 | }; | |
144 | ||
3e80ddc7 | 145 | class gnu_time_put_out: public std::time_put<char, output_iterator> |
0479a462 BK |
146 | { |
147 | public: | |
148 | explicit | |
149 | gnu_time_put_out(size_t refs = 0) | |
3e80ddc7 | 150 | : std::time_put<char, output_iterator>(refs) { } |
0479a462 BK |
151 | }; |
152 | ||
153 | class gnu_messages_byname: public std::messages_byname<char> | |
154 | { | |
155 | public: | |
156 | explicit | |
157 | gnu_messages_byname(const char* c, size_t refs = 0) | |
158 | : std::messages_byname<char>(c, refs) { } | |
159 | }; | |
160 | ||
161 | ||
162 | // 2 or if it is a class deerived from locale:;facet and containing a | |
163 | // publicly-accessible declaration as follows: | |
164 | class gnu_facet: public std::locale::facet | |
165 | { | |
166 | public: | |
167 | static std::locale::id id; | |
168 | }; | |
169 | ||
170 | std::locale::id gnu_facet::id; | |
171 | ||
172 | void test01() | |
173 | { | |
0214010c BK |
174 | bool test = true; |
175 | const std::string name_no("*"); | |
176 | const std::string name_c("C"); | |
177 | ||
178 | try | |
179 | { | |
180 | gnu_collate obj01; | |
181 | gnu_ctype obj02; | |
182 | gnu_codecvt obj03; | |
183 | gnu_moneypunct obj04; | |
184 | gnu_moneypunct_true obj05; | |
185 | gnu_money_get obj06; | |
186 | gnu_money_put obj07; | |
187 | gnu_numpunct obj08; | |
188 | gnu_num_get obj09; | |
189 | gnu_num_put obj10; | |
190 | gnu_time_get obj11; | |
191 | gnu_time_put obj12; | |
192 | gnu_messages obj13; | |
193 | gnu_time_put_out obj14(0); | |
194 | gnu_time_put_byname obj15("C", 0); | |
195 | gnu_time_get_in obj16(0); | |
196 | gnu_time_get_byname obj17("C", 0); | |
197 | gnu_num_put_out obj18(0); | |
198 | gnu_num_get_in obj19(0); | |
199 | gnu_numpunct_byname obj20("C", 0); | |
200 | gnu_money_put_out obj21(0); | |
201 | gnu_money_get_in obj22(0); | |
202 | gnu_moneypunct_byname_false obj23("C", 0); | |
203 | gnu_moneypunct_byname_true obj24("C", 0); | |
204 | gnu_ctype_byname obj25("C", 0); | |
205 | gnu_collate_byname obj26("C", 0); | |
206 | gnu_messages_byname obj27("C", 0); | |
207 | } | |
208 | catch (std::runtime_error& obj) | |
209 | { | |
210 | // named locale not valid | |
211 | VERIFY( false ); | |
212 | } | |
213 | catch (std::exception& obj) | |
214 | { | |
215 | // some other error | |
216 | VERIFY( false ); | |
217 | } | |
0479a462 BK |
218 | |
219 | // 2 | |
0214010c BK |
220 | try |
221 | { | |
222 | gnu_facet obj28; | |
223 | } | |
224 | catch (std::runtime_error& obj) | |
225 | { | |
226 | // named locale not valid | |
227 | VERIFY( false ); | |
228 | } | |
229 | catch (std::exception& obj) | |
230 | { | |
231 | // some other error | |
232 | VERIFY( false ); | |
233 | } | |
0479a462 BK |
234 | } |
235 | ||
236 | int main () | |
237 | { | |
238 | test01(); | |
239 | ||
240 | return 0; | |
241 | } |