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.2.4 basic_ostream seek members
26 #include <testsuite_hooks.h>
32 typedef ios::pos_type pos_type
;
35 const char str_lit01
[] = "ostream_seeks-1.txt";
38 // test default ctors leave things in the same positions...
40 pos_type p1
= ost1
.tellp();
43 pos_type p2
= ofs1
.tellp();
48 // test ctors leave things in the same positions...
49 ostringstream
ost2("bob_marley:kaya");
52 ofstream
ofs2(str_lit01
);
66 // basically this is the istreams_seeks.cc code. We need to fix it up
73 std::istream::pos_type pos01
, pos02
, pos03
, pos04
, pos05
, pos06
;
74 std::ios_base::iostate state01
, state02
;
75 const char str_lit01
[] = "istream_unformatted-1.txt";
76 const char str_lit02
[] = "istream_unformatted-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
.tellp();
103 pos06
= is03
.tellp();
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 tellp.
115 state01
= is01
.rdstate();
116 is01
.seekg(10, std::ios_base::cur
);
117 state02
= is01
.rdstate();
118 pos01
= is01
.tellp();
119 VERIFY( pos01
== pos02
+ 10 );
120 VERIFY( state01
== state02
);
121 pos02
= is01
.tellp();
122 VERIFY( pos02
== pos01
);
124 state01
= is02
.rdstate();
125 is02
.seekg(10, std::ios_base::cur
);
126 state02
= is02
.rdstate();
127 pos03
= is02
.tellp();
128 VERIFY( pos03
== pos04
+ 10 );
129 VERIFY( state01
== state02
);
130 pos04
= is02
.tellp();
131 VERIFY( pos03
== pos04
);
133 state01
= is03
.rdstate();
134 is03
.seekg(10, std::ios_base::cur
);
135 state02
= is03
.rdstate();
136 pos05
= is03
.tellp();
137 VERIFY( pos05
== pos06
+ 10 );
138 VERIFY( state01
== state02
);
139 pos06
= is03
.tellp();
140 VERIFY( pos05
== pos06
);
143 state01
= is01
.rdstate();
144 is01
.seekg(20, std::ios_base::beg
);
145 state02
= is01
.rdstate();
146 pos01
= is01
.tellp();
147 VERIFY( pos01
== pos02
+ 10 );
148 VERIFY( state01
== state02
);
149 pos02
= is01
.tellp();
150 VERIFY( pos02
== pos01
);
152 state01
= is02
.rdstate();
153 is02
.seekg(20, std::ios_base::beg
);
154 state02
= is02
.rdstate();
155 pos03
= is02
.tellp();
156 VERIFY( pos03
== pos04
+ 10 );
157 VERIFY( state01
== state02
);
158 pos04
= is02
.tellp();
159 VERIFY( pos03
== pos04
);
161 state01
= is03
.rdstate();
162 is03
.seekg(20, std::ios_base::beg
);
163 state02
= is03
.rdstate();
164 pos05
= is03
.tellp();
165 VERIFY( pos05
== pos06
+ 10 );
166 VERIFY( state01
== state02
);
167 pos06
= is03
.tellp();
168 VERIFY( pos05
== pos06
);
179 std::istream::pos_type pos01
, pos02
, pos03
, pos04
, pos05
, pos06
;
180 std::ios_base::iostate state01
, state02
;
181 const char str_lit01
[] = "istream_unformatted-1.tst";
182 std::ifstream
if01(str_lit01
);
183 std::ifstream
if02(str_lit01
);
184 std::ifstream
if03(str_lit01
);
185 VERIFY( if01
.good() );
186 VERIFY( if02
.good() );
187 VERIFY( if03
.good() );
189 std::stringbuf
strbuf01(std::ios_base::in
| std::ios_base::out
);
191 // initialize stringbufs that are ios_base::out
192 std::stringbuf
strbuf03(strbuf01
.str(), std::ios_base::out
);
193 // initialize stringbufs that are ios_base::in
194 std::stringbuf
strbuf02(strbuf01
.str(), std::ios_base::in
);
196 std::istream
is01(&strbuf01
);
197 std::istream
is02(&strbuf02
);
198 std::istream
is03(&strbuf03
);
202 pos01
= is01
.tellp();
203 pos02
= is01
.tellp();
204 VERIFY( pos01
== pos02
);
205 // VERIFY( istream::pos_type(0) != pos01 ); // deprecated
208 pos03
= is02
.tellp();
209 pos04
= is02
.tellp();
210 VERIFY( pos03
== pos04
);
211 // VERIFY( istream::pos_type(0) != pos03 ); // deprecated
214 pos05
= is03
.tellp();
215 pos06
= is03
.tellp();
216 VERIFY( pos05
== pos06
);
217 // VERIFY( istream::pos_type(0) != pos01 ); //deprecated
219 // istream& seekg(pos_type)
220 // istream& seekg(off_type, ios_base::seekdir)
223 // NB: see library issues list 136. It's the v-3 interp that seekg
224 // only sets the input buffer, or else istreams with buffers that
225 // have _M_mode == ios_base::out will fail to have consistency
226 // between seekg and tellp.
227 state01
= is01
.rdstate();
228 is01
.seekg(10, std::ios_base::cur
);
229 state02
= is01
.rdstate();
230 pos01
= is01
.tellp();
231 VERIFY( pos01
== pos02
+ 10 );
232 VERIFY( state01
== state02
);
233 pos02
= is01
.tellp();
234 VERIFY( pos02
== pos01
);
236 state01
= is02
.rdstate();
237 is02
.seekg(10, std::ios_base::cur
);
238 state02
= is02
.rdstate();
239 pos03
= is02
.tellp();
240 VERIFY( pos03
== pos04
+ 10 );
241 VERIFY( state01
== state02
);
242 pos04
= is02
.tellp();
243 VERIFY( pos03
== pos04
);
245 state01
= is03
.rdstate();
246 is03
.seekg(10, std::ios_base::cur
);
247 state02
= is03
.rdstate();
248 pos05
= is03
.tellp();
249 VERIFY( pos05
== pos06
); // as only out buffer
250 VERIFY( state01
== state02
);
251 pos06
= is03
.tellp();
252 VERIFY( pos05
== pos06
);
255 state01
= is01
.rdstate();
256 is01
.seekg(20, std::ios_base::beg
);
257 state02
= is01
.rdstate();
258 pos01
= is01
.tellp();
259 VERIFY( pos01
== pos02
+ 10 );
260 VERIFY( state01
== state02
);
261 pos02
= is01
.tellp();
262 VERIFY( pos02
== pos01
);
264 state01
= is02
.rdstate();
265 is02
.seekg(20, std::ios_base::beg
);
266 state02
= is02
.rdstate();
267 pos03
= is02
.tellp();
268 VERIFY( pos03
== pos04
+ 10 );
269 VERIFY( state01
== state02
);
270 pos04
= is02
.tellp();
271 VERIFY( pos03
== pos04
);
273 state01
= is03
.rdstate();
274 is03
.seekg(20, std::ios_base::beg
);
275 state02
= is03
.rdstate();
276 pos05
= is03
.tellp();
277 VERIFY( pos05
== pos06
); // as only out buffer
278 VERIFY( state01
== state02
);
279 pos06
= is03
.tellp();
280 VERIFY( pos05
== pos06
);