Merged trunk at revision 161680 into branch.
[official-gcc.git] / libstdc++-v3 / testsuite / 27_io / basic_istream / extractors_other / char / 1.cc
blob854dc7c856586d374a53ac3bfc6be66bc16c2fe5
1 // 1999-07-28 bkoz
3 // Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
4 // 2009, 2010
5 // Free Software Foundation
6 //
7 // This file is part of the GNU ISO C++ Library. This library is free
8 // software; you can redistribute it and/or modify it under the
9 // terms of the GNU General Public License as published by the
10 // Free Software Foundation; either version 3, or (at your option)
11 // any later version.
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License along
19 // with this library; see the file COPYING3. If not see
20 // <http://www.gnu.org/licenses/>.
22 // 27.6.1.2.3 basic_istream::operator>>
24 #include <istream>
25 #include <sstream>
26 #include <testsuite_hooks.h>
28 // stringbufs.
29 void test01()
31 typedef std::ios::traits_type ctraits_type;
33 bool test __attribute__((unused)) = true;
34 const std::string str_01;
35 const std::string str_02("art taylor kickin it on DAKAR");
36 std::string strtmp;
38 std::stringbuf isbuf_00(std::ios_base::in);
39 std::stringbuf isbuf_01(std::ios_base::in | std::ios_base::out);
40 std::stringbuf isbuf_02(str_01, std::ios_base::in);
41 std::stringbuf isbuf_03(str_01, std::ios_base::in | std::ios_base::out);
42 std::stringbuf isbuf_04(str_02, std::ios_base::in);
43 std::stringbuf isbuf_05(str_02, std::ios_base::in | std::ios_base::out);
45 std::istream is_00(0);
46 std::istream is_01(&isbuf_01);
47 std::istream is_02(&isbuf_02);
48 std::istream is_03(&isbuf_03);
49 std::istream is_04(&isbuf_04);
50 std::istream is_05(&isbuf_05);
51 std::ios_base::iostate state1, state2, statefail, stateeof;
52 statefail = std::ios_base::failbit;
53 stateeof = std::ios_base::eofbit;
56 // template<_CharT, _Traits>
57 // basic_istream& operator>>(basic_streambuf*)
59 // null istream to empty in_buf
60 state1 = is_00.rdstate();
61 is_00 >> &isbuf_00;
62 state2 = is_00.rdstate();
63 VERIFY( state1 != state2 );
64 VERIFY( static_cast<bool>(state2 & statefail) );
65 VERIFY( isbuf_00.str() == str_01 );
67 // null istream to empty in_out_buf
68 is_00.clear(std::ios_base::goodbit);
69 state1 = is_00.rdstate();
70 is_00 >> &isbuf_01;
71 state2 = is_00.rdstate();
72 VERIFY( state1 != state2 );
73 VERIFY( static_cast<bool>(state2 & statefail) );
74 VERIFY( isbuf_01.str() == str_01 );
76 // null istream to full in_buf
77 is_00.clear(std::ios_base::goodbit);
78 state1 = is_00.rdstate();
79 is_00 >> &isbuf_04;
80 state2 = is_00.rdstate();
81 VERIFY( state1 != state2 );
82 VERIFY( static_cast<bool>(state2 & statefail) );
83 VERIFY( isbuf_04.str() == str_02 );
85 // null istream to full in_out_buf
86 is_00.clear(std::ios_base::goodbit);
87 state1 = is_00.rdstate();
88 is_00 >> &isbuf_05;
89 state2 = is_00.rdstate();
90 VERIFY( state1 != state2 );
91 VERIFY( static_cast<bool>(state2 & statefail) );
92 VERIFY( isbuf_05.str() == str_02 );
94 // empty but non-null istream to full in_buf
95 state1 = is_02.rdstate();
96 is_02 >> &isbuf_04;
97 state2 = is_02.rdstate();
98 VERIFY( state1 != state2 );
99 VERIFY( static_cast<bool>(state2 & statefail) );
100 VERIFY( isbuf_04.str() == str_02 ); // as only an "in" buffer
101 VERIFY( isbuf_04.sgetc() == 'a' );
103 // empty but non-null istream to full in_out_buf
104 is_02.clear(std::ios_base::goodbit);
105 state1 = is_02.rdstate();
106 is_02 >> &isbuf_05;
107 state2 = is_02.rdstate();
108 VERIFY( state1 != state2 );
109 VERIFY( static_cast<bool>(state2 & statefail) );
110 VERIFY( isbuf_05.str() == str_02 ); // as only an "in" buffer
111 VERIFY( isbuf_05.sgetc() == 'a' );
113 // full istream to empty in_buf (need out_buf, you know?)
114 state1 = is_04.rdstate();
115 is_04 >> &isbuf_02;
116 state2 = is_04.rdstate();
117 VERIFY( state1 != state2 );
118 VERIFY( static_cast<bool>(state2 & statefail) );
119 VERIFY( isbuf_02.str() == str_01 ); // as only an "in" buffer
120 VERIFY( isbuf_02.sgetc() == ctraits_type::eof() );
121 VERIFY( is_04.peek() == ctraits_type::eof() ); // as failed
123 // full istream to empty in_out_buf
124 is_04.clear(std::ios_base::goodbit);
125 state1 = is_04.rdstate();
126 is_04 >> &isbuf_03;
127 state2 = is_04.rdstate();
128 VERIFY( state1 != state2 );
129 VERIFY( !static_cast<bool>(state2 & statefail) );
130 VERIFY( state2 == stateeof );
131 strtmp = isbuf_03.str();
132 VERIFY( strtmp == str_02 ); // as only an "in" buffer
133 VERIFY( isbuf_03.sgetc() == 'a' );
134 VERIFY( is_04.peek() == ctraits_type::eof() );
137 int main()
139 test01();
140 return 0;