diff options
author | paolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4> | 2003-02-24 18:22:58 +0000 |
---|---|---|
committer | paolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4> | 2003-02-24 18:22:58 +0000 |
commit | 943886d66e25a2c910223c3e63d43b786b405387 (patch) | |
tree | 8376b0af396f1a5c1994c13b24882ce10a2d45f0 /libstdc++-v3/testsuite/27_io | |
parent | 305563158154afa634a4da93accc63ccc525089d (diff) | |
download | gcc-943886d66e25a2c910223c3e63d43b786b405387.tar.gz |
2003-02-24 Paolo Carlini <pcarlini@unitus.it>
Nathan Myers <ncm@cantrip.org>
PR libstdc++/9404, PR libstdc++/9701 (partial)
(aka pptr == epptr implies overflow)
* include/bits/fstream.tcc (_M_allocate_internal_buffer):
Consistently, _M_out_end points to the end of the buffer just
created.
(overflow): Tweak to use _M_out_buf_size().
(_M_convert_to_external): The role of the old _M_out_end is
now played by _M_out_lim.
(_M_really_overflow): Likewise.
(seekoff): Likewise.
(setbuf): _M_out_end points to the end of the external buffer.
* include/bits/sstream.tcc (overflow): Rewrote, taking into
account the resolution of DR 169 (TC).
(seekoff): Use _M_string.capacity(); ios_base::end is now _M_out_lim.
(seekpos): Use _M_string.capacity(); tweak.
* include/bits/streambuf.tcc (sputc, xsputn): Remove comments.
* include/std/std_fstream.h (sync): The role of the old
_M_out_end is now played by _M_out_lim.
(_M_set_indeterminate): Use _M_set_determinate.
(_M_set_determinate): _M_out_end is now _M_out_lim.
(_M_is_indeterminate): Likewise.
* include/std/std_sstream.h (str()): _M_out_end is now _M_out_lim.
(_M_stringbuf_init): Don't set _M_buf_size, unused for sstreams,
which have the information readily available as _M_string.capacity();
for ate and app modes, pass the string size to _M_really_sync.
(_M_really_sync): Consistently set _M_out_end and _M_out_lim, to
point to the end of the buffer (i.e., epptr) and to the string end,
respectively.
* include/std/std_streambuf.h: tweak comments, add _M_out_lim,
which points to the right limit of the used put area.
(_M_out_cur_move): The role of the old _M_out_end is now played
by _M_out_lim.
(_M_out_buf_size): Simplify: now (when _M_out_cur) return simply
_M_out_end - _M_out_cur (i.e., pptr), _very_ close to the letter
of the standard.
(basic_streambuf()): Initialize _M_out_lim too.
* testsuite/27_io/filebuf_virtuals.cc (test10): Trivial tweak.
* testsuite/27_io/filebuf_virtuals.cc (test11): Add.
* testsuite/27_io/stringbuf_virtuals.cc (test09): Add.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@63367 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libstdc++-v3/testsuite/27_io')
-rw-r--r-- | libstdc++-v3/testsuite/27_io/filebuf_virtuals.cc | 64 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/27_io/stringbuf_virtuals.cc | 56 |
2 files changed, 117 insertions, 3 deletions
diff --git a/libstdc++-v3/testsuite/27_io/filebuf_virtuals.cc b/libstdc++-v3/testsuite/27_io/filebuf_virtuals.cc index 843038aab48..fc9262f8e75 100644 --- a/libstdc++-v3/testsuite/27_io/filebuf_virtuals.cc +++ b/libstdc++-v3/testsuite/27_io/filebuf_virtuals.cc @@ -71,7 +71,8 @@ const char carray_02[] = "memphis, new orleans, and savanah"; 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 - +const char name_04[] = "filebuf_virtuals-4.txt"; // empty file, need to create +const char name_05[] = "filebuf_virtuals-5.txt"; // empty file, need to create class derived_filebuf: public std::filebuf { @@ -607,14 +608,14 @@ void test10() { ofstream out; out.imbue(loc); - out.open("filebuf_virtuals-4.txt"); + out.open(name_04); copy(str.begin(), str.end(), ostreambuf_iterator<char>(out)); } { ifstream in; - in.open("filebuf_virtuals-4.txt"); + in.open(name_04); copy(istreambuf_iterator<char>(in), istreambuf_iterator<char>(), back_inserter(tmp)); @@ -624,6 +625,62 @@ void test10() VERIFY( tmp == str ); } +bool over_called; + +class Derived_filebuf : public std::filebuf +{ +public: + int_type overflow(int_type c) + { + over_called = true; + return std::filebuf::overflow(c); + } + + const char_type* pub_epptr() const + { + return epptr(); + } + + const char_type* pub_pptr() const + { + return pptr(); + } +}; + +// libstdc++/9701 (partial) +void test11() +{ + bool test = true; + + bool over_expected; + + // sputc + Derived_filebuf dfbuf_01; + dfbuf_01.open(name_05, std::ios_base::out); + over_called = false; + dfbuf_01.sputc('i'); + VERIFY( !over_called ); + over_expected = dfbuf_01.pub_epptr() == dfbuf_01.pub_pptr(); + over_called = false; + dfbuf_01.sputc('v'); + VERIFY( (!over_expected && !over_called) + || (over_expected && over_called) ); + dfbuf_01.close(); + + // sputn + Derived_filebuf dfbuf_02; + dfbuf_02.open(name_05, std::ios_base::out); + over_called = false; + dfbuf_02.sputn("sonne's", 7); + VERIFY( !over_called ); + over_expected = dfbuf_02.pub_epptr() == dfbuf_02.pub_pptr(); + over_called = false; + dfbuf_02.sputn(" peak", 5); + VERIFY( (!over_expected && !over_called) + || (over_expected && over_called) ); + dfbuf_02.close(); +} + main() { test01(); @@ -638,5 +695,6 @@ main() test08(); test09(); test10(); + test11(); return 0; } diff --git a/libstdc++-v3/testsuite/27_io/stringbuf_virtuals.cc b/libstdc++-v3/testsuite/27_io/stringbuf_virtuals.cc index 8a6add9dfc5..a2a8368abfc 100644 --- a/libstdc++-v3/testsuite/27_io/stringbuf_virtuals.cc +++ b/libstdc++-v3/testsuite/27_io/stringbuf_virtuals.cc @@ -92,6 +92,61 @@ void test08() VERIFY( ob.getloc() == loc_de ); } +bool over_called; + +class Derived_stringbuf : public std::stringbuf +{ +public: + int_type overflow(int_type c) + { + over_called = true; + return std::stringbuf::overflow(c); + } + + const char_type* pub_epptr() const + { + return epptr(); + } + + const char_type* pub_pptr() const + { + return pptr(); + } +}; + +// libstdc++/9404 +void test09() +{ + bool test = true; + + bool over_expected; + + // sputc + Derived_stringbuf dsbuf_01; + over_called = false; + dsbuf_01.sputc('i'); + VERIFY( over_called ); + over_expected = dsbuf_01.pub_epptr() == dsbuf_01.pub_pptr(); + over_called = false; + dsbuf_01.sputc('v'); + VERIFY( (!over_expected && !over_called) + || (over_expected && over_called) ); + dsbuf_01.sputc('i'); + VERIFY( dsbuf_01.str() == "ivi" ); // Sanity check. + + // sputn + Derived_stringbuf dsbuf_02; + over_called = false; + dsbuf_02.sputn("sonne's", 7); + VERIFY( over_called ); + over_expected = dsbuf_02.pub_epptr() == dsbuf_02.pub_pptr(); + over_called = false; + dsbuf_02.sputn(" peak", 5); + VERIFY( (!over_expected && !over_called) + || (over_expected && over_called) ); + VERIFY( dsbuf_02.str() == "sonne's peak" ); // Sanity check. +} + int main() { using namespace std; @@ -106,5 +161,6 @@ int main() test02(in3, false); test08(); + test09(); return 0; } |