mirror of
https://github.com/mat007/turtle.git
synced 2026-06-22 12:13:43 +00:00
Generalized to MOCK_CONSTRAINT
git-svn-id: https://svn.code.sf.net/p/turtle/code/trunk@660 860be788-9bd5-4423-9f1e-828f051e677b
This commit is contained in:
parent
8a6edd531e
commit
400aaddf9a
7 changed files with 108 additions and 123 deletions
|
|
@ -12,6 +12,11 @@
|
|||
#include "config.hpp"
|
||||
#include "log.hpp"
|
||||
#include <boost/preprocessor/stringize.hpp>
|
||||
#include <boost/preprocessor/control/if.hpp>
|
||||
#include <boost/preprocessor/repetition/enum_binary_params.hpp>
|
||||
#include <boost/preprocessor/repetition/enum_params.hpp>
|
||||
#include <boost/preprocessor/repetition/enum.hpp>
|
||||
#include <boost/preprocessor/repetition/repeat.hpp>
|
||||
|
||||
namespace mock
|
||||
{
|
||||
|
|
@ -119,94 +124,79 @@ namespace detail
|
|||
}
|
||||
} // mock
|
||||
|
||||
#define MOCK_UNARY_CONSTRAINT(N, Expr) \
|
||||
#define MOCK_UNARY_CONSTRAINT(n, Name, Expr) \
|
||||
namespace detail \
|
||||
{ \
|
||||
struct N \
|
||||
struct Name \
|
||||
{ \
|
||||
template< typename Actual > \
|
||||
bool operator()( const Actual& actual ) const \
|
||||
{ \
|
||||
return Expr; \
|
||||
} \
|
||||
friend std::ostream& operator<<( std::ostream& s, const N& ) \
|
||||
friend std::ostream& operator<<( std::ostream& s, const Name& ) \
|
||||
{ \
|
||||
return s << BOOST_STRINGIZE(N); \
|
||||
return s << BOOST_STRINGIZE(Name); \
|
||||
} \
|
||||
}; \
|
||||
} \
|
||||
const mock::constraint< detail::N > N;
|
||||
const mock::constraint< detail::Name > Name;
|
||||
|
||||
#define MOCK_BINARY_CONSTRAINT(N, Expr) \
|
||||
#define MOCK_CONSTRAINT_ASSIGN(z, n, d) \
|
||||
expected##n( e##n )
|
||||
|
||||
#define MOCK_CONSTRAINT_UNWRAP_REF(z, n, d) \
|
||||
boost::unwrap_ref( expected##n )
|
||||
|
||||
#define MOCK_CONSTRAINT_FORMAT(z, n, d) \
|
||||
BOOST_PP_IF(n, << ", " <<,) mock::format( c.expected##n )
|
||||
|
||||
#define MOCK_CONSTRAINT_MEMBER(z, n, d) \
|
||||
Expected_##n expected##n;
|
||||
|
||||
#define MOCK_NARY_CONSTRAINT(n, Name, Expr) \
|
||||
namespace detail \
|
||||
{ \
|
||||
template< typename Expected > \
|
||||
struct N \
|
||||
template< BOOST_PP_ENUM_PARAMS(n, typename Expected_) > \
|
||||
struct Name \
|
||||
{ \
|
||||
explicit N( const Expected& expected ) \
|
||||
: expected_( expected ) \
|
||||
explicit Name( \
|
||||
BOOST_PP_ENUM_BINARY_PARAMS(n, const Expected_, & e ) ) \
|
||||
: BOOST_PP_ENUM(n, MOCK_CONSTRAINT_ASSIGN, _) \
|
||||
{} \
|
||||
template< typename Actual > \
|
||||
bool operator()( const Actual& actual ) const \
|
||||
{ \
|
||||
return test( actual, boost::unwrap_ref( expected_ ) ); \
|
||||
return test( actual, \
|
||||
BOOST_PP_ENUM(n, MOCK_CONSTRAINT_UNWRAP_REF, _ ) ); \
|
||||
} \
|
||||
template< typename Actual, typename T > \
|
||||
bool test( const Actual& actual, const T& expected ) const \
|
||||
{ \
|
||||
return Expr; \
|
||||
} \
|
||||
friend std::ostream& operator<<( std::ostream& s, const N& n ) \
|
||||
{ \
|
||||
return s << BOOST_STRINGIZE(N) \
|
||||
<< "( " << mock::format( n.expected_ ) << " )"; \
|
||||
} \
|
||||
Expected expected_; \
|
||||
}; \
|
||||
} \
|
||||
template< typename Expected > \
|
||||
mock::constraint< detail::N< Expected > > N( Expected expected ) \
|
||||
{ \
|
||||
return detail::N< Expected >( expected ); \
|
||||
}
|
||||
|
||||
#define MOCK_TERNARY_CONSTRAINT(N, Expr) \
|
||||
namespace detail \
|
||||
{ \
|
||||
template< typename Expected, typename Arg > \
|
||||
struct N \
|
||||
{ \
|
||||
explicit N( const Expected& expected, const Arg& arg ) \
|
||||
: expected_( expected ) \
|
||||
, arg_( arg ) \
|
||||
{} \
|
||||
template< typename Actual > \
|
||||
bool operator()( const Actual& actual ) const \
|
||||
{ \
|
||||
return test( actual, boost::unwrap_ref( expected_ ), \
|
||||
boost::unwrap_ref( arg_ ) ); \
|
||||
} \
|
||||
template< typename Actual, typename T1, typename T2 > \
|
||||
template< typename Actual, BOOST_PP_ENUM_PARAMS(n, typename T) > \
|
||||
bool test( const Actual& actual, \
|
||||
const T1& expected, const T2& arg ) const \
|
||||
BOOST_PP_ENUM_BINARY_PARAMS(n, const T, & expected_ ) ) const \
|
||||
{ \
|
||||
return Expr; \
|
||||
} \
|
||||
friend std::ostream& operator<<( std::ostream& s, const N& n ) \
|
||||
friend std::ostream& operator<<( std::ostream& s, const Name& c ) \
|
||||
{ \
|
||||
return s << BOOST_STRINGIZE(N) \
|
||||
<< "( " << mock::format( n.expected_ ) \
|
||||
<< ", " << mock::format( n.arg_ ) << " )"; \
|
||||
return s << BOOST_STRINGIZE(Name) << "( " \
|
||||
<< BOOST_PP_REPEAT(n, MOCK_CONSTRAINT_FORMAT, _) \
|
||||
<< " )"; \
|
||||
} \
|
||||
Expected expected_; \
|
||||
Arg arg_; \
|
||||
BOOST_PP_REPEAT(n, MOCK_CONSTRAINT_MEMBER, _) \
|
||||
}; \
|
||||
} \
|
||||
template< typename Expected, typename Arg > \
|
||||
mock::constraint< detail::N< Expected, Arg > > N( \
|
||||
Expected expected, Arg arg ) \
|
||||
template< BOOST_PP_ENUM_PARAMS(n, typename Expected_) > \
|
||||
mock::constraint< detail::Name< \
|
||||
BOOST_PP_ENUM_PARAMS(n, Expected_) > \
|
||||
> Name( BOOST_PP_ENUM_BINARY_PARAMS(n, Expected_, expected_ ) ) \
|
||||
{ \
|
||||
return detail::N< Expected, Arg >( expected, arg ); \
|
||||
return detail::Name< BOOST_PP_ENUM_PARAMS(n, Expected_) >( \
|
||||
BOOST_PP_ENUM_PARAMS(n, expected_ ) ); \
|
||||
}
|
||||
|
||||
#define MOCK_CONSTRAINT(n, Name, Expr) \
|
||||
BOOST_PP_IF(n, \
|
||||
MOCK_NARY_CONSTRAINT, \
|
||||
MOCK_UNARY_CONSTRAINT)(n, Name, Expr)
|
||||
|
||||
#endif // MOCK_CONSTRAINT_HPP_INCLUDED
|
||||
|
|
|
|||
|
|
@ -14,37 +14,33 @@
|
|||
#include "detail/addressof.hpp"
|
||||
#include <boost/ref.hpp>
|
||||
#include <boost/utility/enable_if.hpp>
|
||||
#include <boost/utility/addressof.hpp>
|
||||
#include <boost/type_traits/is_convertible.hpp>
|
||||
#include <boost/test/floating_point_comparison.hpp>
|
||||
|
||||
namespace mock
|
||||
{
|
||||
MOCK_UNARY_CONSTRAINT( any, true && &actual )
|
||||
MOCK_UNARY_CONSTRAINT( affirm, !! actual )
|
||||
MOCK_UNARY_CONSTRAINT( negate, ! actual )
|
||||
MOCK_UNARY_CONSTRAINT( evaluate, actual() )
|
||||
MOCK_CONSTRAINT( 0, any, true && &actual )
|
||||
MOCK_CONSTRAINT( 0, affirm, !! actual )
|
||||
MOCK_CONSTRAINT( 0, negate, ! actual )
|
||||
MOCK_CONSTRAINT( 0, evaluate, actual() )
|
||||
|
||||
MOCK_BINARY_CONSTRAINT( equal, actual == expected )
|
||||
MOCK_BINARY_CONSTRAINT( less, actual < expected )
|
||||
MOCK_BINARY_CONSTRAINT( greater, actual > expected )
|
||||
MOCK_BINARY_CONSTRAINT( less_equal, actual <= expected )
|
||||
MOCK_BINARY_CONSTRAINT( greater_equal, actual >= expected )
|
||||
MOCK_CONSTRAINT( 1, equal, actual == expected_0 )
|
||||
MOCK_CONSTRAINT( 1, less, actual < expected_0 )
|
||||
MOCK_CONSTRAINT( 1, greater, actual > expected_0 )
|
||||
MOCK_CONSTRAINT( 1, less_equal, actual <= expected_0 )
|
||||
MOCK_CONSTRAINT( 1, greater_equal, actual >= expected_0 )
|
||||
|
||||
MOCK_BINARY_CONSTRAINT( small, \
|
||||
( boost::test_tools::check_is_small( actual, expected ) ) );
|
||||
|
||||
MOCK_TERNARY_CONSTRAINT( close, \
|
||||
MOCK_CONSTRAINT( 1, small, \
|
||||
( boost::test_tools::check_is_small( actual, expected_0 ) ) )
|
||||
MOCK_CONSTRAINT( 2, close, \
|
||||
( boost::test_tools::check_is_close( \
|
||||
actual, expected, \
|
||||
boost::test_tools::percent_tolerance( arg ) ) ) );
|
||||
|
||||
MOCK_TERNARY_CONSTRAINT( close_fraction, \
|
||||
actual, expected_0, \
|
||||
boost::test_tools::percent_tolerance( expected_1 ) ) ) )
|
||||
MOCK_CONSTRAINT( 2, close_fraction, \
|
||||
( boost::test_tools::check_is_close( \
|
||||
actual, expected, \
|
||||
boost::test_tools::fraction_tolerance( arg ) ) ) );
|
||||
|
||||
MOCK_TERNARY_CONSTRAINT( near, std::abs( actual - expected ) < arg );
|
||||
actual, expected_0, \
|
||||
boost::test_tools::fraction_tolerance( expected_1 ) ) ) )
|
||||
MOCK_CONSTRAINT( 2, near, std::abs( actual - expected_0 ) < expected_1 )
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@
|
|||
|
||||
#define MOCK_EXPECTATION_IN_ADD(z, n, d ) \
|
||||
add( s##n.impl_ );
|
||||
|
||||
#define MOCK_EXPECTATION_IN(z, n, d) \
|
||||
expectation& in( BOOST_PP_ENUM_PARAMS(n, sequence& s) ) \
|
||||
{ \
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue