422a53340eb82a8bd20119b8b44c9626c4bd8349
[gcc.git] / libstdc++-v3 / testsuite / 22_locale / money_get / get / char / 2.cc
1 // 2001-09-12 Benjamin Kosnik <bkoz@redhat.com>
2
3 // Copyright (C) 2001, 2002, 2003 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.
10
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.
15
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.
20
21 // 22.2.6.1.1 money_get members
22
23 #include <locale>
24 #include <sstream>
25 #include <testsuite_hooks.h>
26
27 // test string version
28 void test02()
29 {
30 using namespace std;
31 typedef money_base::part part;
32 typedef money_base::pattern pattern;
33 typedef istreambuf_iterator<char> iterator_type;
34
35 bool test __attribute__((unused)) = true;
36
37 // basic construction
38 locale loc_c = locale::classic();
39 locale loc_hk = __gnu_test::try_named_locale("en_HK");
40 locale loc_fr = __gnu_test::try_named_locale("fr_FR@euro");
41 locale loc_de = __gnu_test::try_named_locale("de_DE@euro");
42 VERIFY( loc_c != loc_de );
43 VERIFY( loc_hk != loc_fr );
44 VERIFY( loc_hk != loc_de );
45 VERIFY( loc_de != loc_fr );
46
47 // cache the moneypunct facets
48 typedef moneypunct<char, true> __money_true;
49 typedef moneypunct<char, false> __money_false;
50
51 // sanity check the data is correct.
52 const string empty;
53
54 // total EPA budget FY 2002
55 const string digits1("720000000000");
56
57 // est. cost, national missile "defense", expressed as a loss in USD 2001
58 const string digits2("-10000000000000");
59
60 // not valid input
61 const string digits3("-A");
62
63 // input less than frac_digits
64 const string digits4("-1");
65
66 iterator_type end;
67 istringstream iss;
68 iss.imbue(loc_hk);
69 // cache the money_get facet
70 const money_get<char>& mon_get = use_facet<money_get<char> >(iss.getloc());
71
72 // now try with showbase, to get currency symbol in format
73 iss.setf(ios_base::showbase);
74
75 iss.str("HK$7,200,000,000.00");
76 iterator_type is_it09(iss);
77 string result9;
78 ios_base::iostate err09 = ios_base::goodbit;
79 mon_get.get(is_it09, end, false, iss, err09, result9);
80 VERIFY( result9 == digits1 );
81 VERIFY( err09 == ios_base::eofbit );
82
83 iss.str("(HKD 100,000,000,000.00)");
84 iterator_type is_it10(iss);
85 string result10;
86 ios_base::iostate err10 = ios_base::goodbit;
87 mon_get.get(is_it10, end, true, iss, err10, result10);
88 VERIFY( result10 == digits2 );
89 VERIFY( err10 == ios_base::goodbit );
90
91 iss.str("(HKD .01)");
92 iterator_type is_it11(iss);
93 string result11;
94 ios_base::iostate err11 = ios_base::goodbit;
95 mon_get.get(is_it11, end, true, iss, err11, result11);
96 VERIFY( result11 == digits4 );
97 VERIFY( err11 == ios_base::goodbit );
98
99 // for the "en_HK" locale the parsing of the very same input streams must
100 // be successful without showbase too, since the symbol field appears in
101 // the first positions in the format and the symbol, when present, must be
102 // consumed.
103 iss.unsetf(ios_base::showbase);
104
105 iss.str("HK$7,200,000,000.00");
106 iterator_type is_it12(iss);
107 string result12;
108 ios_base::iostate err12 = ios_base::goodbit;
109 mon_get.get(is_it12, end, false, iss, err12, result12);
110 VERIFY( result12 == digits1 );
111 VERIFY( err12 == ios_base::eofbit );
112
113 iss.str("(HKD 100,000,000,000.00)");
114 iterator_type is_it13(iss);
115 string result13;
116 ios_base::iostate err13 = ios_base::goodbit;
117 mon_get.get(is_it13, end, true, iss, err13, result13);
118 VERIFY( result13 == digits2 );
119 VERIFY( err13 == ios_base::goodbit );
120
121 iss.str("(HKD .01)");
122 iterator_type is_it14(iss);
123 string result14;
124 ios_base::iostate err14 = ios_base::goodbit;
125 mon_get.get(is_it14, end, true, iss, err14, result14);
126 VERIFY( result14 == digits4 );
127 VERIFY( err14 == ios_base::goodbit );
128 }
129
130 int main()
131 {
132 test02();
133 return 0;
134 }