This commit was manufactured by cvs2svn to create branch
[official-gcc.git] / libstdc++-v3 / testsuite / 22_locale / money_get / get / char / 2.cc
blobe6ae8d926bb76498a91c887e3adb6464ad2a6d1d
1 // 2001-09-12 Benjamin Kosnik <bkoz@redhat.com>
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.
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 string version
28 void test02()
30 using namespace std;
31 typedef istreambuf_iterator<char> iterator_type;
33 bool test __attribute__((unused)) = true;
35 // basic construction
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");
49 iterator_type end;
50 istringstream iss;
51 iss.imbue(loc_hk);
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);
60 string result9;
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);
68 string result10;
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 );
74 iss.str("(HKD .01)");
75 iterator_type is_it11(iss);
76 string result11;
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
85 // consumed.
86 iss.unsetf(ios_base::showbase);
88 iss.str("HK$7,200,000,000.00");
89 iterator_type is_it12(iss);
90 string result12;
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);
98 string result13;
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);
106 string result14;
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 );
113 int main()
115 test02();
116 return 0;