]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/22_locale/num_get/get/char/37958.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 22_locale / num_get / get / char / 37958.cc
CommitLineData
a74f2daa 1// 2008-10-31 Paolo Carlini <paolo.carlini@oracle.com>
2
f1717362 3// Copyright (C) 2008-2016 Free Software Foundation, Inc.
a74f2daa 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
6bc9506f 8// Free Software Foundation; either version 3, or (at your option)
a74f2daa 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
6bc9506f 17// with this library; see the file COPYING3. If not see
18// <http://www.gnu.org/licenses/>.
a74f2daa 19
20// 22.2.2.1.1 num_get members
21
22#include <locale>
23#include <sstream>
24#include <testsuite_hooks.h>
25
26struct Punct1: std::numpunct<char>
27{
28 std::string do_truename() const { return "a"; }
29 std::string do_falsename() const { return "abb"; }
30};
31
32struct Punct2: std::numpunct<char>
33{
34 std::string do_truename() const { return "1"; }
35 std::string do_falsename() const { return "0"; }
36};
37
38struct Punct3: std::numpunct<char>
39{
40 std::string do_truename() const { return ""; }
41 std::string do_falsename() const { return ""; }
42};
43
a8940b84 44struct Punct4: std::numpunct<char>
45{
46 std::string do_truename() const { return "one"; }
47 std::string do_falsename() const { return "two"; }
48};
49
a74f2daa 50// libstdc++/37958
51void test01()
52{
53 using namespace std;
54 typedef istreambuf_iterator<char> iterator_type;
55
56 bool test __attribute__((unused)) = true;
57
a8940b84 58 istringstream iss0, iss1, iss2, iss3, iss4;
a74f2daa 59 iss1.imbue(locale(iss1.getloc(), new Punct1));
60 iss2.imbue(locale(iss2.getloc(), new Punct2));
61 iss3.imbue(locale(iss3.getloc(), new Punct3));
a8940b84 62 iss4.imbue(locale(iss4.getloc(), new Punct4));
5e8de854 63 const num_get<char>& ng0 = use_facet<num_get<char> >(iss0.getloc());
a74f2daa 64 const num_get<char>& ng1 = use_facet<num_get<char> >(iss1.getloc());
65 const num_get<char>& ng2 = use_facet<num_get<char> >(iss2.getloc());
66 const num_get<char>& ng3 = use_facet<num_get<char> >(iss3.getloc());
a8940b84 67 const num_get<char>& ng4 = use_facet<num_get<char> >(iss4.getloc());
a74f2daa 68
69 ios_base::iostate err = ios_base::goodbit;
70 iterator_type end;
5e8de854 71 bool b0 = false;
a74f2daa 72 bool b1 = false;
73 bool b2 = false;
74 bool b3 = true;
a8940b84 75 bool b4 = false;
a74f2daa 76
5e8de854 77 iss0.str("true");
78 iss0.setf(ios_base::boolalpha);
79 err = ios_base::goodbit;
80 end = ng0.get(iss0.rdbuf(), 0, iss0, err, b0);
81 VERIFY( err == ios_base::goodbit );
82 VERIFY( b0 == true );
83
84 iss0.str("false");
85 iss0.clear();
86 err = ios_base::goodbit;
87 end = ng0.get(iss0.rdbuf(), 0, iss0, err, b0);
88 VERIFY( err == ios_base::goodbit );
89 VERIFY( b0 == false );
90
a74f2daa 91 iss1.str("a");
92 iss1.setf(ios_base::boolalpha);
93 err = ios_base::goodbit;
94 end = ng1.get(iss1.rdbuf(), 0, iss1, err, b1);
95 VERIFY( err == ios_base::eofbit );
96 VERIFY( b1 == true );
97
98 iss1.str("abb");
99 iss1.clear();
100 err = ios_base::goodbit;
101 end = ng1.get(iss1.rdbuf(), 0, iss1, err, b1);
102 VERIFY( err == ios_base::goodbit );
103 VERIFY( b1 == false );
104
105 iss1.str("abc");
106 iss1.clear();
107 err = ios_base::goodbit;
108 end = ng1.get(iss1.rdbuf(), 0, iss1, err, b1);
109 VERIFY( err == ios_base::failbit );
110 VERIFY( b1 == false );
111 VERIFY( *end == 'c' );
112
a8940b84 113 iss1.str("ab");
114 iss1.clear();
115 b1 = true;
116 err = ios_base::goodbit;
117 end = ng1.get(iss1.rdbuf(), 0, iss1, err, b1);
118 VERIFY( err == (ios_base::failbit | ios_base::eofbit) );
119 VERIFY( b1 == false );
120
a74f2daa 121 iss2.str("1");
122 iss2.setf(ios_base::boolalpha);
123 err = ios_base::goodbit;
124 end = ng2.get(iss2.rdbuf(), 0, iss2, err, b2);
125 VERIFY( err == ios_base::goodbit );
126 VERIFY( b2 == true );
127
5e8de854 128 iss2.str("0");
129 iss2.clear();
130 err = ios_base::goodbit;
131 end = ng2.get(iss2.rdbuf(), 0, iss2, err, b2);
132 VERIFY( err == ios_base::goodbit );
133 VERIFY( b2 == false );
134
a8940b84 135 iss2.str("2");
136 iss2.clear();
137 b2 = true;
138 err = ios_base::goodbit;
139 end = ng2.get(iss2.rdbuf(), 0, iss2, err, b2);
140 VERIFY( err == ios_base::failbit );
141 VERIFY( b2 == false );
142 VERIFY( *end == '2' );
143
a74f2daa 144 iss3.str("blah");
145 iss3.setf(ios_base::boolalpha);
146 err = ios_base::goodbit;
147 end = ng3.get(iss3.rdbuf(), 0, iss3, err, b3);
148 VERIFY( err == ios_base::failbit );
149 VERIFY( b3 == false );
150 VERIFY( *end == 'b' );
5e8de854 151
152 iss3.str("");
153 iss3.clear();
154 b3 = true;
155 err = ios_base::goodbit;
156 end = ng3.get(iss3.rdbuf(), 0, iss3, err, b3);
157 VERIFY( err == ios_base::failbit );
158 VERIFY( b3 == false );
a8940b84 159
160 iss4.str("one");
161 iss4.setf(ios_base::boolalpha);
162 err = ios_base::goodbit;
163 end = ng4.get(iss4.rdbuf(), 0, iss4, err, b4);
164 VERIFY( err == ios_base::goodbit );
165 VERIFY( b4 == true );
166
167 iss4.str("two");
168 iss4.clear();
169 err = ios_base::goodbit;
170 end = ng4.get(iss4.rdbuf(), 0, iss4, err, b4);
171 VERIFY( err == ios_base::goodbit );
172 VERIFY( b4 == false );
173
174 iss4.str("three");
175 iss4.clear();
176 b4 = true;
177 err = ios_base::goodbit;
178 end = ng4.get(iss4.rdbuf(), 0, iss4, err, b4);
179 VERIFY( err == ios_base::failbit );
180 VERIFY( b4 == false );
181 VERIFY( *end == 'h' );
182
183 iss4.str("on");
184 iss4.clear();
185 b4 = true;
186 err = ios_base::goodbit;
187 end = ng4.get(iss4.rdbuf(), 0, iss4, err, b4);
188 VERIFY( err == (ios_base::failbit | ios_base::eofbit) );
189 VERIFY( b4 == false );
a74f2daa 190}
191
192int main()
193{
194 test01();
195 return 0;
196}