]>
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, 2009, 2010
5 // Free Software Foundation, Inc.
7 // This file is part of the GNU ISO C++ Library. This library is free
8 // software; you can redistribute it and/or modify it under the
9 // terms of the GNU General Public License as published by the
10 // Free Software Foundation; either version 3, or (at your option)
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License along
19 // with this library; see the file COPYING3. If not see
20 // <http://www.gnu.org/licenses/>.
23 #ifndef _GLIBCXX_TESTSUITE_IO_H
24 #define _GLIBCXX_TESTSUITE_IO_H
30 // Used to verify the constraints/requirements on get and put areas
32 // 27.5.1 - Stream buffer requirements: get and put areas
33 // 27.8.1.1 - Template class basic_filebuf p 3
34 // If the file is not open (ios_base::in) -> input seq. cannot be read
35 // If the file is not open (ios_base::out) -> output seq. cannot be written
36 // Joint file position
37 // 27.8.1.4 - Overridden virtual functions p9
38 // If unbuffered, pbase == pptr == NULL
39 // 27.7.1.1 - Basic_stringbuf constructors p 1
40 // 27.8.1.2 - Basic_filebuf constructors p 1
41 // ... , initializing the base class with basic_streambuf() 27.5.2.1
50 bool one
= this->pptr() != 0;
51 bool two
= this->pptr() < this->epptr();
58 bool one
= this->gptr() != 0;
59 bool two
= this->gptr() < this->egptr();
66 bool one
= this->pbase() == 0;
67 bool two
= this->pptr() == 0;
74 bool one
= this->eback() == 0;
75 bool two
= this->gptr() == 0;
76 bool three
= this->egptr() == 0;
78 bool four
= this->pbase() == 0;
79 bool five
= this->pptr() == 0;
80 bool six
= this->epptr() == 0;
81 return one
&& two
&& three
&& four
&& five
&& six
;
85 typedef constraint_buf
<std::streambuf
> constraint_streambuf
;
86 typedef constraint_buf
<std::filebuf
> constraint_filebuf
;
87 typedef constraint_buf
<std::stringbuf
> constraint_stringbuf
;
88 #ifdef _GLIBCXX_USE_WCHAR_T
89 typedef constraint_buf
<std::wstreambuf
> constraint_wstreambuf
;
90 typedef constraint_buf
<std::wfilebuf
> constraint_wfilebuf
;
91 typedef constraint_buf
<std::wstringbuf
> constraint_wstringbuf
;
94 // Used to check if basic_streambuf::pubsync() has been called.
95 // This is useful for checking if a function creates [io]stream::sentry
96 // objects, since the sentry constructors call tie()->flush().
106 : m_sync_called(false)
109 bool sync_called() const
110 { return m_sync_called
; }
115 m_sync_called
= true;
120 typedef sync_buf
<std::streambuf
> sync_streambuf
;
121 #ifdef _GLIBCXX_USE_WCHAR_T
122 typedef sync_buf
<std::wstreambuf
> sync_wstreambuf
;
125 // Throws on all overflow and underflow calls.
126 struct underflow_error
: std::exception
{ };
127 struct overflow_error
: std::exception
{ };
128 struct positioning_error
: std::exception
{ };
134 typedef typename
T::char_type char_type
;
135 typedef typename
T::int_type int_type
;
136 typedef typename
T::off_type off_type
;
137 typedef typename
T::pos_type pos_type
;
145 p
[0] = char_type('s');
147 this->setg(p
, p
, p
+ 1);
150 virtual int_type
underflow()
152 throw underflow_error();
156 virtual int_type
uflow()
158 throw underflow_error();
165 throw overflow_error();
170 seekoff(off_type
, std::ios_base::seekdir
, std::ios_base::openmode
)
172 throw positioning_error();
173 return pos_type(off_type(-1));
177 seekpos(pos_type
, std::ios_base::openmode
)
179 throw positioning_error();
180 return pos_type(off_type(-1));
186 throw positioning_error();
191 typedef fail_buf
<std::streambuf
> fail_streambuf
;
192 #ifdef _GLIBCXX_USE_WCHAR_T
193 typedef fail_buf
<std::wstreambuf
> fail_wstreambuf
;
196 // Facets that throw an exception for every virtual function.
197 struct facet_error
: std::exception
{ };
201 : public std::num_get
<T
>
203 typedef std::ios_base ios_base
;
204 typedef typename
std::num_get
<T
>::iter_type iter_type
;
208 do_get(iter_type
, iter_type
, ios_base
&, ios_base::iostate
&, bool&) const
209 { throw facet_error(); return iter_type(); }
212 do_get(iter_type
, iter_type
, ios_base
&, ios_base::iostate
&, long&) const
213 { throw facet_error(); return iter_type(); }
216 do_get(iter_type
, iter_type
, ios_base
&, ios_base::iostate
&,
217 unsigned short&) const
218 { throw facet_error(); return iter_type(); }
221 do_get(iter_type
, iter_type
, ios_base
&, ios_base::iostate
&,
223 { throw facet_error(); return iter_type(); }
226 do_get(iter_type
, iter_type
, ios_base
&, ios_base::iostate
&,
227 unsigned long&) const
228 { throw facet_error(); return iter_type(); }
230 #ifdef _GLIBCXX_USE_LONG_LONG
232 do_get(iter_type
, iter_type
, ios_base
&, ios_base::iostate
&,
234 { throw facet_error(); return iter_type(); }
237 do_get(iter_type
, iter_type
, ios_base
&, ios_base::iostate
&,
238 unsigned long long&) const
239 { throw facet_error(); return iter_type(); }
243 do_get(iter_type
, iter_type
, ios_base
&, ios_base::iostate
&,
245 { throw facet_error(); return iter_type(); }
248 do_get(iter_type
, iter_type
, ios_base
&, ios_base::iostate
&,
250 { throw facet_error(); return iter_type(); }
253 do_get(iter_type
, iter_type
, ios_base
&, ios_base::iostate
&,
255 { throw facet_error(); return iter_type(); }
258 do_get(iter_type
, iter_type
, ios_base
&, ios_base::iostate
&,
260 { throw facet_error(); return iter_type(); }
263 typedef fail_num_get
<char> fail_num_get_char
;
264 #ifdef _GLIBCXX_USE_WCHAR_T
265 typedef fail_num_get
<wchar_t> fail_num_get_wchar_t
;
270 : public std::num_put
<T
>
272 typedef std::ios_base ios_base
;
273 typedef typename
std::num_put
<T
>::iter_type iter_type
;
274 typedef typename
std::num_put
<T
>::char_type char_type
;
278 do_put(iter_type
, ios_base
&, char_type
, bool) const
279 { throw facet_error(); return iter_type(0); }
282 do_put(iter_type
, ios_base
&, char_type
, long) const
283 { throw facet_error(); return iter_type(0); }
286 do_put(iter_type
, ios_base
&, char_type
, unsigned long) const
287 { throw facet_error(); return iter_type(0); }
289 #ifdef _GLIBCXX_USE_LONG_LONG
291 do_put(iter_type
, ios_base
&, char_type
, long long) const
292 { throw facet_error(); return iter_type(0); }
295 do_put(iter_type
, ios_base
&, char_type
, unsigned long long) const
296 { throw facet_error(); return iter_type(0); }
300 do_put(iter_type
, ios_base
&, char_type
, double) const
301 { throw facet_error(); return iter_type(0); }
304 do_put(iter_type
, ios_base
&, char_type
, long double) const
305 { throw facet_error(); return iter_type(0); }
308 do_put(iter_type
, ios_base
&, char_type
, const void*) const
309 { throw facet_error(); return iter_type(0); }
312 typedef fail_num_put
<char> fail_num_put_char
;
313 #ifdef _GLIBCXX_USE_WCHAR_T
314 typedef fail_num_put
<wchar_t> fail_num_put_wchar_t
;
316 } // namespace __gnu_test
318 #endif // _GLIBCXX_TESTSUITE_IO_H