3 // Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2009
4 // Free Software Foundation
6 // This file is part of the GNU ISO C++ Library. This library is free
7 // software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the
9 // Free Software Foundation; either version 3, or (at your option)
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License along
18 // with this library; see the file COPYING3. If not see
19 // <http://www.gnu.org/licenses/>.
21 // 27.6.1.2.3 basic_istream::operator>>
25 #include <testsuite_hooks.h>
30 typedef std::ios::traits_type ctraits_type;
32 bool test __attribute__((unused)) = true;
33 const std::string str_01;
34 const std::string str_02("art taylor kickin it on DAKAR");
37 std::stringbuf isbuf_00(std::ios_base::in);
38 std::stringbuf isbuf_01(std::ios_base::in | std::ios_base::out);
39 std::stringbuf isbuf_02(str_01, std::ios_base::in);
40 std::stringbuf isbuf_03(str_01, std::ios_base::in | std::ios_base::out);
41 std::stringbuf isbuf_04(str_02, std::ios_base::in);
42 std::stringbuf isbuf_05(str_02, std::ios_base::in | std::ios_base::out);
44 std::istream is_00(NULL);
45 std::istream is_01(&isbuf_01);
46 std::istream is_02(&isbuf_02);
47 std::istream is_03(&isbuf_03);
48 std::istream is_04(&isbuf_04);
49 std::istream is_05(&isbuf_05);
50 std::ios_base::iostate state1, state2, statefail, stateeof;
51 statefail = std::ios_base::failbit;
52 stateeof = std::ios_base::eofbit;
55 // template<_CharT, _Traits>
56 // basic_istream& operator>>(basic_streambuf*)
58 // null istream to empty in_buf
59 state1 = is_00.rdstate();
61 state2 = is_00.rdstate();
62 VERIFY( state1 != state2 );
63 VERIFY( static_cast<bool>(state2 & statefail) );
64 VERIFY( isbuf_00.str() == str_01 );
66 // null istream to empty in_out_buf
67 is_00.clear(std::ios_base::goodbit);
68 state1 = is_00.rdstate();
70 state2 = is_00.rdstate();
71 VERIFY( state1 != state2 );
72 VERIFY( static_cast<bool>(state2 & statefail) );
73 VERIFY( isbuf_01.str() == str_01 );
75 // null istream to full in_buf
76 is_00.clear(std::ios_base::goodbit);
77 state1 = is_00.rdstate();
79 state2 = is_00.rdstate();
80 VERIFY( state1 != state2 );
81 VERIFY( static_cast<bool>(state2 & statefail) );
82 VERIFY( isbuf_04.str() == str_02 );
84 // null istream to full in_out_buf
85 is_00.clear(std::ios_base::goodbit);
86 state1 = is_00.rdstate();
88 state2 = is_00.rdstate();
89 VERIFY( state1 != state2 );
90 VERIFY( static_cast<bool>(state2 & statefail) );
91 VERIFY( isbuf_05.str() == str_02 );
93 // empty but non-null istream to full in_buf
94 state1 = is_02.rdstate();
96 state2 = is_02.rdstate();
97 VERIFY( state1 != state2 );
98 VERIFY( static_cast<bool>(state2 & statefail) );
99 VERIFY( isbuf_04.str() == str_02 ); // as only an "in" buffer
100 VERIFY( isbuf_04.sgetc() == 'a' );
102 // empty but non-null istream to full in_out_buf
103 is_02.clear(std::ios_base::goodbit);
104 state1 = is_02.rdstate();
106 state2 = is_02.rdstate();
107 VERIFY( state1 != state2 );
108 VERIFY( static_cast<bool>(state2 & statefail) );
109 VERIFY( isbuf_05.str() == str_02 ); // as only an "in" buffer
110 VERIFY( isbuf_05.sgetc() == 'a' );
112 // full istream to empty in_buf (need out_buf, you know?)
113 state1 = is_04.rdstate();
115 state2 = is_04.rdstate();
116 VERIFY( state1 != state2 );
117 VERIFY( static_cast<bool>(state2 & statefail) );
118 VERIFY( isbuf_02.str() == str_01 ); // as only an "in" buffer
119 VERIFY( isbuf_02.sgetc() == ctraits_type::eof() );
120 VERIFY( is_04.peek() == ctraits_type::eof() ); // as failed
122 // full istream to empty in_out_buf
123 is_04.clear(std::ios_base::goodbit);
124 state1 = is_04.rdstate();
126 state2 = is_04.rdstate();
127 VERIFY( state1 != state2 );
128 VERIFY( !static_cast<bool>(state2 & statefail) );
129 VERIFY( state2 == stateeof );
130 strtmp = isbuf_03.str();
131 VERIFY( strtmp == str_02 ); // as only an "in" buffer
132 VERIFY( isbuf_03.sgetc() == 'a' );
133 VERIFY( is_04.peek() == ctraits_type::eof() );