|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r83505 - in trunk: boost/iostreams libs/iostreams/test
From: steven_at_[hidden]
Date: 2013-03-20 11:45:42
Author: steven_watanabe
Date: 2013-03-20 11:45:41 EDT (Wed, 20 Mar 2013)
New Revision: 83505
URL: http://svn.boost.org/trac/boost/changeset/83505
Log:
Make tee work correctly for std::streams. Fixes #8315.
Text files modified:
trunk/boost/iostreams/tee.hpp | 16 +++++++++++
trunk/libs/iostreams/test/tee_test.cpp | 56 ++++++++++++++++++++++++++++++++++++++++
2 files changed, 72 insertions(+), 0 deletions(-)
Modified: trunk/boost/iostreams/tee.hpp
==============================================================================
--- trunk/boost/iostreams/tee.hpp (original)
+++ trunk/boost/iostreams/tee.hpp 2013-03-20 11:45:41 EDT (Wed, 20 Mar 2013)
@@ -204,10 +204,26 @@
};
template<typename Sink>
+tee_filter<Sink> tee(Sink& snk)
+{ return tee_filter<Sink>(snk); }
+
+template<typename Sink>
tee_filter<Sink> tee(const Sink& snk)
{ return tee_filter<Sink>(snk); }
template<typename Device, typename Sink>
+tee_device<Device, Sink> tee(Device& dev, Sink& sink)
+{ return tee_device<Device, Sink>(dev, sink); }
+
+template<typename Device, typename Sink>
+tee_device<Device, Sink> tee(const Device& dev, Sink& sink)
+{ return tee_device<Device, Sink>(dev, sink); }
+
+template<typename Device, typename Sink>
+tee_device<Device, Sink> tee(Device& dev, const Sink& sink)
+{ return tee_device<Device, Sink>(dev, sink); }
+
+template<typename Device, typename Sink>
tee_device<Device, Sink> tee(const Device& dev, const Sink& sink)
{ return tee_device<Device, Sink>(dev, sink); }
Modified: trunk/libs/iostreams/test/tee_test.cpp
==============================================================================
--- trunk/libs/iostreams/test/tee_test.cpp (original)
+++ trunk/libs/iostreams/test/tee_test.cpp 2013-03-20 11:45:41 EDT (Wed, 20 Mar 2013)
@@ -240,6 +240,62 @@
}
}
+void test_std_io()
+{
+ {
+ temp_file dest1;
+ temp_file dest2;
+ filtering_ostream out;
+ std::ofstream stream1(dest1.name(), out_mode);
+ out.push(tee(stream1));
+ out.push(file_sink(dest2.name(), out_mode));
+ write_data_in_chunks(out);
+ BOOST_CHECK_MESSAGE(
+ compare_files(dest1.name(), dest2.name()),
+ "failed writing to a tee_device in chunks"
+ );
+ }
+ {
+ temp_file dest1;
+ temp_file dest2;
+ filtering_ostream out;
+ std::ofstream stream1(dest1.name(), out_mode);
+ out.push( tee ( stream1,
+ file_sink(dest2.name(), out_mode) ) );
+ write_data_in_chunks(out);
+ BOOST_CHECK_MESSAGE(
+ compare_files(dest1.name(), dest2.name()),
+ "failed writing to a tee_device in chunks"
+ );
+ }
+ {
+ temp_file dest1;
+ temp_file dest2;
+ filtering_ostream out;
+ std::ofstream stream2(dest2.name(), out_mode);
+ out.push( tee ( file_sink(dest1.name(), out_mode),
+ stream2 ) );
+ write_data_in_chunks(out);
+ BOOST_CHECK_MESSAGE(
+ compare_files(dest1.name(), dest2.name()),
+ "failed writing to a tee_device in chunks"
+ );
+ }
+ {
+ temp_file dest1;
+ temp_file dest2;
+ filtering_ostream out;
+ std::ofstream stream1(dest1.name(), out_mode);
+ std::ofstream stream2(dest2.name(), out_mode);
+ out.push(tee(stream1, stream2));
+ write_data_in_chunks(out);
+ BOOST_CHECK_MESSAGE(
+ compare_files(dest1.name(), dest2.name()),
+ "failed writing to a tee_device in chunks"
+ );
+ }
+}
+
void tee_composite_test()
{
// This test is probably redundant, given the above test and the tests in
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk