From 51f095f019b45ad8f2cfb1f1ae95232cf299ef26 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Tue, 15 Oct 2019 21:07:40 +0300 Subject: [PATCH] Add data_test --- test/Jamfile.v2 | 47 ++++++++++------------- test/data_test.cpp | 95 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 116 insertions(+), 26 deletions(-) create mode 100644 test/data_test.cpp diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index d9745e2..74265f1 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -28,19 +28,23 @@ project clang:on ; -run buffer_test.cpp ; -run buffer_test.cpp : : : BOOST_ENDIAN_NO_INTRINSICS : buffer_test_ni ; +local rule endian-run ( sources + ) +{ + local result ; -run endian_test.cpp ; -run endian_test.cpp : : : BOOST_ENDIAN_NO_INTRINSICS : endian_test_ni ; + result += [ run $(sources) ] ; + result += [ run $(sources) : : : BOOST_ENDIAN_NO_INTRINSICS : $(sources[1]:B)_ni ] ; -run endian_operations_test.cpp ; -run endian_operations_test.cpp : : : BOOST_ENDIAN_NO_INTRINSICS : endian_operations_test_ni ; + return $(result) ; +} + +endian-run buffer_test.cpp ; +endian-run endian_test.cpp ; +endian-run endian_operations_test.cpp ; run endian_in_union_test.cpp ; -run conversion_test.cpp ; -run conversion_test.cpp : : : BOOST_ENDIAN_NO_INTRINSICS : conversion_test_ni ; +endian-run conversion_test.cpp ; run intrinsic_test.cpp ; @@ -54,31 +58,22 @@ local allow-warnings = compile spirit_conflict_test.cpp : $(allow-warnings) ; -run endian_reverse_test.cpp ; -run endian_reverse_test.cpp : : : BOOST_ENDIAN_NO_INTRINSICS : endian_reverse_test_ni ; +endian-run endian_reverse_test.cpp ; -run endian_load_test.cpp ; -run endian_load_test.cpp : : : BOOST_ENDIAN_NO_INTRINSICS : endian_load_test_ni ; +endian-run endian_load_test.cpp ; +endian-run endian_store_test.cpp ; +endian-run endian_ld_st_roundtrip_test.cpp ; -run endian_store_test.cpp ; -run endian_store_test.cpp : : : BOOST_ENDIAN_NO_INTRINSICS : endian_store_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 ; - -run endian_arithmetic_test.cpp ; -run endian_arithmetic_test.cpp : : : BOOST_ENDIAN_NO_INTRINSICS : endian_arithmetic_test_ni ; +endian-run endian_arithmetic_test.cpp ; run deprecated_test.cpp ; compile endian_reverse_cx_test.cpp ; compile endian_reverse_cx_test.cpp : BOOST_ENDIAN_NO_INTRINSICS : endian_reverse_cx_test_ni ; -run load_convenience_test.cpp ; -run load_convenience_test.cpp : : : BOOST_ENDIAN_NO_INTRINSICS : load_convenience_test_ni ; +endian-run load_convenience_test.cpp ; +endian-run store_convenience_test.cpp ; -run store_convenience_test.cpp ; -run store_convenience_test.cpp : : : BOOST_ENDIAN_NO_INTRINSICS : store_convenience_test_ni ; +endian-run float_typedef_test.cpp ; -run float_typedef_test.cpp ; -run float_typedef_test.cpp : : : BOOST_ENDIAN_NO_INTRINSICS : float_typedef_test_ni ; +endian-run data_test.cpp ; diff --git a/test/data_test.cpp b/test/data_test.cpp new file mode 100644 index 0000000..f4d64c2 --- /dev/null +++ b/test/data_test.cpp @@ -0,0 +1,95 @@ +// 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() +{ + { + U u( 0 ); + + unsigned char * p1 = u.data(); + void * p2 = &u; + + BOOST_TEST_EQ( p1, p2 ); + } + + { + U const u( 0 ); + + unsigned char const * p1 = u.data(); + void const * p2 = &u; + + BOOST_TEST_EQ( p1, p2 ); + } +} + +template void test_unaligned() +{ + using namespace boost::endian; + + test< endian_buffer >(); + test< endian_buffer >(); + test< endian_buffer >(); + + test< endian_arithmetic >(); + test< endian_arithmetic >(); + test< endian_arithmetic >(); +} + +template void test_aligned() +{ + using namespace boost::endian; + + test< endian_buffer >(); + test< endian_buffer >(); + + test< endian_arithmetic >(); + test< endian_arithmetic >(); +} + +int main() +{ + test_unaligned(); + test_unaligned(); + test_unaligned(); + test_unaligned(); + test_unaligned(); + test_unaligned(); + test_unaligned(); + test_unaligned(); + + test_unaligned(); + test_unaligned(); + test_unaligned(); + test_unaligned(); + test_unaligned(); + test_unaligned(); + test_unaligned(); + test_unaligned(); + + test_unaligned(); + test_unaligned(); + + test_aligned(); + test_aligned(); + test_aligned(); + test_aligned(); + + test_aligned(); + test_aligned(); + test_aligned(); + test_aligned(); + + test_aligned(); + test_aligned(); + + return boost::report_errors(); +}