forked from boostorg/endian
Add endian_ld_st_roundtrip_test
This commit is contained in:
@ -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 ;
|
||||||
run endian_load_test.cpp : : : <define>BOOST_ENDIAN_NO_INTRINSICS : endian_load_test_ni ;
|
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 ;
|
||||||
|
46
test/endian_ld_st_roundtrip_test.cpp
Normal file
46
test/endian_ld_st_roundtrip_test.cpp
Normal 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();
|
||||||
|
}
|
Reference in New Issue
Block a user