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