From 0c934b3466cd19492efaa5641cc7121c6bf4376b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorsten=20J=C3=B8rgen=20Ottosen?= Date: Wed, 6 May 2009 19:20:55 +0000 Subject: [PATCH] new test of empty aligned_storage [SVN r52803] --- test/aligned_storage_empy_test.cpp | 119 +++++++++++++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 test/aligned_storage_empy_test.cpp diff --git a/test/aligned_storage_empy_test.cpp b/test/aligned_storage_empy_test.cpp new file mode 100644 index 0000000..79c8519 --- /dev/null +++ b/test/aligned_storage_empy_test.cpp @@ -0,0 +1,119 @@ + +// (C) Copyright Thorsten Ottosen 2009. +// Use, modification and distribution are subject to the +// Boost Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#include "test.hpp" +#include "check_integral_constant.hpp" +#ifdef TEST_STD +# include +# include // max_align and long_long_type +#else +# include +# include +# include +#endif + + +namespace +{ + template< unsigned N, unsigned Alignment > + struct alignment_implementation1 + { + boost::detail::aligned_storage::aligned_storage_imp type; + const void* address() const { return this; } + }; + + template< unsigned N, unsigned Alignment > + struct alignment_implementation2 : private boost::detail::aligned_storage::aligned_storage_imp + { + typedef boost::detail::aligned_storage::aligned_storage_imp type; + const void* address() const { return static_cast(this)->address(); } + }; + + template< unsigned N, class T > + const void* get_address1() + { + alignment_implementation1::value> imp1; + return imp1.address(); + } + + template< unsigned N, class T > + const void* get_address2() + { + alignment_implementation2::value> imp2; + return imp2.address(); + } + + template< class T > + void check() + { + const void* addr1 = get_address1<0,T>(); + const void* addr2 = get_address2<0,T>(); + // + // @remark: only the empty case differs + // + BOOST_CHECK( addr1 != addr2 ); + + addr1 = get_address1<1,T>(); + addr2 = get_address2<1,T>(); + BOOST_CHECK( addr1 == addr2 ); + + addr1 = get_address1<2,T>(); + addr2 = get_address2<2,T>(); + BOOST_CHECK( addr1 == addr2 ); + + addr1 = get_address1<3,T>(); + addr2 = get_address2<3,T>(); + BOOST_CHECK( addr1 == addr2 ); + + addr1 = get_address1<4,T>(); + addr2 = get_address2<4,T>(); + BOOST_CHECK( addr1 == addr2 ); + + addr1 = get_address1<17,T>(); + addr2 = get_address2<17,T>(); + BOOST_CHECK( addr1 == addr2 ); + + addr1 = get_address1<32,T>(); + addr2 = get_address2<32,T>(); + BOOST_CHECK( addr1 == addr2 ); + } +} + +TT_TEST_BEGIN(type_with_empty_alignment_buffer) + +check(); +check(); +check(); +check(); +check(); +check(); +check(); + +#ifdef BOOST_HAS_MS_INT64 +check<__int64>(); +#endif + +check(); +check(); +check(); +check(); +check(); +check(); +check(); +check(); +check(); +check(); + +TT_TEST_END + + + + + + + + +