From ca994c1972d87939d60f5899e51bf3a43bc59cd8 Mon Sep 17 00:00:00 2001 From: boris Date: Wed, 5 Jun 2019 00:19:53 +0200 Subject: [PATCH] fix move assignment operators for basic_[io]pstream --- include/boost/process/pipe.hpp | 9 ++- test/pipe.cpp | 106 ++++++++++++++++++++++++++++++++- 2 files changed, 111 insertions(+), 4 deletions(-) diff --git a/include/boost/process/pipe.hpp b/include/boost/process/pipe.hpp index 2040c78e..f73ac060 100644 --- a/include/boost/process/pipe.hpp +++ b/include/boost/process/pipe.hpp @@ -340,8 +340,9 @@ public: basic_ipstream& operator=(basic_ipstream && lhs) { std::basic_istream::operator=(std::move(lhs)); - _buf = std::move(lhs); + _buf = std::move(lhs._buf); std::basic_istream::rdbuf(&_buf); + return *this; }; ///Move assignment of a pipe. basic_ipstream& operator=(pipe_type && p) @@ -448,8 +449,9 @@ public: basic_opstream& operator=(basic_opstream && lhs) { std::basic_ostream::operator=(std::move(lhs)); - _buf = std::move(lhs); + _buf = std::move(lhs._buf); std::basic_ostream::rdbuf(&_buf); + return *this; }; ///Move assignment of a pipe. @@ -556,8 +558,9 @@ public: basic_pstream& operator=(basic_pstream && lhs) { std::basic_istream::operator=(std::move(lhs)); - _buf = std::move(lhs); + _buf = std::move(lhs._buf); std::basic_iostream::rdbuf(&_buf); + return *this; }; ///Move assignment of a pipe. basic_pstream& operator=(pipe_type && p) diff --git a/test/pipe.cpp b/test/pipe.cpp index 809ebb94..cb0caf8d 100644 --- a/test/pipe.cpp +++ b/test/pipe.cpp @@ -102,6 +102,110 @@ BOOST_AUTO_TEST_CASE(stream, *boost::unit_test::timeout(2)) BOOST_CHECK_EQUAL(i, j); } +BOOST_AUTO_TEST_CASE(stream_move, *boost::unit_test::timeout(2)) +{ + + bp::pipe pipe; + + bp::pstream os(pipe); + bp::ipstream is(pipe); + + int i = 42, j = 0, k = 0; + + os << i << std::endl; + os << std::endl; + is >> j; + + BOOST_CHECK_EQUAL(i, j); + + bp::pstream os2 = std::move(os); + bp::ipstream is2 = std::move(is); + os2 << i << std::endl; + os2 << std::endl; + is2 >> k; + + BOOST_CHECK_EQUAL(i, k); +} + +BOOST_AUTO_TEST_CASE(ostream_move, *boost::unit_test::timeout(2)) +{ + + bp::pipe pipe; + + bp::opstream os(pipe); + bp::ipstream is(pipe); + + int i = 42, j = 0, k = 0; + + os << i << std::endl; + os << std::endl; + is >> j; + + BOOST_CHECK_EQUAL(i, j); + + bp::opstream os2 = std::move(os); + bp::ipstream is2 = std::move(is); + os2 << i << std::endl; + os2 << std::endl; + is2 >> k; + + BOOST_CHECK_EQUAL(i, k); +} + +BOOST_AUTO_TEST_CASE(stream_move_assignment, *boost::unit_test::timeout(2)) +{ + + bp::pipe pipe; + + bp::pstream os(pipe); + bp::ipstream is(pipe); + + int i = 42, j = 0, k = 0; + + os << i << std::endl; + os << std::endl; + is >> j; + + BOOST_CHECK_EQUAL(i, j); + + bp::pstream os2; + os2 = std::move(os); + bp::ipstream is2; + is2 = std::move(is); + os2 << i << std::endl; + os2 << std::endl; + is2 >> k; + + BOOST_CHECK_EQUAL(i, k); +} + +BOOST_AUTO_TEST_CASE(ostream_move_assignment, *boost::unit_test::timeout(2)) +{ + + bp::pipe pipe; + + bp::opstream os(pipe); + bp::ipstream is(pipe); + + int i = 42, j = 0, k = 0; + + os << i << std::endl; + os << std::endl; + is >> j; + + BOOST_CHECK_EQUAL(i, j); + + bp::opstream os2; + os2 = std::move(os); + bp::ipstream is2; + is2 = std::move(is); + os2 << i << std::endl; + os2 << std::endl; + is2 >> k; + + BOOST_CHECK_EQUAL(i, k); +} + BOOST_AUTO_TEST_CASE(stream_line, *boost::unit_test::timeout(2)) { @@ -268,4 +372,4 @@ BOOST_AUTO_TEST_CASE(stream_close_scope, *boost::unit_test::timeout(5)) } -BOOST_AUTO_TEST_SUITE_END(); \ No newline at end of file +BOOST_AUTO_TEST_SUITE_END();