From 10e5587b9e2ae1417cbd831f937d194cf39f4b47 Mon Sep 17 00:00:00 2001 From: Daryle Walker Date: Mon, 14 Jul 2008 04:25:31 +0000 Subject: [PATCH] Improved/added testing for the processor-optimized integer template [SVN r47413] --- test/integer_test.cpp | 45 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/test/integer_test.cpp b/test/integer_test.cpp index d296011..6772e56 100644 --- a/test/integer_test.cpp +++ b/test/integer_test.cpp @@ -8,6 +8,7 @@ // See http://www.boost.org/libs/integer for documentation. // Revision History +// 14 Jul 08 Improved testing of fast-integer template. (Daryle Walker) // 13 Jul 08 Modernized tests w/ MPL instead of giant macros (Daryle Walker) // 07 Jul 08 Changed tests to use the unit-test system (Daryle Walker) // 04 Oct 01 Added tests for new templates; rewrote code (Daryle Walker) @@ -49,6 +50,11 @@ #include // for std::type_info +// Control what the "fast" specialization of "short" is +#ifndef CONTROL_FAST_SHORT +#define CONTROL_FAST_SHORT long +#endif + // Control if the names of the types for each version // of the integer templates will be printed. #ifndef CONTROL_SHOW_TYPES @@ -57,13 +63,15 @@ // If specializations have not already been done, then we can confirm -// the effects of the "fast" types by making a specialization. +// the effects of the "fast" types by making a specialization. If there +// is a specialization for "short," make sure that CONTROL_FAST_SHORT +// is set to a type distinct from "short" and the default implementation. namespace boost { template < > struct int_fast_t< short > { - typedef long fast; + typedef CONTROL_FAST_SHORT fast; }; } @@ -177,6 +185,34 @@ typedef boost::mpl::push_back< } // unnamed namespace +// Check the processor-optimzed type system +BOOST_AUTO_TEST_SUITE( optimized_type_tests ) + +// Check the optimzed type override of a given type +BOOST_AUTO_TEST_CASE( fast_type_test ) +{ +#ifndef BOOST_NO_USING_TEMPLATE + using std::numeric_limits; +#else + using namespace std; +#endif + + typedef short least_type; + typedef boost::int_fast_t::fast fast_type; + typedef numeric_limits least_limits; + typedef numeric_limits fast_limits; + + BOOST_MPL_ASSERT_RELATION( (boost::is_same::value), + ==, false ); + BOOST_MPL_ASSERT_RELATION( fast_limits::is_specialized, ==, true ); + BOOST_MPL_ASSERT_RELATION( fast_limits::is_signed && + fast_limits::is_bounded, ==, true ); + BOOST_MPL_ASSERT_RELATION( fast_limits::radix, ==, 2 ); + BOOST_MPL_ASSERT_RELATION( fast_limits::digits, >=, least_limits::digits ); +} + +BOOST_AUTO_TEST_SUITE_END() + // Check if given types can support given size parameters BOOST_AUTO_TEST_SUITE( show_type_tests ) @@ -404,3 +440,8 @@ BOOST_AUTO_TEST_CASE_TEMPLATE( fit_for_shifted_values_test, T, } BOOST_AUTO_TEST_SUITE_END() + +// Verification of bugs and their fixes +BOOST_AUTO_TEST_SUITE( bug_fix_tests ) + +BOOST_AUTO_TEST_SUITE_END()