OSDN Git Service

2005-05-18 Paolo Carlini <pcarlini@suse.de>
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / testsuite / 22_locale / money_put / put / wchar_t / 2.cc
1 // { dg-require-namedlocale "" }
2
3 // 2001-08-27 Benjamin Kosnik  <bkoz@redhat.com>
4
5 // Copyright (C) 2001, 2002, 2003, 2004, 2005 Free Software Foundation
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.2.1 money_put members
24
25 #include <locale>
26 #include <sstream>
27 #include <testsuite_hooks.h>
28
29 // test wstring version
30 void test02()
31 {
32   using namespace std;
33   typedef ostreambuf_iterator<wchar_t> iterator_type;
34
35   bool test __attribute__((unused)) = true;
36
37   // basic construction
38   locale loc_c = locale::classic();
39   locale loc_hk = locale("en_HK");
40   VERIFY( loc_c != loc_hk );
41
42   // sanity check the data is correct.
43   const wstring empty;
44
45   // total EPA budget FY 2002
46   const wstring digits1(L"720000000000");
47
48   // est. cost, national missile "defense", expressed as a loss in USD 2001
49   const wstring digits2(L"-10000000000000");  
50
51   // not valid input
52   const wstring digits3(L"-A"); 
53
54   // input less than frac_digits
55   const wstring digits4(L"-1");
56   
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()); 
62
63   // now try with showbase, to get currency symbol in format
64   oss.setf(ios_base::showbase);
65
66   // test sign of more than one digit, say hong kong.
67   oss.str(empty);
68   iterator_type os_it05 = mon_put.put(oss.rdbuf(), false, oss, L' ', digits1);
69   wstring result5 = oss.str();
70   VERIFY( result5 == L"HK$7,200,000,000.00" );
71
72   oss.str(empty);
73   iterator_type os_it06 = mon_put.put(oss.rdbuf(), true, oss, L' ', digits2);
74   wstring result6 = oss.str();
75   VERIFY( result6 == L"(HKD 100,000,000,000.00)" );
76
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   iterator_type os_it07 = mon_put2.put(oss.rdbuf(), true, oss, L' ', digits4);
83   wstring result7 = oss.str();
84   VERIFY( result7 == L"1" );
85
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   iterator_type os_it08 = mon_put3.put(oss.rdbuf(), true, oss, L' ', digits4);
92   wstring result8 = oss.str();
93   VERIFY( result8 == L"(HKD .01)" );
94
95   oss.unsetf(ios_base::showbase);
96
97   // test bunk input
98   oss.str(empty);
99   iterator_type os_it09 = mon_put.put(oss.rdbuf(), true, oss, L' ', digits3);
100   wstring result9 = oss.str();
101   VERIFY( result9 == L"" );
102 }
103
104 int main()
105 {
106   test02();
107   return 0;
108 }