Imported Upstream version 4.7.2
[platform/upstream/gcc48.git] / libstdc++-v3 / testsuite / 22_locale / facet / 1.cc
1 // 2000-08-31 Benjamin Kosnik <bkoz@redhat.com>
2
3 // Copyright (C) 2000, 2002, 2003, 2009 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 3, 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 COPYING3.  If not see
18 // <http://www.gnu.org/licenses/>.
19
20 // 22.1.1.1.2 - class locale::facet [lib.locale.facet]
21
22 #include <cwchar> // for mbstate_t
23 #include <locale>
24 #include <stdexcept>
25 #include <string>
26 #include <iterator>
27 #include <limits>
28 #include <testsuite_hooks.h>
29
30 // 1 a class if a facet if it is publicly derived from another facet
31 typedef std::istreambuf_iterator<char>          input_iterator;
32 typedef std::ostreambuf_iterator<char>          output_iterator;
33
34 class gnu_collate: public std::collate<char> { }; 
35 class gnu_ctype: public std::ctype<char> { }; 
36 class gnu_codecvt: public std::codecvt<char, char, std::mbstate_t> { }; 
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
81 class gnu_money_get_in: public std::money_get<char, input_iterator>
82 {
83 public:
84   explicit
85   gnu_money_get_in(size_t refs = 0)
86   : std::money_get<char, input_iterator>(refs) { }
87 };
88
89 class gnu_money_put_out: public std::money_put<char, output_iterator>
90 {
91 public:
92   explicit
93   gnu_money_put_out(size_t refs = 0)
94   : std::money_put<char, output_iterator>(refs) { }
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
105 class gnu_num_get_in: public std::num_get<char, input_iterator> 
106 {
107 public:
108   explicit
109   gnu_num_get_in(size_t refs = 0)
110   : std::num_get<char, input_iterator>(refs) { }
111 };
112
113 class gnu_num_put_out: public std::num_put<char, output_iterator> 
114 {
115 public:
116   explicit
117   gnu_num_put_out(size_t refs = 0)
118   : std::num_put<char, output_iterator>(refs) { }
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
129 class gnu_time_get_in: public std::time_get<char, input_iterator>
130 {
131 public:
132   explicit
133   gnu_time_get_in(size_t refs = 0)
134   : std::time_get<char, input_iterator>(refs) { }
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
145 class gnu_time_put_out: public std::time_put<char, output_iterator> 
146 {
147 public:
148   explicit
149   gnu_time_put_out(size_t refs = 0)
150   : std::time_put<char, output_iterator>(refs) { }
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 derived 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 {
174   bool test __attribute__((unused)) = 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     }
218
219   // 2
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     }
234 }
235
236 int main ()
237 {
238   test01();
239   return 0;
240 }