]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/dr696.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 27_io / basic_istream / extractors_arithmetic / char / dr696.cc
1 // 2009-07-15 Paolo Carlini <paolo.carlini@oracle.com>
2 //
3 // Copyright (C) 2009-2022 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 ostringstream oss1;
33 oss1 << numeric_limits<short>::max();
34 istringstream 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 ostringstream oss2;
41 oss2 << static_cast<long long>(numeric_limits<short>::max()) + 1;
42 istringstream 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 ostringstream oss3;
49 oss3 << numeric_limits<short>::min();
50 istringstream 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 ostringstream oss4;
57 oss4 << static_cast<long long>(numeric_limits<short>::min()) - 1;
58 istringstream 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 ostringstream oss5;
65 oss5 << numeric_limits<int>::max();
66 istringstream 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 ostringstream oss6;
73 oss6 << static_cast<long long>(numeric_limits<int>::max()) + 1;
74 istringstream 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 ostringstream oss7;
81 oss7 << numeric_limits<int>::min();
82 istringstream 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 ostringstream oss8;
89 oss8 << static_cast<long long>(numeric_limits<int>::min()) - 1;
90 istringstream 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 }