diff options
Diffstat (limited to 'libstdc++-v3/testsuite/27_io/basic_istringstream')
8 files changed, 461 insertions, 0 deletions
diff --git a/libstdc++-v3/testsuite/27_io/basic_istringstream/cons/2020.cc b/libstdc++-v3/testsuite/27_io/basic_istringstream/cons/2020.cc new file mode 100644 index 000000000..9eb4ca7a4 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istringstream/cons/2020.cc @@ -0,0 +1,54 @@ +// 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.8.1.1 - Template class basic_filebuf +// 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_istringstream<__gnu_test::pod_ushort> gnu_isstr; + + try + { + gnu_isstr 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_istringstream/rdbuf/char/2832.cc b/libstdc++-v3/testsuite/27_io/basic_istringstream/rdbuf/char/2832.cc new file mode 100644 index 000000000..02f2e268f --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istringstream/rdbuf/char/2832.cc @@ -0,0 +1,74 @@ +// 2000-01-10 bkoz + +// Copyright (C) 2000, 2001, 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.2.2 member functions (istringstream_members) + +#include <sstream> +#include <testsuite_hooks.h> + +void +redirect_buffer(std::ios& stream, std::streambuf* new_buf) +{ stream.rdbuf(new_buf); } + +std::streambuf* +active_buffer(std::ios& stream) +{ return stream.rdbuf(); } + +// libstdc++/2832 +void test02() +{ + bool test __attribute__((unused)) = true; + const char* strlit01 = "fuck war"; + const std::string str00; + const std::string str01(strlit01); + std::string str02; + std::stringbuf sbuf(str01); + std::streambuf* pbasebuf0 = &sbuf; + + std::istringstream sstrm1; + VERIFY( sstrm1.str() == str00 ); + // derived rdbuf() always returns original streambuf, even though + // it's no longer associated with the stream. + std::stringbuf* const buf1 = sstrm1.rdbuf(); + // base rdbuf() returns the currently associated streambuf + std::streambuf* pbasebuf1 = active_buffer(sstrm1); + redirect_buffer(sstrm1, &sbuf); + std::stringbuf* const buf2 = sstrm1.rdbuf(); + std::streambuf* pbasebuf2 = active_buffer(sstrm1); + VERIFY( buf1 == buf2 ); + VERIFY( pbasebuf1 != pbasebuf2 ); + VERIFY( pbasebuf2 == pbasebuf0 ); + + // derived rdbuf() returns the original buf, so str() doesn't change. + VERIFY( sstrm1.str() != str01 ); + VERIFY( sstrm1.str() == str00 ); + // however, casting the active streambuf to a stringbuf shows what's up: + std::stringbuf* psbuf = dynamic_cast<std::stringbuf*>(pbasebuf2); + str02 = psbuf->str(); + VERIFY( str02 == str01 ); + + // How confusing and non-intuitive is this? + // These semantics are a joke, a serious defect, and incredibly lame. +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istringstream/rdbuf/wchar_t/2832.cc b/libstdc++-v3/testsuite/27_io/basic_istringstream/rdbuf/wchar_t/2832.cc new file mode 100644 index 000000000..14a659aac --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istringstream/rdbuf/wchar_t/2832.cc @@ -0,0 +1,72 @@ +// 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.2.2 member functions (istringstream_members) + +#include <sstream> +#include <testsuite_hooks.h> + +void +redirect_buffer(std::wios& stream, std::wstreambuf* new_buf) +{ stream.rdbuf(new_buf); } + +std::wstreambuf* +active_buffer(std::wios& stream) +{ return stream.rdbuf(); } + +// libstdc++/2832 +void test02() +{ + bool test __attribute__((unused)) = true; + const wchar_t* strlit01 = L"fuck war"; + const std::wstring str00; + const std::wstring str01(strlit01); + std::wstring str02; + std::wstringbuf sbuf(str01); + std::wstreambuf* pbasebuf0 = &sbuf; + + std::wistringstream sstrm1; + VERIFY( sstrm1.str() == str00 ); + // derived rdbuf() always returns original streambuf, even though + // it's no longer associated with the stream. + std::wstringbuf* const buf1 = sstrm1.rdbuf(); + // base rdbuf() returns the currently associated streambuf + std::wstreambuf* pbasebuf1 = active_buffer(sstrm1); + redirect_buffer(sstrm1, &sbuf); + std::wstringbuf* const buf2 = sstrm1.rdbuf(); + std::wstreambuf* pbasebuf2 = active_buffer(sstrm1); + VERIFY( buf1 == buf2 ); + VERIFY( pbasebuf1 != pbasebuf2 ); + VERIFY( pbasebuf2 == pbasebuf0 ); + + // derived rdbuf() returns the original buf, so str() doesn't change. + VERIFY( sstrm1.str() != str01 ); + VERIFY( sstrm1.str() == str00 ); + // however, casting the active streambuf to a stringbuf shows what's up: + std::wstringbuf* psbuf = dynamic_cast<std::wstringbuf*>(pbasebuf2); + str02 = psbuf->str(); + VERIFY( str02 == str01 ); + + // How confusing and non-intuitive is this? + // These semantics are a joke, a serious defect, and incredibly lame. +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istringstream/requirements/base_classes.cc b/libstdc++-v3/testsuite/27_io/basic_istringstream/requirements/base_classes.cc new file mode 100644 index 000000000..77625a2d1 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istringstream/requirements/base_classes.cc @@ -0,0 +1,44 @@ +// { 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.8.1.1 - Template class basic_filebuf + +#include <istream> +#include <sstream> + +void test01() +{ + // Check for required base class. + typedef std::istringstream test_type; + typedef std::istream 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_istringstream/requirements/explicit_instantiation.cc b/libstdc++-v3/testsuite/27_io/basic_istringstream/requirements/explicit_instantiation.cc new file mode 100644 index 000000000..194dc9e8e --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istringstream/requirements/explicit_instantiation.cc @@ -0,0 +1,31 @@ +// { dg-do compile } +// 2002-07-25 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2002, 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.2 - Template class basic_istringstream +// NB: This file is for testing basic_istringstream with NO OTHER INCLUDES. + +#include <sstream> + +namespace std +{ + typedef short type_t; + template class basic_istringstream<type_t, char_traits<type_t> >; +} // test diff --git a/libstdc++-v3/testsuite/27_io/basic_istringstream/requirements/typedefs.cc b/libstdc++-v3/testsuite/27_io/basic_istringstream/requirements/typedefs.cc new file mode 100644 index 000000000..379e64dd9 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istringstream/requirements/typedefs.cc @@ -0,0 +1,37 @@ +// { dg-do compile } +// 2002-07-25 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2002, 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.2 - Template class basic_istringstream +// NB: This file is for testing basic_istringstream with NO OTHER INCLUDES. + +#include <sstream> + +// libstdc++/7216 +void test01() +{ + // Check for required typedefs + typedef std::istringstream 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_istringstream/str/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_istringstream/str/char/1.cc new file mode 100644 index 000000000..3a3529eb1 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istringstream/str/char/1.cc @@ -0,0 +1,76 @@ +// 2000-01-10 bkoz + +// Copyright (C) 2000, 2001, 2003, 2004, 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/>. + +// 27.7.2.2 member functions (istringstream_members) + +#include <sstream> +#include <testsuite_hooks.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + std::istringstream is01; + const std::string str00; + const std::string str01 = "123"; + std::string str02; + const int i01 = 123; + int a = 0, b = 0; + + std::ios_base::iostate state1, state2, stateeof; + stateeof = std::ios_base::eofbit; + + // string str() const + str02 = is01.str(); + VERIFY( str00 == str02 ); + + // void str(const basic_string&) + is01.str(str01); + str02 = is01.str(); + VERIFY( str01 == str02 ); + state1 = is01.rdstate(); + is01 >> a; + state2 = is01.rdstate(); + VERIFY( a == i01 ); + // 22.2.2.1.2 num_get virtual functions + // p 13 + // in any case, if stage 2 processing was terminated by the test for + // in == end then err != ios_base::eofbit is performed. + VERIFY( state1 != state2 ); + VERIFY( state2 == stateeof ); + + is01.str(str01); + is01 >> b; + VERIFY( b != a ); + // as is01.good() is false, istream::sentry blocks extraction. + + is01.clear(); + state1 = is01.rdstate(); + is01 >> b; + state2 = is01.rdstate(); + VERIFY( b == a ); + VERIFY( state1 != state2 ); + VERIFY( state2 == stateeof ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istringstream/str/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_istringstream/str/wchar_t/1.cc new file mode 100644 index 000000000..2548610d7 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istringstream/str/wchar_t/1.cc @@ -0,0 +1,73 @@ +// Copyright (C) 2004, 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/>. + +// 27.7.2.2 member functions (istringstream_members) + +#include <sstream> +#include <testsuite_hooks.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + std::wistringstream is01; + const std::wstring str00; + const std::wstring str01 = L"123"; + std::wstring str02; + const int i01 = 123; + int a = 0, b = 0; + + std::ios_base::iostate state1, state2, stateeof; + stateeof = std::ios_base::eofbit; + + // string str() const + str02 = is01.str(); + VERIFY( str00 == str02 ); + + // void str(const basic_string&) + is01.str(str01); + str02 = is01.str(); + VERIFY( str01 == str02 ); + state1 = is01.rdstate(); + is01 >> a; + state2 = is01.rdstate(); + VERIFY( a == i01 ); + // 22.2.2.1.2 num_get virtual functions + // p 13 + // in any case, if stage 2 processing was terminated by the test for + // in == end then err != ios_base::eofbit is performed. + VERIFY( state1 != state2 ); + VERIFY( state2 == stateeof ); + + is01.str(str01); + is01 >> b; + VERIFY( b != a ); + // as is01.good() is false, istream::sentry blocks extraction. + + is01.clear(); + state1 = is01.rdstate(); + is01 >> b; + state2 = is01.rdstate(); + VERIFY( b == a ); + VERIFY( state1 != state2 ); + VERIFY( state2 == stateeof ); +} + +int main() +{ + test01(); + return 0; +} |