1 // 2001-09-14 Benjamin Kosnik <bkoz@redhat.com>
3 // Copyright (C) 2001-2002 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.2.6.1.1 money_get members
25 #include <testsuite_hooks.h>
27 // XXX This test is not working for non-glibc locale models.
28 // { dg-do run { xfail *-*-* } }
30 #ifdef _GLIBCPP_USE_WCHAR_T
31 // test string version
35 typedef money_base::part part;
36 typedef money_base::pattern pattern;
37 typedef istreambuf_iterator<wchar_t> iterator_type;
42 locale loc_c = locale::classic();
43 locale loc_hk("en_HK");
44 locale loc_fr("fr_FR@euro");
45 locale loc_de("de_DE");
46 VERIFY( loc_c != loc_de );
47 VERIFY( loc_hk != loc_fr );
48 VERIFY( loc_hk != loc_de );
49 VERIFY( loc_de != loc_fr );
51 // cache the moneypunct facets
52 typedef moneypunct<wchar_t, true> __money_true;
53 typedef moneypunct<wchar_t, false> __money_false;
54 const __money_true& monpunct_c_t = use_facet<__money_true>(loc_c);
55 const __money_true& monpunct_de_t = use_facet<__money_true>(loc_de);
56 const __money_false& monpunct_c_f = use_facet<__money_false>(loc_c);
57 const __money_false& monpunct_de_f = use_facet<__money_false>(loc_de);
58 const __money_true& monpunct_hk_t = use_facet<__money_true>(loc_hk);
59 const __money_false& monpunct_hk_f = use_facet<__money_false>(loc_hk);
61 // sanity check the data is correct.
64 // total EPA budget FY 2002
65 const wstring digits1(L"720000000000");
67 // est. cost, national missile "defense", expressed as a loss in USD 2001
68 const wstring digits2(L"-10000000000000");
71 const wstring digits3(L"-A");
73 // input less than frac_digits
74 const wstring digits4(L"-1");
79 // cache the money_get facet
80 const money_get<wchar_t>& mon_get = use_facet<money_get<wchar_t> >(iss.getloc());
83 iss.str(L"7.200.000.000,00 ");
84 iterator_type is_it01(iss);
86 ios_base::iostate err01 = ios_base::goodbit;
87 mon_get.get(is_it01, end, true, iss, err01, result1);
88 VERIFY( result1 == digits1 );
89 VERIFY( err01 == ios_base::eofbit );
91 iss.str(L"7.200.000.000,00 ");
92 iterator_type is_it02(iss);
94 ios_base::iostate err02 = ios_base::goodbit;
95 mon_get.get(is_it02, end, true, iss, err02, result2);
96 VERIFY( result2 == digits1 );
97 VERIFY( err02 == ios_base::eofbit );
99 iss.str(L"7.200.000.000,00 a");
100 iterator_type is_it03(iss);
102 ios_base::iostate err03 = ios_base::goodbit;
103 mon_get.get(is_it03, end, true, iss, err03, result3);
104 VERIFY( result3 == digits1 );
105 VERIFY( err03 == ios_base::goodbit );
108 iterator_type is_it04(iss);
110 ios_base::iostate err04 = ios_base::goodbit;
111 mon_get.get(is_it04, end, true, iss, err04, result4);
112 VERIFY( result4 == empty );
113 VERIFY( err04 == ios_base::failbit | ios_base::eofbit );
115 iss.str(L"working for enlightenment and peace in a mad world");
116 iterator_type is_it05(iss);
118 ios_base::iostate err05 = ios_base::goodbit;
119 mon_get.get(is_it05, end, true, iss, err05, result5);
120 VERIFY( result5 == empty );
121 VERIFY( err05 == ios_base::failbit );
123 // now try with showbase, to get currency symbol in format
124 iss.setf(ios_base::showbase);
126 iss.str(L"7.200.000.000,00 DEM ");
127 iterator_type is_it06(iss);
129 ios_base::iostate err06 = ios_base::goodbit;
130 mon_get.get(is_it06, end, true, iss, err06, result6);
131 VERIFY( result6 == digits1 );
132 VERIFY( err06 == ios_base::eofbit );
134 iss.str(L"7.200.000.000,00 DEM "); // Extra space.
135 iterator_type is_it07(iss);
137 ios_base::iostate err07 = ios_base::goodbit;
138 mon_get.get(is_it07, end, true, iss, err07, result7);
139 VERIFY( result7 == digits1 );
140 VERIFY( err07 == ios_base::goodbit );
142 iss.str(L"7.200.000.000,00 DM");
143 iterator_type is_it08(iss);
145 ios_base::iostate err08 = ios_base::goodbit;
146 mon_get.get(is_it08, end, false, iss, err08, result8);
147 VERIFY( result8 == digits1 );
148 VERIFY( err08 == ios_base::eofbit );
151 iss.str(L"HK$7,200,000,000.00");
152 iterator_type is_it09(iss);
154 ios_base::iostate err09 = ios_base::goodbit;
155 mon_get.get(is_it09, end, false, iss, err09, result9);
156 VERIFY( result9 == digits1 );
157 VERIFY( err09 == ios_base::eofbit );
159 iss.str(L"(HKD 100,000,000,000.00)");
160 iterator_type is_it10(iss);
162 ios_base::iostate err10 = ios_base::goodbit;
163 mon_get.get(is_it10, end, true, iss, err10, result10);
164 VERIFY( result10 == digits2 );
165 VERIFY( err10 == ios_base::goodbit );
167 iss.str(L"(HKD .01)");
168 iterator_type is_it11(iss);
170 ios_base::iostate err11 = ios_base::goodbit;
171 mon_get.get(is_it11, end, true, iss, err11, result11);
172 VERIFY( result11 == digits4 );
173 VERIFY( err11 == ios_base::goodbit );
177 // test double/wstring versions
181 typedef money_base::part part;
182 typedef money_base::pattern pattern;
183 typedef istreambuf_iterator<wchar_t> iterator_type;
187 // basic construction
188 locale loc_c = locale::classic();
189 locale loc_hk("en_HK");
190 locale loc_fr("fr_FR@euro");
191 locale loc_de("de_DE");
192 VERIFY( loc_c != loc_de );
193 VERIFY( loc_hk != loc_fr );
194 VERIFY( loc_hk != loc_de );
195 VERIFY( loc_de != loc_fr );
197 // cache the moneypunct facets
198 typedef moneypunct<wchar_t, true> __money_true;
199 typedef moneypunct<wchar_t, false> __money_false;
200 const __money_true& monpunct_c_t = use_facet<__money_true>(loc_c);
201 const __money_true& monpunct_de_t = use_facet<__money_true>(loc_de);
202 const __money_false& monpunct_c_f = use_facet<__money_false>(loc_c);
203 const __money_false& monpunct_de_f = use_facet<__money_false>(loc_de);
204 const __money_true& monpunct_hk_t = use_facet<__money_true>(loc_hk);
205 const __money_false& monpunct_hk_f = use_facet<__money_false>(loc_hk);
207 // sanity check the data is correct.
210 // total EPA budget FY 2002
211 const long double digits1 = 720000000000;
213 // est. cost, national missile "defense", expressed as a loss in USD 2001
214 const long double digits2 = -10000000000000;
216 // input less than frac_digits
217 const long double digits4 = -1;
222 // cache the money_get facet
223 const money_get<wchar_t>& mon_get = use_facet<money_get<wchar_t> >(iss.getloc());
225 iss.str(L"7.200.000.000,00 ");
226 iterator_type is_it01(iss);
228 ios_base::iostate err01 = ios_base::goodbit;
229 mon_get.get(is_it01, end, true, iss, err01, result1);
230 VERIFY( result1 == digits1 );
231 VERIFY( err01 == ios_base::eofbit );
233 iss.str(L"7.200.000.000,00 ");
234 iterator_type is_it02(iss);
236 ios_base::iostate err02 = ios_base::goodbit;
237 mon_get.get(is_it02, end, false, iss, err02, result2);
238 VERIFY( result2 == digits1 );
239 VERIFY( err02 == ios_base::eofbit );
241 // now try with showbase, to get currency symbol in format
242 iss.setf(ios_base::showbase);
245 iss.str(L"(HKD .01)");
246 iterator_type is_it03(iss);
248 ios_base::iostate err03 = ios_base::goodbit;
249 mon_get.get(is_it03, end, true, iss, err03, result3);
250 VERIFY( result3 == digits4 );
251 VERIFY( err03 == ios_base::goodbit );
259 // Check money_get works with other iterators besides streambuf
261 typedef wstring::const_iterator iter_type;
262 typedef money_get<wchar_t, iter_type> mon_get_type;
263 const ios_base::iostate goodbit = ios_base::goodbit;
264 const ios_base::iostate eofbit = ios_base::eofbit;
265 ios_base::iostate err = goodbit;
266 const locale loc_c = locale::classic();
267 const wstring str = L"0.01Eleanor Roosevelt";
270 iss.imbue(locale(loc_c, new mon_get_type));
272 // Iterator advanced, state, output.
273 const mon_get_type& mg = use_facet<mon_get_type>(iss.getloc());
277 iter_type end1 = mg.get(str.begin(), str.end(), false, iss, err, res1);
278 wstring rem1(end1, str.end());
279 VERIFY( err == goodbit );
280 VERIFY( res1 == L"1" );
281 VERIFY( rem1 == L"Eleanor Roosevelt" );
287 iter_type end2 = mg.get(str.begin(), str.end(), false, iss, err, res2);
288 wstring rem2(end2, str.end());
289 VERIFY( err == goodbit );
291 VERIFY( rem2 == L"Eleanor Roosevelt" );
298 #ifdef _GLIBCPP_USE_WCHAR_T