From 1bf4ab23be149358053e63587d1c09e7d001088f Mon Sep 17 00:00:00 2001 From: Paolo Carlini Date: Fri, 9 Jul 2004 22:00:59 +0000 Subject: [PATCH] Add wchar_t counterparts of the basic_stringbuf tests. 2004-07-09 Paolo Carlini Add wchar_t counterparts of the basic_stringbuf tests. * testsuite/27_io/basic_stringbuf/imbue/wchar_t/1.cc, 9322.cc: New. * testsuite/27_io/basic_stringbuf/in_avail/wchar_t/1.cc: Likewise. * testsuite/27_io/basic_stringbuf/overflow/wchar_t/1.cc, 2.cc, 3599.cc, 9988.cc: Likewise. * testsuite/27_io/basic_stringbuf/sbumpc/wchar_t/1.cc, 9825.cc: Likewise. * testsuite/27_io/basic_stringbuf/seekoff/wchar_t/1.cc, 2.cc: Likewise. * testsuite/27_io/basic_stringbuf/seekoff/wchar_t/1.cc, 2.cc, 3.cc: Likewise. * testsuite/27_io/basic_stringbuf/setbuf/wchar_t/1.cc, 2.cc, 3.cc: Likewise. * testsuite/27_io/basic_stringbuf/sgetc/wchar_t/1.cc: Likewise. * testsuite/27_io/basic_stringbuf/sgetn/wchar_t/1.cc: Likewise. * testsuite/27_io/basic_stringbuf/snextc/wchar_t/1.cc: Likewise. * testsuite/27_io/basic_stringbuf/sputbackc/wchar_t/1.cc, 9425.cc: Likewise. * testsuite/27_io/basic_stringbuf/sputc/wchar_t/1.cc, 1057.cc, 9404-1.cc: Likewise. * testsuite/27_io/basic_stringbuf/sputn/wchar_t/1.cc, 1057.cc, 9404-2.cc: Likewise. * testsuite/27_io/basic_stringbuf/str/wchar_t/1.cc, 2.cc, 3.cc, 3955.cc: Likewise. * testsuite/27_io/basic_stringbuf/sungetc/wchar_t/1.cc: Likewise. * testsuite/27_io/basic_stringbuf/sync/wchar_t/1057.cc: Likewise. From-SVN: r84405 --- libstdc++-v3/ChangeLog | 29 ++++ .../27_io/basic_stringbuf/imbue/wchar_t/1.cc | 46 ++++++ .../basic_stringbuf/imbue/wchar_t/9322.cc | 53 +++++++ .../basic_stringbuf/in_avail/wchar_t/1.cc | 64 ++++++++ .../basic_stringbuf/overflow/wchar_t/1.cc | 57 +++++++ .../basic_stringbuf/overflow/wchar_t/2.cc | 81 ++++++++++ .../basic_stringbuf/overflow/wchar_t/3599.cc | 67 ++++++++ .../basic_stringbuf/overflow/wchar_t/9988.cc | 63 ++++++++ .../27_io/basic_stringbuf/sbumpc/wchar_t/1.cc | 73 +++++++++ .../basic_stringbuf/sbumpc/wchar_t/9825.cc | 50 ++++++ .../basic_stringbuf/seekoff/wchar_t/1.cc | 121 ++++++++++++++ .../basic_stringbuf/seekoff/wchar_t/2.cc | 59 +++++++ .../basic_stringbuf/seekpos/wchar_t/1.cc | 94 +++++++++++ .../basic_stringbuf/seekpos/wchar_t/2.cc | 60 +++++++ .../basic_stringbuf/seekpos/wchar_t/3.cc | 48 ++++++ .../27_io/basic_stringbuf/setbuf/wchar_t/1.cc | 64 ++++++++ .../27_io/basic_stringbuf/setbuf/wchar_t/2.cc | 45 ++++++ .../27_io/basic_stringbuf/setbuf/wchar_t/3.cc | 45 ++++++ .../27_io/basic_stringbuf/sgetc/wchar_t/1.cc | 75 +++++++++ .../27_io/basic_stringbuf/sgetn/wchar_t/1.cc | 109 +++++++++++++ .../27_io/basic_stringbuf/snextc/wchar_t/1.cc | 83 ++++++++++ .../basic_stringbuf/sputbackc/wchar_t/1.cc | 120 ++++++++++++++ .../basic_stringbuf/sputbackc/wchar_t/9425.cc | 43 +++++ .../27_io/basic_stringbuf/sputc/wchar_t/1.cc | 71 +++++++++ .../basic_stringbuf/sputc/wchar_t/1057.cc | 62 ++++++++ .../basic_stringbuf/sputc/wchar_t/9404-1.cc | 73 +++++++++ .../27_io/basic_stringbuf/sputn/wchar_t/1.cc | 80 ++++++++++ .../basic_stringbuf/sputn/wchar_t/1057.cc | 62 ++++++++ .../basic_stringbuf/sputn/wchar_t/9404-2.cc | 73 +++++++++ .../27_io/basic_stringbuf/str/wchar_t/1.cc | 74 +++++++++ .../27_io/basic_stringbuf/str/wchar_t/2.cc | 55 +++++++ .../27_io/basic_stringbuf/str/wchar_t/3.cc | 43 +++++ .../27_io/basic_stringbuf/str/wchar_t/3955.cc | 44 ++++++ .../basic_stringbuf/sungetc/wchar_t/1.cc | 149 ++++++++++++++++++ .../basic_stringbuf/sync/wchar_t/1057.cc | 109 +++++++++++++ 35 files changed, 2444 insertions(+) create mode 100644 libstdc++-v3/testsuite/27_io/basic_stringbuf/imbue/wchar_t/1.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_stringbuf/imbue/wchar_t/9322.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_stringbuf/in_avail/wchar_t/1.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_stringbuf/overflow/wchar_t/1.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_stringbuf/overflow/wchar_t/2.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_stringbuf/overflow/wchar_t/3599.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_stringbuf/overflow/wchar_t/9988.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_stringbuf/sbumpc/wchar_t/1.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_stringbuf/sbumpc/wchar_t/9825.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_stringbuf/seekoff/wchar_t/1.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_stringbuf/seekoff/wchar_t/2.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_stringbuf/seekpos/wchar_t/1.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_stringbuf/seekpos/wchar_t/2.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_stringbuf/seekpos/wchar_t/3.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_stringbuf/setbuf/wchar_t/1.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_stringbuf/setbuf/wchar_t/2.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_stringbuf/setbuf/wchar_t/3.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_stringbuf/sgetc/wchar_t/1.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_stringbuf/sgetn/wchar_t/1.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_stringbuf/snextc/wchar_t/1.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_stringbuf/sputbackc/wchar_t/1.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_stringbuf/sputbackc/wchar_t/9425.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_stringbuf/sputc/wchar_t/1.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_stringbuf/sputc/wchar_t/1057.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_stringbuf/sputc/wchar_t/9404-1.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_stringbuf/sputn/wchar_t/1.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_stringbuf/sputn/wchar_t/1057.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_stringbuf/sputn/wchar_t/9404-2.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_stringbuf/str/wchar_t/1.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_stringbuf/str/wchar_t/2.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_stringbuf/str/wchar_t/3.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_stringbuf/str/wchar_t/3955.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_stringbuf/sungetc/wchar_t/1.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_stringbuf/sync/wchar_t/1057.cc diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 4b0036b3bc6..00ce84dac50 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,32 @@ +2004-07-09 Paolo Carlini + + Add wchar_t counterparts of the basic_stringbuf tests. + * testsuite/27_io/basic_stringbuf/imbue/wchar_t/1.cc, 9322.cc: New. + * testsuite/27_io/basic_stringbuf/in_avail/wchar_t/1.cc: Likewise. + * testsuite/27_io/basic_stringbuf/overflow/wchar_t/1.cc, 2.cc, + 3599.cc, 9988.cc: Likewise. + * testsuite/27_io/basic_stringbuf/sbumpc/wchar_t/1.cc, 9825.cc: + Likewise. + * testsuite/27_io/basic_stringbuf/seekoff/wchar_t/1.cc, 2.cc: + Likewise. + * testsuite/27_io/basic_stringbuf/seekoff/wchar_t/1.cc, 2.cc, 3.cc: + Likewise. + * testsuite/27_io/basic_stringbuf/setbuf/wchar_t/1.cc, 2.cc, 3.cc: + Likewise. + * testsuite/27_io/basic_stringbuf/sgetc/wchar_t/1.cc: Likewise. + * testsuite/27_io/basic_stringbuf/sgetn/wchar_t/1.cc: Likewise. + * testsuite/27_io/basic_stringbuf/snextc/wchar_t/1.cc: Likewise. + * testsuite/27_io/basic_stringbuf/sputbackc/wchar_t/1.cc, 9425.cc: + Likewise. + * testsuite/27_io/basic_stringbuf/sputc/wchar_t/1.cc, 1057.cc, + 9404-1.cc: Likewise. + * testsuite/27_io/basic_stringbuf/sputn/wchar_t/1.cc, 1057.cc, + 9404-2.cc: Likewise. + * testsuite/27_io/basic_stringbuf/str/wchar_t/1.cc, 2.cc, 3.cc, + 3955.cc: Likewise. + * testsuite/27_io/basic_stringbuf/sungetc/wchar_t/1.cc: Likewise. + * testsuite/27_io/basic_stringbuf/sync/wchar_t/1057.cc: Likewise. + 2004-07-08 Paolo Carlini * include/bits/gslice.h: Trivial formatting fixes. diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/imbue/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/imbue/wchar_t/1.cc new file mode 100644 index 00000000000..855580d04ad --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/imbue/wchar_t/1.cc @@ -0,0 +1,46 @@ +// 981208 bkoz test functionality of basic_stringbuf 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 + +std::wstring str_01(L"mykonos. . . or what?"); +std::wstringbuf strb_01(str_01); + +// test the streambuf/stringbuf locale settings +void test02() +{ + std::locale loc_c = std::locale::classic(); + loc_c = strb_01.getloc(); + strb_01.pubimbue(loc_c); //This should initialize _M_init to true + std::locale loc_tmp = strb_01.getloc(); + VERIFY( loc_tmp == loc_c ); +} + +int main() +{ + test02(); + return 0; +} + + + +// more candy!!! diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/imbue/wchar_t/9322.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/imbue/wchar_t/9322.cc new file mode 100644 index 00000000000..b91b067534d --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/imbue/wchar_t/9322.cc @@ -0,0 +1,53 @@ +// 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.7.1.3 Overridden virtual functions + +#include +#include + +// libstdc++/9322 +void test03() +{ + using std::locale; + bool test __attribute__((unused)) = true; + + locale loc = std::locale::classic(); + std::wstringbuf 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() +{ + using namespace std; + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/in_avail/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/in_avail/wchar_t/1.cc new file mode 100644 index 00000000000..96fcbcdaf10 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/in_avail/wchar_t/1.cc @@ -0,0 +1,64 @@ +// 981208 bkoz test functionality of basic_stringbuf 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 + +std::wstring str_01(L"mykonos. . . or what?"); +std::wstring str_02(L"paris, or sainte-maxime?"); +std::wstring str_03; +std::wstringbuf strb_01(str_01); +std::wstringbuf strb_02(str_02, std::ios_base::in); +std::wstringbuf strb_03(str_03, std::ios_base::out); + +// test overloaded virtual functions +void test04() +{ + bool test __attribute__((unused)) = true; + std::wstring str_tmp; + std::wstringbuf strb_tmp; + std::streamoff strmof_1(-1), strmof_2; + typedef std::wstringbuf::int_type int_type; + typedef std::wstringbuf::traits_type traits_type; + typedef std::wstringbuf::pos_type pos_type; + typedef std::wstringbuf::off_type off_type; + + // GET + // int in_avail() + strmof_1 = strb_01.in_avail(); + strmof_2 = strb_02.in_avail(); + VERIFY( strmof_1 != strmof_2 ); + VERIFY( strmof_1 == static_cast(str_01.length()) ); + VERIFY( strmof_2 == static_cast(str_02.length()) ); + strmof_1 = strb_03.in_avail(); + // zero cuz write-only, or eof()? zero, from showmany + VERIFY( strmof_1 == 0 ); +} + +int main() +{ + test04(); + return 0; +} + + + +// more candy!!! diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/overflow/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/overflow/wchar_t/1.cc new file mode 100644 index 00000000000..7a15c3dbae4 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/overflow/wchar_t/1.cc @@ -0,0 +1,57 @@ +// 2004-07-07 Paolo Carlini + +// Copyright (C) 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.7.1.3 basic_stringbuf overridden virtual functions. + +#include +#include +#include + +using namespace std; + +wstring +data(unsigned len) +{ + wstring ret; + for (unsigned i = 0; i < len; ++i) + ret.push_back(L'a' + rand() % 26); + return ret; +} + +void +test01(unsigned iter) +{ + bool test __attribute__((unused)) = true; + + for (unsigned n = 1; n <= iter; n *= 10) + { + const wstring str = data(n); + wstringbuf sstr; + for (unsigned i = 0; i < n; ++i) + sstr.sputc(str[i]); + VERIFY( str == sstr.str() ); + } +} + +int main() +{ + test01(10000000); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/overflow/wchar_t/2.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/overflow/wchar_t/2.cc new file mode 100644 index 00000000000..324baabf105 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/overflow/wchar_t/2.cc @@ -0,0 +1,81 @@ +// 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 + +// test03 +// http://gcc.gnu.org/ml/libstdc++/2000-q1/msg00151.html +template > + class basic_nullbuf : public std::basic_stringbuf + { + protected: + typedef typename + std::basic_stringbuf::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_stringbuf/overflow/wchar_t/3599.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/overflow/wchar_t/3599.cc new file mode 100644 index 00000000000..d95ead1d86d --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/overflow/wchar_t/3599.cc @@ -0,0 +1,67 @@ +// 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. + +#include +#include +#include + +// libstdc++/3599 +class testbuf : public std::wstringbuf +{ +public: + typedef std::wstringbuf::traits_type traits_type; + + testbuf() : std::wstringbuf() { } + +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_stringbuf/overflow/wchar_t/9988.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/overflow/wchar_t/9988.cc new file mode 100644 index 00000000000..a156e81a6d7 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/overflow/wchar_t/9988.cc @@ -0,0 +1,63 @@ +// 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 + +class OverBuf : public std::wstringbuf +{ +public: + int_type pub_overflow(int_type c = traits_type::eof()) + { return std::wstringbuf::overflow(c); } +}; + +// libstdc++/9988 +// filebuf::overflow writes EOF to file +void test15() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + OverBuf sb; + + sb.sputc(L'a'); + sb.pub_overflow(L'b'); + sb.pub_overflow(); + sb.sputc(L'c'); + + wstringbuf sbin(sb.str(), ios_base::in); + wstringbuf::int_type c; + c = sbin.sbumpc(); + VERIFY( c == L'a' ); + c = sbin.sbumpc(); + VERIFY( c == L'b' ); + c = sbin.sbumpc(); + VERIFY( c == L'c' ); + c = sbin.sbumpc(); + VERIFY( c == wstringbuf::traits_type::eof() ); +} + +int main() +{ + test15(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/sbumpc/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sbumpc/wchar_t/1.cc new file mode 100644 index 00000000000..188a87ee600 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sbumpc/wchar_t/1.cc @@ -0,0 +1,73 @@ +// 981208 bkoz test functionality of basic_stringbuf 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 + +std::wstring str_01(L"mykonos. . . or what?"); +std::wstring str_02(L"paris, or sainte-maxime?"); +std::wstring str_03; +std::wstringbuf strb_01(str_01); +std::wstringbuf strb_02(str_02, std::ios_base::in); +std::wstringbuf strb_03(str_03, std::ios_base::out); + +// test overloaded virtual functions +void test04() +{ + bool test __attribute__((unused)) = true; + std::wstring str_tmp; + std::wstringbuf strb_tmp; + std::streamoff strmof_1(-1), strmof_2; + typedef std::wstringbuf::int_type int_type; + typedef std::wstringbuf::traits_type traits_type; + typedef std::wstringbuf::pos_type pos_type; + typedef std::wstringbuf::off_type off_type; + + // GET + strmof_1 = strb_01.in_avail(); + strmof_2 = strb_02.in_avail(); + strmof_1 = strb_03.in_avail(); + + // int_type sbumpc() + // if read_cur not avail, return uflow(), else return *read_cur & increment + int_type c1 = strb_01.sbumpc(); + int_type c2 = strb_02.sbumpc(); + VERIFY( c1 != c2 ); + VERIFY( c1 == str_01[0] ); + VERIFY( c2 == str_02[0] ); //should equal first letter at this point + int_type c3 = strb_01.sbumpc(); + int_type c4 = strb_02.sbumpc(); + VERIFY( c1 != c2 ); + VERIFY( c1 != c3 ); + VERIFY( c2 != c4 ); + int_type c5 = strb_03.sbumpc(); + VERIFY( c5 == traits_type::eof() ); +} + +int main() +{ + test04(); + return 0; +} + + + +// more candy!!! diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/sbumpc/wchar_t/9825.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sbumpc/wchar_t/9825.cc new file mode 100644 index 00000000000..1a874ba1fad --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sbumpc/wchar_t/9825.cc @@ -0,0 +1,50 @@ +// 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 + +// libstdc++/9825 +// filebuf::sputbackc breaks sbumpc +void test12() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + wstringbuf sbuf; + sbuf.sputn(L"crazy bees!", 11); + sbuf.pubseekoff(0, ios_base::beg); + sbuf.sbumpc(); + sbuf.sputbackc(L'x'); + stringbuf::int_type c = sbuf.sbumpc(); + VERIFY( c == L'x' ); + c = sbuf.sbumpc(); + VERIFY( c == L'r' ); + c = sbuf.sbumpc(); + VERIFY( c == L'a' ); +} + +int main() +{ + test12(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekoff/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekoff/wchar_t/1.cc new file mode 100644 index 00000000000..c1a659e6be1 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekoff/wchar_t/1.cc @@ -0,0 +1,121 @@ +// 981208 bkoz test functionality of basic_stringbuf 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 + +std::wstring str_01(L"mykonos. . . or what?"); +std::wstring str_02(L"paris, or sainte-maxime?"); +std::wstring str_03; +std::wstringbuf strb_01(str_01); +std::wstringbuf strb_02(str_02, std::ios_base::in); +std::wstringbuf strb_03(str_03, std::ios_base::out); + +// test overloaded virtual functions +void test04() +{ + bool test __attribute__((unused)) = true; + std::wstring str_tmp; + std::wstringbuf strb_tmp; + std::streamsize strmsz_1, strmsz_2; + typedef std::wstringbuf::int_type int_type; + typedef std::wstringbuf::traits_type traits_type; + typedef std::wstringbuf::pos_type pos_type; + typedef std::wstringbuf::off_type off_type; + + int_type c1 = strb_01.sbumpc(); + int_type c2 = strb_02.sbumpc(); + int_type c3 = strb_01.sbumpc(); + + // PUT + strb_03.str(str_01); //reset + + // BUFFER MANAGEMENT & POSITIONING + + // seekoff + // pubseekoff(off_type off, ios_base::seekdir way, ios_base::openmode which) + // alters the stream position to off + pos_type pt_1(off_type(-1)); + pos_type pt_2(off_type(0)); + off_type off_1 = 0; + off_type off_2 = 0; + strb_01.str(str_01); //in|out ("mykonos. . . or what?"); + strb_02.str(str_02); //in ("paris, or sainte-maxime?"); + strb_03.str(str_03); //out ("") + //IN|OUT + //beg + pt_1 = strb_01.pubseekoff(2, std::ios_base::beg); + off_1 = off_type(pt_1); + VERIFY( off_1 >= 0 ); + c1 = strb_01.snextc(); //current in pointer +1 + VERIFY( c1 == L'o' ); + c2 = strb_01.sputc(L'x'); //test current out pointer + str_tmp = std::wstring(L"myxonos. . . or what?"); + VERIFY( strb_01.str() == str_tmp ); + //cur + pt_1 = strb_01.pubseekoff(2, std::ios_base::cur); + off_1 = off_type(pt_1); + VERIFY( off_1 == -1 ); // can't seekoff for in and out + cur in sstreams + pt_1 = strb_01.pubseekoff(2, std::ios_base::cur, std::ios_base::in); + off_1 = off_type(pt_1); + pt_2 = strb_01.pubseekoff(2, std::ios_base::cur, std::ios_base::in); + off_2 = off_type(pt_2); + VERIFY( off_2 == off_1 + 2 ); + c1 = strb_01.snextc(); //current in pointer + 1 + VERIFY( c1 == L' ' ); + c2 = strb_01.sputc(L'x'); //test current out pointer + str_tmp = std::wstring(L"myxxnos. . . or what?"); + VERIFY( strb_01.str() == str_tmp ); + //end + pt_2 = strb_01.pubseekoff(2, std::ios_base::end); + off_1 = off_type(pt_2); + VERIFY( off_1 == -1 ); // not a valid position + VERIFY( strb_01.str() == str_tmp ); + // end part two (from the filebuf tests) + strb_01.pubseekoff(0, std::ios_base::end); + strmsz_1 = strb_01.in_avail(); // 0 cuz at the end + c1 = strb_01.sgetc(); + c2 = strb_01.sungetc(); + strmsz_2 = strb_01.in_avail(); // 1 + c3 = strb_01.sgetc(); + VERIFY( c1 != c2 ); + VERIFY( strmsz_2 != strmsz_1 ); + VERIFY( strmsz_2 == 1 ); + // end part three + strmsz_1 = strb_01.str().size(); + strmsz_2 = strb_01.sputn(L" ravi shankar meets carlos santana in LoHa", 90); + strb_01.pubseekoff(0, std::ios_base::end); + strb_01.sputc(L'<'); + str_tmp = strb_01.str(); + VERIFY(static_cast(str_tmp.size()) == strmsz_1 + strmsz_2 + 1); + // IN + // OUT +} + +int main() +{ + test04(); + return 0; +} + + + +// more candy!!! diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekoff/wchar_t/2.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekoff/wchar_t/2.cc new file mode 100644 index 00000000000..63a0a2ea865 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekoff/wchar_t/2.cc @@ -0,0 +1,59 @@ +// 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.7.1.3 Overridden virtual functions + +#include +#include + +void test02(std::wstringbuf& in, bool pass) +{ + bool test __attribute__((unused)) = true; + using namespace std; + typedef wstreambuf::pos_type pos_type; + typedef wstreambuf::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 ); +} + +int main() +{ + using namespace std; + + // movie star, submarine scientist! + wstringbuf in1(L"Hedy Lamarr", ios_base::in); + wstringbuf in2(ios_base::in); + wstringbuf in3(L"", ios_base::in); + test02(in1, true); + test02(in2, false); + test02(in3, false); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekpos/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekpos/wchar_t/1.cc new file mode 100644 index 00000000000..bac614efa9f --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekpos/wchar_t/1.cc @@ -0,0 +1,94 @@ +// 981208 bkoz test functionality of basic_stringbuf 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 + +std::wstring str_01(L"mykonos. . . or what?"); +std::wstring str_02(L"paris, or sainte-maxime?"); +std::wstring str_03; +std::wstringbuf strb_01(str_01); +std::wstringbuf strb_02(str_02, std::ios_base::in); +std::wstringbuf strb_03(str_03, std::ios_base::out); + +// test overloaded virtual functions +void test04() +{ + bool test __attribute__((unused)) = true; + std::wstring str_tmp; + std::wstringbuf strb_tmp; + typedef std::wstringbuf::int_type int_type; + typedef std::wstringbuf::traits_type traits_type; + typedef std::wstringbuf::pos_type pos_type; + typedef std::wstringbuf::off_type off_type; + + int_type c1 = strb_01.sbumpc(); + int_type c2 = strb_02.sbumpc(); + int_type c3 = strb_01.sbumpc(); + + pos_type pt_1(off_type(-1)); + pos_type pt_2(off_type(0)); + off_type off_1 = 0; + off_type off_2 = 0; + + // PUT + strb_03.str(str_01); //reset + + // BUFFER MANAGEMENT & POSITIONING + + // seekpos + // pubseekpos(pos_type sp, ios_base::openmode) + // alters the stream position to sp + strb_01.str(str_01); //in|out ("mykonos. . . or what?"); + strb_02.str(str_02); //in ("paris, or sainte-maxime?"); + strb_03.str(str_03); //out ("") + //IN|OUT + //beg + pt_1 = strb_01.pubseekoff(2, std::ios_base::beg); + off_1 = off_type(pt_1); + VERIFY( off_1 >= 0 ); + pt_1 = strb_01.pubseekoff(0, std::ios_base::cur, std::ios_base::out); + off_1 = off_type(pt_1); + c1 = strb_01.snextc(); //current in pointer +1 + VERIFY( c1 == L'o' ); + c2 = strb_01.sputc(L'x'); //test current out pointer + str_tmp = std::wstring(L"myxonos. . . or what?"); + VERIFY( strb_01.str() == str_tmp ); + strb_01.pubsync(); //resets pointers + pt_2 = strb_01.pubseekpos(pt_1, std::ios_base::in|std::ios_base::out); + off_2 = off_type(pt_2); + VERIFY( off_1 == off_2 ); + c3 = strb_01.snextc(); //current in pointer +1 + VERIFY( c1 == c3 ); + c2 = strb_01.sputc(L'x'); //test current out pointer + str_tmp = std::wstring(L"myxonos. . . or what?"); + VERIFY( strb_01.str() == str_tmp ); +} + +int main() +{ + test04(); + return 0; +} + + + +// more candy!!! diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekpos/wchar_t/2.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekpos/wchar_t/2.cc new file mode 100644 index 00000000000..eb82442dd55 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekpos/wchar_t/2.cc @@ -0,0 +1,60 @@ +// 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.7.1.3 Overridden virtual functions + +#include +#include + +void test02(std::wstringbuf& in, bool pass) +{ + bool test __attribute__((unused)) = true; + using namespace std; + typedef wstreambuf::pos_type pos_type; + typedef wstreambuf::off_type off_type; + pos_type bad = pos_type(off_type(-1)); + pos_type p = 0; + + // 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); + if (pass) + VERIFY( p != bad ); +} + +int main() +{ + using namespace std; + + // movie star, submarine scientist! + wstringbuf in1(L"Hedy Lamarr", ios_base::in); + wstringbuf in2(ios_base::in); + wstringbuf in3(L"", ios_base::in); + test02(in1, true); + test02(in2, false); + test02(in3, false); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekpos/wchar_t/3.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekpos/wchar_t/3.cc new file mode 100644 index 00000000000..f9fc736a9af --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekpos/wchar_t/3.cc @@ -0,0 +1,48 @@ +// 2003-05-30 Paolo Carlini + +// 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. + +#include +#include + +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + typedef wstringbuf::pos_type pos_type; + typedef wstringbuf::off_type off_type; + + wstringbuf strb_01(ios_base::out); + + strb_01.sputn(L"broken peak", 11); + pos_type pt_1 = strb_01.pubseekoff(0, ios_base::end, ios_base::out); + + // In general, according to 27.7.1.3,14, the below has undefined + // behaviour since pt_1 + off_type(1) doesn't come from a + // previous pubseekpos or pubseekoff. However, given v3 implementation, + // this was useful to expose a bug in pubseekpos checks. + pos_type pt_2 = strb_01.pubseekpos(pt_1 + off_type(1), ios_base::out); + VERIFY( pt_2 == pos_type(off_type(-1)) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/setbuf/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/setbuf/wchar_t/1.cc new file mode 100644 index 00000000000..ba01e1d395d --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/setbuf/wchar_t/1.cc @@ -0,0 +1,64 @@ +// 981208 bkoz test functionality of basic_stringbuf 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 + +std::wstring str_01(L"mykonos. . . or what?"); +std::wstring str_02(L"paris, or sainte-maxime?"); +std::wstring str_03; +std::wstringbuf strb_01(str_01); +std::wstringbuf strb_02(str_02, std::ios_base::in); +std::wstringbuf strb_03(str_03, std::ios_base::out); + +// test overloaded virtual functions +void test04() +{ + bool test __attribute__((unused)) = true; + std::wstring str_tmp; + std::wstringbuf strb_tmp; + typedef std::wstringbuf::int_type int_type; + typedef std::wstringbuf::traits_type traits_type; + typedef std::wstringbuf::pos_type pos_type; + typedef std::wstringbuf::off_type off_type; + + // PUT + strb_03.str(str_01); //reset + + // BUFFER MANAGEMENT & POSITIONING + // setbuf + // pubsetbuf(char_type* s, streamsize n) + str_tmp = std::wstring(L"naaaah, go to cebu"); + strb_01.pubsetbuf(const_cast (str_tmp.c_str()), str_tmp.size()); + VERIFY( strb_01.str() == str_tmp ); + strb_01.pubsetbuf(0,0); + VERIFY( strb_01.str() == str_tmp ); +} + +int main() +{ + test04(); + return 0; +} + + + +// more candy!!! diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/setbuf/wchar_t/2.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/setbuf/wchar_t/2.cc new file mode 100644 index 00000000000..569cec2df39 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/setbuf/wchar_t/2.cc @@ -0,0 +1,45 @@ +// 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 + +void test01() +{ + using namespace std; + + bool test __attribute__((unused)) = true; + wchar_t buf[512]; + const wchar_t* strlit = L"how to tell a story and other essays: mark twain"; + const size_t strlitsize = std::wcslen(strlit); + wstringbuf sbuf; + + sbuf.pubsetbuf(buf, 512); + sbuf.sputn(strlit, strlitsize); + VERIFY( std::wcsncmp(strlit, buf, strlitsize) == 0 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/setbuf/wchar_t/3.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/setbuf/wchar_t/3.cc new file mode 100644 index 00000000000..952fe2c1361 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/setbuf/wchar_t/3.cc @@ -0,0 +1,45 @@ +// 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 + +void test02() +{ + using namespace std; + + bool test __attribute__((unused)) = true; + wchar_t buf[512]; + const wchar_t* strlit = L"how to tell a story and other essays: mark twain"; + const size_t strlitsize = std::wcslen(strlit); + wstring s(L"tmp"); + wstringbuf sbuf(s, ios_base::out); + sbuf.pubsetbuf(buf, strlitsize); + sbuf.sputn(strlit, strlitsize); + VERIFY( std::wcsncmp(strlit, buf, strlitsize) == 0 ); +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/sgetc/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sgetc/wchar_t/1.cc new file mode 100644 index 00000000000..5912b05ad8f --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sgetc/wchar_t/1.cc @@ -0,0 +1,75 @@ +// 981208 bkoz test functionality of basic_stringbuf 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 + +std::wstring str_01(L"mykonos. . . or what?"); +std::wstring str_02(L"paris, or sainte-maxime?"); +std::wstring str_03; +std::wstringbuf strb_01(str_01); +std::wstringbuf strb_02(str_02, std::ios_base::in); +std::wstringbuf strb_03(str_03, std::ios_base::out); + +// test overloaded virtual functions +void test04() +{ + bool test __attribute__((unused)) = true; + std::wstring str_tmp; + std::wstringbuf strb_tmp; + std::streamoff strmof_1(-1), strmof_2; + typedef std::wstringbuf::int_type int_type; + typedef std::wstringbuf::traits_type traits_type; + typedef std::wstringbuf::pos_type pos_type; + typedef std::wstringbuf::off_type off_type; + + // GET + strmof_1 = strb_01.in_avail(); + strmof_2 = strb_02.in_avail(); + strmof_1 = strb_03.in_avail(); + + int_type c3 = strb_01.sbumpc(); + int_type c4 = strb_02.sbumpc(); + int_type c5 = strb_03.sbumpc(); + + // int_type sgetc() + // if read_cur not avail, return uflow(), else return *read_cur + int_type c6 = strb_01.sgetc(); + int_type c7 = strb_02.sgetc(); + VERIFY( c6 != c3 ); + VERIFY( c7 != c4 ); + int_type c8 = strb_01.sgetc(); + int_type c9 = strb_02.sgetc(); + VERIFY( c6 == c8 ); + VERIFY( c7 == c9 ); + c5 = strb_03.sgetc(); + VERIFY( c5 == traits_type::eof() ); +} + +int main() +{ + test04(); + return 0; +} + + + +// more candy!!! diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/sgetn/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sgetn/wchar_t/1.cc new file mode 100644 index 00000000000..e03806831b3 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sgetn/wchar_t/1.cc @@ -0,0 +1,109 @@ +// 981208 bkoz test functionality of basic_stringbuf 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 + +std::wstring str_01(L"mykonos. . . or what?"); +std::wstring str_02(L"paris, or sainte-maxime?"); +std::wstring str_03; +std::wstringbuf strb_01(str_01); +std::wstringbuf strb_02(str_02, std::ios_base::in); +std::wstringbuf strb_03(str_03, std::ios_base::out); + +// test overloaded virtual functions +void test04() +{ + bool test __attribute__((unused)) = true; + std::wstring str_tmp; + std::wstringbuf strb_tmp; + std::streamsize strmsz_1, strmsz_2; + std::streamoff strmof_1(-1), strmof_2; + typedef std::wstringbuf::int_type int_type; + typedef std::wstringbuf::traits_type traits_type; + typedef std::wstringbuf::pos_type pos_type; + typedef std::wstringbuf::off_type off_type; + + // GET + strmof_1 = strb_01.in_avail(); + strmof_2 = strb_02.in_avail(); + strmof_1 = strb_03.in_avail(); + + int_type c1 = strb_01.sbumpc(); + int_type c2 = strb_02.sbumpc(); + strb_01.sbumpc(); + int_type c4 = strb_02.sbumpc(); + int_type c5 = strb_03.sbumpc(); + + // int_type sgetc() + // if read_cur not avail, return uflow(), else return *read_cur + int_type c6 = strb_01.sgetc(); + int_type c7 = strb_02.sgetc(); + strb_01.sgetc(); + strb_02.sgetc(); + c5 = strb_03.sgetc(); + + // int_type snextc() + // calls sbumpc and if sbumpc != eof, return sgetc + c6 = strb_01.snextc(); + c7 = strb_02.snextc(); + c5 = strb_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 = strb_01.in_avail(); + strmsz_2 = strb_02.in_avail(); + test = strmsz_1 != strmsz_2; + VERIFY( strmsz_1 != static_cast(str_01.length()) ); + // because now we've moved into string + VERIFY( strmsz_2 != static_cast(str_02.length()) ); + wchar_t carray1[11] = L""; + strmsz_1 = strb_01.sgetn(carray1, 10); + wchar_t carray2[20] = L""; + strmsz_2 = strb_02.sgetn(carray2, 10); + VERIFY( strmsz_1 == strmsz_2 ); + VERIFY( strmsz_1 == 10 ); + c1 = strb_01.sgetc(); + c2 = strb_02.sgetc(); + VERIFY( c6 == c1 ); //just by co-incidence both o's + VERIFY( c7 != c2 ); // n != i + VERIFY( c1 == str_01[13] ); + VERIFY( c2 == str_02[13] ); //should equal fourteenth letter at this point + strmsz_1 = strb_03.sgetn(carray1, 10); + VERIFY( !strmsz_1 ); //zero + strmsz_1 = strb_02.in_avail(); + strmsz_2 = strb_02.sgetn(carray2, strmsz_1 + 5); + VERIFY( strmsz_1 == strmsz_2 ); //write off the end + c4 = strb_02.sgetc(); // should be EOF + VERIFY( c4 == traits_type::eof() ); +} + +int main() +{ + test04(); + return 0; +} + + + +// more candy!!! diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/snextc/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/snextc/wchar_t/1.cc new file mode 100644 index 00000000000..fa82e656594 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/snextc/wchar_t/1.cc @@ -0,0 +1,83 @@ +// 981208 bkoz test functionality of basic_stringbuf 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 + +std::wstring str_01(L"mykonos. . . or what?"); +std::wstring str_02(L"paris, or sainte-maxime?"); +std::wstring str_03; +std::wstringbuf strb_01(str_01); +std::wstringbuf strb_02(str_02, std::ios_base::in); +std::wstringbuf strb_03(str_03, std::ios_base::out); + +// test overloaded virtual functions +void test04() +{ + bool test __attribute__((unused)) = true; + std::wstring str_tmp; + std::wstringbuf strb_tmp; + std::streamoff strmof_1(-1), strmof_2; + typedef std::wstringbuf::int_type int_type; + typedef std::wstringbuf::traits_type traits_type; + typedef std::wstringbuf::pos_type pos_type; + typedef std::wstringbuf::off_type off_type; + + // GET + strmof_1 = strb_01.in_avail(); + strmof_2 = strb_02.in_avail(); + strmof_1 = strb_03.in_avail(); + + strb_01.sbumpc(); + strb_02.sbumpc(); + strb_01.sbumpc(); + strb_02.sbumpc(); + int_type c5 = strb_03.sbumpc(); + + // int_type sgetc() + // if read_cur not avail, return uflow(), else return *read_cur + int_type c6 = strb_01.sgetc(); + int_type c7 = strb_02.sgetc(); + int_type c8 = strb_01.sgetc(); + int_type c9 = strb_02.sgetc(); + c5 = strb_03.sgetc(); + + // int_type snextc() + // calls sbumpc and if sbumpc != eof, return sgetc + c6 = strb_01.snextc(); + c7 = strb_02.snextc(); + VERIFY( c6 != c8 ); + VERIFY( c7 != c9 ); + VERIFY( c6 == str_01[3] ); + VERIFY( c7 == str_02[3] ); //should equal fourth letter at this point + c5 = strb_03.snextc(); + VERIFY( c5 == traits_type::eof() ); +} + +int main() +{ + test04(); + return 0; +} + + + +// more candy!!! diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/sputbackc/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sputbackc/wchar_t/1.cc new file mode 100644 index 00000000000..a6e8ae62379 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sputbackc/wchar_t/1.cc @@ -0,0 +1,120 @@ +// 981208 bkoz test functionality of basic_stringbuf 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 + +std::wstring str_01(L"mykonos. . . or what?"); +std::wstring str_02(L"paris, or sainte-maxime?"); +std::wstring str_03; +std::wstringbuf strb_01(str_01); +std::wstringbuf strb_02(str_02, std::ios_base::in); +std::wstringbuf strb_03(str_03, std::ios_base::out); + +// test overloaded virtual functions +void test04() +{ + bool test __attribute__((unused)) = true; + std::wstring str_tmp, str_tmp2; + std::wstringbuf strb_tmp; + std::streamsize strmsz_1, strmsz_2; + typedef std::wstringbuf::int_type int_type; + typedef std::wstringbuf::traits_type traits_type; + typedef std::wstringbuf::pos_type pos_type; + typedef std::wstringbuf::off_type off_type; + + int_type c1 = strb_01.sbumpc(); + int_type c2 = strb_02.sbumpc(); + int_type c3 = strb_01.sbumpc(); + int_type c4 = strb_02.sbumpc(); + + // PUT + strb_03.str(str_01); //reset + std::wstring::size_type sz1 = strb_03.str().length(); + std::wstring::size_type sz2 = strb_03.str().length(); + + // 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* + str_tmp = strb_03.str(); + sz1 = str_tmp.length(); + strmsz_1 = strb_03.sputn(L"racadabras", 10);//"abracadabras or what?" + sz2 = strb_03.str().length(); + strmsz_2 = strb_03.sputn(L", i wanna reach out and", 10); + sz2 = strb_03.str().length(); + str_tmp = strb_02.str(); + strmsz_1 = strb_02.sputn(L"racadabra", 10); + + // PUTBACK + + // int_type sputbackc(char_type c) + // if in_cur not avail || ! traits::eq(c, gptr() [-1]), return pbfail + // otherwise decrements in_cur and returns *gptr() + strmsz_1 = strb_01.in_avail(); + str_tmp = strb_01.str(); + c1 = strb_01.sgetc(); //"mykonos. . . 'o'r what?" + c2 = strb_01.sputbackc(L'z');//"mykonos. . .zor what?" + c3 = strb_01.sgetc(); + str_tmp2 = strb_01.str(); + VERIFY( c1 != c2 ); + VERIFY( c3 == c2 ); + VERIFY( str_tmp2 == std::wstring(L"mzkonos. . . or what?") ); + VERIFY( str_tmp.size() == str_tmp2.size() ); + //test for _in_cur == _in_beg + strb_01.str(str_tmp); + strmsz_1 = strb_01.in_avail(); + c1 = strb_01.sgetc(); //"'m'ykonos. . . or what?" + c2 = strb_01.sputbackc(L'z');//"mykonos. . . or what?" + c3 = strb_01.sgetc(); + VERIFY( c1 != c2 ); + VERIFY( c3 != c2 ); + VERIFY( c1 == c3 ); + VERIFY( c2 == traits_type::eof() ); + VERIFY( strb_01.str() == str_tmp ); + VERIFY( str_tmp.size() == strb_01.str().size() ); + // test for replacing char with identical one + strb_01.str(str_01); //reset + strmsz_1 = strb_01.in_avail(); + strb_01.sbumpc(); + strb_01.sbumpc(); + c1 = strb_01.sgetc(); //"my'k'onos. . . or what?" + c2 = strb_01.sputbackc(L'y');//"mykonos. . . or what?" + c3 = strb_01.sgetc(); + VERIFY( c1 != c2 ); + VERIFY( c3 == c2 ); + VERIFY( c1 != c3 ); + VERIFY( strb_01.str() == str_01 ); + VERIFY( str_01.size() == strb_01.str().size() ); + //test for ios_base::out + strmsz_2 = strb_03.in_avail(); + c4 = strb_03.sputbackc(L'x'); + VERIFY( c4 == traits_type::eof() ); +} + +int main() +{ + test04(); + return 0; +} + + + +// more candy!!! diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/sputbackc/wchar_t/9425.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sputbackc/wchar_t/9425.cc new file mode 100644 index 00000000000..0ac6d879996 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sputbackc/wchar_t/9425.cc @@ -0,0 +1,43 @@ +// 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 + +// libstdc++/9439, libstdc++/9425 +// basic_filebuf<>::pbackfail calls basic_filebuf<>::seekoff, but +// fails to check the return value +void test09() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + wstringbuf sbuf; + wstringbuf::int_type r = sbuf.sputbackc(L'a'); + VERIFY( r == wstringbuf::traits_type::eof() ); +} + +int main() +{ + test09(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/sputc/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sputc/wchar_t/1.cc new file mode 100644 index 00000000000..2c749711ab4 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sputc/wchar_t/1.cc @@ -0,0 +1,71 @@ +// 981208 bkoz test functionality of basic_stringbuf 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 + +std::wstring str_01(L"mykonos. . . or what?"); +std::wstring str_02(L"paris, or sainte-maxime?"); +std::wstring str_03; +std::wstringbuf strb_01(str_01); +std::wstringbuf strb_02(str_02, std::ios_base::in); +std::wstringbuf strb_03(str_03, std::ios_base::out); + +// test overloaded virtual functions +void test04() +{ + bool test __attribute__((unused)) = true; + std::wstring str_tmp; + std::wstringbuf strb_tmp; + typedef std::wstringbuf::int_type int_type; + typedef std::wstringbuf::traits_type traits_type; + typedef std::wstringbuf::pos_type pos_type; + typedef std::wstringbuf::off_type off_type; + + int_type c1 = strb_01.sbumpc(); + int_type c2 = strb_02.sbumpc(); + int_type c3 = strb_01.sbumpc(); + + // PUT + // int_type sputc(char_type c) + // if out_cur not avail, return overflow. Else, stores c at out_cur, + // increments out_cur, and returns c as int_type + strb_03.str(str_01); //reset + std::wstring::size_type sz1 = strb_03.str().length(); + c1 = strb_03.sputc(L'a'); + std::wstring::size_type sz2 = strb_03.str().length(); + VERIFY( sz1 == sz2 ); //cuz inserting at out_cur, which is at beg to start + c2 = strb_03.sputc(L'b'); + VERIFY( c1 != c2 ); + VERIFY( strb_03.str() != str_01 ); + c3 = strb_02.sputc(L'a'); // should be EOF because this is read-only + VERIFY( c3 == traits_type::eof() ); +} + +int main() +{ + test04(); + return 0; +} + + + +// more candy!!! diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/sputc/wchar_t/1057.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sputc/wchar_t/1057.cc new file mode 100644 index 00000000000..3fb14751a8f --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/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::wstringbuf +{ + 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_stringbuf/sputc/wchar_t/9404-1.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sputc/wchar_t/9404-1.cc new file mode 100644 index 00000000000..d3da54edf6f --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sputc/wchar_t/9404-1.cc @@ -0,0 +1,73 @@ +// 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.7.1.3 Overridden virtual functions + +#include +#include + +bool over_called; + +class Derived_stringbuf : public std::wstringbuf +{ +public: + int_type overflow(int_type c) + { + over_called = true; + return std::wstringbuf::overflow(c); + } + + const char_type* pub_epptr() const + { + return epptr(); + } + + const char_type* pub_pptr() const + { + return pptr(); + } +}; + +// libstdc++/9404 +void test04() +{ + bool test __attribute__((unused)) = true; + + bool over_expected; + + // sputc + Derived_stringbuf dsbuf_01; + over_called = false; + dsbuf_01.sputc(L'i'); + VERIFY( over_called ); + over_expected = dsbuf_01.pub_epptr() == dsbuf_01.pub_pptr(); + over_called = false; + dsbuf_01.sputc(L'v'); + VERIFY( (!over_expected && !over_called) + || (over_expected && over_called) ); + dsbuf_01.sputc(L'i'); + VERIFY( dsbuf_01.str() == L"ivi" ); // Sanity check. +} + +int main() +{ + test04(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/sputn/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sputn/wchar_t/1.cc new file mode 100644 index 00000000000..450c2e70c98 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sputn/wchar_t/1.cc @@ -0,0 +1,80 @@ +// 981208 bkoz test functionality of basic_stringbuf 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 + +std::wstring str_01(L"mykonos. . . or what?"); +std::wstring str_02(L"paris, or sainte-maxime?"); +std::wstring str_03; +std::wstringbuf strb_01(str_01); +std::wstringbuf strb_02(str_02, std::ios_base::in); +std::wstringbuf strb_03(str_03, std::ios_base::out); + +// test overloaded virtual functions +void test04() +{ + bool test __attribute__((unused)) = true; + std::wstring str_tmp; + std::wstringbuf strb_tmp; + std::streamsize strmsz_1, strmsz_2; + typedef std::wstringbuf::int_type int_type; + typedef std::wstringbuf::traits_type traits_type; + typedef std::wstringbuf::pos_type pos_type; + typedef std::wstringbuf::off_type off_type; + + // PUT + strb_03.str(str_01); //reset + std::wstring::size_type sz1 = strb_03.str().length(); + std::wstring::size_type sz2 = strb_03.str().length(); + + // streamsize sputn(const char_type* 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* + str_tmp = strb_03.str(); + sz1 = str_tmp.length(); + strmsz_1 = strb_03.sputn(L"racadabras", 10);//"abracadabras or what?" + sz2 = strb_03.str().length(); + VERIFY( sz1 == sz2 ); //shouldn't have changed length + VERIFY( strmsz_1 == 10 ); + VERIFY( str_tmp != strb_03.str() ); + strmsz_2 = strb_03.sputn(L", i wanna reach out and", 23); + VERIFY( strmsz_1 != strmsz_2 ); // should re-allocate, copy 10 chars. + VERIFY( strmsz_1 == 10 ); + VERIFY( strmsz_2 == 23 ); + sz2 = strb_03.str().length(); + VERIFY( sz1 != sz2 ); // need to change length + VERIFY( str_tmp != strb_03.str() ); + str_tmp = strb_02.str(); + strmsz_1 = strb_02.sputn(L"racadabra", 10); + VERIFY( strmsz_1 == 0 ); + VERIFY( str_tmp == strb_02.str() ); +} + +int main() +{ + test04(); + return 0; +} + + + +// more candy!!! diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/sputn/wchar_t/1057.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sputn/wchar_t/1057.cc new file mode 100644 index 00000000000..7d0b2d56e18 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/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::wstringbuf +{ + 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_stringbuf/sputn/wchar_t/9404-2.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sputn/wchar_t/9404-2.cc new file mode 100644 index 00000000000..1c448d1f3a3 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sputn/wchar_t/9404-2.cc @@ -0,0 +1,73 @@ +// 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.7.1.3 Overridden virtual functions + +#include +#include + +bool over_called; + +class Derived_stringbuf : public std::wstringbuf +{ +public: + int_type overflow(int_type c) + { + over_called = true; + return std::wstringbuf::overflow(c); + } + + const char_type* pub_epptr() const + { + return epptr(); + } + + const char_type* pub_pptr() const + { + return pptr(); + } +}; + +// libstdc++/9404 +void test04() +{ + bool test __attribute__((unused)) = true; + + bool over_expected; + Derived_stringbuf dsbuf_01; + + // sputn + Derived_stringbuf dsbuf_02; + over_called = false; + dsbuf_02.sputn(L"sonne's", 7); + VERIFY( over_called ); + over_expected = dsbuf_02.pub_epptr() == dsbuf_02.pub_pptr(); + over_called = false; + dsbuf_02.sputn(L" peak", 5); + VERIFY( (!over_expected && !over_called) + || (over_expected && over_called) ); + VERIFY( dsbuf_02.str() == L"sonne's peak" ); // Sanity check. +} + +int main() +{ + test04(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/str/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/str/wchar_t/1.cc new file mode 100644 index 00000000000..4c89bc932c7 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/str/wchar_t/1.cc @@ -0,0 +1,74 @@ +// 981208 bkoz test functionality of basic_stringbuf 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 + +std::wstring str_01(L"mykonos. . . or what?"); +std::wstring str_02(L"paris, or sainte-maxime?"); +std::wstring str_03; +std::wstringbuf strb_01(str_01); +std::wstringbuf strb_02(str_02, std::ios_base::in); +std::wstringbuf strb_03(str_03, std::ios_base::out); + +// test member functions +void test03() +{ + bool test __attribute__((unused)) = true; + + // stringbuf::str() + VERIFY( strb_01.str() == str_01 ); + VERIFY( strb_02.str() == str_02 ); + VERIFY( strb_03.str() == str_03 ); + + // stringbuf::str(string&) + strb_03.str(L"none of the above, go to the oberoi in cairo, egypt."); + strb_03.str(str_01); + std::streamsize d1 = strb_01.in_avail(); + std::streamsize d2 = strb_03.in_avail(); + VERIFY( d1 ); // non-zero + VERIFY( !d2 ); // zero, cuz ios_base::out + VERIFY( d1 != d2 ); //these should be the same + VERIFY( static_cast(str_01.length()) == d1 ); + VERIFY( strb_01.str() == strb_03.str() ); //ditto + + // stringbuf::str(string&) and stringbuf::stringbuf(string&), where the + // string in question contains embedded NUL characters. Note that in this + // embedded-NUL situation, the size must be passed to the string ctor. + std::wstring str_nulls(L"eschew \0 obfuscation", 20); // tested in 21_strings + std::wstringbuf strb_normal(str_01); + std::wstringbuf strb_nulls(str_nulls); + strb_normal.str(str_nulls); // tried using 'strb_01' rather than declaring + // another variable, but then test04 broke! + VERIFY( strb_nulls.in_avail() == static_cast(str_nulls.size()) ); + VERIFY( strb_nulls.str().size() == 20 ); + VERIFY( strb_normal.in_avail() == static_cast(str_nulls.size()) ); +} + +int main() +{ + test03(); + return 0; +} + + + +// more candy!!! diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/str/wchar_t/2.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/str/wchar_t/2.cc new file mode 100644 index 00000000000..fafd423b681 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/str/wchar_t/2.cc @@ -0,0 +1,55 @@ +// 981208 bkoz test functionality of basic_stringbuf 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 + +// http://gcc.gnu.org/ml/libstdc++/2003-02/msg00269.html +// Growing and then seeking to ios_base::beg triggered a bug in str(), +// which didn't notice the grow. +void test07() +{ + bool test __attribute__((unused)) = true; + + std::wstringbuf strb_01; + strb_01.sputc(L's'); + strb_01.pubseekoff(0, std::ios_base::beg); + std::wstring tmp = strb_01.str(); + VERIFY( tmp == L"s" ); + + std::wstring str(L"strivi,"); + std::wstringbuf strb_02(str); + strb_02.pubseekoff(0, std::ios_base::end); + strb_02.sputn(L" no better!", 11); + strb_02.pubseekoff(0, std::ios_base::beg); + tmp = strb_02.str(); + VERIFY( tmp == L"strivi, no better!" ); +} + +int main() +{ + test07(); + return 0; +} + + + +// more candy!!! diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/str/wchar_t/3.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/str/wchar_t/3.cc new file mode 100644 index 00000000000..3100de7ecbc --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/str/wchar_t/3.cc @@ -0,0 +1,43 @@ +// 981208 bkoz test functionality of basic_stringbuf 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 + +void test06() +{ + bool test __attribute__((unused)) = true; + + std::wostringstream os (L"foo", std::ios_base::app); + os << L"bar"; + + VERIFY( os.str() == L"foobar" ); +} + +int main() +{ + test06(); + return 0; +} + + + +// more candy!!! diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/str/wchar_t/3955.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/str/wchar_t/3955.cc new file mode 100644 index 00000000000..c638128d0d2 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/str/wchar_t/3955.cc @@ -0,0 +1,44 @@ +// 981208 bkoz test functionality of basic_stringbuf 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 + +// libstdc++/3955 -- ios_base::app overwrites from the beginning +void test05() +{ + bool test __attribute__((unused)) = true; + + std::wostringstream os (L"foo"); + os << L"bar"; + + VERIFY( os.str() == L"bar" ); +} + +int main() +{ + test05(); + return 0; +} + + + +// more candy!!! diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/sungetc/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sungetc/wchar_t/1.cc new file mode 100644 index 00000000000..a25ded4362b --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sungetc/wchar_t/1.cc @@ -0,0 +1,149 @@ +// 981208 bkoz test functionality of basic_stringbuf 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 + +std::wstring str_01(L"mykonos. . . or what?"); +std::wstring str_02(L"paris, or sainte-maxime?"); +std::wstring str_03; +std::wstringbuf strb_01(str_01); +std::wstringbuf strb_02(str_02, std::ios_base::in); +std::wstringbuf strb_03(str_03, std::ios_base::out); + +// test overloaded virtual functions +void test04() +{ + bool test __attribute__((unused)) = true; + std::wstring str_tmp; + std::wstringbuf strb_tmp; + std::streamsize strmsz_1, strmsz_2; + typedef std::wstringbuf::int_type int_type; + typedef std::wstringbuf::traits_type traits_type; + typedef std::wstringbuf::pos_type pos_type; + typedef std::wstringbuf::off_type off_type; + + int_type c1 = strb_01.sbumpc(); + int_type c2 = strb_02.sbumpc(); + int_type c3 = strb_01.sbumpc(); + int_type c4 = strb_02.sbumpc(); + + // PUT + strb_03.str(str_01); //reset + std::wstring::size_type sz1 = strb_03.str().length(); + std::wstring::size_type sz2 = strb_03.str().length(); + + // 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* + str_tmp = strb_03.str(); + sz1 = str_tmp.length(); + strmsz_1 = strb_03.sputn(L"racadabras", 10);//"abracadabras or what?" + sz2 = strb_03.str().length(); + strmsz_2 = strb_03.sputn(L", i wanna reach out and", 10); + sz2 = strb_03.str().length(); + str_tmp = strb_02.str(); + strmsz_1 = strb_02.sputn(L"racadabra", 10); + + // PUTBACK + + // int_type sputbackc(char_type c) + // if in_cur not avail || ! traits::eq(c, gptr() [-1]), return pbfail + // otherwise decrements in_cur and returns *gptr() + strmsz_1 = strb_01.in_avail(); + str_tmp = strb_01.str(); + c1 = strb_01.sgetc(); //"mykonos. . . 'o'r what?" + c2 = strb_01.sputbackc('z');//"mykonos. . .zor what?" + c3 = strb_01.sgetc(); + //test for _in_cur == _in_beg + strb_01.str(str_tmp); + strmsz_1 = strb_01.in_avail(); + c1 = strb_01.sgetc(); //"'m'ykonos. . . or what?" + c2 = strb_01.sputbackc(L'z');//"mykonos. . . or what?" + c3 = strb_01.sgetc(); + // test for replacing char with identical one + strb_01.str(str_01); //reset + strmsz_1 = strb_01.in_avail(); + strb_01.sbumpc(); + strb_01.sbumpc(); + c1 = strb_01.sgetc(); //"my'k'onos. . . or what?" + c2 = strb_01.sputbackc(L'y');//"mykonos. . . or what?" + c3 = strb_01.sgetc(); + //test for ios_base::out + strmsz_2 = strb_03.in_avail(); + c4 = strb_03.sputbackc(L'x'); + + // int_type sungetc() + // if in_cur not avail, return pbackfail(), else decrement and + // return to_int_type(*gptr()) + for (int i = 0; i<12; ++i) + strb_01.sbumpc(); + strmsz_1 = strb_01.in_avail(); + str_tmp = strb_01.str(); + c1 = strb_01.sgetc(); //"mykonos. . . 'o'r what?" + c2 = strb_01.sungetc();//"mykonos. . . or what?" + c3 = strb_01.sgetc(); + VERIFY( c1 != c2 ); + VERIFY( c3 == c2 ); + VERIFY( c1 != c3 ); + VERIFY( c2 == L' ' ); + VERIFY( strb_01.str() == str_01 ); + VERIFY( str_01.size() == strb_01.str().size() ); + //test for _in_cur == _in_beg + strb_01.str(str_tmp); + strmsz_1 = strb_01.in_avail(); + c1 = strb_01.sgetc(); //"'m'ykonos. . . or what?" + c2 = strb_01.sungetc();//"mykonos. . . or what?" + c3 = strb_01.sgetc(); + VERIFY( c1 != c2 ); + VERIFY( c3 != c2 ); + VERIFY( c1 == c3 ); + VERIFY( c2 == traits_type::eof() ); + VERIFY( strb_01.str() == str_01 ); + VERIFY( str_01.size() == strb_01.str().size() ); + // test for replacing char with identical one + strb_01.str(str_01); //reset + strmsz_1 = strb_01.in_avail(); + strb_01.sbumpc(); + strb_01.sbumpc(); + c1 = strb_01.sgetc(); //"my'k'onos. . . or what?" + c2 = strb_01.sungetc();//"mykonos. . . or what?" + c3 = strb_01.sgetc(); + VERIFY( c1 != c2 ); + VERIFY( c3 == c2 ); + VERIFY( c1 != c3 ); + VERIFY( strb_01.str() == str_01 ); + VERIFY( str_01.size() == strb_01.str().size() ); + //test for ios_base::out + strmsz_2 = strb_03.in_avail(); + c4 = strb_03.sungetc(); + VERIFY( c4 == traits_type::eof() ); +} + +int main() +{ + test04(); + return 0; +} + + + +// more candy!!! diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/sync/wchar_t/1057.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sync/wchar_t/1057.cc new file mode 100644 index 00000000000..c84e3318d90 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sync/wchar_t/1057.cc @@ -0,0 +1,109 @@ +// 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 setpbuf : public std::wstringbuf +{ + 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