write_bidir_streambuf_test.hpp 2.7 KB

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