endian_reverse_cx_test.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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. #include <boost/endian/conversion.hpp>
  6. #include <boost/config/pragma_message.hpp>
  7. #include <boost/config.hpp>
  8. #include <boost/cstdint.hpp>
  9. #if defined(BOOST_NO_CXX11_CONSTEXPR)
  10. BOOST_PRAGMA_MESSAGE("Test skipped because BOOST_NO_CXX11_CONSTEXPR is defined")
  11. #elif defined(BOOST_ENDIAN_NO_INTRINSICS) && defined(BOOST_NO_CXX14_CONSTEXPR)
  12. BOOST_PRAGMA_MESSAGE("Test skipped because BOOST_ENDIAN_NO_INTRINSICS and BOOST_NO_CXX14_CONSTEXPR are defined")
  13. #elif !defined(BOOST_ENDIAN_NO_INTRINSICS) && !defined(BOOST_ENDIAN_CONSTEXPR_INTRINSICS)
  14. BOOST_PRAGMA_MESSAGE("Test skipped because BOOST_ENDIAN_NO_INTRINSICS and BOOST_ENDIAN_CONSTEXPR_INTRINSICS are not defined")
  15. #else
  16. using namespace boost::endian;
  17. #define STATIC_ASSERT(expr) static_assert(expr, #expr)
  18. STATIC_ASSERT( endian_reverse( static_cast<boost::uint8_t>( 0x01 ) ) == 0x01 );
  19. STATIC_ASSERT( endian_reverse( static_cast<boost::uint16_t>( 0x0102 ) ) == 0x0201 );
  20. STATIC_ASSERT( endian_reverse( static_cast<boost::uint32_t>( 0x01020304 ) ) == 0x04030201 );
  21. STATIC_ASSERT( endian_reverse( static_cast<boost::uint64_t>( 0x0102030405060708 ) ) == 0x0807060504030201 );
  22. STATIC_ASSERT( big_to_native( native_to_big( 0x01020304 ) ) == 0x01020304 );
  23. STATIC_ASSERT( little_to_native( native_to_little( 0x01020304 ) ) == 0x01020304 );
  24. STATIC_ASSERT( native_to_big( 0x01020304 ) == (conditional_reverse<order::native, order::big>( 0x01020304 )) );
  25. STATIC_ASSERT( native_to_big( 0x01020304 ) == conditional_reverse( 0x01020304, order::native, order::big ) );
  26. #endif