OSDN Git Service

2003-01-21 Benjamin Kosnik <bkoz@redhat.com>
[pf3gnuchains/gcc-fork.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 = true;
36
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 );
46
47   // cache the moneypunct facets
48   typedef moneypunct<char, true> __money_true;
49   typedef moneypunct<char, 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); 
56
57   // sanity check the data is correct.
58   const string empty;
59
60   // total EPA budget FY 2002
61   const string digits1("720000000000");
62
63   // est. cost, national missile "defense", expressed as a loss in USD 2001
64   const string digits2("-10000000000000");  
65
66   // not valid input
67   const string digits3("-A"); 
68
69   // input less than frac_digits
70   const string digits4("-1");
71   
72   iterator_type end;
73   istringstream iss;
74   iss.imbue(loc_hk);
75   // cache the money_get facet
76   const money_get<char>& mon_get = use_facet<money_get<char> >(iss.getloc()); 
77
78   // now try with showbase, to get currency symbol in format
79   iss.setf(ios_base::showbase);
80
81   iss.str("HK$7,200,000,000.00"); 
82   iterator_type is_it09(iss);
83   string 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 );
88
89   iss.str("(HKD 100,000,000,000.00)"); 
90   iterator_type is_it10(iss);
91   string 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 );
96
97   iss.str("(HKD .01)"); 
98   iterator_type is_it11(iss);
99   string 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 );
104
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);
110
111   iss.str("HK$7,200,000,000.00"); 
112   iterator_type is_it12(iss);
113   string 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 );
118
119   iss.str("(HKD 100,000,000,000.00)"); 
120   iterator_type is_it13(iss);
121   string 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 );
126
127   iss.str("(HKD .01)"); 
128   iterator_type is_it14(iss);
129   string 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 );
134 }
135
136 int main()
137 {
138   test02();
139   return 0;
140 }