From d9e5fb0d414cc54612961846bf40f277dec67099 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Sat, 27 Apr 2019 02:40:47 +0300 Subject: [PATCH] Add endian_ld_st_roundtrip_test --- test/Jamfile.v2 | 3 ++ test/endian_ld_st_roundtrip_test.cpp | 46 ++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 test/endian_ld_st_roundtrip_test.cpp diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index c39b584..1a5d9ad 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -58,3 +58,6 @@ run endian_reverse_test.cpp : : : BOOST_ENDIAN_NO_INTRINSICS : endian_re run endian_load_test.cpp ; run endian_load_test.cpp : : : BOOST_ENDIAN_NO_INTRINSICS : endian_load_test_ni ; + +run endian_ld_st_roundtrip_test.cpp ; +run endian_ld_st_roundtrip_test.cpp : : : BOOST_ENDIAN_NO_INTRINSICS : endian_ld_st_roundtrip_test_ni ; diff --git a/test/endian_ld_st_roundtrip_test.cpp b/test/endian_ld_st_roundtrip_test.cpp new file mode 100644 index 0000000..163e09f --- /dev/null +++ b/test/endian_ld_st_roundtrip_test.cpp @@ -0,0 +1,46 @@ +// 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 +#include +#include + +template void test( T const& x ) +{ + { + unsigned char buffer[ sizeof(T) ]; + + boost::endian::endian_store( x, buffer ); + T x2 = boost::endian::endian_load( buffer ); + + BOOST_TEST_EQ( x, x2 ); + } + + { + unsigned char buffer[ sizeof(T) ]; + + boost::endian::endian_store( x, buffer ); + T x2 = boost::endian::endian_load( buffer ); + + BOOST_TEST_EQ( x, x2 ); + } +} + +enum E +{ + e = 0xF1F2F3 +}; + +int main() +{ + test( 1.2e+34f ); + test( -1.234e+56 ); + test( e ); + + return boost::report_errors(); +}