diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 27c8702..d9745e2 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -79,3 +79,6 @@ run load_convenience_test.cpp : : : BOOST_ENDIAN_NO_INTRINSICS : load_co run store_convenience_test.cpp ; run store_convenience_test.cpp : : : BOOST_ENDIAN_NO_INTRINSICS : store_convenience_test_ni ; + +run float_typedef_test.cpp ; +run float_typedef_test.cpp : : : BOOST_ENDIAN_NO_INTRINSICS : float_typedef_test_ni ; diff --git a/test/float_typedef_test.cpp b/test/float_typedef_test.cpp new file mode 100644 index 0000000..e6f8a23 --- /dev/null +++ b/test/float_typedef_test.cpp @@ -0,0 +1,77 @@ +// Copyright 2019 Peter Dimov +// +// Distributed under the Boost Software License, Version 1.0. +// http://www.boost.org/LICENSE_1_0.txt + +#include +#include +#include + +template struct align +{ + char _; + T v; + + explicit align( typename T::value_type y ): _(), v( y ) + { + } +}; + +template void test_buffer( U const & y, bool aligned ) +{ + align x( y ); + + BOOST_TEST_EQ( sizeof(x), aligned? 2 * sizeof(U): 1 + sizeof(U) ); + + BOOST_TEST_EQ( x.v.value(), y ); +} + +template void test_arithmetic( U const & y, bool aligned ) +{ + test_buffer( y, aligned ); + + align x( y ); + + BOOST_TEST_EQ( x.v + 7, y + 7 ); +} + +int main() +{ + using namespace boost::endian; + + // buffers + + test_buffer( 3.1416f, false ); + test_buffer( 3.14159, false ); + + test_buffer( 3.1416f, false ); + test_buffer( 3.14159, false ); + + test_buffer( 3.1416f, false ); + test_buffer( 3.14159, false ); + + test_buffer( 3.1416f, true ); + test_buffer( 3.14159, true ); + + test_buffer( 3.1416f, true ); + test_buffer( 3.14159, true ); + + // arithmetic + + test_arithmetic( 3.1416f, false ); + test_arithmetic( 3.14159, false ); + + test_arithmetic( 3.1416f, false ); + test_arithmetic( 3.14159, false ); + + test_arithmetic( 3.1416f, false ); + test_arithmetic( 3.14159, false ); + + test_arithmetic( 3.1416f, true ); + test_arithmetic( 3.14159, true ); + + test_arithmetic( 3.1416f, true ); + test_arithmetic( 3.14159, true ); + + return boost::report_errors(); +}