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.)
5 * See http://www.boost.org/libs/iostreams for documentation.
7 * File: libs/iostreams/test/stream_offset_64bit_test.cpp
8 * Date: Sun Dec 23 21:11:23 MST 2007
9 * Copyright: 2007-2008 CodeRage, LLC
10 * Author: Jonathan Turkanis
11 * Contact: turkanis at coderage dot com
13 * Tests the functions defined in the header "boost/iostreams/positioning.hpp"
14 * with large (64-bit) file offsets.
17 #include <cstdio> // fpos_t
20 #include <boost/config.hpp> // BOOST_MSVC
21 #include <boost/iostreams/detail/ios.hpp>
22 #include <boost/iostreams/positioning.hpp>
23 #include <boost/test/test_tools.hpp>
24 #include <boost/test/unit_test.hpp>
27 using namespace boost
;
28 using namespace boost::iostreams
;
29 using boost::unit_test::test_suite
;
32 # pragma warning(disable:4127)
35 void stream_offset_64bit_test()
37 stream_offset large_file
= (stream_offset
) 100 *
38 (stream_offset
) 1024 *
39 (stream_offset
) 1024 *
41 stream_offset first
= -large_file
- (-large_file
) % 10000000;
42 stream_offset last
= large_file
- large_file
% 10000000;
44 for (stream_offset off
= first
; off
< last
; off
+= 10000000)
46 if (off
!= position_to_offset(offset_to_position(off
))) {
47 cout
<< "****************************************\n"
48 << "* sizeof(fpos_t) = " << sizeof(fpos_t) << "\n"
49 << "* sizeof(streamoff) = " << sizeof(streamoff
) << "\n"
50 << "* sizeof(stream_offset) = "
51 << sizeof(stream_offset
) << "\n"
52 << "****************************************\n";
54 s
<< "off != position_to_offset(offset_to_position(off)) "
55 "failed for (off >> 32) == 0x"
57 << static_cast<unsigned int>(off
>> 32)
58 << " and (off & 0xFFFFFFFF) == 0x"
59 << static_cast<unsigned int>(off
& 0xFFFFFFFF)
61 BOOST_REQUIRE_MESSAGE(0, s
.str().c_str());
66 void stream_offset_64bit_test2()
68 boost::int64_t val
= boost::int64_t(1) << 31;
69 std::streampos pos
= boost::iostreams::offset_to_position(val
);
71 BOOST_CHECK_EQUAL(val
- 2, boost::iostreams::position_to_offset(pos
));
74 pos
= boost::iostreams::offset_to_position(val
);
76 BOOST_CHECK_EQUAL(val
+ 2, boost::iostreams::position_to_offset(pos
));
79 test_suite
* init_unit_test_suite(int, char* [])
81 test_suite
* test
= BOOST_TEST_SUITE("stream_offset 64-bit test");
82 test
->add(BOOST_TEST_CASE(&stream_offset_64bit_test
));
83 test
->add(BOOST_TEST_CASE(&stream_offset_64bit_test2
));