write_output_ostream_test.hpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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_OSTREAM_HPP_INCLUDED
  7. #define BOOST_IOSTREAMS_TEST_WRITE_OUTPUT_OSTREAM_HPP_INCLUDED
  8. #include <fstream>
  9. #include <boost/iostreams/filtering_stream.hpp>
  10. #include <boost/test/test_tools.hpp>
  11. #include "detail/sequence.hpp"
  12. #include "detail/temp_file.hpp"
  13. #include "detail/verification.hpp"
  14. void write_output_ostream_test()
  15. {
  16. using namespace std;
  17. using namespace boost;
  18. using namespace boost::iostreams;
  19. using namespace boost::iostreams::test;
  20. test_file test;
  21. {
  22. temp_file test2;
  23. {
  24. ofstream dest(test2.name().c_str(), out_mode);
  25. filtering_ostream out(dest, 0);
  26. write_data_in_chars(out);
  27. }
  28. BOOST_CHECK_MESSAGE(
  29. compare_files(test2.name(), test.name()),
  30. "failed writing to filtering_ostream based on an ostream "
  31. "in chars with no buffer"
  32. );
  33. }
  34. {
  35. temp_file test2;
  36. {
  37. ofstream dest(test2.name().c_str(), out_mode);
  38. filtering_ostream out(dest, 0);
  39. write_data_in_chunks(out);
  40. }
  41. BOOST_CHECK_MESSAGE(
  42. compare_files(test2.name(), test.name()),
  43. "failed writing to filtering_ostream based on an ostream "
  44. "in chunks with no buffer"
  45. );
  46. }
  47. {
  48. test_file test2;
  49. {
  50. ofstream dest(test2.name().c_str(), out_mode);
  51. filtering_ostream out(dest);
  52. write_data_in_chars(out);
  53. }
  54. BOOST_CHECK_MESSAGE(
  55. compare_files(test2.name(), test.name()),
  56. "failed writing to filtering_ostream based on an ostream "
  57. "in chars with large buffer"
  58. );
  59. }
  60. {
  61. temp_file test2;
  62. {
  63. ofstream dest(test2.name().c_str(), out_mode);
  64. filtering_ostream out(dest);
  65. write_data_in_chunks(out);
  66. }
  67. BOOST_CHECK_MESSAGE(
  68. compare_files(test2.name(), test.name()),
  69. "failed writing to filtering_ostream based on an ostream "
  70. "in chunks with large buffer"
  71. );
  72. }
  73. }
  74. #endif // #ifndef BOOST_IOSTREAMS_TEST_WRITE_OUTPUT_OSTREAM_HPP_INCLUDED