mirror of
https://github.com/mat007/turtle.git
synced 2026-06-22 12:13:43 +00:00
Added support for dereferencing in mock::equal
This commit is contained in:
parent
a2d36e961a
commit
5d11db0f52
10 changed files with 117 additions and 12 deletions
|
|
@ -70,6 +70,12 @@
|
|||
# endif
|
||||
#endif
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_HDR_FUNCTIONAL)
|
||||
# ifndef MOCK_NO_HDR_FUNCTIONAL
|
||||
# define MOCK_HDR_FUNCTIONAL
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_HDR_MUTEX) && !defined(BOOST_NO_0X_HDR_MUTEX)
|
||||
# ifndef MOCK_NO_HDR_MUTEX
|
||||
# define MOCK_HDR_MUTEX
|
||||
|
|
|
|||
|
|
@ -158,9 +158,8 @@ namespace detail
|
|||
Expected_##n expected##n;
|
||||
|
||||
#define MOCK_CONSTRAINT_CREF_PARAM(z, n, Args) \
|
||||
typename \
|
||||
const boost::unwrap_reference< Expected_##n >::type& \
|
||||
BOOST_PP_ARRAY_ELEM(n, Args)
|
||||
const typename boost::unwrap_reference< Expected_##n >::type& \
|
||||
BOOST_PP_ARRAY_ELEM(n, Args)
|
||||
|
||||
#define MOCK_CONSTRAINT_ARG(z, n, Args) \
|
||||
BOOST_FWD_REF(T##n) BOOST_PP_ARRAY_ELEM(n, Args)
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@
|
|||
#include <boost/utility/enable_if.hpp>
|
||||
#include <boost/type_traits/common_type.hpp>
|
||||
#include <boost/type_traits/is_convertible.hpp>
|
||||
#include <boost/type_traits/has_equal_to.hpp>
|
||||
#include <boost/test/floating_point_comparison.hpp>
|
||||
|
||||
namespace mock
|
||||
|
|
@ -26,7 +27,6 @@ namespace mock
|
|||
MOCK_UNARY_CONSTRAINT( negate, 0,, ! actual )
|
||||
MOCK_UNARY_CONSTRAINT( evaluate, 0,, actual() )
|
||||
|
||||
MOCK_NARY_CONSTRAINT( equal, 1, ( expected ), actual == expected )
|
||||
MOCK_NARY_CONSTRAINT( less, 1, ( expected ), actual < expected )
|
||||
MOCK_NARY_CONSTRAINT( greater, 1, ( expected ), actual > expected )
|
||||
MOCK_NARY_CONSTRAINT( less_equal, 1, ( expected ), actual <= expected )
|
||||
|
|
@ -107,6 +107,43 @@ namespace detail
|
|||
|
||||
namespace detail
|
||||
{
|
||||
template< typename Expected >
|
||||
struct equal
|
||||
{
|
||||
explicit equal( Expected expected )
|
||||
: expected_( expected )
|
||||
{}
|
||||
template< typename Actual >
|
||||
bool operator()( const Actual& actual,
|
||||
typename boost::enable_if<
|
||||
boost::has_equal_to<
|
||||
Actual,
|
||||
typename
|
||||
boost::unwrap_reference< Expected >::type
|
||||
>
|
||||
>::type* = 0 ) const
|
||||
{
|
||||
return actual == boost::unwrap_ref( expected_ );
|
||||
}
|
||||
template< typename Actual >
|
||||
bool operator()( const Actual& actual,
|
||||
typename boost::disable_if<
|
||||
boost::has_equal_to<
|
||||
Actual,
|
||||
typename
|
||||
boost::unwrap_reference< Expected >::type
|
||||
>
|
||||
>::type* = 0 ) const
|
||||
{
|
||||
return actual && *actual == boost::unwrap_ref( expected_ );
|
||||
}
|
||||
friend std::ostream& operator<<( std::ostream& s, const equal& e )
|
||||
{
|
||||
return s << "equal( " << mock::format( e.expected_ ) << " )";
|
||||
}
|
||||
Expected expected_;
|
||||
};
|
||||
|
||||
template< typename Expected >
|
||||
struct same
|
||||
{
|
||||
|
|
@ -187,6 +224,8 @@ namespace detail
|
|||
>
|
||||
>::type* = 0 ) const
|
||||
{
|
||||
if( ! actual )
|
||||
return false;
|
||||
*actual = boost::unwrap_ref( expected_ );
|
||||
return true;
|
||||
}
|
||||
|
|
@ -216,6 +255,12 @@ namespace detail
|
|||
};
|
||||
}
|
||||
|
||||
template< typename T >
|
||||
constraint< detail::equal< T > > equal( BOOST_FWD_REF(T) t )
|
||||
{
|
||||
return detail::equal< T >( boost::forward< T >( t ) );
|
||||
}
|
||||
|
||||
template< typename T >
|
||||
constraint< detail::same< T > > same( T& t )
|
||||
{
|
||||
|
|
|
|||
|
|
@ -27,8 +27,13 @@ namespace detail
|
|||
class action_base
|
||||
{
|
||||
private:
|
||||
#ifdef MOCK_HDR_FUNCTIONAL
|
||||
typedef std::function< Signature > functor_type;
|
||||
typedef std::function< Result() > action_type;
|
||||
#else
|
||||
typedef boost::function< Signature > functor_type;
|
||||
typedef boost::function< Result() > action_type;
|
||||
#endif
|
||||
|
||||
public:
|
||||
const functor_type& functor() const
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
|
||||
#include "config.hpp"
|
||||
#include "log.hpp"
|
||||
#include "constraint.hpp"
|
||||
#include "constraints.hpp"
|
||||
#include "detail/is_functor.hpp"
|
||||
#include <boost/utility/enable_if.hpp>
|
||||
#include <boost/ref.hpp>
|
||||
|
|
@ -26,9 +26,10 @@ namespace mock
|
|||
explicit matcher( Expected expected )
|
||||
: expected_( expected )
|
||||
{}
|
||||
bool operator()( Actual actual )
|
||||
bool operator()( const Actual& actual )
|
||||
{
|
||||
return actual == boost::unwrap_ref( expected_ );
|
||||
return mock::equal(
|
||||
boost::unwrap_ref( expected_ ) ).c_( actual );
|
||||
}
|
||||
friend std::ostream& operator<<(
|
||||
std::ostream& s, const matcher& m )
|
||||
|
|
@ -66,7 +67,7 @@ namespace mock
|
|||
explicit matcher( const constraint< Constraint >& c )
|
||||
: c_( c.c_ )
|
||||
{}
|
||||
bool operator()( Actual actual )
|
||||
bool operator()( const Actual& actual )
|
||||
{
|
||||
return c_( actual );
|
||||
}
|
||||
|
|
@ -90,7 +91,7 @@ namespace mock
|
|||
explicit matcher( const Functor& f )
|
||||
: c_( f )
|
||||
{}
|
||||
bool operator()( Actual actual )
|
||||
bool operator()( const Actual& actual )
|
||||
{
|
||||
return c_( actual );
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue