1 // 2001-09-12 Benjamin Kosnik <bkoz@redhat.com>
3 // Copyright (C) 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.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 // test string version
34 typedef money_base::part part
;
35 typedef money_base::pattern pattern
;
36 typedef istreambuf_iterator
<char> iterator_type
;
42 locale loc_c
= locale::classic();
45 locale
loc_hk("en_HK");
47 VERIFY( loc_c
!= loc_hk
);
49 locale
loc_fr("fr_FR@euro");
51 VERIFY( loc_c
!= loc_fr
);
53 locale
loc_de("de_DE");
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.
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");
81 const string
digits3("-A");
83 // input less than frac_digits
84 const string
digits4("-1");
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
);
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
);
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
);
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
);
118 iterator_type
is_it04(iss
);
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
);
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
);
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
);
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
);
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
);
161 iss
.str("HK$7,200,000,000.00");
162 iterator_type
is_it09(iss
);
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
);
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
);
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
190 typedef money_base::part part
;
191 typedef money_base::pattern pattern
;
192 typedef istreambuf_iterator
<char> iterator_type
;
197 // basic construction
198 locale loc_c
= locale::classic();
201 locale
loc_hk("en_HK");
203 VERIFY( loc_c
!= loc_hk
);
205 locale
loc_fr("fr_FR@euro");
207 VERIFY( loc_c
!= loc_fr
);
209 locale
loc_de("de_DE");
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.
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;
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
);
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
);
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
);
265 iss
.str("(HKD .01)");
266 iterator_type
is_it03(iss
);
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
);