write_seekable_seq_test.hpp 2.7 KB

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