2001-09-13 Alexandre Petit-Bianco <apbianco@redhat.com>
[official-gcc.git] / libstdc++-v3 / testsuite / 22_locale / money_get_members_char.cc
bloba3e8ad670e97cb909626d1c51aa65828406e346f
1 // 2001-09-12 Benjamin Kosnik <bkoz@redhat.com>
3 // Copyright (C) 2001 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.
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,
19 // USA.
21 // 22.2.6.1.1 money_get members
23 #include <locale>
24 #include <sstream>
25 #include <testsuite_hooks.h>
27 // XXX This test is not working for non-glibc locale models.
28 // { dg-do run { xfail *-*-* } }
30 // test string version
31 void test01()
33 using namespace std;
34 typedef money_base::part part;
35 typedef money_base::pattern pattern;
36 typedef istreambuf_iterator<char> iterator_type;
38 bool test = true;
39 string str;
41 // basic construction
42 locale loc_c = locale::classic();
43 str = loc_c.name();
45 locale loc_hk("en_HK");
46 str = loc_hk.name();
47 VERIFY( loc_c != loc_hk );
49 locale loc_fr("fr_FR@euro");
50 str = loc_fr.name();
51 VERIFY( loc_c != loc_fr );
53 locale loc_de("de_DE");
54 str = loc_de.name();
55 VERIFY( loc_c != loc_de );
57 VERIFY( loc_hk != loc_fr );
58 VERIFY( loc_hk != loc_de );
59 VERIFY( loc_de != loc_fr );
61 // cache the moneypunct facets
62 typedef moneypunct<char, true> __money_true;
63 typedef moneypunct<char, false> __money_false;
64 const __money_true& monpunct_c_t = use_facet<__money_true>(loc_c);
65 const __money_true& monpunct_de_t = use_facet<__money_true>(loc_de);
66 const __money_false& monpunct_c_f = use_facet<__money_false>(loc_c);
67 const __money_false& monpunct_de_f = use_facet<__money_false>(loc_de);
68 const __money_true& monpunct_hk_t = use_facet<__money_true>(loc_hk);
69 const __money_false& monpunct_hk_f = use_facet<__money_false>(loc_hk);
71 // sanity check the data is correct.
72 const string empty;
74 // total EPA budget FY 2002
75 const string digits1("720000000000");
77 // est. cost, national missile "defense", expressed as a loss in USD 2001
78 const string digits2("-10000000000000");
80 // not valid input
81 const string digits3("-A");
83 // input less than frac_digits
84 const string digits4("-1");
86 iterator_type end;
87 istringstream iss;
88 iss.imbue(loc_de);
89 // cache the money_get facet
90 const money_get<char>& mon_get = use_facet<money_get<char> >(iss.getloc());
93 iss.str("7.200.000.000,00 ");
94 iterator_type is_it01(iss);
95 string result1;
96 ios_base::iostate err01 = ios_base::goodbit;
97 mon_get.get(is_it01, end, true, iss, err01, result1);
98 VERIFY( result1 == digits1 );
99 VERIFY( err01 == ios_base::eofbit );
101 iss.str("7.200.000.000,00 ");
102 iterator_type is_it02(iss);
103 string result2;
104 ios_base::iostate err02 = ios_base::goodbit;
105 mon_get.get(is_it02, end, true, iss, err02, result2);
106 VERIFY( result2 == digits1 );
107 VERIFY( err02 == ios_base::eofbit );
109 iss.str("7.200.000.000,00 a");
110 iterator_type is_it03(iss);
111 string result3;
112 ios_base::iostate err03 = ios_base::goodbit;
113 mon_get.get(is_it03, end, true, iss, err03, result3);
114 VERIFY( result3 == digits1 );
115 VERIFY( err03 == ios_base::goodbit );
117 iss.str("");
118 iterator_type is_it04(iss);
119 string result4;
120 ios_base::iostate err04 = ios_base::goodbit;
121 mon_get.get(is_it04, end, true, iss, err04, result4);
122 VERIFY( result4 == empty );
123 VERIFY( err04 == ios_base::failbit | ios_base::eofbit );
125 iss.str("working for enlightenment and peace in a mad world");
126 iterator_type is_it05(iss);
127 string result5;
128 ios_base::iostate err05 = ios_base::goodbit;
129 mon_get.get(is_it05, end, true, iss, err05, result5);
130 VERIFY( result5 == empty );
131 VERIFY( err05 == ios_base::failbit );
133 // now try with showbase, to get currency symbol in format
134 iss.setf(ios_base::showbase);
136 iss.str("7.200.000.000,00 DEM ");
137 iterator_type is_it06(iss);
138 string result6;
139 ios_base::iostate err06 = ios_base::goodbit;
140 mon_get.get(is_it06, end, true, iss, err06, result6);
141 VERIFY( result6 == digits1 );
142 VERIFY( err06 == ios_base::eofbit );
144 iss.str("7.200.000.000,00 DEM "); // Extra space.
145 iterator_type is_it07(iss);
146 string result7;
147 ios_base::iostate err07 = ios_base::goodbit;
148 mon_get.get(is_it07, end, true, iss, err07, result7);
149 VERIFY( result7 == digits1 );
150 VERIFY( err07 == ios_base::goodbit );
152 iss.str("7.200.000.000,00 DM");
153 iterator_type is_it08(iss);
154 string result8;
155 ios_base::iostate err08 = ios_base::goodbit;
156 mon_get.get(is_it08, end, false, iss, err08, result8);
157 VERIFY( result8 == digits1 );
158 VERIFY( err08 == ios_base::eofbit );
160 iss.imbue(loc_hk);
161 iss.str("HK$7,200,000,000.00");
162 iterator_type is_it09(iss);
163 string result9;
164 ios_base::iostate err09 = ios_base::goodbit;
165 mon_get.get(is_it09, end, false, iss, err09, result9);
166 VERIFY( result9 == digits1 );
167 VERIFY( err09 == ios_base::eofbit );
169 iss.str("(HKD 100,000,000,000.00)");
170 iterator_type is_it10(iss);
171 string result10;
172 ios_base::iostate err10 = ios_base::goodbit;
173 mon_get.get(is_it10, end, true, iss, err10, result10);
174 VERIFY( result10 == digits2 );
175 VERIFY( err10 == ios_base::goodbit );
177 iss.str("(HKD .01)");
178 iterator_type is_it11(iss);
179 string result11;
180 ios_base::iostate err11 = ios_base::goodbit;
181 mon_get.get(is_it11, end, true, iss, err11, result11);
182 VERIFY( result11 == digits4 );
183 VERIFY( err11 == ios_base::goodbit );
186 // test double/string versions
187 void test02()
189 using namespace std;
190 typedef money_base::part part;
191 typedef money_base::pattern pattern;
192 typedef istreambuf_iterator<char> iterator_type;
194 bool test = true;
195 string str;
197 // basic construction
198 locale loc_c = locale::classic();
199 str = loc_c.name();
201 locale loc_hk("en_HK");
202 str = loc_hk.name();
203 VERIFY( loc_c != loc_hk );
205 locale loc_fr("fr_FR@euro");
206 str = loc_fr.name();
207 VERIFY( loc_c != loc_fr );
209 locale loc_de("de_DE");
210 str = loc_de.name();
211 VERIFY( loc_c != loc_de );
213 VERIFY( loc_hk != loc_fr );
214 VERIFY( loc_hk != loc_de );
215 VERIFY( loc_de != loc_fr );
217 // cache the moneypunct facets
218 typedef moneypunct<char, true> __money_true;
219 typedef moneypunct<char, false> __money_false;
220 const __money_true& monpunct_c_t = use_facet<__money_true>(loc_c);
221 const __money_true& monpunct_de_t = use_facet<__money_true>(loc_de);
222 const __money_false& monpunct_c_f = use_facet<__money_false>(loc_c);
223 const __money_false& monpunct_de_f = use_facet<__money_false>(loc_de);
224 const __money_true& monpunct_hk_t = use_facet<__money_true>(loc_hk);
225 const __money_false& monpunct_hk_f = use_facet<__money_false>(loc_hk);
227 // sanity check the data is correct.
228 const string empty;
230 // total EPA budget FY 2002
231 const long double digits1 = 720000000000;
233 // est. cost, national missile "defense", expressed as a loss in USD 2001
234 const long double digits2 = -10000000000000;
236 // input less than frac_digits
237 const long double digits4 = -1;
239 iterator_type end;
240 istringstream iss;
241 iss.imbue(loc_de);
242 // cache the money_get facet
243 const money_get<char>& mon_get = use_facet<money_get<char> >(iss.getloc());
245 iss.str("7.200.000.000,00 ");
246 iterator_type is_it01(iss);
247 long double result1;
248 ios_base::iostate err01 = ios_base::goodbit;
249 mon_get.get(is_it01, end, true, iss, err01, result1);
250 VERIFY( result1 == digits1 );
251 VERIFY( err01 == ios_base::eofbit );
253 iss.str("7.200.000.000,00 ");
254 iterator_type is_it02(iss);
255 long double result2;
256 ios_base::iostate err02 = ios_base::goodbit;
257 mon_get.get(is_it02, end, false, iss, err02, result2);
258 VERIFY( result2 == digits1 );
259 VERIFY( err02 == ios_base::eofbit );
261 // now try with showbase, to get currency symbol in format
262 iss.setf(ios_base::showbase);
264 iss.imbue(loc_hk);
265 iss.str("(HKD .01)");
266 iterator_type is_it03(iss);
267 long double result3;
268 ios_base::iostate err03 = ios_base::goodbit;
269 mon_get.get(is_it03, end, true, iss, err03, result3);
270 VERIFY( result3 == digits4 );
271 VERIFY( err03 == ios_base::goodbit );
274 int main()
276 test01();
277 test02();
278 return 0;