]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/27_io/filebuf.cc
varasm.c (assemble_constructor): Take a symbol_ref and a priority instead of a bare...
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 27_io / filebuf.cc
CommitLineData
b2dad0e3
BK
1// 990117 bkoz test functionality of basic_filebuf for char_type == char
2
69302d8b 3// Copyright (C) 1997-1999, 2000, 2001 Free Software Foundation, Inc.
b2dad0e3
BK
4//
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)
9// any later version.
10
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.
15
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,
19// USA.
20
21// NB: this test assumes that _M_buf_size == 40, and not the usual
22// buffer_size length of 8092, so that overflow/underflow can be
23// simulated a bit more readily.
24
db353c2c
GDR
25// @require@ %-*.tst %-*.txt
26// @diff@ %-*.tst %*.txt
27
b2dad0e3 28#include <fstream>
aa1b2f7d 29#include <debug_assert.h>
b2dad0e3
BK
30
31const char carray_01[] = "santa cruz or sandiego?";
32const char carray_02[] = "memphis, new orleans, and savanah";
db353c2c
GDR
33const char name_01[] = "filebuf-1.txt"; // file with data in it
34const char name_02[] = "filebuf-2.txt"; // empty file, need to create
35const char name_03[] = "filebuf-3.txt"; // empty file, need to create
b2dad0e3
BK
36
37class derived_filebuf: public std::filebuf
38{
39 public:
40 void
d207c3f7 41 set_size(int_type __size) { _M_buf_size_opt = __size; }
b2dad0e3
BK
42};
43
44derived_filebuf fb_01; // in
45derived_filebuf fb_02; // out
46derived_filebuf fb_03; // in | out
47
48const int buffer_size = 8192;
49
ab30ba5c 50
b2dad0e3
BK
51// initialize filebufs to be the same size regardless of platform
52void test00()
53{
54 fb_01.set_size(buffer_size);
55 fb_02.set_size(buffer_size);
56 fb_03.set_size(buffer_size);
57}
58
ab30ba5c 59
b2dad0e3
BK
60// test the filebuf/stringbuf locale settings
61bool test01() {
62 std::locale loc_tmp;
63 loc_tmp = fb_01.getloc();
64 fb_01.pubimbue(loc_tmp); //This should initialize _M_init to true
65 fb_01.getloc(); //This should just return _M_locale
66
67 return true;
68}
69
70
71// test member functions functions
72bool test02() {
73 bool test = true;
74
75 // bool is_open()
aa1b2f7d
BV
76 VERIFY( !fb_01.is_open() );
77 VERIFY( !fb_02.is_open() );
78 VERIFY( !fb_03.is_open() );
b2dad0e3
BK
79
80 // filebuf_type* open(const char* __s, ios_base::openmode __mode)
ab30ba5c 81 fb_01.open(name_01, std::ios_base::in | std::ios_base::ate);
b2dad0e3
BK
82 fb_02.open(name_02, std::ios_base::in | std::ios_base::out | std::ios_base::trunc);
83 // Try to open two different files without closing the first:
84 // Should keep the old file attached, and disregard attempt to overthrow.
85 fb_02.open(name_03, std::ios_base::in | std::ios_base::out);
86 fb_03.open(name_03, std::ios_base::out | std::ios_base::trunc);
aa1b2f7d
BV
87 VERIFY( fb_01.is_open() );
88 VERIFY( fb_02.is_open() );
89 VERIFY( fb_03.is_open() );
b2dad0e3
BK
90
91 // filebuf_type* close()
92 fb_01.close();
93 fb_02.close();
94 fb_03.close();
aa1b2f7d
BV
95 VERIFY( !fb_01.is_open() );
96 VERIFY( !fb_02.is_open() );
97 VERIFY( !fb_03.is_open() );
b2dad0e3
BK
98
99#ifdef DEBUG_ASSERT
100 assert(test);
101#endif
102
103 return test;
104}
105
106
107// test overloaded virtual functions
108bool test03() {
109 typedef std::filebuf::int_type int_type;
110 typedef std::filebuf::traits_type traits_type;
111 typedef std::filebuf::pos_type pos_type;
112 typedef std::filebuf::off_type off_type;
113 typedef size_t size_type;
114
115 bool test = true;
116 std::filebuf f_tmp;
117 std::streamsize strmsz_1, strmsz_2;
118 std::streamoff strmof_1, strmof_2;
119 int i = 0, j = 0, k = 0;
120
121 // GET
122 // int showmanyc()
123 // returns an estimate of the numbers of chars in the seq, or -1.
124 // if __retval > 0, then calls to underflow won't return
125 // traits_type::eof() till at least __retval chars.
126 // if __retval == -1, then calls to underflow or uflow will fail.
127 // NB overriding def if it can determine more chars can be read from
128 // the input sequence.
129
130 // int in_avail()
131 // if a read position is available, return _M_in_end - _M_in_cur.
132 // else return showmanyc.
133 strmof_1 = fb_01.in_avail();
134 strmof_2 = fb_02.in_avail();
aa1b2f7d
BV
135 VERIFY( strmof_1 == -1 );
136 VERIFY( strmof_1 == strmof_2 ); //fail because not open
b2dad0e3 137 strmof_1 = fb_03.in_avail();
aa1b2f7d 138 VERIFY( strmof_1 == strmof_2 );
b2dad0e3
BK
139 fb_01.open(name_01, std::ios_base::in);
140 fb_02.open(name_02, std::ios_base::out | std::ios_base::trunc);
141 fb_03.open(name_03, std::ios_base::out | std::ios_base::in | std::ios_base::trunc);
142 strmof_1 = fb_01.in_avail();
143 strmof_2 = fb_02.in_avail();
aa1b2f7d
BV
144 VERIFY( strmof_1 != strmof_2 );
145 VERIFY( strmof_1 >= 0 );
146 VERIFY( strmof_2 == -1 ); // empty file
b2dad0e3 147 strmof_1 = fb_03.in_avail();
aa1b2f7d 148 VERIFY( strmof_1 == -1 ); // empty file
b2dad0e3
BK
149
150 // int_type sbumpc()
151 // if read_cur not avail returns uflow(), else return *read_cur & increment
152 int_type c1 = fb_01.sbumpc();
153 int_type c2 = fb_02.sbumpc();
aa1b2f7d
BV
154 VERIFY( c1 != c2 );
155 VERIFY( c1 == '/' );
156 VERIFY( c2 == -1 );
b2dad0e3
BK
157 int_type c3 = fb_01.sbumpc();
158 int_type c4 = fb_02.sbumpc();
aa1b2f7d
BV
159 VERIFY( c3 != c4 );
160 VERIFY( c1 == c3 ); // fluke, both happen to be '/'
161 VERIFY( c2 == c4 );
b2dad0e3 162 int_type c5 = fb_03.sbumpc();
aa1b2f7d 163 VERIFY( c5 == traits_type::eof() );
b2dad0e3
BK
164 // XXX should do some kind of test to make sure that internal
165 // buffers point ot the same thing, to check consistancy.
166
167 // int_type sgetc()
168 // if read_cur not avail, return uflow(), else return *read_cur
169 int_type c6 = fb_01.sgetc();
170 int_type c7 = fb_02.sgetc();
aa1b2f7d
BV
171 VERIFY( c6 != c3 );
172 VERIFY( c7 == c4 ); // both -1
b2dad0e3
BK
173 int_type c8 = fb_01.sgetc();
174 int_type c9 = fb_02.sgetc();
aa1b2f7d
BV
175 VERIFY( c6 == c8 );
176 VERIFY( c7 == c9 );
b2dad0e3 177 c5 = fb_03.sgetc();
aa1b2f7d 178 VERIFY( c5 == traits_type::eof() );
b2dad0e3
BK
179
180 // int_type snextc()
181 // calls sbumpc and if sbumpc != eof, return sgetc
182 c6 = fb_01.snextc();
183 c7 = fb_02.snextc();
aa1b2f7d
BV
184 VERIFY( c6 != c8 );
185 VERIFY( c7 == c9 ); // -1
186 VERIFY( c6 == '9' );
b2dad0e3
BK
187 c6 = fb_01.snextc();
188 c7 = fb_02.snextc();
aa1b2f7d
BV
189 VERIFY( c6 != c8 );
190 VERIFY( c7 == c9 ); // -1
191 VERIFY( c6 == '9' );
b2dad0e3 192 c5 = fb_03.snextc();
aa1b2f7d 193 VERIFY( c5 == traits_type::eof() );
b2dad0e3
BK
194
195 // streamsize sgetn(char_type *s, streamsize n)
196 // streamsize xsgetn(char_type *s, streamsize n)
197 // assign up to n chars to s from input sequence, indexing in_cur as
198 // approp and returning the number of chars assigned
199 strmsz_1 = fb_01.in_avail();
200 strmsz_2 = fb_02.in_avail();
201 test = strmsz_1 != strmsz_2;
202 char carray1[13] = "";
203 strmsz_1 = fb_01.sgetn(carray1, 10);
204 char carray2[buffer_size] = "";
205 strmsz_2 = fb_02.sgetn(carray2, 10);
aa1b2f7d
BV
206 VERIFY( strmsz_1 != strmsz_2 );
207 VERIFY( strmsz_1 == 10 );
208 VERIFY( strmsz_2 == 0 );
b2dad0e3
BK
209 c1 = fb_01.sgetc();
210 c2 = fb_02.sgetc();
aa1b2f7d
BV
211 VERIFY( c1 == '\n' );
212 VERIFY( c7 == c2 ); // n != i
b2dad0e3 213 strmsz_1 = fb_03.sgetn(carray1, 10);
aa1b2f7d 214 VERIFY( !strmsz_1 ); //zero
b2dad0e3
BK
215 strmsz_1 = fb_01.in_avail();
216 strmsz_2 = fb_01.sgetn(carray2, strmsz_1 + 5);
aa1b2f7d 217 VERIFY( strmsz_1 == strmsz_2 - 5 );
b2dad0e3 218 c4 = fb_01.sgetc(); // buffer should have underflowed from above.
aa1b2f7d 219 VERIFY( c4 == 'i' );
b2dad0e3 220 strmsz_1 = fb_01.in_avail();
aa1b2f7d 221 VERIFY( strmsz_1 > 0 );
b2dad0e3 222 strmsz_2 = fb_01.sgetn(carray2, strmsz_1 + 5);
aa1b2f7d 223 VERIFY( strmsz_1 == strmsz_2 ); //at the end of the actual file
b2dad0e3
BK
224 strmsz_1 = fb_02.in_avail();
225 strmsz_2 = fb_02.sgetn(carray2, strmsz_1 + 5);
aa1b2f7d
BV
226 VERIFY( strmsz_1 == -1 );
227 VERIFY( strmsz_2 == 0 );
b2dad0e3 228 c4 = fb_02.sgetc(); // should be EOF
aa1b2f7d 229 VERIFY( c4 == traits_type::eof() );
b2dad0e3
BK
230
231 // PUT
232 // int_type sputc(char_type c)
233 // if out_cur not avail, return overflow(traits_type::to_int_type(c))
234 // else, stores c at out_cur,
235 // increments out_cur, and returns c as int_type
236 // strmsz_1 = fb_03.in_avail(); // XXX valid for in|out??
237 c1 = fb_02.sputc('a');
238 c2 = fb_03.sputc('b');
aa1b2f7d 239 VERIFY( c1 != c2 );
b2dad0e3
BK
240 c1 = fb_02.sputc('c');
241 c2 = fb_03.sputc('d');
aa1b2f7d 242 VERIFY( c1 != c2 );
b2dad0e3 243 // strmsz_2 = fb_03.in_avail();
aa1b2f7d 244 // VERIFY( strmsz_1 != strmsz_2 );
b2dad0e3
BK
245 for (int i = 50; i <= 90; ++i)
246 c2 = fb_02.sputc(char(i));
247 // 27filebuf-2.txt == ac23456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWX
248 // fb_02._M_out_cur = '2'
249 strmsz_1 = fb_03.in_avail();
250 for (int i = 50; i <= 90; ++i)
251 c2 = fb_03.sputc(char(i));
252 strmsz_2 = fb_03.in_avail();
aa1b2f7d
BV
253 // VERIFY( strmsz_1 != strmsz_2 );
254 // VERIFY( strmsz_1 > 0 );
255 // VERIFY( strmsz_2 > 0 );
b2dad0e3
BK
256 // 27filebuf-2.txt == bd23456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWX
257 // fb_02._M_out_cur = '2'
258 c3 = fb_01.sputc('a'); // should be EOF because this is read-only
aa1b2f7d 259 VERIFY( c3 == traits_type::eof() );
b2dad0e3
BK
260
261 // streamsize sputn(const char_typs* s, streamsize n)
262 // write up to n chars to out_cur from s, returning number assigned
263 // NB *sputn will happily put '\0' into your stream if you give it a chance*
264 strmsz_1 = fb_03.sputn("racadabras", 10);//"abracadabras or what?"
aa1b2f7d 265 VERIFY( strmsz_1 == 10 );
b2dad0e3 266 strmsz_2 = fb_03.sputn(", i wanna reach out and", 10);
aa1b2f7d
BV
267 VERIFY( strmsz_2 == 10 );
268 VERIFY( strmsz_1 == strmsz_2 );
b2dad0e3
BK
269 // fb_03._M_out_beg = "YZracadabras, i wanna FGHIJKLMNOPQRSTUVW"
270 // fb_03._M_out_cur = "FGHIJKLMNOPQRSTUVW"
271 strmsz_1 = fb_02.sputn("racadabras", 10);
aa1b2f7d 272 VERIFY( strmsz_1 == 10 );
b2dad0e3
BK
273 // fb_02._M_out_beg = "YZracadabras<=>?@ABCDEFGHIJKLMNOPQRSTUVW"
274 // fb_02._M_out_cur = "<=>?@ABCDEFGHIJKLMNOPQRSTUVW"
275 strmsz_1 = fb_01.sputn("racadabra", 10);
aa1b2f7d 276 VERIFY( strmsz_1 == 0 );
b2dad0e3
BK
277
278 // PUTBACK
279 // int_type pbfail(int_type c)
280 // called when gptr() null, gptr() == eback(), or traits::eq(*gptr, c) false
281 // "pending sequence" is:
282 // 1) everything as defined in underflow
283 // 2) + if (traits::eq_int_type(c, traits::eof()), then input
284 // sequence is backed up one char before the pending sequence is
285 // determined.
286 // 3) + if (not 2) then c is prepended. Left unspecified is
287 // whether the input sequence is backedup or modified in any way
288 // returns traits::eof() for failure, unspecified other value for success
289
290 // int_type sputbackc(char_type c)
291 // if in_cur not avail || ! traits::eq(c, gptr() [-1]), return pbfail
292 // otherwise decrements in_cur and returns *gptr()
293 c1 = fb_03.sgetc(); // -1
294 c2 = fb_03.sputbackc('z');
295 strmsz_2 = fb_03.in_avail();
296 c3 = fb_03.sgetc();
aa1b2f7d
BV
297 VERIFY( c3 == c2 );
298 VERIFY( c1 != c3 );
299 VERIFY( 1 == strmsz_2 );
b2dad0e3
BK
300 //test for _in_cur == _in_beg
301 // fb_03._M_out_beg = "bd23456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZracada" etc
302 fb_03.pubseekoff(10, std::ios_base::beg,
303 std::ios_base::in | std::ios_base::out);
304 fb_03.sputc('m');
305 strmsz_1 = fb_03.in_avail();
306 c1 = fb_03.sgetc();
307 fb_03.snextc();
308 c2 = fb_03.sputbackc('z');
309 strmsz_2 = fb_03.in_avail();
310 c3 = fb_03.sgetc();
aa1b2f7d
BV
311 VERIFY( c1 != c2 );
312 VERIFY( c3 == c2 );
313 VERIFY( c1 != c3 );
314 VERIFY( c2 == 'z' );
315 VERIFY( strmsz_1 == strmsz_2 );
b2dad0e3
BK
316 // test for replacing char with identical one
317 fb_03.snextc();
318 fb_03.sputc('u');
319 fb_03.sputc('v');
320 fb_03.sputc('a');
321 strmsz_1 = fb_03.in_avail();
322 c2 = fb_03.sputbackc('a');
323 strmsz_2 = fb_03.in_avail();
324 c3 = fb_03.sgetc();
aa1b2f7d
BV
325 VERIFY( c3 == c2 );
326 VERIFY( strmsz_1 + 1 == strmsz_2 );
b2dad0e3
BK
327 //test for ios_base::out
328 c1 = fb_02.sgetc(); // undefined
329 c2 = fb_02.sputbackc('a');
aa1b2f7d
BV
330 VERIFY( c1 == c2 );
331 VERIFY( c1 == -1 );
b2dad0e3
BK
332
333 // int_type sungetc()
334 // if in_cur not avail, return pbackfail(), else decrement and
335 // return to_int_type(*gptr())
336 // fb_03._M_out_beg = "uvaacadabras, i wannaZ[\\]^_`abcdefghijkl"
337 // fb_03._M_out_cur = "aacadabras, i wannaZ[\\]^_`abcdefghijkl"
338 strmsz_1 = fb_03.in_avail();
339 c2 = fb_03.sungetc(); // delete the 'a'
340 strmsz_2 = fb_03.in_avail();
aa1b2f7d
BV
341 VERIFY( c2 == 'v' ); // VERIFY( c2 != traits_type::eof() );
342 VERIFY( strmsz_1 + 1 == strmsz_2 );
b2dad0e3
BK
343 //test for _in_cur == _in_beg
344 for (int i = 50; i < 32 + 29; ++i)
345 fb_02.sputc(char(i));
346 fb_02.pubseekoff(0, std::ios_base::beg, std::ios_base::out);
347 strmsz_1 = fb_02.in_avail();
348 c1 = fb_02.sgetc();
349 c2 = fb_02.sungetc();
350 strmsz_2 = fb_02.in_avail();
351 c3 = fb_02.sgetc();
aa1b2f7d
BV
352 VERIFY( c1 == c2 );
353 VERIFY( c3 == c2 );
354 VERIFY( c1 == c3 );
355 VERIFY( c2 == traits_type::eof() );
356 VERIFY( strmsz_1 == strmsz_2 );
b2dad0e3
BK
357 //test for _in_cur == _in_end
358 fb_03.pubseekoff(0, std::ios_base::end);
359 strmsz_1 = fb_03.in_avail(); // -1 cuz at the end
360 c1 = fb_03.sgetc();
361 c2 = fb_03.sungetc();
362 strmsz_2 = fb_03.in_avail(); // 1
363 c3 = fb_03.sgetc();
aa1b2f7d
BV
364 VERIFY( c1 != c2 );
365 // VERIFY( c2 == c3 || c2 == traits_type::not_eof(int(c3)) );
366 VERIFY( strmsz_2 != strmsz_1 );
367 VERIFY( strmsz_2 == 1 );
b2dad0e3
BK
368 //test for ios_base::out
369
370 // BUFFER MANAGEMENT & POSITIONING
371 // int sync()
372 // if a put area exists, overflow.
373 // if a get area exists, do something undefined. (like, nothing)
374 strmsz_1 = fb_01.in_avail();
375 fb_01.pubsync();
376 strmsz_2 = fb_01.in_avail();
aa1b2f7d 377 VERIFY( strmsz_2 == strmsz_1 );
b2dad0e3
BK
378 strmsz_1 = fb_02.in_avail();
379 fb_02.pubsync();
380 // 27filebuf-2.txt == 53 bytes after this.
381 strmsz_2 = fb_02.in_avail();
aa1b2f7d
BV
382 VERIFY( strmsz_2 == -1 );
383 VERIFY( strmsz_2 == strmsz_1 );
b2dad0e3
BK
384 strmsz_1 = fb_03.in_avail();
385 fb_03.pubsync();
386 // 27filebuf-3.txt
387 // bd23456789mzuva?@ABCDEFGHIJKLMNOPQRSTUVWXYZracadabras, i wannaz
388 // 63 bytes.
389 strmsz_2 = fb_03.in_avail();
aa1b2f7d
BV
390 VERIFY( strmsz_1 == 1 );
391 VERIFY( strmsz_2 == 1 );
b2dad0e3
BK
392
393 // setbuf
394 // pubsetbuf(char_type* s, streamsize n)
395 fb_01.pubsetbuf(0,0);
396 fb_02.pubsetbuf(0,0);
397 fb_03.pubsetbuf(0,0);
398 // Need to test unbuffered output, which means calling this on some
399 // things that have just been opened.
400
401
402 // seekoff
403 // pubseekoff(off_type off, ios_base::seekdir way, ios_base::openmode which)
404 // alters the stream position to off
405 pos_type pt_1(off_type(-1));
406 pos_type pt_2(off_type(0));
407 off_type off_1 = 0;
408 off_type off_2 = 0;
409 //IN|OUT
410 // 27filebuf-3.txt = bd23456789:;<=>?...
411 //beg
412 strmsz_1 = fb_03.in_avail();
413 pt_1 = fb_03.pubseekoff(2, std::ios_base::beg);
414 strmsz_2 = fb_03.in_avail();
97e0a05a 415 off_1 = pt_1;
aa1b2f7d 416 VERIFY( off_1 > 0 );
b2dad0e3 417 c1 = fb_03.snextc(); //current in pointer +1
aa1b2f7d 418 VERIFY( c1 == '3' );
b2dad0e3
BK
419 c2 = fb_03.sputc('\n'); //current in pointer +1
420 c3 = fb_03.sgetc();
aa1b2f7d
BV
421 VERIFY( c2 != c3 );
422 VERIFY( c3 == '4' );
b2dad0e3
BK
423 fb_03.pubsync();
424 c1 = fb_03.sgetc();
aa1b2f7d 425 VERIFY( c1 == c3 );
b2dad0e3
BK
426 //cur
427 // 27filebuf-3.txt = bd2\n456789:;<=>?...
428 pt_2 = fb_03.pubseekoff(2, std::ios_base::cur);
97e0a05a 429 off_2 = pt_2;
aa1b2f7d 430 VERIFY( (off_2 == (off_1 + 2 + 1 + 1)) );
b2dad0e3 431 c1 = fb_03.snextc(); //current in pointer +1
aa1b2f7d 432 VERIFY( c1 == '7' );
b2dad0e3
BK
433 c2 = fb_03.sputc('x'); //test current out pointer
434 c3 = fb_03.sputc('\n');
435 c1 = fb_03.sgetc();
436 fb_03.pubsync();
437 c3 = fb_03.sgetc();
aa1b2f7d 438 VERIFY( c1 == c3 );
b2dad0e3
BK
439 //end
440 // 27filebuf-3.txt = "bd2\n456x\n9"
441 pt_2 = fb_03.pubseekoff(0, std::ios_base::end,
442 std::ios_base::in|std::ios_base::out);
97e0a05a 443 off_1 = pt_2;
aa1b2f7d 444 VERIFY( off_1 > off_2 ); //weak, but don't know exactly where it ends
b2dad0e3
BK
445 c3 = fb_03.sputc('\n');
446 strmsz_1 = fb_03.sputn("because because because. . .", 28);
aa1b2f7d 447 VERIFY( strmsz_1 == 28 );
b2dad0e3
BK
448 c1 = fb_03.sungetc();
449 fb_03.pubsync();
450 c3 = fb_03.sgetc();
aa1b2f7d 451 VERIFY( c1 == c3 );
b2dad0e3
BK
452 // IN
453 // OUT
454
455
456 // seekpos
457 // pubseekpos(pos_type sp, ios_base::openmode)
458 // alters the stream position to sp
459 //IN|OUT
460 //beg
461 pt_1 = fb_03.pubseekoff(78, std::ios_base::beg);
97e0a05a 462 off_1 = pt_1;
aa1b2f7d 463 VERIFY( off_1 > 0 );
b2dad0e3 464 c1 = fb_03.snextc(); //current in pointer +1
aa1b2f7d 465 VERIFY( c1 == ' ' );
b2dad0e3
BK
466 c2 = fb_03.sputc('\n'); //test current out pointer
467 c3 = fb_03.sgetc();
468 fb_03.pubsync(); //resets pointers
469 pt_2 = fb_03.pubseekpos(pt_1);
97e0a05a 470 off_2 = pt_2;
aa1b2f7d 471 VERIFY( off_1 == off_2 );
b2dad0e3 472 c3 = fb_03.snextc(); //current in pointer +1
aa1b2f7d 473 VERIFY( c2 == c3 );
b2dad0e3 474 pt_1 = fb_03.pubseekoff(0, std::ios_base::end);
97e0a05a 475 off_1 = pt_1;
aa1b2f7d 476 VERIFY( off_1 > off_2 );
b2dad0e3
BK
477 fb_03.sputn("\nof the wonderful things he does!!\nok", 37);
478 fb_03.pubsync();
479
480 // IN
481 // OUT
482
483 // VIRTUALS (indirectly tested)
484 // underflow
485 // if read position avail, returns *gptr()
486
487 // pbackfail(int_type c)
488 // put c back into input sequence
489
490 // overflow
491 // appends c to output seq
492
493 // NB Have to close these suckers. . .
494 // filebuf_type* close()
495 fb_01.close();
496 fb_02.close();
497 fb_03.close();
aa1b2f7d
BV
498 VERIFY( !fb_01.is_open() );
499 VERIFY( !fb_02.is_open() );
500 VERIFY( !fb_03.is_open() );
b2dad0e3
BK
501
502#ifdef DEBUG_ASSERT
503 assert(test);
504#endif
505
506 return test;
507}
508
c0b84d79
VE
509bool test04()
510{
511 using namespace std;
512 typedef istream::int_type int_type;
513
514 bool test = true;
515 ifstream ifs(name_02);
516 char buffer[] = "xxxxxxxxxx";
517 int_type len1 = ifs.rdbuf()->sgetn(buffer, sizeof(buffer));
aa1b2f7d
BV
518 VERIFY( len1 == sizeof(buffer) );
519 VERIFY( buffer[0] == 'a' );
b2dad0e3 520
c0b84d79
VE
521#ifdef DEBUG_ASSERT
522 assert(test);
523#endif
524 return test;
525}
526
c0a26060
BK
527// test05
528// libstdc++/1886
529// should be able to instantiate basic_filebuf for non-standard types.
530template class std::basic_filebuf<short, std::char_traits<short> >;
531
69302d8b
BK
532// test06
533// libstdc++/2020
534// should be able to use custom char_type
535class gnu_char_type
536{
537 unsigned long character;
538public:
539 // operator ==
540 bool
541 operator==(const gnu_char_type& __lhs)
542 { return character == __lhs.character; }
543
544 // operator <
545 bool
546 operator<(const gnu_char_type& __lhs)
547 { return character < __lhs.character; }
548
39003c99
BK
549 // default ctor
550 gnu_char_type() { }
551
69302d8b
BK
552 // to_char_type
553 gnu_char_type(const unsigned long& __l) : character(__l) { }
554
555 // to_int_type
556 operator unsigned long() const { return character; }
557};
558
559bool test06()
560{
561 bool test = true;
562 typedef std::basic_filebuf<gnu_char_type> gnu_filebuf;
563
564 try
565 { gnu_filebuf obj; }
566 catch(std::exception& obj)
567 {
568 test = false;
569 VERIFY( test );
570 }
571 return test;
572}
c0a26060 573
c0b84d79
VE
574int main()
575{
b2dad0e3
BK
576 test00();
577 test01();
578 test02();
579 test03();
c0b84d79 580 test04();
b2dad0e3 581
69302d8b 582 test06();
b2dad0e3
BK
583 return 0;
584}
585
586
587
588// more surf!!!