]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/22_locale/money_get/get/char/2.cc
Improve portability of named locale tests
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 22_locale / money_get / get / char / 2.cc
1 // { dg-require-namedlocale "en_HK.ISO8859-1" }
2
3 // 2001-09-12 Benjamin Kosnik <bkoz@redhat.com>
4
5 // Copyright (C) 2001-2015 Free Software Foundation, Inc.
6 //
7 // This file is part of the GNU ISO C++ Library. This library is free
8 // software; you can redistribute it and/or modify it under the
9 // terms of the GNU General Public License as published by the
10 // Free Software Foundation; either version 3, or (at your option)
11 // any later version.
12
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
17
18 // You should have received a copy of the GNU General Public License along
19 // with this library; see the file COPYING3. If not see
20 // <http://www.gnu.org/licenses/>.
21
22 // 22.2.6.1.1 money_get members
23
24 #include <locale>
25 #include <sstream>
26 #include <testsuite_hooks.h>
27
28 // test string version
29 void test02()
30 {
31 using namespace std;
32 typedef istreambuf_iterator<char> iterator_type;
33
34 bool test __attribute__((unused)) = true;
35
36 // basic construction
37 locale loc_c = locale::classic();
38 locale loc_hk = locale(ISO_8859(1,en_HK));
39 VERIFY( loc_c != loc_hk );
40
41 // total EPA budget FY 2002
42 const string digits1("720000000000");
43
44 // est. cost, national missile "defense", expressed as a loss in USD 2001
45 const string digits2("-10000000000000");
46
47 // input less than frac_digits
48 const string digits4("-1");
49
50 iterator_type end;
51 istringstream iss;
52 iss.imbue(loc_hk);
53 // cache the money_get facet
54 const money_get<char>& mon_get = use_facet<money_get<char> >(iss.getloc());
55
56 // now try with showbase, to get currency symbol in format
57 iss.setf(ios_base::showbase);
58
59 iss.str("HK$7,200,000,000.00");
60 iterator_type is_it09(iss);
61 string result9;
62 ios_base::iostate err09 = ios_base::goodbit;
63 mon_get.get(is_it09, end, false, iss, err09, result9);
64 VERIFY( result9 == digits1 );
65 VERIFY( err09 == ios_base::eofbit );
66
67 iss.str("(HKD 100,000,000,000.00)");
68 iterator_type is_it10(iss);
69 string result10;
70 ios_base::iostate err10 = ios_base::goodbit;
71 mon_get.get(is_it10, end, true, iss, err10, result10);
72 VERIFY( result10 == digits2 );
73 VERIFY( err10 == ios_base::eofbit );
74
75 iss.str("(HKD .01)");
76 iterator_type is_it11(iss);
77 string result11;
78 ios_base::iostate err11 = ios_base::goodbit;
79 mon_get.get(is_it11, end, true, iss, err11, result11);
80 VERIFY( result11 == digits4 );
81 VERIFY( err11 == ios_base::eofbit );
82
83 // for the "en_HK.ISO8859-1" locale the parsing of the very same input streams must
84 // be successful without showbase too, since the symbol field appears in
85 // the first positions in the format and the symbol, when present, must be
86 // consumed.
87 iss.unsetf(ios_base::showbase);
88
89 iss.str("HK$7,200,000,000.00");
90 iterator_type is_it12(iss);
91 string result12;
92 ios_base::iostate err12 = ios_base::goodbit;
93 mon_get.get(is_it12, end, false, iss, err12, result12);
94 VERIFY( result12 == digits1 );
95 VERIFY( err12 == ios_base::eofbit );
96
97 iss.str("(HKD 100,000,000,000.00)");
98 iterator_type is_it13(iss);
99 string result13;
100 ios_base::iostate err13 = ios_base::goodbit;
101 mon_get.get(is_it13, end, true, iss, err13, result13);
102 VERIFY( result13 == digits2 );
103 VERIFY( err13 == ios_base::eofbit );
104
105 iss.str("(HKD .01)");
106 iterator_type is_it14(iss);
107 string result14;
108 ios_base::iostate err14 = ios_base::goodbit;
109 mon_get.get(is_it14, end, true, iss, err14, result14);
110 VERIFY( result14 == digits4 );
111 VERIFY( err14 == ios_base::eofbit );
112 }
113
114 int main()
115 {
116 test02();
117 return 0;
118 }