write_output_seq_test.hpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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_OUTPUT_SEQUENCE_HPP_INCLUDED
  7. #define BOOST_IOSTREAMS_TEST_WRITE_OUTPUT_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_output_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_ostream 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_ostream based on a sequence "
  31. "in chars with no buffer"
  32. );
  33. }
  34. {
  35. vector<char> first(data_reps * data_length(), '?');
  36. filtering_ostream 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_ostream based on a sequence "
  42. "in chunks with no buffer"
  43. );
  44. }
  45. {
  46. vector<char> first(data_reps * data_length(), '?');
  47. filtering_ostream 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_ostream based on a sequence "
  53. "in chars with large buffer"
  54. );
  55. }
  56. {
  57. vector<char> first(data_reps * data_length(), '?');
  58. filtering_ostream 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_ostream based on a sequence "
  64. "in chunks with large buffer"
  65. );
  66. }
  67. }
  68. #endif // #ifndef BOOST_IOSTREAMS_TEST_WRITE_OUTPUT_SEQUENCE_HPP_INCLUDED