read_bidir_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_READ_BIDIRECTIONAL_HPP_INCLUDED
  7. #define BOOST_IOSTREAMS_TEST_READ_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 read_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. test_file src;
  24. temp_file dest; // Dummy.
  25. filtering_stream<bidirectional> first(
  26. combine(file_source(src.name()), file_sink(dest.name())), 0
  27. );
  28. ifstream second(test.name().c_str());
  29. BOOST_CHECK_MESSAGE(
  30. compare_streams_in_chars(first, second),
  31. "failed reading from filtering_stream<bidirectional>"
  32. "in chars with no buffer"
  33. );
  34. }
  35. {
  36. test_file src;
  37. temp_file dest; // Dummy.
  38. filtering_stream<bidirectional> first(
  39. combine(file_source(src.name()), file_sink(dest.name())), 0
  40. );
  41. ifstream second(test.name().c_str());
  42. BOOST_CHECK_MESSAGE(
  43. compare_streams_in_chunks(first, second),
  44. "failed reading from filtering_stream<bidirectional>"
  45. "in chunks with no buffer"
  46. );
  47. }
  48. {
  49. test_file src;
  50. temp_file dest; // Dummy.
  51. filtering_stream<bidirectional> first(
  52. combine(file_source(src.name()), file_sink(dest.name()))
  53. );
  54. ifstream second(test.name().c_str());
  55. BOOST_CHECK_MESSAGE(
  56. compare_streams_in_chars(first, second),
  57. "failed reading from filtering_stream<bidirectional>"
  58. "in chars with large buffer"
  59. );
  60. }
  61. {
  62. test_file src;
  63. temp_file dest; // Dummy.
  64. filtering_stream<bidirectional> first(
  65. combine(file_source(src.name()), file_sink(dest.name()))
  66. );
  67. ifstream second(test.name().c_str());
  68. BOOST_CHECK_MESSAGE(
  69. compare_streams_in_chunks(first, second),
  70. "failed reading from filtering_stream<bidirectional>"
  71. "in chunks with large buffer"
  72. );
  73. }
  74. }
  75. #endif // #ifndef BOOST_IOSTREAMS_TEST_READ_BIDIRECTIONAL_HPP_INCLUDED