seekable_file_test.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 <fstream>
  7. #include <boost/iostreams/device/file.hpp>
  8. #include <boost/iostreams/filtering_stream.hpp>
  9. #include <boost/test/test_tools.hpp>
  10. #include <boost/test/unit_test.hpp>
  11. #include "detail/temp_file.hpp"
  12. #include "detail/verification.hpp"
  13. using namespace std;
  14. using namespace boost;
  15. using namespace boost::iostreams;
  16. using namespace boost::iostreams::test;
  17. using boost::unit_test::test_suite;
  18. void seekable_file_test()
  19. {
  20. {
  21. temp_file temp;
  22. file f( temp.name(),
  23. BOOST_IOS::in | BOOST_IOS::out |
  24. BOOST_IOS::trunc | BOOST_IOS::binary);
  25. filtering_stream<seekable> io(f);
  26. io.exceptions(BOOST_IOS::failbit | BOOST_IOS::badbit);
  27. BOOST_CHECK_MESSAGE(
  28. test_seekable_in_chars(io),
  29. "failed seeking within a file, in chars"
  30. );
  31. }
  32. {
  33. temp_file temp;
  34. file f( temp.name(),
  35. BOOST_IOS::in | BOOST_IOS::out |
  36. BOOST_IOS::trunc | BOOST_IOS::binary);
  37. filtering_stream<seekable> io(f);
  38. io.exceptions(BOOST_IOS::failbit | BOOST_IOS::badbit);
  39. BOOST_CHECK_MESSAGE(
  40. test_seekable_in_chunks(io),
  41. "failed seeking within a file, in chunks"
  42. );
  43. }
  44. }
  45. test_suite* init_unit_test_suite(int, char* [])
  46. {
  47. test_suite* test = BOOST_TEST_SUITE("seekable file test");
  48. test->add(BOOST_TEST_CASE(&seekable_file_test));
  49. return test;
  50. }