1// 2009-07-15 Paolo Carlini <paolo.carlini@oracle.com> 2// 3// Copyright (C) 2009-2015 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. 27void test01() 28{ 29 using namespace std; 30 bool test __attribute__((unused)) = true; 31 32 short s1 = 0; 33 ostringstream oss1; 34 oss1 << numeric_limits<short>::max(); 35 istringstream iss1(oss1.str()); 36 iss1 >> s1; 37 VERIFY( s1 == numeric_limits<short>::max() ); 38 VERIFY( !iss1.fail() && iss1.eof() ); 39 40 short s2 = 0; 41 ostringstream oss2; 42 oss2 << static_cast<long long>(numeric_limits<short>::max()) + 1; 43 istringstream iss2(oss2.str()); 44 iss2 >> s2; 45 VERIFY( s2 == numeric_limits<short>::max() ); 46 VERIFY( iss2.fail() && iss2.eof() ); 47 48 short s3 = 0; 49 ostringstream oss3; 50 oss3 << numeric_limits<short>::min(); 51 istringstream iss3(oss3.str()); 52 iss3 >> s3; 53 VERIFY( s3 == numeric_limits<short>::min() ); 54 VERIFY( !iss3.fail() && iss3.eof() ); 55 56 short s4 = 0; 57 ostringstream oss4; 58 oss4 << static_cast<long long>(numeric_limits<short>::min()) - 1; 59 istringstream iss4(oss4.str()); 60 iss4 >> s4; 61 VERIFY( s4 == numeric_limits<short>::min() ); 62 VERIFY( iss4.fail() && iss4.eof() ); 63 64 int i1 = 0; 65 ostringstream oss5; 66 oss5 << numeric_limits<int>::max(); 67 istringstream iss5(oss5.str()); 68 iss5 >> i1; 69 VERIFY( i1 == numeric_limits<int>::max() ); 70 VERIFY( !iss5.fail() && iss5.eof() ); 71 72 int i2 = 0; 73 ostringstream oss6; 74 oss6 << static_cast<long long>(numeric_limits<int>::max()) + 1; 75 istringstream iss6(oss6.str()); 76 iss6 >> i2; 77 VERIFY( i1 == numeric_limits<int>::max() ); 78 VERIFY( iss6.fail() && iss6.eof() ); 79 80 int i3 = 0; 81 ostringstream oss7; 82 oss7 << numeric_limits<int>::min(); 83 istringstream iss7(oss7.str()); 84 iss7 >> i3; 85 VERIFY( i3 == numeric_limits<int>::min() ); 86 VERIFY( !iss7.fail() && iss7.eof() ); 87 88 int i4 = 0; 89 ostringstream oss8; 90 oss8 << static_cast<long long>(numeric_limits<int>::min()) - 1; 91 istringstream iss8(oss8.str()); 92 iss8 >> i4; 93 VERIFY( i4 == numeric_limits<int>::min() ); 94 VERIFY( iss8.fail() && iss8.eof() ); 95} 96 97int main() 98{ 99 test01(); 100 return 0; 101} 102