| 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 | |
| 9 | #ifndef BOOST_IOSTREAMS_TEST_WRITE_SEEKABLE_SEQUENCE_HPP_INCLUDED |
| 10 | #define BOOST_IOSTREAMS_TEST_WRITE_SEEKABLE_SEQUENCE_HPP_INCLUDED |
| 11 | |
| 12 | #include <fstream> |
| 13 | #include <vector> |
| 14 | #include <boost/iostreams/filtering_stream.hpp> |
| 15 | #include <boost/range/iterator_range.hpp> |
| 16 | #include <boost/test/test_tools.hpp> |
| 17 | #include "detail/sequence.hpp" |
| 18 | #include "detail/temp_file.hpp" |
| 19 | #include "detail/verification.hpp" |
| 20 | |
| 21 | void write_seekable_sequence_test() |
| 22 | { |
| 23 | using namespace std; |
| 24 | using namespace boost; |
| 25 | using namespace boost::iostreams; |
| 26 | using namespace boost::iostreams::test; |
| 27 | |
| 28 | test_file test; |
| 29 | |
| 30 | { |
| 31 | vector<char> first(data_reps * data_length(), '?'); |
| 32 | filtering_stream<seekable> out(make_iterator_range(r&: first), 0); |
| 33 | write_data_in_chars(os&: out); |
| 34 | ifstream second(test.name().c_str()); |
| 35 | BOOST_CHECK_MESSAGE( |
| 36 | compare_container_and_stream(first, second), |
| 37 | "failed writing to filtering_stream<seekable> based on a " |
| 38 | "sequence in chars with no buffer" |
| 39 | ); |
| 40 | } |
| 41 | |
| 42 | { |
| 43 | vector<char> first(data_reps * data_length(), '?'); |
| 44 | filtering_stream<seekable> out(make_iterator_range(r&: first), 0); |
| 45 | write_data_in_chunks(os&: out); |
| 46 | ifstream second(test.name().c_str()); |
| 47 | BOOST_CHECK_MESSAGE( |
| 48 | compare_container_and_stream(first, second), |
| 49 | "failed writing to filtering_stream<seekable> based on a " |
| 50 | "sequence in chunks with no buffer" |
| 51 | ); |
| 52 | } |
| 53 | |
| 54 | { |
| 55 | vector<char> first(data_reps * data_length(), '?'); |
| 56 | filtering_stream<seekable> out(make_iterator_range(r&: first)); |
| 57 | write_data_in_chars(os&: out); |
| 58 | ifstream second(test.name().c_str()); |
| 59 | BOOST_CHECK_MESSAGE( |
| 60 | compare_container_and_stream(first, second), |
| 61 | "failed writing to filtering_stream<seekable> based on a " |
| 62 | "sequence in chars with large buffer" |
| 63 | ); |
| 64 | } |
| 65 | |
| 66 | { |
| 67 | vector<char> first(data_reps * data_length(), '?'); |
| 68 | filtering_stream<seekable> out(make_iterator_range(r&: first)); |
| 69 | write_data_in_chunks(os&: out); |
| 70 | ifstream second(test.name().c_str()); |
| 71 | BOOST_CHECK_MESSAGE( |
| 72 | compare_container_and_stream(first, second), |
| 73 | "failed writing to filtering_stream<seekable> based on a " |
| 74 | "sequence in chunks with large buffer" |
| 75 | ); |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | #endif // #ifndef BOOST_IOSTREAMS_TEST_WRITE_SEEKABLE_SEQUENCE_HPP_INCLUDED |
| 80 | |