]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/22_locale/money_get/get/char/2.cc
testsuite_hooks.cc: Remove try_named_locale.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 22_locale / money_get / get / char / 2.cc
CommitLineData
f63a8495
PC
1// { dg-require-namedlocale "" }
2
5f8d36fe
BK
3// 2001-09-12 Benjamin Kosnik <bkoz@redhat.com>
4
f63a8495 5// Copyright (C) 2001, 2002, 2003, 2004, 2005 Free Software Foundation
5f8d36fe
BK
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 2, 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 COPYING. If not, write to the Free
20// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
21// USA.
22
23// 22.2.6.1.1 money_get members
24
25#include <locale>
26#include <sstream>
27#include <testsuite_hooks.h>
28
29// test string version
30void test02()
31{
32 using namespace std;
5f8d36fe
BK
33 typedef istreambuf_iterator<char> iterator_type;
34
11f10e6b 35 bool test __attribute__((unused)) = true;
5f8d36fe
BK
36
37 // basic construction
38 locale loc_c = locale::classic();
f63a8495 39 locale loc_hk = locale("en_HK");
d9010fca 40 VERIFY( loc_c != loc_hk );
5f8d36fe 41
5f8d36fe
BK
42 // total EPA budget FY 2002
43 const string digits1("720000000000");
44
45 // est. cost, national missile "defense", expressed as a loss in USD 2001
46 const string digits2("-10000000000000");
47
5f8d36fe
BK
48 // input less than frac_digits
49 const string digits4("-1");
50
51 iterator_type end;
52 istringstream iss;
53 iss.imbue(loc_hk);
54 // cache the money_get facet
55 const money_get<char>& mon_get = use_facet<money_get<char> >(iss.getloc());
56
57 // now try with showbase, to get currency symbol in format
58 iss.setf(ios_base::showbase);
59
60 iss.str("HK$7,200,000,000.00");
61 iterator_type is_it09(iss);
62 string result9;
63 ios_base::iostate err09 = ios_base::goodbit;
64 mon_get.get(is_it09, end, false, iss, err09, result9);
65 VERIFY( result9 == digits1 );
66 VERIFY( err09 == ios_base::eofbit );
67
68 iss.str("(HKD 100,000,000,000.00)");
69 iterator_type is_it10(iss);
70 string result10;
71 ios_base::iostate err10 = ios_base::goodbit;
72 mon_get.get(is_it10, end, true, iss, err10, result10);
73 VERIFY( result10 == digits2 );
b7e64db2 74 VERIFY( err10 == ios_base::eofbit );
5f8d36fe
BK
75
76 iss.str("(HKD .01)");
77 iterator_type is_it11(iss);
78 string result11;
79 ios_base::iostate err11 = ios_base::goodbit;
80 mon_get.get(is_it11, end, true, iss, err11, result11);
81 VERIFY( result11 == digits4 );
b7e64db2 82 VERIFY( err11 == ios_base::eofbit );
5f8d36fe
BK
83
84 // for the "en_HK" locale the parsing of the very same input streams must
85 // be successful without showbase too, since the symbol field appears in
86 // the first positions in the format and the symbol, when present, must be
87 // consumed.
88 iss.unsetf(ios_base::showbase);
89
90 iss.str("HK$7,200,000,000.00");
91 iterator_type is_it12(iss);
92 string result12;
93 ios_base::iostate err12 = ios_base::goodbit;
94 mon_get.get(is_it12, end, false, iss, err12, result12);
95 VERIFY( result12 == digits1 );
96 VERIFY( err12 == ios_base::eofbit );
97
98 iss.str("(HKD 100,000,000,000.00)");
99 iterator_type is_it13(iss);
100 string result13;
101 ios_base::iostate err13 = ios_base::goodbit;
102 mon_get.get(is_it13, end, true, iss, err13, result13);
103 VERIFY( result13 == digits2 );
b7e64db2 104 VERIFY( err13 == ios_base::eofbit );
5f8d36fe
BK
105
106 iss.str("(HKD .01)");
107 iterator_type is_it14(iss);
108 string result14;
109 ios_base::iostate err14 = ios_base::goodbit;
110 mon_get.get(is_it14, end, true, iss, err14, result14);
111 VERIFY( result14 == digits4 );
b7e64db2 112 VERIFY( err14 == ios_base::eofbit );
5f8d36fe
BK
113}
114
115int main()
116{
3d838e28 117 test02();
5f8d36fe
BK
118 return 0;
119}