1 // 2001-09-12 Benjamin Kosnik <bkoz@redhat.com>
3 // Copyright (C) 2001, 2002, 2003, 2004 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 // test string version
31 typedef money_base::part part
;
32 typedef money_base::pattern pattern
;
33 typedef istreambuf_iterator
<char> iterator_type
;
35 bool test
__attribute__((unused
)) = true;
38 locale loc_c
= locale::classic();
39 locale loc_hk
= __gnu_test::try_named_locale("en_HK");
40 VERIFY( loc_c
!= loc_hk
);
42 // cache the moneypunct facets
43 typedef moneypunct
<char, true> __money_true
;
44 typedef moneypunct
<char, false> __money_false
;
46 // sanity check the data is correct.
49 // total EPA budget FY 2002
50 const string
digits1("720000000000");
52 // est. cost, national missile "defense", expressed as a loss in USD 2001
53 const string
digits2("-10000000000000");
56 const string
digits3("-A");
58 // input less than frac_digits
59 const string
digits4("-1");
64 // cache the money_get facet
65 const money_get
<char>& mon_get
= use_facet
<money_get
<char> >(iss
.getloc());
67 // now try with showbase, to get currency symbol in format
68 iss
.setf(ios_base::showbase
);
70 iss
.str("HK$7,200,000,000.00");
71 iterator_type
is_it09(iss
);
73 ios_base::iostate err09
= ios_base::goodbit
;
74 mon_get
.get(is_it09
, end
, false, iss
, err09
, result9
);
75 VERIFY( result9
== digits1
);
76 VERIFY( err09
== ios_base::eofbit
);
78 iss
.str("(HKD 100,000,000,000.00)");
79 iterator_type
is_it10(iss
);
81 ios_base::iostate err10
= ios_base::goodbit
;
82 mon_get
.get(is_it10
, end
, true, iss
, err10
, result10
);
83 VERIFY( result10
== digits2
);
84 VERIFY( err10
== ios_base::goodbit
);
87 iterator_type
is_it11(iss
);
89 ios_base::iostate err11
= ios_base::goodbit
;
90 mon_get
.get(is_it11
, end
, true, iss
, err11
, result11
);
91 VERIFY( result11
== digits4
);
92 VERIFY( err11
== ios_base::goodbit
);
94 // for the "en_HK" locale the parsing of the very same input streams must
95 // be successful without showbase too, since the symbol field appears in
96 // the first positions in the format and the symbol, when present, must be
98 iss
.unsetf(ios_base::showbase
);
100 iss
.str("HK$7,200,000,000.00");
101 iterator_type
is_it12(iss
);
103 ios_base::iostate err12
= ios_base::goodbit
;
104 mon_get
.get(is_it12
, end
, false, iss
, err12
, result12
);
105 VERIFY( result12
== digits1
);
106 VERIFY( err12
== ios_base::eofbit
);
108 iss
.str("(HKD 100,000,000,000.00)");
109 iterator_type
is_it13(iss
);
111 ios_base::iostate err13
= ios_base::goodbit
;
112 mon_get
.get(is_it13
, end
, true, iss
, err13
, result13
);
113 VERIFY( result13
== digits2
);
114 VERIFY( err13
== ios_base::goodbit
);
116 iss
.str("(HKD .01)");
117 iterator_type
is_it14(iss
);
119 ios_base::iostate err14
= ios_base::goodbit
;
120 mon_get
.get(is_it14
, end
, true, iss
, err14
, result14
);
121 VERIFY( result14
== digits4
);
122 VERIFY( err14
== ios_base::goodbit
);