| 1 |
// 2005-06-28 Paolo Carlini <[email protected]> |
| 2 |
|
| 3 |
// Copyright (C) 2005-2025 Free Software Foundation, Inc. |
| 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 |
| 8 |
// Free Software Foundation; either version 3, or (at your option) |
| 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 |
| 17 |
// with this library; see the file COPYING3. If not see |
| 18 |
// <http://www.gnu.org/licenses/>. |
| 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 Punct: std::numpunct<char> |
| 27 |
{ |
| 28 |
std::string do_grouping() const { return "\1"; } |
| 29 |
char do_thousands_sep() const { return '#'; } |
| 30 |
}; |
| 31 |
|
| 32 |
// libstdc++/22131 |
| 33 |
void test01() |
| 34 |
{ |
| 35 |
using namespace std; |
| 36 |
typedef istreambuf_iterator<char> iterator_type; |
| 37 |
|
| 38 |
istringstream iss1, iss2; |
| 39 |
iss1.imbue(locale(iss1.getloc(), new Punct)); |
| 40 |
const num_get<char>& ng1 = use_facet<num_get<char> >(iss1.getloc()); |
| 41 |
|
| 42 |
ios_base::iostate err = ios_base::goodbit; |
| 43 |
iterator_type end; |
| 44 |
long l = 0l; |
| 45 |
long l1 = 1l; |
| 46 |
long l2 = 2l; |
| 47 |
long l3 = 3l; |
| 48 |
double d = 0.0; |
| 49 |
double d1 = 1.0; |
| 50 |
double d2 = 2.0; |
| 51 |
|
| 52 |
iss1.str("00#0#1"); |
| 53 |
err = ios_base::goodbit; |
| 54 |
end = ng1.get(iss1.rdbuf(), 0, iss1, err, l); |
| 55 |
VERIFY( err == (ios_base::eofbit | ios_base::failbit) ); |
| 56 |
VERIFY( l == l1 ); |
| 57 |
|
| 58 |
iss1.str("000##2"); |
| 59 |
iss1.clear(); |
| 60 |
err = ios_base::goodbit; |
| 61 |
end = ng1.get(iss1.rdbuf(), 0, iss1, err, l); |
| 62 |
VERIFY( err == ios_base::failbit ); |
| 63 |
VERIFY( *end == '#' ); |
| 64 |
VERIFY( l == 0 ); |
| 65 |
|
| 66 |
iss1.str("0#0#0#2"); |
| 67 |
iss1.clear(); |
| 68 |
err = ios_base::goodbit; |
| 69 |
end = ng1.get(iss1.rdbuf(), 0, iss1, err, l); |
| 70 |
VERIFY( err == ios_base::eofbit ); |
| 71 |
VERIFY( l == l2 ); |
| 72 |
|
| 73 |
iss1.str("00#0#1"); |
| 74 |
iss1.clear(); |
| 75 |
err = ios_base::goodbit; |
| 76 |
end = ng1.get(iss1.rdbuf(), 0, iss1, err, d); |
| 77 |
VERIFY( err == (ios_base::eofbit | ios_base::failbit) ); |
| 78 |
VERIFY( d == d1 ); |
| 79 |
|
| 80 |
iss1.str("000##2"); |
| 81 |
iss1.clear(); |
| 82 |
err = ios_base::goodbit; |
| 83 |
end = ng1.get(iss1.rdbuf(), 0, iss1, err, d); |
| 84 |
VERIFY( err == ios_base::failbit ); |
| 85 |
VERIFY( *end == '#' ); |
| 86 |
VERIFY( d == 0.0 ); |
| 87 |
|
| 88 |
iss1.str("0#0#0#2"); |
| 89 |
iss1.clear(); |
| 90 |
err = ios_base::goodbit; |
| 91 |
end = ng1.get(iss1.rdbuf(), 0, iss1, err, d); |
| 92 |
VERIFY( err == ios_base::eofbit ); |
| 93 |
VERIFY( d == d2 ); |
| 94 |
|
| 95 |
iss1.str("0#0"); |
| 96 |
iss1.clear(); |
| 97 |
iss1.unsetf(ios::basefield); |
| 98 |
err = ios_base::goodbit; |
| 99 |
end = ng1.get(iss1.rdbuf(), 0, iss1, err, l); |
| 100 |
VERIFY( err == ios_base::failbit ); |
| 101 |
VERIFY( *end == '#' ); |
| 102 |
VERIFY( l == 0 ); |
| 103 |
|
| 104 |
iss1.str("00#0#3"); |
| 105 |
iss1.clear(); |
| 106 |
err = ios_base::goodbit; |
| 107 |
end = ng1.get(iss1.rdbuf(), 0, iss1, err, l); |
| 108 |
VERIFY( err == ios_base::eofbit ); |
| 109 |
VERIFY( l == l3 ); |
| 110 |
|
| 111 |
iss1.str("00#02"); |
| 112 |
iss1.clear(); |
| 113 |
err = ios_base::goodbit; |
| 114 |
end = ng1.get(iss1.rdbuf(), 0, iss1, err, l); |
| 115 |
VERIFY( err == (ios_base::eofbit | ios_base::failbit) ); |
| 116 |
VERIFY( l == l2 ); |
| 117 |
} |
| 118 |
|
| 119 |
int main() |
| 120 |
{ |
| 121 |
test01(); |
| 122 |
return 0; |
| 123 |
} |