Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/libs/iostreams/test/positioning_test.cpp @ 29

Last change on this file since 29 was 29, checked in by landauf, 16 years ago

updated boost from 1_33_1 to 1_34_1

File size: 2.2 KB
Line 
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
15using namespace std;
16using namespace boost;
17using namespace boost::iostreams;
18using 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
30void 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
42void 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
61test_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}
Note: See TracBrowser for help on using the repository browser.