]>
Commit | Line | Data |
---|---|---|
83ffe9cd | 1 | // Copyright (C) 2004-2023 Free Software Foundation, Inc. |
cfc45d90 PC |
2 | // |
3 | // This file is part of the GNU ISO C++ Library. This library is free | |
4 | // software; you can redistribute it and/or modify it under the | |
5 | // terms of the GNU General Public License as published by the | |
748086b7 | 6 | // Free Software Foundation; either version 3, or (at your option) |
cfc45d90 PC |
7 | // any later version. |
8 | ||
9 | // This library is distributed in the hope that it will be useful, | |
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | // GNU General Public License for more details. | |
13 | ||
14 | // You should have received a copy of the GNU General Public License along | |
748086b7 JJ |
15 | // with this library; see the file COPYING3. If not see |
16 | // <http://www.gnu.org/licenses/>. | |
cfc45d90 PC |
17 | |
18 | // 27.6.1.2.2 arithmetic extractors | |
19 | ||
20 | #include <istream> | |
21 | #include <sstream> | |
22 | #include <locale> | |
23 | #include <testsuite_hooks.h> | |
24 | ||
fd0bf20c | 25 | void test10() |
cfc45d90 PC |
26 | { |
27 | std::wstring str_01(L"0 00 000 +0 +0 -0"); | |
28 | std::wstringbuf isbuf_01(str_01); | |
29 | std::wistream is_01(&isbuf_01); | |
30 | ||
cfc45d90 PC |
31 | int n = 365; |
32 | is_01 >> n; | |
33 | VERIFY( n == 0 ); | |
34 | n = 364; | |
35 | is_01 >> n; | |
36 | VERIFY( n == 0 ); | |
37 | n = 363; | |
38 | is_01 >> n; | |
39 | VERIFY( n == 0 ); | |
40 | n = 362; | |
41 | is_01 >> n; | |
42 | VERIFY( n == 0 ); | |
43 | n = 361; | |
44 | is_01 >> n; | |
45 | VERIFY( n == 0 ); | |
46 | n = 360; | |
47 | is_01 >> n; | |
48 | VERIFY( n == 0 ); | |
49 | VERIFY( is_01.rdstate() == std::ios_base::eofbit ); | |
50 | ||
51 | std::wstring str_02(L"0x32 0X33 033 33"); | |
52 | std::wstringbuf isbuf_02(str_02); | |
53 | std::wistream is_02(&isbuf_02); | |
54 | is_02.unsetf(std::ios_base::basefield); | |
55 | is_02 >> n; | |
56 | VERIFY( n == 50 ); | |
57 | is_02 >> n; | |
58 | VERIFY( n == 51 ); | |
59 | is_02 >> n; | |
60 | VERIFY( n == 27 ); | |
61 | is_02 >> n; | |
62 | VERIFY( n == 33 ); | |
63 | VERIFY( is_02.rdstate() == std::ios_base::eofbit ); | |
64 | ||
65 | std::wstringbuf isbuf_03(str_02); | |
66 | std::wistream is_03(&isbuf_03); | |
67 | wchar_t c; | |
68 | int m; | |
69 | ||
70 | is_03 >> std::dec >> n >> c >> m; | |
71 | VERIFY( n == 0 ); | |
72 | VERIFY( c == L'x' ); | |
73 | VERIFY( m == 32 ); | |
74 | ||
75 | is_03 >> std::oct >> m >> c >> n; | |
76 | VERIFY( m == 0 ); | |
77 | VERIFY( c == L'X' ); | |
78 | VERIFY( n == 27 ); | |
79 | ||
80 | is_03 >> std::dec >> m >> n; | |
81 | VERIFY( m == 33 ); | |
82 | VERIFY( n == 33 ); | |
83 | VERIFY( is_03.rdstate() == std::ios_base::eofbit ); | |
84 | ||
85 | std::wstring str_04(L"3. 4.5E+2a5E-3 .6E1"); | |
86 | std::wstringbuf isbuf_04(str_04); | |
87 | std::wistream is_04(&isbuf_04); | |
88 | ||
89 | double f; | |
90 | is_04 >> f; | |
91 | VERIFY( f == 3.0 ); | |
92 | is_04 >> f; | |
93 | VERIFY( f == 450.0 ); | |
94 | is_04.ignore(); | |
95 | is_04 >> f; | |
96 | VERIFY( f == 0.005 ); | |
97 | is_04 >> f; | |
98 | VERIFY( f == 6 ); | |
99 | VERIFY( is_03.rdstate() == std::ios_base::eofbit ); | |
100 | ||
101 | std::wstring str_05(L"0E20 5Ea E16"); | |
102 | std::wstringbuf isbuf_05(str_05); | |
103 | std::wistream is_05(&isbuf_05); | |
104 | ||
105 | is_05 >> f; | |
106 | VERIFY( f == 0 ); | |
5ef46f95 | 107 | f = 1; |
cfc45d90 | 108 | is_05 >> f; |
5ef46f95 PC |
109 | VERIFY( f == 0 ); |
110 | VERIFY( is_05.rdstate() == std::ios_base::failbit ); | |
cfc45d90 PC |
111 | is_05.clear(); |
112 | is_05 >> c; | |
113 | VERIFY( c == L'a' ); | |
5ef46f95 | 114 | f = 1; |
cfc45d90 | 115 | is_05 >> f; |
5ef46f95 | 116 | VERIFY( f == 0 ); |
cfc45d90 PC |
117 | VERIFY( is_05.rdstate() == std::ios_base::failbit ); |
118 | is_05.clear(); | |
119 | is_05.ignore(); | |
120 | is_05 >> n; | |
121 | VERIFY( n == 16 ); | |
cfc45d90 PC |
122 | } |
123 | ||
124 | int main() | |
125 | { | |
126 | test10(); | |
127 | return 0; | |
128 | } |