2 // Testing streambuf/filebuf/stringbuf for the C++ library testsuite.
4 // Copyright (C) 2003, 2004 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
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
39 // Used to verify the constraints/requirements on get and put areas
41 // 27.5.1 - Stream buffer requirements: get and put areas
42 // 27.8.1.1 - Template class basic_filebuf p 3
43 // If the file is not open (ios_base::in) -> input seq. cannot be read
44 // If the file is not open (ios_base::out) -> output seq. cannot be written
45 // Joint file position
46 // 27.8.1.4 - Overridden virtual functions p9
47 // If unbuffered, pbase == pptr == NULL
48 // 27.7.1.1 - Basic_stringbuf constructors p 1
49 // 27.8.1.2 - Basic_filebuf constructors p 1
50 // ... , initializing the base class with basic_streambuf() 27.5.2.1
59 bool one = this->pptr() != NULL;
60 bool two = this->pptr() < this->epptr();
67 bool one = this->gptr() != NULL;
68 bool two = this->gptr() < this->egptr();
75 bool one = this->pbase() == NULL;
76 bool two = this->pptr() == NULL;
83 bool one = this->eback() == NULL;
84 bool two = this->gptr() == NULL;
85 bool three = this->egptr() == NULL;
87 bool four = this->pbase() == NULL;
88 bool five = this->pptr() == NULL;
89 bool six = this->epptr() == NULL;
90 return one && two && three && four && five && six;
94 typedef constraint_buf<std::streambuf> constraint_streambuf;
95 typedef constraint_buf<std::filebuf> constraint_filebuf;
96 typedef constraint_buf<std::stringbuf> constraint_stringbuf;
97 #ifdef _GLIBCXX_USE_WCHAR_T
98 typedef constraint_buf<std::wstreambuf> constraint_wstreambuf;
99 typedef constraint_buf<std::wfilebuf> constraint_wfilebuf;
100 typedef constraint_buf<std::wstringbuf> constraint_wstringbuf;
103 // Used to check if basic_streambuf::pubsync() has been called.
104 // This is useful for checking if a function creates [io]stream::sentry
105 // objects, since the sentry constructors call tie()->flush().
115 : m_sync_called(false)
118 bool sync_called() const
119 { return m_sync_called; }
124 m_sync_called = true;
129 typedef sync_buf<std::streambuf> sync_streambuf;
130 #ifdef _GLIBCXX_USE_WCHAR_T
131 typedef sync_buf<std::wstreambuf> sync_wstreambuf;
134 // Throws on all overflow and underflow calls.
135 struct underflow_error: std::exception { };
136 struct overflow_error: std::exception { };
137 struct positioning_error: std::exception { };
143 typedef typename T::char_type char_type;
144 typedef typename T::int_type int_type;
145 typedef typename T::off_type off_type;
146 typedef typename T::pos_type pos_type;
154 p[0] = char_type('s');
159 virtual int_type underflow()
161 throw underflow_error();
165 virtual int_type uflow()
167 throw underflow_error();
174 throw overflow_error();
179 seekoff(off_type, std::ios_base::seekdir, std::ios_base::openmode)
181 throw positioning_error();
182 return pos_type(off_type(-1));
186 seekpos(pos_type, std::ios_base::openmode)
188 throw positioning_error();
189 return pos_type(off_type(-1));
195 throw positioning_error();
200 typedef fail_buf<std::streambuf> fail_streambuf;
201 #ifdef _GLIBCXX_USE_WCHAR_T
202 typedef fail_buf<std::wstreambuf> fail_wstreambuf;
205 // Facets that throw an exception for every virtual function.
206 struct facet_error: std::exception { };
210 : public std::num_get<T>
212 typedef std::ios_base ios_base;
213 typedef typename std::num_get<T>::iter_type iter_type;
217 do_get(iter_type a, iter_type, ios_base&, ios_base::iostate&, bool&) const
218 { throw facet_error(); return iter_type(); }
221 do_get(iter_type, iter_type, ios_base&, ios_base::iostate&, long&) const
222 { throw facet_error(); return iter_type(); }
225 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
226 unsigned short&) const
227 { throw facet_error(); return iter_type(); }
230 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
232 { throw facet_error(); return iter_type(); }
235 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
236 unsigned long&) const
237 { throw facet_error(); return iter_type(); }
239 #ifdef _GLIBCXX_USE_LONG_LONG
241 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
243 { throw facet_error(); return iter_type(); }
246 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
247 unsigned long long&) const
248 { throw facet_error(); return iter_type(); }
252 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
254 { throw facet_error(); return iter_type(); }
257 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
259 { throw facet_error(); return iter_type(); }
262 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
264 { throw facet_error(); return iter_type(); }
267 do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
269 { throw facet_error(); return iter_type(); }
272 typedef fail_num_get<char> fail_num_get_char;
273 #ifdef _GLIBCXX_USE_WCHAR_T
274 typedef fail_num_get<wchar_t> fail_num_get_wchar_t;
279 : public std::num_put<T>
281 typedef std::ios_base ios_base;
282 typedef typename std::num_put<T>::iter_type iter_type;
283 typedef typename std::num_put<T>::char_type char_type;
287 do_put(iter_type, ios_base&, char_type __fill, bool __v) const
288 { throw facet_error(); return iter_type(NULL); }
291 do_put(iter_type, ios_base&, char_type __fill, long __v) const
292 { throw facet_error(); return iter_type(NULL); }
295 do_put(iter_type, ios_base&, char_type __fill, unsigned long) const
296 { throw facet_error(); return iter_type(NULL); }
298 #ifdef _GLIBCXX_USE_LONG_LONG
300 do_put(iter_type, ios_base&, char_type __fill, long long __v) const
301 { throw facet_error(); return iter_type(NULL); }
304 do_put(iter_type, ios_base&, char_type __fill, unsigned long long) const
305 { throw facet_error(); return iter_type(NULL); }
309 do_put(iter_type, ios_base&, char_type __fill, double __v) const
310 { throw facet_error(); return iter_type(NULL); }
313 do_put(iter_type, ios_base&, char_type __fill, long double __v) const
314 { throw facet_error(); return iter_type(NULL); }
317 do_put(iter_type, ios_base&, char_type __fill, const void* __v) const
318 { throw facet_error(); return iter_type(NULL); }
321 typedef fail_num_put<char> fail_num_put_char;
322 #ifdef _GLIBCXX_USE_WCHAR_T
323 typedef fail_num_put<wchar_t> fail_num_put_wchar_t;
325 }; // namespace __gnu_test
327 #endif // _GLIBCXX_TESTSUITE_IO_H