write_output_iterator_test.hpp 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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_ITERATOR_HPP_INCLUDED
  7. #define BOOST_IOSTREAMS_TEST_WRITE_OUTPUT_ITERATOR_HPP_INCLUDED
  8. #include <fstream>
  9. #include <iterator> // Back inserter.
  10. #include <vector>
  11. #include <boost/iostreams/filtering_stream.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. // Note: adding raw inserter iterators to chains is not supported
  17. // on VC6.
  18. void write_output_iterator_test()
  19. {
  20. using namespace std;
  21. using namespace boost;
  22. using namespace boost::iostreams;
  23. using namespace boost::iostreams::test;
  24. test_file test;
  25. {
  26. vector<char> first;
  27. filtering_ostream out;
  28. out.push(std::back_inserter(first), 0);
  29. write_data_in_chars(out);
  30. ifstream second(test.name().c_str());
  31. BOOST_CHECK_MESSAGE(
  32. compare_container_and_stream(first, second),
  33. "failed writing to filtering_ostream based on an "
  34. "output iterator in chars with no buffer"
  35. );
  36. }
  37. {
  38. vector<char> first;
  39. filtering_ostream out;
  40. out.push(std::back_inserter(first), 0);
  41. write_data_in_chunks(out);
  42. ifstream second(test.name().c_str());
  43. BOOST_CHECK_MESSAGE(
  44. compare_container_and_stream(first, second),
  45. "failed writing to filtering_ostream based on an "
  46. "output iterator in chunks with no buffer"
  47. );
  48. }
  49. {
  50. vector<char> first;
  51. filtering_ostream out;
  52. out.push(std::back_inserter(first));
  53. write_data_in_chars(out);
  54. ifstream second(test.name().c_str());
  55. BOOST_CHECK_MESSAGE(
  56. compare_container_and_stream(first, second),
  57. "failed writing to filtering_ostream based on an "
  58. "output iterator in chars with large buffer"
  59. );
  60. }
  61. {
  62. vector<char> first;
  63. filtering_ostream out;
  64. out.push(std::back_inserter(first));
  65. write_data_in_chunks(out);
  66. ifstream second(test.name().c_str());
  67. BOOST_CHECK_MESSAGE(
  68. compare_container_and_stream(first, second),
  69. "failed writing to filtering_ostream based on an "
  70. "output iterator in chunks with large buffer"
  71. );
  72. }
  73. }
  74. #endif // #ifndef BOOST_IOSTREAMS_TEST_WRITE_OUTPUT_ITERATOR_HPP_INCLUDED