1 | // (C) Copyright Jonathan Turkanis 2005 |
---|
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 | |
---|
7 | #include <boost/iostreams/detail/ios.hpp> |
---|
8 | #include <boost/iostreams/positioning.hpp> |
---|
9 | #include <boost/integer_traits.hpp> |
---|
10 | #include <boost/test/test_tools.hpp> |
---|
11 | #include <boost/test/unit_test.hpp> |
---|
12 | |
---|
13 | #include <iostream> |
---|
14 | |
---|
15 | using namespace std; |
---|
16 | using namespace boost; |
---|
17 | using namespace boost::iostreams; |
---|
18 | using boost::unit_test::test_suite; |
---|
19 | |
---|
20 | //void extrema_test_test() |
---|
21 | //{ |
---|
22 | // stream_offset minoff = integer_traits<stream_offset>::const_min; |
---|
23 | // stream_offset maxoff = integer_traits<stream_offset>::const_max; |
---|
24 | // |
---|
25 | // BOOST_CHECK(minoff == position_to_offset(offset_to_position(minoff))); |
---|
26 | // BOOST_CHECK(0 == position_to_offset(offset_to_position(0))); |
---|
27 | // BOOST_CHECK(maxoff == position_to_offset(offset_to_position(maxoff))); |
---|
28 | //} |
---|
29 | |
---|
30 | void large_file_test() |
---|
31 | { |
---|
32 | stream_offset large_file = 100 * 1024 * 1024 * 1024; // 100GB. |
---|
33 | stream_offset first = -large_file - (-large_file) % 10000000; |
---|
34 | stream_offset last = large_file - large_file % 10000000; |
---|
35 | |
---|
36 | for (stream_offset off = first; off < last; off += 10000000) |
---|
37 | { |
---|
38 | BOOST_CHECK(off == position_to_offset(offset_to_position(off))); |
---|
39 | } |
---|
40 | } |
---|
41 | |
---|
42 | void small_file_test() |
---|
43 | { |
---|
44 | stream_offset small_file = 1000000; |
---|
45 | stream_offset off = -small_file; |
---|
46 | streampos pos = offset_to_position(off); |
---|
47 | |
---|
48 | while (off < small_file) |
---|
49 | { |
---|
50 | BOOST_CHECK(off == position_to_offset(offset_to_position(off))); |
---|
51 | BOOST_CHECK(pos == offset_to_position(position_to_offset(pos))); |
---|
52 | off += 20000; |
---|
53 | pos += 20000; |
---|
54 | BOOST_CHECK(off == position_to_offset(offset_to_position(off))); |
---|
55 | BOOST_CHECK(pos == offset_to_position(position_to_offset(pos))); |
---|
56 | off -= 10000; |
---|
57 | pos -= 10000; |
---|
58 | } |
---|
59 | } |
---|
60 | |
---|
61 | test_suite* init_unit_test_suite(int, char* []) |
---|
62 | { |
---|
63 | test_suite* test = BOOST_TEST_SUITE("positioning test"); |
---|
64 | //test->add(BOOST_TEST_CASE(&extrema_test_test)); |
---|
65 | test->add(BOOST_TEST_CASE(&large_file_test)); |
---|
66 | test->add(BOOST_TEST_CASE(&small_file_test)); |
---|
67 | return test; |
---|
68 | } |
---|