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