1 2 // (C) Copyright John Maddock 2000. 3 // Use, modification and distribution are subject to the 4 // Boost Software License, Version 1.0. (See accompanying file 5 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 7 #ifndef BOOST_CHECK_INTEGRAL_CONSTANT_HPP 8 #define BOOST_CHECK_INTEGRAL_CONSTANT_HPP 9 10 #include "test.hpp" 11 12 namespace boost{ 13 namespace detail{ 14 15 /* 16 macro: 17 BOOST_CHECK_INTEGRAL_CONSTANT(expression, expected_value) 18 19 expression: an integral constant expression to check. 20 expected_value: the value expected. 21 */ 22 23 template <long test_value> 24 struct integral_constant 25 { valueboost::detail::integral_constant26 static long value() { return test_value; } 27 }; 28 29 template <class T, class U> tt_compare(T found,U expected)30 bool tt_compare(T found, U expected) 31 { return static_cast<U>(found) == expected; } 32 33 #define BOOST_CHECK_INTEGRAL_CONSTANT(expression, expected_value)\ 34 if(!::boost::detail::tt_compare(::boost::detail::integral_constant<(int)(expression)>::value(), (int)expression)){\ 35 BOOST_CHECK_MESSAGE(false, "The expression: \"" << BOOST_STRINGIZE(expression) << "\" had differing values depending upon whether it was used as an integral constant expression or not");\ 36 }else{\ 37 BOOST_CHECK_MESSAGE(true, "Validating Integral Constant Expression: \"" << BOOST_STRINGIZE(expression) << "\"");\ 38 }\ 39 if(!::boost::detail::tt_compare((int)expression, expected_value))\ 40 BOOST_CHECK_MESSAGE(false, "The expression: \"" << BOOST_STRINGIZE(expression) << "\" had an invalid value (found " << ::boost::detail::integral_constant<(int)(expression)>::value() << ", expected " << expected_value << ")" ) 41 42 /* 43 macro: 44 BOOST_CHECK_SOFT_INTEGRAL_CONSTANT(expression, expected_value, alternate_value) 45 46 expression: an integral constant expression to check. 47 expected_value: the value expected. 48 alternate_value: an alternative value that results is a warning not a failure if found. 49 */ 50 51 #define BOOST_CHECK_SOFT_INTEGRAL_CONSTANT(expression, expected_value, alternate_value)\ 52 if(!::boost::detail::tt_compare(::boost::detail::integral_constant<(int)(expression)>::value(), (int)expression)){\ 53 BOOST_CHECK_MESSAGE(false, "The expression: \"" << BOOST_STRINGIZE(expression) << "\" had differing values depending upon whether it was used as an integral constant expression or not");\ 54 }else{\ 55 BOOST_CHECK_MESSAGE(true, "Validating Integral Constant Expression: \"" << BOOST_STRINGIZE(expression) << "\"");\ 56 }\ 57 if(!::boost::detail::tt_compare((int)expression, expected_value))\ 58 {\ 59 if(!::boost::detail::tt_compare((int)expression, alternate_value))\ 60 {\ 61 BOOST_CHECK_MESSAGE(false, "The expression: \"" << BOOST_STRINGIZE(expression) << "\" had an invalid value (found " << ::boost::detail::integral_constant<(int)(expression)>::value() << ", expected " << expected_value << ")" );\ 62 }\ 63 else\ 64 {\ 65 BOOST_WARN_MESSAGE(false, "<note>The expression: \"" << BOOST_STRINGIZE(expression) << "\" did not have the value we wish it to have (found " << ::boost::detail::integral_constant<(int)(expression)>::value() << ", expected " << expected_value << ")</note>" );\ 66 }\ 67 } 68 69 70 }//detail 71 }//boost 72 73 74 #endif 75 76 77 78 79 80