]>
Commit | Line | Data |
---|---|---|
a5544970 | 1 | // Copyright (C) 2004-2019 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.3 basic_istream::operator>> | |
19 | ||
20 | #include <istream> | |
21 | #include <sstream> | |
22 | #include <testsuite_hooks.h> | |
23 | ||
24 | // stringbufs. | |
25 | void test01() | |
26 | { | |
27 | typedef std::wios::traits_type ctraits_type; | |
28 | ||
cfc45d90 PC |
29 | const std::wstring str_01; |
30 | const std::wstring str_02(L"art taylor kickin it on DAKAR"); | |
31 | std::wstring strtmp; | |
32 | ||
33 | std::wstringbuf isbuf_00(std::ios_base::in); | |
34 | std::wstringbuf isbuf_01(std::ios_base::in | std::ios_base::out); | |
35 | std::wstringbuf isbuf_02(str_01, std::ios_base::in); | |
36 | std::wstringbuf isbuf_03(str_01, std::ios_base::in | std::ios_base::out); | |
37 | std::wstringbuf isbuf_04(str_02, std::ios_base::in); | |
38 | std::wstringbuf isbuf_05(str_02, std::ios_base::in | std::ios_base::out); | |
39 | ||
8fc81078 | 40 | std::wistream is_00(0); |
cfc45d90 PC |
41 | std::wistream is_01(&isbuf_01); |
42 | std::wistream is_02(&isbuf_02); | |
43 | std::wistream is_03(&isbuf_03); | |
44 | std::wistream is_04(&isbuf_04); | |
45 | std::wistream is_05(&isbuf_05); | |
46 | std::ios_base::iostate state1, state2, statefail, stateeof; | |
47 | statefail = std::ios_base::failbit; | |
48 | stateeof = std::ios_base::eofbit; | |
49 | ||
50 | ||
51 | // template<_CharT, _Traits> | |
52 | // basic_istream& operator>>(basic_streambuf*) | |
53 | ||
54 | // null istream to empty in_buf | |
55 | state1 = is_00.rdstate(); | |
56 | is_00 >> &isbuf_00; | |
57 | state2 = is_00.rdstate(); | |
58 | VERIFY( state1 != state2 ); | |
59 | VERIFY( static_cast<bool>(state2 & statefail) ); | |
60 | VERIFY( isbuf_00.str() == str_01 ); | |
61 | ||
62 | // null istream to empty in_out_buf | |
63 | is_00.clear(std::ios_base::goodbit); | |
64 | state1 = is_00.rdstate(); | |
65 | is_00 >> &isbuf_01; | |
66 | state2 = is_00.rdstate(); | |
67 | VERIFY( state1 != state2 ); | |
68 | VERIFY( static_cast<bool>(state2 & statefail) ); | |
69 | VERIFY( isbuf_01.str() == str_01 ); | |
70 | ||
71 | // null istream to full in_buf | |
72 | is_00.clear(std::ios_base::goodbit); | |
73 | state1 = is_00.rdstate(); | |
74 | is_00 >> &isbuf_04; | |
75 | state2 = is_00.rdstate(); | |
76 | VERIFY( state1 != state2 ); | |
77 | VERIFY( static_cast<bool>(state2 & statefail) ); | |
78 | VERIFY( isbuf_04.str() == str_02 ); | |
79 | ||
80 | // null istream to full in_out_buf | |
81 | is_00.clear(std::ios_base::goodbit); | |
82 | state1 = is_00.rdstate(); | |
83 | is_00 >> &isbuf_05; | |
84 | state2 = is_00.rdstate(); | |
85 | VERIFY( state1 != state2 ); | |
86 | VERIFY( static_cast<bool>(state2 & statefail) ); | |
87 | VERIFY( isbuf_05.str() == str_02 ); | |
88 | ||
89 | // empty but non-null istream to full in_buf | |
90 | state1 = is_02.rdstate(); | |
91 | is_02 >> &isbuf_04; | |
92 | state2 = is_02.rdstate(); | |
93 | VERIFY( state1 != state2 ); | |
94 | VERIFY( static_cast<bool>(state2 & statefail) ); | |
95 | VERIFY( isbuf_04.str() == str_02 ); // as only an "in" buffer | |
96 | VERIFY( isbuf_04.sgetc() == L'a' ); | |
97 | ||
98 | // empty but non-null istream to full in_out_buf | |
99 | is_02.clear(std::ios_base::goodbit); | |
100 | state1 = is_02.rdstate(); | |
101 | is_02 >> &isbuf_05; | |
102 | state2 = is_02.rdstate(); | |
103 | VERIFY( state1 != state2 ); | |
104 | VERIFY( static_cast<bool>(state2 & statefail) ); | |
105 | VERIFY( isbuf_05.str() == str_02 ); // as only an "in" buffer | |
106 | VERIFY( isbuf_05.sgetc() == L'a' ); | |
107 | ||
108 | // full istream to empty in_buf (need out_buf, you know?) | |
109 | state1 = is_04.rdstate(); | |
110 | is_04 >> &isbuf_02; | |
111 | state2 = is_04.rdstate(); | |
112 | VERIFY( state1 != state2 ); | |
113 | VERIFY( static_cast<bool>(state2 & statefail) ); | |
114 | VERIFY( isbuf_02.str() == str_01 ); // as only an "in" buffer | |
115 | VERIFY( isbuf_02.sgetc() == ctraits_type::eof() ); | |
116 | VERIFY( is_04.peek() == ctraits_type::eof() ); // as failed | |
117 | ||
118 | // full istream to empty in_out_buf | |
119 | is_04.clear(std::ios_base::goodbit); | |
120 | state1 = is_04.rdstate(); | |
121 | is_04 >> &isbuf_03; | |
122 | state2 = is_04.rdstate(); | |
6f4d3d86 | 123 | VERIFY( state1 != state2 ); |
cfc45d90 | 124 | VERIFY( !static_cast<bool>(state2 & statefail) ); |
6f4d3d86 | 125 | VERIFY( state2 == stateeof ); |
cfc45d90 PC |
126 | strtmp = isbuf_03.str(); |
127 | VERIFY( strtmp == str_02 ); // as only an "in" buffer | |
128 | VERIFY( isbuf_03.sgetc() == L'a' ); | |
129 | VERIFY( is_04.peek() == ctraits_type::eof() ); | |
130 | } | |
131 | ||
132 | int main() | |
133 | { | |
134 | test01(); | |
135 | return 0; | |
136 | } |