BOOST_WARN_PREDICATE( predicate, arguments_list )
BOOST_CHECK_PREDICATE( predicate, arguments_list )
BOOST_REQUIRE_PREDICATE( predicate, arguments_list )

These are generic tools used to validate an arbitrary supplied predicate functor (there is a compile time limit on predicate arity defined by the configurable macro BOOST_TEST_MAX_PREDICATE_ARITY). To validate zero arity predicate use BOOST_<level> tools. In other cases prefer theses tools. The advantage of these tools is that they show arguments values in case of predicate failure.

The first parameter is the predicate itself. The second parameter is the list of predicate arguments each wrapped in round brackets (BOOST_PP sequence format).

Example: test.cpp

#define BOOST_TEST_MAIN
#include <boost/test/unit_test.hpp>
using namespace boost::unit_test; bool moo( int arg1, int arg2, int mod ) { return ((arg1+arg2) % mod) == 0; } BOOST_AUTO_TEST_CASE( test ) { int i = 17; int j = 15; unit_test_log.set_threshold_level( log_warnings ); BOOST_WARN( moo( 12,i,j ) ); BOOST_WARN_PREDICATE( moo, (12)(i)(j) ); }

Output:

Running 1 test case...
test.cpp(13): warning in "test": condition moo( 12,i,j ) is not satisfied
test.cpp(14): warning in "test": condition moo( 12, i, j ) is not satisfied for ( 12, 17, 15 )

*** No errors detected

Example: test.cpp

#define BOOST_TEST_MAIN
#include <boost/test/unit_test.hpp>
#include <functional>
BOOST_AUTO_TEST_CASE( test ) { int i = 17; BOOST_CHECK_PREDICATE( std::not_equal_to<int>(), (i)(17) ); }

Output:

Running 1 test case...
test.cpp(10): error in "test": check std::not_equal_to<int>()( i, 17 ) failed for ( 17, 17 )

*** 1 failure detected in test suite "Master Test Suite"

See Also

BOOST_CHECK