write_output_test.hpp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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_HPP_INCLUDED
  7. #define BOOST_IOSTREAMS_TEST_WRITE_OUTPUT_HPP_INCLUDED
  8. #include <fstream>
  9. #include <boost/iostreams/device/file.hpp>
  10. #include <boost/iostreams/filtering_stream.hpp>
  11. #include <boost/test/test_tools.hpp>
  12. #include "detail/sequence.hpp"
  13. #include "detail/temp_file.hpp"
  14. #include "detail/verification.hpp"
  15. void write_output_test()
  16. {
  17. using namespace std;
  18. using namespace boost;
  19. using namespace boost::iostreams;
  20. using namespace boost::iostreams::test;
  21. test_file test;
  22. {
  23. temp_file test2;
  24. filtering_ostream out(file_sink(test2.name(), out_mode), 0);
  25. write_data_in_chars(out);
  26. out.reset();
  27. BOOST_CHECK_MESSAGE(
  28. compare_files(test2.name(), test.name()),
  29. "failed writing to filtering_ostream in chars with no buffer"
  30. );
  31. }
  32. {
  33. temp_file test2;
  34. filtering_ostream out(file_sink(test2.name(), out_mode), 0);
  35. write_data_in_chunks(out);
  36. out.reset();
  37. BOOST_CHECK_MESSAGE(
  38. compare_files(test2.name(), test.name()),
  39. "failed writing to filtering_ostream in chunks with no buffer"
  40. );
  41. }
  42. {
  43. temp_file test2;
  44. filtering_ostream out(file_sink(test2.name(), out_mode));
  45. write_data_in_chars(out);
  46. out.reset();
  47. BOOST_CHECK_MESSAGE(
  48. compare_files(test2.name(), test.name()),
  49. "failed writing to filtering_ostream in chars with buffer"
  50. );
  51. }
  52. {
  53. temp_file test2;
  54. filtering_ostream out(file_sink(test2.name(), out_mode));
  55. write_data_in_chunks(out);
  56. out.reset();
  57. BOOST_CHECK_MESSAGE(
  58. compare_files(test2.name(), test.name()),
  59. "failed writing to filtering_ostream in chunks with buffer"
  60. );
  61. }
  62. }
  63. #endif // #ifndef BOOST_IOSTREAMS_TEST_WRITE_OUTPUT_HPP_INCLUDED