diff --git a/example/unit_test_example_14.cpp b/example/unit_test_example_14.cpp deleted file mode 100644 index e9699e49..00000000 --- a/example/unit_test_example_14.cpp +++ /dev/null @@ -1,122 +0,0 @@ -// (C) Copyright Gennadiy Rozental 2001-2014. -// Distributed under 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) - -// See http://www.boost.org/libs/test for the library home page. -// -// *************************************************************************** -// DOES NOT WORK; to be fixed - -#define BOOST_TEST_TOOL_REPORT_WARN_FAILURE( assertion_descr ) \ - std::cout << "Condition " << assertion_descr << " is not satisfied\n" - -#include -#include -#include - -#include - -void report( void (*test_func)()) -{ - try { - (*test_func)(); - } catch ( std::runtime_error const& x ) { - std::cout << *boost::get_error_info(x) - << '(' - << *boost::get_error_info(x) - << "): Error in '" << *boost::get_error_info(x) - << "': " << x.what() << std::endl; - } -} - -//------------------------------------------------------------------// - -void do_check() -{ - int i = 62; - BOOST_CHECK( i == 144 ); -} - -//------------------------------------------------------------------// - -void do_check_msg() -{ - int i = 62; - BOOST_CHECK_MESSAGE( i == 144, "Expecting i == 62" ); -} - -//------------------------------------------------------------------// - -void do_check_eq() -{ - int i = 62; - BOOST_CHECK_EQUAL( i, 62 ); - BOOST_CHECK_EQUAL( i, 144 ); -} - -//------------------------------------------------------------------// - -void do_check_le() -{ - int i = 62; - BOOST_CHECK_LE( i, 16 ); -} - -//------------------------------------------------------------------// - -void do_bitwise_eq() -{ - int i = 62; - - BOOST_CHECK_BITWISE_EQUAL( i, 144 ); -} - -//------------------------------------------------------------------// - -int goo() -{ - static int i = 0; - return i++; -} - -struct Foo : boost::noncopyable { - static int copy_counter; - - Foo( int i_ = 0 ) : i(i_) {} - Foo( Foo const& ) { copy_counter++; } - - int i; -}; - -int Foo::copy_counter = 0; - -bool operator==( Foo const&, Foo const& ) { return true; } -std::ostream& operator<<( std::ostream& os, Foo const& ) { return os << "Foo"; } - -bool some_pred( Foo const& foo1, Foo const& foo2, Foo const& foo3, Foo const& foo4 ) -{ - return foo1.i + foo2.i != foo3.i + foo4.i; -} - -void do_check_pred() -{ - BOOST_CHECK_PREDICATE( some_pred, (Foo( 1 ))(Foo( 4 ))(Foo( 2 ))(Foo( 3 )) ); - BOOST_CHECK_EQUAL( Foo::copy_counter, 0 ); -} - -//------------------------------------------------------------------// - -int main() -{ - report( &do_check ); - report( &do_check_msg ); - report( &do_check_eq ); - report( &do_bitwise_eq ); - report( &do_check_pred ); - return 0; -} - -//------------------------------------------------------------------// - -// EOF diff --git a/include/boost/test/test_tools.hpp b/include/boost/test/test_tools.hpp index e1a7e6fe..71e6d2dc 100644 --- a/include/boost/test/test_tools.hpp +++ b/include/boost/test/test_tools.hpp @@ -45,6 +45,8 @@ # include # include +# include +# include #endif #if !BOOST_PP_VARIADICS || ((__cplusplus >= 201103L) && defined(BOOST_NO_CXX11_VARIADIC_MACROS)) diff --git a/include/boost/test/tools/assertion.hpp b/include/boost/test/tools/assertion.hpp index f4c37c7b..9cd1c128 100644 --- a/include/boost/test/tools/assertion.hpp +++ b/include/boost/test/tools/assertion.hpp @@ -18,9 +18,11 @@ #include #include +#include #include // Boost +#include #include // for numeric::conversion_traits #include #include @@ -169,179 +171,6 @@ BOOST_TEST_FOR_EACH_CONST_OP( DEFINE_CONST_OPER ) //____________________________________________________________________________// -namespace op_detail { - -template -inline assertion_result -lexicographic_compare( Lhs const& lhs, Rhs const& rhs ) -{ - assertion_result ar( true ); - - typename Lhs::const_iterator first1 = lhs.begin(); - typename Rhs::const_iterator first2 = rhs.begin(); - typename Lhs::const_iterator last1 = lhs.end(); - typename Rhs::const_iterator last2 = rhs.end(); - std::size_t pos = 0; - - for( ; (first1 != last1) && (first2 != last2); ++first1, ++first2, ++pos ) { - assertion_result const& element_ar = OP::eval(*first1, *first2); - if( !can_be_equal && element_ar ) - return ar; // a < b - - assertion_result const& reverse_ar = OP::eval(*first2, *first1); - if( element_ar && !reverse_ar ) - return ar; // a<=b and !(b<=a) => a < b => return true - - if( element_ar || !reverse_ar ) - continue; // (a<=b and b<=a) or (!(a a == b => keep looking - - // !(a<=b) and b<=a => b < a => return false - ar = false; - ar.message() << "\nFailure at position " << pos << ": " - << tt_detail::print_helper(*first1) - << OP::revert() - << tt_detail::print_helper(*first2) - << ". " << element_ar.message(); - return ar; - } - - - if( first1 != last1 ) { - if( prefer_shorter ) { - ar = false; - ar.message() << "\nFirst collection has extra trailing elements."; - } - } - else if( first2 != last2 ) { - if( !prefer_shorter ) { - ar = false; - ar.message() << "\nSecond collection has extra trailing elements."; - } - } - else if( !can_be_equal ) { - ar = false; - ar.message() << "\nCollections appear to be equal."; - } - - return ar; -} - -template -struct compare_collections; - -template -struct compare_collections > { - typedef op::EQ OP; - - static assertion_result - eval( Lhs const& lhs, Rhs const& rhs ) - { - assertion_result ar( true ); - - if( lhs.size() != rhs.size() ) { - ar = false; - ar.message() << "Collections size mismatch: " << lhs.size() << " != " << rhs.size(); - return ar; - } - - typename Lhs::const_iterator left = lhs.begin(); - typename Rhs::const_iterator right = rhs.begin(); - std::size_t pos = 0; - - for( ; pos < lhs.size(); ++left, ++right, ++pos ) { - assertion_result const element_ar = OP::eval( *left, *right ); - if( element_ar ) - continue; - - ar = false; - ar.message() << "\nMismatch at position " << pos << ": " - << tt_detail::print_helper(*left) - << OP::revert() - << tt_detail::print_helper(*right) - << ". " << element_ar.message(); - } - - return ar; - } -}; - -template -struct compare_collections > { - typedef op::NE OP; - - static assertion_result - eval( Lhs const& lhs, Rhs const& rhs ) - { - assertion_result ar( true ); - - if( lhs.size() != rhs.size() ) - return ar; - - typename Lhs::const_iterator left = lhs.begin(); - typename Rhs::const_iterator right = rhs.begin(); - typename Lhs::const_iterator end = lhs.end(); - - for( ; left != end; ++left, ++right ) { - if( OP::eval( *left, *right ) ) - return ar; - } - - ar = false; - ar.message() << "\nCollections appear to be equal"; - - return ar; - } -}; - -template -struct compare_collections > { - typedef op::LT OP; - - static assertion_result - eval( Lhs const& lhs, Rhs const& rhs ) - { - return op_detail::lexicographic_compare( lhs, rhs ); - } -}; - -template -struct compare_collections > { - typedef op::LE OP; - - static assertion_result - eval( Lhs const& lhs, Rhs const& rhs ) - { - return op_detail::lexicographic_compare( lhs, rhs ); - } -}; - -template -struct compare_collections > { - typedef op::GT OP; - - static assertion_result - eval( Lhs const& lhs, Rhs const& rhs ) - { - return op_detail::lexicographic_compare( lhs, rhs ); - } -}; - -template -struct compare_collections > { - typedef op::GE OP; - - static assertion_result - eval( Lhs const& lhs, Rhs const& rhs ) - { - return op_detail::lexicographic_compare( lhs, rhs ); - } -}; - -} // namespace op_detail - -//____________________________________________________________________________// - #define DEFINE_CSTRING_COMPARISON( oper, name, rev ) \ template \ struct name +struct coll_comp_traits; + +template +struct coll_comp_traits > { + static const bool can_be_equal = false; + static const bool prefer_short = true; +}; + +template +struct coll_comp_traits > { + static const bool can_be_equal = true; + static const bool prefer_short = true; +}; + +template +struct coll_comp_traits > { + static const bool can_be_equal = false; + static const bool prefer_short = false; +}; + +template +struct coll_comp_traits > { + static const bool can_be_equal = true; + static const bool prefer_short = false; +}; + +} // namespace op_detail + +template +inline assertion_result +compare_collections( Lhs const& lhs, Rhs const& rhs, boost::type >* ) +{ + return assertion::op::element_compare >( lhs, rhs ); +} + +//____________________________________________________________________________// + +template +inline assertion_result +compare_collections( Lhs const& lhs, Rhs const& rhs, boost::type >* ) +{ + return assertion::op::non_equality_compare >( lhs, rhs ); +} + +//____________________________________________________________________________// + +template +inline assertion_result +lexicographic_compare( Lhs const& lhs, Rhs const& rhs ) +{ + return assertion::op::lexicographic_compare::can_be_equal, + op_detail::coll_comp_traits::prefer_short>( lhs, rhs ); +} + +//____________________________________________________________________________// + +template +inline assertion_result +compare_collections( Lhs const& lhs, Rhs const& rhs, boost::type* tp ) +{ + return lexicographic_compare( lhs, rhs ); +} + +//____________________________________________________________________________// + #define DEFINE_COLLECTION_COMPARISON( oper, name, _ ) \ template \ struct name elem_op; \ + \ static assertion_result \ eval( Lhs const& lhs, Rhs const& rhs) \ { \ - typedef name OP; \ - typedef op_detail::compare_collections Comp; \ - return Comp::eval( lhs, rhs ); \ + return assertion::op::compare_collections( lhs, rhs, \ + (boost::type*)0 ); \ } \ \ template \ diff --git a/include/boost/test/tools/collection_comparison.hpp b/include/boost/test/tools/collection_comparison.hpp new file mode 100644 index 00000000..f991ecd6 --- /dev/null +++ b/include/boost/test/tools/collection_comparison.hpp @@ -0,0 +1,165 @@ +// (C) Copyright Gennadiy Rozental 2014-2015. +// Distributed under 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) + +// See http://www.boost.org/libs/test for the library home page. +// +//!@file +//!@brief Collection comparison with enhanced reporting +// *************************************************************************** + +#ifndef BOOST_TEST_TOOLS_ASSERTION_HPP_050815GER +#define BOOST_TEST_TOOLS_ASSERTION_HPP_050815GER + +// Boost.Test + +#include + +//____________________________________________________________________________// + +namespace boost { +namespace test_tools { +namespace assertion { + +// ************************************************************************** // +// ************** lexicographic_compare ************** // +// ************************************************************************** // + +namespace op { + +template +inline assertion_result +lexicographic_compare( Lhs const& lhs, Rhs const& rhs ) +{ + assertion_result ar( true ); + + typename Lhs::const_iterator first1 = lhs.begin(); + typename Rhs::const_iterator first2 = rhs.begin(); + typename Lhs::const_iterator last1 = lhs.end(); + typename Rhs::const_iterator last2 = rhs.end(); + std::size_t pos = 0; + + for( ; (first1 != last1) && (first2 != last2); ++first1, ++first2, ++pos ) { + assertion_result const& element_ar = OP::eval(*first1, *first2); + if( !can_be_equal && element_ar ) + return ar; // a < b + + assertion_result const& reverse_ar = OP::eval(*first2, *first1); + if( element_ar && !reverse_ar ) + return ar; // a<=b and !(b<=a) => a < b => return true + + if( element_ar || !reverse_ar ) + continue; // (a<=b and b<=a) or (!(a a == b => keep looking + + // !(a<=b) and b<=a => b < a => return false + ar = false; + ar.message() << "\nFailure at position " << pos << ": " + << tt_detail::print_helper(*first1) + << OP::revert() + << tt_detail::print_helper(*first2) + << ". " << element_ar.message(); + return ar; + } + + + if( first1 != last1 ) { + if( prefer_shorter ) { + ar = false; + ar.message() << "\nFirst collection has extra trailing elements."; + } + } + else if( first2 != last2 ) { + if( !prefer_shorter ) { + ar = false; + ar.message() << "\nSecond collection has extra trailing elements."; + } + } + else if( !can_be_equal ) { + ar = false; + ar.message() << "\nCollections appear to be equal."; + } + + return ar; +} + +//____________________________________________________________________________// + +// ************************************************************************** // +// ************** equality_compare ************** // +// ************************************************************************** // + +template +inline assertion_result +element_compare( Lhs const& lhs, Rhs const& rhs ) +{ + assertion_result ar( true ); + + if( lhs.size() != rhs.size() ) { + ar = false; + ar.message() << "Collections size mismatch: " << lhs.size() << " != " << rhs.size(); + return ar; + } + + typename Lhs::const_iterator left = lhs.begin(); + typename Rhs::const_iterator right = rhs.begin(); + std::size_t pos = 0; + + for( ; pos < lhs.size(); ++left, ++right, ++pos ) { + assertion_result const element_ar = OP::eval( *left, *right ); + if( element_ar ) + continue; + + ar = false; + ar.message() << "\nMismatch at position " << pos << ": " + << tt_detail::print_helper(*left) + << OP::revert() + << tt_detail::print_helper(*right) + << ". " << element_ar.message(); + } + + return ar; +} + +//____________________________________________________________________________// + +// ************************************************************************** // +// ************** non_equality_compare ************** // +// ************************************************************************** // + +template +inline assertion_result +non_equality_compare( Lhs const& lhs, Rhs const& rhs ) +{ + assertion_result ar( true ); + + if( lhs.size() != rhs.size() ) + return ar; + + typename Lhs::const_iterator left = lhs.begin(); + typename Rhs::const_iterator right = rhs.begin(); + typename Lhs::const_iterator end = lhs.end(); + + for( ; left != end; ++left, ++right ) { + if( OP::eval( *left, *right ) ) + return ar; + } + + ar = false; + ar.message() << "\nCollections appear to be equal"; + + return ar; +} + +//____________________________________________________________________________// + +} // namespace op +} // namespace assertion +} // namespace test_tools +} // namespace boost + +#include + +#endif // BOOST_TEST_TOOLS_ASSERTION_HPP_050815GER + diff --git a/include/boost/test/tools/detail/lexicographic_manip.hpp b/include/boost/test/tools/detail/lexicographic_manip.hpp new file mode 100644 index 00000000..93f507d7 --- /dev/null +++ b/include/boost/test/tools/detail/lexicographic_manip.hpp @@ -0,0 +1,70 @@ +// (C) Copyright Gennadiy Rozental 2015. +// Distributed under 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) + +// See http://www.boost.org/libs/test for the library home page. +// +//! @file +//! Lexicographic comparison manipulator implementation +// *************************************************************************** + +#ifndef BOOST_TEST_TOOLS_DETAIL_LEXICOGRAPHIC_MANIP_HPP_050815GER +#define BOOST_TEST_TOOLS_DETAIL_LEXICOGRAPHIC_MANIP_HPP_050815GER + +// Boost Test +#include +#include + +#include +#include +#include + +#include + +//____________________________________________________________________________// + +namespace boost { +namespace test_tools { + +// ************************************************************************** // +// ************** per element comparison manipulator ************** // +// ************************************************************************** // + +//! Bitwise comparison manipulator +struct lexicographic {}; + +//____________________________________________________________________________// + +inline int +operator<<( unit_test::lazy_ostream const&, lexicographic ) { return 0; } + +//____________________________________________________________________________// + +namespace tt_detail { + +template +inline assertion_result +operator<<(assertion_evaluate_t > const& ae, lexicographic ) +{ + typedef typename OP::elem_op elem_op; + return assertion::op::lexicographic_compare( ae.m_e.lhs().value(), ae.m_e.rhs() ); +} + +//____________________________________________________________________________// + +inline check_type +operator<<( assertion_type const&, lexicographic ) +{ + return CHECK_BUILT_ASSERTION; +} + +//____________________________________________________________________________// + +} // namespace tt_detail +} // namespace test_tools +} // namespace boost + +#include + +#endif // BOOST_TEST_TOOLS_DETAIL_LEXICOGRAPHIC_MANIP_HPP_050815GER diff --git a/include/boost/test/tools/detail/per_element_manip.hpp b/include/boost/test/tools/detail/per_element_manip.hpp new file mode 100644 index 00000000..6b632c6a --- /dev/null +++ b/include/boost/test/tools/detail/per_element_manip.hpp @@ -0,0 +1,70 @@ +// (C) Copyright Gennadiy Rozental 2015. +// Distributed under 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) + +// See http://www.boost.org/libs/test for the library home page. +// +//! @file +//! Per element comparison manipulator implementation +// *************************************************************************** + +#ifndef BOOST_TEST_TOOLS_DETAIL_PER_ELEMENT_MANIP_HPP_050815GER +#define BOOST_TEST_TOOLS_DETAIL_PER_ELEMENT_MANIP_HPP_050815GER + +// Boost Test +#include +#include + +#include +#include +#include + +#include + +//____________________________________________________________________________// + +namespace boost { +namespace test_tools { + +// ************************************************************************** // +// ************** per element comparison manipulator ************** // +// ************************************************************************** // + +//! Bitwise comparison manipulator +struct per_element {}; + +//____________________________________________________________________________// + +inline int +operator<<( unit_test::lazy_ostream const&, per_element ) { return 0; } + +//____________________________________________________________________________// + +namespace tt_detail { + +template +inline assertion_result +operator<<(assertion_evaluate_t > const& ae, per_element ) +{ + typedef typename OP::elem_op elem_op; + return assertion::op::element_compare( ae.m_e.lhs().value(), ae.m_e.rhs() ); +} + +//____________________________________________________________________________// + +inline check_type +operator<<( assertion_type const&, per_element ) +{ + return CHECK_BUILT_ASSERTION; +} + +//____________________________________________________________________________// + +} // namespace tt_detail +} // namespace test_tools +} // namespace boost + +#include + +#endif // BOOST_TEST_TOOLS_DETAIL_PER_ELEMENT_MANIP_HPP_050815GER diff --git a/include/boost/test/tools/prod_tools.hpp b/include/boost/test/tools/prod_tools.hpp deleted file mode 100644 index 1de04f9d..00000000 --- a/include/boost/test/tools/prod_tools.hpp +++ /dev/null @@ -1,203 +0,0 @@ -// (C) Copyright Gennadiy Rozental 2009-2014. -// Distributed under 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) - -// See http://www.boost.org/libs/test for the library home page. -// -// File : $RCSfile$ -// -// Version : $Revision$ -// -// Description : contains implementation of test tools usable in production -// *************************************************************************** - -#ifndef BOOST_TEST_PROD_TOOLS_HPP_122109GER -#define BOOST_TEST_PROD_TOOLS_HPP_122109GER - -// Boost.Test -#define BOOST_TEST_PROD -#include - -// Boost -#include -#include - -#include - -//____________________________________________________________________________// - -// ************************************************************************** // -// ************** TOOL BOX ************** // -// ************************************************************************** // - -//____________________________________________________________________________// - -#ifndef BOOST_TEST_TOOL_REPORT_WARN_FAILURE -#define BOOST_TEST_TOOL_REPORT_WARN_FAILURE( failure_descr ) -#endif - -//____________________________________________________________________________// - -#ifndef BOOST_TEST_TOOL_REPORT_CHECK_FAILURE -#define BOOST_TEST_TOOL_REPORT_CHECK_FAILURE( failure_descr ) \ - BOOST_THROW_EXCEPTION( std::runtime_error( failure_descr ) ) -#endif - -//____________________________________________________________________________// - -#ifndef BOOST_TEST_TOOL_REPORT_REQUIRE_FAILURE -#define BOOST_TEST_TOOL_REPORT_REQUIRE_FAILURE( failure_descr ) \ - BOOST_ASSERT( false ) -#endif - -//____________________________________________________________________________// - -#ifndef BOOST_TEST_TOOL_REPORT_FORMAT - -#define BOOST_TEST_TOOL_REPORT_ARG( r, _, arg ) , arg, BOOST_STRINGIZE( arg ) -#define BOOST_TEST_TOOL_REPORT_ARG_DESCR( r, _, arg ) , BOOST_STRINGIZE( arg ) - -#define BOOST_TEST_TOOL_REPORT_ARGS1(ARGS) \ - BOOST_PP_SEQ_SIZE(ARGS) BOOST_PP_SEQ_FOR_EACH( BOOST_TEST_TOOL_REPORT_ARG_DESCR, _, ARGS ) -#define BOOST_TEST_TOOL_REPORT_ARGS2(ARGS) 0 - -#define BOOST_TEST_TOOL_REPORT_FORMAT( frwd_type, pred_res, assertion_descr, CT, ARGS ) \ - ::boost::test_tools::tt_detail::prod_report_format( pred_res, \ - BOOST_TEST_LAZY_MSG( assertion_descr ), \ - ::boost::test_tools::tt_detail::CT, \ - BOOST_JOIN( BOOST_TEST_TOOL_REPORT_ARGS, frwd_type )( ARGS ) ) \ -/**/ - -#endif - -//____________________________________________________________________________// - -// 0 - args exists and need to be forwarded; call prod_check_frwd -#define BOOST_TEST_TOOL_IMPL0( P, assertion_descr, TL, CT, ARGS ) \ - if( BOOST_TEST_TOOL_PRED_HOLDER( P, assertion_descr, CT, ARGS ) ) \ - ((void)0); \ - else BOOST_JOIN( BOOST_JOIN( BOOST_TEST_TOOL_REPORT_, TL), _FAILURE)( \ - PH.failure_descr() ) \ -/**/ - -//____________________________________________________________________________// - -// 1 - args exists, but do not need to be forwarded -#define BOOST_TEST_TOOL_IMPL1( P, assertion_descr, TL, CT, ARGS ) \ - if( ::boost::test_tools::assertion_result const& pr = P BOOST_PP_SEQ_TO_TUPLE( ARGS ) ) \ - ((void)0); \ - else BOOST_JOIN( BOOST_JOIN( BOOST_TEST_TOOL_REPORT_, TL), _FAILURE)( \ - BOOST_TEST_TOOL_REPORT_FORMAT( 1, pr, assertion_descr, CT, ARGS ) ) \ -/**/ - -//____________________________________________________________________________// - -// 2 - assertion with no arguments; -#define BOOST_TEST_TOOL_IMPL2( P, assertion_descr, TL, CT, _ ) \ - if( ::boost::test_tools::assertion_result const& pr = P ) \ - ((void)0); \ - else BOOST_JOIN( BOOST_JOIN( BOOST_TEST_TOOL_REPORT_, TL), _FAILURE)( \ - BOOST_TEST_TOOL_REPORT_FORMAT( 2, pr, assertion_descr, CT, _ ) ) \ -/**/ - -//____________________________________________________________________________// - -#define BOOST_TEST_TOOL_IMPL( frwd_type, P, check_descr, TL, CT, ARGS ) \ - BOOST_JOIN( BOOST_TEST_TOOL_IMPL, frwd_type )( P, check_descr, TL, CT, ARGS ) - -//____________________________________________________________________________// - -namespace boost { -namespace test_tools { -namespace tt_detail { - -// ************************************************************************** // -// ************** prod_report_format ************** // -// ************************************************************************** // - -BOOST_TEST_DECL std::string -prod_report_format( assertion_result const& pr, - unit_test::lazy_ostream const& assertion_descr, - check_type ct, std::size_t num_args, ... ); - -//____________________________________________________________________________// - -// ************************************************************************** // -// ************** predicate_holder ************** // -// ************************************************************************** // - -#define BOOST_TEST_TOOL_PASS_ARG( r, _, arg ) , arg, BOOST_STRINGIZE( arg ) - -#define BOOST_TEST_TOOL_PRED_HOLDER( P, assertion_descr, CT, ARGS ) \ -::boost::test_tools::tt_detail::predicate_holder const& PH = \ -::boost::test_tools::tt_detail::predicate_holder( P, assertion_descr, \ - ::boost::test_tools::tt_detail::CT \ - BOOST_PP_SEQ_FOR_EACH( BOOST_TEST_TOOL_PASS_ARG, _, ARGS ) ) \ -/**/ - -#define TEMPL_PARAMS( z, m, dummy ) , typename BOOST_JOIN( Arg, m ) - -#define FUNC_PARAMS( z, m, dummy ) \ - , BOOST_JOIN( Arg, m ) const& BOOST_JOIN( arg, m ) \ - , char const* BOOST_JOIN( BOOST_JOIN( arg, m ), _descr ) \ -/**/ - -#define PRED_PARAMS( z, m, dummy ) BOOST_PP_COMMA_IF( m ) BOOST_JOIN( arg, m ) - -#define ARG_INFO( z, m, dummy ) \ - , BOOST_JOIN( BOOST_JOIN( arg, m ), _descr ) \ - , &static_cast(unit_test::lazy_ostream::instance() \ - << ::boost::test_tools::tt_detail::print_helper( BOOST_JOIN( arg, m ) )) \ -/**/ - -#define CONSTRUCTOR_IMPL( z, n, dummy ) \ -template \ -predicate_holder( Pred P, char const* assertion_descr, check_type ct \ - BOOST_PP_REPEAT_ ## z( BOOST_PP_ADD( n, 1 ), FUNC_PARAMS, _ ) ) \ -: m_failure_descr( 0 ) \ -{ \ - assertion_result const& pr = \ - P( BOOST_PP_REPEAT_ ## z( BOOST_PP_ADD( n, 1 ), PRED_PARAMS, _ ) ); \ - if( pr ) return; \ - \ - m_failure_descr = new std::string; \ - *m_failure_descr = prod_report_format( pr, \ - BOOST_TEST_LAZY_MSG( assertion_descr ), \ - ct, \ - BOOST_PP_ADD( n, 1 ) \ - BOOST_PP_REPEAT_ ## z( BOOST_PP_ADD( n, 1 ), ARG_INFO, _ ) ); \ -} \ -/**/ - -#ifndef BOOST_TEST_MAX_PREDICATE_ARITY -#define BOOST_TEST_MAX_PREDICATE_ARITY 5 -#endif - -struct predicate_holder { - BOOST_PP_REPEAT( BOOST_TEST_MAX_PREDICATE_ARITY, CONSTRUCTOR_IMPL, _ ) - - ~predicate_holder() { if( m_failure_descr ) delete m_failure_descr; } - std::string const& failure_descr() const { return *m_failure_descr; } - operator bool() const { return !m_failure_descr; } -private: - // Data members - std::string* m_failure_descr; -}; - -#undef TEMPL_PARAMS -#undef FUNC_PARAMS -#undef PRED_INFO -#undef ARG_INFO -#undef CONSTRUCTOR_IMPL - -//____________________________________________________________________________// - -} // namespace tt_detail -} // namespace test_tools -} // namespace boost - -#include - -#endif // BOOST_TEST_PROD_TOOLS_HPP_122109GER diff --git a/include/boost/test/utils/is_cstring.hpp b/include/boost/test/utils/is_cstring.hpp index cbdbe667..92387703 100644 --- a/include/boost/test/utils/is_cstring.hpp +++ b/include/boost/test/utils/is_cstring.hpp @@ -9,7 +9,7 @@ // // Version : $Revision$ // -// Description : defines the is_forward_iterable collection type trait +// Description : defines the is_cstring type trait // *************************************************************************** #ifndef BOOST_TEST_IS_CSTRING_HPP_112512GER diff --git a/test/test_collection_comparison.cpp b/test/test_collection_comparison.cpp index 7d61680e..55cfb7b9 100644 --- a/test/test_collection_comparison.cpp +++ b/test/test_collection_comparison.cpp @@ -15,7 +15,8 @@ // Boost.Test #define BOOST_TEST_MODULE Test collection`s comparisons #include -namespace tt=boost::test_tools; +namespace tt = boost::test_tools; +namespace ut = boost::unit_test; #define VALIDATE_OP( op ) \ { \ @@ -39,7 +40,7 @@ validate_comparisons(Col const& c1, Col const& c2 ) VALIDATE_OP( >= ) } -BOOST_AUTO_TEST_CASE( test2 ) +BOOST_AUTO_TEST_CASE( test_against_overloaded_comp_op ) { std::vector a{1, 2, 3}; std::vector b{1, 3, 2}; @@ -56,4 +57,84 @@ BOOST_AUTO_TEST_CASE( test2 ) //____________________________________________________________________________// +BOOST_AUTO_TEST_CASE( test_per_element_eq, * ut::expected_failures(2) ) +{ + std::vector a{1, 2, 3}; + std::vector b{1, 3, 2}; + + BOOST_TEST( a == b, tt::per_element() ); +} + +//____________________________________________________________________________// + +BOOST_AUTO_TEST_CASE( test_per_element_ne, * ut::expected_failures(1) ) +{ + std::vector a{1, 2, 3}; + std::vector b{1, 3, 2}; + + BOOST_TEST( a != b, tt::per_element() ); +} + +//____________________________________________________________________________// + +BOOST_AUTO_TEST_CASE( test_per_element_lt, * ut::expected_failures(2) ) +{ + std::vector a{1, 2, 3}; + std::vector b{1, 3, 2}; + + BOOST_TEST( a < b, tt::per_element() ); +} + +//____________________________________________________________________________// + +BOOST_AUTO_TEST_CASE( test_per_element_ge, * ut::expected_failures(1) ) +{ + std::vector a{1, 2, 3}; + std::vector b{1, 3, 2}; + + BOOST_TEST( b >= a, tt::per_element() ); +} + +//____________________________________________________________________________// + +BOOST_AUTO_TEST_CASE( test_lexicographic_lt ) +{ + std::vector a{1, 2, 3}; + std::vector b{1, 3, 2}; + + BOOST_TEST( a < b, tt::lexicographic() ); +} + +//____________________________________________________________________________// + +BOOST_AUTO_TEST_CASE( test_lexicographic_le ) +{ + std::vector a{1, 2, 3}; + std::vector b{1, 3, 2}; + + BOOST_TEST( a <= b, tt::lexicographic() ); +} + +//____________________________________________________________________________// + +BOOST_AUTO_TEST_CASE( test_lexicographic_gt ) +{ + std::vector a{1, 2, 3}; + std::vector b{1, 3, 2}; + + BOOST_TEST( b > a, tt::lexicographic() ); +} + +//____________________________________________________________________________// + +BOOST_AUTO_TEST_CASE( test_lexicographic_ge ) +{ + std::vector a{1, 2, 3}; + std::vector b{1, 3, 2}; + + BOOST_TEST( b >= a, tt::lexicographic() ); +} + +//____________________________________________________________________________// + // EOF diff --git a/tools/console_test_runner/test/test_runner_test.cpp b/tools/console_test_runner/test/test_runner_test.cpp index ab72536e..b3c40e79 100644 --- a/tools/console_test_runner/test/test_runner_test.cpp +++ b/tools/console_test_runner/test/test_runner_test.cpp @@ -38,7 +38,7 @@ extern "C" { #ifdef BOOST_WINDOWS __declspec(dllexport) #endif - bool +bool init_unit_test() { framework::master_test_suite().p_name.value = "Test runner test";