locale_facets.tcc (money_get::do_get(string_type&)): Thousands-sep are always optional...
[gcc.git] / libstdc++-v3 / testsuite / 22_locale / money_get / get / wchar_t / 2.cc
1 // 2001-09-12 Benjamin Kosnik <bkoz@redhat.com>
2
3 // Copyright (C) 2001, 2002, 2003, 2004 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 wstring 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<wchar_t> 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 VERIFY( loc_c != loc_hk );
41
42 // cache the moneypunct facets
43 typedef moneypunct<wchar_t, true> __money_true;
44 typedef moneypunct<wchar_t, false> __money_false;
45
46 // sanity check the data is correct.
47 const wstring empty;
48
49 // total EPA budget FY 2002
50 const wstring digits1(L"720000000000");
51
52 // est. cost, national missile "defense", expressed as a loss in USD 2001
53 const wstring digits2(L"-10000000000000");
54
55 // not valid input
56 const wstring digits3(L"-A");
57
58 // input less than frac_digits
59 const wstring digits4(L"-1");
60
61 iterator_type end;
62 wistringstream iss;
63 iss.imbue(loc_hk);
64 // cache the money_get facet
65 const money_get<wchar_t>& mon_get = use_facet<money_get<wchar_t> >(iss.getloc());
66
67 // now try with showbase, to get currency symbol in format
68 iss.setf(ios_base::showbase);
69
70 iss.str(L"HK$7,200,000,000.00");
71 iterator_type is_it09(iss);
72 wstring result9;
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 );
77
78 iss.str(L"(HKD 100,000,000,000.00)");
79 iterator_type is_it10(iss);
80 wstring result10;
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 );
85
86 iss.str(L"(HKD .01)");
87 iterator_type is_it11(iss);
88 wstring result11;
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 );
93
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
97 // consumed.
98 iss.unsetf(ios_base::showbase);
99
100 iss.str(L"HK$7,200,000,000.00");
101 iterator_type is_it12(iss);
102 wstring result12;
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 );
107
108 iss.str(L"(HKD 100,000,000,000.00)");
109 iterator_type is_it13(iss);
110 wstring result13;
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 );
115
116 iss.str(L"(HKD .01)");
117 iterator_type is_it14(iss);
118 wstring result14;
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 );
123 }
124
125 int main()
126 {
127 test02();
128 return 0;
129 }