| 1 | // (C) Copyright Jonathan Turkanis 2004 |
|---|
| 2 | // Distributed under the Boost Software License, Version 1.0. (See accompanying |
|---|
| 3 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.) |
|---|
| 4 | |
|---|
| 5 | // See http://www.boost.org/libs/iostreams for documentation. |
|---|
| 6 | |
|---|
| 7 | #include <fstream> |
|---|
| 8 | #include <boost/iostreams/device/file.hpp> |
|---|
| 9 | #include <boost/iostreams/filtering_stream.hpp> |
|---|
| 10 | #include <boost/iostreams/tee.hpp> |
|---|
| 11 | #include <boost/test/test_tools.hpp> |
|---|
| 12 | #include <boost/test/unit_test.hpp> |
|---|
| 13 | #include "detail/temp_file.hpp" |
|---|
| 14 | #include "detail/verification.hpp" |
|---|
| 15 | |
|---|
| 16 | using namespace std; |
|---|
| 17 | using namespace boost; |
|---|
| 18 | using namespace boost::iostreams; |
|---|
| 19 | using namespace boost::iostreams::test; |
|---|
| 20 | using boost::unit_test::test_suite; |
|---|
| 21 | |
|---|
| 22 | void tee_test() |
|---|
| 23 | { |
|---|
| 24 | { |
|---|
| 25 | temp_file dest1; |
|---|
| 26 | temp_file dest2; |
|---|
| 27 | filtering_ostream out; |
|---|
| 28 | out.push(tee(file_sink(dest1.name(), out_mode))); |
|---|
| 29 | out.push(file_sink(dest2.name(), out_mode)); |
|---|
| 30 | write_data_in_chars(out); |
|---|
| 31 | out.reset(); |
|---|
| 32 | BOOST_CHECK_MESSAGE( |
|---|
| 33 | compare_files(dest1.name(), dest2.name()), |
|---|
| 34 | "failed writing to a tee_filter in chars" |
|---|
| 35 | ); |
|---|
| 36 | } |
|---|
| 37 | |
|---|
| 38 | { |
|---|
| 39 | temp_file dest1; |
|---|
| 40 | temp_file dest2; |
|---|
| 41 | filtering_ostream out; |
|---|
| 42 | out.push(tee(file_sink(dest1.name(), out_mode))); |
|---|
| 43 | out.push(file_sink(dest2.name(), out_mode)); |
|---|
| 44 | write_data_in_chunks(out); |
|---|
| 45 | out.reset(); |
|---|
| 46 | BOOST_CHECK_MESSAGE( |
|---|
| 47 | compare_files(dest1.name(), dest2.name()), |
|---|
| 48 | "failed writing to a tee_filter in chunks" |
|---|
| 49 | ); |
|---|
| 50 | } |
|---|
| 51 | |
|---|
| 52 | { |
|---|
| 53 | temp_file dest1; |
|---|
| 54 | temp_file dest2; |
|---|
| 55 | filtering_ostream out; |
|---|
| 56 | out.push( tee( file_sink(dest1.name(), out_mode), |
|---|
| 57 | file_sink(dest2.name(), out_mode) ) ); |
|---|
| 58 | write_data_in_chars(out); |
|---|
| 59 | out.reset(); |
|---|
| 60 | BOOST_CHECK_MESSAGE( |
|---|
| 61 | compare_files(dest1.name(), dest2.name()), |
|---|
| 62 | "failed writing to a tee_device in chars" |
|---|
| 63 | ); |
|---|
| 64 | } |
|---|
| 65 | |
|---|
| 66 | { |
|---|
| 67 | temp_file dest1; |
|---|
| 68 | temp_file dest2; |
|---|
| 69 | filtering_ostream out; |
|---|
| 70 | out.push( tee( file_sink(dest1.name(), out_mode), |
|---|
| 71 | file_sink(dest2.name(), out_mode) ) ); |
|---|
| 72 | write_data_in_chunks(out); |
|---|
| 73 | out.reset(); |
|---|
| 74 | BOOST_CHECK_MESSAGE( |
|---|
| 75 | compare_files(dest1.name(), dest2.name()), |
|---|
| 76 | "failed writing to a tee_device in chunks" |
|---|
| 77 | ); |
|---|
| 78 | } |
|---|
| 79 | } |
|---|
| 80 | |
|---|
| 81 | test_suite* init_unit_test_suite(int, char* []) |
|---|
| 82 | { |
|---|
| 83 | test_suite* test = BOOST_TEST_SUITE("tee test"); |
|---|
| 84 | test->add(BOOST_TEST_CASE(&tee_test)); |
|---|
| 85 | return test; |
|---|
| 86 | } |
|---|