]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/07.cc
3 // Copyright (C) 1999-2022 Free Software Foundation, Inc.
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
8 // Free Software Foundation; either version 3, or (at your option)
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.
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING3. If not see
18 // <http://www.gnu.org/licenses/>.
20 // 27.6.1.2.2 arithmetic extractors
25 #include <testsuite_hooks.h>
28 class test_numpunct1
: public numpunct
<char>
33 { return string(1, '\003'); }
39 // manufactured locale, grouping is turned on
40 unsigned int h4
= 0, h3
= 0, h2
= 0;
42 const std::string
s1("205,199 23,445.25 1,024,365 123,22,24");
43 std::istringstream
is(s1
);
44 is
.imbue(std::locale(std::locale(), new std::test_numpunct1
));
48 VERIFY( h4
== 205199 );
53 VERIFY( f1
== 23445.25 );
58 VERIFY( h3
== 1024365 );
63 VERIFY( h2
== 1232224 );
64 VERIFY( static_cast<bool>(is
.rdstate() & std::ios_base::failbit
) );
65 VERIFY( static_cast<bool>(is
.rdstate() & std::ios_base::eofbit
) );
67 // Stress tests for explicit errors in grouping corner cases. The
68 // validity of these tests and results have been hammered out in
69 // private email between bkoz and ncm between Jan 25 and Jan 27, 2000.
70 // Thanks nate -- benjamin
71 const std::string
s2(",111 4,,4 0.25,345 5..25 156,, 1,000000 1000000 1234,567");
74 const char c_control
= '?';
81 VERIFY( static_cast<bool>(is
.rdstate() & std::ios_base::failbit
) );
90 VERIFY( static_cast<bool>(is
.rdstate() & std::ios_base::failbit
) );
118 VERIFY( static_cast<bool>(is
.rdstate() & std::ios_base::failbit
) );
121 VERIFY( c
== ',' ); // second one
125 VERIFY( h2
== 1000000 );
126 VERIFY( static_cast<bool>(is
.rdstate() & std::ios_base::failbit
) );
131 VERIFY( h2
== 1000000 );
136 VERIFY( h2
== 1234567 );
137 VERIFY( static_cast<bool>(is
.rdstate() & std::ios_base::failbit
) );
138 VERIFY( static_cast<bool>(is
.rdstate() & std::ios_base::eofbit
) );