]>
gcc.gnu.org Git - gcc.git/blob - libstdc++-v3/testsuite/27_io/istream_seeks.cc
97ef01b121cb9a36d48c9d58b9b0c8b42ed8e77b
3 // Copyright (C) 2000 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.3 unformatted input functions
22 // NB: ostream has a particular "seeks" category. Adopt this for istreams too.
23 // @require@ %-*.tst %-*.txt
24 // @diff@ %-*.tst %-*.txt
29 #include <debug_assert.h>
35 typedef ios::pos_type pos_type
;
38 const char str_lit01
[] = "istream_seeks-1.tst";
41 // test default ctors leave things in the same positions...
43 pos_type p3
= ist1
.tellg();
46 pos_type p4
= ifs1
.tellg();
51 // test ctors leave things in the same positions...
52 istringstream
ist2("bob_marley:kaya");
55 ifstream
ifs2(str_lit01
);
70 typedef std::istream::off_type off_type
;
73 std::istream::pos_type pos01
, pos02
, pos03
, pos04
, pos05
, pos06
;
74 std::ios_base::iostate state01
, state02
;
75 const char str_lit01
[] = "istream_seeks-1.txt";
76 const char str_lit02
[] = "istream_seeks-2.txt";
77 std::ifstream
if01(str_lit01
, std::ios_base::in
| std::ios_base::out
);
78 std::ifstream
if02(str_lit01
, std::ios_base::in
);
79 std::ifstream
if03(str_lit02
, std::ios_base::out
| std::ios_base::trunc
);
80 VERIFY( if01
.good() );
81 VERIFY( if02
.good() );
82 VERIFY( if03
.good() );
84 std::istream
is01(if01
.rdbuf());
85 std::istream
is02(if02
.rdbuf());
86 std::istream
is03(if03
.rdbuf());
92 VERIFY( pos01
== pos02
);
93 // VERIFY( istream::pos_type(0) != pos01 ); //deprecated
98 VERIFY( pos03
== pos04
);
99 // VERIFY( istream::pos_type(0) != pos03 ); //deprecated
102 pos05
= is03
.tellg();
103 pos06
= is03
.tellg();
104 VERIFY( pos05
== pos06
);
105 // VERIFY( istream::pos_type(0) != pos01 ); //deprecated
107 // istream& seekg(pos_type)
108 // istream& seekg(off_type, ios_base::seekdir)
111 // NB: see library issues list 136. It's the v-3 interp that seekg
112 // only sets the input buffer, or else istreams with buffers that
113 // have _M_mode == ios_base::out will fail to have consistency
114 // between seekg and tellg.
115 state01
= is01
.rdstate();
116 is01
.seekg(10, std::ios_base::cur
);
117 state02
= is01
.rdstate();
118 pos01
= is01
.tellg();
119 VERIFY( pos01
== pos02
+ off_type(10) );
120 VERIFY( state01
== state02
);
121 pos02
= is01
.tellg();
122 VERIFY( pos02
== pos01
);
124 state01
= is02
.rdstate();
125 is02
.seekg(10, std::ios_base::cur
);
126 state02
= is02
.rdstate();
127 pos03
= is02
.tellg();
128 VERIFY( pos03
== pos04
+ off_type(10) );
129 VERIFY( state01
== state02
);
130 pos04
= is02
.tellg();
131 VERIFY( pos03
== pos04
);
133 state01
= is03
.rdstate();
134 is03
.seekg(10, std::ios_base::cur
);
135 state02
= is03
.rdstate();
136 pos05
= is03
.tellg();
137 VERIFY( pos05
== pos06
+ off_type(10) );
138 VERIFY( state01
== state02
);
139 pos06
= is03
.tellg();
140 VERIFY( pos05
== pos06
);
143 state01
= is01
.rdstate();
144 is01
.seekg(20, std::ios_base::beg
);
145 state02
= is01
.rdstate();
146 pos01
= is01
.tellg();
147 VERIFY( pos01
== pos02
+ off_type(10) );
148 VERIFY( state01
== state02
);
149 pos02
= is01
.tellg();
150 VERIFY( pos02
== pos01
);
152 state01
= is02
.rdstate();
153 is02
.seekg(20, std::ios_base::beg
);
154 state02
= is02
.rdstate();
155 pos03
= is02
.tellg();
156 VERIFY( pos03
== pos04
+ off_type(10) );
157 VERIFY( state01
== state02
);
158 pos04
= is02
.tellg();
159 VERIFY( pos03
== pos04
);
161 state01
= is03
.rdstate();
162 is03
.seekg(20, std::ios_base::beg
);
163 state02
= is03
.rdstate();
164 pos05
= is03
.tellg();
165 VERIFY( pos05
== pos06
+ off_type(10) );
166 VERIFY( state01
== state02
);
167 pos06
= is03
.tellg();
168 VERIFY( pos05
== pos06
);
178 typedef std::istream::off_type off_type
;
181 std::istream::pos_type pos01
, pos02
, pos03
, pos04
, pos05
, pos06
;
182 std::ios_base::iostate state01
, state02
;
183 const char str_lit01
[] = "istream_seeks-1.tst";
184 std::ifstream
if01(str_lit01
);
185 std::ifstream
if02(str_lit01
);
186 std::ifstream
if03(str_lit01
);
187 VERIFY( if01
.good() );
188 VERIFY( if02
.good() );
189 VERIFY( if03
.good() );
191 std::stringbuf
strbuf01(std::ios_base::in
| std::ios_base::out
);
193 // initialize stringbufs that are ios_base::out
194 std::stringbuf
strbuf03(strbuf01
.str(), std::ios_base::out
);
195 // initialize stringbufs that are ios_base::in
196 std::stringbuf
strbuf02(strbuf01
.str(), std::ios_base::in
);
198 std::istream
is01(&strbuf01
);
199 std::istream
is02(&strbuf02
);
200 std::istream
is03(&strbuf03
);
204 pos01
= is01
.tellg();
205 pos02
= is01
.tellg();
206 VERIFY( pos01
== pos02
);
207 // VERIFY( istream::pos_type(0) != pos01 ); // deprecated
210 pos03
= is02
.tellg();
211 pos04
= is02
.tellg();
212 VERIFY( pos03
== pos04
);
213 // VERIFY( istream::pos_type(0) != pos03 ); // deprecated
216 pos05
= is03
.tellg();
217 pos06
= is03
.tellg();
218 VERIFY( pos05
== pos06
);
219 // VERIFY( istream::pos_type(0) != pos01 ); //deprecated
221 // istream& seekg(pos_type)
222 // istream& seekg(off_type, ios_base::seekdir)
225 // NB: see library issues list 136. It's the v-3 interp that seekg
226 // only sets the input buffer, or else istreams with buffers that
227 // have _M_mode == ios_base::out will fail to have consistency
228 // between seekg and tellg.
229 state01
= is01
.rdstate();
230 is01
.seekg(10, std::ios_base::cur
);
231 state02
= is01
.rdstate();
232 pos01
= is01
.tellg();
233 VERIFY( pos01
== pos02
+ off_type(10) );
234 VERIFY( state01
== state02
);
235 pos02
= is01
.tellg();
236 VERIFY( pos02
== pos01
);
238 state01
= is02
.rdstate();
239 is02
.seekg(10, std::ios_base::cur
);
240 state02
= is02
.rdstate();
241 pos03
= is02
.tellg();
242 VERIFY( pos03
== pos04
+ off_type(10) );
243 VERIFY( state01
== state02
);
244 pos04
= is02
.tellg();
245 VERIFY( pos03
== pos04
);
247 state01
= is03
.rdstate();
248 is03
.seekg(10, std::ios_base::cur
);
249 state02
= is03
.rdstate();
250 pos05
= is03
.tellg();
251 VERIFY( pos05
== pos06
); // as only out buffer
252 VERIFY( state01
!= state02
);
253 pos06
= is03
.tellg();
254 VERIFY( pos05
== pos06
);
257 state01
= is01
.rdstate();
258 is01
.seekg(20, std::ios_base::beg
);
259 state02
= is01
.rdstate();
260 pos01
= is01
.tellg();
261 VERIFY( pos01
== pos02
+ off_type(10) );
262 VERIFY( state01
== state02
);
263 pos02
= is01
.tellg();
264 VERIFY( pos02
== pos01
);
266 state01
= is02
.rdstate();
267 is02
.seekg(20, std::ios_base::beg
);
268 state02
= is02
.rdstate();
269 pos03
= is02
.tellg();
270 VERIFY( pos03
== pos04
+ off_type(10) );
271 VERIFY( state01
== state02
);
272 pos04
= is02
.tellg();
273 VERIFY( pos03
== pos04
);
275 state01
= is03
.rdstate();
276 is03
.seekg(20, std::ios_base::beg
);
277 state02
= is03
.rdstate();
278 pos05
= is03
.tellg();
279 VERIFY( pos05
== pos06
); // as only out buffer
280 VERIFY( state01
== state02
);
281 pos06
= is03
.tellg();
282 VERIFY( pos05
== pos06
);
This page took 0.049088 seconds and 4 git commands to generate.