]>
Commit | Line | Data |
---|---|---|
4216708a | 1 | // { dg-require-namedlocale "en_HK.ISO8859-1" } |
f63a8495 | 2 | |
5f8d36fe BK |
3 | // 2001-08-27 Benjamin Kosnik <bkoz@redhat.com> |
4 | ||
a945c346 | 5 | // Copyright (C) 2001-2024 Free Software Foundation, Inc. |
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 | |
748086b7 | 10 | // Free Software Foundation; either version 3, or (at your option) |
5f8d36fe BK |
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 | |
748086b7 JJ |
19 | // with this library; see the file COPYING3. If not see |
20 | // <http://www.gnu.org/licenses/>. | |
5f8d36fe BK |
21 | |
22 | // 22.2.6.2.1 money_put 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; | |
5f8d36fe BK |
32 | typedef ostreambuf_iterator<char> iterator_type; |
33 | ||
5f8d36fe BK |
34 | // basic construction |
35 | locale loc_c = locale::classic(); | |
4216708a | 36 | locale loc_hk = locale(ISO_8859(1,en_HK)); |
fe932e50 | 37 | VERIFY( loc_c != loc_hk ); |
5f8d36fe BK |
38 | |
39 | // sanity check the data is correct. | |
40 | const string empty; | |
41 | ||
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 | ||
48 | // not valid input | |
49 | const string digits3("-A"); | |
50 | ||
51 | // input less than frac_digits | |
52 | const string digits4("-1"); | |
53 | ||
54 | // cache the money_put facet | |
55 | ostringstream oss; | |
56 | oss.imbue(loc_hk); | |
57 | const money_put<char>& mon_put = use_facet<money_put<char> >(oss.getloc()); | |
58 | ||
59 | // now try with showbase, to get currency symbol in format | |
60 | oss.setf(ios_base::showbase); | |
61 | ||
62 | // test sign of more than one digit, say hong kong. | |
63 | oss.str(empty); | |
567d4027 | 64 | mon_put.put(oss.rdbuf(), false, oss, ' ', digits1); |
5f8d36fe BK |
65 | string result5 = oss.str(); |
66 | VERIFY( result5 == "HK$7,200,000,000.00"); | |
67 | ||
68 | oss.str(empty); | |
567d4027 | 69 | mon_put.put(oss.rdbuf(), true, oss, ' ', digits2); |
5f8d36fe BK |
70 | string result6 = oss.str(); |
71 | VERIFY( result6 == "(HKD 100,000,000,000.00)"); | |
72 | ||
73 | // test one-digit formats without zero padding | |
74 | oss.imbue(loc_c); | |
75 | oss.str(empty); | |
76 | const money_put<char>& mon_put2 = use_facet<money_put<char> >(oss.getloc()); | |
567d4027 | 77 | mon_put2.put(oss.rdbuf(), true, oss, ' ', digits4); |
5f8d36fe BK |
78 | string result7 = oss.str(); |
79 | VERIFY( result7 == "1"); | |
80 | ||
81 | // test one-digit formats with zero padding, zero frac widths | |
82 | oss.imbue(loc_hk); | |
83 | oss.str(empty); | |
84 | const money_put<char>& mon_put3 = use_facet<money_put<char> >(oss.getloc()); | |
567d4027 | 85 | mon_put3.put(oss.rdbuf(), true, oss, ' ', digits4); |
5f8d36fe BK |
86 | string result8 = oss.str(); |
87 | VERIFY( result8 == "(HKD .01)"); | |
88 | ||
89 | oss.unsetf(ios_base::showbase); | |
90 | ||
91 | // test bunk input | |
92 | oss.str(empty); | |
567d4027 | 93 | mon_put.put(oss.rdbuf(), true, oss, ' ', digits3); |
5f8d36fe BK |
94 | string result9 = oss.str(); |
95 | VERIFY( result9 == ""); | |
96 | } | |
97 | ||
98 | int main() | |
99 | { | |
3d838e28 | 100 | test02(); |
5f8d36fe BK |
101 | return 0; |
102 | } |