1 | // Copyright 2019 Peter Dimov |
---|---|
2 | // |
3 | // Distributed under the Boost Software License, Version 1.0. |
4 | // http://www.boost.org/LICENSE_1_0.txt |
5 | |
6 | #include <boost/endian/conversion.hpp> |
7 | #include <boost/config/pragma_message.hpp> |
8 | #include <boost/config.hpp> |
9 | #include <boost/cstdint.hpp> |
10 | |
11 | #if defined(BOOST_NO_CXX11_CONSTEXPR) |
12 | |
13 | BOOST_PRAGMA_MESSAGE("Test skipped because BOOST_NO_CXX11_CONSTEXPR is defined") |
14 | |
15 | #elif defined(BOOST_ENDIAN_NO_INTRINSICS) && defined(BOOST_NO_CXX14_CONSTEXPR) |
16 | |
17 | BOOST_PRAGMA_MESSAGE("Test skipped because BOOST_ENDIAN_NO_INTRINSICS and BOOST_NO_CXX14_CONSTEXPR are defined") |
18 | |
19 | #elif !defined(BOOST_ENDIAN_NO_INTRINSICS) && !defined(BOOST_ENDIAN_CONSTEXPR_INTRINSICS) |
20 | |
21 | BOOST_PRAGMA_MESSAGE("Test skipped because BOOST_ENDIAN_NO_INTRINSICS and BOOST_ENDIAN_CONSTEXPR_INTRINSICS are not defined") |
22 | |
23 | #else |
24 | |
25 | using namespace boost::endian; |
26 | |
27 | #define STATIC_ASSERT(expr) static_assert(expr, #expr) |
28 | |
29 | STATIC_ASSERT( endian_reverse( static_cast<boost::uint8_t>( 0x01 ) ) == 0x01 ); |
30 | STATIC_ASSERT( endian_reverse( static_cast<boost::uint16_t>( 0x0102 ) ) == 0x0201 ); |
31 | STATIC_ASSERT( endian_reverse( static_cast<boost::uint32_t>( 0x01020304 ) ) == 0x04030201 ); |
32 | STATIC_ASSERT( endian_reverse( static_cast<boost::uint64_t>( 0x0102030405060708 ) ) == 0x0807060504030201 ); |
33 | |
34 | STATIC_ASSERT( big_to_native( native_to_big( 0x01020304 ) ) == 0x01020304 ); |
35 | STATIC_ASSERT( little_to_native( native_to_little( 0x01020304 ) ) == 0x01020304 ); |
36 | |
37 | STATIC_ASSERT( native_to_big( 0x01020304 ) == (conditional_reverse<order::native, order::big>( 0x01020304 )) ); |
38 | STATIC_ASSERT( native_to_big( 0x01020304 ) == conditional_reverse( 0x01020304, order::native, order::big ) ); |
39 | |
40 | #endif |
41 |