Merged trunk at revision 161680 into branch.
[official-gcc.git] / libstdc++-v3 / testsuite / 22_locale / money_put / put / wchar_t / 2.cc
blob592c913f08459001cdb2b7e9ee8e0ff2890cfb71
1 // { dg-require-namedlocale "" }
3 // 2001-08-27 Benjamin Kosnik <bkoz@redhat.com>
5 // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2009, 2010
6 // Free Software Foundation
7 //
8 // This file is part of the GNU ISO C++ Library. This library is free
9 // software; you can redistribute it and/or modify it under the
10 // terms of the GNU General Public License as published by the
11 // Free Software Foundation; either version 3, or (at your option)
12 // any later version.
14 // This library is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 // GNU General Public License for more details.
19 // You should have received a copy of the GNU General Public License along
20 // with this library; see the file COPYING3. If not see
21 // <http://www.gnu.org/licenses/>.
23 // 22.2.6.2.1 money_put members
25 #include <locale>
26 #include <sstream>
27 #include <testsuite_hooks.h>
29 // test wstring version
30 void test02()
32 using namespace std;
33 typedef ostreambuf_iterator<wchar_t> iterator_type;
35 bool test __attribute__((unused)) = true;
37 // basic construction
38 locale loc_c = locale::classic();
39 locale loc_hk = locale("en_HK");
40 VERIFY( loc_c != loc_hk );
42 // sanity check the data is correct.
43 const wstring empty;
45 // total EPA budget FY 2002
46 const wstring digits1(L"720000000000");
48 // est. cost, national missile "defense", expressed as a loss in USD 2001
49 const wstring digits2(L"-10000000000000");
51 // not valid input
52 const wstring digits3(L"-A");
54 // input less than frac_digits
55 const wstring digits4(L"-1");
57 // cache the money_put facet
58 wostringstream oss;
59 oss.imbue(loc_hk);
60 const money_put<wchar_t>& mon_put =
61 use_facet<money_put<wchar_t> >(oss.getloc());
63 // now try with showbase, to get currency symbol in format
64 oss.setf(ios_base::showbase);
66 // test sign of more than one digit, say hong kong.
67 oss.str(empty);
68 mon_put.put(oss.rdbuf(), false, oss, L' ', digits1);
69 wstring result5 = oss.str();
70 VERIFY( result5 == L"HK$7,200,000,000.00" );
72 oss.str(empty);
73 mon_put.put(oss.rdbuf(), true, oss, L' ', digits2);
74 wstring result6 = oss.str();
75 VERIFY( result6 == L"(HKD 100,000,000,000.00)" );
77 // test one-digit formats without zero padding
78 oss.imbue(loc_c);
79 oss.str(empty);
80 const money_put<wchar_t>& mon_put2 =
81 use_facet<money_put<wchar_t> >(oss.getloc());
82 mon_put2.put(oss.rdbuf(), true, oss, L' ', digits4);
83 wstring result7 = oss.str();
84 VERIFY( result7 == L"1" );
86 // test one-digit formats with zero padding, zero frac widths
87 oss.imbue(loc_hk);
88 oss.str(empty);
89 const money_put<wchar_t>& mon_put3 =
90 use_facet<money_put<wchar_t> >(oss.getloc());
91 mon_put3.put(oss.rdbuf(), true, oss, L' ', digits4);
92 wstring result8 = oss.str();
93 VERIFY( result8 == L"(HKD .01)" );
95 oss.unsetf(ios_base::showbase);
97 // test bunk input
98 oss.str(empty);
99 mon_put.put(oss.rdbuf(), true, oss, L' ', digits3);
100 wstring result9 = oss.str();
101 VERIFY( result9 == L"" );
104 int main()
106 test02();
107 return 0;