1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
|
// 2005-04-26 Paolo Carlini <pcarlini@suse.de>
// Copyright (C) 2005-2023 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// 22.2.2.1.1 num_get members
#include <locale>
#include <sstream>
#include <limits>
#include <testsuite_hooks.h>
void test01()
{
using namespace std;
typedef istreambuf_iterator<char> iterator_type;
stringstream ss;
const num_get<char>& ng = use_facet<num_get<char> >(ss.getloc());
ios_base::iostate err;
iterator_type end;
unsigned short us0, us1 = numeric_limits<unsigned short>::max();
unsigned int ui0, ui1 = numeric_limits<unsigned int>::max();
unsigned long ul0, ul1 = numeric_limits<unsigned long>::max();
long l01, l1 = numeric_limits<long>::max();
long l02, l2 = numeric_limits<long>::min();
#ifdef _GLIBCXX_USE_LONG_LONG
unsigned long long ull0, ull1 = numeric_limits<unsigned long long>::max();
long long ll01, ll1 = numeric_limits<long long>::max();
long long ll02, ll2 = numeric_limits<long long>::min();
#endif
const string empty;
us0 = 0;
ss << us1;
err = ios_base::goodbit;
end = ng.get(ss.rdbuf(), 0, ss, err, us0);
VERIFY( err == ios_base::eofbit );
VERIFY( us0 == us1 );
us0 = 0;
ss.clear();
ss.str(empty);
ss << us1 << '0';
err = ios_base::goodbit;
end = ng.get(ss.rdbuf(), 0, ss, err, us0);
VERIFY( err == (ios_base::failbit | ios_base::eofbit) );
VERIFY( us0 == numeric_limits<unsigned short>::max() );
ui0 = 0U;
ss.clear();
ss.str(empty);
ss << ui1 << ' ';
err = ios_base::goodbit;
end = ng.get(ss.rdbuf(), 0, ss, err, ui0);
VERIFY( err == ios_base::goodbit );
VERIFY( ui0 == ui1 );
ui0 = 0U;
ss.clear();
ss.str(empty);
ss << ui1 << '1';
err = ios_base::goodbit;
end = ng.get(ss.rdbuf(), 0, ss, err, ui0);
VERIFY( err == (ios_base::failbit | ios_base::eofbit) );
VERIFY( ui0 == numeric_limits<unsigned int>::max() );
ul0 = 0UL;
ss.clear();
ss.str(empty);
ss << ul1;
err = ios_base::goodbit;
end = ng.get(ss.rdbuf(), 0, ss, err, ul0);
VERIFY( err == ios_base::eofbit );
VERIFY( ul0 == ul1 );
ul0 = 0UL;
ss.clear();
ss.str(empty);
ss << ul1 << '2';
err = ios_base::goodbit;
end = ng.get(ss.rdbuf(), 0, ss, err, ul0);
VERIFY( err == (ios_base::failbit | ios_base::eofbit) );
VERIFY( ul0 == numeric_limits<unsigned long>::max() );
l01 = 0L;
ss.clear();
ss.str(empty);
ss << l1 << ' ';
err = ios_base::goodbit;
end = ng.get(ss.rdbuf(), 0, ss, err, l01);
VERIFY( err == ios_base::goodbit );
VERIFY( l01 == l1 );
l01 = 0L;
ss.clear();
ss.str(empty);
ss << l1 << '3';
err = ios_base::goodbit;
end = ng.get(ss.rdbuf(), 0, ss, err, l01);
VERIFY( err == (ios_base::failbit | ios_base::eofbit) );
VERIFY( l01 == numeric_limits<long>::max() );
l02 = 0L;
ss.clear();
ss.str(empty);
ss << l2;
err = ios_base::goodbit;
end = ng.get(ss.rdbuf(), 0, ss, err, l02);
VERIFY( err == ios_base::eofbit );
VERIFY( l02 == l2 );
l02 = 0L;
ss.clear();
ss.str(empty);
ss << l2 << '4';
err = ios_base::goodbit;
end = ng.get(ss.rdbuf(), 0, ss, err, l02);
VERIFY( err == (ios_base::failbit | ios_base::eofbit) );
VERIFY( l02 == numeric_limits<long>::min() );
#ifdef _GLIBCXX_USE_LONG_LONG
ull0 = 0ULL;
ss.clear();
ss.str(empty);
ss << ull1 << ' ';
err = ios_base::goodbit;
end = ng.get(ss.rdbuf(), 0, ss, err, ull0);
VERIFY( err == ios_base::goodbit );
VERIFY( ull0 == ull1 );
ull0 = 0ULL;
ss.clear();
ss.str(empty);
ss << ull1 << '5';
err = ios_base::goodbit;
end = ng.get(ss.rdbuf(), 0, ss, err, ull0);
VERIFY( err == (ios_base::failbit | ios_base::eofbit) );
VERIFY( ull0 == numeric_limits<unsigned long long>::max() );
ll01 = 0LL;
ss.clear();
ss.str(empty);
ss << ll1;
err = ios_base::goodbit;
end = ng.get(ss.rdbuf(), 0, ss, err, ll01);
VERIFY( err == ios_base::eofbit );
VERIFY( ll01 == ll1 );
ll01 = 0LL;
ss.clear();
ss.str(empty);
ss << ll1 << '6';
err = ios_base::goodbit;
end = ng.get(ss.rdbuf(), 0, ss, err, ll01);
VERIFY( err == (ios_base::failbit | ios_base::eofbit) );
VERIFY( ll01 == numeric_limits<long long>::max() );
ll02 = 0LL;
ss.clear();
ss.str(empty);
ss << ll2 << ' ';
err = ios_base::goodbit;
end = ng.get(ss.rdbuf(), 0, ss, err, ll02);
VERIFY( err == ios_base::goodbit );
VERIFY( ll02 == ll2 );
ll02 = 0LL;
ss.clear();
ss.str(empty);
ss << ll2 << '7';
err = ios_base::goodbit;
end = ng.get(ss.rdbuf(), 0, ss, err, ll02);
VERIFY( err == (ios_base::failbit | ios_base::eofbit) );
VERIFY( ll02 == numeric_limits<long long>::min() );
#endif
}
int main()
{
test01();
return 0;
}
|