mirror of
https://github.com/mat007/turtle.git
synced 2026-06-22 12:13:43 +00:00
Made template parameters names more user friendly in order to provide better diagnostic upon compilation error
git-svn-id: https://svn.code.sf.net/p/turtle/code/trunk@127 860be788-9bd5-4423-9f1e-828f051e677b
This commit is contained in:
parent
7325a49c0a
commit
fe3d419f66
4 changed files with 114 additions and 115 deletions
|
|
@ -22,48 +22,47 @@ namespace mock
|
|||
{
|
||||
namespace detail
|
||||
{
|
||||
template< typename Arg >
|
||||
template< typename Actual >
|
||||
class check
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME
|
||||
boost::function< bool( Arg ) > functor_type;
|
||||
boost::function< bool( Actual ) > functor_type;
|
||||
|
||||
public:
|
||||
template< typename F >
|
||||
explicit check( const F& f,
|
||||
template< typename Functor >
|
||||
explicit check( const Functor& functor,
|
||||
BOOST_DEDUCED_TYPENAME boost::enable_if<
|
||||
BOOST_DEDUCED_TYPENAME detail::is_functor< F >::type
|
||||
BOOST_DEDUCED_TYPENAME detail::is_functor< Functor >
|
||||
>::type* = 0 )
|
||||
: functor_( f )
|
||||
: functor_( functor )
|
||||
, desc_ ( "?" )
|
||||
{
|
||||
if( !functor_ )
|
||||
std::invalid_argument( "invalid functor" );
|
||||
}
|
||||
template< typename T >
|
||||
explicit check( const T& t,
|
||||
template< typename Expected >
|
||||
explicit check( const Expected& expected,
|
||||
BOOST_DEDUCED_TYPENAME boost::disable_if<
|
||||
BOOST_DEDUCED_TYPENAME detail::is_functor< T >::type
|
||||
BOOST_DEDUCED_TYPENAME detail::is_functor< Expected >
|
||||
>::type* = 0 )
|
||||
: functor_( equal( t ).functor_ )
|
||||
, desc_ ( format( t ) )
|
||||
: functor_( mock::equal( expected ).functor_ )
|
||||
, desc_ ( format( expected ) )
|
||||
{
|
||||
if( !functor_ )
|
||||
std::invalid_argument( "invalid functor" );
|
||||
}
|
||||
template< typename Constraint >
|
||||
explicit check( const placeholder< Constraint >& p )
|
||||
: functor_( p.functor_ )
|
||||
, desc_ ( p.desc_ )
|
||||
explicit check( const placeholder< Constraint >& ph )
|
||||
: functor_( ph.functor_ )
|
||||
, desc_ ( ph.desc_ )
|
||||
{
|
||||
if( !functor_ )
|
||||
std::invalid_argument( "invalid functor" );
|
||||
}
|
||||
|
||||
template< typename Y >
|
||||
bool operator()( Y& y ) const
|
||||
bool operator()( Actual actual ) const
|
||||
{
|
||||
return functor_( y );
|
||||
return functor_( actual );
|
||||
}
|
||||
|
||||
friend std::ostream& operator<<( std::ostream& s, const check& c )
|
||||
|
|
|
|||
|
|
@ -41,65 +41,65 @@ namespace mock
|
|||
namespace detail
|
||||
{
|
||||
template<>
|
||||
struct placeholder< nothing >
|
||||
struct placeholder< any >
|
||||
{
|
||||
placeholder()
|
||||
: desc_( "any" )
|
||||
{}
|
||||
nothing functor_;
|
||||
any functor_;
|
||||
std::string desc_;
|
||||
};
|
||||
template<>
|
||||
struct placeholder< negation >
|
||||
struct placeholder< negate >
|
||||
{
|
||||
placeholder()
|
||||
: desc_( "negate" )
|
||||
{}
|
||||
negation functor_;
|
||||
negate functor_;
|
||||
std::string desc_;
|
||||
};
|
||||
template<>
|
||||
struct placeholder< evaluation >
|
||||
struct placeholder< evaluate >
|
||||
{
|
||||
placeholder()
|
||||
: desc_( "evaluate" )
|
||||
{}
|
||||
evaluation functor_;
|
||||
evaluate functor_;
|
||||
std::string desc_;
|
||||
};
|
||||
}
|
||||
const detail::placeholder< detail::nothing > any;
|
||||
const detail::placeholder< detail::negation > negate;
|
||||
const detail::placeholder< detail::evaluation > evaluate;
|
||||
const detail::placeholder< detail::any > any;
|
||||
const detail::placeholder< detail::negate > negate;
|
||||
const detail::placeholder< detail::evaluate > evaluate;
|
||||
|
||||
template< typename T >
|
||||
detail::placeholder< detail::equality< T > > equal( T t )
|
||||
detail::placeholder< detail::equal< T > > equal( T t )
|
||||
{
|
||||
return constraint( detail::equality< T >( t ), "equal", t );
|
||||
return constraint( detail::equal< T >( t ), "equal", t );
|
||||
}
|
||||
|
||||
template< typename T >
|
||||
detail::placeholder< detail::identity< T > > same( T& t )
|
||||
detail::placeholder< detail::same< T > > same( T& t )
|
||||
{
|
||||
return constraint( detail::identity< T >( boost::ref( t ) ),
|
||||
return constraint( detail::same< T >( boost::ref( t ) ),
|
||||
"same", &t );
|
||||
}
|
||||
|
||||
template< typename T >
|
||||
detail::placeholder< detail::inferiority< T > > less( T t )
|
||||
detail::placeholder< detail::less< T > > less( T t )
|
||||
{
|
||||
return constraint( detail::inferiority< T >( t ), "less", t );
|
||||
return constraint( detail::less< T >( t ), "less", t );
|
||||
}
|
||||
|
||||
template< typename T >
|
||||
detail::placeholder< detail::superiority< T > > greater( T t )
|
||||
detail::placeholder< detail::greater< T > > greater( T t )
|
||||
{
|
||||
return constraint( detail::superiority< T >( t ), "greater", t );
|
||||
return constraint( detail::greater< T >( t ), "greater", t );
|
||||
}
|
||||
|
||||
template< typename T >
|
||||
detail::placeholder<
|
||||
detail::or_< detail::inferiority< T >, detail::equality< T > > >
|
||||
detail::or_< detail::less< T >, detail::equal< T > > >
|
||||
less_equal( T t )
|
||||
{
|
||||
return constraint( (less( t ) || equal( t )).functor_,
|
||||
|
|
@ -108,7 +108,7 @@ namespace detail
|
|||
|
||||
template< typename T >
|
||||
detail::placeholder<
|
||||
detail::or_< detail::superiority< T >, detail::equality< T > > >
|
||||
detail::or_< detail::greater< T >, detail::equal< T > > >
|
||||
greater_equal( T t )
|
||||
{
|
||||
return constraint( (greater( t ) || equal( t )).functor_,
|
||||
|
|
@ -116,22 +116,22 @@ namespace detail
|
|||
}
|
||||
|
||||
template< typename T >
|
||||
detail::placeholder< detail::assignment< T > > assign( T t )
|
||||
detail::placeholder< detail::assign< T > > assign( T t )
|
||||
{
|
||||
return constraint( detail::assignment< T >( t ), "assign", t );
|
||||
return constraint( detail::assign< T >( t ), "assign", t );
|
||||
}
|
||||
|
||||
template< typename T >
|
||||
detail::placeholder< detail::retrieval< T > > retrieve( T& t )
|
||||
detail::placeholder< detail::retrieve< T > > retrieve( T& t )
|
||||
{
|
||||
return constraint( detail::retrieval< T >( boost::ref( t ) ),
|
||||
return constraint( detail::retrieve< T >( boost::ref( t ) ),
|
||||
"retrieve", t );
|
||||
}
|
||||
|
||||
template< typename T >
|
||||
detail::placeholder< detail::container< T > > contain( T t )
|
||||
detail::placeholder< detail::contains< T > > contain( T t )
|
||||
{
|
||||
return constraint( detail::container< T >( t ), "contain", t );
|
||||
return constraint( detail::contains< T >( t ), "contain", t );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -18,158 +18,158 @@ namespace mock
|
|||
{
|
||||
namespace detail
|
||||
{
|
||||
class nothing
|
||||
class any
|
||||
{
|
||||
public:
|
||||
template< typename Y >
|
||||
bool operator()( const Y& ) const
|
||||
template< typename Actual >
|
||||
bool operator()( const Actual& ) const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
class negation
|
||||
class negate
|
||||
{
|
||||
public:
|
||||
template< typename Y >
|
||||
bool operator()( const Y& y ) const
|
||||
template< typename Actual >
|
||||
bool operator()( const Actual& actual ) const
|
||||
{
|
||||
return ! y;
|
||||
return ! actual;
|
||||
}
|
||||
};
|
||||
|
||||
class evaluation
|
||||
class evaluate
|
||||
{
|
||||
public:
|
||||
template< typename Y >
|
||||
bool operator()( const Y& y ) const
|
||||
template< typename Actual >
|
||||
bool operator()( const Actual& actual ) const
|
||||
{
|
||||
return y();
|
||||
return actual();
|
||||
}
|
||||
};
|
||||
|
||||
template< typename T >
|
||||
class equality
|
||||
template< typename Expected >
|
||||
class equal
|
||||
{
|
||||
public:
|
||||
explicit equality( const T& t )
|
||||
: t_( t )
|
||||
explicit equal( const Expected& expected )
|
||||
: expected_( expected )
|
||||
{}
|
||||
template< typename Y >
|
||||
bool operator()( const Y& y ) const
|
||||
template< typename Actual >
|
||||
bool operator()( const Actual& actual ) const
|
||||
{
|
||||
return y == t_;
|
||||
return actual == expected_;
|
||||
}
|
||||
private:
|
||||
T t_;
|
||||
Expected expected_;
|
||||
};
|
||||
|
||||
template< typename T >
|
||||
class identity
|
||||
template< typename Expected >
|
||||
class same
|
||||
{
|
||||
public:
|
||||
explicit identity( const boost::reference_wrapper< T >& t )
|
||||
: t_( t )
|
||||
explicit same( const boost::reference_wrapper< Expected >& expected )
|
||||
: expected_( expected )
|
||||
{}
|
||||
template< typename Y >
|
||||
bool operator()( const Y& y ) const
|
||||
template< typename Actual >
|
||||
bool operator()( const Actual& actual ) const
|
||||
{
|
||||
return &y == t_.get_pointer();
|
||||
return &actual == expected_.get_pointer();
|
||||
}
|
||||
private:
|
||||
boost::reference_wrapper< T > t_;
|
||||
boost::reference_wrapper< Expected > expected_;
|
||||
};
|
||||
|
||||
template< typename T >
|
||||
class inferiority
|
||||
template< typename Expected >
|
||||
class less
|
||||
{
|
||||
public:
|
||||
explicit inferiority( const T& t )
|
||||
: t_( t )
|
||||
explicit less( const Expected& expected )
|
||||
: expected_( expected )
|
||||
{}
|
||||
template< typename Y >
|
||||
bool operator()( const Y& y ) const
|
||||
template< typename Actual >
|
||||
bool operator()( const Actual& actual ) const
|
||||
{
|
||||
return y < t_;
|
||||
return actual < expected_;
|
||||
}
|
||||
private:
|
||||
T t_;
|
||||
Expected expected_;
|
||||
};
|
||||
|
||||
template< typename T >
|
||||
class superiority
|
||||
template< typename Expected >
|
||||
class greater
|
||||
{
|
||||
public:
|
||||
explicit superiority( const T& t )
|
||||
: t_( t )
|
||||
explicit greater( const Expected& expected )
|
||||
: expected_( expected )
|
||||
{}
|
||||
template< typename Y >
|
||||
bool operator()( const Y& y ) const
|
||||
template< typename Actual >
|
||||
bool operator()( const Actual& actual ) const
|
||||
{
|
||||
return y > t_;
|
||||
return actual > expected_;
|
||||
}
|
||||
private:
|
||||
T t_;
|
||||
Expected expected_;
|
||||
};
|
||||
|
||||
template< typename T >
|
||||
class assignment
|
||||
template< typename Expected >
|
||||
class assign
|
||||
{
|
||||
public:
|
||||
explicit assignment( const T& t )
|
||||
: t_( t )
|
||||
explicit assign( const Expected& expected )
|
||||
: expected_( expected )
|
||||
{}
|
||||
template< typename Y >
|
||||
bool operator()( Y& y ) const
|
||||
template< typename Actual >
|
||||
bool operator()( Actual& actual ) const
|
||||
{
|
||||
y = t_;
|
||||
actual = expected_;
|
||||
return true;
|
||||
}
|
||||
private:
|
||||
T t_;
|
||||
Expected expected_;
|
||||
};
|
||||
|
||||
template< typename T >
|
||||
class retrieval
|
||||
template< typename Expected >
|
||||
class retrieve
|
||||
{
|
||||
public:
|
||||
explicit retrieval( const boost::reference_wrapper< T >& t )
|
||||
: t_( t )
|
||||
explicit retrieve( const boost::reference_wrapper< Expected >& expected )
|
||||
: expected_( expected )
|
||||
{}
|
||||
template< typename Y >
|
||||
bool operator()( const Y& y,
|
||||
template< typename Actual >
|
||||
bool operator()( const Actual& actual,
|
||||
BOOST_DEDUCED_TYPENAME boost::disable_if<
|
||||
boost::is_convertible< const Y*, T >, Y >::type* = 0 ) const
|
||||
boost::is_convertible< const Actual*, Expected >, Actual >::type* = 0 ) const
|
||||
{
|
||||
t_.get() = y;
|
||||
expected_.get() = actual;
|
||||
return true;
|
||||
}
|
||||
template< typename Y >
|
||||
bool operator()( Y& y,
|
||||
template< typename Actual >
|
||||
bool operator()( Actual& actual,
|
||||
BOOST_DEDUCED_TYPENAME boost::enable_if<
|
||||
boost::is_convertible< Y*, T >, Y >::type* = 0 ) const
|
||||
boost::is_convertible< Actual*, Expected >, Actual >::type* = 0 ) const
|
||||
{
|
||||
t_.get() = &y;
|
||||
expected_.get() = &actual;
|
||||
return true;
|
||||
}
|
||||
private:
|
||||
boost::reference_wrapper< T > t_;
|
||||
boost::reference_wrapper< Expected > expected_;
|
||||
};
|
||||
|
||||
template< typename T >
|
||||
class container
|
||||
template< typename Expected >
|
||||
class contains
|
||||
{
|
||||
public:
|
||||
explicit container( const T& t )
|
||||
: t_( t )
|
||||
explicit contains( const Expected& expected )
|
||||
: expected_( expected )
|
||||
{}
|
||||
template< typename Y >
|
||||
bool operator()( const Y& y ) const
|
||||
template< typename Actual >
|
||||
bool operator()( const Actual& actual ) const
|
||||
{
|
||||
return boost::algorithm::contains( y, t_ );
|
||||
return boost::algorithm::contains( actual, expected_ );
|
||||
}
|
||||
private:
|
||||
T t_;
|
||||
Expected expected_;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -173,7 +173,7 @@ namespace detail
|
|||
n \
|
||||
>::type arg##n##_type; \
|
||||
typedef detail::check< arg##n##_type > constraint##n##_type;
|
||||
#define MOCK_MATCHER_CONSTRUCTOR(z, n, d) BOOST_PP_COMMA_IF(n) c##n##_ ( any )
|
||||
#define MOCK_MATCHER_CONSTRUCTOR(z, n, d) BOOST_PP_COMMA_IF(n) c##n##_( mock::any )
|
||||
#define MOCK_MATCHER_WITH(z, n, d) c##n##_ = constraint##n##_type( c##n );
|
||||
#define MOCK_MATCHER_MEMBER(z, n, d) constraint##n##_type c##n##_;
|
||||
#define MOCK_MATCHER_ARGS(z, n, d) BOOST_PP_COMMA_IF(n) arg##n##_type a##n
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue