write_bidir_test.hpp 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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_BIDIRECTIONAL_HPP_INCLUDED
  7. #define BOOST_IOSTREAMS_TEST_WRITE_BIDIRECTIONAL_HPP_INCLUDED
  8. #include <fstream>
  9. #include <boost/iostreams/combine.hpp>
  10. #include <boost/iostreams/device/file.hpp>
  11. #include <boost/iostreams/filtering_stream.hpp>
  12. #include <boost/test/test_tools.hpp>
  13. #include "detail/temp_file.hpp"
  14. #include "detail/verification.hpp"
  15. void write_bidirectional_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 dest;
  24. temp_file src; // Dummy;
  25. filtering_stream<bidirectional> out(
  26. combine(file_source(src.name()), file_sink(dest.name(), out_mode)), 0
  27. );
  28. write_data_in_chars(out);
  29. out.reset();
  30. BOOST_CHECK_MESSAGE(
  31. compare_files(dest.name(), test.name()),
  32. "failed writing to filtering_stream<bidirectional> in chars "
  33. "with no buffer"
  34. );
  35. }
  36. {
  37. temp_file dest;
  38. temp_file src; // Dummy;
  39. filtering_stream<bidirectional> out(
  40. combine(file_source(src.name()), file_sink(dest.name(), out_mode)), 0
  41. );
  42. write_data_in_chunks(out);
  43. out.reset();
  44. BOOST_CHECK_MESSAGE(
  45. compare_files(dest.name(), test.name()),
  46. "failed writing to filtering_stream<bidirectional> in chunks "
  47. "with no buffer"
  48. );
  49. }
  50. {
  51. temp_file dest;
  52. temp_file src; // Dummy;
  53. filtering_stream<bidirectional> out(
  54. combine(file_source(src.name()), file_sink(dest.name(), out_mode))
  55. );
  56. write_data_in_chars(out);
  57. out.reset();
  58. BOOST_CHECK_MESSAGE(
  59. compare_files(dest.name(), test.name()),
  60. "failed writing to filtering_stream<bidirectional> in chars "
  61. "with large buffer"
  62. );
  63. }
  64. {
  65. temp_file dest;
  66. temp_file src; // Dummy;
  67. filtering_stream<bidirectional> out(
  68. combine(file_source(src.name()), file_sink(dest.name(), out_mode))
  69. );
  70. write_data_in_chunks(out);
  71. out.reset();
  72. BOOST_CHECK_MESSAGE(
  73. compare_files(dest.name(), test.name()),
  74. "failed writing to filtering_stream<bidirectional> in chunks "
  75. "with large buffer"
  76. );
  77. }
  78. }
  79. #endif // #ifndef BOOST_IOSTREAMS_TEST_WRITE_BIDIRECTIONAL_HPP_INCLUDED