1 |
19 |
jlechner |
// Copyright (C) 2004 Free Software Foundation
|
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
|
6 |
|
|
// Free Software Foundation; either version 2, or (at your option)
|
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
|
15 |
|
|
// with this library; see the file COPYING. If not, write to the Free
|
16 |
|
|
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
|
17 |
|
|
// USA.
|
18 |
|
|
|
19 |
|
|
// 27.6.1.2.3 basic_istream::operator>>
|
20 |
|
|
|
21 |
|
|
#include <istream>
|
22 |
|
|
#include <sstream>
|
23 |
|
|
#include <testsuite_hooks.h>
|
24 |
|
|
|
25 |
|
|
// stringbufs.
|
26 |
|
|
void test01()
|
27 |
|
|
{
|
28 |
|
|
typedef std::wios::traits_type ctraits_type;
|
29 |
|
|
|
30 |
|
|
bool test __attribute__((unused)) = true;
|
31 |
|
|
const std::wstring str_01;
|
32 |
|
|
const std::wstring str_02(L"art taylor kickin it on DAKAR");
|
33 |
|
|
std::wstring strtmp;
|
34 |
|
|
|
35 |
|
|
std::wstringbuf isbuf_00(std::ios_base::in);
|
36 |
|
|
std::wstringbuf isbuf_01(std::ios_base::in | std::ios_base::out);
|
37 |
|
|
std::wstringbuf isbuf_02(str_01, std::ios_base::in);
|
38 |
|
|
std::wstringbuf isbuf_03(str_01, std::ios_base::in | std::ios_base::out);
|
39 |
|
|
std::wstringbuf isbuf_04(str_02, std::ios_base::in);
|
40 |
|
|
std::wstringbuf isbuf_05(str_02, std::ios_base::in | std::ios_base::out);
|
41 |
|
|
|
42 |
|
|
std::wistream is_00(NULL);
|
43 |
|
|
std::wistream is_01(&isbuf_01);
|
44 |
|
|
std::wistream is_02(&isbuf_02);
|
45 |
|
|
std::wistream is_03(&isbuf_03);
|
46 |
|
|
std::wistream is_04(&isbuf_04);
|
47 |
|
|
std::wistream 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 |
|
|
|
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();
|
60 |
|
|
VERIFY( state1 != state2 );
|
61 |
|
|
VERIFY( static_cast<bool>(state2 & statefail) );
|
62 |
|
|
VERIFY( isbuf_00.str() == str_01 );
|
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();
|
69 |
|
|
VERIFY( state1 != state2 );
|
70 |
|
|
VERIFY( static_cast<bool>(state2 & statefail) );
|
71 |
|
|
VERIFY( isbuf_01.str() == str_01 );
|
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();
|
78 |
|
|
VERIFY( state1 != state2 );
|
79 |
|
|
VERIFY( static_cast<bool>(state2 & statefail) );
|
80 |
|
|
VERIFY( isbuf_04.str() == str_02 );
|
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();
|
87 |
|
|
VERIFY( state1 != state2 );
|
88 |
|
|
VERIFY( static_cast<bool>(state2 & statefail) );
|
89 |
|
|
VERIFY( isbuf_05.str() == str_02 );
|
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();
|
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() == L'a' );
|
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();
|
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() == L'a' );
|
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();
|
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
|
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();
|
125 |
|
|
VERIFY( state1 == state2 );
|
126 |
|
|
VERIFY( !static_cast<bool>(state2 & statefail) );
|
127 |
|
|
VERIFY( state2 != stateeof );
|
128 |
|
|
strtmp = isbuf_03.str();
|
129 |
|
|
VERIFY( strtmp == str_02 ); // as only an "in" buffer
|
130 |
|
|
VERIFY( isbuf_03.sgetc() == L'a' );
|
131 |
|
|
VERIFY( is_04.peek() == ctraits_type::eof() );
|
132 |
|
|
}
|
133 |
|
|
|
134 |
|
|
int main()
|
135 |
|
|
{
|
136 |
|
|
test01();
|
137 |
|
|
return 0;
|
138 |
|
|
}
|