]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/27_io/istream_extractor_other.cc
3 // Copyright (C) 1999, 2001 Free Software Foundation
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
8 // Free Software Foundation; either version 2, or (at your option)
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.
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING. If not, write to the Free
18 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
21 // 27.6.1.2.3 basic_istream::operator>>
22 // @require@ %-*.tst %-*.txt
23 // @diff@ %-*.tst %-*.txt
28 #include <debug_assert.h>
34 typedef std::ios::traits_type ctraits_type
;
37 const std::string str_01
;
38 const std::string
str_02("art taylor kickin it on DAKAR");
41 std::stringbuf
isbuf_00(std::ios_base::in
);
42 std::stringbuf
isbuf_01(std::ios_base::in
| std::ios_base::out
);
43 std::stringbuf
isbuf_02(str_01
, std::ios_base::in
);
44 std::stringbuf
isbuf_03(str_01
, std::ios_base::in
| std::ios_base::out
);
45 std::stringbuf
isbuf_04(str_02
, std::ios_base::in
);
46 std::stringbuf
isbuf_05(str_02
, std::ios_base::in
| std::ios_base::out
);
48 std::istream
is_00(NULL
);
49 std::istream
is_01(&isbuf_01
);
50 std::istream
is_02(&isbuf_02
);
51 std::istream
is_03(&isbuf_03
);
52 std::istream
is_04(&isbuf_04
);
53 std::istream
is_05(&isbuf_05
);
54 std::ios_base::iostate state1
, state2
, statefail
, stateeof
;
55 statefail
= std::ios_base::failbit
;
56 stateeof
= std::ios_base::eofbit
;
59 // template<_CharT, _Traits>
60 // basic_istream& operator>>(basic_streambuf*)
62 // null istream to empty in_buf
63 state1
= is_00
.rdstate();
65 state2
= is_00
.rdstate();
66 VERIFY( state1
!= state2
);
67 VERIFY( static_cast<bool>(state2
& statefail
) );
68 VERIFY( isbuf_00
.str() == str_01
);
70 // null istream to empty in_out_buf
71 is_00
.clear(std::ios_base::goodbit
);
72 state1
= is_00
.rdstate();
74 state2
= is_00
.rdstate();
75 VERIFY( state1
!= state2
);
76 VERIFY( static_cast<bool>(state2
& statefail
) );
77 VERIFY( isbuf_01
.str() == str_01
);
79 // null istream to full in_buf
80 is_00
.clear(std::ios_base::goodbit
);
81 state1
= is_00
.rdstate();
83 state2
= is_00
.rdstate();
84 VERIFY( state1
!= state2
);
85 VERIFY( static_cast<bool>(state2
& statefail
) );
86 VERIFY( isbuf_04
.str() == str_02
);
88 // null istream to full in_out_buf
89 is_00
.clear(std::ios_base::goodbit
);
90 state1
= is_00
.rdstate();
92 state2
= is_00
.rdstate();
93 VERIFY( state1
!= state2
);
94 VERIFY( static_cast<bool>(state2
& statefail
) );
95 VERIFY( isbuf_05
.str() == str_02
);
97 // empty but non-null istream to full in_buf
98 state1
= is_02
.rdstate();
100 state2
= is_02
.rdstate();
101 VERIFY( state1
!= state2
);
102 VERIFY( static_cast<bool>(state2
& statefail
) );
103 VERIFY( isbuf_04
.str() == str_02
); // as only an "in" buffer
104 VERIFY( isbuf_04
.sgetc() == 'a' );
106 // empty but non-null istream to full in_out_buf
107 is_02
.clear(std::ios_base::goodbit
);
108 state1
= is_02
.rdstate();
110 state2
= is_02
.rdstate();
111 VERIFY( state1
!= state2
);
112 VERIFY( static_cast<bool>(state2
& statefail
) );
113 VERIFY( isbuf_05
.str() == str_02
); // as only an "in" buffer
114 VERIFY( isbuf_05
.sgetc() == 'a' );
116 // full istream to empty in_buf (need out_buf, you know?)
117 state1
= is_04
.rdstate();
119 state2
= is_04
.rdstate();
120 VERIFY( state1
!= state2
);
121 VERIFY( static_cast<bool>(state2
& statefail
) );
122 VERIFY( isbuf_02
.str() == str_01
); // as only an "in" buffer
123 VERIFY( isbuf_02
.sgetc() == ctraits_type::eof() );
124 VERIFY( is_04
.peek() == ctraits_type::eof() ); // as failed
126 // full istream to empty in_out_buf
127 is_04
.clear(std::ios_base::goodbit
);
128 state1
= is_04
.rdstate();
130 state2
= is_04
.rdstate();
131 VERIFY( state1
!= state2
);
132 VERIFY( !static_cast<bool>(state2
& statefail
) );
133 VERIFY( state2
== stateeof
);
134 strtmp
= isbuf_03
.str();
135 VERIFY( strtmp
== str_02
); // as only an "in" buffer
136 VERIFY( isbuf_03
.sgetc() == 'a' );
137 VERIFY( is_04
.peek() == ctraits_type::eof() );
150 typedef std::ios::traits_type ctraits_type
;
151 const char name_01
[] = "istream_extractor_other-1.txt"; //read
152 const char name_02
[] = "istream_extractor_other-2.txt"; //write
154 std::filebuf fbin
, fbout
;
155 fbin
.open(name_01
, std::ios_base::in
);
156 fbout
.open(name_02
, std::ios_base::out
| std::ios_base::trunc
);
157 VERIFY( fbin
.is_open() );
158 VERIFY( fbout
.is_open() );
162 std::istream
is(&fbin
);
163 is
.unsetf(std::ios_base::skipws
);
169 VERIFY( !fbin
.is_open() );
170 VERIFY( !fbout
.is_open() );
184 // template<_CharT, _Traits>
185 // basic_istream& operator>>(ios_base& (*pf) (ios_base&))
188 std::istringstream
iss(" 43");
189 iss
>> std::noskipws
>> i
;
190 std::ios::iostate i3
= iss
.rdstate();
191 VERIFY ( !iss
); //should set failbit
194 // template<_CharT, _Traits>
195 // basic_istream& operator>>(basic_ios& (*pf) (basic_ios&))
197 // template<_CharT, _Traits>
198 // basic_istream& operator>>(basic_istream& (*pf) (basic_istream&))