mirror of
https://github.com/mat007/turtle.git
synced 2026-06-22 12:13:43 +00:00
Fixed move-only type support in constraints
This commit is contained in:
parent
d3a5d3010c
commit
a2d36e961a
3 changed files with 36 additions and 14 deletions
|
|
@ -14,6 +14,7 @@ Not yet released
|
||||||
* Added MOCK_NO_AUTO_PTR to deactivate std::auto_ptr support
|
* Added MOCK_NO_AUTO_PTR to deactivate std::auto_ptr support
|
||||||
* Added [@https://github.com/philsquared/Catch Catch] integration
|
* Added [@https://github.com/philsquared/Catch Catch] integration
|
||||||
* Fixed move-only type argument in actions
|
* Fixed move-only type argument in actions
|
||||||
|
* Fixed move-only type support in constraints
|
||||||
|
|
||||||
[endsect]
|
[endsect]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@
|
||||||
#include <boost/preprocessor/repetition/enum_params.hpp>
|
#include <boost/preprocessor/repetition/enum_params.hpp>
|
||||||
#include <boost/preprocessor/repetition/enum.hpp>
|
#include <boost/preprocessor/repetition/enum.hpp>
|
||||||
#include <boost/preprocessor/array.hpp>
|
#include <boost/preprocessor/array.hpp>
|
||||||
|
#include <boost/move/move.hpp>
|
||||||
|
|
||||||
namespace mock
|
namespace mock
|
||||||
{
|
{
|
||||||
|
|
@ -158,11 +159,14 @@ namespace detail
|
||||||
|
|
||||||
#define MOCK_CONSTRAINT_CREF_PARAM(z, n, Args) \
|
#define MOCK_CONSTRAINT_CREF_PARAM(z, n, Args) \
|
||||||
typename \
|
typename \
|
||||||
boost::unwrap_reference< Expected_##n >::type \
|
const boost::unwrap_reference< Expected_##n >::type& \
|
||||||
BOOST_PP_ARRAY_ELEM(n, Args)
|
BOOST_PP_ARRAY_ELEM(n, Args)
|
||||||
|
|
||||||
|
#define MOCK_CONSTRAINT_ARG(z, n, Args) \
|
||||||
|
BOOST_FWD_REF(T##n) BOOST_PP_ARRAY_ELEM(n, Args)
|
||||||
|
|
||||||
#define MOCK_CONSTRAINT_PARAM(z, n, Args) \
|
#define MOCK_CONSTRAINT_PARAM(z, n, Args) \
|
||||||
T##n BOOST_PP_ARRAY_ELEM(n, Args)
|
boost::forward< T##n >( BOOST_PP_ARRAY_ELEM(n, Args) )
|
||||||
|
|
||||||
#define MOCK_NARY_CONSTRAINT(Name, n, Args, Expr) \
|
#define MOCK_NARY_CONSTRAINT(Name, n, Args, Expr) \
|
||||||
namespace detail \
|
namespace detail \
|
||||||
|
|
@ -171,7 +175,7 @@ namespace detail
|
||||||
struct Name \
|
struct Name \
|
||||||
{ \
|
{ \
|
||||||
explicit Name( \
|
explicit Name( \
|
||||||
BOOST_PP_ENUM_BINARY_PARAMS(n, const Expected_, & e) ) \
|
BOOST_PP_ENUM_BINARY_PARAMS(n, Expected_, e) ) \
|
||||||
: BOOST_PP_ENUM(n, MOCK_CONSTRAINT_ASSIGN, _) \
|
: BOOST_PP_ENUM(n, MOCK_CONSTRAINT_ASSIGN, _) \
|
||||||
{} \
|
{} \
|
||||||
template< typename Actual > \
|
template< typename Actual > \
|
||||||
|
|
@ -199,9 +203,10 @@ namespace detail
|
||||||
template< BOOST_PP_ENUM_PARAMS(n, typename T) > \
|
template< BOOST_PP_ENUM_PARAMS(n, typename T) > \
|
||||||
mock::constraint< \
|
mock::constraint< \
|
||||||
detail::Name< BOOST_PP_ENUM_PARAMS(n, T) > \
|
detail::Name< BOOST_PP_ENUM_PARAMS(n, T) > \
|
||||||
> Name( BOOST_PP_ENUM(n, MOCK_CONSTRAINT_PARAM, (n, Args)) ) \
|
> Name( BOOST_PP_ENUM(n, MOCK_CONSTRAINT_ARG, (n, Args)) ) \
|
||||||
{ \
|
{ \
|
||||||
return detail::Name< BOOST_PP_ENUM_PARAMS(n, T) > Args; \
|
return detail::Name< BOOST_PP_ENUM_PARAMS(n, T) >( \
|
||||||
|
BOOST_PP_ENUM(n, MOCK_CONSTRAINT_PARAM, (n, Args)) ); \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define MOCK_CONSTRAINT_EXT(Name, n, Args, Expr) \
|
#define MOCK_CONSTRAINT_EXT(Name, n, Args, Expr) \
|
||||||
|
|
|
||||||
|
|
@ -47,14 +47,20 @@ BOOST_AUTO_TEST_CASE( equal_constraint )
|
||||||
BOOST_CHECK( ! mock::equal( std::string( "string" ) ).c_( "not string" ) );
|
BOOST_CHECK( ! mock::equal( std::string( "string" ) ).c_( "not string" ) );
|
||||||
{
|
{
|
||||||
std::string s;
|
std::string s;
|
||||||
mock::constraint<
|
auto c = mock::equal( boost::cref( s ) );
|
||||||
mock::detail::equal<
|
|
||||||
boost::reference_wrapper< const std::string >
|
|
||||||
>
|
|
||||||
> c = mock::equal( boost::cref( s ) );
|
|
||||||
s = "string";
|
s = "string";
|
||||||
BOOST_CHECK( c.c_( "string" ) );
|
BOOST_CHECK( c.c_( "string" ) );
|
||||||
}
|
}
|
||||||
|
#ifdef MOCK_SMART_PTR
|
||||||
|
{
|
||||||
|
std::unique_ptr< int > i;
|
||||||
|
std::unique_ptr< int > j( new int( 3 ) );
|
||||||
|
BOOST_CHECK( ! mock::equal( i ).c_( j ) );
|
||||||
|
BOOST_CHECK( ! mock::equal( j ).c_( i ) );
|
||||||
|
BOOST_CHECK( mock::equal( i ).c_( i ) );
|
||||||
|
BOOST_CHECK( mock::equal( j ).c_( j ) );
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE( same_constraint )
|
BOOST_AUTO_TEST_CASE( same_constraint )
|
||||||
|
|
@ -244,10 +250,20 @@ BOOST_AUTO_TEST_CASE( retrieve_constraint_uses_assignment_operator )
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE( affirm_constraint )
|
BOOST_AUTO_TEST_CASE( affirm_constraint )
|
||||||
{
|
{
|
||||||
|
{
|
||||||
int* i = 0;
|
int* i = 0;
|
||||||
int j;
|
int j;
|
||||||
BOOST_CHECK( ! mock::affirm.c_( i ) );
|
BOOST_CHECK( ! mock::affirm.c_( i ) );
|
||||||
BOOST_CHECK( mock::affirm.c_( &j ) );
|
BOOST_CHECK( mock::affirm.c_( &j ) );
|
||||||
|
}
|
||||||
|
{
|
||||||
|
#ifdef MOCK_SMART_PTR
|
||||||
|
std::unique_ptr< int > i;
|
||||||
|
std::unique_ptr< int > j( new int( 3 ) );
|
||||||
|
BOOST_CHECK( ! mock::affirm.c_( i ) );
|
||||||
|
BOOST_CHECK( mock::affirm.c_( j ) );
|
||||||
|
#endif
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE( negate_constraint )
|
BOOST_AUTO_TEST_CASE( negate_constraint )
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue