diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 1e4433d..f2fafcb 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -44,8 +44,13 @@ run intrinsic_test.cpp ; run quick.cpp ; -compile spirit_conflict_test.cpp - : "-msvc:on" +local allow-warnings = + "-msvc:on" "-gcc:on" - "-clang:on" - ; + "-clang:on" ; + +compile spirit_conflict_test.cpp + : $(allow-warnings) ; + +run endian_reverse_test.cpp + : : : $(allow-warnings) ; diff --git a/test/endian_reverse_test.cpp b/test/endian_reverse_test.cpp new file mode 100644 index 0000000..41737f3 --- /dev/null +++ b/test/endian_reverse_test.cpp @@ -0,0 +1,152 @@ +// Copyright 2019 Peter Dimov +// +// Distributed under the Boost Software License, Version 1.0. +// http://www.boost.org/LICENSE_1_0.txt + +#include +#include +#include +#include + +template struct test_value +{ +}; + +template struct test_value +{ + static const T v1 = static_cast( 0x1F ); + static const T w1 = static_cast( 0x1F ); + + static const T v2 = static_cast( 0xF1 ); + static const T w2 = static_cast( 0xF1 ); +}; + +template T const test_value::v1; +template T const test_value::w1; +template T const test_value::v2; +template T const test_value::w2; + +template struct test_value +{ + static const T v1 = static_cast( 0x1F2E ); + static const T w1 = static_cast( 0x2E1F ); + + static const T v2 = static_cast( 0xF1E2 ); + static const T w2 = static_cast( 0xE2F1 ); +}; + +template T const test_value::v1; +template T const test_value::w1; +template T const test_value::v2; +template T const test_value::w2; + +template struct test_value +{ + static const T v1 = static_cast( 0x1F2E3D4C ); + static const T w1 = static_cast( 0x4C3D2E1F ); + + static const T v2 = static_cast( 0xF1E2D3C4 ); + static const T w2 = static_cast( 0xC4D3E2F1 ); +}; + +template T const test_value::v1; +template T const test_value::w1; +template T const test_value::v2; +template T const test_value::w2; + +template struct test_value +{ + static const T v1 = static_cast( 0x1F2E3D4C5B6A7988ull ); + static const T w1 = static_cast( 0x88796A5B4C3D2E1Full ); + + static const T v2 = static_cast( 0xF1E2D3C4B5A69788ull ); + static const T w2 = static_cast( 0x8897A6B5C4D3E2F1ull ); +}; + +template T const test_value::v1; +template T const test_value::w1; +template T const test_value::v2; +template T const test_value::w2; + +template void test() +{ + using boost::endian::endian_reverse; + using boost::endian::endian_reverse_inplace; + + { + T t1 = test_value::v1; + + T t2 = endian_reverse( t1 ); + BOOST_TEST_EQ( t2, test_value::w1 ); + + T t3 = endian_reverse( t2 ); + BOOST_TEST_EQ( t3, t1 ); + + T t4 = t1; + + endian_reverse_inplace( t4 ); + BOOST_TEST_EQ( t4, test_value::w1 ); + + endian_reverse_inplace( t4 ); + BOOST_TEST_EQ( t4, t1 ); + } + + { + T t1 = test_value::v2; + + T t2 = endian_reverse( t1 ); + BOOST_TEST_EQ( t2, test_value::w2 ); + + T t3 = endian_reverse( t2 ); + BOOST_TEST_EQ( t3, t1 ); + + T t4 = t1; + + endian_reverse_inplace( t4 ); + BOOST_TEST_EQ( t4, test_value::w2 ); + + endian_reverse_inplace( t4 ); + BOOST_TEST_EQ( t4, t1 ); + } +} + +int main() +{ + test(); + test(); + + test(); + test(); + + test(); + test(); + + test(); + test(); + + test(); + test(); + test(); + + test(); + test(); + + test(); + test(); + + // test(); + // test(); + + test(); + test(); + +#if !defined(BOOST_NO_CXX11_CHAR16_T) + test(); +#endif + +#if !defined(BOOST_NO_CXX11_CHAR32_T) + test(); +#endif + + return boost::report_errors(); +}