2001-05-22 20:48:19 +02:00
|
|
|
// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com>
|
|
|
|
|
2003-01-23 23:53:35 +01:00
|
|
|
// Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc.
|
2001-05-22 20:48:19 +02:00
|
|
|
//
|
|
|
|
// 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.7.1.3 Overridden virtual functions
|
|
|
|
|
|
|
|
#include <sstream>
|
2001-08-07 05:38:33 +02:00
|
|
|
#include <testsuite_hooks.h>
|
2001-05-22 20:48:19 +02:00
|
|
|
|
|
|
|
void test01()
|
|
|
|
{
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
bool test = true;
|
|
|
|
char buf[512];
|
|
|
|
const char* strlit = "how to tell a story and other essays: mark twain";
|
2001-06-04 17:46:03 +02:00
|
|
|
const size_t strlitsize = std::strlen(strlit);
|
2001-05-22 20:48:19 +02:00
|
|
|
stringbuf sbuf(ios_base::out);
|
|
|
|
|
|
|
|
sbuf.pubsetbuf(buf, strlitsize);
|
|
|
|
sbuf.sputn(strlit, strlitsize);
|
2001-06-04 17:46:03 +02:00
|
|
|
VERIFY( std::strncmp(strlit, buf, strlitsize) != 0 );
|
2001-05-22 20:48:19 +02:00
|
|
|
}
|
|
|
|
|
2002-04-09 08:14:32 +02:00
|
|
|
void test02(std::stringbuf& in, bool pass)
|
|
|
|
{
|
|
|
|
using namespace std;
|
|
|
|
typedef streambuf::pos_type pos_type;
|
|
|
|
typedef streambuf::off_type off_type;
|
|
|
|
pos_type bad = pos_type(off_type(-1));
|
|
|
|
pos_type p = 0;
|
|
|
|
|
|
|
|
// seekoff
|
|
|
|
p = in.pubseekoff(0, ios_base::beg, ios_base::in);
|
|
|
|
if (pass)
|
|
|
|
VERIFY( p != bad );
|
|
|
|
|
|
|
|
p = in.pubseekoff(0, ios_base::beg, ios_base::out);
|
|
|
|
VERIFY( p == bad );
|
|
|
|
|
|
|
|
p = in.pubseekoff(0, ios_base::beg);
|
|
|
|
VERIFY( p == bad );
|
|
|
|
|
|
|
|
|
|
|
|
// seekpos
|
|
|
|
p = in.pubseekpos(0, ios_base::in);
|
|
|
|
if (pass)
|
|
|
|
VERIFY( p != bad );
|
|
|
|
|
|
|
|
p = in.pubseekpos(0, ios_base::out);
|
|
|
|
VERIFY( p == bad );
|
|
|
|
|
|
|
|
p = in.pubseekpos(0);
|
|
|
|
VERIFY( p == bad );
|
|
|
|
}
|
|
|
|
|
2003-01-23 23:53:35 +01:00
|
|
|
// libstdc++/9322
|
|
|
|
void test08()
|
|
|
|
{
|
|
|
|
using std::locale;
|
|
|
|
bool test = true;
|
|
|
|
|
|
|
|
locale loc;
|
|
|
|
std::stringbuf ob;
|
|
|
|
VERIFY( ob.getloc() == loc );
|
|
|
|
|
|
|
|
locale::global(locale("en_US"));
|
|
|
|
VERIFY( ob.getloc() == loc );
|
|
|
|
|
|
|
|
locale loc_de ("de_DE");
|
|
|
|
locale ret = ob.pubimbue(loc_de);
|
|
|
|
VERIFY( ob.getloc() == loc_de );
|
|
|
|
VERIFY( ret == loc );
|
|
|
|
|
|
|
|
locale::global(loc);
|
|
|
|
VERIFY( ob.getloc() == loc_de );
|
|
|
|
}
|
|
|
|
|
PR libstdc++/9404, PR libstdc++/9701 (partial)
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.
Co-Authored-By: Nathan Myers <ncm@cantrip.org>
From-SVN: r63367
2003-02-24 19:22:58 +01:00
|
|
|
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.
|
|
|
|
}
|
|
|
|
|
2001-05-22 20:48:19 +02:00
|
|
|
int main()
|
|
|
|
{
|
2002-04-09 08:14:32 +02:00
|
|
|
using namespace std;
|
2001-05-22 20:48:19 +02:00
|
|
|
test01();
|
|
|
|
|
2002-04-09 08:14:32 +02:00
|
|
|
// movie star, submarine scientist!
|
|
|
|
stringbuf in1("Hedy Lamarr", ios_base::in);
|
|
|
|
stringbuf in2(ios_base::in);
|
|
|
|
stringbuf in3("", ios_base::in);
|
|
|
|
test02(in1, true);
|
|
|
|
test02(in2, false);
|
|
|
|
test02(in3, false);
|
|
|
|
|
2003-01-23 23:53:35 +01:00
|
|
|
test08();
|
PR libstdc++/9404, PR libstdc++/9701 (partial)
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.
Co-Authored-By: Nathan Myers <ncm@cantrip.org>
From-SVN: r63367
2003-02-24 19:22:58 +01:00
|
|
|
test09();
|
2001-05-22 20:48:19 +02:00
|
|
|
return 0;
|
|
|
|
}
|