| 1 | // (C) Copyright 2008 CodeRage, LLC (turkanis at coderage dot com) |
| 2 | // (C) Copyright 2004-2007 Jonathan Turkanis |
| 3 | // Distributed under the Boost Software License, Version 1.0. (See accompanying |
| 4 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.) |
| 5 | |
| 6 | // See http://www.boost.org/libs/iostreams for documentation. |
| 7 | |
| 8 | #ifndef BOOST_IOSTREAMS_TEST_WRITE_BIDIRECTIONAL_HPP_INCLUDED |
| 9 | #define BOOST_IOSTREAMS_TEST_WRITE_BIDIRECTIONAL_HPP_INCLUDED |
| 10 | |
| 11 | #include <fstream> |
| 12 | #include <boost/iostreams/combine.hpp> |
| 13 | #include <boost/iostreams/device/file.hpp> |
| 14 | #include <boost/iostreams/filtering_stream.hpp> |
| 15 | #include <boost/test/test_tools.hpp> |
| 16 | #include "detail/temp_file.hpp" |
| 17 | #include "detail/verification.hpp" |
| 18 | |
| 19 | void write_bidirectional_test() |
| 20 | { |
| 21 | using namespace std; |
| 22 | using namespace boost; |
| 23 | using namespace boost::iostreams; |
| 24 | using namespace boost::iostreams::test; |
| 25 | |
| 26 | test_file test; |
| 27 | |
| 28 | { |
| 29 | temp_file dest; |
| 30 | temp_file src; // Dummy; |
| 31 | filtering_stream<bidirectional> out( |
| 32 | combine(in: file_source(src.name()), out: file_sink(dest.name(), out_mode)), 0 |
| 33 | ); |
| 34 | write_data_in_chars(os&: out); |
| 35 | out.reset(); |
| 36 | BOOST_CHECK_MESSAGE( |
| 37 | compare_files(dest.name(), test.name()), |
| 38 | "failed writing to filtering_stream<bidirectional> in chars " |
| 39 | "with no buffer" |
| 40 | ); |
| 41 | } |
| 42 | |
| 43 | { |
| 44 | temp_file dest; |
| 45 | temp_file src; // Dummy; |
| 46 | filtering_stream<bidirectional> out( |
| 47 | combine(in: file_source(src.name()), out: file_sink(dest.name(), out_mode)), 0 |
| 48 | ); |
| 49 | write_data_in_chunks(os&: out); |
| 50 | out.reset(); |
| 51 | BOOST_CHECK_MESSAGE( |
| 52 | compare_files(dest.name(), test.name()), |
| 53 | "failed writing to filtering_stream<bidirectional> in chunks " |
| 54 | "with no buffer" |
| 55 | ); |
| 56 | } |
| 57 | |
| 58 | { |
| 59 | temp_file dest; |
| 60 | temp_file src; // Dummy; |
| 61 | filtering_stream<bidirectional> out( |
| 62 | combine(in: file_source(src.name()), out: file_sink(dest.name(), out_mode)) |
| 63 | ); |
| 64 | write_data_in_chars(os&: out); |
| 65 | out.reset(); |
| 66 | BOOST_CHECK_MESSAGE( |
| 67 | compare_files(dest.name(), test.name()), |
| 68 | "failed writing to filtering_stream<bidirectional> in chars " |
| 69 | "with large buffer" |
| 70 | ); |
| 71 | } |
| 72 | |
| 73 | { |
| 74 | temp_file dest; |
| 75 | temp_file src; // Dummy; |
| 76 | filtering_stream<bidirectional> out( |
| 77 | combine(in: file_source(src.name()), out: file_sink(dest.name(), out_mode)) |
| 78 | ); |
| 79 | write_data_in_chunks(os&: out); |
| 80 | out.reset(); |
| 81 | BOOST_CHECK_MESSAGE( |
| 82 | compare_files(dest.name(), test.name()), |
| 83 | "failed writing to filtering_stream<bidirectional> in chunks " |
| 84 | "with large buffer" |
| 85 | ); |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | #endif // #ifndef BOOST_IOSTREAMS_TEST_WRITE_BIDIRECTIONAL_HPP_INCLUDED |
| 90 | |