mirror of
https://github.com/mat007/turtle.git
synced 2026-06-22 12:13:43 +00:00
Added support for move only types to constraints
Therefore mock::retrieve now supports std::unique_ptr.
This commit is contained in:
parent
5795f4be70
commit
bccd3ff303
8 changed files with 60 additions and 19 deletions
|
|
@ -183,6 +183,19 @@ namespace detail
|
|||
return true;
|
||||
}
|
||||
template< typename Actual >
|
||||
bool operator()( BOOST_RV_REF(Actual) actual,
|
||||
typename boost::disable_if<
|
||||
boost::is_convertible<
|
||||
const Actual*,
|
||||
typename
|
||||
boost::unwrap_reference< Expected >::type
|
||||
>
|
||||
>::type* = 0 ) const
|
||||
{
|
||||
*expected_ = boost::move( actual );
|
||||
return true;
|
||||
}
|
||||
template< typename Actual >
|
||||
bool operator()( Actual& actual,
|
||||
typename boost::enable_if<
|
||||
boost::is_convertible< Actual*,
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@
|
|||
matcher< T##n, Constraint_##n > c##n##_;
|
||||
|
||||
#define MOCK_EXPECTATION_IS_VALID(z, n, d) \
|
||||
BOOST_PP_IF(n, &&,) c##n##_( a##n )
|
||||
BOOST_PP_IF(n, &&,) c##n##_( boost::forward< T##n >( a##n ) )
|
||||
|
||||
#define MOCK_EXPECTATION_SERIALIZE(z, n, d) \
|
||||
BOOST_PP_IF(n, << ", " <<,) c##n##_
|
||||
|
|
@ -23,8 +23,8 @@
|
|||
#define MOCK_EXPECTATION_SERIALIZE_ANY(z, n, d) \
|
||||
BOOST_PP_IF(n, << ", " <<,) "any"
|
||||
|
||||
#define MOCK_CALL_PARAM_TYPE(z, n, d) \
|
||||
typename boost::call_traits< T##n >::param_type
|
||||
#define MOCK_EXPECTATION_PARAM(z, n, Args) \
|
||||
boost::forward< T##n >( a##n )
|
||||
|
||||
namespace mock
|
||||
{
|
||||
|
|
@ -39,7 +39,7 @@ namespace detail
|
|||
{
|
||||
private:
|
||||
virtual bool operator()(
|
||||
BOOST_PP_ENUM(MOCK_NUM_ARGS, MOCK_CALL_PARAM_TYPE, _) )
|
||||
BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, T) )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
|
@ -73,7 +73,7 @@ namespace detail
|
|||
|
||||
private:
|
||||
virtual bool operator()(
|
||||
BOOST_PP_ENUM(MOCK_NUM_ARGS, MOCK_CALL_PARAM, _) )
|
||||
BOOST_PP_ENUM_BINARY_PARAMS(MOCK_NUM_ARGS, T, a) )
|
||||
{
|
||||
return BOOST_PP_REPEAT(MOCK_NUM_ARGS,
|
||||
MOCK_EXPECTATION_IS_VALID, _);
|
||||
|
|
@ -103,9 +103,9 @@ namespace detail
|
|||
|
||||
private:
|
||||
virtual bool operator()(
|
||||
BOOST_PP_ENUM(MOCK_NUM_ARGS, MOCK_CALL_PARAM, _) )
|
||||
BOOST_PP_ENUM_BINARY_PARAMS(MOCK_NUM_ARGS, T, a) )
|
||||
{
|
||||
return f_( BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, a) );
|
||||
return f_( BOOST_PP_ENUM(MOCK_NUM_ARGS, MOCK_EXPECTATION_PARAM, _) );
|
||||
}
|
||||
virtual void serialize( std::ostream& s ) const
|
||||
{
|
||||
|
|
@ -201,10 +201,10 @@ namespace detail
|
|||
}
|
||||
|
||||
bool is_valid(
|
||||
BOOST_PP_ENUM(MOCK_NUM_ARGS, MOCK_CALL_PARAM, _) ) const
|
||||
BOOST_PP_ENUM_BINARY_PARAMS(MOCK_NUM_ARGS, T, a) ) const
|
||||
{
|
||||
return !invocation_->exhausted()
|
||||
&& (*matcher_)( BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, a) );
|
||||
&& (*matcher_)( BOOST_PP_ENUM(MOCK_NUM_ARGS, MOCK_EXPECTATION_PARAM, _) );
|
||||
}
|
||||
|
||||
bool invoke() const
|
||||
|
|
@ -259,7 +259,6 @@ namespace detail
|
|||
}
|
||||
} // mock
|
||||
|
||||
#undef MOCK_CALL_PARAM_TYPE
|
||||
#undef MOCK_EXPECTATION_INITIALIZE
|
||||
#undef MOCK_EXPECTATION_MEMBER
|
||||
#undef MOCK_EXPECTATION_IS_VALID
|
||||
|
|
|
|||
|
|
@ -216,7 +216,7 @@ namespace detail
|
|||
for( expectations_cit it = expectations_.begin();
|
||||
it != expectations_.end(); ++it )
|
||||
if( it->is_valid(
|
||||
BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, t) ) )
|
||||
BOOST_PP_ENUM(MOCK_NUM_ARGS, MOCK_FORWARD, _) ) )
|
||||
{
|
||||
if( ! it->invoke() )
|
||||
{
|
||||
|
|
|
|||
|
|
@ -6,9 +6,6 @@
|
|||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#define MOCK_CALL_PARAM(z, n, d) \
|
||||
typename boost::call_traits< T##n >::param_type a##n
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace detail
|
||||
|
|
@ -24,7 +21,7 @@ namespace detail
|
|||
virtual ~matcher_base() {}
|
||||
|
||||
virtual bool operator()(
|
||||
BOOST_PP_ENUM(MOCK_NUM_ARGS, MOCK_CALL_PARAM, _) ) = 0;
|
||||
BOOST_PP_ENUM_BINARY_PARAMS(MOCK_NUM_ARGS, T, a) ) = 0;
|
||||
|
||||
friend std::ostream& operator<<(
|
||||
std::ostream& s, const matcher_base& m )
|
||||
|
|
|
|||
|
|
@ -67,9 +67,9 @@ namespace mock
|
|||
explicit matcher( const constraint< Constraint >& c )
|
||||
: c_( c.c_ )
|
||||
{}
|
||||
bool operator()( const Actual& actual )
|
||||
bool operator()( BOOST_RV_REF(Actual) actual )
|
||||
{
|
||||
return c_( actual );
|
||||
return c_( boost::forward< Actual >( actual ) );
|
||||
}
|
||||
friend std::ostream& operator<<(
|
||||
std::ostream& s, const matcher& m )
|
||||
|
|
@ -91,9 +91,9 @@ namespace mock
|
|||
explicit matcher( const Functor& f )
|
||||
: c_( f )
|
||||
{}
|
||||
bool operator()( const Actual& actual )
|
||||
bool operator()( BOOST_RV_REF(Actual) actual )
|
||||
{
|
||||
return c_( actual );
|
||||
return c_( boost::forward< Actual >( actual ) );
|
||||
}
|
||||
friend std::ostream& operator<<(
|
||||
std::ostream& s, const matcher& m )
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue