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 istreambuf_iterator
<char> iterator_type
;
33 bool test
__attribute__((unused
)) = true;
36 locale loc_c
= locale::classic();
37 locale loc_hk
= __gnu_test::try_named_locale("en_HK");
38 VERIFY( loc_c
!= loc_hk
);
40 // total EPA budget FY 2002
41 const string
digits1("720000000000");
43 // est. cost, national missile "defense", expressed as a loss in USD 2001
44 const string
digits2("-10000000000000");
46 // input less than frac_digits
47 const string
digits4("-1");
52 // cache the money_get facet
53 const money_get
<char>& mon_get
= use_facet
<money_get
<char> >(iss
.getloc());
55 // now try with showbase, to get currency symbol in format
56 iss
.setf(ios_base::showbase
);
58 iss
.str("HK$7,200,000,000.00");
59 iterator_type
is_it09(iss
);
61 ios_base::iostate err09
= ios_base::goodbit
;
62 mon_get
.get(is_it09
, end
, false, iss
, err09
, result9
);
63 VERIFY( result9
== digits1
);
64 VERIFY( err09
== ios_base::eofbit
);
66 iss
.str("(HKD 100,000,000,000.00)");
67 iterator_type
is_it10(iss
);
69 ios_base::iostate err10
= ios_base::goodbit
;
70 mon_get
.get(is_it10
, end
, true, iss
, err10
, result10
);
71 VERIFY( result10
== digits2
);
72 VERIFY( err10
== ios_base::eofbit
);
75 iterator_type
is_it11(iss
);
77 ios_base::iostate err11
= ios_base::goodbit
;
78 mon_get
.get(is_it11
, end
, true, iss
, err11
, result11
);
79 VERIFY( result11
== digits4
);
80 VERIFY( err11
== ios_base::eofbit
);
82 // for the "en_HK" locale the parsing of the very same input streams must
83 // be successful without showbase too, since the symbol field appears in
84 // the first positions in the format and the symbol, when present, must be
86 iss
.unsetf(ios_base::showbase
);
88 iss
.str("HK$7,200,000,000.00");
89 iterator_type
is_it12(iss
);
91 ios_base::iostate err12
= ios_base::goodbit
;
92 mon_get
.get(is_it12
, end
, false, iss
, err12
, result12
);
93 VERIFY( result12
== digits1
);
94 VERIFY( err12
== ios_base::eofbit
);
96 iss
.str("(HKD 100,000,000,000.00)");
97 iterator_type
is_it13(iss
);
99 ios_base::iostate err13
= ios_base::goodbit
;
100 mon_get
.get(is_it13
, end
, true, iss
, err13
, result13
);
101 VERIFY( result13
== digits2
);
102 VERIFY( err13
== ios_base::eofbit
);
104 iss
.str("(HKD .01)");
105 iterator_type
is_it14(iss
);
107 ios_base::iostate err14
= ios_base::goodbit
;
108 mon_get
.get(is_it14
, end
, true, iss
, err14
, result14
);
109 VERIFY( result14
== digits4
);
110 VERIFY( err14
== ios_base::eofbit
);