]>
Commit | Line | Data |
---|---|---|
4216708a | 1 | // { dg-require-namedlocale "de_DE.ISO8859-15" } |
f63a8495 | 2 | |
5f8d36fe BK |
3 | // 2001-11-21 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.2.1.1 num_get members | |
23 | ||
24 | #include <locale> | |
25 | #include <sstream> | |
26 | #include <testsuite_hooks.h> | |
27 | ||
28 | void test01() | |
29 | { | |
30 | using namespace std; | |
31 | typedef istreambuf_iterator<wchar_t> iterator_type; | |
32 | ||
5f8d36fe BK |
33 | // basic construction |
34 | locale loc_c = locale::classic(); | |
4216708a | 35 | locale loc_de = locale(ISO_8859(15,de_DE)); |
5f8d36fe | 36 | VERIFY( loc_c != loc_de ); |
5f8d36fe | 37 | |
5f8d36fe BK |
38 | // sanity check the data is correct. |
39 | const wstring empty; | |
5f8d36fe BK |
40 | |
41 | bool b1 = true; | |
42 | bool b0 = false; | |
5f8d36fe | 43 | unsigned long ul1 = 1294967294; |
5f8d36fe BK |
44 | unsigned long ul; |
45 | double d1 = 1.02345e+308; | |
46 | double d2 = 3.15e-308; | |
47 | double d; | |
48 | long double ld1 = 6.630025e+4; | |
5f8d36fe | 49 | long double ld; |
54e2e812 | 50 | void* v = 0; |
5f8d36fe BK |
51 | |
52 | // cache the num_get facet | |
53 | wistringstream iss; | |
54 | iss.imbue(loc_de); | |
55 | const num_get<wchar_t>& ng = use_facet<num_get<wchar_t> >(iss.getloc()); | |
56 | const ios_base::iostate goodbit = ios_base::goodbit; | |
57 | const ios_base::iostate eofbit = ios_base::eofbit; | |
58 | ios_base::iostate err = ios_base::goodbit; | |
59 | ||
60 | // bool, simple | |
61 | iss.str(L"1"); | |
62 | iterator_type os_it00 = iss.rdbuf(); | |
567d4027 | 63 | ng.get(os_it00, 0, iss, err, b1); |
5f8d36fe BK |
64 | VERIFY( b1 == true ); |
65 | VERIFY( err & ios_base::eofbit ); | |
66 | ||
67 | iss.str(L"0"); | |
68 | err = goodbit; | |
69 | ng.get(iss.rdbuf(), 0, iss, err, b0); | |
70 | VERIFY( b0 == false ); | |
71 | VERIFY( err & eofbit ); | |
72 | ||
73 | // ... and one that does | |
74 | iss.str(L"1.294.967.294+++++++"); | |
75 | iss.clear(); | |
76 | iss.width(20); | |
77 | iss.setf(ios_base::left, ios_base::adjustfield); | |
78 | err = goodbit; | |
79 | ng.get(iss.rdbuf(), 0, iss, err, ul); | |
80 | VERIFY( ul == ul1 ); | |
81 | VERIFY( err == goodbit ); | |
82 | ||
83 | iss.str(L"+1,02345e+308"); | |
84 | iss.clear(); | |
85 | iss.width(20); | |
86 | iss.setf(ios_base::right, ios_base::adjustfield); | |
87 | iss.setf(ios_base::scientific, ios_base::floatfield); | |
88 | err = goodbit; | |
89 | ng.get(iss.rdbuf(), 0, iss, err, d); | |
90 | VERIFY( d == d1 ); | |
91 | VERIFY( err == eofbit ); | |
92 | ||
93 | iss.str(L"3,15E-308 "); | |
94 | iss.clear(); | |
95 | iss.width(20); | |
96 | iss.precision(10); | |
97 | iss.setf(ios_base::right, ios_base::adjustfield); | |
98 | iss.setf(ios_base::scientific, ios_base::floatfield); | |
99 | iss.setf(ios_base::uppercase); | |
100 | err = goodbit; | |
101 | ng.get(iss.rdbuf(), 0, iss, err, d); | |
102 | VERIFY( d == d2 ); | |
103 | VERIFY( err == goodbit ); | |
104 | ||
105 | // long double | |
106 | iss.str(L"6,630025e+4"); | |
107 | iss.clear(); | |
108 | err = goodbit; | |
109 | ng.get(iss.rdbuf(), 0, iss, err, ld); | |
110 | VERIFY( ld == ld1 ); | |
111 | VERIFY( err == eofbit ); | |
112 | ||
113 | iss.str(L"0 "); | |
114 | iss.clear(); | |
115 | iss.precision(0); | |
116 | iss.setf(ios_base::fixed, ios_base::floatfield); | |
117 | err = goodbit; | |
118 | ng.get(iss.rdbuf(), 0, iss, err, ld); | |
119 | VERIFY( ld == 0 ); | |
120 | VERIFY( err == goodbit ); | |
121 | ||
90737ab7 | 122 | // void* |
5f8d36fe BK |
123 | iss.str(L"0xbffff74c,"); |
124 | iss.clear(); | |
125 | err = goodbit; | |
126 | ng.get(iss.rdbuf(), 0, iss, err, v); | |
90737ab7 | 127 | VERIFY( v != 0 ); |
5f8d36fe BK |
128 | VERIFY( err == goodbit ); |
129 | ||
3d7c150e | 130 | #ifdef _GLIBCXX_USE_LONG_LONG |
5f8d36fe | 131 | long long ll1 = 9223372036854775807LL; |
5f8d36fe BK |
132 | long long ll; |
133 | ||
134 | iss.str(L"9.223.372.036.854.775.807"); | |
135 | iss.clear(); | |
136 | err = goodbit; | |
137 | ng.get(iss.rdbuf(), 0, iss, err, ll); | |
138 | VERIFY( ll == ll1 ); | |
139 | VERIFY( err == eofbit ); | |
140 | #endif | |
141 | } | |
142 | ||
143 | int main() | |
144 | { | |
145 | test01(); | |
146 | return 0; | |
147 | } | |
148 | ||
149 | ||
150 | // Kathleen Hannah, humanitarian, woman, art-thief |