seekable_filter_test.cpp 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. #include <vector>
  7. #include <boost/config.hpp>
  8. #include <boost/detail/workaround.hpp>
  9. #include <boost/iostreams/device/array.hpp>
  10. #include <boost/iostreams/device/array.hpp>
  11. #include <boost/iostreams/filtering_stream.hpp>
  12. #include <boost/test/test_tools.hpp>
  13. #include <boost/test/unit_test.hpp>
  14. #include "../example/container_device.hpp" // We use container_device instead
  15. #include "detail/filters.hpp" // of make_iterator_range to
  16. #include "detail/temp_file.hpp" // reduce dependence on Boost.Range
  17. #include "detail/verification.hpp"
  18. using namespace std;
  19. using namespace boost;
  20. using namespace boost::iostreams;
  21. using namespace boost::iostreams::example;
  22. using namespace boost::iostreams::test;
  23. using boost::unit_test::test_suite;
  24. // Code generation bugs cause tests to fail with global optimization.
  25. #if BOOST_WORKAROUND(BOOST_MSVC, < 1300)
  26. # pragma optimize("g", off)
  27. #endif
  28. void seekable_filter_test()
  29. {
  30. {
  31. vector<char> test(data_reps * data_length(), '0');
  32. filtering_stream<seekable> io;
  33. io.push(identity_seekable_filter());
  34. io.push(container_device< vector<char> >(test));
  35. io.exceptions(BOOST_IOS::failbit | BOOST_IOS::badbit);
  36. BOOST_CHECK_MESSAGE(
  37. test_seekable_in_chars(io),
  38. "failed seeking within a file, in chars"
  39. );
  40. }
  41. {
  42. vector<char> test(data_reps * data_length(), '0');
  43. filtering_stream<seekable> io;
  44. io.push(identity_seekable_filter());
  45. io.push(container_device< vector<char> >(test));
  46. io.exceptions(BOOST_IOS::failbit | BOOST_IOS::badbit);
  47. BOOST_CHECK_MESSAGE(
  48. test_seekable_in_chunks(io),
  49. "failed seeking within a file, in chunks"
  50. );
  51. }
  52. {
  53. vector<char> test(data_reps * data_length(), '0');
  54. filtering_stream<seekable> io;
  55. io.push(identity_seekable_multichar_filter());
  56. io.push(container_device< vector<char> >(test));
  57. io.exceptions(BOOST_IOS::failbit | BOOST_IOS::badbit);
  58. BOOST_CHECK_MESSAGE(
  59. test_seekable_in_chars(io),
  60. "failed seeking within a file, in chars"
  61. );
  62. }
  63. {
  64. vector<char> test(data_reps * data_length(), '0');
  65. filtering_stream<seekable> io;
  66. io.push(identity_seekable_multichar_filter());
  67. io.push(container_device< vector<char> >(test));
  68. io.exceptions(BOOST_IOS::failbit | BOOST_IOS::badbit);
  69. BOOST_CHECK_MESSAGE(
  70. test_seekable_in_chunks(io),
  71. "failed seeking within a file, in chunks"
  72. );
  73. }
  74. }
  75. #if BOOST_WORKAROUND(BOOST_MSVC, < 1300)
  76. # pragma optimize("", on)
  77. #endif
  78. test_suite* init_unit_test_suite(int, char* [])
  79. {
  80. test_suite* test = BOOST_TEST_SUITE("seekable filter test");
  81. test->add(BOOST_TEST_CASE(&seekable_filter_test));
  82. return test;
  83. }