]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/util/testsuite_io.h
2 // Testing streambuf/filebuf/stringbuf for the C++ library testsuite.
4 // Copyright (C) 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
6 // This file is part of the GNU ISO C++ Library. This library is free
7 // software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the
9 // Free Software Foundation; either version 2, or (at your option)
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License along
18 // with this library; see the file COPYING. If not, write to the Free
19 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
22 // As a special exception, you may use this file as part of a free software
23 // library without restriction. Specifically, if other files instantiate
24 // templates or use macros or inline functions from this file, or you compile
25 // this file and link it with other files to produce an executable, this
26 // file does not by itself cause the resulting executable to be covered by
27 // the GNU General Public License. This exception does not however
28 // invalidate any other reasons why the executable file might be covered by
29 // the GNU General Public License.
31 #ifndef _GLIBCXX_TESTSUITE_IO_H
32 #define _GLIBCXX_TESTSUITE_IO_H
38 // Used to verify the constraints/requirements on get and put areas
40 // 27.5.1 - Stream buffer requirements: get and put areas
41 // 27.8.1.1 - Template class basic_filebuf p 3
42 // If the file is not open (ios_base::in) -> input seq. cannot be read
43 // If the file is not open (ios_base::out) -> output seq. cannot be written
44 // Joint file position
45 // 27.8.1.4 - Overridden virtual functions p9
46 // If unbuffered, pbase == pptr == NULL
47 // 27.7.1.1 - Basic_stringbuf constructors p 1
48 // 27.8.1.2 - Basic_filebuf constructors p 1
49 // ... , initializing the base class with basic_streambuf() 27.5.2.1
58 bool one
= this->pptr() != NULL
;
59 bool two
= this->pptr() < this->epptr();
66 bool one
= this->gptr() != NULL
;
67 bool two
= this->gptr() < this->egptr();
74 bool one
= this->pbase() == NULL
;
75 bool two
= this->pptr() == NULL
;
82 bool one
= this->eback() == NULL
;
83 bool two
= this->gptr() == NULL
;
84 bool three
= this->egptr() == NULL
;
86 bool four
= this->pbase() == NULL
;
87 bool five
= this->pptr() == NULL
;
88 bool six
= this->epptr() == NULL
;
89 return one
&& two
&& three
&& four
&& five
&& six
;
93 typedef constraint_buf
<std::streambuf
> constraint_streambuf
;
94 typedef constraint_buf
<std::filebuf
> constraint_filebuf
;
95 typedef constraint_buf
<std::stringbuf
> constraint_stringbuf
;
96 #ifdef _GLIBCXX_USE_WCHAR_T
97 typedef constraint_buf
<std::wstreambuf
> constraint_wstreambuf
;
98 typedef constraint_buf
<std::wfilebuf
> constraint_wfilebuf
;
99 typedef constraint_buf
<std::wstringbuf
> constraint_wstringbuf
;
102 // Used to check if basic_streambuf::pubsync() has been called.
103 // This is useful for checking if a function creates [io]stream::sentry
104 // objects, since the sentry constructors call tie()->flush().
114 : m_sync_called(false)
117 bool sync_called() const
118 { return m_sync_called
; }
123 m_sync_called
= true;
128 typedef sync_buf
<std::streambuf
> sync_streambuf
;
129 #ifdef _GLIBCXX_USE_WCHAR_T
130 typedef sync_buf
<std::wstreambuf
> sync_wstreambuf
;
133 // Throws on all overflow and underflow calls.
134 struct underflow_error
: std::exception
{ };
135 struct overflow_error
: std::exception
{ };
136 struct positioning_error
: std::exception
{ };
142 typedef typename
T::char_type char_type
;
143 typedef typename
T::int_type int_type
;
144 typedef typename
T::off_type off_type
;
145 typedef typename
T::pos_type pos_type
;
153 p
[0] = char_type('s');
158 virtual int_type
underflow()
160 throw underflow_error();
164 virtual int_type
uflow()
166 throw underflow_error();
173 throw overflow_error();
178 seekoff(off_type
, std::ios_base::seekdir
, std::ios_base::openmode
)
180 throw positioning_error();
181 return pos_type(off_type(-1));
185 seekpos(pos_type
, std::ios_base::openmode
)
187 throw positioning_error();
188 return pos_type(off_type(-1));
194 throw positioning_error();
199 typedef fail_buf
<std::streambuf
> fail_streambuf
;
200 #ifdef _GLIBCXX_USE_WCHAR_T
201 typedef fail_buf
<std::wstreambuf
> fail_wstreambuf
;
204 // Facets that throw an exception for every virtual function.
205 struct facet_error
: std::exception
{ };
209 : public std::num_get
<T
>
211 typedef std::ios_base ios_base
;
212 typedef typename
std::num_get
<T
>::iter_type iter_type
;
216 do_get(iter_type
, iter_type
, ios_base
&, ios_base::iostate
&, bool&) const
217 { throw facet_error(); return iter_type(); }
220 do_get(iter_type
, iter_type
, ios_base
&, ios_base::iostate
&, long&) const
221 { throw facet_error(); return iter_type(); }
224 do_get(iter_type
, iter_type
, ios_base
&, ios_base::iostate
&,
225 unsigned short&) const
226 { throw facet_error(); return iter_type(); }
229 do_get(iter_type
, iter_type
, ios_base
&, ios_base::iostate
&,
231 { throw facet_error(); return iter_type(); }
234 do_get(iter_type
, iter_type
, ios_base
&, ios_base::iostate
&,
235 unsigned long&) const
236 { throw facet_error(); return iter_type(); }
238 #ifdef _GLIBCXX_USE_LONG_LONG
240 do_get(iter_type
, iter_type
, ios_base
&, ios_base::iostate
&,
242 { throw facet_error(); return iter_type(); }
245 do_get(iter_type
, iter_type
, ios_base
&, ios_base::iostate
&,
246 unsigned long long&) const
247 { throw facet_error(); return iter_type(); }
251 do_get(iter_type
, iter_type
, ios_base
&, ios_base::iostate
&,
253 { throw facet_error(); return iter_type(); }
256 do_get(iter_type
, iter_type
, ios_base
&, ios_base::iostate
&,
258 { throw facet_error(); return iter_type(); }
261 do_get(iter_type
, iter_type
, ios_base
&, ios_base::iostate
&,
263 { throw facet_error(); return iter_type(); }
266 do_get(iter_type
, iter_type
, ios_base
&, ios_base::iostate
&,
268 { throw facet_error(); return iter_type(); }
271 typedef fail_num_get
<char> fail_num_get_char
;
272 #ifdef _GLIBCXX_USE_WCHAR_T
273 typedef fail_num_get
<wchar_t> fail_num_get_wchar_t
;
278 : public std::num_put
<T
>
280 typedef std::ios_base ios_base
;
281 typedef typename
std::num_put
<T
>::iter_type iter_type
;
282 typedef typename
std::num_put
<T
>::char_type char_type
;
286 do_put(iter_type
, ios_base
&, char_type
, bool) const
287 { throw facet_error(); return iter_type(NULL
); }
290 do_put(iter_type
, ios_base
&, char_type
, long) const
291 { throw facet_error(); return iter_type(NULL
); }
294 do_put(iter_type
, ios_base
&, char_type
, unsigned long) const
295 { throw facet_error(); return iter_type(NULL
); }
297 #ifdef _GLIBCXX_USE_LONG_LONG
299 do_put(iter_type
, ios_base
&, char_type
, long long) const
300 { throw facet_error(); return iter_type(NULL
); }
303 do_put(iter_type
, ios_base
&, char_type
, unsigned long long) const
304 { throw facet_error(); return iter_type(NULL
); }
308 do_put(iter_type
, ios_base
&, char_type
, double) const
309 { throw facet_error(); return iter_type(NULL
); }
312 do_put(iter_type
, ios_base
&, char_type
, long double) const
313 { throw facet_error(); return iter_type(NULL
); }
316 do_put(iter_type
, ios_base
&, char_type
, const void*) const
317 { throw facet_error(); return iter_type(NULL
); }
320 typedef fail_num_put
<char> fail_num_put_char
;
321 #ifdef _GLIBCXX_USE_WCHAR_T
322 typedef fail_num_put
<wchar_t> fail_num_put_wchar_t
;
324 }; // namespace __gnu_test
326 #endif // _GLIBCXX_TESTSUITE_IO_H