| 1 |
// 2009-07-15 Paolo Carlini <[email protected]> |
| 2 |
// |
| 3 |
// Copyright (C) 2009-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 |
// 27.6.1.2.2 arithmetic extractors |
| 21 |
|
| 22 |
#include <sstream> |
| 23 |
#include <limits> |
| 24 |
#include <testsuite_hooks.h> |
| 25 |
|
| 26 |
// DR 696. |
| 27 |
void test01() |
| 28 |
{ |
| 29 |
using namespace std; |
| 30 |
|
| 31 |
short s1 = 0; |
| 32 |
wostringstream oss1; |
| 33 |
oss1 << numeric_limits<short>::max(); |
| 34 |
wistringstream iss1(oss1.str()); |
| 35 |
iss1 >> s1; |
| 36 |
VERIFY( s1 == numeric_limits<short>::max() ); |
| 37 |
VERIFY( !iss1.fail() && iss1.eof() ); |
| 38 |
|
| 39 |
short s2 = 0; |
| 40 |
wostringstream oss2; |
| 41 |
oss2 << static_cast<long long>(numeric_limits<short>::max()) + 1; |
| 42 |
wistringstream iss2(oss2.str()); |
| 43 |
iss2 >> s2; |
| 44 |
VERIFY( s2 == numeric_limits<short>::max() ); |
| 45 |
VERIFY( iss2.fail() && iss2.eof() ); |
| 46 |
|
| 47 |
short s3 = 0; |
| 48 |
wostringstream oss3; |
| 49 |
oss3 << numeric_limits<short>::min(); |
| 50 |
wistringstream iss3(oss3.str()); |
| 51 |
iss3 >> s3; |
| 52 |
VERIFY( s3 == numeric_limits<short>::min() ); |
| 53 |
VERIFY( !iss3.fail() && iss3.eof() ); |
| 54 |
|
| 55 |
short s4 = 0; |
| 56 |
wostringstream oss4; |
| 57 |
oss4 << static_cast<long long>(numeric_limits<short>::min()) - 1; |
| 58 |
wistringstream iss4(oss4.str()); |
| 59 |
iss4 >> s4; |
| 60 |
VERIFY( s4 == numeric_limits<short>::min() ); |
| 61 |
VERIFY( iss4.fail() && iss4.eof() ); |
| 62 |
|
| 63 |
int i1 = 0; |
| 64 |
wostringstream oss5; |
| 65 |
oss5 << numeric_limits<int>::max(); |
| 66 |
wistringstream iss5(oss5.str()); |
| 67 |
iss5 >> i1; |
| 68 |
VERIFY( i1 == numeric_limits<int>::max() ); |
| 69 |
VERIFY( !iss5.fail() && iss5.eof() ); |
| 70 |
|
| 71 |
int i2 = 0; |
| 72 |
wostringstream oss6; |
| 73 |
oss6 << static_cast<long long>(numeric_limits<int>::max()) + 1; |
| 74 |
wistringstream iss6(oss6.str()); |
| 75 |
iss6 >> i2; |
| 76 |
VERIFY( i1 == numeric_limits<int>::max() ); |
| 77 |
VERIFY( iss6.fail() && iss6.eof() ); |
| 78 |
|
| 79 |
int i3 = 0; |
| 80 |
wostringstream oss7; |
| 81 |
oss7 << numeric_limits<int>::min(); |
| 82 |
wistringstream iss7(oss7.str()); |
| 83 |
iss7 >> i3; |
| 84 |
VERIFY( i3 == numeric_limits<int>::min() ); |
| 85 |
VERIFY( !iss7.fail() && iss7.eof() ); |
| 86 |
|
| 87 |
int i4 = 0; |
| 88 |
wostringstream oss8; |
| 89 |
oss8 << static_cast<long long>(numeric_limits<int>::min()) - 1; |
| 90 |
wistringstream iss8(oss8.str()); |
| 91 |
iss8 >> i4; |
| 92 |
VERIFY( i4 == numeric_limits<int>::min() ); |
| 93 |
VERIFY( iss8.fail() && iss8.eof() ); |
| 94 |
} |
| 95 |
|
| 96 |
int main() |
| 97 |
{ |
| 98 |
test01(); |
| 99 |
return 0; |
| 100 |
} |