]>
Commit | Line | Data |
---|---|---|
4216708a | 1 | // { dg-require-namedlocale "en_HK.ISO8859-1" } |
f63a8495 | 2 | |
5f8d36fe BK |
3 | // 2001-09-12 Benjamin Kosnik <bkoz@redhat.com> |
4 | ||
7adcbafe | 5 | // Copyright (C) 2001-2022 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.1.1 money_get members | |
23 | ||
24 | #include <locale> | |
25 | #include <sstream> | |
26 | #include <testsuite_hooks.h> | |
27 | ||
28 | // test wstring version | |
29 | void test02() | |
30 | { | |
31 | using namespace std; | |
5f8d36fe BK |
32 | typedef istreambuf_iterator<wchar_t> 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)); |
d9010fca | 37 | VERIFY( loc_c != loc_hk ); |
5f8d36fe | 38 | |
5f8d36fe BK |
39 | // total EPA budget FY 2002 |
40 | const wstring digits1(L"720000000000"); | |
41 | ||
42 | // est. cost, national missile "defense", expressed as a loss in USD 2001 | |
43 | const wstring digits2(L"-10000000000000"); | |
44 | ||
5f8d36fe BK |
45 | // input less than frac_digits |
46 | const wstring digits4(L"-1"); | |
47 | ||
48 | iterator_type end; | |
49 | wistringstream iss; | |
50 | iss.imbue(loc_hk); | |
51 | // cache the money_get facet | |
52 | const money_get<wchar_t>& mon_get = use_facet<money_get<wchar_t> >(iss.getloc()); | |
53 | ||
54 | // now try with showbase, to get currency symbol in format | |
55 | iss.setf(ios_base::showbase); | |
56 | ||
57 | iss.str(L"HK$7,200,000,000.00"); | |
58 | iterator_type is_it09(iss); | |
59 | wstring result9; | |
60 | ios_base::iostate err09 = ios_base::goodbit; | |
61 | mon_get.get(is_it09, end, false, iss, err09, result9); | |
62 | VERIFY( result9 == digits1 ); | |
63 | VERIFY( err09 == ios_base::eofbit ); | |
64 | ||
65 | iss.str(L"(HKD 100,000,000,000.00)"); | |
66 | iterator_type is_it10(iss); | |
67 | wstring result10; | |
68 | ios_base::iostate err10 = ios_base::goodbit; | |
69 | mon_get.get(is_it10, end, true, iss, err10, result10); | |
70 | VERIFY( result10 == digits2 ); | |
b7e64db2 | 71 | VERIFY( err10 == ios_base::eofbit ); |
5f8d36fe BK |
72 | |
73 | iss.str(L"(HKD .01)"); | |
74 | iterator_type is_it11(iss); | |
75 | wstring result11; | |
76 | ios_base::iostate err11 = ios_base::goodbit; | |
77 | mon_get.get(is_it11, end, true, iss, err11, result11); | |
78 | VERIFY( result11 == digits4 ); | |
b7e64db2 | 79 | VERIFY( err11 == ios_base::eofbit ); |
5f8d36fe | 80 | |
4216708a | 81 | // for the "en_HK.ISO8859-1" locale the parsing of the very same input streams must |
5f8d36fe BK |
82 | // be successful without showbase too, since the symbol field appears in |
83 | // the first positions in the format and the symbol, when present, must be | |
84 | // consumed. | |
85 | iss.unsetf(ios_base::showbase); | |
86 | ||
87 | iss.str(L"HK$7,200,000,000.00"); | |
88 | iterator_type is_it12(iss); | |
89 | wstring result12; | |
90 | ios_base::iostate err12 = ios_base::goodbit; | |
91 | mon_get.get(is_it12, end, false, iss, err12, result12); | |
92 | VERIFY( result12 == digits1 ); | |
93 | VERIFY( err12 == ios_base::eofbit ); | |
94 | ||
95 | iss.str(L"(HKD 100,000,000,000.00)"); | |
96 | iterator_type is_it13(iss); | |
97 | wstring result13; | |
98 | ios_base::iostate err13 = ios_base::goodbit; | |
99 | mon_get.get(is_it13, end, true, iss, err13, result13); | |
100 | VERIFY( result13 == digits2 ); | |
b7e64db2 | 101 | VERIFY( err13 == ios_base::eofbit ); |
5f8d36fe BK |
102 | |
103 | iss.str(L"(HKD .01)"); | |
104 | iterator_type is_it14(iss); | |
105 | wstring result14; | |
106 | ios_base::iostate err14 = ios_base::goodbit; | |
107 | mon_get.get(is_it14, end, true, iss, err14, result14); | |
108 | VERIFY( result14 == digits4 ); | |
b7e64db2 | 109 | VERIFY( err14 == ios_base::eofbit ); |
5f8d36fe BK |
110 | } |
111 | ||
112 | int main() | |
113 | { | |
114 | test02(); | |
115 | return 0; | |
116 | } |