diff options
author | upstream source tree <ports@midipix.org> | 2015-03-15 20:14:05 -0400 |
---|---|---|
committer | upstream source tree <ports@midipix.org> | 2015-03-15 20:14:05 -0400 |
commit | 554fd8c5195424bdbcabf5de30fdc183aba391bd (patch) | |
tree | 976dc5ab7fddf506dadce60ae936f43f58787092 /libstdc++-v3/testsuite/27_io/basic_stringbuf | |
download | cbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.bz2 cbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.xz |
obtained gcc-4.6.4.tar.bz2 from upstream website;upstream
verified gcc-4.6.4.tar.bz2.sig;
imported gcc-4.6.4 source tree from verified upstream tarball.
downloading a git-generated archive based on the 'upstream' tag
should provide you with a source tree that is binary identical
to the one extracted from the above tarball.
if you have obtained the source via the command 'git clone',
however, do note that line-endings of files in your working
directory might differ from line-endings of the respective
files in the upstream repository.
Diffstat (limited to 'libstdc++-v3/testsuite/27_io/basic_stringbuf')
90 files changed, 5751 insertions, 0 deletions
diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/cons/2020.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/cons/2020.cc new file mode 100644 index 000000000..aa4c669cb --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/cons/2020.cc @@ -0,0 +1,52 @@ +// 1999-01-17 bkoz test functionality of basic_filebuf for char_type == char + +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2009 +// 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.7.1 - Template class basic_stringbuf +// NB: This file is for testing basic_filebuf with NO OTHER INCLUDES. + +#include <sstream> +#include <testsuite_hooks.h> +#include <testsuite_character.h> + +// libstdc++/2020 +// should be able to use custom char_type, custom traits type +void test07() +{ + bool test __attribute__((unused)) = true; + typedef std::basic_stringbuf<__gnu_test::pod_ushort> gnu_ssbuf; + + try + { gnu_ssbuf obj; } + catch(std::exception& obj) + { + test = false; + VERIFY( test ); + } +} + +int main() +{ + test07(); + return 0; +} + + + +// more surf!!! diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/cons/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/cons/char/1.cc new file mode 100644 index 000000000..d2bfe7a9c --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/cons/char/1.cc @@ -0,0 +1,39 @@ +// 2004-09-29 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2004, 2009 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.7.1.1 basic_stringbuf constructors [lib.stringbuf.cons] + +#include <sstream> +#include <testsuite_hooks.h> +#include <testsuite_io.h> + +// http://gcc.gnu.org/ml/libstdc++/2004-09/msg00243.html +void test01() +{ + bool test __attribute__((unused)) = true; + + __gnu_test::constraint_stringbuf sbuf; + VERIFY( sbuf.check_pointers() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/cons/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/cons/wchar_t/1.cc new file mode 100644 index 000000000..ba512f98f --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/cons/wchar_t/1.cc @@ -0,0 +1,39 @@ +// 2004-09-29 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2004, 2009 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.7.1.1 basic_stringbuf constructors [lib.stringbuf.cons] + +#include <sstream> +#include <testsuite_hooks.h> +#include <testsuite_io.h> + +// http://gcc.gnu.org/ml/libstdc++/2004-09/msg00243.html +void test01() +{ + bool test __attribute__((unused)) = true; + + __gnu_test::constraint_wstringbuf sbuf; + VERIFY( sbuf.check_pointers() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/imbue/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/imbue/char/1.cc new file mode 100644 index 000000000..6fe9c64aa --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/imbue/char/1.cc @@ -0,0 +1,47 @@ +// 981208 bkoz test functionality of basic_stringbuf for char_type == char + +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2009 +// 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <sstream> +#include <testsuite_hooks.h> + +std::string str_01("mykonos. . . or what?"); +std::stringbuf strb_01(str_01); + +// test the streambuf/stringbuf locale settings +void test02() +{ + bool test __attribute__((unused)) = true; + + 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/char/9322.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/imbue/char/9322.cc new file mode 100644 index 000000000..bfc864351 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/imbue/char/9322.cc @@ -0,0 +1,55 @@ +// { dg-require-namedlocale "en_US" } +// { dg-require-namedlocale "de_DE" } + +// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2005, 2009 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.7.1.3 Overridden virtual functions + +#include <sstream> +#include <testsuite_hooks.h> + +// libstdc++/9322 +void test03() +{ + using std::locale; + bool test __attribute__((unused)) = true; + + locale loc = std::locale::classic(); + std::stringbuf ob; + VERIFY( ob.getloc() == loc ); + + locale::global(locale("en_US")); + VERIFY( ob.getloc() == loc ); + + locale loc_de = 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/imbue/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/imbue/wchar_t/1.cc new file mode 100644 index 000000000..a3f4fac51 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/imbue/wchar_t/1.cc @@ -0,0 +1,47 @@ +// 981208 bkoz test functionality of basic_stringbuf for char_type == wchar_t + +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2009 +// 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <sstream> +#include <testsuite_hooks.h> + +std::wstring str_01(L"mykonos. . . or what?"); +std::wstringbuf strb_01(str_01); + +// test the streambuf/stringbuf locale settings +void test02() +{ + bool test __attribute__((unused)) = true; + + 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 000000000..7182fd912 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/imbue/wchar_t/9322.cc @@ -0,0 +1,56 @@ +// { dg-require-namedlocale "en_US" } +// { dg-require-namedlocale "de_DE" } + +// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2009 +// 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.7.1.3 Overridden virtual functions + +#include <sstream> +#include <testsuite_hooks.h> + +// 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(locale("en_US")); + VERIFY( ob.getloc() == loc ); + + locale loc_de = 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/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/in_avail/char/1.cc new file mode 100644 index 000000000..2925b8447 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/in_avail/char/1.cc @@ -0,0 +1,57 @@ +// 981208 bkoz test functionality of basic_stringbuf for char_type == char + +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2009 +// 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <sstream> +#include <testsuite_hooks.h> + +std::string str_01("mykonos. . . or what?"); +std::string str_02("paris, or sainte-maxime?"); +std::string str_03; +std::stringbuf strb_01(str_01); +std::stringbuf strb_02(str_02, std::ios_base::in); +std::stringbuf strb_03(str_03, std::ios_base::out); + +// test overloaded virtual functions +void test04() +{ + bool test __attribute__((unused)) = true; + std::streamoff strmof_1(-1), strmof_2; + + // 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<std::streamoff>(str_01.length()) ); + VERIFY( strmof_2 == static_cast<std::streamoff>(str_02.length()) ); + strmof_1 = strb_03.in_avail(); + // zero cuz write-only, or eof() to match basic_filebuf + VERIFY( strmof_1 == -1 ); +} + +int main() +{ + test04(); + return 0; +} + + + +// more candy!!! diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/in_avail/char/21955.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/in_avail/char/21955.cc new file mode 100644 index 000000000..8fa7044ff --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/in_avail/char/21955.cc @@ -0,0 +1,53 @@ +// 2005-06-07 Benjamin Kosnik + +// Copyright (C) 2005, 2006, 2009 +// 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <sstream> +#include <testsuite_hooks.h> +#include <stdexcept> + +double +test_stringstream() +{ + double result; + const char* source = "1918"; + std::stringstream s; + s << source; + + std::string tmp = s.str(); + std::streambuf* sb = s.rdbuf(); + int i = sb->in_avail(); + + if (i) + { + s >> result; + } + else + { + throw std::runtime_error("conversion failed"); + } + return result; +} + + +int main () +{ + test_stringstream(); + 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 000000000..1700f3a82 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/in_avail/wchar_t/1.cc @@ -0,0 +1,57 @@ +// 981208 bkoz test functionality of basic_stringbuf for char_type == wchar_t + +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2009 +// 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <sstream> +#include <testsuite_hooks.h> + +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::streamoff strmof_1(-1), strmof_2; + + // 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<std::streamoff>(str_01.length()) ); + VERIFY( strmof_2 == static_cast<std::streamoff>(str_02.length()) ); + strmof_1 = strb_03.in_avail(); + // zero cuz write-only, or eof() to match basic_filebuf + VERIFY( strmof_1 == -1 ); +} + +int main() +{ + test04(); + return 0; +} + + + +// more candy!!! diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/overflow/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/overflow/char/1.cc new file mode 100644 index 000000000..cdf84ef91 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/overflow/char/1.cc @@ -0,0 +1,62 @@ +// 2004-07-07 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2004, 2009 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.7.1.3 basic_stringbuf overridden virtual functions. + +#include <sstream> +#include <cstdlib> +#include <testsuite_hooks.h> + +using namespace std; + +string +data(unsigned len) +{ + string ret; + for (unsigned i = 0; i < len; ++i) + ret.push_back('a' + rand() % 26); + return ret; +} + +void +test01(unsigned iter) +{ + bool test __attribute__((unused)) = true; + + for (unsigned n = 1; n <= iter; n *= 10) + { + const string str = data(n); + stringbuf sstr; + for (unsigned i = 0; i < n; ++i) + sstr.sputc(str[i]); + VERIFY( str == sstr.str() ); + } +} + +// This can take long on simulators, timing out the test. +// { dg-options "-DITERATIONS=10000" { target simulator } } +#ifndef ITERATIONS +#define ITERATIONS 10000000 +#endif + +int main() +{ + test01(ITERATIONS); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/overflow/char/2.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/overflow/char/2.cc new file mode 100644 index 000000000..3328e5520 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/overflow/char/2.cc @@ -0,0 +1,72 @@ +// 1999-10-11 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2009 +// 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +// 27.5.2 template class basic_streambuf + +#include <sstream> +#include <ostream> +#include <testsuite_hooks.h> + +// test03 +// http://gcc.gnu.org/ml/libstdc++/2000-q1/msg00151.html +template<typename charT, typename traits = std::char_traits<charT> > + class basic_nullbuf : public std::basic_stringbuf<charT, traits> + { + protected: + typedef typename + std::basic_stringbuf<charT, traits>::int_type int_type; + virtual int_type + overflow(int_type c) + { return traits::not_eof(c); } + }; + +typedef basic_nullbuf<char> nullbuf; + +template<typename T> + char + print(const T& x) + { + nullbuf ob; + std::ostream out(&ob); + out << x << std::endl; + return (!out ? '0' : '1'); + } + +void test03() +{ + bool test __attribute__((unused)) = true; + const std::string control01("11111"); + std::string test01; + + test01 += print(true); + test01 += print(3.14159); + test01 += print(10); + test01 += print('x'); + test01 += print("pipo"); + + VERIFY( test01 == control01 ); +} + +int main() +{ + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/overflow/char/26250.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/overflow/char/26250.cc new file mode 100644 index 000000000..a16fabc8c --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/overflow/char/26250.cc @@ -0,0 +1,57 @@ +// Copyright (C) 2006, 2009 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.8.1.4 Overridden virtual functions + +#include <sstream> +#include <testsuite_hooks.h> + +struct pubbuf +: std::stringbuf +{ + using std::stringbuf::eback; + using std::stringbuf::egptr; + using std::stringbuf::pbase; + using std::stringbuf::pptr; + using std::stringbuf::epptr; + using std::stringbuf::overflow; +}; + +// libstdc++/26250 +void test01() +{ + bool test __attribute__((unused)) = true; + + pubbuf buf; + + VERIFY( buf.overflow('x') == 'x' ); + VERIFY( buf.pptr() - buf.pbase() == 1 ); + + // not required but good for efficiency + // NB: we are implementing DR 169 and DR 432 + const int write_positions = buf.epptr() - buf.pbase(); + VERIFY( write_positions > 1 ); + + // 27.7.1.3, p8: + VERIFY( buf.egptr() - buf.eback() == 1 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/overflow/char/3599.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/overflow/char/3599.cc new file mode 100644 index 000000000..b9d86a6ec --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/overflow/char/3599.cc @@ -0,0 +1,58 @@ +// 1999-10-11 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2009 +// 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <sstream> +#include <ostream> +#include <testsuite_hooks.h> + +// libstdc++/3599 +class testbuf : public std::stringbuf +{ +public: + typedef std::stringbuf::traits_type traits_type; + + testbuf() : std::stringbuf() { } + +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::ostream out(&ob); + + out << "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/char/9988.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/overflow/char/9988.cc new file mode 100644 index 000000000..cf1653073 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/overflow/char/9988.cc @@ -0,0 +1,62 @@ +// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2009 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.8.1.4 Overridden virtual functions + +#include <sstream> +#include <testsuite_hooks.h> + +class OverBuf : public std::stringbuf +{ +public: + int_type pub_overflow(int_type c = traits_type::eof()) + { return std::stringbuf::overflow(c); } +}; + +// libstdc++/9988 +// filebuf::overflow writes EOF to file +void test15() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + OverBuf sb; + + sb.sputc('a'); + sb.pub_overflow('b'); + sb.pub_overflow(); + sb.sputc('c'); + + stringbuf sbin(sb.str(), ios_base::in); + stringbuf::int_type c; + c = sbin.sbumpc(); + VERIFY( c == 'a' ); + c = sbin.sbumpc(); + VERIFY( c == 'b' ); + c = sbin.sbumpc(); + VERIFY( c == 'c' ); + c = sbin.sbumpc(); + VERIFY( c == stringbuf::traits_type::eof() ); +} + +int main() +{ + test15(); + return 0; +} 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 000000000..0d3ea89e8 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/overflow/wchar_t/1.cc @@ -0,0 +1,56 @@ +// 2004-07-07 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2004, 2009 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.7.1.3 basic_stringbuf overridden virtual functions. + +#include <sstream> +#include <cstdlib> +#include <testsuite_hooks.h> + +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 000000000..ff5c00744 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/overflow/wchar_t/2.cc @@ -0,0 +1,72 @@ +// 1999-10-11 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2009 +// 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +// 27.5.2 template class basic_streambuf + +#include <sstream> +#include <ostream> +#include <testsuite_hooks.h> + +// test03 +// http://gcc.gnu.org/ml/libstdc++/2000-q1/msg00151.html +template<typename charT, typename traits = std::char_traits<charT> > + class basic_nullbuf : public std::basic_stringbuf<charT, traits> + { + protected: + typedef typename + std::basic_stringbuf<charT, traits>::int_type int_type; + virtual int_type + overflow(int_type c) + { return traits::not_eof(c); } + }; + +typedef basic_nullbuf<wchar_t> nullbuf; + +template<typename T> + 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/26250.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/overflow/wchar_t/26250.cc new file mode 100644 index 000000000..152b54912 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/overflow/wchar_t/26250.cc @@ -0,0 +1,57 @@ +// Copyright (C) 2006, 2009 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.8.1.4 Overridden virtual functions + +#include <sstream> +#include <testsuite_hooks.h> + +struct pubbuf +: std::wstringbuf +{ + using std::wstringbuf::eback; + using std::wstringbuf::egptr; + using std::wstringbuf::pbase; + using std::wstringbuf::pptr; + using std::wstringbuf::epptr; + using std::wstringbuf::overflow; +}; + +// libstdc++/26250 +void test01() +{ + bool test __attribute__((unused)) = true; + + pubbuf buf; + + VERIFY( buf.overflow(L'x') == L'x' ); + VERIFY( buf.pptr() - buf.pbase() == 1 ); + + // not required but good for efficiency + // NB: we are implementing DR 169 and DR 432 + const int write_positions = buf.epptr() - buf.pbase(); + VERIFY( write_positions > 1 ); + + // 27.7.1.3, p8: + VERIFY( buf.egptr() - buf.eback() == 1 ); +} + +int main() +{ + test01(); + 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 000000000..54c33f425 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/overflow/wchar_t/3599.cc @@ -0,0 +1,58 @@ +// 1999-10-11 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2009 +// 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <sstream> +#include <ostream> +#include <testsuite_hooks.h> + +// 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 000000000..e0d51b91b --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/overflow/wchar_t/9988.cc @@ -0,0 +1,62 @@ +// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2004, 2009 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.8.1.4 Overridden virtual functions + +#include <sstream> +#include <testsuite_hooks.h> + +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/pbackfail/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/pbackfail/char/1.cc new file mode 100644 index 000000000..a8be7b69a --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/pbackfail/char/1.cc @@ -0,0 +1,75 @@ +// 2004-10-01 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2004, 2009 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.7.1.3 Overridden virtual functions [lib.stringbuf.virtuals] + +#include <sstream> +#include <testsuite_hooks.h> + +class my_stringbuf : public std::stringbuf +{ +public: + my_stringbuf(const std::string& str, std::ios_base::openmode mode) + : std::stringbuf(str, mode) { } + + int_type + pub_pbackfail(int_type c) + { return this->pbackfail(c); } +}; + +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + typedef my_stringbuf::int_type int_type; + typedef my_stringbuf::traits_type traits_type; + + my_stringbuf sbuf("any", ios_base::in | ios_base::out); + + int_type c = sbuf.sgetc(); + VERIFY( c == 'a' ); + + c = sbuf.pub_pbackfail('z'); + VERIFY( c == traits_type::eof() ); + c = sbuf.sbumpc(); + VERIFY( c == 'a' ); + + c = sbuf.pub_pbackfail('a'); + VERIFY( c == 'a' ); + c = sbuf.sbumpc(); + VERIFY( c == 'a' ); + + c = sbuf.pub_pbackfail('x'); + VERIFY( c == 'x' ); + c = sbuf.sbumpc(); + VERIFY( c == 'x' ); + + const int_type eof = traits_type::eof(); + c = sbuf.pub_pbackfail(eof); + VERIFY( c == traits_type::not_eof(eof) ); + c = sbuf.sgetc(); + VERIFY( c == 'x' ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/pbackfail/char/2.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/pbackfail/char/2.cc new file mode 100644 index 000000000..abe8bb0e7 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/pbackfail/char/2.cc @@ -0,0 +1,63 @@ +// 2004-10-01 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2004, 2009 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.7.1.3 Overridden virtual functions [lib.stringbuf.virtuals] + +#include <sstream> +#include <testsuite_hooks.h> + +class my_stringbuf : public std::stringbuf +{ +public: + my_stringbuf(const std::string& str, std::ios_base::openmode mode) + : std::stringbuf(str, mode) { } + + int_type + pub_pbackfail(int_type __c) + { return this->pbackfail(__c); } +}; + +// We weren't enforcing 27.7.1.3/2, bullet 2: "... and if +// mode & ios_base::out is nonzero, ..." +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + typedef my_stringbuf::int_type int_type; + typedef my_stringbuf::traits_type traits_type; + + my_stringbuf sbuf("any", ios_base::in); + + int_type c = sbuf.sbumpc(); + VERIFY( c == 'a' ); + + c = sbuf.pub_pbackfail('x'); + VERIFY( c == traits_type::eof() ); + VERIFY( sbuf.str() == "any" ); + c = sbuf.sgetc(); + VERIFY( c == 'n' ); +} + + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/pbackfail/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/pbackfail/wchar_t/1.cc new file mode 100644 index 000000000..9854db5c6 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/pbackfail/wchar_t/1.cc @@ -0,0 +1,75 @@ +// 2004-10-01 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2004, 2009 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.7.1.3 Overridden virtual functions [lib.stringbuf.virtuals] + +#include <sstream> +#include <testsuite_hooks.h> + +class my_stringbuf : public std::wstringbuf +{ +public: + my_stringbuf(const std::wstring& str, std::ios_base::openmode mode) + : std::wstringbuf(str, mode) { } + + int_type + pub_pbackfail(int_type c) + { return this->pbackfail(c); } +}; + +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + typedef my_stringbuf::int_type int_type; + typedef my_stringbuf::traits_type traits_type; + + my_stringbuf sbuf(L"any", ios_base::in | ios_base::out); + + int_type c = sbuf.sgetc(); + VERIFY( c == L'a' ); + + c = sbuf.pub_pbackfail(L'z'); + VERIFY( c == traits_type::eof() ); + c = sbuf.sbumpc(); + VERIFY( c == L'a' ); + + c = sbuf.pub_pbackfail(L'a'); + VERIFY( c == L'a' ); + c = sbuf.sbumpc(); + VERIFY( c == L'a' ); + + c = sbuf.pub_pbackfail(L'x'); + VERIFY( c == L'x' ); + c = sbuf.sbumpc(); + VERIFY( c == L'x' ); + + const int_type eof = traits_type::eof(); + c = sbuf.pub_pbackfail(eof); + VERIFY( c == traits_type::not_eof(eof) ); + c = sbuf.sgetc(); + VERIFY( c == L'x' ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/pbackfail/wchar_t/2.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/pbackfail/wchar_t/2.cc new file mode 100644 index 000000000..7063b7d27 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/pbackfail/wchar_t/2.cc @@ -0,0 +1,63 @@ +// 2004-10-01 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2004, 2009 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.7.1.3 Overridden virtual functions [lib.stringbuf.virtuals] + +#include <sstream> +#include <testsuite_hooks.h> + +class my_stringbuf : public std::wstringbuf +{ +public: + my_stringbuf(const std::wstring& str, std::ios_base::openmode mode) + : std::wstringbuf(str, mode) { } + + int_type + pub_pbackfail(int_type __c) + { return this->pbackfail(__c); } +}; + +// We weren't enforcing 27.7.1.3/2, bullet 2: "... and if +// mode & ios_base::out is nonzero, ..." +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + typedef my_stringbuf::int_type int_type; + typedef my_stringbuf::traits_type traits_type; + + my_stringbuf sbuf(L"any", ios_base::in); + + int_type c = sbuf.sbumpc(); + VERIFY( c == L'a' ); + + c = sbuf.pub_pbackfail(L'x'); + VERIFY( c == traits_type::eof() ); + VERIFY( sbuf.str() == L"any" ); + c = sbuf.sgetc(); + VERIFY( c == L'n' ); +} + + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/requirements/base_classes.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/requirements/base_classes.cc new file mode 100644 index 000000000..0d33d4e82 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/requirements/base_classes.cc @@ -0,0 +1,43 @@ +// { dg-do compile } +// 2003-03-26 B enjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2003, 2009 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.7.1 - Template class basic_stringbuf + +#include <sstream> + +void test01() +{ + // Check for required base class. + typedef std::stringbuf test_type; + typedef std::streambuf base_type; + const test_type& obj = *new test_type(); + const base_type* base __attribute__((unused)) = &obj; +} + +// more surf!!! + + + + + + + + + diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/requirements/explicit_instantiation/2.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/requirements/explicit_instantiation/2.cc new file mode 100644 index 000000000..681757b95 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/requirements/explicit_instantiation/2.cc @@ -0,0 +1,49 @@ +// { dg-do compile } +// 1999-01-17 bkoz test functionality of basic_filebuf for char_type == char + +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2009 +// 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.7.1 - Template class basic_stringbuf +// NB: This file is for testing basic_filebuf with NO OTHER INCLUDES. + +#include <sstream> +#include <testsuite_hooks.h> +#include <testsuite_character.h> + +// test05 +// libstdc++/1886 +// should be able to instantiate basic_stringbuf for non-standard types. +namespace std +{ + using __gnu_test::pod_char; + typedef short type_t; + template class basic_stringbuf<type_t, char_traits<type_t> >; + template class basic_stringbuf<pod_char, char_traits<pod_char> >; +} // std + +// more surf!!! + + + + + + + + + diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/requirements/explicit_instantiation/4.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/requirements/explicit_instantiation/4.cc new file mode 100644 index 000000000..8477035e3 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/requirements/explicit_instantiation/4.cc @@ -0,0 +1,45 @@ +// { dg-do compile } +// 2003-04-07 bkoz + +// Copyright (C) 2003, 2004, 2005, 2009 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.7.1 - Template class basic_stringbuf +// NB: This file is for testing basic_filebuf with NO OTHER INCLUDES. + +#include <sstream> +#include <testsuite_hooks.h> +#include <testsuite_allocator.h> +#include <testsuite_character.h> + +namespace std +{ + using __gnu_test::pod_char; + typedef __gnu_test::tracker_allocator<char> alloc_type; + template class basic_stringbuf<char, char_traits<char>, alloc_type>; +} // test + +// more surf!!! + + + + + + + + + diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/requirements/typedefs.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/requirements/typedefs.cc new file mode 100644 index 000000000..0039f96a5 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/requirements/typedefs.cc @@ -0,0 +1,38 @@ +// { dg-do compile } +// 2002-07-25 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2002, 2003, 2009 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +// 27.7.1 - Template class basic_stringbuf +// NB: This file is for testing basic_stringbuf with NO OTHER INCLUDES. + +#include <sstream> +#include <testsuite_hooks.h> + +// libstdc++/7216 +void test01() +{ + // Check for required typedefs + typedef std::stringbuf test_type; + typedef test_type::char_type char_type; + typedef test_type::traits_type traits_type; + typedef test_type::int_type int_type; + typedef test_type::pos_type pos_type; + typedef test_type::off_type off_type; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/sbumpc/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sbumpc/char/1.cc new file mode 100644 index 000000000..f60911bdc --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sbumpc/char/1.cc @@ -0,0 +1,68 @@ +// 981208 bkoz test functionality of basic_stringbuf for char_type == char + +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, +// 2006, 2007, 2009, 2010 +// 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <sstream> +#include <testsuite_hooks.h> + +std::string str_01("mykonos. . . or what?"); +std::string str_02("paris, or sainte-maxime?"); +std::string str_03; +std::stringbuf strb_01(str_01); +std::stringbuf strb_02(str_02, std::ios_base::in); +std::stringbuf strb_03(str_03, std::ios_base::out); + +// test overloaded virtual functions +void test04() +{ + bool test __attribute__((unused)) = true; + typedef std::stringbuf::int_type int_type; + typedef std::stringbuf::traits_type traits_type; + + // GET + strb_01.in_avail(); + strb_02.in_avail(); + 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 == traits_type::to_int_type(str_01[0]) ); + VERIFY( c2 == traits_type::to_int_type(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/char/9825.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sbumpc/char/9825.cc new file mode 100644 index 000000000..bd4c41129 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sbumpc/char/9825.cc @@ -0,0 +1,49 @@ +// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2009 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.8.1.4 Overridden virtual functions + +#include <sstream> +#include <testsuite_hooks.h> + +// libstdc++/9825 +// filebuf::sputbackc breaks sbumpc +void test12() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + stringbuf sbuf; + sbuf.sputn("crazy bees!", 11); + sbuf.pubseekoff(0, ios_base::beg); + sbuf.sbumpc(); + sbuf.sputbackc('x'); + stringbuf::int_type c = sbuf.sbumpc(); + VERIFY( c == 'x' ); + c = sbuf.sbumpc(); + VERIFY( c == 'r' ); + c = sbuf.sbumpc(); + VERIFY( c == 'a' ); +} + +int main() +{ + test12(); + 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 000000000..3ec279a19 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sbumpc/wchar_t/1.cc @@ -0,0 +1,67 @@ +// 981208 bkoz test functionality of basic_stringbuf for char_type == wchar_t + +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2009, 2010 +// 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <sstream> +#include <testsuite_hooks.h> + +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; + typedef std::wstringbuf::int_type int_type; + typedef std::wstringbuf::traits_type traits_type; + + // GET + strb_01.in_avail(); + strb_02.in_avail(); + 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 == traits_type::to_int_type(str_01[0]) ); + VERIFY( c2 == traits_type::to_int_type(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 000000000..93ca56f09 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sbumpc/wchar_t/9825.cc @@ -0,0 +1,49 @@ +// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2004, 2009 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.8.1.4 Overridden virtual functions + +#include <sstream> +#include <testsuite_hooks.h> + +// 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/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekoff/char/1.cc new file mode 100644 index 000000000..142cde9c7 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekoff/char/1.cc @@ -0,0 +1,110 @@ +// 981208 bkoz test functionality of basic_stringbuf for char_type == char + +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2009, 2010 +// 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <sstream> +#include <testsuite_hooks.h> + +std::string str_01("mykonos. . . or what?"); +std::stringbuf strb_01(str_01); + +// test overloaded virtual functions +void test04() +{ + bool test __attribute__((unused)) = true; + std::string str_tmp; + std::streamsize strmsz_1, strmsz_2; + typedef std::stringbuf::int_type int_type; + typedef std::stringbuf::traits_type traits_type; + typedef std::stringbuf::pos_type pos_type; + typedef std::stringbuf::off_type off_type; + + int_type c1 = strb_01.sbumpc(); + int_type c2; + + // 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?"); + + //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 == 'o' ); + c2 = strb_01.sputc('x'); //test current out pointer + str_tmp = std::string("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 == ' ' ); + c2 = strb_01.sputc('x'); //test current out pointer + str_tmp = std::string("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 + 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(" ravi shankar meets carlos santana in LoHa", 90); + strb_01.pubseekoff(0, std::ios_base::end); + strb_01.sputc('<'); + str_tmp = strb_01.str(); + VERIFY(static_cast<std::streamsize>(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/char/10975.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekoff/char/10975.cc new file mode 100644 index 000000000..9638f788c --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekoff/char/10975.cc @@ -0,0 +1,56 @@ +// 2004-09-30 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2004, 2009 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.7.1.3 Overridden virtual functions + +#include <sstream> +#include <testsuite_hooks.h> + +// libstdc++/10975 +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + typedef streambuf::pos_type pos_type; + typedef streambuf::off_type off_type; + + const pos_type good = pos_type(off_type(0)); + const pos_type bad = pos_type(off_type(-1)); + pos_type p; + + stringbuf sbuf; + + p = sbuf.pubseekoff(0, ios_base::cur, ios_base::in); + VERIFY( p == good ); + + p = sbuf.pubseekoff(0, ios_base::beg, ios_base::out); + VERIFY( p == good ); + + p = sbuf.pubseekoff(0, ios_base::end); + VERIFY( p == good ); + + p = sbuf.pubseekoff(0, ios_base::cur); + VERIFY( p == bad ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekoff/char/16956.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekoff/char/16956.cc new file mode 100644 index 000000000..724a12d2d --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekoff/char/16956.cc @@ -0,0 +1,60 @@ +// 2004-08-12 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2004, 2009 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.7.1.3 Overridden virtual functions + +#include <sstream> +#include <testsuite_hooks.h> + +// libstdc++/16956 +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + typedef stringbuf::int_type int_type; + typedef stringbuf::traits_type traits_type; + typedef stringbuf::pos_type pos_type; + typedef stringbuf::off_type off_type; + + stringbuf strb_01("lara's place", ios_base::in); + pos_type pt_1 = strb_01.pubseekoff(5, ios_base::cur, ios_base::in); + int_type c1 = strb_01.sgetc(); + VERIFY( c1 != traits_type::eof() ); + pos_type pt_2 = strb_01.pubseekoff(2, ios_base::cur, ios_base::in); + pos_type pt_3 = strb_01.pubseekpos(pt_1, ios_base::in); + int_type c2 = strb_01.sbumpc(); + VERIFY( off_type(pt_3) == off_type(pt_2) - 2 ); + VERIFY( c2 == c1 ); + + stringbuf strb_02("-", ios_base::out); + pos_type pt_4 = strb_02.pubseekoff(0, ios_base::cur, ios_base::out); + strb_02.sputn("red", 3); + pos_type pt_5 = strb_02.pubseekoff(-3, ios_base::cur, ios_base::out); + strb_02.pubseekpos(pt_5, ios_base::out); + VERIFY( off_type(pt_5) == off_type(pt_4) ); + strb_02.sputn("blu", 3); + VERIFY( strb_02.str() == "blu" ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekoff/char/2.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekoff/char/2.cc new file mode 100644 index 000000000..a1d05d72a --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekoff/char/2.cc @@ -0,0 +1,58 @@ +// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2009 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.7.1.3 Overridden virtual functions + +#include <sstream> +#include <testsuite_hooks.h> + +void test02(std::stringbuf& in, bool pass) +{ + bool test __attribute__((unused)) = true; + using namespace std; + typedef streambuf::pos_type pos_type; + typedef streambuf::off_type off_type; + pos_type bad = pos_type(off_type(-1)); + pos_type p = 0; + + // seekoff + p = in.pubseekoff(0, ios_base::beg, ios_base::in); + if (pass) + VERIFY( p != bad ); + + p = in.pubseekoff(0, ios_base::beg, ios_base::out); + VERIFY( p == bad ); + + p = in.pubseekoff(0, ios_base::beg); + VERIFY( p == bad ); +} + +int main() +{ + using namespace std; + + // movie star, submarine scientist! + stringbuf in1("Hedy Lamarr", ios_base::in); + stringbuf in2(ios_base::in); + stringbuf in3("", ios_base::in); + test02(in1, true); + test02(in2, false); + test02(in3, false); + 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 000000000..1b0ee5fe5 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekoff/wchar_t/1.cc @@ -0,0 +1,110 @@ +// 981208 bkoz test functionality of basic_stringbuf for char_type == wchar_t + +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2009, 2010 +// 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <sstream> +#include <testsuite_hooks.h> + +std::wstring str_01(L"mykonos. . . or what?"); +std::wstringbuf strb_01(str_01); + +// test overloaded virtual functions +void test04() +{ + bool test __attribute__((unused)) = true; + std::wstring str_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; + + // 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?"); + + //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 + 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<std::streamsize>(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/10975.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekoff/wchar_t/10975.cc new file mode 100644 index 000000000..b83f07e13 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekoff/wchar_t/10975.cc @@ -0,0 +1,56 @@ +// 2004-09-30 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2004, 2009 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.7.1.3 Overridden virtual functions + +#include <sstream> +#include <testsuite_hooks.h> + +// libstdc++/10975 +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + typedef wstreambuf::pos_type pos_type; + typedef wstreambuf::off_type off_type; + + const pos_type good = pos_type(off_type(0)); + const pos_type bad = pos_type(off_type(-1)); + pos_type p; + + wstringbuf sbuf; + + p = sbuf.pubseekoff(0, ios_base::cur, ios_base::in); + VERIFY( p == good ); + + p = sbuf.pubseekoff(0, ios_base::beg, ios_base::out); + VERIFY( p == good ); + + p = sbuf.pubseekoff(0, ios_base::end); + VERIFY( p == good ); + + p = sbuf.pubseekoff(0, ios_base::cur); + VERIFY( p == bad ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekoff/wchar_t/16956.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekoff/wchar_t/16956.cc new file mode 100644 index 000000000..4e79b97cd --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekoff/wchar_t/16956.cc @@ -0,0 +1,60 @@ +// 2004-08-12 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2004, 2009 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.7.1.3 Overridden virtual functions + +#include <sstream> +#include <testsuite_hooks.h> + +// libstdc++/16956 +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + typedef wstringbuf::int_type int_type; + typedef wstringbuf::traits_type traits_type; + typedef wstringbuf::pos_type pos_type; + typedef wstringbuf::off_type off_type; + + wstringbuf strb_01(L"lara's place", ios_base::in); + pos_type pt_1 = strb_01.pubseekoff(5, ios_base::cur, ios_base::in); + int_type c1 = strb_01.sgetc(); + VERIFY( c1 != traits_type::eof() ); + pos_type pt_2 = strb_01.pubseekoff(2, ios_base::cur, ios_base::in); + pos_type pt_3 = strb_01.pubseekpos(pt_1, ios_base::in); + int_type c2 = strb_01.sbumpc(); + VERIFY( off_type(pt_3) == off_type(pt_2) - 2 ); + VERIFY( c2 == c1 ); + + wstringbuf strb_02(L"-", ios_base::out); + pos_type pt_4 = strb_02.pubseekoff(0, ios_base::cur, ios_base::out); + strb_02.sputn(L"red", 3); + pos_type pt_5 = strb_02.pubseekoff(-3, ios_base::cur, ios_base::out); + strb_02.pubseekpos(pt_5, ios_base::out); + VERIFY( off_type(pt_5) == off_type(pt_4) ); + strb_02.sputn(L"blu", 3); + VERIFY( strb_02.str() == L"blu" ); +} + +int main() +{ + test01(); + return 0; +} 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 000000000..7aefcac93 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekoff/wchar_t/2.cc @@ -0,0 +1,58 @@ +// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2004, 2009 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.7.1.3 Overridden virtual functions + +#include <sstream> +#include <testsuite_hooks.h> + +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/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekpos/char/1.cc new file mode 100644 index 000000000..53f98bf98 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekpos/char/1.cc @@ -0,0 +1,82 @@ +// 981208 bkoz test functionality of basic_stringbuf for char_type == char + +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2009, 2010 +// 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <sstream> +#include <testsuite_hooks.h> + +std::string str_01("mykonos. . . or what?"); +std::stringbuf strb_01(str_01); + +// test overloaded virtual functions +void test04() +{ + bool test __attribute__((unused)) = true; + std::string str_tmp; + typedef std::stringbuf::int_type int_type; + typedef std::stringbuf::pos_type pos_type; + typedef std::stringbuf::off_type off_type; + + int_type c1 = strb_01.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; + + // 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?"); + + //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 == 'o' ); + strb_01.sputc('x'); //test current out pointer + str_tmp = std::string("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 ); + strb_01.sputc('x'); //test current out pointer + str_tmp = std::string("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/char/2.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekpos/char/2.cc new file mode 100644 index 000000000..484fac826 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekpos/char/2.cc @@ -0,0 +1,59 @@ +// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2009 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.7.1.3 Overridden virtual functions + +#include <sstream> +#include <testsuite_hooks.h> + +void test02(std::stringbuf& in, bool pass) +{ + bool test __attribute__((unused)) = true; + using namespace std; + typedef streambuf::pos_type pos_type; + typedef streambuf::off_type off_type; + pos_type bad = pos_type(off_type(-1)); + pos_type p = 0; + + // 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! + stringbuf in1("Hedy Lamarr", ios_base::in); + stringbuf in2(ios_base::in); + stringbuf in3("", ios_base::in); + test02(in1, true); + test02(in2, false); + test02(in3, false); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekpos/char/29354.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekpos/char/29354.cc new file mode 100644 index 000000000..e23f8664d --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekpos/char/29354.cc @@ -0,0 +1,43 @@ +// Copyright (C) 2006, 2009 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <sstream> +#include <testsuite_hooks.h> + +// libstdc++/29354 +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + typedef stringbuf::pos_type pos_type; + typedef stringbuf::off_type off_type; + + stringbuf strb_01(ios_base::out); + + pos_type pt_1 = strb_01.pubseekoff(0, ios_base::cur, ios_base::out); + VERIFY( pt_1 == pos_type(off_type(0)) ); + + pos_type pt_2 = strb_01.pubseekpos(pt_1, ios_base::out); + VERIFY( pt_2 == pos_type(off_type(0)) ); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekpos/char/3.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekpos/char/3.cc new file mode 100644 index 000000000..8c3ff42db --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekpos/char/3.cc @@ -0,0 +1,47 @@ +// 2003-05-30 Paolo Carlini <pcarlini@unitus.it> + +// Copyright (C) 2003, 2009 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <sstream> +#include <testsuite_hooks.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + typedef stringbuf::pos_type pos_type; + typedef stringbuf::off_type off_type; + + stringbuf strb_01(ios_base::out); + + strb_01.sputn("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/seekpos/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekpos/wchar_t/1.cc new file mode 100644 index 000000000..bc01ea640 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekpos/wchar_t/1.cc @@ -0,0 +1,82 @@ +// 981208 bkoz test functionality of basic_stringbuf for char_type == wchar_t + +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2009, 2010 +// 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <sstream> +#include <testsuite_hooks.h> + +std::wstring str_01(L"mykonos. . . or what?"); +std::wstringbuf strb_01(str_01); + +// test overloaded virtual functions +void test04() +{ + bool test __attribute__((unused)) = true; + std::wstring str_tmp; + typedef std::wstringbuf::int_type int_type; + typedef std::wstringbuf::pos_type pos_type; + typedef std::wstringbuf::off_type off_type; + + int_type c1 = strb_01.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; + + // 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?"); + + //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' ); + 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 ); + 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 000000000..b95b19331 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekpos/wchar_t/2.cc @@ -0,0 +1,59 @@ +// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2004, 2009 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.7.1.3 Overridden virtual functions + +#include <sstream> +#include <testsuite_hooks.h> + +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/29354.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekpos/wchar_t/29354.cc new file mode 100644 index 000000000..d89d02dae --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekpos/wchar_t/29354.cc @@ -0,0 +1,43 @@ +// Copyright (C) 2006, 2009 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <sstream> +#include <testsuite_hooks.h> + +// libstdc++/29354 +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + typedef stringbuf::pos_type pos_type; + typedef stringbuf::off_type off_type; + + wstringbuf strb_01(ios_base::out); + + pos_type pt_1 = strb_01.pubseekoff(0, ios_base::cur, ios_base::out); + VERIFY( pt_1 == pos_type(off_type(0)) ); + + pos_type pt_2 = strb_01.pubseekpos(pt_1, ios_base::out); + VERIFY( pt_2 == pos_type(off_type(0)) ); +} + +int +main() +{ + test01(); + 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 000000000..bb0963244 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekpos/wchar_t/3.cc @@ -0,0 +1,47 @@ +// 2003-05-30 Paolo Carlini <pcarlini@unitus.it> + +// Copyright (C) 2003, 2004, 2009 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <sstream> +#include <testsuite_hooks.h> + +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/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/setbuf/char/1.cc new file mode 100644 index 000000000..728256154 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/setbuf/char/1.cc @@ -0,0 +1,56 @@ +// 981208 bkoz test functionality of basic_stringbuf for char_type == char + +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2009 +// 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <sstream> +#include <testsuite_hooks.h> + +std::string str_01("mykonos. . . or what?"); +std::string str_03; +std::stringbuf strb_01(str_01); +std::stringbuf strb_03(str_03, std::ios_base::out); + +// test overloaded virtual functions +void test04() +{ + bool test __attribute__((unused)) = true; + std::string str_tmp; + + // PUT + strb_03.str(str_01); //reset + + // BUFFER MANAGEMENT & POSITIONING + // setbuf + // pubsetbuf(char_type* s, streamsize n) + str_tmp = std::string("naaaah, go to cebu"); + strb_01.pubsetbuf(const_cast<char*> (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/char/2.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/setbuf/char/2.cc new file mode 100644 index 000000000..e870d592c --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/setbuf/char/2.cc @@ -0,0 +1,46 @@ +// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009 +// 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.8.1.4 Overridden virtual functions + +#include <sstream> +#include <cstring> +#include <testsuite_hooks.h> + +void test01() +{ + using namespace std; + + bool test __attribute__((unused)) = true; + char buf[512]; + const char* strlit = "how to tell a story and other essays: mark twain"; + const size_t strlitsize = std::strlen(strlit); + stringbuf sbuf; + + sbuf.pubsetbuf(buf, 512); + sbuf.sputn(strlit, strlitsize); + VERIFY( std::strncmp(strlit, buf, strlitsize) == 0 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/setbuf/char/3.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/setbuf/char/3.cc new file mode 100644 index 000000000..8e5912910 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/setbuf/char/3.cc @@ -0,0 +1,46 @@ +// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009 +// 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.8.1.4 Overridden virtual functions + +#include <sstream> +#include <cstring> +#include <testsuite_hooks.h> + +void test02() +{ + using namespace std; + + bool test __attribute__((unused)) = true; + char buf[512]; + const char* strlit = "how to tell a story and other essays: mark twain"; + const size_t strlitsize = std::strlen(strlit); + string s("tmp"); + stringbuf sbuf(s, ios_base::out); + sbuf.pubsetbuf(buf, strlitsize); + sbuf.sputn(strlit, strlitsize); + VERIFY( std::strncmp(strlit, buf, strlitsize) == 0 ); +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/setbuf/char/4.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/setbuf/char/4.cc new file mode 100644 index 000000000..f069db50f --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/setbuf/char/4.cc @@ -0,0 +1,58 @@ +// 2004-10-06 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2004, 2005, 2006, 2007, 2009 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.8.1.4 Overridden virtual functions + +#include <sstream> +#include <cstring> +#include <testsuite_hooks.h> + +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + const unsigned max_size = 1 << 18; + + char ref[max_size]; + memset(ref, '\0', max_size); + + char src[max_size * 2]; + memset(src, '\1', max_size * 2); + + for (unsigned i = 128; i <= max_size; i *= 2) + { + char* dest = new char[i * 2]; + memset(dest, '\0', i * 2); + + stringbuf sbuf; + sbuf.pubsetbuf(dest, i); + + sbuf.sputn(src, i * 2); + VERIFY( !memcmp(dest + i, ref, i) ); + + delete[] dest; + } +} + +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 000000000..62da6db10 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/setbuf/wchar_t/1.cc @@ -0,0 +1,56 @@ +// 981208 bkoz test functionality of basic_stringbuf for char_type == wchar_t + +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2009 +// 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <sstream> +#include <testsuite_hooks.h> + +std::wstring str_01(L"mykonos. . . or what?"); +std::wstring str_03; +std::wstringbuf strb_01(str_01); +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; + + // 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<wchar_t*> (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 000000000..06b8bef4c --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/setbuf/wchar_t/2.cc @@ -0,0 +1,44 @@ +// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2004, 2009 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.8.1.4 Overridden virtual functions + +#include <sstream> +#include <testsuite_hooks.h> + +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 000000000..ebaea1f9c --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/setbuf/wchar_t/3.cc @@ -0,0 +1,44 @@ +// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2004, 2009 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.8.1.4 Overridden virtual functions + +#include <sstream> +#include <testsuite_hooks.h> + +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/setbuf/wchar_t/4.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/setbuf/wchar_t/4.cc new file mode 100644 index 000000000..c6c966db7 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/setbuf/wchar_t/4.cc @@ -0,0 +1,57 @@ +// 2004-10-06 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2004, 2009 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.8.1.4 Overridden virtual functions + +#include <sstream> +#include <testsuite_hooks.h> + +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + const unsigned max_size = 1 << 18; + + static wchar_t ref[max_size]; + wmemset(ref, L'\0', max_size); + + static wchar_t src[max_size * 2]; + wmemset(src, L'\1', max_size * 2); + + for (unsigned i = 128; i <= max_size; i *= 2) + { + wchar_t* dest = new wchar_t[i * 2]; + wmemset(dest, L'\0', i * 2); + + wstringbuf sbuf; + sbuf.pubsetbuf(dest, i); + + sbuf.sputn(src, i * 2); + VERIFY( !wmemcmp(dest + i, ref, i) ); + + delete[] dest; + } +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/sgetc/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sgetc/char/1.cc new file mode 100644 index 000000000..f26ec85c5 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sgetc/char/1.cc @@ -0,0 +1,69 @@ +// 981208 bkoz test functionality of basic_stringbuf for char_type == char + +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2009, 2010 +// 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <sstream> +#include <testsuite_hooks.h> + +std::string str_01("mykonos. . . or what?"); +std::string str_02("paris, or sainte-maxime?"); +std::string str_03; +std::stringbuf strb_01(str_01); +std::stringbuf strb_02(str_02, std::ios_base::in); +std::stringbuf strb_03(str_03, std::ios_base::out); + +// test overloaded virtual functions +void test04() +{ + bool test __attribute__((unused)) = true; + typedef std::stringbuf::int_type int_type; + typedef std::stringbuf::traits_type traits_type; + + // GET + strb_01.in_avail(); + strb_02.in_avail(); + 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/sgetc/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sgetc/wchar_t/1.cc new file mode 100644 index 000000000..98ca73d75 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sgetc/wchar_t/1.cc @@ -0,0 +1,69 @@ +// 981208 bkoz test functionality of basic_stringbuf for char_type == wchar_t + +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2009, 2010 +// 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <sstream> +#include <testsuite_hooks.h> + +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; + typedef std::wstringbuf::int_type int_type; + typedef std::wstringbuf::traits_type traits_type; + + // GET + strb_01.in_avail(); + strb_02.in_avail(); + 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/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sgetn/char/1.cc new file mode 100644 index 000000000..2f077a508 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sgetn/char/1.cc @@ -0,0 +1,104 @@ +// 981208 bkoz test functionality of basic_stringbuf for char_type == char + +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 +// 2006, 2007, 2009, 2010 +// 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <sstream> +#include <testsuite_hooks.h> + +std::string str_01("mykonos. . . or what?"); +std::string str_02("paris, or sainte-maxime?"); +std::string str_03; +std::stringbuf strb_01(str_01); +std::stringbuf strb_02(str_02, std::ios_base::in); +std::stringbuf strb_03(str_03, std::ios_base::out); + +// test overloaded virtual functions +void test04() +{ + bool test __attribute__((unused)) = true; + std::streamsize strmsz_1, strmsz_2; + typedef std::stringbuf::int_type int_type; + typedef std::stringbuf::traits_type traits_type; + + // GET + strb_01.in_avail(); + strb_02.in_avail(); + 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(); + 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(); + strb_03.sgetc(); + + // int_type snextc() + // calls sbumpc and if sbumpc != eof, return sgetc + c6 = strb_01.snextc(); + c7 = strb_02.snextc(); + 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<std::streamsize>(str_01.length()) ); + // because now we've moved into string + VERIFY( strmsz_2 != static_cast<std::streamsize>(str_02.length()) ); + char carray1[11] = ""; + strmsz_1 = strb_01.sgetn(carray1, 10); + char carray2[20] = ""; + 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 == traits_type::to_int_type(str_01[13]) ); + VERIFY( c2 == traits_type::to_int_type(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/sgetn/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sgetn/wchar_t/1.cc new file mode 100644 index 000000000..5c917e109 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sgetn/wchar_t/1.cc @@ -0,0 +1,104 @@ +// 981208 bkoz test functionality of basic_stringbuf for char_type == wchar_t + +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, +// 2006, 2007, 2009, 2010 +// 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <sstream> +#include <testsuite_hooks.h> + +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::streamsize strmsz_1, strmsz_2; + typedef std::wstringbuf::int_type int_type; + typedef std::wstringbuf::traits_type traits_type; + + // GET + strb_01.in_avail(); + strb_02.in_avail(); + 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(); + 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(); + strb_03.sgetc(); + + // int_type snextc() + // calls sbumpc and if sbumpc != eof, return sgetc + c6 = strb_01.snextc(); + c7 = strb_02.snextc(); + 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<std::streamsize>(str_01.length()) ); + // because now we've moved into string + VERIFY( strmsz_2 != static_cast<std::streamsize>(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 == traits_type::to_int_type(str_01[13]) ); + VERIFY( c2 == traits_type::to_int_type(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/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/snextc/char/1.cc new file mode 100644 index 000000000..afe1dfa57 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/snextc/char/1.cc @@ -0,0 +1,78 @@ +// 981208 bkoz test functionality of basic_stringbuf for char_type == char + +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, +// 2006, 2007, 2009, 2010 +// 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <sstream> +#include <testsuite_hooks.h> + +std::string str_01("mykonos. . . or what?"); +std::string str_02("paris, or sainte-maxime?"); +std::string str_03; +std::stringbuf strb_01(str_01); +std::stringbuf strb_02(str_02, std::ios_base::in); +std::stringbuf strb_03(str_03, std::ios_base::out); + +// test overloaded virtual functions +void test04() +{ + bool test __attribute__((unused)) = true; + typedef std::stringbuf::int_type int_type; + typedef std::stringbuf::traits_type traits_type; + + // GET + strb_01.in_avail(); + strb_02.in_avail(); + 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 == traits_type::to_int_type(str_01[3]) ); + VERIFY( c7 == traits_type::to_int_type(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/snextc/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/snextc/wchar_t/1.cc new file mode 100644 index 000000000..0154594b6 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/snextc/wchar_t/1.cc @@ -0,0 +1,78 @@ +// 981208 bkoz test functionality of basic_stringbuf for char_type == wchar_t + +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 +// 2006, 2007, 2009, 2010 +// 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <sstream> +#include <testsuite_hooks.h> + +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; + typedef std::wstringbuf::int_type int_type; + typedef std::wstringbuf::traits_type traits_type; + + // GET + strb_01.in_avail(); + strb_02.in_avail(); + 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 == traits_type::to_int_type(str_01[3]) ); + VERIFY( c7 == traits_type::to_int_type(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/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sputbackc/char/1.cc new file mode 100644 index 000000000..67358a3b9 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sputbackc/char/1.cc @@ -0,0 +1,115 @@ +// 981208 bkoz test functionality of basic_stringbuf for char_type == char + +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2009, 2010 +// 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <sstream> +#include <testsuite_hooks.h> + +std::string str_01("mykonos. . . or what?"); +std::string str_02("paris, or sainte-maxime?"); +std::string str_03; +std::stringbuf strb_01(str_01); +std::stringbuf strb_02(str_02, std::ios_base::in); +std::stringbuf strb_03(str_03, std::ios_base::out); + +// test overloaded virtual functions +void test04() +{ + bool test __attribute__((unused)) = true; + std::string str_tmp, str_tmp2; + typedef std::stringbuf::int_type int_type; + typedef std::stringbuf::traits_type traits_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 + strb_03.str().length(); + 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(); + str_tmp.length(); + strb_03.sputn("racadabras", 10);//"abracadabras or what?" + strb_03.str().length(); + strb_03.sputn(", i wanna reach out and", 10); + strb_03.str().length(); + str_tmp = strb_02.str(); + strb_02.sputn("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() + 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(); + str_tmp2 = strb_01.str(); + VERIFY( c1 != c2 ); + VERIFY( c3 == c2 ); + VERIFY( str_tmp2 == std::string("mzkonos. . . or what?") ); + VERIFY( str_tmp.size() == str_tmp2.size() ); + //test for _in_cur == _in_beg + strb_01.str(str_tmp); + strb_01.in_avail(); + c1 = strb_01.sgetc(); //"'m'ykonos. . . or what?" + c2 = strb_01.sputbackc('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 + strb_01.in_avail(); + strb_01.sbumpc(); + strb_01.sbumpc(); + c1 = strb_01.sgetc(); //"my'k'onos. . . or what?" + c2 = strb_01.sputbackc('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 + strb_03.in_avail(); + c4 = strb_03.sputbackc('x'); + VERIFY( c4 == traits_type::eof() ); +} + +int main() +{ + test04(); + return 0; +} + + + +// more candy!!! diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/sputbackc/char/9425.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sputbackc/char/9425.cc new file mode 100644 index 000000000..5e56378e8 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sputbackc/char/9425.cc @@ -0,0 +1,42 @@ +// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2009 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.8.1.4 Overridden virtual functions + +#include <sstream> +#include <testsuite_hooks.h> + +// 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; + + stringbuf sbuf; + stringbuf::int_type r = sbuf.sputbackc('a'); + VERIFY( r == stringbuf::traits_type::eof() ); +} + +int main() +{ + test09(); + return 0; +} 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 000000000..e0c91a3b2 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sputbackc/wchar_t/1.cc @@ -0,0 +1,115 @@ +// 981208 bkoz test functionality of basic_stringbuf for char_type == wchar_t + +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2009, 2010 +// 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <sstream> +#include <testsuite_hooks.h> + +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; + typedef std::wstringbuf::int_type int_type; + typedef std::wstringbuf::traits_type traits_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 + strb_03.str().length(); + 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(); + str_tmp.length(); + strb_03.sputn(L"racadabras", 10);//"abracadabras or what?" + strb_03.str().length(); + strb_03.sputn(L", i wanna reach out and", 10); + strb_03.str().length(); + str_tmp = strb_02.str(); + 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() + 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); + 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 + 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 + 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 000000000..87b4c64b6 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sputbackc/wchar_t/9425.cc @@ -0,0 +1,42 @@ +// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2004, 2009 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.8.1.4 Overridden virtual functions + +#include <sstream> +#include <testsuite_hooks.h> + +// 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/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sputc/char/1.cc new file mode 100644 index 000000000..b7b76da0d --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sputc/char/1.cc @@ -0,0 +1,66 @@ +// 981208 bkoz test functionality of basic_stringbuf for char_type == char + +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2009 +// 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <sstream> +#include <testsuite_hooks.h> + +std::string str_01("mykonos. . . or what?"); +std::string str_02("paris, or sainte-maxime?"); +std::string str_03; +std::stringbuf strb_01(str_01); +std::stringbuf strb_02(str_02, std::ios_base::in); +std::stringbuf strb_03(str_03, std::ios_base::out); + +// test overloaded virtual functions +void test04() +{ + bool test __attribute__((unused)) = true; + typedef std::stringbuf::int_type int_type; + typedef std::stringbuf::traits_type traits_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::string::size_type sz1 = strb_03.str().length(); + c1 = strb_03.sputc('a'); + std::string::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('b'); + VERIFY( c1 != c2 ); + VERIFY( strb_03.str() != str_01 ); + c3 = strb_02.sputc('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/char/1057.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sputc/char/1057.cc new file mode 100644 index 000000000..f88f28e39 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sputc/char/1057.cc @@ -0,0 +1,53 @@ +// 1999-10-11 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2009, 2010 +// 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +// 27.5.2 template class basic_streambuf + +#include <string> +#include <sstream> +#include <testsuite_hooks.h> + +class nullsetpbuf : public std::stringbuf +{ + char foo[64]; +public: + nullsetpbuf() + { + setp(foo, foo + 64); + setp(0, 0); + } +}; + +// libstdc++/1057 +void test05() +{ + std::string text1 = "abcdefghijklmn"; + + nullsetpbuf nsp; + // Immediate crash as sputc writes to null pointer + nsp.sputc('a'); +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/sputc/char/9404-1.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sputc/char/9404-1.cc new file mode 100644 index 000000000..3521c0454 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sputc/char/9404-1.cc @@ -0,0 +1,72 @@ +// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2009 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.7.1.3 Overridden virtual functions + +#include <sstream> +#include <testsuite_hooks.h> + +bool over_called; + +class Derived_stringbuf : public std::stringbuf +{ +public: + int_type overflow(int_type c) + { + over_called = true; + return std::stringbuf::overflow(c); + } + + const char_type* pub_epptr() const + { + return epptr(); + } + + const char_type* pub_pptr() const + { + return pptr(); + } +}; + +// libstdc++/9404 +void test04() +{ + bool test __attribute__((unused)) = true; + + bool over_expected; + + // sputc + Derived_stringbuf dsbuf_01; + over_called = false; + dsbuf_01.sputc('i'); + VERIFY( over_called ); + over_expected = dsbuf_01.pub_epptr() == dsbuf_01.pub_pptr(); + over_called = false; + dsbuf_01.sputc('v'); + VERIFY( (!over_expected && !over_called) + || (over_expected && over_called) ); + dsbuf_01.sputc('i'); + VERIFY( dsbuf_01.str() == "ivi" ); // Sanity check. +} + +int main() +{ + test04(); + 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 000000000..e9c7fb174 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sputc/wchar_t/1.cc @@ -0,0 +1,66 @@ +// 981208 bkoz test functionality of basic_stringbuf for char_type == wchar_t + +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2009 +// 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <sstream> +#include <testsuite_hooks.h> + +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; + typedef std::wstringbuf::int_type int_type; + typedef std::wstringbuf::traits_type traits_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 000000000..ae07ebf30 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sputc/wchar_t/1057.cc @@ -0,0 +1,53 @@ +// 1999-10-11 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2009, 2010 +// 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +// 27.5.2 template class basic_streambuf + +#include <string> +#include <sstream> +#include <testsuite_hooks.h> + +class nullsetpbuf : public std::wstringbuf +{ + wchar_t foo[64]; +public: + nullsetpbuf() + { + setp(foo, foo + 64); + setp(0, 0); + } +}; + +// 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 000000000..693af97aa --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sputc/wchar_t/9404-1.cc @@ -0,0 +1,72 @@ +// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2004, 2009 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.7.1.3 Overridden virtual functions + +#include <sstream> +#include <testsuite_hooks.h> + +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/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sputn/char/1.cc new file mode 100644 index 000000000..b9a96641f --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sputn/char/1.cc @@ -0,0 +1,76 @@ +// 981208 bkoz test functionality of basic_stringbuf for char_type == char + +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2009 +// 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <sstream> +#include <testsuite_hooks.h> + +std::string str_01("mykonos. . . or what?"); +std::string str_02("paris, or sainte-maxime?"); +std::string str_03; +std::stringbuf strb_01(str_01); +std::stringbuf strb_02(str_02, std::ios_base::in); +std::stringbuf strb_03(str_03, std::ios_base::out); + +// test overloaded virtual functions +void test04() +{ + bool test __attribute__((unused)) = true; + std::string str_tmp; + std::streamsize strmsz_1, strmsz_2; + typedef std::stringbuf::int_type int_type; + typedef std::stringbuf::traits_type traits_type; + + // PUT + strb_03.str(str_01); //reset + std::string::size_type sz1 = strb_03.str().length(); + std::string::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("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(", 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("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/char/1057.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sputn/char/1057.cc new file mode 100644 index 000000000..c51f47a8d --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sputn/char/1057.cc @@ -0,0 +1,53 @@ +// 1999-10-11 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2009, 2010 +// 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +// 27.5.2 template class basic_streambuf + +#include <string> +#include <sstream> +#include <testsuite_hooks.h> + +class nullsetpbuf : public std::stringbuf +{ + char foo[64]; +public: + nullsetpbuf() + { + setp(foo, foo + 64); + setp(0, 0); + } +}; + +// libstdc++/1057 +void test05() +{ + std::string text1 = "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/char/9404-2.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sputn/char/9404-2.cc new file mode 100644 index 000000000..a532f203a --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sputn/char/9404-2.cc @@ -0,0 +1,72 @@ +// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2009 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.7.1.3 Overridden virtual functions + +#include <sstream> +#include <testsuite_hooks.h> + +bool over_called; + +class Derived_stringbuf : public std::stringbuf +{ +public: + int_type overflow(int_type c) + { + over_called = true; + return std::stringbuf::overflow(c); + } + + const char_type* pub_epptr() const + { + return epptr(); + } + + const char_type* pub_pptr() const + { + return pptr(); + } +}; + +// libstdc++/9404 +void test04() +{ + bool test __attribute__((unused)) = true; + + bool over_expected; + Derived_stringbuf dsbuf_01; + + // sputn + Derived_stringbuf dsbuf_02; + over_called = false; + dsbuf_02.sputn("sonne's", 7); + VERIFY( over_called ); + over_expected = dsbuf_02.pub_epptr() == dsbuf_02.pub_pptr(); + over_called = false; + dsbuf_02.sputn(" peak", 5); + VERIFY( (!over_expected && !over_called) + || (over_expected && over_called) ); + VERIFY( dsbuf_02.str() == "sonne's peak" ); // Sanity check. +} + +int main() +{ + 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 000000000..c62ba3678 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sputn/wchar_t/1.cc @@ -0,0 +1,76 @@ +// 981208 bkoz test functionality of basic_stringbuf for char_type == wchar_t + +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2009 +// 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <sstream> +#include <testsuite_hooks.h> + +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::streamsize strmsz_1, strmsz_2; + typedef std::wstringbuf::int_type int_type; + typedef std::wstringbuf::traits_type traits_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 000000000..99f7a5509 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sputn/wchar_t/1057.cc @@ -0,0 +1,53 @@ +// 1999-10-11 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2009, 2010 +// 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +// 27.5.2 template class basic_streambuf + +#include <string> +#include <sstream> +#include <testsuite_hooks.h> + +class nullsetpbuf : public std::wstringbuf +{ + wchar_t foo[64]; +public: + nullsetpbuf() + { + setp(foo, foo + 64); + setp(0, 0); + } +}; + +// 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 000000000..7e7adbea4 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sputn/wchar_t/9404-2.cc @@ -0,0 +1,72 @@ +// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2004, 2009 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.7.1.3 Overridden virtual functions + +#include <sstream> +#include <testsuite_hooks.h> + +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/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/str/char/1.cc new file mode 100644 index 000000000..cc0d0bd79 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/str/char/1.cc @@ -0,0 +1,73 @@ +// 981208 bkoz test functionality of basic_stringbuf for char_type == char + +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2005, 2009 +// 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <sstream> +#include <testsuite_hooks.h> + +std::string str_01("mykonos. . . or what?"); +std::string str_02("paris, or sainte-maxime?"); +std::string str_03; +std::stringbuf strb_01(str_01); +std::stringbuf strb_02(str_02, std::ios_base::in); +std::stringbuf 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("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 == -1 ); // -1, cuz ios_base::out + VERIFY( d1 != d2 ); //these should be the same + VERIFY( static_cast<std::streamsize>(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::string str_nulls ("eschew \0 obfuscation", 20); // tested in 21_strings + std::stringbuf strb_normal (str_01); + std::stringbuf 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<std::streamsize>(str_nulls.size()) ); + VERIFY( strb_nulls.str().size() == 20 ); + VERIFY( strb_normal.in_avail() == static_cast<std::streamsize>(str_nulls.size()) ); +} + +int main() +{ + test03(); + return 0; +} + + + +// more candy!!! diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/str/char/2.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/str/char/2.cc new file mode 100644 index 000000000..c367d3810 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/str/char/2.cc @@ -0,0 +1,54 @@ +// 981208 bkoz test functionality of basic_stringbuf for char_type == char + +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2009 +// 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <sstream> +#include <testsuite_hooks.h> + +// 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::stringbuf strb_01; + strb_01.sputc('s'); + strb_01.pubseekoff(0, std::ios_base::beg); + std::string tmp = strb_01.str(); + VERIFY( tmp == "s" ); + + std::string str("strivi,"); + std::stringbuf strb_02(str); + strb_02.pubseekoff(0, std::ios_base::end); + strb_02.sputn(" no better!", 11); + strb_02.pubseekoff(0, std::ios_base::beg); + tmp = strb_02.str(); + VERIFY( tmp == "strivi, no better!" ); +} + +int main() +{ + test07(); + return 0; +} + + + +// more candy!!! diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/str/char/3.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/str/char/3.cc new file mode 100644 index 000000000..973a7c843 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/str/char/3.cc @@ -0,0 +1,42 @@ +// 981208 bkoz test functionality of basic_stringbuf for char_type == char + +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2009 +// 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <sstream> +#include <testsuite_hooks.h> + +void test06() +{ + bool test __attribute__((unused)) = true; + + std::ostringstream os ("foo", std::ios_base::app); + os << "bar"; + + VERIFY( os.str() == "foobar" ); +} + +int main() +{ + test06(); + return 0; +} + + + +// more candy!!! diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/str/char/3955.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/str/char/3955.cc new file mode 100644 index 000000000..113235738 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/str/char/3955.cc @@ -0,0 +1,43 @@ +// 981208 bkoz test functionality of basic_stringbuf for char_type == char + +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2009 +// 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <sstream> +#include <testsuite_hooks.h> + +// libstdc++/3955 -- ios_base::app overwrites from the beginning +void test05() +{ + bool test __attribute__((unused)) = true; + + std::ostringstream os ("foo"); + os << "bar"; + + VERIFY( os.str() == "bar" ); +} + +int main() +{ + test05(); + return 0; +} + + + +// more candy!!! 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 000000000..7369b18ee --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/str/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, 2005, 2009 +// 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <sstream> +#include <testsuite_hooks.h> + +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 == -1 ); // -1, cuz ios_base::out + VERIFY( d1 != d2 ); //these should be the same + VERIFY( static_cast<std::streamsize>(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<std::streamsize>(str_nulls.size()) ); + VERIFY( strb_nulls.str().size() == 20 ); + VERIFY( strb_normal.in_avail() == static_cast<std::streamsize>(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 000000000..5b028e551 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/str/wchar_t/2.cc @@ -0,0 +1,54 @@ +// 981208 bkoz test functionality of basic_stringbuf for char_type == wchar_t + +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2009 +// 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <sstream> +#include <testsuite_hooks.h> + +// 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 000000000..710789cb7 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/str/wchar_t/3.cc @@ -0,0 +1,42 @@ +// 981208 bkoz test functionality of basic_stringbuf for char_type == wchar_t + +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2009 +// 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <sstream> +#include <testsuite_hooks.h> + +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 000000000..3a1179ccb --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/str/wchar_t/3955.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, 2009 +// 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <sstream> +#include <testsuite_hooks.h> + +// 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/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sungetc/char/1.cc new file mode 100644 index 000000000..ae038e518 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sungetc/char/1.cc @@ -0,0 +1,144 @@ +// 981208 bkoz test functionality of basic_stringbuf for char_type == char + +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2009, 2010 +// 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <sstream> +#include <testsuite_hooks.h> + +std::string str_01("mykonos. . . or what?"); +std::string str_02("paris, or sainte-maxime?"); +std::string str_03; +std::stringbuf strb_01(str_01); +std::stringbuf strb_02(str_02, std::ios_base::in); +std::stringbuf strb_03(str_03, std::ios_base::out); + +// test overloaded virtual functions +void test04() +{ + bool test __attribute__((unused)) = true; + std::string str_tmp; + typedef std::stringbuf::int_type int_type; + typedef std::stringbuf::traits_type traits_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 + strb_03.str().length(); + 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(); + str_tmp.length(); + strb_03.sputn("racadabras", 10);//"abracadabras or what?" + strb_03.str().length(); + strb_03.sputn(", i wanna reach out and", 10); + strb_03.str().length(); + str_tmp = strb_02.str(); + strb_02.sputn("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() + 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); + strb_01.in_avail(); + c1 = strb_01.sgetc(); //"'m'ykonos. . . or what?" + c2 = strb_01.sputbackc('z');//"mykonos. . . or what?" + c3 = strb_01.sgetc(); + // test for replacing char with identical one + strb_01.str(str_01); //reset + strb_01.in_avail(); + strb_01.sbumpc(); + strb_01.sbumpc(); + c1 = strb_01.sgetc(); //"my'k'onos. . . or what?" + c2 = strb_01.sputbackc('y');//"mykonos. . . or what?" + c3 = strb_01.sgetc(); + //test for ios_base::out + strb_03.in_avail(); + c4 = strb_03.sputbackc('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(); + 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 == ' ' ); + 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); + 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 + 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 + 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/sungetc/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sungetc/wchar_t/1.cc new file mode 100644 index 000000000..767b7eac5 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sungetc/wchar_t/1.cc @@ -0,0 +1,144 @@ +// 981208 bkoz test functionality of basic_stringbuf for char_type == wchar_t + +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2009, 2010 +// 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <sstream> +#include <testsuite_hooks.h> + +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; + typedef std::wstringbuf::int_type int_type; + typedef std::wstringbuf::traits_type traits_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 + strb_03.str().length(); + 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(); + str_tmp.length(); + strb_03.sputn(L"racadabras", 10);//"abracadabras or what?" + strb_03.str().length(); + strb_03.sputn(L", i wanna reach out and", 10); + strb_03.str().length(); + str_tmp = strb_02.str(); + 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() + 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); + 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 + 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 + 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(); + 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); + 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 + 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 + 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/char/1057.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sync/char/1057.cc new file mode 100644 index 000000000..baa93fbfd --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sync/char/1057.cc @@ -0,0 +1,100 @@ +// 1999-10-11 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2009 +// 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +// 27.5.2 template class basic_streambuf + +#include <sstream> +#include <testsuite_hooks.h> + +class setpbuf : public std::stringbuf +{ + char buffer[4]; + std::string result; + +public: + + std::string& + get_result() + { return result; } + + setpbuf() + { + char 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::string text = "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::string::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; +} 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 000000000..25cf5b0da --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sync/wchar_t/1057.cc @@ -0,0 +1,100 @@ +// 1999-10-11 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2009 +// 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +// 27.5.2 template class basic_streambuf + +#include <sstream> +#include <testsuite_hooks.h> + +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; +} |