From 46c4e5d6e9e539d736eebbd7cab1d76a569af11a Mon Sep 17 00:00:00 2001 From: Benjamin Kosnik Date: Fri, 6 Jun 2003 00:19:17 +0000 Subject: [PATCH] re PR libstdc++/9024 (Input fails after call to basic_filebuf<>::pubsetbuf(0, 0)) 2003-06-05 Benjamin Kosnik PR libstdc++/9024 * include/bits/fstream.tcc (_M_underflow): Fix for unbuffered. * include/bits/stl_algobase.h: Tweak. * include/std/std_fstream.h: Move _M_buf_size to... * include/std/std_streambuf.h: ...here. Modify. * include/bits/streambuf.tcc: Same. * testsuite/testsuite_hooks.h: Tweak. * testsuite/testsuite_io.h (constraint_filebuf): New. * testsuite/27_io/basic_filebuf/sbumpc/char/1.cc: Split into... * testsuite/27_io/basic_filebuf/sbumpc/char/1-in.cc: New. * testsuite/27_io/basic_filebuf/sbumpc/char/1-io.cc: New. * testsuite/27_io/basic_filebuf/sbumpc/char/1-out.cc: New. * testsuite/27_io/basic_filebuf/sbumpc/char/2-in.cc: New. * testsuite/27_io/basic_filebuf/sbumpc/char/2-io.cc: New. * testsuite/27_io/basic_filebuf/sbumpc/char/2-out.cc: New. * testsuite/27_io/basic_filebuf/sgetc/char/1.cc: Split into... * testsuite/27_io/basic_filebuf/sgetc/char/1-in.cc: New. * testsuite/27_io/basic_filebuf/sgetc/char/1-io.cc: New. * testsuite/27_io/basic_filebuf/sgetc/char/1-out.cc: New. * testsuite/27_io/basic_filebuf/sgetc/char/2-in.cc: New. * testsuite/27_io/basic_filebuf/sgetc/char/2-io.cc: New. * testsuite/27_io/basic_filebuf/sgetc/char/2-out.cc: New. * testsuite/27_io/basic_filebuf/sgetn/char/1.cc: Split into... * testsuite/27_io/basic_filebuf/sgetn/char/1-in.cc: New. * testsuite/27_io/basic_filebuf/sgetn/char/1-io.cc: New. * testsuite/27_io/basic_filebuf/sgetn/char/1-out.cc: New. * testsuite/27_io/basic_filebuf/sgetn/char/2.cc: Split into... * testsuite/27_io/basic_filebuf/sgetn/char/2-in.cc: New. * testsuite/27_io/basic_filebuf/sgetn/char/2-io.cc: New. * testsuite/27_io/basic_filebuf/sgetn/char/2-out.cc: New. * testsuite/27_io/basic_filebuf/sgetn/char/3.cc: New. * testsuite/27_io/basic_filebuf/snextc/char/1.cc: Split into... * testsuite/27_io/basic_filebuf/snextc/char/1-in.cc: New. * testsuite/27_io/basic_filebuf/snextc/char/1-io.cc: New. * testsuite/27_io/basic_filebuf/snextc/char/1-out.cc: New. * testsuite/27_io/basic_filebuf/snextc/char/2-in.cc: New. * testsuite/27_io/basic_filebuf/snextc/char/2-io.cc: New. * testsuite/27_io/basic_filebuf/snextc/char/2-out.cc: New. * testsuite/27_io/basic_filebuf/sputc/char/1.cc: Split into... * testsuite/27_io/basic_filebuf/sputc/char/1-in.cc: New. * testsuite/27_io/basic_filebuf/sputc/char/1-io.cc: New. * testsuite/27_io/basic_filebuf/sputc/char/1-out.cc: New. * testsuite/27_io/basic_filebuf/sputc/char/2.cc: Split into... * testsuite/27_io/basic_filebuf/sputc/char/2-in.cc: New. * testsuite/27_io/basic_filebuf/sputc/char/2-io.cc: New. * testsuite/27_io/basic_filebuf/sputc/char/2-out.cc: New. * testsuite/27_io/basic_filebuf/sputn/char/1.cc: Split into... * testsuite/27_io/basic_filebuf/sputn/char/1-in.cc: New. * testsuite/27_io/basic_filebuf/sputn/char/1-io.cc: New. * testsuite/27_io/basic_filebuf/sputn/char/1-out.cc: New. * testsuite/27_io/basic_filebuf/sputn/char/2-in.cc: New. * testsuite/27_io/basic_filebuf/sputn/char/2-io.cc: New. * testsuite/27_io/basic_filebuf/sputn/char/2-out.cc: New. * testsuite/data/sgetc.txt: New. * testsuite/data/sgetn.txt: New. From-SVN: r67524 --- libstdc++-v3/ChangeLog | 81 +++++++-- libstdc++-v3/include/bits/fstream.tcc | 100 +++++++---- libstdc++-v3/include/bits/stl_algobase.h | 170 +++++++----------- libstdc++-v3/include/bits/streambuf.tcc | 6 +- libstdc++-v3/include/std/std_fstream.h | 22 +-- libstdc++-v3/include/std/std_streambuf.h | 37 ++-- .../27_io/basic_filebuf/sbumpc/char/1-in.cc | 79 ++++++++ .../27_io/basic_filebuf/sbumpc/char/1-io.cc | 92 ++++++++++ .../27_io/basic_filebuf/sbumpc/char/1-out.cc | 63 +++++++ .../27_io/basic_filebuf/sbumpc/char/1.cc | 106 ----------- .../27_io/basic_filebuf/sbumpc/char/2-in.cc | 79 ++++++++ .../27_io/basic_filebuf/sbumpc/char/2-io.cc | 91 ++++++++++ .../27_io/basic_filebuf/sbumpc/char/2-out.cc | 64 +++++++ .../27_io/basic_filebuf/sgetc/char/1-in.cc | 71 ++++++++ .../27_io/basic_filebuf/sgetc/char/1-io.cc | 86 +++++++++ .../27_io/basic_filebuf/sgetc/char/1-out.cc | 69 +++++++ .../27_io/basic_filebuf/sgetc/char/1.cc | 107 ----------- .../27_io/basic_filebuf/sgetc/char/2-in.cc | 71 ++++++++ .../27_io/basic_filebuf/sgetc/char/2-io.cc | 85 +++++++++ .../27_io/basic_filebuf/sgetc/char/2-out.cc | 70 ++++++++ .../27_io/basic_filebuf/sgetn/char/1-in.cc | 83 +++++++++ .../27_io/basic_filebuf/sgetn/char/1-io.cc | 96 ++++++++++ .../27_io/basic_filebuf/sgetn/char/1-out.cc | 79 ++++++++ .../27_io/basic_filebuf/sgetn/char/1.cc | 148 --------------- .../27_io/basic_filebuf/sgetn/char/2-in.cc | 83 +++++++++ .../27_io/basic_filebuf/sgetn/char/2-io.cc | 95 ++++++++++ .../27_io/basic_filebuf/sgetn/char/2-out.cc | 79 ++++++++ .../basic_filebuf/sgetn/char/{2.cc => 3.cc} | 2 +- .../27_io/basic_filebuf/snextc/char/1-in.cc | 84 +++++++++ .../27_io/basic_filebuf/snextc/char/1-io.cc | 83 +++++++++ .../27_io/basic_filebuf/snextc/char/1-out.cc | 66 +++++++ .../27_io/basic_filebuf/snextc/char/1.cc | 116 ------------ .../27_io/basic_filebuf/snextc/char/2-in.cc | 82 +++++++++ .../27_io/basic_filebuf/snextc/char/2-io.cc | 81 +++++++++ .../27_io/basic_filebuf/snextc/char/2-out.cc | 63 +++++++ .../27_io/basic_filebuf/sputc/char/1-in.cc | 65 +++++++ .../27_io/basic_filebuf/sputc/char/1-io.cc | 72 ++++++++ .../27_io/basic_filebuf/sputc/char/1-out.cc | 71 ++++++++ .../27_io/basic_filebuf/sputc/char/1.cc | 124 ------------- .../27_io/basic_filebuf/sputc/char/2-in.cc | 66 +++++++ .../27_io/basic_filebuf/sputc/char/2-io.cc | 71 ++++++++ .../27_io/basic_filebuf/sputc/char/2-out.cc | 72 ++++++++ .../27_io/basic_filebuf/sputc/char/2.cc | 129 ------------- .../27_io/basic_filebuf/sputn/char/1-in.cc | 63 +++++++ .../27_io/basic_filebuf/sputn/char/1-io.cc | 69 +++++++ .../27_io/basic_filebuf/sputn/char/1-out.cc | 65 +++++++ .../27_io/basic_filebuf/sputn/char/1.cc | 112 ------------ .../27_io/basic_filebuf/sputn/char/2-in.cc | 64 +++++++ .../27_io/basic_filebuf/sputn/char/2-io.cc | 68 +++++++ .../27_io/basic_filebuf/sputn/char/2-out.cc | 66 +++++++ libstdc++-v3/testsuite/data/sgetc.txt | 3 + libstdc++-v3/testsuite/data/sgetn.txt | 158 ++++++++++++++++ libstdc++-v3/testsuite/testsuite_hooks.h | 2 + libstdc++-v3/testsuite/testsuite_io.h | 79 ++++++++ 54 files changed, 3190 insertions(+), 1018 deletions(-) create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/sbumpc/char/1-in.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/sbumpc/char/1-io.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/sbumpc/char/1-out.cc delete mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/sbumpc/char/1.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/sbumpc/char/2-in.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/sbumpc/char/2-io.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/sbumpc/char/2-out.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/sgetc/char/1-in.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/sgetc/char/1-io.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/sgetc/char/1-out.cc delete mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/sgetc/char/1.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/sgetc/char/2-in.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/sgetc/char/2-io.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/sgetc/char/2-out.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/1-in.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/1-io.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/1-out.cc delete mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/1.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/2-in.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/2-io.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/2-out.cc rename libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/{2.cc => 3.cc} (94%) create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/snextc/char/1-in.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/snextc/char/1-io.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/snextc/char/1-out.cc delete mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/snextc/char/1.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/snextc/char/2-in.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/snextc/char/2-io.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/snextc/char/2-out.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/sputc/char/1-in.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/sputc/char/1-io.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/sputc/char/1-out.cc delete mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/sputc/char/1.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/sputc/char/2-in.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/sputc/char/2-io.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/sputc/char/2-out.cc delete mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/sputc/char/2.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/sputn/char/1-in.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/sputn/char/1-io.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/sputn/char/1-out.cc delete mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/sputn/char/1.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/sputn/char/2-in.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/sputn/char/2-io.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/sputn/char/2-out.cc create mode 100644 libstdc++-v3/testsuite/data/sgetc.txt create mode 100644 libstdc++-v3/testsuite/data/sgetn.txt create mode 100644 libstdc++-v3/testsuite/testsuite_io.h diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 8026421a5fe..052958a28e3 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,21 +1,78 @@ +2003-06-05 Benjamin Kosnik + + PR libstdc++/9024 + * include/bits/fstream.tcc (_M_underflow): Fix for unbuffered. + * include/bits/stl_algobase.h: Tweak. + * include/std/std_fstream.h: Move _M_buf_size to... + * include/std/std_streambuf.h: ...here. Modify. + * include/bits/streambuf.tcc: Same. + * testsuite/testsuite_hooks.h: Tweak. + * testsuite/testsuite_io.h (constraint_filebuf): New. + * testsuite/27_io/basic_filebuf/sbumpc/char/1.cc: Split into... + * testsuite/27_io/basic_filebuf/sbumpc/char/1-in.cc: New. + * testsuite/27_io/basic_filebuf/sbumpc/char/1-io.cc: New. + * testsuite/27_io/basic_filebuf/sbumpc/char/1-out.cc: New. + * testsuite/27_io/basic_filebuf/sbumpc/char/2-in.cc: New. + * testsuite/27_io/basic_filebuf/sbumpc/char/2-io.cc: New. + * testsuite/27_io/basic_filebuf/sbumpc/char/2-out.cc: New. + * testsuite/27_io/basic_filebuf/sgetc/char/1.cc: Split into... + * testsuite/27_io/basic_filebuf/sgetc/char/1-in.cc: New. + * testsuite/27_io/basic_filebuf/sgetc/char/1-io.cc: New. + * testsuite/27_io/basic_filebuf/sgetc/char/1-out.cc: New. + * testsuite/27_io/basic_filebuf/sgetc/char/2-in.cc: New. + * testsuite/27_io/basic_filebuf/sgetc/char/2-io.cc: New. + * testsuite/27_io/basic_filebuf/sgetc/char/2-out.cc: New. + * testsuite/27_io/basic_filebuf/sgetn/char/1.cc: Split into... + * testsuite/27_io/basic_filebuf/sgetn/char/1-in.cc: New. + * testsuite/27_io/basic_filebuf/sgetn/char/1-io.cc: New. + * testsuite/27_io/basic_filebuf/sgetn/char/1-out.cc: New. + * testsuite/27_io/basic_filebuf/sgetn/char/2.cc: Split into... + * testsuite/27_io/basic_filebuf/sgetn/char/2-in.cc: New. + * testsuite/27_io/basic_filebuf/sgetn/char/2-io.cc: New. + * testsuite/27_io/basic_filebuf/sgetn/char/2-out.cc: New. + * testsuite/27_io/basic_filebuf/sgetn/char/3.cc: New. + * testsuite/27_io/basic_filebuf/snextc/char/1.cc: Split into... + * testsuite/27_io/basic_filebuf/snextc/char/1-in.cc: New. + * testsuite/27_io/basic_filebuf/snextc/char/1-io.cc: New. + * testsuite/27_io/basic_filebuf/snextc/char/1-out.cc: New. + * testsuite/27_io/basic_filebuf/snextc/char/2-in.cc: New. + * testsuite/27_io/basic_filebuf/snextc/char/2-io.cc: New. + * testsuite/27_io/basic_filebuf/snextc/char/2-out.cc: New. + * testsuite/27_io/basic_filebuf/sputc/char/1.cc: Split into... + * testsuite/27_io/basic_filebuf/sputc/char/1-in.cc: New. + * testsuite/27_io/basic_filebuf/sputc/char/1-io.cc: New. + * testsuite/27_io/basic_filebuf/sputc/char/1-out.cc: New. + * testsuite/27_io/basic_filebuf/sputc/char/2.cc: Split into... + * testsuite/27_io/basic_filebuf/sputc/char/2-in.cc: New. + * testsuite/27_io/basic_filebuf/sputc/char/2-io.cc: New. + * testsuite/27_io/basic_filebuf/sputc/char/2-out.cc: New. + * testsuite/27_io/basic_filebuf/sputn/char/1.cc: Split into... + * testsuite/27_io/basic_filebuf/sputn/char/1-in.cc: New. + * testsuite/27_io/basic_filebuf/sputn/char/1-io.cc: New. + * testsuite/27_io/basic_filebuf/sputn/char/1-out.cc: New. + * testsuite/27_io/basic_filebuf/sputn/char/2-in.cc: New. + * testsuite/27_io/basic_filebuf/sputn/char/2-io.cc: New. + * testsuite/27_io/basic_filebuf/sputn/char/2-out.cc: New. + * testsuite/data/sgetc.txt: New. + * testsuite/data/sgetn.txt: New. + 2003-06-05 Paolo Carlini PR libstdc++/11095 * include/bits/istream.tcc (operator>>(basic_istream&, _CharT*)): Deal with width() smaller than zero. * include/bits/ostream.tcc (operator<<(basic_ostream&, _CharT), - operator<<(basic_ostream&, char), operator<<(basic_ostream&, - const _CharT*), operator<<(basic_ostream<_CharT, _Traits>&, - const char*), operator<<(basic_ostream&, - const char*), operator<<(basic_ostream, const basic_string&)): Likewise. - * testsuite/27_io/basic_istream/extractors_character/char/11095-i.cc: - * testsuite/27_io/basic_ostream/inserters_character/char/11095-oa.cc: - * testsuite/27_io/basic_ostream/inserters_character/char/11095-ob.cc: - * testsuite/27_io/basic_ostream/inserters_character/char/11095-oc.cc: - * testsuite/27_io/basic_ostream/inserters_character/wchar_t/11095-od.cc: - * testsuite/27_io/basic_ostream/inserters_character/wchar_t/11095-oe.cc: - * testsuite/27_io/basic_ostream/inserters_character/wchar_t/11095-of.cc: - New. + operator<<(basic_ostream&, char), operator<<(basic_ostream&, const + _CharT*), operator<<(basic_ostream<_CharT, _Traits>&, const + char*), operator<<(basic_ostream&, const char*), + operator<<(basic_ostream, const basic_string&)): Likewise. + + * testsuite/27_io/basic_istream/extractors_character/char/ + (11095-i.cc, 11095-oa.cc, 11095-ob.cc, 11095-oc.cc): New. + * testsuite/27_io/basic_ostream/inserters_character/char/ + (11095-oa.cc, 11095-ob.cc, 11095-oc.cc): New. + * testsuite/27_io/basic_ostream/inserters_character/wchar_t/ + (11095-od.cc, 11095-oe.cc, 11095-of.cc): New. 2003-06-05 Rainer Orth diff --git a/libstdc++-v3/include/bits/fstream.tcc b/libstdc++-v3/include/bits/fstream.tcc index e4119bfcff2..a46b478af3b 100644 --- a/libstdc++-v3/include/bits/fstream.tcc +++ b/libstdc++-v3/include/bits/fstream.tcc @@ -71,14 +71,13 @@ namespace std template basic_filebuf<_CharT, _Traits>:: basic_filebuf() : __streambuf_type(), _M_file(&_M_lock), - _M_state_cur(__state_type()), _M_state_beg(__state_type()), - _M_buf(NULL), _M_buf_size(BUFSIZ), _M_buf_allocated(false), - _M_last_overflowed(false), _M_filepos(0), _M_pback_cur_save(0), + _M_state_cur(__state_type()), _M_state_beg(__state_type()), _M_buf(NULL), + _M_buf_allocated(false),_M_last_overflowed(false), + _M_filepos(0), _M_pback(char_type()), _M_pback_cur_save(0), _M_pback_end_save(0), _M_pback_init(false), _M_codecvt(0) { this->_M_buf_unified = true; - if (__builtin_expect(has_facet<__codecvt_type>(this->_M_buf_locale), - true)) + if (has_facet<__codecvt_type>(this->_M_buf_locale)) _M_codecvt = &use_facet<__codecvt_type>(this->_M_buf_locale); } @@ -194,40 +193,41 @@ namespace std // fileops happen... _M_destroy_pback(); - if (this->_M_in_cur < this->_M_in_end) + const size_t __buflen = this->_M_buf_size + ? this->_M_buf_size - 1 : 0; + if (__buflen) { - __ret = traits_type::to_int_type(*this->_M_in_cur); - if (__bump) - _M_move_in_cur(1); - return __ret; - } + if (this->_M_in_cur < this->_M_in_end) + { + __ret = traits_type::to_int_type(*this->_M_in_cur); + if (__bump) + _M_move_in_cur(1); + return __ret; + } - // Sync internal and external buffers. - if (__testout && this->_M_out_beg < this->_M_out_lim) - this->overflow(); + // Sync internal and external buffers. + if (__testout && this->_M_out_beg < this->_M_out_lim) + this->overflow(); - if (_M_buf_size > 1) - { + // Get and convert input sequence. streamsize __elen = 0; streamsize __ilen = 0; - if (__check_facet(_M_codecvt).always_noconv()) { - __elen = _M_file.xsgetn(reinterpret_cast(this->_M_in_beg), _M_buf_size - 1); + __elen = _M_file.xsgetn(reinterpret_cast(this->_M_in_beg), __buflen); __ilen = __elen; } else { - char* __buf = static_cast(__builtin_alloca(_M_buf_size - 1)); - __elen = _M_file.xsgetn(__buf, _M_buf_size - 1); + char* __buf = static_cast(__builtin_alloca(__buflen)); + __elen = _M_file.xsgetn(__buf, __buflen); const char* __eend; char_type* __iend; codecvt_base::result __r; __r = _M_codecvt->in(_M_state_cur, __buf, __buf + __elen, __eend, this->_M_in_beg, - this->_M_in_beg + _M_buf_size - 1, - __iend); + this->_M_in_beg + __buflen, __iend); if (__r == codecvt_base::ok) __ilen = __iend - this->_M_in_beg; else if (__r == codecvt_base::noconv) @@ -245,13 +245,49 @@ namespace std } } - if (0 < __ilen) + if (__ilen > 0) { _M_set_buffer(__ilen); __ret = traits_type::to_int_type(*this->_M_in_cur); if (__bump) _M_move_in_cur(1); - } + } + } + else + { + // Unbuffered. + char __buf; + if (_M_file.xsgetn(&__buf, 1) > 0) + { + if (__check_facet(_M_codecvt).always_noconv()) + { + char_type* __cp = reinterpret_cast(&__buf); + __ret = traits_type::to_int_type(*__cp); + } + else + { + char_type __c; + const char* __eend; + char_type* __iend; + codecvt_base::result __r; + __r = _M_codecvt->in(_M_state_cur, &__buf, &__buf + 1, + __eend, &__c, &__c + 1, __iend); + if (__r == codecvt_base::ok + || __r == codecvt_base::noconv) + __ret = traits_type::to_int_type(__c); + } + + // Need to put back this extracted character so that + // sgetc will not advance the input stream iff + // underflow, but cannot call pbackfail directly as + // it calls underflow... which leads to a recursive + // showdown. + if (!__bump) + { + _M_create_pback(); + *this->_M_in_cur = traits_type::to_char_type(__ret); + } + } } } _M_last_overflowed = false; @@ -279,11 +315,6 @@ namespace std _M_move_in_cur(-1); __tmp = traits_type::to_int_type(*this->_M_in_cur); } - // At the beginning of the buffer, need to make a - // putback position available. - // But the seek may fail (f.i., at the beginning of - // a file, see libstdc++/9439) and in that case - // we return traits_type::eof(). else if (this->seekoff(-1, ios_base::cur) >= 0) { __tmp = this->underflow(); @@ -291,7 +322,14 @@ namespace std return __ret; } else - return __ret; + { + // At the beginning of the buffer, need to make a + // putback position available. But the seek may fail + // (f.i., at the beginning of a file, see + // libstdc++/9439) and in that case we return + // traits_type::eof(). + return __ret; + } // Try to put back __i into input sequence in one of three ways. // Order these tests done in is unspecified by the standard. @@ -394,7 +432,7 @@ namespace std } else { - // Result == error + // Result == error . __blen = 0; } diff --git a/libstdc++-v3/include/bits/stl_algobase.h b/libstdc++-v3/include/bits/stl_algobase.h index d19d1a012ea..c5ba0d4ce35 100644 --- a/libstdc++-v3/include/bits/stl_algobase.h +++ b/libstdc++-v3/include/bits/stl_algobase.h @@ -1,6 +1,6 @@ // Bits and pieces used in algorithms -*- C++ -*- -// Copyright (C) 2001, 2002 Free Software Foundation, Inc. +// Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free // software; you can redistribute it and/or modify it under the @@ -77,8 +77,6 @@ namespace std { - // swap and iter_swap - /** * @brief Swaps the contents of two iterators. * @param a An iterator. @@ -127,9 +125,6 @@ namespace std __b = __tmp; } - //-------------------------------------------------- - // min and max - #undef min #undef max @@ -209,9 +204,6 @@ namespace std if (__comp(__a, __b)) return __b; return __a; } - //-------------------------------------------------- - // copy - // All of these auxiliary functions serve two purposes. (1) Replace // calls to copy with memmove whenever possible. (Memmove, not memcpy, // because the input and output ranges are permitted to overlap.) @@ -221,10 +213,9 @@ namespace std template inline _OutputIter __copy(_InputIter __first, _InputIter __last, - _OutputIter __result, - input_iterator_tag) + _OutputIter __result, input_iterator_tag) { - for ( ; __first != __last; ++__result, ++__first) + for (; __first != __last; ++__result, ++__first) *__result = *__first; return __result; } @@ -232,16 +223,16 @@ namespace std template inline _OutputIter __copy(_RandomAccessIter __first, _RandomAccessIter __last, - _OutputIter __result, - random_access_iterator_tag) + _OutputIter __result, random_access_iterator_tag) { typedef typename iterator_traits<_RandomAccessIter>::difference_type _Distance; - for (_Distance __n = __last - __first; __n > 0; --__n) { - *__result = *__first; - ++__first; - ++__result; - } + for (_Distance __n = __last - __first; __n > 0; --__n) + { + *__result = *__first; + ++__first; + ++__result; + } return __result; } @@ -255,60 +246,55 @@ namespace std template inline _OutputIter - __copy_aux2(_InputIter __first, _InputIter __last, - _OutputIter __result, __false_type) + __copy_aux2(_InputIter __first, _InputIter __last, _OutputIter __result, + __false_type) { return __copy(__first, __last, __result, __iterator_category(__first)); } template inline _OutputIter - __copy_aux2(_InputIter __first, _InputIter __last, - _OutputIter __result, __true_type) + __copy_aux2(_InputIter __first, _InputIter __last, _OutputIter __result, + __true_type) { return __copy(__first, __last, __result, __iterator_category(__first)); } template inline _Tp* - __copy_aux2(_Tp* __first, _Tp* __last, - _Tp* __result, __true_type) + __copy_aux2(_Tp* __first, _Tp* __last, _Tp* __result, __true_type) { return __copy_trivial(__first, __last, __result); } template inline _Tp* - __copy_aux2(const _Tp* __first, const _Tp* __last, - _Tp* __result, __true_type) + __copy_aux2(const _Tp* __first, const _Tp* __last, _Tp* __result, + __true_type) { return __copy_trivial(__first, __last, __result); } template inline _OutputIter - __copy_ni2(_InputIter __first, _InputIter __last, - _OutputIter __result, __true_type) + __copy_ni2(_InputIter __first, _InputIter __last, _OutputIter __result, + __true_type) { typedef typename iterator_traits<_InputIter>::value_type _ValueType; typedef typename __type_traits<_ValueType>::has_trivial_assignment_operator _Trivial; - return _OutputIter(__copy_aux2(__first, __last, - __result.base(), + return _OutputIter(__copy_aux2(__first, __last, __result.base(), _Trivial())); } template inline _OutputIter - __copy_ni2(_InputIter __first, _InputIter __last, - _OutputIter __result, __false_type) + __copy_ni2(_InputIter __first, _InputIter __last, _OutputIter __result, + __false_type) { - typedef typename iterator_traits<_InputIter>::value_type - _ValueType; + typedef typename iterator_traits<_InputIter>::value_type _ValueType; typedef typename __type_traits<_ValueType>::has_trivial_assignment_operator _Trivial; - return __copy_aux2(__first, __last, - __result, - _Trivial()); + return __copy_aux2(__first, __last, __result, _Trivial()); } template inline _OutputIter - __copy_ni1(_InputIter __first, _InputIter __last, - _OutputIter __result, __true_type) + __copy_ni1(_InputIter __first, _InputIter __last, _OutputIter __result, + __true_type) { typedef typename _Is_normal_iterator<_OutputIter>::_Normal __Normal; return __copy_ni2(__first.base(), __last.base(), __result, __Normal()); @@ -316,8 +302,8 @@ namespace std template inline _OutputIter - __copy_ni1(_InputIter __first, _InputIter __last, - _OutputIter __result, __false_type) + __copy_ni1(_InputIter __first, _InputIter __last, _OutputIter __result, + __false_type) { typedef typename _Is_normal_iterator<_OutputIter>::_Normal __Normal; return __copy_ni2(__first, __last, __result, __Normal()); @@ -349,14 +335,10 @@ namespace std return __copy_ni1(__first, __last, __result, __Normal()); } - //-------------------------------------------------- - // copy_backward - template inline _BidirectionalIter2 __copy_backward(_BidirectionalIter1 __first, _BidirectionalIter1 __last, - _BidirectionalIter2 __result, - bidirectional_iterator_tag) + _BidirectionalIter2 __result, bidirectional_iterator_tag) { while (__first != __last) *--__result = *--__last; @@ -366,8 +348,7 @@ namespace std template inline _BidirectionalIter __copy_backward(_RandomAccessIter __first, _RandomAccessIter __last, - _BidirectionalIter __result, - random_access_iterator_tag) + _BidirectionalIter __result, random_access_iterator_tag) { typename iterator_traits<_RandomAccessIter>::difference_type __n; for (__n = __last - __first; __n > 0; --__n) @@ -380,7 +361,6 @@ namespace std // have partial ordering of function templates. All we're doing is // creating a specialization so that we can turn a call to copy_backward // into a memmove whenever possible. - template struct __copy_backward_dispatch @@ -389,8 +369,7 @@ namespace std copy(_BidirectionalIter1 __first, _BidirectionalIter1 __last, _BidirectionalIter2 __result) { - return __copy_backward(__first, __last, - __result, + return __copy_backward(__first, __last, __result, __iterator_category(__first)); } }; @@ -424,8 +403,9 @@ namespace std { typedef typename __type_traits::value_type> ::has_trivial_assignment_operator _Trivial; - return __copy_backward_dispatch<_BI1, _BI2, _Trivial> - ::copy(__first, __last, __result); + return __copy_backward_dispatch<_BI1, _BI2, _Trivial>::copy(__first, + __last, + __result); } template @@ -446,8 +426,9 @@ namespace std _BI2 __result, __true_type) { typedef typename _Is_normal_iterator<_BI2>::_Normal __Normal; - return __copy_backward_output_normal_iterator(__first.base(), __last.base(), - __result, __Normal()); + return __copy_backward_output_normal_iterator(__first.base(), + __last.base(), __result, + __Normal()); } template @@ -491,10 +472,6 @@ namespace std } - //-------------------------------------------------- - // fill and fill_n - - /** * @brief Fills the range [first,last) with copies of value. * @param first A forward iterator. @@ -541,7 +518,6 @@ namespace std } // Specialization: for one-byte types we can use memset. - inline void fill(unsigned char* __first, unsigned char* __last, const unsigned char& __c) { @@ -588,9 +564,6 @@ namespace std } - //-------------------------------------------------- - // equal and mismatch - /** * @brief Finds the places in ranges which don't match. * @param first1 An input iterator. @@ -605,8 +578,7 @@ namespace std */ template pair<_InputIter1, _InputIter2> - mismatch(_InputIter1 __first1, _InputIter1 __last1, - _InputIter2 __first2) + mismatch(_InputIter1 __first1, _InputIter1 __last1, _InputIter2 __first2) { // concept requirements __glibcpp_function_requires(_InputIteratorConcept<_InputIter1>) @@ -616,10 +588,11 @@ namespace std __glibcpp_function_requires(_EqualityComparableConcept< typename iterator_traits<_InputIter2>::value_type>) - while (__first1 != __last1 && *__first1 == *__first2) { - ++__first1; - ++__first2; - } + while (__first1 != __last1 && *__first1 == *__first2) + { + ++__first1; + ++__first2; + } return pair<_InputIter1, _InputIter2>(__first1, __first2); } @@ -639,18 +612,18 @@ namespace std */ template pair<_InputIter1, _InputIter2> - mismatch(_InputIter1 __first1, _InputIter1 __last1, - _InputIter2 __first2, + mismatch(_InputIter1 __first1, _InputIter1 __last1, _InputIter2 __first2, _BinaryPredicate __binary_pred) { // concept requirements __glibcpp_function_requires(_InputIteratorConcept<_InputIter1>) __glibcpp_function_requires(_InputIteratorConcept<_InputIter2>) - while (__first1 != __last1 && __binary_pred(*__first1, *__first2)) { - ++__first1; - ++__first2; - } + while (__first1 != __last1 && __binary_pred(*__first1, *__first2)) + { + ++__first1; + ++__first2; + } return pair<_InputIter1, _InputIter2>(__first1, __first2); } @@ -667,8 +640,7 @@ namespace std */ template inline bool - equal(_InputIter1 __first1, _InputIter1 __last1, - _InputIter2 __first2) + equal(_InputIter1 __first1, _InputIter1 __last1, _InputIter2 __first2) { // concept requirements __glibcpp_function_requires(_InputIteratorConcept<_InputIter1>) @@ -712,9 +684,6 @@ namespace std return true; } - //-------------------------------------------------- - // lexicographical_compare - /** * @brief Performs "dictionary" comparison on ranges. * @param first1 An input iterator. @@ -742,13 +711,13 @@ namespace std __glibcpp_function_requires(_LessThanComparableConcept< typename iterator_traits<_InputIter2>::value_type>) - for ( ; __first1 != __last1 && __first2 != __last2 - ; ++__first1, ++__first2) { - if (*__first1 < *__first2) - return true; - if (*__first2 < *__first1) - return false; - } + for (;__first1 != __last1 && __first2 != __last2; ++__first1, ++__first2) + { + if (*__first1 < *__first2) + return true; + if (*__first2 < *__first1) + return false; + } return __first1 == __last1 && __first2 != __last2; } @@ -775,18 +744,21 @@ namespace std __glibcpp_function_requires(_InputIteratorConcept<_InputIter2>) for ( ; __first1 != __last1 && __first2 != __last2 - ; ++__first1, ++__first2) { - if (__comp(*__first1, *__first2)) - return true; - if (__comp(*__first2, *__first1)) - return false; - } + ; ++__first1, ++__first2) + { + if (__comp(*__first1, *__first2)) + return true; + if (__comp(*__first2, *__first1)) + return false; + } return __first1 == __last1 && __first2 != __last2; } inline bool - lexicographical_compare(const unsigned char* __first1, const unsigned char* __last1, - const unsigned char* __first2, const unsigned char* __last2) + lexicographical_compare(const unsigned char* __first1, + const unsigned char* __last1, + const unsigned char* __first2, + const unsigned char* __last2) { const size_t __len1 = __last1 - __first1; const size_t __len2 = __last2 - __first2; @@ -813,8 +785,4 @@ namespace std } // namespace std -#endif /* __GLIBCPP_INTERNAL_ALGOBASE_H */ - -// Local Variables: -// mode:C++ -// End: +#endif diff --git a/libstdc++-v3/include/bits/streambuf.tcc b/libstdc++-v3/include/bits/streambuf.tcc index 5b76c40f928..502645d4003 100644 --- a/libstdc++-v3/include/bits/streambuf.tcc +++ b/libstdc++-v3/include/bits/streambuf.tcc @@ -48,8 +48,12 @@ namespace std if (_M_in_cur < _M_in_end) { char_type __c = *this->_M_in_cur; - _M_move_in_cur(1); __ret = traits_type::to_int_type(__c); + + if (_M_buf_size) + _M_move_in_cur(1); + else + this->underflow(); } else __ret = this->uflow(); diff --git a/libstdc++-v3/include/std/std_fstream.h b/libstdc++-v3/include/std/std_fstream.h index de192131c14..77350d024e5 100644 --- a/libstdc++-v3/include/std/std_fstream.h +++ b/libstdc++-v3/include/std/std_fstream.h @@ -121,15 +121,6 @@ namespace std */ char_type* _M_buf; - /** - * @if maint - * Actual size of internal buffer. This number is equal to the size - * of the put area + 1 position, reserved for the overflow char of - * a full area. - * @endif - */ - size_t _M_buf_size; - // Set iff _M_buf is allocated memory from _M_allocate_internal_buffer. /** * @if maint @@ -191,9 +182,9 @@ namespace std if (_M_pback_init) { // Length _M_in_cur moved in the pback buffer. - const size_t __off = this->_M_in_cur == this->_M_in_beg ? 0 : 1; - this->setg(this->_M_buf, _M_pback_cur_save + __off, - _M_pback_end_save); + if (_M_pback_cur_save) + _M_pback_cur_save += this->_M_in_cur != this->_M_in_beg; + this->setg(this->_M_buf, _M_pback_cur_save, _M_pback_end_save); _M_pback_init = false; } } @@ -215,7 +206,6 @@ namespace std ~basic_filebuf() { this->close(); - _M_buf_size = 0; _M_last_overflowed = false; } @@ -375,7 +365,7 @@ namespace std // Need to restore current position after the write. off_type __off = this->_M_out_cur - this->_M_out_lim; - // _M_file.sync() will be called within + // _M_file.sync() will be called within. if (traits_type::eq_int_type(this->overflow(), traits_type::eof())) __ret = -1; else if (__off) @@ -395,8 +385,8 @@ namespace std virtual streamsize xsgetn(char_type* __s, streamsize __n) { - streamsize __ret = 0; // Clear out pback buffer before going on to the real deal... + streamsize __ret = 0; if (this->_M_pback_init) { if (__n && this->_M_in_cur == this->_M_in_beg) @@ -439,7 +429,7 @@ namespace std { const bool __testin = this->_M_mode & ios_base::in; const bool __testout = this->_M_mode & ios_base::out; - if (_M_buf_size) + if (this->_M_buf_size) { if (__testin) this->setg(this->_M_buf, this->_M_buf, this->_M_buf + __off); diff --git a/libstdc++-v3/include/std/std_streambuf.h b/libstdc++-v3/include/std/std_streambuf.h index 38aa6075f03..c4159cc4eca 100644 --- a/libstdc++-v3/include/std/std_streambuf.h +++ b/libstdc++-v3/include/std/std_streambuf.h @@ -159,14 +159,6 @@ namespace std __streambuf_type* __sbin,__streambuf_type* __sbout); protected: - /** - * @if maint - * True iff _M_in_* and _M_out_* buffers should always point to - * the same place. True for fstreams, false for sstreams. - * @endif - */ - bool _M_buf_unified; - //@{ /** * @if maint @@ -193,15 +185,31 @@ namespace std * @endif */ char_type* _M_out_lim; // End limit of used put area. - //@} + /** + * @if maint + * True iff _M_in_* and _M_out_* buffers should always point to + * the same place. True for fstreams, false for sstreams. + * @endif + */ + bool _M_buf_unified; + + /** + * @if maint + * Actual size of internal buffer. This number is equal to the size + * of the put area + 1 position, reserved for the overflow char of + * a full area. + * @endif + */ + size_t _M_buf_size; + /** * @if maint * Place to stash in || out || in | out settings for current streambuf. * @endif */ - ios_base::openmode _M_mode; + ios_base::openmode _M_mode; /** * @if maint @@ -259,6 +267,7 @@ namespace std ~basic_streambuf() { _M_buf_unified = false; + _M_buf_size = 0; _M_mode = ios_base::openmode(0); } @@ -458,10 +467,10 @@ namespace std * - this is not an error */ basic_streambuf() - : _M_buf_unified(false), _M_in_beg(0), _M_in_cur(0), - _M_in_end(0), _M_out_beg(0), _M_out_cur(0), _M_out_end(0), - _M_out_lim(0), _M_mode(ios_base::openmode(0)), - _M_buf_locale(locale()) + : _M_in_beg(0), _M_in_cur(0), _M_in_end(0), + _M_out_beg(0), _M_out_cur(0), _M_out_end(0),_M_out_lim(0), + _M_buf_unified(false), _M_buf_size(BUFSIZ), + _M_mode(ios_base::openmode(0)),_M_buf_locale(locale()) { } // [27.5.2.3.1] get area access diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sbumpc/char/1-in.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sbumpc/char/1-in.cc new file mode 100644 index 00000000000..e03da5f2064 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sbumpc/char/1-in.cc @@ -0,0 +1,79 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_01[] = "sgetc.txt"; // file with data in it + +void test05() +{ + using namespace std; + using namespace __gnu_cxx_test; + typedef filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test = true; + + // int_type sbumpc() + // if read_cur not avail returns uflow(), else return *read_cur & increment + + // in + { + constraint_filebuf fb_01; + fb_01.open(name_01, ios_base::in); + VERIFY( !fb_01.write_position() ); + + int_type c1 = fb_01.sbumpc(); + VERIFY( c1 == '/' ); + int_type c3 = fb_01.sbumpc(); + VERIFY( c3 == '/' ); + + c1 = fb_01.sgetc(); + int_type c2 = fb_01.sbumpc(); + c3 = fb_01.sgetc(); + VERIFY( c1 == ' ' ); + VERIFY( c3 == '9' ); + VERIFY( c1 == c2 ); + VERIFY( c2 != c3 ); + + c1 = fb_01.sbumpc(); + c2 = fb_01.sbumpc(); + c3 = fb_01.sgetc(); + VERIFY( c1 == '9' ); + VERIFY( c2 == '9' ); + VERIFY( c3 == '0' ); + + VERIFY( !fb_01.write_position() ); + VERIFY( fb_01.read_position() ); + } +} + +main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sbumpc/char/1-io.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sbumpc/char/1-io.cc new file mode 100644 index 00000000000..9098a2083e7 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sbumpc/char/1-io.cc @@ -0,0 +1,92 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_01[] = "sgetc.txt"; // file with data in it +const char name_03[] = "tmp_sbumpc_1io.tst"; // empty file, need to create + +void test05() +{ + using namespace std; + using namespace __gnu_cxx_test; + typedef filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test = true; + + // int_type sbumpc() + // if read_cur not avail returns uflow(), else return *read_cur & increment + + // in | out 1 + { + constraint_filebuf fb_03; + fb_03.open(name_03, ios_base::out | ios_base::in | ios_base::trunc); + VERIFY( fb_03.write_position() ); + VERIFY( !fb_03.read_position() ); + int_type c5 = fb_03.sbumpc(); + VERIFY( c5 == traits_type::eof() ); + VERIFY( fb_03.write_position() ); + VERIFY( !fb_03.read_position() ); + } + + // in | out 2 + { + constraint_filebuf fb_01; + fb_01.open(name_01, ios_base::in | ios_base::out); + VERIFY( fb_01.write_position() ); + + int_type c1 = fb_01.sbumpc(); + VERIFY( c1 == '/' ); + int_type c3 = fb_01.sbumpc(); + VERIFY( c3 == '/' ); + + c1 = fb_01.sgetc(); + int_type c2 = fb_01.sbumpc(); + c3 = fb_01.sgetc(); + VERIFY( c1 == ' ' ); + VERIFY( c3 == '9' ); + VERIFY( c1 == c2 ); + VERIFY( c2 != c3 ); + + c1 = fb_01.sbumpc(); + c2 = fb_01.sbumpc(); + c3 = fb_01.sgetc(); + VERIFY( c1 == '9' ); + VERIFY( c2 == '9' ); + VERIFY( c3 == '0' ); + + VERIFY( fb_01.write_position() ); + VERIFY( fb_01.read_position() ); + } +} + +main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sbumpc/char/1-out.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sbumpc/char/1-out.cc new file mode 100644 index 00000000000..ff0cb97dd5d --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sbumpc/char/1-out.cc @@ -0,0 +1,63 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_02[] = "tmp_sbumpc_1out.tst"; // empty file, need to create + +void test05() +{ + using namespace std; + using namespace __gnu_cxx_test; + typedef filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test = true; + + // int_type sbumpc() + // if read_cur not avail returns uflow(), else return *read_cur & increment + + // out + { + constraint_filebuf fb_02; + fb_02.open(name_02, ios_base::out | ios_base::trunc); + VERIFY( fb_02.write_position() ); + VERIFY( !fb_02.read_position() ); + int_type c2 = fb_02.sbumpc(); + VERIFY( c2 == traits_type::eof() ); + int_type c4 = fb_02.sbumpc(); + VERIFY( c4 == traits_type::eof() ); + VERIFY( fb_02.write_position() ); + VERIFY( !fb_02.read_position() ); + } +} + +main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sbumpc/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sbumpc/char/1.cc deleted file mode 100644 index d2c7ccd53b4..00000000000 --- a/libstdc++-v3/testsuite/27_io/basic_filebuf/sbumpc/char/1.cc +++ /dev/null @@ -1,106 +0,0 @@ -// 2001-05-21 Benjamin Kosnik - -// Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc. -// -// This file is part of the GNU ISO C++ Library. This library is free -// software; you can redistribute it and/or modify it under the -// terms of the GNU General Public License as published by the -// Free Software Foundation; either version 2, or (at your option) -// any later version. - -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License along -// with this library; see the file COPYING. If not, write to the Free -// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, -// USA. - -// 27.8.1.4 Overridden virtual functions - -#include -#include - -// @require@ %-*.tst %-*.txt -// @diff@ %-*.tst %*.txt - -// NB: This test assumes that _M_buf_size == 40, and not the usual -// buffer_size length of BUFSIZ (8192), so that overflow/underflow can be -// simulated a bit more readily. -// NRB (Nota Really Bene): setting it to 40 breaks the test, as intended. -const int buffer_size = 8192; -//const int buffer_size = 40; - -const char name_01[] = "filebuf_virtuals-1.txt"; // file with data in it -const char name_02[] = "filebuf_virtuals-2.txt"; // empty file, need to create -const char name_03[] = "filebuf_virtuals-3.txt"; // empty file, need to create - -class derived_filebuf: public std::filebuf -{ - public: - void - set_size(int_type __size) { _M_buf_size = __size; } -}; - -derived_filebuf fb_01; // in -derived_filebuf fb_02; // out -derived_filebuf fb_03; // in | out - -// Initialize filebufs to be the same size regardless of platform. -void test03() -{ - fb_01.set_size(buffer_size); - fb_02.set_size(buffer_size); - fb_03.set_size(buffer_size); -} - -// Test overloaded virtual functions. -void test05() -{ - using namespace std; - typedef filebuf::int_type int_type; - typedef filebuf::traits_type traits_type; - typedef filebuf::pos_type pos_type; - typedef filebuf::off_type off_type; - typedef size_t size_type; - - bool test = true; - filebuf f_tmp; - streamsize strmsz_1, strmsz_2; - streamoff strmof_1, strmof_2; - int i = 0, j = 0, k = 0; - - // GET - fb_01.open(name_01, ios_base::in); - fb_02.open(name_02, ios_base::out | ios_base::trunc); - fb_03.open(name_03, ios_base::out | ios_base::in | ios_base::trunc); - strmof_1 = fb_01.in_avail(); - strmof_2 = fb_02.in_avail(); - strmof_1 = fb_03.in_avail(); - - // int_type sbumpc() - // if read_cur not avail returns uflow(), else return *read_cur & increment - int_type c1 = fb_01.sbumpc(); - int_type c2 = fb_02.sbumpc(); - VERIFY( c1 != c2 ); - VERIFY( c1 == '/' ); - VERIFY( c2 == -1 ); - int_type c3 = fb_01.sbumpc(); - int_type c4 = fb_02.sbumpc(); - VERIFY( c3 != c4 ); - VERIFY( c1 == c3 ); // fluke, both happen to be '/' - VERIFY( c2 == c4 ); - int_type c5 = fb_03.sbumpc(); - VERIFY( c5 == traits_type::eof() ); - // XXX should do some kind of test to make sure that internal - // buffers point to the same thing, to check consistancy. -} - -main() -{ - test03(); - test05(); - return 0; -} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sbumpc/char/2-in.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sbumpc/char/2-in.cc new file mode 100644 index 00000000000..d0f256ee10c --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sbumpc/char/2-in.cc @@ -0,0 +1,79 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_01[] = "sgetc.txt"; // file with data in it + +void test05() +{ + using namespace std; + using namespace __gnu_cxx_test; + typedef filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test = true; + + // int_type sbumpc() + // if read_cur not avail returns uflow(), else return *read_cur & increment + + // in + { + constraint_filebuf fb_01; + fb_01.pubsetbuf(0, 0); + fb_01.open(name_01, ios_base::in); + VERIFY( fb_01.unbuffered() ); + + int_type c1 = fb_01.sbumpc(); + VERIFY( c1 == '/' ); + int_type c3 = fb_01.sbumpc(); + VERIFY( c3 == '/' ); + + c1 = fb_01.sgetc(); + int_type c2 = fb_01.sbumpc(); + c3 = fb_01.sgetc(); + VERIFY( c1 == ' ' ); + VERIFY( c3 == '9' ); + VERIFY( c1 == c2 ); + VERIFY( c2 != c3 ); + + c1 = fb_01.sbumpc(); + c2 = fb_01.sbumpc(); + c3 = fb_01.sgetc(); + VERIFY( c1 == '9' ); + VERIFY( c2 == '9' ); + VERIFY( c3 == '0' ); + + VERIFY( fb_01.unbuffered() ); + } +} + +main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sbumpc/char/2-io.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sbumpc/char/2-io.cc new file mode 100644 index 00000000000..ef1f28f786e --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sbumpc/char/2-io.cc @@ -0,0 +1,91 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_01[] = "sgetc.txt"; // file with data in it +const char name_03[] = "tmp_sbumpc_2io.tst"; // empty file, need to create + +void test05() +{ + using namespace std; + using namespace __gnu_cxx_test; + typedef filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test = true; + + // int_type sbumpc() + // if read_cur not avail returns uflow(), else return *read_cur & increment + + // in | out 1 + { + constraint_filebuf fb_03; + fb_03.pubsetbuf(0, 0); + fb_03.open(name_03, ios_base::out | ios_base::in | ios_base::trunc); + VERIFY( fb_03.unbuffered() ); + int_type c5 = fb_03.sbumpc(); + VERIFY( c5 == traits_type::eof() ); + VERIFY( fb_03.unbuffered() ); + } + + // in | out 2 + { + constraint_filebuf fb_01; + fb_01.pubsetbuf(0, 0); + fb_01.open(name_01, ios_base::in | ios_base::out); + VERIFY( fb_01.unbuffered() ); + + int_type c1 = fb_01.sbumpc(); + VERIFY( c1 == '/' ); + int_type c3 = fb_01.sbumpc(); + VERIFY( c3 == '/' ); + + c1 = fb_01.sgetc(); + int_type c2 = fb_01.sbumpc(); + c3 = fb_01.sgetc(); + VERIFY( c1 == ' ' ); + VERIFY( c3 == '9' ); + VERIFY( c1 == c2 ); + VERIFY( c2 != c3 ); + + c1 = fb_01.sbumpc(); + c2 = fb_01.sbumpc(); + c3 = fb_01.sgetc(); + VERIFY( c1 == '9' ); + VERIFY( c2 == '9' ); + VERIFY( c3 == '0' ); + + VERIFY( fb_01.unbuffered() ); + } +} + +main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sbumpc/char/2-out.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sbumpc/char/2-out.cc new file mode 100644 index 00000000000..1d8df086bcc --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sbumpc/char/2-out.cc @@ -0,0 +1,64 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_02[] = "tmp_sbumpc_2out.tst"; // empty file, need to create + +void test05() +{ + using namespace std; + using namespace __gnu_cxx_test; + typedef filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test = true; + + // int_type sbumpc() + // if read_cur not avail returns uflow(), else return *read_cur & increment + + // out + { + constraint_filebuf fb_02; + fb_02.pubsetbuf(0, 0); + fb_02.open(name_02, ios_base::out | ios_base::trunc); + VERIFY( fb_02.unbuffered() ); + VERIFY( !fb_02.read_position() ); + int_type c2 = fb_02.sbumpc(); + VERIFY( c2 == traits_type::eof() ); + int_type c4 = fb_02.sbumpc(); + VERIFY( c4 == traits_type::eof() ); + VERIFY( fb_02.unbuffered() ); + VERIFY( !fb_02.read_position() ); + } +} + +main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetc/char/1-in.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetc/char/1-in.cc new file mode 100644 index 00000000000..7ae7cdccee4 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetc/char/1-in.cc @@ -0,0 +1,71 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_01[] = "filebuf_virtuals-1.txt"; // file with data in it + +// Test overloaded virtual functions. +void test05() +{ + using namespace std; + using namespace __gnu_cxx_test; + typedef std::filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test = true; + int_type c1, c2, c3; + + // int_type sgetc() + // if read_cur not avail, return uflow(), else return *read_cur + + // in + { + constraint_filebuf fb_01; // in + fb_01.open(name_01, ios::in); + VERIFY( !fb_01.write_position() ); + c1 = fb_01.sgetc(); + VERIFY( c1 == '/' ); + c2 = fb_01.sgetc(); + VERIFY( c1 == c2 ); + fb_01.sbumpc(); + c1 = fb_01.sbumpc(); + c2 = fb_01.sgetc(); + c3 = fb_01.sgetc(); + VERIFY( c1 == '/' ); + VERIFY( c2 == ' ' ); + VERIFY( c3 == ' ' ); + VERIFY( !fb_01.write_position() ); + VERIFY( fb_01.read_position() ); + } +} + +main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetc/char/1-io.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetc/char/1-io.cc new file mode 100644 index 00000000000..6882234f1d5 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetc/char/1-io.cc @@ -0,0 +1,86 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_01[] = "sgetc.txt"; // file with data in it +const char name_03[] = "tmp_sgetc_1io.tst"; // empty file, need to create + +// Test overloaded virtual functions. +void test05() +{ + using namespace std; + using namespace __gnu_cxx_test; + typedef std::filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test = true; + int_type c1, c2, c3; + + // int_type sgetc() + // if read_cur not avail, return uflow(), else return *read_cur + + // in | out 1 + { + constraint_filebuf fb_03; // in | out + fb_03.open(name_03, ios::out | ios::in | ios::trunc); + VERIFY( fb_03.write_position() ); + VERIFY( !fb_03.read_position() ); + c1 = fb_03.sgetc(); + c2 = fb_03.sbumpc(); + VERIFY( c1 == traits_type::eof() ); + VERIFY( c1 == c2 ); + VERIFY( fb_03.write_position() ); + VERIFY( !fb_03.read_position() ); + } + + // in | out 2 + { + constraint_filebuf fb_01; // in + fb_01.open(name_01, ios::in | ios::out); + VERIFY( fb_01.write_position() ); + c1 = fb_01.sgetc(); + VERIFY( c1 == '/' ); + c2 = fb_01.sgetc(); + VERIFY( c1 == c2 ); + fb_01.sbumpc(); + c1 = fb_01.sbumpc(); + c2 = fb_01.sgetc(); + c3 = fb_01.sgetc(); + VERIFY( c1 == '/' ); + VERIFY( c2 == ' ' ); + VERIFY( c3 == ' ' ); + VERIFY( fb_01.write_position() ); + VERIFY( fb_01.read_position() ); + } +} + +main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetc/char/1-out.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetc/char/1-out.cc new file mode 100644 index 00000000000..30d4d1b5e40 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetc/char/1-out.cc @@ -0,0 +1,69 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_02[] = "tmp_sgetc_1out.tst"; // empty file, need to create + +// Test overloaded virtual functions. +void test05() +{ + using namespace std; + using namespace __gnu_cxx_test; + typedef std::filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test = true; + int_type c1, c2, c3; + + // int_type sgetc() + // if read_cur not avail, return uflow(), else return *read_cur + + // out + { + constraint_filebuf fb_02; // out + fb_02.open(name_02, ios::out | ios::trunc); + VERIFY( fb_02.write_position() ); + VERIFY( !fb_02.read_position() ); + c1 = fb_02.sgetc(); + VERIFY( c1 == traits_type::eof() ); + c2 = fb_02.sgetc(); + VERIFY( c2 == traits_type::eof() ); + fb_02.sbumpc(); + c1 = fb_02.sbumpc(); + c2 = fb_02.sgetc(); + VERIFY( c1 == c2 ); + VERIFY( fb_02.write_position() ); + VERIFY( !fb_02.read_position() ); + } +} + +main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetc/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetc/char/1.cc deleted file mode 100644 index 37573c8edfd..00000000000 --- a/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetc/char/1.cc +++ /dev/null @@ -1,107 +0,0 @@ -// 2001-05-21 Benjamin Kosnik - -// Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc. -// -// This file is part of the GNU ISO C++ Library. This library is free -// software; you can redistribute it and/or modify it under the -// terms of the GNU General Public License as published by the -// Free Software Foundation; either version 2, or (at your option) -// any later version. - -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License along -// with this library; see the file COPYING. If not, write to the Free -// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, -// USA. - -// 27.8.1.4 Overridden virtual functions - -#include -#include - -// @require@ %-*.tst %-*.txt -// @diff@ %-*.tst %*.txt - -// NB: This test assumes that _M_buf_size == 40, and not the usual -// buffer_size length of BUFSIZ (8192), so that overflow/underflow can be -// simulated a bit more readily. -// NRB (Nota Really Bene): setting it to 40 breaks the test, as intended. -const int buffer_size = 8192; -//const int buffer_size = 40; - -const char name_01[] = "filebuf_virtuals-1.txt"; // file with data in it -const char name_02[] = "filebuf_virtuals-2.txt"; // empty file, need to create -const char name_03[] = "filebuf_virtuals-3.txt"; // empty file, need to create - -class derived_filebuf: public std::filebuf -{ - public: - void - set_size(int_type __size) { _M_buf_size = __size; } -}; - -derived_filebuf fb_01; // in -derived_filebuf fb_02; // out -derived_filebuf fb_03; // in | out - -// Initialize filebufs to be the same size regardless of platform. -void test03() -{ - fb_01.set_size(buffer_size); - fb_02.set_size(buffer_size); - fb_03.set_size(buffer_size); -} - -// Test overloaded virtual functions. -void test05() -{ - typedef std::filebuf::int_type int_type; - typedef std::filebuf::traits_type traits_type; - typedef std::filebuf::pos_type pos_type; - typedef std::filebuf::off_type off_type; - typedef size_t size_type; - - bool test = true; - std::filebuf f_tmp; - std::streamsize strmsz_1, strmsz_2; - std::streamoff strmof_1, strmof_2; - int i = 0, j = 0, k = 0; - - // GET - fb_01.open(name_01, std::ios_base::in); - fb_02.open(name_02, std::ios_base::out | std::ios_base::trunc); - fb_03.open(name_03, std::ios_base::out | std::ios_base::in | std::ios_base::trunc); - strmof_1 = fb_01.in_avail(); - strmof_2 = fb_02.in_avail(); - strmof_1 = fb_03.in_avail(); - - int_type c1 = fb_01.sbumpc(); - int_type c2 = fb_02.sbumpc(); - int_type c3 = fb_01.sbumpc(); - int_type c4 = fb_02.sbumpc(); - int_type c5 = fb_03.sbumpc(); - - // int_type sgetc() - // if read_cur not avail, return uflow(), else return *read_cur - int_type c6 = fb_01.sgetc(); - int_type c7 = fb_02.sgetc(); - VERIFY( c6 != c3 ); - VERIFY( c7 == c4 ); // both -1 - int_type c8 = fb_01.sgetc(); - int_type c9 = fb_02.sgetc(); - VERIFY( c6 == c8 ); - VERIFY( c7 == c9 ); - c5 = fb_03.sgetc(); - VERIFY( c5 == traits_type::eof() ); -} - -main() -{ - test03(); - test05(); - return 0; -} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetc/char/2-in.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetc/char/2-in.cc new file mode 100644 index 00000000000..979a3fd3845 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetc/char/2-in.cc @@ -0,0 +1,71 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_01[] = "sgetc.txt"; // file with data in it + +// Test overloaded virtual functions. +void test05() +{ + using namespace std; + using namespace __gnu_cxx_test; + typedef std::filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test = true; + int_type c1, c2, c3; + + // int_type sgetc() + // if read_cur not avail, return uflow(), else return *read_cur + + // in + { + constraint_filebuf fb_01; // in + fb_01.pubsetbuf(0, 0); + fb_01.open(name_01, ios::in); + VERIFY( fb_01.unbuffered() ); + c1 = fb_01.sgetc(); + VERIFY( c1 == '/' ); + c2 = fb_01.sgetc(); + VERIFY( c1 == c2 ); + fb_01.sbumpc(); + c1 = fb_01.sbumpc(); + c2 = fb_01.sgetc(); + c3 = fb_01.sgetc(); + VERIFY( c1 == '/' ); + VERIFY( c2 == ' ' ); + VERIFY( c3 == ' ' ); + VERIFY( fb_01.unbuffered() ); + } +} + +main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetc/char/2-io.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetc/char/2-io.cc new file mode 100644 index 00000000000..e12ef3455cd --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetc/char/2-io.cc @@ -0,0 +1,85 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_01[] = "sgetc.txt"; // file with data in it +const char name_03[] = "tmp_sgetc_2io.tst"; // empty file, need to create + +// Test overloaded virtual functions. +void test05() +{ + using namespace std; + using namespace __gnu_cxx_test; + typedef std::filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test = true; + int_type c1, c2, c3; + + // int_type sgetc() + // if read_cur not avail, return uflow(), else return *read_cur + + // in | out 1 + { + constraint_filebuf fb_03; // in | out + fb_03.pubsetbuf(0, 0); + fb_03.open(name_03, ios::out | ios::in | ios::trunc); + VERIFY( fb_03.unbuffered() ); + c1 = fb_03.sgetc(); + c2 = fb_03.sbumpc(); + VERIFY( c1 == traits_type::eof() ); + VERIFY( c1 == c2 ); + VERIFY( fb_03.unbuffered() ); + } + + // in | out 2 + { + constraint_filebuf fb_01; // in + fb_01.pubsetbuf(0, 0); + fb_01.open(name_01, ios::in | ios::out); + VERIFY( fb_01.unbuffered() ); + c1 = fb_01.sgetc(); + VERIFY( c1 == '/' ); + c2 = fb_01.sgetc(); + VERIFY( c1 == c2 ); + fb_01.sbumpc(); + c1 = fb_01.sbumpc(); + c2 = fb_01.sgetc(); + c3 = fb_01.sgetc(); + VERIFY( c1 == '/' ); + VERIFY( c2 == ' ' ); + VERIFY( c3 == ' ' ); + VERIFY( fb_01.unbuffered() ); + } +} + +main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetc/char/2-out.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetc/char/2-out.cc new file mode 100644 index 00000000000..491c028c281 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetc/char/2-out.cc @@ -0,0 +1,70 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_02[] = "tmp_sgetc_2out.tst"; // empty file, need to create + +// Test overloaded virtual functions. +void test05() +{ + using namespace std; + using namespace __gnu_cxx_test; + typedef std::filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test = true; + int_type c1, c2, c3; + + // int_type sgetc() + // if read_cur not avail, return uflow(), else return *read_cur + + // out + { + constraint_filebuf fb_02; // out + fb_02.pubsetbuf(0, 0); + fb_02.open(name_02, ios::out | ios::trunc); + VERIFY( fb_02.unbuffered() ); + VERIFY( !fb_02.read_position() ); + c1 = fb_02.sgetc(); + VERIFY( c1 == traits_type::eof() ); + c2 = fb_02.sgetc(); + VERIFY( c2 == traits_type::eof() ); + fb_02.sbumpc(); + c1 = fb_02.sbumpc(); + c2 = fb_02.sgetc(); + VERIFY( c1 == c2 ); + VERIFY( fb_02.unbuffered() ); + VERIFY( !fb_02.read_position() ); + } +} + +main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/1-in.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/1-in.cc new file mode 100644 index 00000000000..021a1c89d68 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/1-in.cc @@ -0,0 +1,83 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_01[] = "sgetn.txt"; // file with data in it + +// Test overloaded virtual functions. +void test05() +{ + using namespace std; + using namespace __gnu_cxx_test; + typedef filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test = true; + + streamsize strmsz_1, strmsz_2, strmsz_3; + int i = 0, j = 0, k = 0; + char carray1[13] = ""; + char carray2[8192] = ""; + int_type c1, c2, c3, c4; + + // streamsize sgetn(char_type *s, streamsize n) + // streamsize xsgetn(char_type *s, streamsize n) + // assign up to n chars to s from input sequence, indexing in_cur as + // approp and returning the number of chars assigned + + // in + { + constraint_filebuf fb_01; + fb_01.open(name_01, ios_base::in); + VERIFY( !fb_01.write_position() ); + strmsz_1 = fb_01.in_avail(); // 8261 + strmsz_2 = fb_01.sgetn(carray1, 10); + VERIFY( strmsz_2 == 10 ); + strmsz_2 = fb_01.in_avail(); + VERIFY( strmsz_1 > strmsz_2 ); + c1 = fb_01.sgetc(); + VERIFY( c1 == 'b' ); + strmsz_1 = fb_01.in_avail(); + strmsz_2 = fb_01.sgetn(carray2, strmsz_1 + 5); + VERIFY( strmsz_1 == strmsz_2 - 5 ); + c4 = fb_01.sgetc(); // buffer should have underflowed from above. + VERIFY( c4 == 'h' ); + strmsz_1 = fb_01.in_avail(); + VERIFY( strmsz_1 > 0 ); + strmsz_2 = fb_01.sgetn(carray2, strmsz_1 + 5); + VERIFY( strmsz_1 == strmsz_2 ); //at the end of the actual file + VERIFY( !fb_01.write_position() ); + VERIFY( !fb_01.read_position() ); + } +} + +main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/1-io.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/1-io.cc new file mode 100644 index 00000000000..432ed6cdab5 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/1-io.cc @@ -0,0 +1,96 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_01[] = "sgetn.txt"; // file with data in it +const char name_03[] = "tmp_sgetn_1io.tst"; // empty file, need to create + +// Test overloaded virtual functions. +void test05() +{ + using namespace std; + using namespace __gnu_cxx_test; + typedef filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test = true; + + streamsize strmsz_1, strmsz_2, strmsz_3; + int i = 0, j = 0, k = 0; + char carray1[13] = ""; + char carray2[8192] = ""; + int_type c1, c2, c3, c4; + + // streamsize sgetn(char_type *s, streamsize n) + // streamsize xsgetn(char_type *s, streamsize n) + // assign up to n chars to s from input sequence, indexing in_cur as + // approp and returning the number of chars assigned + + // in | out 1 + { + constraint_filebuf fb_03; + fb_03.open(name_03, ios_base::out | ios_base::in | ios_base::trunc); + VERIFY( fb_03.write_position() ); + VERIFY( !fb_03.read_position() ); + strmsz_1 = fb_03.sgetn(carray1, 10); + VERIFY( strmsz_1 == 0 ); + VERIFY( fb_03.write_position() ); + VERIFY( !fb_03.read_position() ); + } + + // in | out 2 + { + constraint_filebuf fb_01; + fb_01.open(name_01, ios_base::in | ios_base::out); + VERIFY( fb_01.write_position() ); + strmsz_1 = fb_01.in_avail(); + strmsz_2 = fb_01.sgetn(carray1, 10); + VERIFY( strmsz_2 == 10 ); + strmsz_2 = fb_01.in_avail(); + VERIFY( strmsz_1 > strmsz_2 ); + c1 = fb_01.sgetc(); + VERIFY( c1 == 'b' ); + strmsz_1 = fb_01.in_avail(); + strmsz_2 = fb_01.sgetn(carray2, strmsz_1 + 5); + VERIFY( strmsz_1 == strmsz_2 - 5 ); + c4 = fb_01.sgetc(); // buffer should have underflowed from above. + VERIFY( c4 == 'h' ); + strmsz_1 = fb_01.in_avail(); + VERIFY( strmsz_1 > 0 ); + strmsz_2 = fb_01.sgetn(carray2, strmsz_1 + 5); + VERIFY( strmsz_1 == strmsz_2 ); //at the end of the actual file + VERIFY( fb_01.write_position() ); + VERIFY( !fb_01.read_position() ); + } +} + +main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/1-out.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/1-out.cc new file mode 100644 index 00000000000..dcefe01c6a1 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/1-out.cc @@ -0,0 +1,79 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_02[] = "tmp_sgetn_1out.tst"; // empty file, need to create + +// Test overloaded virtual functions. +void test05() +{ + using namespace std; + using namespace __gnu_cxx_test; + typedef filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test = true; + + streamsize strmsz_1, strmsz_2, strmsz_3; + int i = 0, j = 0, k = 0; + char carray1[13] = ""; + char carray2[8192] = ""; + int_type c1, c2, c3, c4; + + // streamsize sgetn(char_type *s, streamsize n) + // streamsize xsgetn(char_type *s, streamsize n) + // assign up to n chars to s from input sequence, indexing in_cur as + // approp and returning the number of chars assigned + + // out + { + constraint_filebuf fb_02; + fb_02.open(name_02, ios_base::out | ios_base::trunc); + VERIFY( fb_02.write_position() ); + VERIFY( !fb_02.read_position() ); + strmsz_2 = fb_02.in_avail(); + strmsz_2 = fb_02.sgetn(carray2, 10); + VERIFY( strmsz_2 == 0 ); + c2 = fb_02.sgetc(); + VERIFY( c2 == traits_type::eof() ); + strmsz_1 = fb_02.in_avail(); + strmsz_2 = fb_02.sgetn(carray2, strmsz_1 + 5); + VERIFY( strmsz_1 == -1 ); + VERIFY( strmsz_2 == 0 ); + c4 = fb_02.sgetc(); + VERIFY( c4 == traits_type::eof() ); + VERIFY( fb_02.write_position() ); + VERIFY( !fb_02.read_position() ); + } +} + +main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/1.cc deleted file mode 100644 index d890f3e7dcf..00000000000 --- a/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/1.cc +++ /dev/null @@ -1,148 +0,0 @@ -// 2001-05-21 Benjamin Kosnik - -// Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc. -// -// This file is part of the GNU ISO C++ Library. This library is free -// software; you can redistribute it and/or modify it under the -// terms of the GNU General Public License as published by the -// Free Software Foundation; either version 2, or (at your option) -// any later version. - -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License along -// with this library; see the file COPYING. If not, write to the Free -// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, -// USA. - -// 27.8.1.4 Overridden virtual functions - -#include -#include - -// @require@ %-*.tst %-*.txt -// @diff@ %-*.tst %*.txt - -// NB: This test assumes that _M_buf_size == 40, and not the usual -// buffer_size length of BUFSIZ (8192), so that overflow/underflow can be -// simulated a bit more readily. -// NRB (Nota Really Bene): setting it to 40 breaks the test, as intended. -const int buffer_size = 8192; -//const int buffer_size = 40; - -const char name_01[] = "filebuf_virtuals-1.txt"; // file with data in it -const char name_02[] = "filebuf_virtuals-2.txt"; // empty file, need to create -const char name_03[] = "filebuf_virtuals-3.txt"; // empty file, need to create - -class derived_filebuf: public std::filebuf -{ - public: - void - set_size(int_type __size) { _M_buf_size = __size; } -}; - -derived_filebuf fb_01; // in -derived_filebuf fb_02; // out -derived_filebuf fb_03; // in | out - -// Initialize filebufs to be the same size regardless of platform. -void test03() -{ - fb_01.set_size(buffer_size); - fb_02.set_size(buffer_size); - fb_03.set_size(buffer_size); -} - -// Test overloaded virtual functions. -void test05() -{ - using namespace std; - typedef filebuf::int_type int_type; - typedef filebuf::traits_type traits_type; - typedef filebuf::pos_type pos_type; - typedef filebuf::off_type off_type; - typedef size_t size_type; - - bool test = true; - filebuf f_tmp; - streamsize strmsz_1, strmsz_2; - streamoff strmof_1, strmof_2; - int i = 0, j = 0, k = 0; - - // GET - fb_01.open(name_01, ios_base::in); - fb_02.open(name_02, ios_base::out | ios_base::trunc); - fb_03.open(name_03, ios_base::out | ios_base::in | ios_base::trunc); - - strmof_1 = fb_01.in_avail(); - int_type c1 = fb_01.sbumpc(); - int_type c3 = fb_01.sbumpc(); - int_type c6 = fb_01.sgetc(); - int_type c8 = fb_01.sgetc(); - - strmof_2 = fb_02.in_avail(); - int_type c2 = fb_02.sbumpc(); - int_type c4 = fb_02.sbumpc(); - int_type c7 = fb_02.sgetc(); - int_type c9 = fb_02.sgetc(); - - strmof_1 = fb_03.in_avail(); - int_type c5 = fb_03.sbumpc(); - c5 = fb_03.sgetc(); - - // int_type snextc() - // calls sbumpc and if sbumpc != eof, return sgetc - c6 = fb_01.snextc(); - c6 = fb_01.snextc(); - - c7 = fb_02.snextc(); - c7 = fb_02.snextc(); - - c5 = fb_03.snextc(); - - // streamsize sgetn(char_type *s, streamsize n) - // streamsize xsgetn(char_type *s, streamsize n) - // assign up to n chars to s from input sequence, indexing in_cur as - // approp and returning the number of chars assigned - strmsz_1 = fb_01.in_avail(); - strmsz_2 = fb_02.in_avail(); - test = strmsz_1 != strmsz_2; - char carray1[13] = ""; - strmsz_1 = fb_01.sgetn(carray1, 10); - char carray2[buffer_size] = ""; - strmsz_2 = fb_02.sgetn(carray2, 10); - VERIFY( strmsz_1 != strmsz_2 ); - VERIFY( strmsz_1 == 10 ); - VERIFY( strmsz_2 == 0 ); - c1 = fb_01.sgetc(); - c2 = fb_02.sgetc(); - VERIFY( c1 == '\n' ); - VERIFY( c7 == c2 ); // n != i - strmsz_1 = fb_03.sgetn(carray1, 10); - VERIFY( !strmsz_1 ); //zero - strmsz_1 = fb_01.in_avail(); // N.B.: _M_in_end - _M_in_beg == BUFSIZ - 1 - strmsz_2 = fb_01.sgetn(carray2, strmsz_1 + 5); - VERIFY( strmsz_1 == strmsz_2 - 5 ); - c4 = fb_01.sgetc(); // buffer should have underflowed from above. - VERIFY( c4 == 'h' ); - strmsz_1 = fb_01.in_avail(); - VERIFY( strmsz_1 > 0 ); - strmsz_2 = fb_01.sgetn(carray2, strmsz_1 + 5); - VERIFY( strmsz_1 == strmsz_2 ); //at the end of the actual file - strmsz_1 = fb_02.in_avail(); - strmsz_2 = fb_02.sgetn(carray2, strmsz_1 + 5); - VERIFY( strmsz_1 == -1 ); - VERIFY( strmsz_2 == 0 ); - c4 = fb_02.sgetc(); // should be EOF - VERIFY( c4 == traits_type::eof() ); -} - -main() -{ - test03(); - test05(); - return 0; -} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/2-in.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/2-in.cc new file mode 100644 index 00000000000..62c5a0f93f0 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/2-in.cc @@ -0,0 +1,83 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_01[] = "sgetn.txt"; // file with data in it + +// Test overloaded virtual functions. +void test05() +{ + using namespace std; + using namespace __gnu_cxx_test; + typedef filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test = true; + + streamsize strmsz_1, strmsz_2, strmsz_3; + int i = 0, j = 0, k = 0; + char carray1[13] = ""; + char carray2[8192] = ""; + int_type c1, c2, c3, c4; + + // streamsize sgetn(char_type *s, streamsize n) + // streamsize xsgetn(char_type *s, streamsize n) + // assign up to n chars to s from input sequence, indexing in_cur as + // approp and returning the number of chars assigned + + // in + { + constraint_filebuf fb_01; + fb_01.pubsetbuf(0, 0); + fb_01.open(name_01, ios_base::in); + VERIFY( fb_01.unbuffered() ); + strmsz_1 = fb_01.in_avail(); + strmsz_2 = fb_01.sgetn(carray1, 10); + VERIFY( strmsz_2 == 10 ); + strmsz_2 = fb_01.in_avail(); + VERIFY( strmsz_1 > strmsz_2 ); + c1 = fb_01.sgetc(); + VERIFY( c1 == 'b' ); + strmsz_1 = fb_01.in_avail(); // 8181 or 8250 depending on buffer + strmsz_2 = fb_01.sgetn(carray2, 8181 + 5); + VERIFY( 8181 == strmsz_2 - 5 ); + c4 = fb_01.sgetc(); // buffer should have underflowed from above. + VERIFY( c4 == 'h' ); + strmsz_1 = fb_01.in_avail(); + VERIFY( strmsz_1 > 0 ); + strmsz_2 = fb_01.sgetn(carray2, 65 + 5); + VERIFY( 65 == strmsz_2 ); // at the end of the actual file + VERIFY( fb_01.unbuffered() ); + } +} + +main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/2-io.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/2-io.cc new file mode 100644 index 00000000000..30ccee29f2e --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/2-io.cc @@ -0,0 +1,95 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_01[] = "sgetn.txt"; // file with data in it +const char name_03[] = "tmp_sgetn_2io.tst"; // empty file, need to create + +// Test overloaded virtual functions. +void test05() +{ + using namespace std; + using namespace __gnu_cxx_test; + typedef filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test = true; + + streamsize strmsz_1, strmsz_2, strmsz_3; + int i = 0, j = 0, k = 0; + char carray1[13] = ""; + char carray2[8192] = ""; + int_type c1, c2, c3, c4; + + // streamsize sgetn(char_type *s, streamsize n) + // streamsize xsgetn(char_type *s, streamsize n) + // assign up to n chars to s from input sequence, indexing in_cur as + // approp and returning the number of chars assigned + + // in | out 1 + { + constraint_filebuf fb_03; + fb_03.pubsetbuf(0, 0); + fb_03.open(name_03, ios_base::out | ios_base::in | ios_base::trunc); + VERIFY( fb_03.unbuffered() ); + strmsz_1 = fb_03.sgetn(carray1, 10); + VERIFY( strmsz_1 == 0 ); + VERIFY( fb_03.unbuffered() ); + } + + // in | out 2 + { + constraint_filebuf fb_01; + fb_01.pubsetbuf(0, 0); + fb_01.open(name_01, ios_base::in | ios_base::out); + VERIFY( fb_01.unbuffered() ); + strmsz_1 = fb_01.in_avail(); + strmsz_2 = fb_01.sgetn(carray1, 10); + VERIFY( strmsz_2 == 10 ); + strmsz_2 = fb_01.in_avail(); + VERIFY( strmsz_1 > strmsz_2 ); + c1 = fb_01.sgetc(); + VERIFY( c1 == 'b' ); + strmsz_1 = fb_01.in_avail(); + strmsz_2 = fb_01.sgetn(carray2, 8181 + 5); + VERIFY( 8181 == strmsz_2 - 5 ); + c4 = fb_01.sgetc(); // buffer should have underflowed from above. + VERIFY( c4 == 'h' ); + strmsz_1 = fb_01.in_avail(); + VERIFY( strmsz_1 > 0 ); + strmsz_2 = fb_01.sgetn(carray2, 65 + 5); + VERIFY( 65 == strmsz_2 ); //at the end of the actual file + VERIFY( fb_01.unbuffered() ); + } +} + +main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/2-out.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/2-out.cc new file mode 100644 index 00000000000..99a907493d4 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/2-out.cc @@ -0,0 +1,79 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_02[] = "tmp_sgetn_2out.tst"; // empty file, need to create + +// Test overloaded virtual functions. +void test05() +{ + using namespace std; + using namespace __gnu_cxx_test; + typedef filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test = true; + + streamsize strmsz_1, strmsz_2, strmsz_3; + int i = 0, j = 0, k = 0; + char carray1[13] = ""; + char carray2[8192] = ""; + int_type c1, c2, c3, c4; + + // streamsize sgetn(char_type *s, streamsize n) + // streamsize xsgetn(char_type *s, streamsize n) + // assign up to n chars to s from input sequence, indexing in_cur as + // approp and returning the number of chars assigned + + // out + { + constraint_filebuf fb_02; + fb_02.pubsetbuf(0, 0); + fb_02.open(name_02, ios_base::out | ios_base::trunc); + VERIFY( fb_02.unbuffered() ); + VERIFY( !fb_02.read_position() ); + strmsz_2 = fb_02.in_avail(); + strmsz_2 = fb_02.sgetn(carray2, 10); + VERIFY( strmsz_2 == 0 ); + c2 = fb_02.sgetc(); + VERIFY( c2 == traits_type::eof() ); + strmsz_1 = fb_02.in_avail(); + strmsz_2 = fb_02.sgetn(carray2, strmsz_1 + 5); + VERIFY( strmsz_1 == -1 ); + VERIFY( strmsz_2 == 0 ); + c4 = fb_02.sgetc(); + VERIFY( fb_02.unbuffered() ); + VERIFY( !fb_02.read_position() ); + } +} + +main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/2.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/3.cc similarity index 94% rename from libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/2.cc rename to libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/3.cc index 6ed16712b88..d3e41805938 100644 --- a/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/2.cc +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/3.cc @@ -23,7 +23,7 @@ #include #include -const char name_01[] = "filebuf_virtuals-1.tst"; // empty file, need to create +const char name_01[] = "sgetn.txt"; void test06() { diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/snextc/char/1-in.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/snextc/char/1-in.cc new file mode 100644 index 00000000000..437a7fb6535 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/snextc/char/1-in.cc @@ -0,0 +1,84 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_01[] = "sgetc.txt"; // file with data in it +const char name_02[] = "tmp_snextc_1out.tst"; // empty file, need to create +const char name_03[] = "tmp_snextc_1io.tst"; // empty file, need to create + +void test05() +{ + using namespace std; + using namespace __gnu_cxx_test; + typedef filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test = true; + int_type c1, c2, c3; + + // int_type snextc() + // calls sbumpc and if sbumpc != eof, return sgetc + + // in + { + constraint_filebuf fb_01; + fb_01.open(name_01, ios_base::in); + VERIFY( !fb_01.write_position() ); + c1 = fb_01.snextc(); + VERIFY( c1 == '/' ); + c1 = fb_01.snextc(); + VERIFY( c1 == ' ' ); + VERIFY( !fb_01.write_position() ); + VERIFY( fb_01.read_position() ); + } + + // in + { + constraint_filebuf fb_01; + fb_01.open(name_01, ios_base::in); + VERIFY( !fb_01.write_position() ); + int_type c4 = fb_01.sbumpc(); + VERIFY( c4 == '/' ); + c4 = fb_01.sbumpc(); + VERIFY( c4 == '/' ); + c4 = fb_01.sgetc(); + VERIFY( c4 == ' ' ); + c1 = fb_01.snextc(); + VERIFY( c1 == '9' ); + c4 = fb_01.sgetc(); + VERIFY( c4 == '9' ); + VERIFY( !fb_01.write_position() ); + VERIFY( fb_01.read_position() ); + } +} + +main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/snextc/char/1-io.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/snextc/char/1-io.cc new file mode 100644 index 00000000000..0627648cc7b --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/snextc/char/1-io.cc @@ -0,0 +1,83 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_01[] = "sgetc.txt"; // file with data in it +const char name_02[] = "tmp_snextc_1out.tst"; // empty file, need to create +const char name_03[] = "tmp_snextc_1io.tst"; // empty file, need to create + +void test05() +{ + using namespace std; + using namespace __gnu_cxx_test; + typedef filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test = true; + int_type c1, c2, c3; + + // int_type snextc() + // calls sbumpc and if sbumpc != eof, return sgetc + + // in | out 1 + { + constraint_filebuf fb_03; + fb_03.open(name_03, ios_base::out | ios_base::in | ios_base::trunc); + VERIFY( fb_03.write_position() ); + VERIFY( !fb_03.read_position() ); + c3 = fb_03.snextc(); + VERIFY( c3 == traits_type::eof() ); + VERIFY( fb_03.write_position() ); + VERIFY( !fb_03.read_position() ); + } + + // in | out 2 + { + constraint_filebuf fb_01; + fb_01.open(name_01, ios_base::in | ios_base::out); + VERIFY( fb_01.write_position() ); + int_type c4 = fb_01.sbumpc(); + VERIFY( c4 == '/' ); + c4 = fb_01.sbumpc(); + VERIFY( c4 == '/' ); + c4 = fb_01.sgetc(); + VERIFY( c4 == ' ' ); + c1 = fb_01.snextc(); + VERIFY( c1 == '9' ); + c4 = fb_01.sgetc(); + VERIFY( c4 == '9' ); + VERIFY( fb_01.write_position() ); + VERIFY( fb_01.read_position() ); + } +} + +main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/snextc/char/1-out.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/snextc/char/1-out.cc new file mode 100644 index 00000000000..d226ac29699 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/snextc/char/1-out.cc @@ -0,0 +1,66 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_01[] = "sgetc.txt"; // file with data in it +const char name_02[] = "tmp_snextc_1out.tst"; // empty file, need to create +const char name_03[] = "tmp_snextc_1io.tst"; // empty file, need to create + +void test05() +{ + using namespace std; + using namespace __gnu_cxx_test; + typedef filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test = true; + int_type c1, c2, c3; + + // int_type snextc() + // calls sbumpc and if sbumpc != eof, return sgetc + + // out + { + constraint_filebuf fb_02; + fb_02.open(name_02, ios_base::out | ios_base::trunc); + VERIFY( fb_02.write_position() ); + VERIFY( !fb_02.read_position() ); + c2 = fb_02.snextc(); + VERIFY( c2 == traits_type::eof() ); + c2 = fb_02.snextc(); + VERIFY( c2 == traits_type::eof() ); + VERIFY( fb_02.write_position() ); + VERIFY( !fb_02.read_position() ); + } +} + +main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/snextc/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/snextc/char/1.cc deleted file mode 100644 index fb205bd701f..00000000000 --- a/libstdc++-v3/testsuite/27_io/basic_filebuf/snextc/char/1.cc +++ /dev/null @@ -1,116 +0,0 @@ -// 2001-05-21 Benjamin Kosnik - -// Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc. -// -// This file is part of the GNU ISO C++ Library. This library is free -// software; you can redistribute it and/or modify it under the -// terms of the GNU General Public License as published by the -// Free Software Foundation; either version 2, or (at your option) -// any later version. - -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License along -// with this library; see the file COPYING. If not, write to the Free -// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, -// USA. - -// 27.8.1.4 Overridden virtual functions - -#include -#include - -// @require@ %-*.tst %-*.txt -// @diff@ %-*.tst %*.txt - -// NB: This test assumes that _M_buf_size == 40, and not the usual -// buffer_size length of BUFSIZ (8192), so that overflow/underflow can be -// simulated a bit more readily. -// NRB (Nota Really Bene): setting it to 40 breaks the test, as intended. -const int buffer_size = 8192; -//const int buffer_size = 40; - -const char name_01[] = "filebuf_virtuals-1.txt"; // file with data in it -const char name_02[] = "filebuf_virtuals-2.txt"; // empty file, need to create -const char name_03[] = "filebuf_virtuals-3.txt"; // empty file, need to create - -class derived_filebuf: public std::filebuf -{ - public: - void - set_size(int_type __size) { _M_buf_size = __size; } -}; - -derived_filebuf fb_01; // in -derived_filebuf fb_02; // out -derived_filebuf fb_03; // in | out - -// Initialize filebufs to be the same size regardless of platform. -void test03() -{ - fb_01.set_size(buffer_size); - fb_02.set_size(buffer_size); - fb_03.set_size(buffer_size); -} - -// Test overloaded virtual functions. -void test05() -{ - using namespace std; - typedef filebuf::int_type int_type; - typedef filebuf::traits_type traits_type; - typedef filebuf::pos_type pos_type; - typedef filebuf::off_type off_type; - typedef size_t size_type; - - bool test = true; - filebuf f_tmp; - streamsize strmsz_1, strmsz_2; - streamoff strmof_1, strmof_2; - int i = 0, j = 0, k = 0; - - // GET - fb_01.open(name_01, ios_base::in); - fb_02.open(name_02, ios_base::out | ios_base::trunc); - fb_03.open(name_03, ios_base::out | ios_base::in | ios_base::trunc); - strmof_1 = fb_01.in_avail(); - strmof_2 = fb_02.in_avail(); - strmof_1 = fb_03.in_avail(); - - int_type c1 = fb_01.sbumpc(); - int_type c2 = fb_02.sbumpc(); - int_type c3 = fb_01.sbumpc(); - int_type c4 = fb_02.sbumpc(); - int_type c5 = fb_03.sbumpc(); - - int_type c6 = fb_01.sgetc(); - int_type c7 = fb_02.sgetc(); - int_type c8 = fb_01.sgetc(); - int_type c9 = fb_02.sgetc(); - c5 = fb_03.sgetc(); - - // int_type snextc() - // calls sbumpc and if sbumpc != eof, return sgetc - c6 = fb_01.snextc(); - c7 = fb_02.snextc(); - VERIFY( c6 != c8 ); - VERIFY( c7 == c9 ); // -1 - VERIFY( c6 == '\n' ); - c6 = fb_01.snextc(); - c7 = fb_02.snextc(); - VERIFY( c6 != c8 ); - VERIFY( c7 == c9 ); // -1 - VERIFY( c6 == '9' ); - c5 = fb_03.snextc(); - VERIFY( c5 == traits_type::eof() ); -} - -main() -{ - test03(); - test05(); - return 0; -} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/snextc/char/2-in.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/snextc/char/2-in.cc new file mode 100644 index 00000000000..8c563ad41e8 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/snextc/char/2-in.cc @@ -0,0 +1,82 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_01[] = "sgetc.txt"; // file with data in it + +void test05() +{ + using namespace std; + using namespace __gnu_cxx_test; + typedef filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test = true; + int_type c1, c2, c3; + + // int_type snextc() + // calls sbumpc and if sbumpc != eof, return sgetc + + // in + { + constraint_filebuf fb_01; + fb_01.pubsetbuf(0, 0); + fb_01.open(name_01, ios_base::in); + VERIFY( fb_01.unbuffered() ); + c1 = fb_01.snextc(); + VERIFY( c1 == '/' ); // overflow + c1 = fb_01.snextc(); + VERIFY( c1 == ' ' ); + VERIFY( fb_01.unbuffered() ); + } + + // in + { + constraint_filebuf fb_01; + fb_01.pubsetbuf(0, 0); + fb_01.open(name_01, ios_base::in); + VERIFY( fb_01.unbuffered() ); + int_type c4 = fb_01.sbumpc(); + VERIFY( c4 == '/' ); + c4 = fb_01.sbumpc(); + VERIFY( c4 == '/' ); + c4 = fb_01.sgetc(); + VERIFY( c4 == ' ' ); + c1 = fb_01.snextc(); + VERIFY( c1 == '9' ); + c4 = fb_01.sgetc(); + VERIFY( c4 == '9' ); + VERIFY( fb_01.unbuffered() ); + } +} + +main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/snextc/char/2-io.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/snextc/char/2-io.cc new file mode 100644 index 00000000000..a044c6d4f41 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/snextc/char/2-io.cc @@ -0,0 +1,81 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_01[] = "sgetc.txt"; // file with data in it +const char name_03[] = "tmp_snextc_2io.tst"; // empty file, need to create + +void test05() +{ + using namespace std; + using namespace __gnu_cxx_test; + typedef filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test = true; + int_type c1, c2, c3; + + // int_type snextc() + // calls sbumpc and if sbumpc != eof, return sgetc + + // in | out 1 + { + constraint_filebuf fb_03; + fb_03.pubsetbuf(0, 0); + fb_03.open(name_03, ios_base::out | ios_base::in | ios_base::trunc); + VERIFY( fb_03.unbuffered() ); + c3 = fb_03.snextc(); + VERIFY( c3 == traits_type::eof() ); + VERIFY( fb_03.unbuffered() ); + } + + // in | out 2 + { + constraint_filebuf fb_01; + fb_01.pubsetbuf(0, 0); + fb_01.open(name_01, ios_base::in | ios_base::out); + VERIFY( fb_01.unbuffered() ); + int_type c4 = fb_01.sbumpc(); + VERIFY( c4 == '/' ); + c4 = fb_01.sbumpc(); + VERIFY( c4 == '/' ); + c4 = fb_01.sgetc(); + VERIFY( c4 == ' ' ); + c1 = fb_01.snextc(); + VERIFY( c1 == '9' ); + c4 = fb_01.sgetc(); + VERIFY( c4 == '9' ); + VERIFY( fb_01.unbuffered() ); + } +} + +main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/snextc/char/2-out.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/snextc/char/2-out.cc new file mode 100644 index 00000000000..8af126337f6 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/snextc/char/2-out.cc @@ -0,0 +1,63 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_02[] = "tmp_snextc_2out.tst"; // empty file, need to create + +void test05() +{ + using namespace std; + using namespace __gnu_cxx_test; + typedef filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test = true; + int_type c1, c2, c3; + + // int_type snextc() + // calls sbumpc and if sbumpc != eof, return sgetc + + // out + { + constraint_filebuf fb_02; + fb_02.pubsetbuf(0, 0); + fb_02.open(name_02, ios_base::out | ios_base::trunc); + VERIFY( fb_02.unbuffered() ); + c2 = fb_02.snextc(); + VERIFY( c2 == traits_type::eof() ); + c2 = fb_02.snextc(); + VERIFY( c2 == traits_type::eof() ); + VERIFY( fb_02.unbuffered() ); + } +} + +main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sputc/char/1-in.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputc/char/1-in.cc new file mode 100644 index 00000000000..25d9ee0ce8d --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputc/char/1-in.cc @@ -0,0 +1,65 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_01[] = "filebuf_virtuals-1.txt"; // file with data in it + +void test05() +{ + using namespace std; + using namespace __gnu_cxx_test; + + typedef filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test = true; + streamsize strmsz_1, strmsz_2; + int i = 0, j = 0, k = 0; + int_type c1, c2, c3; + + // int_type sputc(char_type c) + // if out_cur not avail, return overflow(traits_type::to_int_type(c)) + // else, stores c at out_cur, + // increments out_cur, and returns c as int_type + + // in + { + constraint_filebuf fb_01; + fb_01.open(name_01, ios_base::in); + VERIFY( !fb_01.write_position() ); + c3 = fb_01.sputc('a'); + VERIFY( c3 == traits_type::eof() ); + VERIFY( !fb_01.write_position() ); + } +} + +main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sputc/char/1-io.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputc/char/1-io.cc new file mode 100644 index 00000000000..c1717612b6c --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputc/char/1-io.cc @@ -0,0 +1,72 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_01[] = "filebuf_virtuals-1.txt"; // file with data in it +const char name_03[] = "tmp_sputc_1io.tst"; + +void test05() +{ + using namespace std; + using namespace __gnu_cxx_test; + + typedef filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test = true; + streamsize strmsz_1, strmsz_2; + int i = 0, j = 0, k = 0; + int_type c1, c2, c3; + + // int_type sputc(char_type c) + // if out_cur not avail, return overflow(traits_type::to_int_type(c)) + // else, stores c at out_cur, + // increments out_cur, and returns c as int_type + + // in | out 1 + { + constraint_filebuf fb_03; + fb_03.open(name_03, ios_base::out | ios_base::in | ios_base::trunc); + VERIFY( fb_03.write_position() ); + VERIFY( !fb_03.read_position() ); + c1 = fb_03.sputc('b'); + VERIFY( c1 == 'b' ); + c2 = fb_03.sputc('d'); + VERIFY( c2 == 'd' ); + for (int i = 50; i <= 90; ++i) + c2 = fb_03.sputc(char(i)); + VERIFY( fb_03.write_position() ); + VERIFY( !fb_03.read_position() ); + } +} + +main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sputc/char/1-out.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputc/char/1-out.cc new file mode 100644 index 00000000000..987b4e26217 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputc/char/1-out.cc @@ -0,0 +1,71 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_02[] = "tmp_sputc_1out.tst"; // empty file, need to create + +void test05() +{ + using namespace std; + using namespace __gnu_cxx_test; + + typedef filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test = true; + streamsize strmsz_1, strmsz_2; + int i = 0, j = 0, k = 0; + int_type c1, c2, c3; + + // int_type sputc(char_type c) + // if out_cur not avail, return overflow(traits_type::to_int_type(c)) + // else, stores c at out_cur, + // increments out_cur, and returns c as int_type + + // out + { + constraint_filebuf fb_02; + fb_02.open(name_02, ios_base::out | ios_base::trunc); + VERIFY( fb_02.write_position() ); + VERIFY( !fb_02.read_position() ); + c1 = fb_02.sputc('a'); + VERIFY( c1 == 'a' ); + c2 = fb_02.sputc('c'); + VERIFY( c2 == 'c' ); + for (int i = 50; i <= 90; ++i) + c2 = fb_02.sputc(char(i)); + VERIFY( fb_02.write_position() ); + VERIFY( !fb_02.read_position() ); + } +} + +main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sputc/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputc/char/1.cc deleted file mode 100644 index b02c70fb49a..00000000000 --- a/libstdc++-v3/testsuite/27_io/basic_filebuf/sputc/char/1.cc +++ /dev/null @@ -1,124 +0,0 @@ -// 2001-05-21 Benjamin Kosnik - -// Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc. -// -// This file is part of the GNU ISO C++ Library. This library is free -// software; you can redistribute it and/or modify it under the -// terms of the GNU General Public License as published by the -// Free Software Foundation; either version 2, or (at your option) -// any later version. - -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License along -// with this library; see the file COPYING. If not, write to the Free -// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, -// USA. - -// 27.8.1.4 Overridden virtual functions - -#include -#include - -// @require@ %-*.tst %-*.txt -// @diff@ %-*.tst %*.txt - -// NB: This test assumes that _M_buf_size == 40, and not the usual -// buffer_size length of BUFSIZ (8192), so that overflow/underflow can be -// simulated a bit more readily. -// NRB (Nota Really Bene): setting it to 40 breaks the test, as intended. -const int buffer_size = 8192; -//const int buffer_size = 40; - -const char name_01[] = "filebuf_virtuals-1.txt"; // file with data in it -const char name_02[] = "filebuf_virtuals-2.txt"; // empty file, need to create -const char name_03[] = "filebuf_virtuals-3.txt"; // empty file, need to create - -class derived_filebuf: public std::filebuf -{ - public: - void - set_size(int_type __size) { _M_buf_size = __size; } -}; - -derived_filebuf fb_01; // in -derived_filebuf fb_02; // out -derived_filebuf fb_03; // in | out - -// Initialize filebufs to be the same size regardless of platform. -void test03() -{ - fb_01.set_size(buffer_size); - fb_02.set_size(buffer_size); - fb_03.set_size(buffer_size); -} - -// Test overloaded virtual functions. -void test05() -{ - typedef std::filebuf::int_type int_type; - typedef std::filebuf::traits_type traits_type; - typedef std::filebuf::pos_type pos_type; - typedef std::filebuf::off_type off_type; - typedef size_t size_type; - - bool test = true; - std::filebuf f_tmp; - std::streamsize strmsz_1, strmsz_2; - std::streamoff strmof_1, strmof_2; - int i = 0, j = 0, k = 0; - - fb_01.open(name_01, std::ios_base::in); - fb_02.open(name_02, std::ios_base::out | std::ios_base::trunc); - fb_03.open(name_03, std::ios_base::out | std::ios_base::in | std::ios_base::trunc); - - int_type c1 = fb_01.sbumpc(); - int_type c2 = fb_02.sbumpc(); - int_type c3 = fb_01.sbumpc(); - int_type c4 = fb_02.sbumpc(); - int_type c5 = fb_03.sbumpc(); - int_type c6 = fb_01.sgetc(); - int_type c7 = fb_02.sgetc(); - int_type c8 = fb_01.sgetc(); - int_type c9 = fb_02.sgetc(); - - // PUT - // int_type sputc(char_type c) - // if out_cur not avail, return overflow(traits_type::to_int_type(c)) - // else, stores c at out_cur, - // increments out_cur, and returns c as int_type - // strmsz_1 = fb_03.in_avail(); // XXX valid for in|out?? - c1 = fb_02.sputc('a'); - c2 = fb_03.sputc('b'); - VERIFY( c1 != c2 ); - c1 = fb_02.sputc('c'); - c2 = fb_03.sputc('d'); - VERIFY( c1 != c2 ); - // strmsz_2 = fb_03.in_avail(); - // VERIFY( strmsz_1 != strmsz_2 ); - for (int i = 50; i <= 90; ++i) - c2 = fb_02.sputc(char(i)); - // 27filebuf-2.txt == ac23456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWX - // fb_02._M_out_cur = '2' - strmsz_1 = fb_03.in_avail(); - for (int i = 50; i <= 90; ++i) - c2 = fb_03.sputc(char(i)); - strmsz_2 = fb_03.in_avail(); - // VERIFY( strmsz_1 != strmsz_2 ); - // VERIFY( strmsz_1 > 0 ); - // VERIFY( strmsz_2 > 0 ); - // 27filebuf-2.txt == bd23456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWX - // fb_02._M_out_cur = '2' - c3 = fb_01.sputc('a'); // should be EOF because this is read-only - VERIFY( c3 == traits_type::eof() ); -} - -main() -{ - test03(); - test05(); - return 0; -} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sputc/char/2-in.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputc/char/2-in.cc new file mode 100644 index 00000000000..85ab4efbeff --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputc/char/2-in.cc @@ -0,0 +1,66 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_01[] = "filebuf_virtuals-1.txt"; // file with data in it + +void test05() +{ + using namespace std; + using namespace __gnu_cxx_test; + + typedef filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test = true; + streamsize strmsz_1, strmsz_2; + int i = 0, j = 0, k = 0; + int_type c1, c2, c3; + + // int_type sputc(char_type c) + // if out_cur not avail, return overflow(traits_type::to_int_type(c)) + // else, stores c at out_cur, + // increments out_cur, and returns c as int_type + + // in + { + constraint_filebuf fb_01; + fb_01.pubsetbuf(0, 0); + fb_01.open(name_01, ios_base::in); + VERIFY( fb_01.unbuffered() ); + c3 = fb_01.sputc('a'); + VERIFY( c3 == traits_type::eof() ); + VERIFY( fb_01.unbuffered() ); + } +} + +main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sputc/char/2-io.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputc/char/2-io.cc new file mode 100644 index 00000000000..373a6a8cba5 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputc/char/2-io.cc @@ -0,0 +1,71 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_01[] = "filebuf_virtuals-1.txt"; // file with data in it +const char name_03[] = "tmp_sputc_2io.tst"; + +void test05() +{ + using namespace std; + using namespace __gnu_cxx_test; + + typedef filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test = true; + streamsize strmsz_1, strmsz_2; + int i = 0, j = 0, k = 0; + int_type c1, c2, c3; + + // int_type sputc(char_type c) + // if out_cur not avail, return overflow(traits_type::to_int_type(c)) + // else, stores c at out_cur, + // increments out_cur, and returns c as int_type + + // in | out 1 + { + constraint_filebuf fb_03; + fb_03.pubsetbuf(0, 0); + fb_03.open(name_03, ios_base::out | ios_base::in | ios_base::trunc); + VERIFY( fb_03.unbuffered() ); + c1 = fb_03.sputc('b'); + VERIFY( c1 == 'b' ); + c2 = fb_03.sputc('d'); + VERIFY( c2 == 'd' ); + for (int i = 50; i <= 90; ++i) + c2 = fb_03.sputc(char(i)); + VERIFY( fb_03.unbuffered() ); + } +} + +main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sputc/char/2-out.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputc/char/2-out.cc new file mode 100644 index 00000000000..96e12954a97 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputc/char/2-out.cc @@ -0,0 +1,72 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_02[] = "tmp_sputc_2out.tst"; // empty file, need to create + +void test05() +{ + using namespace std; + using namespace __gnu_cxx_test; + + typedef filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test = true; + streamsize strmsz_1, strmsz_2; + int i = 0, j = 0, k = 0; + int_type c1, c2, c3; + + // int_type sputc(char_type c) + // if out_cur not avail, return overflow(traits_type::to_int_type(c)) + // else, stores c at out_cur, + // increments out_cur, and returns c as int_type + + // out + { + constraint_filebuf fb_02; + fb_02.pubsetbuf(0, 0); + fb_02.open(name_02, ios_base::out | ios_base::trunc); + VERIFY( fb_02.unbuffered() ); + VERIFY( !fb_02.read_position() ); + c1 = fb_02.sputc('a'); + VERIFY( c1 == 'a' ); + c2 = fb_02.sputc('c'); + VERIFY( c2 == 'c' ); + for (int i = 50; i <= 90; ++i) + c2 = fb_02.sputc(char(i)); + VERIFY( fb_02.unbuffered() ); + VERIFY( !fb_02.read_position() ); + } +} + +main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sputc/char/2.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputc/char/2.cc deleted file mode 100644 index f6a4ae8b0db..00000000000 --- a/libstdc++-v3/testsuite/27_io/basic_filebuf/sputc/char/2.cc +++ /dev/null @@ -1,129 +0,0 @@ -// 2003-05-21 Benjamin Kosnik - -// Copyright (C) 2003 Free Software Foundation, Inc. -// -// This file is part of the GNU ISO C++ Library. This library is free -// software; you can redistribute it and/or modify it under the -// terms of the GNU General Public License as published by the -// Free Software Foundation; either version 2, or (at your option) -// any later version. - -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License along -// with this library; see the file COPYING. If not, write to the Free -// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, -// USA. - -// 27.8.1.4 Overridden virtual functions - -#include -#include - -// @require@ %-*.tst %-*.txt -// @diff@ %-*.tst %*.txt - -// NB: This test assumes that _M_buf_size == 40, and not the usual -// buffer_size length of BUFSIZ (8192), so that overflow/underflow can be -// simulated a bit more readily. -// NRB (Nota Really Bene): setting it to 40 breaks the test, as intended. -const int buffer_size = 8192; -//const int buffer_size = 40; - -const char name_01[] = "filebuf_virtuals-1.txt"; // file with data in it -const char name_02[] = "filebuf_virtuals-2.txt"; // empty file, need to create -const char name_03[] = "filebuf_virtuals-3.txt"; // empty file, need to create - -class derived_filebuf: public std::filebuf -{ - public: - void - set_size(int_type __size) { _M_buf_size = __size; } -}; - -derived_filebuf fb_01; // in -derived_filebuf fb_02; // out -derived_filebuf fb_03; // in | out - -// Initialize filebufs to be the same size regardless of platform. -void test03() -{ - fb_01.set_size(buffer_size); - fb_02.set_size(buffer_size); - fb_03.set_size(buffer_size); -} - -// Test overloaded virtual functions. -void test05() -{ - typedef std::filebuf::int_type int_type; - typedef std::filebuf::traits_type traits_type; - typedef std::filebuf::pos_type pos_type; - typedef std::filebuf::off_type off_type; - typedef size_t size_type; - - bool test = true; - std::filebuf f_tmp; - std::streamsize strmsz_1, strmsz_2; - std::streamoff strmof_1, strmof_2; - int i = 0, j = 0, k = 0; - - // Unbuffered - fb_01.pubsetbuf(0, 0); - fb_02.pubsetbuf(0, 0); - fb_03.pubsetbuf(0, 0); - - fb_01.open(name_01, std::ios_base::in); - fb_02.open(name_02, std::ios_base::out | std::ios_base::trunc); - fb_03.open(name_03, std::ios_base::out | std::ios_base::in | std::ios_base::trunc); - - int_type c1 = fb_01.sbumpc(); - int_type c2 = fb_02.sbumpc(); - int_type c3 = fb_01.sbumpc(); - int_type c4 = fb_02.sbumpc(); - int_type c5 = fb_03.sbumpc(); - int_type c6 = fb_01.sgetc(); - int_type c7 = fb_02.sgetc(); - int_type c8 = fb_01.sgetc(); - int_type c9 = fb_02.sgetc(); - - // PUT - // int_type sputc(char_type c) - // if out_cur not avail, return overflow(traits_type::to_int_type(c)) - // else, stores c at out_cur, - // increments out_cur, and returns c as int_type - // strmsz_1 = fb_03.in_avail(); // XXX valid for in|out?? - c1 = fb_02.sputc('a'); - c2 = fb_03.sputc('b'); - VERIFY( c1 != c2 ); - c1 = fb_02.sputc('c'); - c2 = fb_03.sputc('d'); - VERIFY( c1 != c2 ); - // strmsz_2 = fb_03.in_avail(); - // VERIFY( strmsz_1 != strmsz_2 ); - for (int i = 50; i <= 90; ++i) - c2 = fb_02.sputc(char(i)); - // 27filebuf-2.txt == ac23456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWX - // fb_02._M_out_cur = '2' - strmsz_1 = fb_03.in_avail(); - for (int i = 50; i <= 90; ++i) - c2 = fb_03.sputc(char(i)); - strmsz_2 = fb_03.in_avail(); - // VERIFY( strmsz_1 != strmsz_2 ); - // VERIFY( strmsz_1 > 0 ); - // VERIFY( strmsz_2 > 0 ); - // 27filebuf-2.txt == bd23456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWX - // fb_02._M_out_cur = '2' - c3 = fb_01.sputc('a'); // should be EOF because this is read-only - VERIFY( c3 == traits_type::eof() ); -} - -main() -{ - test03(); - test05(); - return 0; -} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sputn/char/1-in.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputn/char/1-in.cc new file mode 100644 index 00000000000..235fce07e22 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputn/char/1-in.cc @@ -0,0 +1,63 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_01[] = "filebuf_virtuals-1.txt"; // file with data in it + +void test05() +{ + using namespace std; + using namespace __gnu_cxx_test; + + typedef filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + typedef size_t size_type; + + bool test = true; + streamsize strmsz_1, strmsz_2; + + // streamsize sputn(const char_typs* s, streamsize n) + // write up to n chars to out_cur from s, returning number assigned + // NB *sputn will happily put '\0' into your stream if you give it a chance* + + // in + { + constraint_filebuf fb_01; + fb_01.open(name_01, ios_base::in); + VERIFY( !fb_01.write_position() ); + strmsz_1 = fb_01.sputn("racadabra", 10); + VERIFY( strmsz_1 == 0 ); + VERIFY( !fb_01.write_position() ); + } +} + +main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sputn/char/1-io.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputn/char/1-io.cc new file mode 100644 index 00000000000..37509601427 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputn/char/1-io.cc @@ -0,0 +1,69 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_01[] = "filebuf_virtuals-1.txt"; // file with data in it +const char name_03[] = "tmp_sputn_1io.tst"; // empty file, need to create + +void test05() +{ + using namespace std; + using namespace __gnu_cxx_test; + + typedef filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + typedef size_t size_type; + + bool test = true; + streamsize strmsz_1, strmsz_2; + + // streamsize sputn(const char_typs* s, streamsize n) + // write up to n chars to out_cur from s, returning number assigned + // NB *sputn will happily put '\0' into your stream if you give it a chance* + + // in | out + { + constraint_filebuf fb_03; + fb_03.open(name_03, ios_base::out | ios_base::in | ios_base::trunc); + VERIFY( fb_03.write_position() ); + VERIFY( !fb_03.read_position() ); + strmsz_1 = fb_03.sputn("racadabras", 10);//"abracadabras or what?" + VERIFY( strmsz_1 == 10 ); + strmsz_2 = fb_03.sputn(", i wanna reach out and", 10); + VERIFY( strmsz_2 == 10 ); + VERIFY( strmsz_1 == strmsz_2 ); + VERIFY( fb_03.write_position() ); + VERIFY( !fb_03.read_position() ); + } +} + +main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sputn/char/1-out.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputn/char/1-out.cc new file mode 100644 index 00000000000..647f310d87f --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputn/char/1-out.cc @@ -0,0 +1,65 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_02[] = "tmp_sputn_1out.tst"; // empty file, need to create + +void test05() +{ + using namespace std; + using namespace __gnu_cxx_test; + + typedef filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + typedef size_t size_type; + + bool test = true; + streamsize strmsz_1, strmsz_2; + + // streamsize sputn(const char_typs* s, streamsize n) + // write up to n chars to out_cur from s, returning number assigned + // NB *sputn will happily put '\0' into your stream if you give it a chance* + + // out + { + constraint_filebuf fb_02; + fb_02.open(name_02, ios_base::out | ios_base::trunc); + VERIFY( fb_02.write_position() ); + VERIFY( !fb_02.read_position() ); + strmsz_1 = fb_02.sputn("racadabras", 10); + VERIFY( strmsz_1 == 10 ); + VERIFY( fb_02.write_position() ); + VERIFY( !fb_02.read_position() ); + } +} + +main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sputn/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputn/char/1.cc deleted file mode 100644 index 151ae42d66f..00000000000 --- a/libstdc++-v3/testsuite/27_io/basic_filebuf/sputn/char/1.cc +++ /dev/null @@ -1,112 +0,0 @@ -// 2001-05-21 Benjamin Kosnik - -// Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc. -// -// This file is part of the GNU ISO C++ Library. This library is free -// software; you can redistribute it and/or modify it under the -// terms of the GNU General Public License as published by the -// Free Software Foundation; either version 2, or (at your option) -// any later version. - -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License along -// with this library; see the file COPYING. If not, write to the Free -// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, -// USA. - -// 27.8.1.4 Overridden virtual functions - -#include -#include - -// @require@ %-*.tst %-*.txt -// @diff@ %-*.tst %*.txt - -// NB: This test assumes that _M_buf_size == 40, and not the usual -// buffer_size length of BUFSIZ (8192), so that overflow/underflow can be -// simulated a bit more readily. -// NRB (Nota Really Bene): setting it to 40 breaks the test, as intended. -const int buffer_size = 8192; -//const int buffer_size = 40; - -const char name_01[] = "filebuf_virtuals-1.txt"; // file with data in it -const char name_02[] = "filebuf_virtuals-2.txt"; // empty file, need to create -const char name_03[] = "filebuf_virtuals-3.txt"; // empty file, need to create - -class derived_filebuf: public std::filebuf -{ - public: - void - set_size(int_type __size) { _M_buf_size = __size; } -}; - -derived_filebuf fb_01; // in -derived_filebuf fb_02; // out -derived_filebuf fb_03; // in | out - -// Initialize filebufs to be the same size regardless of platform. -void test03() -{ - fb_01.set_size(buffer_size); - fb_02.set_size(buffer_size); - fb_03.set_size(buffer_size); -} - -// Test overloaded virtual functions. -void test05() -{ - typedef std::filebuf::int_type int_type; - typedef std::filebuf::traits_type traits_type; - typedef std::filebuf::pos_type pos_type; - typedef std::filebuf::off_type off_type; - typedef size_t size_type; - - bool test = true; - std::filebuf f_tmp; - std::streamsize strmsz_1, strmsz_2; - std::streamoff strmof_1, strmof_2; - int i = 0, j = 0, k = 0; - - fb_01.open(name_01, std::ios_base::in); - fb_02.open(name_02, std::ios_base::out | std::ios_base::trunc); - fb_03.open(name_03, std::ios_base::out | std::ios_base::in | std::ios_base::trunc); - - int_type c1 = fb_01.sbumpc(); - int_type c2 = fb_02.sbumpc(); - int_type c3 = fb_01.sbumpc(); - int_type c4 = fb_02.sbumpc(); - int_type c5 = fb_03.sbumpc(); - int_type c6 = fb_01.sgetc(); - int_type c7 = fb_02.sgetc(); - int_type c8 = fb_01.sgetc(); - int_type c9 = fb_02.sgetc(); - - // PUT - // streamsize sputn(const char_typs* s, streamsize n) - // write up to n chars to out_cur from s, returning number assigned - // NB *sputn will happily put '\0' into your stream if you give it a chance* - strmsz_1 = fb_03.sputn("racadabras", 10);//"abracadabras or what?" - VERIFY( strmsz_1 == 10 ); - strmsz_2 = fb_03.sputn(", i wanna reach out and", 10); - VERIFY( strmsz_2 == 10 ); - VERIFY( strmsz_1 == strmsz_2 ); - // fb_03._M_out_beg = "YZracadabras, i wanna FGHIJKLMNOPQRSTUVW" - // fb_03._M_out_cur = "FGHIJKLMNOPQRSTUVW" - strmsz_1 = fb_02.sputn("racadabras", 10); - VERIFY( strmsz_1 == 10 ); - // fb_02._M_out_beg = "YZracadabras<=>?@ABCDEFGHIJKLMNOPQRSTUVW" - // fb_02._M_out_cur = "<=>?@ABCDEFGHIJKLMNOPQRSTUVW" - strmsz_1 = fb_01.sputn("racadabra", 10); - VERIFY( strmsz_1 == 0 ); -} - -main() -{ - test03(); - test05(); - return 0; -} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sputn/char/2-in.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputn/char/2-in.cc new file mode 100644 index 00000000000..8972b5efcb8 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputn/char/2-in.cc @@ -0,0 +1,64 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_01[] = "filebuf_virtuals-1.txt"; // file with data in it + +void test05() +{ + using namespace std; + using namespace __gnu_cxx_test; + + typedef filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + typedef size_t size_type; + + bool test = true; + streamsize strmsz_1, strmsz_2; + + // streamsize sputn(const char_typs* s, streamsize n) + // write up to n chars to out_cur from s, returning number assigned + // NB *sputn will happily put '\0' into your stream if you give it a chance* + + // in + { + constraint_filebuf fb_01; + fb_01.pubsetbuf(0, 0); + fb_01.open(name_01, ios_base::in); + VERIFY( fb_01.unbuffered() ); + strmsz_1 = fb_01.sputn("racadabra", 10); + VERIFY( strmsz_1 == 0 ); + VERIFY( fb_01.unbuffered() ); + } +} + +main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sputn/char/2-io.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputn/char/2-io.cc new file mode 100644 index 00000000000..c6109c2f100 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputn/char/2-io.cc @@ -0,0 +1,68 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_01[] = "filebuf_virtuals-1.txt"; // file with data in it +const char name_03[] = "tmp_sputn_2io.tst"; // empty file, need to create + +void test05() +{ + using namespace std; + using namespace __gnu_cxx_test; + + typedef filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + typedef size_t size_type; + + bool test = true; + streamsize strmsz_1, strmsz_2; + + // streamsize sputn(const char_typs* s, streamsize n) + // write up to n chars to out_cur from s, returning number assigned + // NB *sputn will happily put '\0' into your stream if you give it a chance* + + // in | out + { + constraint_filebuf fb_03; + fb_03.pubsetbuf(0, 0); + fb_03.open(name_03, ios_base::out | ios_base::in | ios_base::trunc); + VERIFY( fb_03.unbuffered() ); + strmsz_1 = fb_03.sputn("racadabras", 10);//"abracadabras or what?" + VERIFY( strmsz_1 == 10 ); + strmsz_2 = fb_03.sputn(", i wanna reach out and", 10); + VERIFY( strmsz_2 == 10 ); + VERIFY( strmsz_1 == strmsz_2 ); + VERIFY( fb_03.unbuffered() ); + } +} + +main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sputn/char/2-out.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputn/char/2-out.cc new file mode 100644 index 00000000000..81cd506aba1 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputn/char/2-out.cc @@ -0,0 +1,66 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_02[] = "tmp_sputn_2out.tst"; // empty file, need to create + +void test05() +{ + using namespace std; + using namespace __gnu_cxx_test; + + typedef filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + typedef size_t size_type; + + bool test = true; + streamsize strmsz_1, strmsz_2; + + // streamsize sputn(const char_typs* s, streamsize n) + // write up to n chars to out_cur from s, returning number assigned + // NB *sputn will happily put '\0' into your stream if you give it a chance* + + // out + { + constraint_filebuf fb_02; + fb_02.pubsetbuf(0, 0); + fb_02.open(name_02, ios_base::out | ios_base::trunc); + VERIFY( fb_02.unbuffered() ); + VERIFY( !fb_02.read_position() ); + strmsz_1 = fb_02.sputn("racadabras", 10); + VERIFY( strmsz_1 == 10 ); + VERIFY( fb_02.unbuffered() ); + VERIFY( !fb_02.read_position() ); + } +} + +main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/data/sgetc.txt b/libstdc++-v3/testsuite/data/sgetc.txt new file mode 100644 index 00000000000..87e81f67772 --- /dev/null +++ b/libstdc++-v3/testsuite/data/sgetc.txt @@ -0,0 +1,3 @@ +// 990117 bkoz +// test functionality of basic_filebuf for char_type == char +// this is a data file for 27filebuf.cc diff --git a/libstdc++-v3/testsuite/data/sgetn.txt b/libstdc++-v3/testsuite/data/sgetn.txt new file mode 100644 index 00000000000..cb3c57f7dfd --- /dev/null +++ b/libstdc++-v3/testsuite/data/sgetn.txt @@ -0,0 +1,158 @@ +// 990117 bkoz +// test functionality of basic_filebuf for char_type == char +// this is a data file for 27filebuf.cc + +// Copyright (C) 1997-1999 Cygnus Solutions +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +/mnt/cdrom/sarah_vaughan/sarah_vaughan.allofme +/mnt/cdrom/sarah_vaughan/sarah_vaughan.speaklow + +/mnt/cdrom/nikkigiovanni_thewayifeel/ng_01_the_way_i_feel +/mnt/cdrom/nikkigiovanni_thewayifeel/ng_02_seduction_kidnap +/mnt/cdrom/nikkigiovanni_thewayifeel/ng_03_just_a_ny_poem +/mnt/cdrom/nikkigiovanni_thewayifeel/ng_04_butterflies_i_remem +/mnt/cdrom/nikkigiovanni_thewayifeel/ng_05_luxury_poem +/mnt/cdrom/nikkigiovanni_thewayifeel/ng_06_my_house +/mnt/cdrom/nikkigiovanni_thewayifeel/ng_07_the_women_gather +/mnt/cdrom/nikkigiovanni_thewayifeel/ng_08_the_life_i_led +/mnt/cdrom/nikkigiovanni_thewayifeel/ng_09_when_i_die +/mnt/cdrom/nikkigiovanni_thewayifeel/ng_10_revolutionary_dreams +/mnt/cdrom/nikkigiovanni_thewayifeel/ng_11_winter_poem +/mnt/cdrom/nikkigiovanni_thewayifeel/ng_12_a_certain_peace_i_nap +/mnt/cdrom/nikkigiovanni_thewayifeel/ng_13_poem_for_a_lady_whose + +/mnt/cdrom/marley-songs_of_freedom/disk_1/ +/mnt/cdrom/marley-songs_of_freedom/disk_2/ +/mnt/cdrom/marley-songs_of_freedom/disk_4/ + +/mnt/cdrom/marley-songs_of_freedom/disk_1/back out +/mnt/cdrom/marley-songs_of_freedom/disk_1/bend down low +/mnt/cdrom/marley-songs_of_freedom/disk_1/bus dem shut (pyaka) +/mnt/cdrom/marley-songs_of_freedom/disk_1/caution +/mnt/cdrom/marley-songs_of_freedom/disk_1/do it twice +/mnt/cdrom/marley-songs_of_freedom/disk_1/don't rock the boat +/mnt/cdrom/marley-songs_of_freedom/disk_1/duppy conqueror +/mnt/cdrom/marley-songs_of_freedom/disk_1/hammer +/mnt/cdrom/marley-songs_of_freedom/disk_1/hypocrites +/mnt/cdrom/marley-songs_of_freedom/disk_1/i'm still waiting +/mnt/cdrom/marley-songs_of_freedom/disk_1/judge not +/mnt/cdrom/marley-songs_of_freedom/disk_1/mellow mood +/mnt/cdrom/marley-songs_of_freedom/disk_1/mr brown +/mnt/cdrom/marley-songs_of_freedom/disk_1/nice time +/mnt/cdrom/marley-songs_of_freedom/disk_1/one cup of coffee +/mnt/cdrom/marley-songs_of_freedom/disk_1/one love_people get ready +/mnt/cdrom/marley-songs_of_freedom/disk_1/put it on +/mnt/cdrom/marley-songs_of_freedom/disk_1/simmer down +/mnt/cdrom/marley-songs_of_freedom/disk_1/small axe +/mnt/cdrom/marley-songs_of_freedom/disk_1/soul rebel +/mnt/cdrom/marley-songs_of_freedom/disk_1/soul shake down party +/mnt/cdrom/marley-songs_of_freedom/disk_1/stir it up (original) +/mnt/cdrom/marley-songs_of_freedom/disk_1/sun is shining +/mnt/cdrom/marley-songs_of_freedom/disk_1/thank you lord (original) +/mnt/cdrom/marley-songs_of_freedom/disk_2/acoustic medley +/mnt/cdrom/marley-songs_of_freedom/disk_2/burnin' and lootin' +/mnt/cdrom/marley-songs_of_freedom/disk_2/concrete jungle +/mnt/cdrom/marley-songs_of_freedom/disk_2/craven choke puppy +/mnt/cdrom/marley-songs_of_freedom/disk_2/get up stand up +/mnt/cdrom/marley-songs_of_freedom/disk_2/guava jelly +/mnt/cdrom/marley-songs_of_freedom/disk_2/high tide or low tide +/mnt/cdrom/marley-songs_of_freedom/disk_2/i shot the sheriff +/mnt/cdrom/marley-songs_of_freedom/disk_2/i'm hurting inside +/mnt/cdrom/marley-songs_of_freedom/disk_2/iron lion zion +/mnt/cdrom/marley-songs_of_freedom/disk_2/lick samba +/mnt/cdrom/marley-songs_of_freedom/disk_2/lively up yourself +/mnt/cdrom/marley-songs_of_freedom/disk_2/natty dread +/mnt/cdrom/marley-songs_of_freedom/disk_2/no more trouble +/mnt/cdrom/marley-songs_of_freedom/disk_2/rastaman chant +/mnt/cdrom/marley-songs_of_freedom/disk_2/screw face +/mnt/cdrom/marley-songs_of_freedom/disk_2/slave driver +/mnt/cdrom/marley-songs_of_freedom/disk_2/trenchtown rock +/mnt/cdrom/marley-songs_of_freedom/disk_4/africa unite +/mnt/cdrom/marley-songs_of_freedom/disk_4/babylon system +/mnt/cdrom/marley-songs_of_freedom/disk_4/bad card +/mnt/cdrom/marley-songs_of_freedom/disk_4/coming in from the cold (12 +/mnt/cdrom/marley-songs_of_freedom/disk_4/could you be loved (12 mix +/mnt/cdrom/marley-songs_of_freedom/disk_4/forever loving jah +/mnt/cdrom/marley-songs_of_freedom/disk_4/give thanks and praise +/mnt/cdrom/marley-songs_of_freedom/disk_4/one drop +/mnt/cdrom/marley-songs_of_freedom/disk_4/one dub +/mnt/cdrom/marley-songs_of_freedom/disk_4/rastaman live up +/mnt/cdrom/marley-songs_of_freedom/disk_4/real situation +/mnt/cdrom/marley-songs_of_freedom/disk_4/redemption song (live in pi +/mnt/cdrom/marley-songs_of_freedom/disk_4/ride natty ride (12 mix) +/mnt/cdrom/marley-songs_of_freedom/disk_4/so much trouble in the worl +/mnt/cdrom/marley-songs_of_freedom/disk_4/survival +/mnt/cdrom/marley-songs_of_freedom/disk_4/why should i (previously un +/mnt/cdrom/marley-songs_of_freedom/disk_4/zimbabwe + +/mnt/cdrom/dj_spooky_riddim_warefare/djspooky_01_pandemonium +/mnt/cdrom/dj_spooky_riddim_warefare/djspooky_02_sync_disjecta +/mnt/cdrom/dj_spooky_riddim_warefare/djspooky_03_object_unknown +/mnt/cdrom/dj_spooky_riddim_warefare/djspooky_04_it's_nice_not +/mnt/cdrom/dj_spooky_rid-2dim_warefare/djspooky_05_dialectical_tra +/mnt/cdrom/dj_spooky_riddim_warefare/djspooky_06_post-human_soph +/mnt/cdrom/dj_spooky_riddim_warefare/djspooky_07_quilombo_ex +/mnt/cdrom/dj_spooky_riddim_warefare/djspooky_08_rekonstruction +/mnt/cdrom/dj_spooky_riddim_warefare/djspooky_09_scientifik +/mnt/cdrom/dj_spooky_riddim_warefare/djspooky_10_a_conversation +/mnt/cdrom/dj_spooky_riddim_warefare/djspooky_11_peace_in_zaire +/mnt/cdrom/dj_spooky_riddim_warefare/djspooky_13_degree_zero +/mnt/cdrom/dj_spooky_riddim_warefare/djspooky_14_roman_planeta +/mnt/cdrom/dj_spooky_riddim_warefare/djspooky_15_bass_digitalis +/mnt/cdrom/dj_spooky_riddim_warefare/djspooky_16_polyphony_of +/mnt/cdrom/dj_spooky_riddim_warefare/djspooky_17_riddim_warfare +/mnt/cdrom/dj_spooky_riddim_warefare/djspooky_18_the_nerd +/mnt/cdrom/dj_spooky_riddim_warefare/djspooky_20_theme_of_the +/mnt/cdrom/dj_spooky_riddim_warefare/djspooky_21_twilight_fugue + +/mnt/cdrom/stuff_smith_mosaic/disk3/01_desert_sands +/mnt/cdrom/stuff_smith_mosaic/disk3/02_soft_winds +/mnt/cdrom/stuff_smith_mosaic/disk3/03_time_and_again +/mnt/cdrom/stuff_smith_mosaic/disk3/04_it_don't_mean_a_thing +/mnt/cdrom/stuff_smith_mosaic/disk3/05_in_a_mellotone +/mnt/cdrom/stuff_smith_mosaic/disk3/06_i_know_that_you_know +/mnt/cdrom/stuff_smith_mosaic/disk3/07_heat_wave +/mnt/cdrom/stuff_smith_mosaic/disk3/08_things_ain't_what_they_used_to_be +/mnt/cdrom/stuff_smith_mosaic/disk3/09_body_and_soul + +So I take a break, wander down to the park to stand, then lean into +the concrete railing demarking the beginnings of space, oceanic +space. I watch the waves break, and form, and ease back out to sea and +wrap my arms around myself and hug tightly because it's early in the +morning and windy, and the sun is late getting out of bed today, which +is good because if there was brilliant light illuminating all the +beauty around me I would be shocked, stunned, forced to retreat back +into my cabana in a daze, blinded by hummingbirds and callilillies and +un-named red, yellow, and blue flowers. Green envelopes me, waves +sooth me. I can see the wind flip the top of the waves seaward, right +before they break. The sea seems so calm from my perch above the fray +that I wonder if maybe there is just some part of the deepest, most +abstract ocean where there is a large creature who happily chews +plankton and wags its tail in gentle, adulating waves that spread and +move and gracefully glide thousands of miles, to crash upon a beach, +one after the other, politely waiting for a turn to dance with the +seashore. + +I know: it is what the Mexican schoolchildren call "la vibora de la +mer," the serpent of the sea. + + + + + diff --git a/libstdc++-v3/testsuite/testsuite_hooks.h b/libstdc++-v3/testsuite/testsuite_hooks.h index 0c3aae6cec9..719135caa58 100644 --- a/libstdc++-v3/testsuite/testsuite_hooks.h +++ b/libstdc++-v3/testsuite/testsuite_hooks.h @@ -110,6 +110,7 @@ namespace __gnu_cxx_test std::locale try_named_locale(const char* name); + // Test data types. struct pod_char { @@ -137,6 +138,7 @@ namespace __gnu_cxx_test unsigned long l2; }; + // Counting. struct counter { diff --git a/libstdc++-v3/testsuite/testsuite_io.h b/libstdc++-v3/testsuite/testsuite_io.h new file mode 100644 index 00000000000..33de2a05b14 --- /dev/null +++ b/libstdc++-v3/testsuite/testsuite_io.h @@ -0,0 +1,79 @@ +// -*- C++ -*- +// Testing filebuf for the C++ library testsuite. +// +// Copyright (C) 2003 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. +// +// As a special exception, you may use this file as part of a free software +// library without restriction. Specifically, if other files instantiate +// templates or use macros or inline functions from this file, or you compile +// this file and link it with other files to produce an executable, this +// file does not by itself cause the resulting executable to be covered by +// the GNU General Public License. This exception does not however +// invalidate any other reasons why the executable file might be covered by +// the GNU General Public License. + +#ifndef _GLIBCPP_TESTSUITE_IO_H +#define _GLIBCPP_TESTSUITE_IO_H + +#include + +namespace __gnu_cxx_test +{ + // Used to verify the constraints/requirements on get and put areas + // as defined in + // 27.5.1 - Stream buffer requirements: get and put areas + // 27.8.1.1 - Template class basic_filebuf p 3 + // If the file is not open (ios_base::in) -> input seq. cannot be read + // If the file is not open (ios_base::out) -> output seq. cannot be written + // Joint file position + // 27.8.1.4 - Overridden virtual functions p9 + // If unbuffered, pbase == pptr == NULL + class constraint_filebuf: public std::filebuf + { + public: + bool + write_position() + { + bool two = this->pptr() != NULL; + bool one = this->pptr() < this->epptr(); + return one && two; + } + + bool + read_position() + { + bool one = this->gptr() != NULL; + bool two = this->gptr() < this->egptr(); + + return one && two; + } + + bool + unbuffered() + { + bool one = this->pbase() == NULL; + bool two = this->pptr() == NULL; + return one && two; + } + + }; +}; // namespace __gnu_cxx_test + +#endif // _GLIBCPP_TESTSUITE_IO_H + -- 2.30.2