]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/core/test/bit_endian_test.cpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / libs / core / test / bit_endian_test.cpp
1 // Test for boost/core/bit.hpp (bit_ceil)
2 //
3 // Copyright 2020 Peter Dimov
4 // Distributed under the Boost Software License, Version 1.0.
5 // https://www.boost.org/LICENSE_1_0.txt
6
7 #include <boost/core/bit.hpp>
8 #include <boost/core/lightweight_test.hpp>
9 #include <boost/cstdint.hpp>
10 #include <cstring>
11
12 #if defined(_MSC_VER)
13 # pragma warning(disable: 4127) // conditional expression is constant
14 #endif
15
16 int main()
17 {
18 boost::uint64_t v = ( static_cast<boost::uint64_t>( 0x01020304u ) << 32 ) + 0x05060708u;
19
20 if( boost::core::endian::native == boost::core::endian::little )
21 {
22 unsigned char w[] = { 8, 7, 6, 5, 4, 3, 2, 1 };
23 BOOST_TEST( std::memcmp( &v, w, 8 ) == 0 );
24 }
25 else if( boost::core::endian::native == boost::core::endian::big )
26 {
27 unsigned char w[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
28 BOOST_TEST( std::memcmp( &v, w, 8 ) == 0 );
29 }
30 else
31 {
32 unsigned char w1[] = { 8, 7, 6, 5, 4, 3, 2, 1 };
33 BOOST_TEST( std::memcmp( &v, w1, 8 ) != 0 );
34
35 unsigned char w2[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
36 BOOST_TEST( std::memcmp( &v, w2, 8 ) != 0 );
37 }
38
39 return boost::report_errors();
40 }