]>
Commit | Line | Data |
---|---|---|
894e47e7 PC |
1 | // 2008-10-31 Paolo Carlini <paolo.carlini@oracle.com> |
2 | ||
7adcbafe | 3 | // Copyright (C) 2008-2022 Free Software Foundation, Inc. |
894e47e7 PC |
4 | // |
5 | // This file is part of the GNU ISO C++ Library. This library is free | |
6 | // software; you can redistribute it and/or modify it under the | |
7 | // terms of the GNU General Public License as published by the | |
748086b7 | 8 | // Free Software Foundation; either version 3, or (at your option) |
894e47e7 PC |
9 | // any later version. |
10 | ||
11 | // This library is distributed in the hope that it will be useful, | |
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | // GNU General Public License for more details. | |
15 | ||
16 | // You should have received a copy of the GNU General Public License along | |
748086b7 JJ |
17 | // with this library; see the file COPYING3. If not see |
18 | // <http://www.gnu.org/licenses/>. | |
894e47e7 PC |
19 | |
20 | // 22.2.2.1.1 num_get members | |
21 | ||
22 | #include <locale> | |
23 | #include <sstream> | |
24 | #include <testsuite_hooks.h> | |
25 | ||
26 | struct Punct1: std::numpunct<char> | |
27 | { | |
28 | std::string do_truename() const { return "a"; } | |
29 | std::string do_falsename() const { return "abb"; } | |
30 | }; | |
31 | ||
32 | struct Punct2: std::numpunct<char> | |
33 | { | |
34 | std::string do_truename() const { return "1"; } | |
35 | std::string do_falsename() const { return "0"; } | |
36 | }; | |
37 | ||
38 | struct Punct3: std::numpunct<char> | |
39 | { | |
40 | std::string do_truename() const { return ""; } | |
41 | std::string do_falsename() const { return ""; } | |
42 | }; | |
43 | ||
2a81fe20 PC |
44 | struct Punct4: std::numpunct<char> |
45 | { | |
46 | std::string do_truename() const { return "one"; } | |
47 | std::string do_falsename() const { return "two"; } | |
48 | }; | |
49 | ||
894e47e7 PC |
50 | // libstdc++/37958 |
51 | void test01() | |
52 | { | |
53 | using namespace std; | |
54 | typedef istreambuf_iterator<char> iterator_type; | |
894e47e7 | 55 | |
2a81fe20 | 56 | istringstream iss0, iss1, iss2, iss3, iss4; |
894e47e7 PC |
57 | iss1.imbue(locale(iss1.getloc(), new Punct1)); |
58 | iss2.imbue(locale(iss2.getloc(), new Punct2)); | |
59 | iss3.imbue(locale(iss3.getloc(), new Punct3)); | |
2a81fe20 | 60 | iss4.imbue(locale(iss4.getloc(), new Punct4)); |
7ea6fdf5 | 61 | const num_get<char>& ng0 = use_facet<num_get<char> >(iss0.getloc()); |
894e47e7 PC |
62 | const num_get<char>& ng1 = use_facet<num_get<char> >(iss1.getloc()); |
63 | const num_get<char>& ng2 = use_facet<num_get<char> >(iss2.getloc()); | |
64 | const num_get<char>& ng3 = use_facet<num_get<char> >(iss3.getloc()); | |
2a81fe20 | 65 | const num_get<char>& ng4 = use_facet<num_get<char> >(iss4.getloc()); |
894e47e7 PC |
66 | |
67 | ios_base::iostate err = ios_base::goodbit; | |
68 | iterator_type end; | |
7ea6fdf5 | 69 | bool b0 = false; |
894e47e7 PC |
70 | bool b1 = false; |
71 | bool b2 = false; | |
72 | bool b3 = true; | |
2a81fe20 | 73 | bool b4 = false; |
894e47e7 | 74 | |
7ea6fdf5 PC |
75 | iss0.str("true"); |
76 | iss0.setf(ios_base::boolalpha); | |
77 | err = ios_base::goodbit; | |
78 | end = ng0.get(iss0.rdbuf(), 0, iss0, err, b0); | |
79 | VERIFY( err == ios_base::goodbit ); | |
80 | VERIFY( b0 == true ); | |
81 | ||
82 | iss0.str("false"); | |
83 | iss0.clear(); | |
84 | err = ios_base::goodbit; | |
85 | end = ng0.get(iss0.rdbuf(), 0, iss0, err, b0); | |
86 | VERIFY( err == ios_base::goodbit ); | |
87 | VERIFY( b0 == false ); | |
88 | ||
894e47e7 PC |
89 | iss1.str("a"); |
90 | iss1.setf(ios_base::boolalpha); | |
91 | err = ios_base::goodbit; | |
92 | end = ng1.get(iss1.rdbuf(), 0, iss1, err, b1); | |
93 | VERIFY( err == ios_base::eofbit ); | |
94 | VERIFY( b1 == true ); | |
95 | ||
96 | iss1.str("abb"); | |
97 | iss1.clear(); | |
98 | err = ios_base::goodbit; | |
99 | end = ng1.get(iss1.rdbuf(), 0, iss1, err, b1); | |
100 | VERIFY( err == ios_base::goodbit ); | |
101 | VERIFY( b1 == false ); | |
102 | ||
103 | iss1.str("abc"); | |
104 | iss1.clear(); | |
105 | err = ios_base::goodbit; | |
106 | end = ng1.get(iss1.rdbuf(), 0, iss1, err, b1); | |
107 | VERIFY( err == ios_base::failbit ); | |
108 | VERIFY( b1 == false ); | |
109 | VERIFY( *end == 'c' ); | |
110 | ||
2a81fe20 PC |
111 | iss1.str("ab"); |
112 | iss1.clear(); | |
113 | b1 = true; | |
114 | err = ios_base::goodbit; | |
115 | end = ng1.get(iss1.rdbuf(), 0, iss1, err, b1); | |
116 | VERIFY( err == (ios_base::failbit | ios_base::eofbit) ); | |
117 | VERIFY( b1 == false ); | |
118 | ||
894e47e7 PC |
119 | iss2.str("1"); |
120 | iss2.setf(ios_base::boolalpha); | |
121 | err = ios_base::goodbit; | |
122 | end = ng2.get(iss2.rdbuf(), 0, iss2, err, b2); | |
123 | VERIFY( err == ios_base::goodbit ); | |
124 | VERIFY( b2 == true ); | |
125 | ||
7ea6fdf5 PC |
126 | iss2.str("0"); |
127 | iss2.clear(); | |
128 | err = ios_base::goodbit; | |
129 | end = ng2.get(iss2.rdbuf(), 0, iss2, err, b2); | |
130 | VERIFY( err == ios_base::goodbit ); | |
131 | VERIFY( b2 == false ); | |
132 | ||
2a81fe20 PC |
133 | iss2.str("2"); |
134 | iss2.clear(); | |
135 | b2 = true; | |
136 | err = ios_base::goodbit; | |
137 | end = ng2.get(iss2.rdbuf(), 0, iss2, err, b2); | |
138 | VERIFY( err == ios_base::failbit ); | |
139 | VERIFY( b2 == false ); | |
140 | VERIFY( *end == '2' ); | |
141 | ||
894e47e7 PC |
142 | iss3.str("blah"); |
143 | iss3.setf(ios_base::boolalpha); | |
144 | err = ios_base::goodbit; | |
145 | end = ng3.get(iss3.rdbuf(), 0, iss3, err, b3); | |
146 | VERIFY( err == ios_base::failbit ); | |
147 | VERIFY( b3 == false ); | |
148 | VERIFY( *end == 'b' ); | |
7ea6fdf5 PC |
149 | |
150 | iss3.str(""); | |
151 | iss3.clear(); | |
152 | b3 = true; | |
153 | err = ios_base::goodbit; | |
154 | end = ng3.get(iss3.rdbuf(), 0, iss3, err, b3); | |
155 | VERIFY( err == ios_base::failbit ); | |
156 | VERIFY( b3 == false ); | |
2a81fe20 PC |
157 | |
158 | iss4.str("one"); | |
159 | iss4.setf(ios_base::boolalpha); | |
160 | err = ios_base::goodbit; | |
161 | end = ng4.get(iss4.rdbuf(), 0, iss4, err, b4); | |
162 | VERIFY( err == ios_base::goodbit ); | |
163 | VERIFY( b4 == true ); | |
164 | ||
165 | iss4.str("two"); | |
166 | iss4.clear(); | |
167 | err = ios_base::goodbit; | |
168 | end = ng4.get(iss4.rdbuf(), 0, iss4, err, b4); | |
169 | VERIFY( err == ios_base::goodbit ); | |
170 | VERIFY( b4 == false ); | |
171 | ||
172 | iss4.str("three"); | |
173 | iss4.clear(); | |
174 | b4 = true; | |
175 | err = ios_base::goodbit; | |
176 | end = ng4.get(iss4.rdbuf(), 0, iss4, err, b4); | |
177 | VERIFY( err == ios_base::failbit ); | |
178 | VERIFY( b4 == false ); | |
179 | VERIFY( *end == 'h' ); | |
180 | ||
181 | iss4.str("on"); | |
182 | iss4.clear(); | |
183 | b4 = true; | |
184 | err = ios_base::goodbit; | |
185 | end = ng4.get(iss4.rdbuf(), 0, iss4, err, b4); | |
186 | VERIFY( err == (ios_base::failbit | ios_base::eofbit) ); | |
187 | VERIFY( b4 == false ); | |
894e47e7 PC |
188 | } |
189 | ||
190 | int main() | |
191 | { | |
192 | test01(); | |
193 | return 0; | |
194 | } |