write_seekable_test.hpp 2.4 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_WRITE_SEEKABLE_HPP_INCLUDED
  7. #define BOOST_IOSTREAMS_TEST_WRITE_SEEKABLE_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 write_seekable_test()
  15. {
  16. using namespace std;
  17. using namespace boost;
  18. using namespace boost::iostreams;
  19. using namespace boost::iostreams::test;
  20. test_file test;
  21. BOOST_IOS::openmode mode = out_mode | BOOST_IOS::trunc;
  22. {
  23. temp_file test2;
  24. filtering_stream<seekable> out(file(test2.name(), 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_stream<seekable> in chars with"
  30. "no buffer"
  31. );
  32. }
  33. {
  34. temp_file test2;
  35. filtering_stream<seekable> out(file(test2.name(), mode), 0);
  36. write_data_in_chunks(out);
  37. out.reset();
  38. BOOST_CHECK_MESSAGE(
  39. compare_files(test2.name(), test.name()),
  40. "failed writing to filtering_stream<seekable> in chunks with"
  41. "no buffer"
  42. );
  43. }
  44. {
  45. temp_file test2;
  46. filtering_stream<seekable> out(file(test2.name(), mode));
  47. write_data_in_chars(out);
  48. out.reset();
  49. BOOST_CHECK_MESSAGE(
  50. compare_files(test2.name(), test.name()),
  51. "failed writing to filtering_stream<seekable> in chars with"
  52. "large buffer"
  53. );
  54. }
  55. {
  56. temp_file test2;
  57. filtering_stream<seekable> out(file(test2.name(), mode));
  58. write_data_in_chunks(out);
  59. out.reset();
  60. BOOST_CHECK_MESSAGE(
  61. compare_files(test2.name(), test.name()),
  62. "failed writing to filtering_stream<seekable> in chunks with"
  63. "large buffer"
  64. );
  65. }
  66. }
  67. #endif // #ifndef BOOST_IOSTREAMS_TEST_WRITE_SEEKABLE_HPP_INCLUDED