Add endian_ld_st_roundtrip_test

This commit is contained in:
Peter Dimov
2019-04-27 02:40:47 +03:00
parent e58970b167
commit d9e5fb0d41
2 changed files with 49 additions and 0 deletions

View File

@ -58,3 +58,6 @@ run endian_reverse_test.cpp : : : <define>BOOST_ENDIAN_NO_INTRINSICS : endian_re
run endian_load_test.cpp ;
run endian_load_test.cpp : : : <define>BOOST_ENDIAN_NO_INTRINSICS : endian_load_test_ni ;
run endian_ld_st_roundtrip_test.cpp ;
run endian_ld_st_roundtrip_test.cpp : : : <define>BOOST_ENDIAN_NO_INTRINSICS : endian_ld_st_roundtrip_test_ni ;

View File

@ -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 <boost/endian/detail/endian_load.hpp>
#include <boost/endian/detail/endian_store.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/config.hpp>
#include <boost/cstdint.hpp>
#include <cstddef>
template<class T> void test( T const& x )
{
{
unsigned char buffer[ sizeof(T) ];
boost::endian::endian_store<T, sizeof(T), boost::endian::order::little>( x, buffer );
T x2 = boost::endian::endian_load<T, sizeof(T), boost::endian::order::little>( buffer );
BOOST_TEST_EQ( x, x2 );
}
{
unsigned char buffer[ sizeof(T) ];
boost::endian::endian_store<T, sizeof(T), boost::endian::order::big>( x, buffer );
T x2 = boost::endian::endian_load<T, sizeof(T), boost::endian::order::big>( 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();
}