From 6f4229658a77a80aedbe50f435ea8c693e745583 Mon Sep 17 00:00:00 2001 From: Paolo Carlini Date: Sun, 11 Jul 2004 19:13:59 +0000 Subject: [PATCH] Add wchar_t counterparts of the basic_streambbuf tests. 2004-07-11 Paolo Carlini Add wchar_t counterparts of the basic_streambbuf tests. * testsuite/27_io/basic_streambuf/cons/wchar_t/1.cc: New. * testsuite/27_io/basic_streambuf/imbue/wchar_t/1.cc, 9322.cc: Likewise. * testsuite/27_io/basic_streambuf/in_avail/wchar_t/9701-3.cc: Likewise. * testsuite/27_io/basic_streambuf/overflow/wchar_t/1.cc, 2.cc, 3599.cc: Likewise. * testsuite/27_io/basic_streambuf/sgetc/wchar_t/1.cc: Likewise. * testsuite/27_io/basic_streambuf/sgetn/wchar_t/1.cc: Likewise. * testsuite/27_io/basic_streambuf/sputbackc/wchar_t/9538.cc: Likewise. * testsuite/27_io/basic_streambuf/sputc/wchar_t/1057.cc: Likewise. * testsuite/27_io/basic_streambuf/sputn/wchar_t/1.cc, 1057.cc: Likewise. * testsuite/27_io/basic_streambuf/sync/wchar_t/1057.cc: Likewise. * testsuite/27_io/basic_streambuf/imbue/char/1.cc, 9322.cc: Minor tweaks. * testsuite/27_io/basic_streambuf/overflow/char/2.cc, 3599.cc: Likewise. * testsuite/27_io/basic_streambuf/sputn/char/1057.cc: Likewise. * testsuite/27_io/basic_streambuf/sync/char/1057.cc: Likewise. From-SVN: r84526 --- libstdc++-v3/ChangeLog | 24 ++++ .../27_io/basic_streambuf/cons/wchar_t/1.cc | 111 +++++++++++++++ .../27_io/basic_streambuf/imbue/char/1.cc | 1 + .../27_io/basic_streambuf/imbue/char/9322.cc | 4 +- .../27_io/basic_streambuf/imbue/wchar_t/1.cc | 53 +++++++ .../basic_streambuf/imbue/wchar_t/9322.cc | 71 ++++++++++ .../in_avail/wchar_t/9701-3.cc | 59 ++++++++ .../27_io/basic_streambuf/overflow/char/2.cc | 1 + .../basic_streambuf/overflow/char/3599.cc | 4 +- .../basic_streambuf/overflow/wchar_t/1.cc | 119 ++++++++++++++++ .../basic_streambuf/overflow/wchar_t/2.cc | 81 +++++++++++ .../basic_streambuf/overflow/wchar_t/3599.cc | 68 +++++++++ .../27_io/basic_streambuf/sgetc/wchar_t/1.cc | 121 ++++++++++++++++ .../27_io/basic_streambuf/sgetn/wchar_t/1.cc | 133 ++++++++++++++++++ .../basic_streambuf/sputbackc/wchar_t/9538.cc | 66 +++++++++ .../basic_streambuf/sputc/wchar_t/1057.cc | 62 ++++++++ .../27_io/basic_streambuf/sputn/char/1057.cc | 2 +- .../27_io/basic_streambuf/sputn/wchar_t/1.cc | 127 +++++++++++++++++ .../basic_streambuf/sputn/wchar_t/1057.cc | 62 ++++++++ .../27_io/basic_streambuf/sync/char/1057.cc | 1 + .../basic_streambuf/sync/wchar_t/1057.cc | 110 +++++++++++++++ 21 files changed, 1274 insertions(+), 6 deletions(-) create mode 100644 libstdc++-v3/testsuite/27_io/basic_streambuf/cons/wchar_t/1.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_streambuf/imbue/wchar_t/1.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_streambuf/imbue/wchar_t/9322.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_streambuf/in_avail/wchar_t/9701-3.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_streambuf/overflow/wchar_t/1.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_streambuf/overflow/wchar_t/2.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_streambuf/overflow/wchar_t/3599.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_streambuf/sgetc/wchar_t/1.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_streambuf/sgetn/wchar_t/1.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_streambuf/sputbackc/wchar_t/9538.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_streambuf/sputc/wchar_t/1057.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_streambuf/sputn/wchar_t/1.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_streambuf/sputn/wchar_t/1057.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_streambuf/sync/wchar_t/1057.cc diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index aeffd691d8f..f7a49d7c355 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,27 @@ +2004-07-11 Paolo Carlini + + Add wchar_t counterparts of the basic_streambbuf tests. + * testsuite/27_io/basic_streambuf/cons/wchar_t/1.cc: New. + * testsuite/27_io/basic_streambuf/imbue/wchar_t/1.cc, 9322.cc: + Likewise. + * testsuite/27_io/basic_streambuf/in_avail/wchar_t/9701-3.cc: Likewise. + * testsuite/27_io/basic_streambuf/overflow/wchar_t/1.cc, 2.cc, + 3599.cc: Likewise. + * testsuite/27_io/basic_streambuf/sgetc/wchar_t/1.cc: Likewise. + * testsuite/27_io/basic_streambuf/sgetn/wchar_t/1.cc: Likewise. + * testsuite/27_io/basic_streambuf/sputbackc/wchar_t/9538.cc: Likewise. + * testsuite/27_io/basic_streambuf/sputc/wchar_t/1057.cc: Likewise. + * testsuite/27_io/basic_streambuf/sputn/wchar_t/1.cc, 1057.cc: + Likewise. + * testsuite/27_io/basic_streambuf/sync/wchar_t/1057.cc: Likewise. + + * testsuite/27_io/basic_streambuf/imbue/char/1.cc, 9322.cc: Minor + tweaks. + * testsuite/27_io/basic_streambuf/overflow/char/2.cc, 3599.cc: + Likewise. + * testsuite/27_io/basic_streambuf/sputn/char/1057.cc: Likewise. + * testsuite/27_io/basic_streambuf/sync/char/1057.cc: Likewise. + 2004-07-11 Phil Edwards * acinclude.m4: Cosmetic shell syntax fixes. diff --git a/libstdc++-v3/testsuite/27_io/basic_streambuf/cons/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_streambuf/cons/wchar_t/1.cc new file mode 100644 index 00000000000..a97b35f4d11 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_streambuf/cons/wchar_t/1.cc @@ -0,0 +1,111 @@ +// 1999-10-11 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004 +// 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. + +// 27.5.2 template class basic_streambuf + +#include +#include + +class testbuf : public std::wstreambuf +{ +public: + + // Typedefs: + typedef std::wstreambuf::traits_type traits_type; + typedef std::wstreambuf::char_type char_type; + + testbuf(): std::wstreambuf() + { } + + bool + check_pointers() + { + bool test __attribute__((unused)) = true; + VERIFY( this->eback() == NULL ); + VERIFY( this->gptr() == NULL ); + VERIFY( this->egptr() == NULL ); + VERIFY( this->pbase() == NULL ); + VERIFY( this->pptr() == NULL ); + VERIFY( this->epptr() == NULL ); + return test; + } + + int_type + pub_uflow() + { return (this->uflow()); } + + int_type + pub_overflow(int_type __c = traits_type::eof()) + { return (this->overflow(__c)); } + + int_type + pub_pbackfail(int_type __c) + { return (this->pbackfail(__c)); } + + void + pub_setg(wchar_t* beg, wchar_t* cur, wchar_t* end) + { this->setg(beg, cur, end); } + + void + pub_setp(wchar_t* beg, wchar_t* end) + { this->setp(beg, end); } + +protected: + int_type + underflow() + { + int_type __retval = traits_type::eof(); + if (this->gptr() < this->egptr()) + __retval = traits_type::not_eof(0); + return __retval; + } +}; + +void test01() +{ + typedef testbuf::traits_type traits_type; + typedef testbuf::int_type int_type; + + bool test __attribute__((unused)) = true; + testbuf buf01; + + // 27.5.2.1 basic_streambuf ctors + // default ctor initializes + // - all pointer members to null pointers + // - locale to current global locale + VERIFY( buf01.check_pointers() ); + VERIFY( buf01.getloc() == std::locale() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_streambuf/imbue/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_streambuf/imbue/char/1.cc index b574cdc6736..24469ba99de 100644 --- a/libstdc++-v3/testsuite/27_io/basic_streambuf/imbue/char/1.cc +++ b/libstdc++-v3/testsuite/27_io/basic_streambuf/imbue/char/1.cc @@ -20,6 +20,7 @@ // USA. #include +#include #include class testbuf : public std::streambuf diff --git a/libstdc++-v3/testsuite/27_io/basic_streambuf/imbue/char/9322.cc b/libstdc++-v3/testsuite/27_io/basic_streambuf/imbue/char/9322.cc index 17d94af7001..964fcca3cf3 100644 --- a/libstdc++-v3/testsuite/27_io/basic_streambuf/imbue/char/9322.cc +++ b/libstdc++-v3/testsuite/27_io/basic_streambuf/imbue/char/9322.cc @@ -29,10 +29,8 @@ // 27.5.2 template class basic_streambuf -#include // for memset, memcmp #include -#include -#include +#include #include class testbuf : public std::streambuf diff --git a/libstdc++-v3/testsuite/27_io/basic_streambuf/imbue/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_streambuf/imbue/wchar_t/1.cc new file mode 100644 index 00000000000..3f735fdae51 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_streambuf/imbue/wchar_t/1.cc @@ -0,0 +1,53 @@ +// 981208 bkoz test functionality of basic_streambuf for char_type == wchar_t + +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004 +// 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. + +#include +#include +#include + +class testbuf : public std::wstreambuf +{ +public: + typedef std::wstreambuf::traits_type traits_type; + + testbuf() : std::wstreambuf() { } +}; + +// test the streambuf locale settings +void test02() +{ + testbuf buf; + std::locale loc_c = std::locale::classic(); + loc_c = buf.getloc(); + buf.pubimbue(loc_c); //This should initialize _M_init to true + std::locale loc_tmp = buf.getloc(); + VERIFY( loc_tmp == loc_c ); +} + +int main() +{ + test02(); + return 0; +} + + + +// more candy!!! diff --git a/libstdc++-v3/testsuite/27_io/basic_streambuf/imbue/wchar_t/9322.cc b/libstdc++-v3/testsuite/27_io/basic_streambuf/imbue/wchar_t/9322.cc new file mode 100644 index 00000000000..68a467822a0 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_streambuf/imbue/wchar_t/9322.cc @@ -0,0 +1,71 @@ +// 1999-10-11 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004 +// 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. + +// 27.5.2 template class basic_streambuf + +#include +#include +#include + +class testbuf : public std::wstreambuf +{ +public: + typedef std::wstreambuf::traits_type traits_type; + + testbuf() : std::wstreambuf() { } +}; + +// libstdc++/9322 +void test08() +{ + using std::locale; + bool test __attribute__((unused)) = true; + + locale loc; + testbuf ob; + VERIFY( ob.getloc() == loc ); + + locale::global(__gnu_test::try_named_locale("en_US")); + VERIFY( ob.getloc() == loc ); + + locale loc_de = __gnu_test::try_named_locale("de_DE"); + locale ret = ob.pubimbue(loc_de); + VERIFY( ob.getloc() == loc_de ); + VERIFY( ret == loc ); + + locale::global(loc); + VERIFY( ob.getloc() == loc_de ); +} + +int main() +{ + test08(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_streambuf/in_avail/wchar_t/9701-3.cc b/libstdc++-v3/testsuite/27_io/basic_streambuf/in_avail/wchar_t/9701-3.cc new file mode 100644 index 00000000000..239f790fe47 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_streambuf/in_avail/wchar_t/9701-3.cc @@ -0,0 +1,59 @@ +// Copyright (C) 2003, 2004 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.5.2.2.3 Get area + +#include +#include + +class Derived_fbuf : public std::wfilebuf +{ +public: + const char_type* pub_egptr() const + { return egptr(); } + + const char_type* pub_gptr() const + { return gptr(); } +}; + +// libstdc++/9701 (in_avail) +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + const char* name = "tmp_file1_w"; + + Derived_fbuf df2; + df2.open(name, ios_base::in | ios_base::out | ios_base::trunc); + + df2.sputn(L"Comomoc", 7); + + df2.pubseekoff(0, ios_base::beg); + df2.sbumpc(); + df2.sputbackc(L't'); + + VERIFY( df2.pub_gptr() < df2.pub_egptr() ); + VERIFY( df2.in_avail() == df2.pub_egptr() - df2.pub_gptr() ); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_streambuf/overflow/char/2.cc b/libstdc++-v3/testsuite/27_io/basic_streambuf/overflow/char/2.cc index a6215529251..dbf79bd384a 100644 --- a/libstdc++-v3/testsuite/27_io/basic_streambuf/overflow/char/2.cc +++ b/libstdc++-v3/testsuite/27_io/basic_streambuf/overflow/char/2.cc @@ -31,6 +31,7 @@ #include #include +#include #include // test03 diff --git a/libstdc++-v3/testsuite/27_io/basic_streambuf/overflow/char/3599.cc b/libstdc++-v3/testsuite/27_io/basic_streambuf/overflow/char/3599.cc index 145e4eb3ec6..82040cdf342 100644 --- a/libstdc++-v3/testsuite/27_io/basic_streambuf/overflow/char/3599.cc +++ b/libstdc++-v3/testsuite/27_io/basic_streambuf/overflow/char/3599.cc @@ -55,10 +55,10 @@ test07() std::ostream out(&ob); out << "gasp"; - VERIFY(out.good()); + VERIFY( out.good() ); out << std::endl; - VERIFY(out.good()); + VERIFY( out.good() ); } int main() diff --git a/libstdc++-v3/testsuite/27_io/basic_streambuf/overflow/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_streambuf/overflow/wchar_t/1.cc new file mode 100644 index 00000000000..0bada3a7357 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_streambuf/overflow/wchar_t/1.cc @@ -0,0 +1,119 @@ +// 1999-10-11 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004 +// 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. + +// 27.5.2 template class basic_streambuf + +#include +#include +#include + +class testbuf : public std::wstreambuf +{ +public: + + // Typedefs: + typedef std::wstreambuf::traits_type traits_type; + typedef std::wstreambuf::char_type char_type; + + testbuf(): std::wstreambuf() + { } + + bool + check_pointers() + { + bool test __attribute__((unused)) = true; + VERIFY( this->eback() == NULL ); + VERIFY( this->gptr() == NULL ); + VERIFY( this->egptr() == NULL ); + VERIFY( this->pbase() == NULL ); + VERIFY( this->pptr() == NULL ); + VERIFY( this->epptr() == NULL ); + return test; + } + + int_type + pub_uflow() + { return (this->uflow()); } + + int_type + pub_overflow(int_type __c = traits_type::eof()) + { return (this->overflow(__c)); } + + int_type + pub_pbackfail(int_type __c) + { return (this->pbackfail(__c)); } + + void + pub_setg(wchar_t* beg, wchar_t* cur, wchar_t* end) + { this->setg(beg, cur, end); } + + void + pub_setp(wchar_t* beg, wchar_t* end) + { this->setp(beg, end); } + +protected: + int_type + underflow() + { + int_type __retval = traits_type::eof(); + if (this->gptr() < this->egptr()) + __retval = traits_type::not_eof(0); + return __retval; + } +}; + +void test01() +{ + typedef testbuf::traits_type traits_type; + typedef testbuf::int_type int_type; + + bool test __attribute__((unused)) = true; + wchar_t lit01[52]; + std::wcscpy(lit01, L"chicago underground trio/possible cube on delmark"); + testbuf buf01; + + // pbackfail + int i01 = 3; + buf01.pub_setg(lit01, lit01, (lit01 + i01)); + VERIFY( i01 == buf01.in_avail() ); + int_type intt01 = traits_type::to_int_type(L'b'); + VERIFY( traits_type::eof() == buf01.pub_pbackfail(intt01) ); + + // overflow + VERIFY( traits_type::eof() == buf01.pub_overflow(intt01) ); + VERIFY( traits_type::eof() == buf01.pub_overflow() ); + VERIFY( buf01.sgetc() == traits_type::to_int_type(lit01[0]) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_streambuf/overflow/wchar_t/2.cc b/libstdc++-v3/testsuite/27_io/basic_streambuf/overflow/wchar_t/2.cc new file mode 100644 index 00000000000..87a650c7fc6 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_streambuf/overflow/wchar_t/2.cc @@ -0,0 +1,81 @@ +// 1999-10-11 bkoz + +// Copyright (C) 1999, 2000, 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. + +// 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. + +// 27.5.2 template class basic_streambuf + +#include +#include +#include +#include + +// test03 +// http://gcc.gnu.org/ml/libstdc++/2000-q1/msg00151.html +template > + class basic_nullbuf : public std::basic_streambuf + { + protected: + typedef typename + std::basic_streambuf::int_type int_type; + virtual int_type + overflow(int_type c) + { return traits::not_eof(c); } + }; + +typedef basic_nullbuf nullbuf; + +template + wchar_t + print(const T& x) + { + nullbuf ob; + std::wostream out(&ob); + out << x << std::endl; + return (!out ? L'0' : L'1'); + } + +void test03() +{ + bool test __attribute__((unused)) = true; + const std::wstring control01(L"11111"); + std::wstring test01; + + test01 += print(true); + test01 += print(3.14159); + test01 += print(10); + test01 += print(L'x'); + test01 += print(L"pipo"); + + VERIFY( test01 == control01 ); +} + +int main() +{ + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_streambuf/overflow/wchar_t/3599.cc b/libstdc++-v3/testsuite/27_io/basic_streambuf/overflow/wchar_t/3599.cc new file mode 100644 index 00000000000..b0dcd1637e2 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_streambuf/overflow/wchar_t/3599.cc @@ -0,0 +1,68 @@ +// 1999-10-11 bkoz + +// Copyright (C) 1999, 2000, 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. + +// 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. + +// 27.5.2 template class basic_streambuf + +#include +#include +#include + +// libstdc++/3599 +class testbuf : public std::wstreambuf +{ +public: + typedef std::wstreambuf::traits_type traits_type; + + testbuf() : std::wstreambuf() { } + +protected: + int_type + overflow(int_type c __attribute__((unused)) = traits_type::eof()) + { return traits_type::not_eof(0); } +}; + +void +test07() +{ + bool test __attribute__((unused)) = true; + testbuf ob; + std::wostream out(&ob); + + out << L"gasp"; + VERIFY( out.good() ); + + out << std::endl; + VERIFY( out.good() ); +} + +int main() +{ + test07(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_streambuf/sgetc/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_streambuf/sgetc/wchar_t/1.cc new file mode 100644 index 00000000000..1b0137e0db3 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_streambuf/sgetc/wchar_t/1.cc @@ -0,0 +1,121 @@ +// 1999-10-11 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004 +// 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. + +// 27.5.2 template class basic_streambuf + +#include +#include +#include + +class testbuf : public std::wstreambuf +{ +public: + + // Typedefs: + typedef std::wstreambuf::traits_type traits_type; + typedef std::wstreambuf::char_type char_type; + + testbuf(): std::wstreambuf() + { } + + bool + check_pointers() + { + bool test __attribute__((unused)) = true; + VERIFY( this->eback() == NULL ); + VERIFY( this->gptr() == NULL ); + VERIFY( this->egptr() == NULL ); + VERIFY( this->pbase() == NULL ); + VERIFY( this->pptr() == NULL ); + VERIFY( this->epptr() == NULL ); + return test; + } + + int_type + pub_uflow() + { return (this->uflow()); } + + int_type + pub_overflow(int_type __c = traits_type::eof()) + { return (this->overflow(__c)); } + + int_type + pub_pbackfail(int_type __c) + { return (this->pbackfail(__c)); } + + void + pub_setg(wchar_t* beg, wchar_t* cur, wchar_t* end) + { this->setg(beg, cur, end); } + + void + pub_setp(wchar_t* beg, wchar_t* end) + { this->setp(beg, end); } + +protected: + int_type + underflow() + { + int_type __retval = traits_type::eof(); + if (this->gptr() < this->egptr()) + __retval = traits_type::not_eof(0); + return __retval; + } +}; + +void test01() +{ + typedef testbuf::traits_type traits_type; + typedef testbuf::int_type int_type; + + bool test __attribute__((unused)) = true; + wchar_t lit01[52]; + std::wcscpy(lit01, L"chicago underground trio/possible cube on delmark"); + testbuf buf01; + + // 27.5.2.3.1 get area + // 27.5.2.2.3 get area + // 27.5.2.4.3 get area + int i01 = 3; + buf01.pub_setg(lit01, lit01, (lit01 + i01)); + VERIFY( i01 == buf01.in_avail() ); + + VERIFY( buf01.pub_uflow() == lit01[0] ); + VERIFY( buf01.sgetc() == traits_type::to_int_type(lit01[1]) ); + VERIFY( buf01.pub_uflow() == lit01[1] ); + VERIFY( buf01.sgetc() == traits_type::to_int_type(lit01[2]) ); + VERIFY( buf01.pub_uflow() == lit01[2] ); + VERIFY( buf01.sgetc() == traits_type::eof() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_streambuf/sgetn/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_streambuf/sgetn/wchar_t/1.cc new file mode 100644 index 00000000000..d67f94aafb9 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_streambuf/sgetn/wchar_t/1.cc @@ -0,0 +1,133 @@ +// 1999-10-11 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004 +// 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. + +// 27.5.2 template class basic_streambuf + +#include +#include +#include + +class testbuf : public std::wstreambuf +{ +public: + + // Typedefs: + typedef std::wstreambuf::traits_type traits_type; + typedef std::wstreambuf::char_type char_type; + + testbuf(): std::wstreambuf() + { } + + bool + check_pointers() + { + bool test __attribute__((unused)) = true; + VERIFY( this->eback() == NULL ); + VERIFY( this->gptr() == NULL ); + VERIFY( this->egptr() == NULL ); + VERIFY( this->pbase() == NULL ); + VERIFY( this->pptr() == NULL ); + VERIFY( this->epptr() == NULL ); + return test; + } + + int_type + pub_uflow() + { return (this->uflow()); } + + int_type + pub_overflow(int_type __c = traits_type::eof()) + { return (this->overflow(__c)); } + + int_type + pub_pbackfail(int_type __c) + { return (this->pbackfail(__c)); } + + void + pub_setg(wchar_t* beg, wchar_t* cur, wchar_t* end) + { this->setg(beg, cur, end); } + + void + pub_setp(wchar_t* beg, wchar_t* end) + { this->setp(beg, end); } + +protected: + int_type + underflow() + { + int_type __retval = traits_type::eof(); + if (this->gptr() < this->egptr()) + __retval = traits_type::not_eof(0); + return __retval; + } +}; + +void test02() +{ + typedef testbuf::traits_type traits_type; + typedef testbuf::int_type int_type; + + bool test __attribute__((unused)) = true; + + const wchar_t* lit00 = L"chicago underground trio/possible cube on delmark"; + size_t i01 = traits_type::length(lit00); + wchar_t lit01[i01]; + std::wcscpy(lit01, lit00); + + testbuf buf01; + + // 27.5.2.1 basic_streambuf ctors + // default ctor initializes + // - all pointer members to null pointers + // - locale to current global locale + VERIFY( buf01.check_pointers() ); + VERIFY( buf01.getloc() == std::locale() ); + + // 27.5.2.2.5 Put area + + wchar_t carray01[i01]; + std::wmemset(carray01, 0, i01); + + buf01.pub_setg(lit01, lit01, lit01 + i01); + buf01.sgetn(carray01, 0); + VERIFY( carray01[0] == 0 ); + buf01.sgetn(carray01, 1); + VERIFY( carray01[0] == L'c' ); + buf01.sgetn(carray01 + 1, i01 - 1); + VERIFY( carray01[0] == L'c' ); + VERIFY( carray01[1] == L'h' ); + VERIFY( carray01[i01 - 1] == L'k' ); +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_streambuf/sputbackc/wchar_t/9538.cc b/libstdc++-v3/testsuite/27_io/basic_streambuf/sputbackc/wchar_t/9538.cc new file mode 100644 index 00000000000..19e794d1851 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_streambuf/sputbackc/wchar_t/9538.cc @@ -0,0 +1,66 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003, 2004 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 +#include + +class MyTraits : public std::char_traits +{ +public: + static bool eq(wchar_t c1, wchar_t c2) + { + bool test __attribute__((unused)) = true; + VERIFY( c1 != L'X' ); + VERIFY( c2 != L'X' ); + return std::char_traits::eq(c1, c2); + } +}; + +class MyBuf : public std::basic_streambuf +{ + wchar_t buffer[8]; + +public: + MyBuf() + { + std::wmemset(buffer, L'X', sizeof(buffer) / sizeof(buffer[0])); + std::wmemset(buffer + 2, L'f', 4); + setg(buffer + 2, buffer + 2, buffer + 6); + } +}; + +// libstdc++/9538 +void test08() +{ + bool test __attribute__((unused)) = true; + + MyBuf mb; + mb.sputbackc(L'a'); +} + +int main() +{ + test08(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_streambuf/sputc/wchar_t/1057.cc b/libstdc++-v3/testsuite/27_io/basic_streambuf/sputc/wchar_t/1057.cc new file mode 100644 index 00000000000..01dc431b10d --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_streambuf/sputc/wchar_t/1057.cc @@ -0,0 +1,62 @@ +// 1999-10-11 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004 +// 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. + +// 27.5.2 template class basic_streambuf + +#include +#include +#include + +class nullsetpbuf : public std::wstreambuf +{ + wchar_t foo[64]; +public: + nullsetpbuf() + { + setp(foo, foo + 64); + setp(NULL, NULL); + } +}; + +// libstdc++/1057 +void test05() +{ + std::wstring text1 = L"abcdefghijklmn"; + + nullsetpbuf nsp; + // Immediate crash as sputc writes to null pointer + nsp.sputc(L'a'); +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_streambuf/sputn/char/1057.cc b/libstdc++-v3/testsuite/27_io/basic_streambuf/sputn/char/1057.cc index 628e2e77d73..f3b40500a8a 100644 --- a/libstdc++-v3/testsuite/27_io/basic_streambuf/sputn/char/1057.cc +++ b/libstdc++-v3/testsuite/27_io/basic_streambuf/sputn/char/1057.cc @@ -30,7 +30,7 @@ // 27.5.2 template class basic_streambuf #include -#include +#include #include class nullsetpbuf : public std::streambuf diff --git a/libstdc++-v3/testsuite/27_io/basic_streambuf/sputn/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_streambuf/sputn/wchar_t/1.cc new file mode 100644 index 00000000000..d638b79dc56 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_streambuf/sputn/wchar_t/1.cc @@ -0,0 +1,127 @@ +// 1999-10-11 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004 +// 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. + +// 27.5.2 template class basic_streambuf + +#include +#include +#include + +class testbuf : public std::wstreambuf +{ +public: + + // Typedefs: + typedef std::wstreambuf::traits_type traits_type; + typedef std::wstreambuf::char_type char_type; + + testbuf(): std::wstreambuf() + { } + + bool + check_pointers() + { + bool test __attribute__((unused)) = true; + VERIFY( this->eback() == NULL ); + VERIFY( this->gptr() == NULL ); + VERIFY( this->egptr() == NULL ); + VERIFY( this->pbase() == NULL ); + VERIFY( this->pptr() == NULL ); + VERIFY( this->epptr() == NULL ); + return test; + } + + int_type + pub_uflow() + { return (this->uflow()); } + + int_type + pub_overflow(int_type __c = traits_type::eof()) + { return (this->overflow(__c)); } + + int_type + pub_pbackfail(int_type __c) + { return (this->pbackfail(__c)); } + + void + pub_setg(wchar_t* beg, wchar_t* cur, wchar_t* end) + { this->setg(beg, cur, end); } + + void + pub_setp(wchar_t* beg, wchar_t* end) + { this->setp(beg, end); } + +protected: + int_type + underflow() + { + int_type __retval = traits_type::eof(); + if (this->gptr() < this->egptr()) + __retval = traits_type::not_eof(0); + return __retval; + } +}; + +void test01() +{ + typedef testbuf::traits_type traits_type; + typedef testbuf::int_type int_type; + + bool test __attribute__((unused)) = true; + testbuf buf01; + + // sputn/xsputn + const wchar_t* lit01 = L"isotope 217: the unstable molecule on thrill jockey"; + const int i02 = std::wcslen(lit01); + wchar_t lit02[i02]; + std::wcscpy(lit02, lit01); + + wchar_t carray[i02 + 1]; + std::wmemset(carray, 0, i02 + 1); + + buf01.pub_setp(carray, (carray + i02)); + buf01.sputn(lit02, 0); + VERIFY( carray[0] == 0 ); + VERIFY( lit02[0] == L'i' ); + buf01.sputn(lit02, 1); + VERIFY( lit02[0] == carray[0] ); + VERIFY( lit02[1] == L's' ); + VERIFY( carray[1] == 0 ); + buf01.sputn(lit02 + 1, 10); + VERIFY( std::memcmp(lit02, carray, 10) == 0 ); + buf01.sputn(lit02 + 11, 20); + VERIFY( std::memcmp(lit02, carray, 30) == 0 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_streambuf/sputn/wchar_t/1057.cc b/libstdc++-v3/testsuite/27_io/basic_streambuf/sputn/wchar_t/1057.cc new file mode 100644 index 00000000000..d25b015c5a2 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_streambuf/sputn/wchar_t/1057.cc @@ -0,0 +1,62 @@ +// 1999-10-11 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004 +// 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. + +// 27.5.2 template class basic_streambuf + +#include +#include +#include + +class nullsetpbuf : public std::wstreambuf +{ + wchar_t foo[64]; +public: + nullsetpbuf() + { + setp(foo, foo + 64); + setp(NULL, NULL); + } +}; + +// libstdc++/1057 +void test05() +{ + std::wstring text1 = L"abcdefghijklmn"; + + nullsetpbuf nsp; + // Immediate crash as xsputn writes to null pointer + nsp.sputn(text1.c_str(), text1.length()); +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_streambuf/sync/char/1057.cc b/libstdc++-v3/testsuite/27_io/basic_streambuf/sync/char/1057.cc index 5c75185774b..9bc2ac00664 100644 --- a/libstdc++-v3/testsuite/27_io/basic_streambuf/sync/char/1057.cc +++ b/libstdc++-v3/testsuite/27_io/basic_streambuf/sync/char/1057.cc @@ -30,6 +30,7 @@ // 27.5.2 template class basic_streambuf #include +#include #include class setpbuf : public std::streambuf diff --git a/libstdc++-v3/testsuite/27_io/basic_streambuf/sync/wchar_t/1057.cc b/libstdc++-v3/testsuite/27_io/basic_streambuf/sync/wchar_t/1057.cc new file mode 100644 index 00000000000..5877cc1be0e --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_streambuf/sync/wchar_t/1057.cc @@ -0,0 +1,110 @@ +// 1999-10-11 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004 +// 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. + +// 27.5.2 template class basic_streambuf + +#include +#include +#include + +class setpbuf : public std::wstreambuf +{ + wchar_t buffer[4]; + std::wstring result; + +public: + + std::wstring& + get_result() + { return result; } + + setpbuf() + { + wchar_t foo[32]; + setp(foo, foo + 32); + setp(buffer, buffer + 4); + } + + ~setpbuf() + { sync(); } + + virtual int_type + overflow(int_type n) + { + if (sync() != 0) + return traits_type::eof(); + + result += traits_type::to_char_type(n); + + return n; + } + + virtual int + sync() + { + result.append(pbase(), pptr()); + setp(buffer, buffer + 4); + return 0; + } +}; + +// libstdc++/1057 +void test04() +{ + bool test __attribute__((unused)) = true; + std::wstring text = L"abcdefghijklmn"; + + // 01 + setpbuf sp1; + // Here xsputn writes over sp1.result + sp1.sputn(text.c_str(), text.length()); + + // This crashes when result is accessed + sp1.pubsync(); + VERIFY( sp1.get_result() == text ); + + // 02 + setpbuf sp2; + for (std::wstring::size_type i = 0; i < text.length(); ++i) + { + // sputc also writes over result + sp2.sputc(text[i]); + } + + // Crash here + sp2.pubsync(); + VERIFY( sp2.get_result() == text ); +} + +int main() +{ + test04(); + return 0; +} -- 2.30.2