stream_offset_32bit_test.cpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. * Distributed under the Boost Software License, Version 1.0.(See accompanying
  3. * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.)
  4. *
  5. * See http://www.boost.org/libs/iostreams for documentation.
  6. * File: libs/iostreams/test/stream_offset_32bit_test.cpp
  7. * Date: Sun Dec 23 21:11:23 MST 2007
  8. * Copyright: 2007-2008 CodeRage, LLC
  9. * Author: Jonathan Turkanis
  10. * Contact: turkanis at coderage dot com
  11. *
  12. * Tests the functions defined in the header "boost/iostreams/positioning.hpp"
  13. * with small (32-bit) file offsets.
  14. */
  15. #include <boost/iostreams/positioning.hpp>
  16. #include <boost/test/test_tools.hpp>
  17. #include <boost/test/unit_test.hpp>
  18. #include <boost/type_traits/is_integral.hpp>
  19. using namespace std;
  20. using namespace boost;
  21. using namespace boost::iostreams;
  22. using boost::unit_test::test_suite;
  23. void stream_offset_32bit_test()
  24. {
  25. stream_offset small_file = 1000000;
  26. stream_offset off = -small_file;
  27. streampos pos = offset_to_position(off);
  28. while (off < small_file)
  29. {
  30. BOOST_CHECK(off == position_to_offset(offset_to_position(off)));
  31. BOOST_CHECK(pos == offset_to_position(position_to_offset(pos)));
  32. off += 20000;
  33. pos += 20000;
  34. BOOST_CHECK(off == position_to_offset(offset_to_position(off)));
  35. BOOST_CHECK(pos == offset_to_position(position_to_offset(pos)));
  36. off -= 10000;
  37. pos -= 10000;
  38. }
  39. }
  40. test_suite* init_unit_test_suite(int, char* [])
  41. {
  42. test_suite* test = BOOST_TEST_SUITE("stream_offset 32-bit test");
  43. test->add(BOOST_TEST_CASE(&stream_offset_32bit_test));
  44. return test;
  45. }