| 1 |
// 2001-11-21 Benjamin Kosnik <[email protected]> |
| 2 |
|
| 3 |
// Copyright (C) 2001-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 |
// { dg-do run { xfail lax_strtofp } } |
| 23 |
|
| 24 |
#include <locale> |
| 25 |
#include <sstream> |
| 26 |
#include <testsuite_hooks.h> |
| 27 |
|
| 28 |
void test02() |
| 29 |
{ |
| 30 |
using namespace std; |
| 31 |
typedef istreambuf_iterator<char> iterator_type; |
| 32 |
|
| 33 |
// basic construction |
| 34 |
locale loc_c = locale::classic(); |
| 35 |
|
| 36 |
// sanity check the data is correct. |
| 37 |
const string empty; |
| 38 |
|
| 39 |
bool b1 = true; |
| 40 |
bool b0 = false; |
| 41 |
unsigned long ul1 = 1294967294; |
| 42 |
unsigned long ul2 = 0; |
| 43 |
unsigned long ul; |
| 44 |
double d1 = 1.02345e+308; |
| 45 |
double d2 = 3.15e-308; |
| 46 |
double d; |
| 47 |
|
| 48 |
// cache the num_get facet |
| 49 |
istringstream iss; |
| 50 |
iss.imbue(loc_c); |
| 51 |
const num_get<char>& ng = use_facet<num_get<char> >(iss.getloc()); |
| 52 |
const ios_base::iostate goodbit = ios_base::goodbit; |
| 53 |
const ios_base::iostate eofbit = ios_base::eofbit; |
| 54 |
ios_base::iostate err = ios_base::goodbit; |
| 55 |
|
| 56 |
// C |
| 57 |
// bool, more twisted examples |
| 58 |
iss.str("true "); |
| 59 |
iss.clear(); |
| 60 |
iss.setf(ios_base::boolalpha); |
| 61 |
err = goodbit; |
| 62 |
ng.get(iss.rdbuf(), 0, iss, err, b0); |
| 63 |
VERIFY( b0 == true ); |
| 64 |
VERIFY( err == goodbit ); |
| 65 |
|
| 66 |
iss.str("false "); |
| 67 |
iss.clear(); |
| 68 |
iss.setf(ios_base::boolalpha); |
| 69 |
err = goodbit; |
| 70 |
ng.get(iss.rdbuf(), 0, iss, err, b1); |
| 71 |
VERIFY( b1 == false ); |
| 72 |
VERIFY( err == goodbit ); |
| 73 |
|
| 74 |
// unsigned long, in a locale that does not group |
| 75 |
iss.imbue(loc_c); |
| 76 |
iss.str("1294967294"); |
| 77 |
iss.clear(); |
| 78 |
err = goodbit; |
| 79 |
ng.get(iss.rdbuf(), 0, iss, err, ul); |
| 80 |
VERIFY( ul == ul1); |
| 81 |
VERIFY( err == eofbit ); |
| 82 |
|
| 83 |
iss.str("0+++++++++++++++++++"); |
| 84 |
iss.clear(); |
| 85 |
err = goodbit; |
| 86 |
ng.get(iss.rdbuf(), 0, iss, err, ul); |
| 87 |
VERIFY( ul == ul2); |
| 88 |
VERIFY( err == goodbit ); |
| 89 |
|
| 90 |
// double |
| 91 |
iss.imbue(loc_c); |
| 92 |
iss.str("1.02345e+308++++++++"); |
| 93 |
iss.clear(); |
| 94 |
iss.width(20); |
| 95 |
iss.setf(ios_base::left, ios_base::adjustfield); |
| 96 |
err = goodbit; |
| 97 |
ng.get(iss.rdbuf(), 0, iss, err, d); |
| 98 |
VERIFY( d == d1 ); |
| 99 |
VERIFY( err == goodbit ); |
| 100 |
|
| 101 |
iss.str("+3.15e-308"); |
| 102 |
iss.clear(); |
| 103 |
iss.width(20); |
| 104 |
iss.setf(ios_base::right, ios_base::adjustfield); |
| 105 |
err = goodbit; |
| 106 |
ng.get(iss.rdbuf(), 0, iss, err, d); |
| 107 |
VERIFY( d == d2 ); |
| 108 |
VERIFY( err == eofbit ); |
| 109 |
} |
| 110 |
|
| 111 |
int main() |
| 112 |
{ |
| 113 |
test02(); |
| 114 |
return 0; |
| 115 |
} |
| 116 |
|
| 117 |
|
| 118 |
// Kathleen Hannah, humanitarian, woman, art-thief |