| 1 | // Test for boost/core/bit.hpp (byteswap) |
|---|---|
| 2 | // |
| 3 | // Copyright 2023 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 | |
| 11 | int main() |
| 12 | { |
| 13 | BOOST_TEST_EQ( boost::core::byteswap( (boost::int8_t)0x01 ), 0x01 ); |
| 14 | BOOST_TEST_EQ( boost::core::byteswap( (boost::uint8_t)0xF1 ), 0xF1 ); |
| 15 | |
| 16 | BOOST_TEST_EQ( boost::core::byteswap( (boost::int16_t)0x0102 ), 0x0201 ); |
| 17 | BOOST_TEST_EQ( boost::core::byteswap( (boost::uint16_t)0xF1E2 ), 0xE2F1 ); |
| 18 | |
| 19 | BOOST_TEST_EQ( boost::core::byteswap( (boost::int32_t)0x01020304 ), 0x04030201 ); |
| 20 | BOOST_TEST_EQ( boost::core::byteswap( (boost::uint32_t)0xF1E2D3C4u ), 0xC4D3E2F1u ); |
| 21 | |
| 22 | BOOST_TEST_EQ( boost::core::byteswap( (boost::int64_t)0x01020304 << 32 | 0x05060708 ), (boost::int64_t)0x08070605 << 32 | 0x04030201 ); |
| 23 | BOOST_TEST_EQ( boost::core::byteswap( (boost::uint64_t)0xF1E2D3C4u << 32 | 0xB5A69788u ), (boost::uint64_t)0x8897A6B5u << 32 | 0xC4D3E2F1u ); |
| 24 | |
| 25 | return boost::report_errors(); |
| 26 | } |
| 27 |
