]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/27_io/basic_filebuf/sbumpc/char/1.cc
Reshuffle 27_io testsuite.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 27_io / basic_filebuf / sbumpc / char / 1.cc
1 // 2001-05-21 Benjamin Kosnik <bkoz@redhat.com>
2
3 // Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc.
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 // 27.8.1.4 Overridden virtual functions
22
23 #include <fstream>
24 #include <testsuite_hooks.h>
25
26 // @require@ %-*.tst %-*.txt
27 // @diff@ %-*.tst %*.txt
28
29 // NB: This test assumes that _M_buf_size == 40, and not the usual
30 // buffer_size length of BUFSIZ (8192), so that overflow/underflow can be
31 // simulated a bit more readily.
32 // NRB (Nota Really Bene): setting it to 40 breaks the test, as intended.
33 const int buffer_size = 8192;
34 //const int buffer_size = 40;
35
36 const char name_01[] = "filebuf_virtuals-1.txt"; // file with data in it
37 const char name_02[] = "filebuf_virtuals-2.txt"; // empty file, need to create
38 const char name_03[] = "filebuf_virtuals-3.txt"; // empty file, need to create
39
40 class derived_filebuf: public std::filebuf
41 {
42 public:
43 void
44 set_size(int_type __size) { _M_buf_size_opt = __size; }
45 };
46
47 derived_filebuf fb_01; // in
48 derived_filebuf fb_02; // out
49 derived_filebuf fb_03; // in | out
50
51 // Initialize filebufs to be the same size regardless of platform.
52 void test03()
53 {
54 fb_01.set_size(buffer_size);
55 fb_02.set_size(buffer_size);
56 fb_03.set_size(buffer_size);
57 }
58
59 // Test overloaded virtual functions.
60 void test05()
61 {
62 using namespace std;
63 typedef filebuf::int_type int_type;
64 typedef filebuf::traits_type traits_type;
65 typedef filebuf::pos_type pos_type;
66 typedef filebuf::off_type off_type;
67 typedef size_t size_type;
68
69 bool test = true;
70 filebuf f_tmp;
71 streamsize strmsz_1, strmsz_2;
72 streamoff strmof_1, strmof_2;
73 int i = 0, j = 0, k = 0;
74
75 // GET
76 fb_01.open(name_01, ios_base::in);
77 fb_02.open(name_02, ios_base::out | ios_base::trunc);
78 fb_03.open(name_03, ios_base::out | ios_base::in | ios_base::trunc);
79 strmof_1 = fb_01.in_avail();
80 strmof_2 = fb_02.in_avail();
81 strmof_1 = fb_03.in_avail();
82
83 // int_type sbumpc()
84 // if read_cur not avail returns uflow(), else return *read_cur & increment
85 int_type c1 = fb_01.sbumpc();
86 int_type c2 = fb_02.sbumpc();
87 VERIFY( c1 != c2 );
88 VERIFY( c1 == '/' );
89 VERIFY( c2 == -1 );
90 int_type c3 = fb_01.sbumpc();
91 int_type c4 = fb_02.sbumpc();
92 VERIFY( c3 != c4 );
93 VERIFY( c1 == c3 ); // fluke, both happen to be '/'
94 VERIFY( c2 == c4 );
95 int_type c5 = fb_03.sbumpc();
96 VERIFY( c5 == traits_type::eof() );
97 // XXX should do some kind of test to make sure that internal
98 // buffers point to the same thing, to check consistancy.
99 }
100
101 main()
102 {
103 test03();
104 test05();
105 return 0;
106 }