diff options
author | redi <redi@138bc75d-0d04-0410-961f-82ee72b054a4> | 2014-09-22 13:34:09 +0000 |
---|---|---|
committer | redi <redi@138bc75d-0d04-0410-961f-82ee72b054a4> | 2014-09-22 13:34:09 +0000 |
commit | 28f8cba268ceb976aa8ce17bd3177d990e8c85d2 (patch) | |
tree | 56471caae5e872ad7a27f4e39b5f246f4a5245c8 /libstdc++-v3/testsuite | |
parent | 3979f78787bdc6db3e1679b6015a1a403bb097ba (diff) | |
download | gcc-28f8cba268ceb976aa8ce17bd3177d990e8c85d2.tar.gz |
Make streams movable and swappable.
PR libstdc++/54316
PR libstdc++/53626
* config/abi/pre/gnu.ver: Add new exports.
* config/io/basic_file_stdio.h (__basic_file): Support moving and
swapping.
* include/bits/basic_ios.h (basic_ios::move, basic_ios::swap):
Likewise.
* include/bits/ios_base.h (ios_base::_M_move, ios_base::_M_swap):
Likewise.
* include/bits/fstream.tcc (basic_filebuf): Likewise.
* include/bits/move.h (__exchange): Define for C++11 mode.
* include/ext/stdio_filebuf.h (stdio_filebuf): Support moving and
swapping.
* include/ext/stdio_sync_filebuf.h (stdio_sync_filebuf): Likewise.
* include/std/fstream (basic_filebuf, basic_ifstream, basic_ofstream,
basic_fstream): Likewise.
* include/std/ios: Remove whitespace.
* include/std/istream (basic_istream, basic_iostream): Support moving
and swapping.
* include/std/ostream (basic_ostream): Likewise.
* include/std/sstream (basic_stringbuf, basic_istringstream,
basic_ostringstream, basic_stringstream): Likewise.
* include/std/streambuf (basic_streambuf): Do not default copy
constructor and assignment on first declaration.
* include/std/utility (exchange): Forward to __exchange.
* testsuite/27_io/basic_filebuf/cons/char/copy_neg.cc: New.
* src/c++11/Makefile.am: Add stream-related files.
* src/c++11/Makefile.in: Regenerate.
* src/c++11/ext11-inst.cc (stdio_filebuf, stdio_sync_filebuf):
New file for explicit instantiation definitions.
* src/c++11/ios.cc: Move from src/c++98 to here.
(ios_base::_M_move, ios_base::_M_swap): Define.
* src/c++11/ios-inst.cc: Move from src/c++98 to here.
* src/c++11/iostream-inst.cc: Likewise.
* src/c++11/istream-inst.cc: Likewise.
* src/c++11/ostream-inst.cc: Likewise.
* src/c++11/sstream-inst.cc: Likewise.
* src/c++11/streambuf-inst.cc: Likewise.
* src/c++98/Makefile.am: Remove stream-related files.
* src/c++98/Makefile.in: Regenerate.
* src/c++98/ext-inst.cc (stdio_filebuf): Remove explicit
instantiations.
* src/c++98/misc-inst.cc (stdio_sync_filebuf): Likewise.
* src/c++98/ios-inst.cc: Move to src/c++11/.
* src/c++98/ios.cc: Move to src/c++11/.
* src/c++98/iostream-inst.cc: Likewise.
* src/c++98/istream-inst.cc: Likewise.
* src/c++98/ostream-inst.cc: Likewise.
* src/c++98/sstream-inst.cc: Likewise.
* src/c++98/streambuf-inst.cc: Likewise.
* testsuite/27_io/basic_filebuf/cons/char/copy_neg.cc: New.
* testsuite/27_io/basic_fstream/cons/move.cc: New.
* testsuite/27_io/basic_fstream/assign/1.cc: New.
* testsuite/27_io/basic_ifstream/cons/move.cc: New.
* testsuite/27_io/basic_ifstream/assign/1.cc: New.
* testsuite/27_io/basic_istringstream/assign/1.cc: New.
* testsuite/27_io/basic_istringstream/cons/move.cc: New.
* testsuite/27_io/basic_ofstream/cons/move.cc: New.
* testsuite/27_io/basic_ofstream/assign/1.cc: New.
* testsuite/27_io/basic_ostringstream/assign/1.cc: New.
* testsuite/27_io/basic_ostringstream/cons/move.cc: New.
* testsuite/27_io/basic_stringstream/assign/1.cc: New.
* testsuite/27_io/basic_stringstream/cons/move.cc: New.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@215463 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libstdc++-v3/testsuite')
13 files changed, 1066 insertions, 0 deletions
diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/cons/char/copy_neg.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/cons/char/copy_neg.cc new file mode 100644 index 00000000000..2080a9b60e2 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/cons/char/copy_neg.cc @@ -0,0 +1,28 @@ +// { dg-options "-std=gnu++11" } +// { dg-do compile } + +// Copyright (C) 2014 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 <fstream> + +void test() +{ + std::filebuf f; + std::filebuf ff(f); // { dg-error "deleted function" } + ff = f; // { dg-error "deleted function" } +} diff --git a/libstdc++-v3/testsuite/27_io/basic_fstream/assign/1.cc b/libstdc++-v3/testsuite/27_io/basic_fstream/assign/1.cc new file mode 100644 index 00000000000..84947d0a7fd --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_fstream/assign/1.cc @@ -0,0 +1,88 @@ +// Copyright (C) 2014 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/>. + +// { dg-options "-std=gnu++11" } +// { dg-require-fileio "" } + +// 27.9.1.16 Assign and swap [fstream.assign] + +#include <fstream> +#include <string> +#include <testsuite_hooks.h> + +using namespace std; + +string const name = "fstream-assign.txt"; + +void +test01() +{ + string orig = "Let the whole outside world consist of a long paper tape."; + { + fstream f(name, ios::in|ios::out|ios::trunc); + VERIFY( f.is_open() ); + f << orig; + fstream f1; + f1 = std::move(f); + VERIFY( f1.is_open() ); + VERIFY( !f.is_open() ); + f1.seekg(0); + string result; + getline(f1, result); + VERIFY( result == orig ); + } + { + fstream f(name, ios::in); + VERIFY( f.is_open() ); + fstream f1; + f1.swap(f); + VERIFY( f1.is_open() ); + VERIFY( !f.is_open() ); + string result; + getline(f1, result); + VERIFY( result == orig ); + } + { + fstream f(name, ios::in); + VERIFY( f.is_open() ); + fstream f1; + swap(f1, f); + VERIFY( f1.is_open() ); + VERIFY( !f.is_open() ); + string result; + getline(f1, result); + VERIFY( result == orig ); + } +} + +void +test02() +{ +#ifdef _GLIBCXX_USE_WCHAR_T + wfstream f, f2; + f2 = std::move(f); + f2.swap(f); + swap(f2, f); +#endif +} + +int +main() +{ + test01(); + test02(); +} diff --git a/libstdc++-v3/testsuite/27_io/basic_fstream/cons/move.cc b/libstdc++-v3/testsuite/27_io/basic_fstream/cons/move.cc new file mode 100644 index 00000000000..1805e52f67e --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_fstream/cons/move.cc @@ -0,0 +1,70 @@ +// Copyright (C) 2014 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/>. + +// { dg-options "-std=gnu++11" } +// { dg-require-fileio "" } + +// 27.9.1.15 basic_fstream constructors [fstream.cons] + +#include <fstream> +#include <string> +#include <testsuite_hooks.h> + +using namespace std; + +std::string const name = "fstream-move.txt"; + +void +test01() +{ + string orig = "Let the whole outside world consist of a long paper tape."; + fstream f(name, ios::in|ios::out|ios::trunc); + VERIFY( f.is_open() ); + f << orig; + fstream f1 = std::move(f); + VERIFY( f1.is_open() ); + VERIFY( !f.is_open() ); + f1.seekg(0); + string result; + getline(f1, result); + VERIFY( result == orig ); +} + +void +test02() +{ +#ifdef _GLIBCXX_USE_WCHAR_T + wstring orig = L"Let the whole outside world consist of a long paper tape."; + wfstream f(name, ios::in|ios::out|ios::trunc); + VERIFY( f.is_open() ); + f << orig; + wfstream f1 = std::move(f); + VERIFY( f1.is_open() ); + VERIFY( !f.is_open() ); + f1.seekg(0); + wstring result; + getline(f1, result); + VERIFY( result == orig ); +#endif +} + +int +main() +{ + test01(); + test02(); +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ifstream/assign/1.cc b/libstdc++-v3/testsuite/27_io/basic_ifstream/assign/1.cc new file mode 100644 index 00000000000..e652d47b431 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ifstream/assign/1.cc @@ -0,0 +1,85 @@ +// Copyright (C) 2014 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/>. + +// { dg-options "-std=gnu++11" } +// { dg-require-fileio "" } + +// 27.9.1.8 Assign and swap [ifstream.assign] + +#include <fstream> +#include <sstream> +#include <testsuite_hooks.h> + +void +read(std::istream& in, std::ostream& out) +{ + std::string s; + for (int i=0; i < 10; ++i) + { + getline(in, s); + out << s << '\n'; + } +} + +void +test01() +{ + std::string const name = "thirty_years_among_the_dead_preproc.txt"; + std::ostringstream ss0; + { + std::ifstream f0(name); + read(f0, ss0); + } + { + std::ifstream f0(name); + std::ifstream f1; + f1 = std::move(f0); + VERIFY( !f0.is_open() ); + VERIFY( f1.is_open() ); + std::ostringstream ss1; + read(f1, ss1); + VERIFY( ss0.str() == ss1.str() ); + } + { + std::ifstream f0(name); + std::ifstream f1; + f1.swap(f0); + VERIFY( !f0.is_open() ); + VERIFY( f1.is_open() ); + std::ostringstream ss1; + read(f1, ss1); + VERIFY( ss0.str() == ss1.str() ); + } +} + +void +test02() +{ +#ifdef _GLIBCXX_USE_WCHAR_T + std::wifstream f, f2; + f2 = std::move(f); + f2.swap(f); + swap(f2, f); +#endif +} + +int +main() +{ + test01(); + test02(); +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ifstream/cons/move.cc b/libstdc++-v3/testsuite/27_io/basic_ifstream/cons/move.cc new file mode 100644 index 00000000000..afa2a62696a --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ifstream/cons/move.cc @@ -0,0 +1,71 @@ +// Copyright (C) 2014 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/>. + +// { dg-options "-std=gnu++11" } +// { dg-require-fileio "" } + +// 27.9.1.7 basic_ifstream constructors [ifstream.cons] + +#include <fstream> +#include <sstream> +#include <testsuite_hooks.h> + +void +read(std::istream& in, std::ostream& out) +{ + std::string s; + for (int i=0; i < 10; ++i) + { + getline(in, s); + out << s << '\n'; + } +} + +void +test01() +{ + std::string const name = "thirty_years_among_the_dead_preproc.txt"; + std::ostringstream ss0; + { + std::ifstream f0(name); + read(f0, ss0); + } + std::ifstream f0(name); + std::ifstream f1 = std::move(f0); + VERIFY( !f0.is_open() ); + VERIFY( f1.is_open() ); + std::ostringstream ss1; + read(f1, ss1); + VERIFY( ss0.str() == ss1.str() ); +} + +void +test02() +{ +#ifdef _GLIBCXX_USE_WCHAR_T + std::wifstream f0("thirty_years_among_the_dead_preproc.txt"); + std::wifstream f1 = std::move(f0); + VERIFY( f1.is_open() ); +#endif +} + +int +main() +{ + test01(); + test02(); +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istringstream/assign/1.cc b/libstdc++-v3/testsuite/27_io/basic_istringstream/assign/1.cc new file mode 100644 index 00000000000..a9ae2ae9eba --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istringstream/assign/1.cc @@ -0,0 +1,97 @@ +// { dg-options "-std=gnu++11" } + +// Copyright (C) 2014 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.3.2 Assign and swap [istringstream.assign] + +#include <sstream> +#include <string> +#include <testsuite_hooks.h> + +void +test01() +{ + std::istringstream s1("absence of a signal"); + std::string s; + s1 >> s; + + std::istringstream s2; + s2 = std::move(s1); + s2 >> s; + VERIFY(s == "of"); + + std::istringstream s3; + s3.swap(s2); + s3 >> s; + VERIFY(s == "a"); + + swap(s1, s3); + s1 >> s; + VERIFY(s == "signal"); + + s2.str("should never be used as a signal"); + s1 = std::move(s2); + getline(s1, s); + VERIFY(s == "should never be used as a signal"); + s3 = std::move(s1); + VERIFY(s3.eof()); +} + +void test02() +{ + std::istringstream s0{ " 1234.5 " }; + std::istringstream s; + s = std::move(s0); + char c{}; + s >> c; + VERIFY( c == '1' ); + int i{}; + s >> i; + VERIFY( i == 234 ); + double d{}; + s >> d; + VERIFY( d == .5 ); +} + +void test03() +{ +#ifdef _GLIBCXX_USE_WCHAR_T + std::wistringstream s0{ L" 1234.5 " }; + std::wistringstream s; + s = std::move(s0); + s.swap(s0); + swap(s, s0); + wchar_t c{}; + s >> c; + VERIFY( c == L'1' ); + int i{}; + s >> i; + VERIFY( i == 234 ); + double d{}; + s >> d; + VERIFY( d == .5 ); +#endif +} + +int +main() +{ + test01(); + test02(); + test03(); +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istringstream/cons/move.cc b/libstdc++-v3/testsuite/27_io/basic_istringstream/cons/move.cc new file mode 100644 index 00000000000..77c1fbb2afe --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istringstream/cons/move.cc @@ -0,0 +1,94 @@ +// { dg-options "-std=gnu++11" } + +// Copyright (C) 2014 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.3.1 basic_istringstream constructors [istringstream.cons] + +#include <sstream> +#include <string> +#include <testsuite_hooks.h> + +void +test01() +{ + std::istringstream s1("absence of a signal"); + std::string s; + s1 >> s; + + std::istringstream s2 = std::move(s1); + s2 >> s; + VERIFY(s == "of"); + + std::istringstream s3; + s3 = std::move(s2); + s3 >> s; + VERIFY(s == "a"); + + s1 = std::move(s3); + s1 >> s; + VERIFY(s == "signal"); + + s2.str("should never be used as a signal"); + s1 = std::move(s2); + getline(s1, s); + VERIFY(s == "should never be used as a signal"); + s3 = std::move(s1); + VERIFY(s3.eof()); +} + +void +test02() +{ + std::istringstream s0{ " 1234.5 " }; + std::istringstream s{ std::move(s0) }; + char c{}; + s >> c; + VERIFY( c == '1' ); + int i{}; + s >> i; + VERIFY( i == 234 ); + double d{}; + s >> d; + VERIFY( d == .5 ); +} + +void +test03() +{ +#ifdef _GLIBCXX_USE_WCHAR_T + std::wistringstream s0{ L" 1234.5 " }; + std::wistringstream s{ std::move(s0) }; + wchar_t c{}; + s >> c; + VERIFY( c == L'1' ); + int i{}; + s >> i; + VERIFY( i == 234 ); + double d{}; + s >> d; + VERIFY( d == .5 ); +#endif +} + +int +main() +{ + test01(); + test02(); + test03(); +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ofstream/assign/1.cc b/libstdc++-v3/testsuite/27_io/basic_ofstream/assign/1.cc new file mode 100644 index 00000000000..7092ebe64a5 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ofstream/assign/1.cc @@ -0,0 +1,74 @@ +// Copyright (C) 2014 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/>. + +// { dg-options "-std=gnu++11" } +// { dg-require-fileio "" } + +// 27.9.1.12 Assign and swap [ostringstream.assign] + +#include <fstream> +#include <string> +#include <testsuite_hooks.h> + +using namespace std; + +string const name = "ofstream-assign.txt"; + +void +test01() +{ + string s1 = "Let the whole outside world"; + string s2 = " consist of a long paper tape."; + ofstream f(name, ios::trunc); + VERIFY( f.is_open() ); + f << s1; + { + ofstream f1; + f1 = std::move(f); + VERIFY( f1.is_open() ); + VERIFY( !f.is_open() ); + f1 << s2; + f1.swap(f); + VERIFY( !f1.is_open() ); + VERIFY( f.is_open() ); + f << s1; + swap(f1, f); + f1 << s2; + } + ifstream in(name); + string result; + getline(in, result); + VERIFY( result == (s1 + s2 + s1 + s2) ); +} + +void +test02() +{ +#ifdef _GLIBCXX_USE_WCHAR_T + std::wofstream s0, s; + s = std::move(s0); + s.swap(s0); + swap(s, s0); +#endif +} + +int +main() +{ + test01(); + test02(); +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ofstream/cons/move.cc b/libstdc++-v3/testsuite/27_io/basic_ofstream/cons/move.cc new file mode 100644 index 00000000000..a6dca710132 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ofstream/cons/move.cc @@ -0,0 +1,78 @@ +// Copyright (C) 2014 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/>. + +// { dg-options "-std=gnu++11" } +// { dg-require-fileio "" } + +// 27.9.1.11 basic_ofstream constructors [ofstream.cons] + +#include <fstream> +#include <string> +#include <testsuite_hooks.h> + +using namespace std; + +std::string const name = "ofstream-move.txt"; + +void +test01() +{ + string s1 = "Let the whole outside world"; + string s2 = " consist of a long paper tape."; + ofstream f(name, ios::trunc); + VERIFY( f.is_open() ); + f << s1; + { + ofstream f1 = std::move(f); + VERIFY( f1.is_open() ); + VERIFY( !f.is_open() ); + f1 << s2; + } + ifstream in(name); + string result; + getline(in, result); + VERIFY( result == (s1 + s2) ); +} + +void +test02() +{ +#ifdef _GLIBCXX_USE_WCHAR_T + wstring s1 = L"Let the whole outside world"; + wstring s2 = L" consist of a long paper tape."; + wofstream f(name, ios::trunc); + VERIFY( f.is_open() ); + f << s1; + { + wofstream f1 = std::move(f); + VERIFY( f1.is_open() ); + VERIFY( !f.is_open() ); + f1 << s2; + } + wifstream in(name); + wstring result; + getline(in, result); + VERIFY( result == (s1 + s2) ); +#endif +} + +int +main() +{ + test01(); + test02(); +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostringstream/assign/1.cc b/libstdc++-v3/testsuite/27_io/basic_ostringstream/assign/1.cc new file mode 100644 index 00000000000..01b92e9e3d1 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostringstream/assign/1.cc @@ -0,0 +1,117 @@ +// { dg-options "-std=gnu++11" } + +// Copyright (C) 2014 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.4.2 Assign and swap [ostringstream.assign] + +#include <sstream> +#include <string> +#include <testsuite_hooks.h> + +const std::string strings[] = { + "one could carry out the description of a machine, ", + "no matter how complicated, ", + "in characters which would be merely the letters of the alphabet, and so ", + "provide the mind with a method of knowing the machine and all its parts" +}; + +void +append(std::ostringstream& ss, std::string& s, const std::string& t) +{ + ss << t; + s += t; +} + +// assign +void +test01() +{ + std::string exp; + std::ostringstream s1; + append(s1, exp, strings[0]); + + std::ostringstream s2; + s2 = std::move(s1); + VERIFY( s2.str() == exp ); + append(s2, exp, strings[1]); + VERIFY( s2.str() == exp ); + + std::ostringstream s3; + s3 = std::move(s2); + VERIFY( s3.str() == exp ); + append(s3, exp, strings[2]); + VERIFY( s3.str() == exp ); + + s1.setstate(std::ios::failbit); + s1 = std::move(s3); + VERIFY( s1.good() ); + VERIFY( s1.str() == exp ); + append(s1, exp, strings[3]); + VERIFY( s1.str() == exp ); +} + +// swap +void +test02() +{ + std::string exp; + std::ostringstream s1; + append(s1, exp, strings[0]); + + std::ostringstream s2; + s2.swap(s1); + VERIFY( s1.str().empty() ); + VERIFY( s2.str() == exp ); + append(s2, exp, strings[1]); + VERIFY( s2.str() == exp ); + + std::ostringstream s3; + swap(s3, s2); + VERIFY( s2.str().empty() ); + VERIFY( s3.str() == exp ); + append(s3, exp, strings[2]); + VERIFY( s3.str() == exp ); + + s1.setstate(std::ios::failbit); + swap(s1, s3); + VERIFY( s1.good() ); + VERIFY( s3.fail() ); + VERIFY( s2.str().empty() ); + VERIFY( s1.str() == exp ); + append(s1, exp, strings[3]); + VERIFY( s1.str() == exp ); +} + +void +test03() +{ +#ifdef _GLIBCXX_USE_WCHAR_T + std::wistringstream s0, s; + s = std::move(s0); + s.swap(s0); + swap(s, s0); +#endif +} + +int +main() +{ + test01(); + test02(); + test03(); +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostringstream/cons/move.cc b/libstdc++-v3/testsuite/27_io/basic_ostringstream/cons/move.cc new file mode 100644 index 00000000000..26ccf1a8bcc --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostringstream/cons/move.cc @@ -0,0 +1,82 @@ +// { dg-options "-std=gnu++11" } + +// Copyright (C) 2014 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.4.1 basic_ostringstream constructors [ostringstream.cons] + +#include <sstream> +#include <string> +#include <testsuite_hooks.h> + +const std::string strings[] = { + "one could carry out the description of a machine, ", + "no matter how complicated, ", + "in characters which would be merely the letters of the alphabet, and so ", + "provide the mind with a method of knowing the machine and all its parts" +}; + +void +append(std::ostringstream& ss, std::string& s, const std::string& t) +{ + ss << t; + s += t; +} + +void +test01() +{ + std::string exp; + std::ostringstream s1; + append(s1, exp, strings[0]); + + std::ostringstream s2 = std::move(s1); + VERIFY( s2.good() ); + VERIFY( s2.rdbuf() != nullptr ); + VERIFY( s2.str() == exp ); + append(s2, exp, strings[1]); + VERIFY( s2.str() == exp ); + + std::ostringstream s3 = std::move(s2); + VERIFY( s3.good() ); + VERIFY( s3.rdbuf() != nullptr ); + VERIFY( s3.str() == exp ); + append(s3, exp, strings[2]); + VERIFY( s3.str() == exp ); + + s1.str(""); + s1.clear(); + exp.clear(); + append(s1, exp, strings[3]); + VERIFY( s1.str() == exp ); +} + +void +test02() +{ +#ifdef _GLIBCXX_USE_WCHAR_T + std::wostringstream s1; + std::wostringstream s2 = std::move(s1); +#endif +} + +int +main() +{ + test01(); + test02(); +} diff --git a/libstdc++-v3/testsuite/27_io/basic_stringstream/assign/1.cc b/libstdc++-v3/testsuite/27_io/basic_stringstream/assign/1.cc new file mode 100644 index 00000000000..0465461c7cb --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringstream/assign/1.cc @@ -0,0 +1,100 @@ +// { dg-options "-std=gnu++11" } + +// Copyright (C) 2014 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.5.2 Assign and swap [stringstream.assign] + +#include <sstream> +#include <string> +#include <testsuite_hooks.h> + +void +test01() +{ + std::stringstream s1; + s1 << "absence of a signal"; + std::string s; + s1 >> s; + + std::stringstream s2; + s2 = std::move(s1); + s2 >> s; + VERIFY(s == "of"); + + std::stringstream s3; + s3.swap(s2); + s3 >> s; + VERIFY(s == "a"); + + swap(s1, s3); + s1 >> s; + VERIFY(s == "signal"); + + s2 << "should never be used as a signal"; + s1 = std::move(s2); + getline(s1, s); + VERIFY(s == "should never be used as a signal"); + s3 = std::move(s1); + VERIFY(s3.eof()); +} + +void test02() +{ + std::stringstream s0; + s0 << " 1234.5 "; + std::stringstream s; + s = std::move(s0); + char c{}; + s >> c; + VERIFY( c == '1' ); + int i{}; + s >> i; + VERIFY( i == 234 ); + double d{}; + s >> d; + VERIFY( d == .5 ); +} + +void test03() +{ +#ifdef _GLIBCXX_USE_WCHAR_T + std::wstringstream s0; + s0 << L" 1234.5 "; + std::wstringstream s; + s = std::move(s0); + s.swap(s0); + swap(s, s0); + wchar_t c{}; + s >> c; + VERIFY( c == L'1' ); + int i{}; + s >> i; + VERIFY( i == 234 ); + double d{}; + s >> d; + VERIFY( d == .5 ); +#endif +} + +int +main() +{ + test01(); + test02(); + test03(); +} diff --git a/libstdc++-v3/testsuite/27_io/basic_stringstream/cons/move.cc b/libstdc++-v3/testsuite/27_io/basic_stringstream/cons/move.cc new file mode 100644 index 00000000000..3991e7c72a0 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringstream/cons/move.cc @@ -0,0 +1,82 @@ +// { dg-options "-std=gnu++11" } + +// Copyright (C) 2014 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.5.1 basic_stringstream constructors [stringstream.cons] + +#include <sstream> +#include <string> +#include <testsuite_hooks.h> + +const std::string strings[] = { + "one could carry out the description of a machine, ", + "no matter how complicated, ", + "in characters which would be merely the letters of the alphabet, and so ", + "provide the mind with a method of knowing the machine and all its parts" +}; + +void +append(std::stringstream& ss, std::string& s, const std::string& t) +{ + ss << t; + s += t; +} + +void +test01() +{ + std::string exp; + std::stringstream s1; + append(s1, exp, strings[0]); + + std::stringstream s2 = std::move(s1); + VERIFY( s2.good() ); + VERIFY( s2.rdbuf() != nullptr ); + VERIFY( s2.str() == exp ); + append(s2, exp, strings[1]); + VERIFY( s2.str() == exp ); + + std::stringstream s3 = std::move(s2); + VERIFY( s3.good() ); + VERIFY( s3.rdbuf() != nullptr ); + VERIFY( s3.str() == exp ); + append(s3, exp, strings[2]); + VERIFY( s3.str() == exp ); + + s1.str(""); + s1.clear(); + exp.clear(); + append(s1, exp, strings[3]); + VERIFY( s1.str() == exp ); +} + +void +test02() +{ +#ifdef _GLIBCXX_USE_WCHAR_T + std::wstringstream s1; + std::wstringstream s2 = std::move(s1); +#endif +} + +int +main() +{ + test01(); + test02(); +} |