Debian Codegraph @

libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/10.cc

raw
1 // 1999-04-12 bkoz
2
3 // Copyright (C) 1999-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 <istream>
23 #include <sstream>
24 #include <locale>
25 #include <testsuite_hooks.h>
26
27 void test10()
28 {
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
33 int n = 365;
34 is_01 >> n;
35 VERIFY( n == 0 );
36 n = 364;
37 is_01 >> n;
38 VERIFY( n == 0 );
39 n = 363;
40 is_01 >> n;
41 VERIFY( n == 0 );
42 n = 362;
43 is_01 >> n;
44 VERIFY( n == 0 );
45 n = 361;
46 is_01 >> n;
47 VERIFY( n == 0 );
48 n = 360;
49 is_01 >> n;
50 VERIFY( n == 0 );
51 VERIFY( is_01.rdstate() == std::ios_base::eofbit );
52
53 std::string str_02("0x32 0X33 033 33");
54 std::stringbuf isbuf_02(str_02);
55 std::istream is_02(&isbuf_02);
56 is_02.unsetf(std::ios_base::basefield);
57 is_02 >> n;
58 VERIFY( n == 50 );
59 is_02 >> n;
60 VERIFY( n == 51 );
61 is_02 >> n;
62 VERIFY( n == 27 );
63 is_02 >> n;
64 VERIFY( n == 33 );
65 VERIFY( is_02.rdstate() == std::ios_base::eofbit );
66
67 std::stringbuf isbuf_03(str_02);
68 std::istream is_03(&isbuf_03);
69 char c;
70 int m;
71
72 is_03 >> std::dec >> n >> c >> m;
73 VERIFY( n == 0 );
74 VERIFY( c == 'x' );
75 VERIFY( m == 32 );
76
77 is_03 >> std::oct >> m >> c >> n;
78 VERIFY( m == 0 );
79 VERIFY( c == 'X' );
80 VERIFY( n == 27 );
81
82 is_03 >> std::dec >> m >> n;
83 VERIFY( m == 33 );
84 VERIFY( n == 33 );
85 VERIFY( is_03.rdstate() == std::ios_base::eofbit );
86
87 std::string str_04("3. 4.5E+2a5E-3 .6E1");
88 std::stringbuf isbuf_04(str_04);
89 std::istream is_04(&isbuf_04);
90
91 double f;
92 is_04 >> f;
93 VERIFY( f == 3.0 );
94 is_04 >> f;
95 VERIFY( f == 450.0 );
96 is_04.ignore();
97 is_04 >> f;
98 VERIFY( f == (double) 0.005 ); // N.B. cast removes excess precision
99 is_04 >> f;
100 VERIFY( f == 6 );
101 VERIFY( is_03.rdstate() == std::ios_base::eofbit );
102
103 std::string str_05("0E20 5Ea E16");
104 std::stringbuf isbuf_05(str_05);
105 std::istream is_05(&isbuf_05);
106
107 is_05 >> f;
108 VERIFY( f == 0 );
109 f = 1;
110 is_05 >> f;
111 VERIFY( f == 0 );
112 VERIFY( is_05.rdstate() == std::ios_base::failbit );
113 is_05.clear();
114 is_05 >> c;
115 VERIFY( c == 'a' );
116 f = 1;
117 is_05 >> f;
118 VERIFY( f == 0 );
119 VERIFY( is_05.rdstate() == std::ios_base::failbit );
120 is_05.clear();
121 is_05.ignore();
122 is_05 >> n;
123 VERIFY( n == 16 );
124 }
125
126 int main()
127 {
128 test10();
129 return 0;
130 }