]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/27_io/basic_filebuf/in_avail/char/1.cc
1 // 2001-05-21 Benjamin Kosnik <bkoz@redhat.com>
3 // Copyright (C) 2001-2021 Free Software Foundation, Inc.
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 3, 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 COPYING3. If not see
18 // <http://www.gnu.org/licenses/>.
20 // 27.8.1.4 Overridden virtual functions
22 // { dg-require-fileio "" }
25 #include <testsuite_hooks.h>
27 // @require@ %-*.tst %-*.txt
28 // @diff@ %-*.tst %*.txt
30 // NB: This test assumes that _M_buf_size == 40, and not the usual
31 // buffer_size length of BUFSIZ (8192), so that overflow/underflow can be
32 // simulated a bit more readily.
33 // NRB (Nota Really Bene): setting it to 40 breaks the test, as intended.
34 const int buffer_size
= 8192;
35 //const int buffer_size = 40;
37 const char name_01
[] = "filebuf_virtuals-1.txt"; // file with data in it
38 const char name_02
[] = "filebuf_virtuals-2.txt"; // empty file, need to create
39 const char name_03
[] = "filebuf_virtuals-3.txt"; // empty file, need to create
41 class derived_filebuf
: public std::filebuf
45 set_size(int_type __size
) { _M_buf_size
= __size
; }
48 derived_filebuf fb_01
; // in
49 derived_filebuf fb_02
; // out
50 derived_filebuf fb_03
; // in | out
52 // Initialize filebufs to be the same size regardless of platform.
55 fb_01
.set_size(buffer_size
);
56 fb_02
.set_size(buffer_size
);
57 fb_03
.set_size(buffer_size
);
60 // Test overloaded virtual functions.
63 typedef std::filebuf::int_type int_type
;
64 typedef std::filebuf::traits_type traits_type
;
65 typedef std::filebuf::pos_type pos_type
;
66 typedef std::filebuf::off_type off_type
;
67 typedef size_t size_type
;
70 std::streamoff strmof_1
, strmof_2
;
74 // if a read position is available, return _M_in_end - _M_in_cur.
75 // else return showmanyc.
76 strmof_1
= fb_01
.in_avail();
77 strmof_2
= fb_02
.in_avail();
78 VERIFY( strmof_1
== -1 );
79 VERIFY( strmof_1
== strmof_2
); //fail because not open
80 strmof_1
= fb_03
.in_avail();
81 VERIFY( strmof_1
== strmof_2
);
82 fb_01
.open(name_01
, std::ios_base::in
);
83 fb_02
.open(name_02
, std::ios_base::out
| std::ios_base::trunc
);
84 fb_03
.open(name_03
, std::ios_base::out
| std::ios_base::in
| std::ios_base::trunc
);
85 strmof_1
= fb_01
.in_avail();
86 strmof_2
= fb_02
.in_avail();
87 VERIFY( strmof_1
!= strmof_2
);
88 VERIFY( strmof_1
>= 0 );
89 VERIFY( strmof_2
== -1 ); // empty file
90 strmof_1
= fb_03
.in_avail();
91 VERIFY( strmof_1
== 0 ); // empty file