]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/10.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 27_io / basic_istream / extractors_arithmetic / char / 10.cc
CommitLineData
6e1fc5ee 1// 1999-04-12 bkoz
2
f1717362 3// Copyright (C) 1999-2016 Free Software Foundation, Inc.
6e1fc5ee 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
6bc9506f 8// Free Software Foundation; either version 3, or (at your option)
6e1fc5ee 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
6bc9506f 17// with this library; see the file COPYING3. If not see
18// <http://www.gnu.org/licenses/>.
6e1fc5ee 19
20// 27.6.1.2.2 arithmetic extractors
21
6e1fc5ee 22#include <istream>
6e1fc5ee 23#include <sstream>
24#include <locale>
25#include <testsuite_hooks.h>
26
4914bf31 27bool test10()
28{
6e1fc5ee 29 std::string str_01("0 00 000 +0 +0 -0");
30 std::stringbuf isbuf_01(str_01);
31 std::istream is_01(&isbuf_01);
32
f8ef786c 33 bool test __attribute__((unused)) = true;
6e1fc5ee 34
35 int n = 365;
36 is_01 >> n;
37 VERIFY( n == 0 );
38 n = 364;
39 is_01 >> n;
40 VERIFY( n == 0 );
41 n = 363;
42 is_01 >> n;
43 VERIFY( n == 0 );
44 n = 362;
45 is_01 >> n;
46 VERIFY( n == 0 );
47 n = 361;
48 is_01 >> n;
49 VERIFY( n == 0 );
50 n = 360;
51 is_01 >> n;
52 VERIFY( n == 0 );
53 VERIFY( is_01.rdstate() == std::ios_base::eofbit );
54
55 std::string str_02("0x32 0X33 033 33");
56 std::stringbuf isbuf_02(str_02);
57 std::istream is_02(&isbuf_02);
58 is_02.unsetf(std::ios_base::basefield);
59 is_02 >> n;
60 VERIFY( n == 50 );
61 is_02 >> n;
62 VERIFY( n == 51 );
63 is_02 >> n;
64 VERIFY( n == 27 );
65 is_02 >> n;
66 VERIFY( n == 33 );
67 VERIFY( is_02.rdstate() == std::ios_base::eofbit );
68
69 std::stringbuf isbuf_03(str_02);
70 std::istream is_03(&isbuf_03);
71 char c;
72 int m;
73
74 is_03 >> std::dec >> n >> c >> m;
75 VERIFY( n == 0 );
76 VERIFY( c == 'x' );
77 VERIFY( m == 32 );
78
79 is_03 >> std::oct >> m >> c >> n;
80 VERIFY( m == 0 );
81 VERIFY( c == 'X' );
82 VERIFY( n == 27 );
83
84 is_03 >> std::dec >> m >> n;
85 VERIFY( m == 33 );
86 VERIFY( n == 33 );
87 VERIFY( is_03.rdstate() == std::ios_base::eofbit );
88
89 std::string str_04("3. 4.5E+2a5E-3 .6E1");
90 std::stringbuf isbuf_04(str_04);
91 std::istream is_04(&isbuf_04);
92
93 double f;
94 is_04 >> f;
95 VERIFY( f == 3.0 );
96 is_04 >> f;
97 VERIFY( f == 450.0 );
98 is_04.ignore();
99 is_04 >> f;
100 VERIFY( f == 0.005 );
101 is_04 >> f;
102 VERIFY( f == 6 );
103 VERIFY( is_03.rdstate() == std::ios_base::eofbit );
104
105 std::string str_05("0E20 5Ea E16");
106 std::stringbuf isbuf_05(str_05);
107 std::istream is_05(&isbuf_05);
108
109 is_05 >> f;
110 VERIFY( f == 0 );
7c23b837 111 f = 1;
6e1fc5ee 112 is_05 >> f;
7c23b837 113 VERIFY( f == 0 );
114 VERIFY( is_05.rdstate() == std::ios_base::failbit );
6e1fc5ee 115 is_05.clear();
116 is_05 >> c;
117 VERIFY( c == 'a' );
7c23b837 118 f = 1;
6e1fc5ee 119 is_05 >> f;
7c23b837 120 VERIFY( f == 0 );
6e1fc5ee 121 VERIFY( is_05.rdstate() == std::ios_base::failbit );
122 is_05.clear();
123 is_05.ignore();
124 is_05 >> n;
125 VERIFY( n == 16 );
6e1fc5ee 126 return test;
127}
128
129int main()
130{
131 test10();
132 return 0;
133}