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