read_bidir_streambuf_test.hpp 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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_STREAMBUF_HPP_INCLUDED
  7. #define BOOST_IOSTREAMS_TEST_READ_BIDIRECTIONAL_STREAMBUF_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/temp_file.hpp"
  13. #include "detail/verification.hpp"
  14. void read_bidirectional_streambuf_test()
  15. {
  16. using namespace std;
  17. using namespace boost;
  18. using namespace boost::iostreams;
  19. using namespace boost::iostreams::test;
  20. test_file test1;
  21. test_file test2;
  22. {
  23. filebuf fb;
  24. fb.open(test1.name().c_str(), BOOST_IOS::in);
  25. filtering_stream<bidirectional> first(fb, 0);
  26. ifstream second(test2.name().c_str());
  27. BOOST_CHECK_MESSAGE(
  28. compare_streams_in_chars(first, second),
  29. "failed reading from filtering_stream<bidirectional> based on a"
  30. "streambuf in chars with no buffer"
  31. );
  32. }
  33. {
  34. filebuf fb;
  35. fb.open(test1.name().c_str(), BOOST_IOS::in);
  36. filtering_stream<bidirectional> first(fb, 0);
  37. ifstream second(test2.name().c_str());
  38. BOOST_CHECK_MESSAGE(
  39. compare_streams_in_chunks(first, second),
  40. "failed reading from filtering_stream<bidirectional> based on a"
  41. "streambuf in chunks with no buffer"
  42. );
  43. }
  44. {
  45. filebuf fb;
  46. fb.open(test1.name().c_str(), BOOST_IOS::in);
  47. filtering_stream<bidirectional> first(fb);
  48. ifstream second(test2.name().c_str());
  49. BOOST_CHECK_MESSAGE(
  50. compare_streams_in_chars(first, second),
  51. "failed reading from filtering_stream<bidirectional> based on a"
  52. "streambuf in chars with large buffer"
  53. );
  54. }
  55. {
  56. filebuf fb;
  57. fb.open(test1.name().c_str(), BOOST_IOS::in);
  58. filtering_stream<bidirectional> first(fb);
  59. ifstream second(test2.name().c_str());
  60. BOOST_CHECK_MESSAGE(
  61. compare_streams_in_chunks(first, second),
  62. "failed reading from filtering_stream<bidirectional> based on a"
  63. "streambuf in chunks with large buffer"
  64. );
  65. }
  66. }
  67. #endif // #ifndef BOOST_IOSTREAMS_TEST_READ_BIDIRECTIONAL_STREAMBUF_HPP_INCLUDED