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
|
namespace detail
|
||||||
{
|
{
|
||||||
template< typename Arg >
|
template< typename Actual >
|
||||||
class check
|
class check
|
||||||
{
|
{
|
||||||
typedef BOOST_DEDUCED_TYPENAME
|
typedef BOOST_DEDUCED_TYPENAME
|
||||||
boost::function< bool( Arg ) > functor_type;
|
boost::function< bool( Actual ) > functor_type;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
template< typename F >
|
template< typename Functor >
|
||||||
explicit check( const F& f,
|
explicit check( const Functor& functor,
|
||||||
BOOST_DEDUCED_TYPENAME boost::enable_if<
|
BOOST_DEDUCED_TYPENAME boost::enable_if<
|
||||||
BOOST_DEDUCED_TYPENAME detail::is_functor< F >::type
|
BOOST_DEDUCED_TYPENAME detail::is_functor< Functor >
|
||||||
>::type* = 0 )
|
>::type* = 0 )
|
||||||
: functor_( f )
|
: functor_( functor )
|
||||||
, desc_ ( "?" )
|
, desc_ ( "?" )
|
||||||
{
|
{
|
||||||
if( !functor_ )
|
if( !functor_ )
|
||||||
std::invalid_argument( "invalid functor" );
|
std::invalid_argument( "invalid functor" );
|
||||||
}
|
}
|
||||||
template< typename T >
|
template< typename Expected >
|
||||||
explicit check( const T& t,
|
explicit check( const Expected& expected,
|
||||||
BOOST_DEDUCED_TYPENAME boost::disable_if<
|
BOOST_DEDUCED_TYPENAME boost::disable_if<
|
||||||
BOOST_DEDUCED_TYPENAME detail::is_functor< T >::type
|
BOOST_DEDUCED_TYPENAME detail::is_functor< Expected >
|
||||||
>::type* = 0 )
|
>::type* = 0 )
|
||||||
: functor_( equal( t ).functor_ )
|
: functor_( mock::equal( expected ).functor_ )
|
||||||
, desc_ ( format( t ) )
|
, desc_ ( format( expected ) )
|
||||||
{
|
{
|
||||||
if( !functor_ )
|
if( !functor_ )
|
||||||
std::invalid_argument( "invalid functor" );
|
std::invalid_argument( "invalid functor" );
|
||||||
}
|
}
|
||||||
template< typename Constraint >
|
template< typename Constraint >
|
||||||
explicit check( const placeholder< Constraint >& p )
|
explicit check( const placeholder< Constraint >& ph )
|
||||||
: functor_( p.functor_ )
|
: functor_( ph.functor_ )
|
||||||
, desc_ ( p.desc_ )
|
, desc_ ( ph.desc_ )
|
||||||
{
|
{
|
||||||
if( !functor_ )
|
if( !functor_ )
|
||||||
std::invalid_argument( "invalid functor" );
|
std::invalid_argument( "invalid functor" );
|
||||||
}
|
}
|
||||||
|
|
||||||
template< typename Y >
|
bool operator()( Actual actual ) const
|
||||||
bool operator()( Y& y ) const
|
|
||||||
{
|
{
|
||||||
return functor_( y );
|
return functor_( actual );
|
||||||
}
|
}
|
||||||
|
|
||||||
friend std::ostream& operator<<( std::ostream& s, const check& c )
|
friend std::ostream& operator<<( std::ostream& s, const check& c )
|
||||||
|
|
|
||||||
|
|
@ -41,65 +41,65 @@ namespace mock
|
||||||
namespace detail
|
namespace detail
|
||||||
{
|
{
|
||||||
template<>
|
template<>
|
||||||
struct placeholder< nothing >
|
struct placeholder< any >
|
||||||
{
|
{
|
||||||
placeholder()
|
placeholder()
|
||||||
: desc_( "any" )
|
: desc_( "any" )
|
||||||
{}
|
{}
|
||||||
nothing functor_;
|
any functor_;
|
||||||
std::string desc_;
|
std::string desc_;
|
||||||
};
|
};
|
||||||
template<>
|
template<>
|
||||||
struct placeholder< negation >
|
struct placeholder< negate >
|
||||||
{
|
{
|
||||||
placeholder()
|
placeholder()
|
||||||
: desc_( "negate" )
|
: desc_( "negate" )
|
||||||
{}
|
{}
|
||||||
negation functor_;
|
negate functor_;
|
||||||
std::string desc_;
|
std::string desc_;
|
||||||
};
|
};
|
||||||
template<>
|
template<>
|
||||||
struct placeholder< evaluation >
|
struct placeholder< evaluate >
|
||||||
{
|
{
|
||||||
placeholder()
|
placeholder()
|
||||||
: desc_( "evaluate" )
|
: desc_( "evaluate" )
|
||||||
{}
|
{}
|
||||||
evaluation functor_;
|
evaluate functor_;
|
||||||
std::string desc_;
|
std::string desc_;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
const detail::placeholder< detail::nothing > any;
|
const detail::placeholder< detail::any > any;
|
||||||
const detail::placeholder< detail::negation > negate;
|
const detail::placeholder< detail::negate > negate;
|
||||||
const detail::placeholder< detail::evaluation > evaluate;
|
const detail::placeholder< detail::evaluate > evaluate;
|
||||||
|
|
||||||
template< typename T >
|
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 >
|
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 );
|
"same", &t );
|
||||||
}
|
}
|
||||||
|
|
||||||
template< typename 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 >
|
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 >
|
template< typename T >
|
||||||
detail::placeholder<
|
detail::placeholder<
|
||||||
detail::or_< detail::inferiority< T >, detail::equality< T > > >
|
detail::or_< detail::less< T >, detail::equal< T > > >
|
||||||
less_equal( T t )
|
less_equal( T t )
|
||||||
{
|
{
|
||||||
return constraint( (less( t ) || equal( t )).functor_,
|
return constraint( (less( t ) || equal( t )).functor_,
|
||||||
|
|
@ -108,7 +108,7 @@ namespace detail
|
||||||
|
|
||||||
template< typename T >
|
template< typename T >
|
||||||
detail::placeholder<
|
detail::placeholder<
|
||||||
detail::or_< detail::superiority< T >, detail::equality< T > > >
|
detail::or_< detail::greater< T >, detail::equal< T > > >
|
||||||
greater_equal( T t )
|
greater_equal( T t )
|
||||||
{
|
{
|
||||||
return constraint( (greater( t ) || equal( t )).functor_,
|
return constraint( (greater( t ) || equal( t )).functor_,
|
||||||
|
|
@ -116,22 +116,22 @@ namespace detail
|
||||||
}
|
}
|
||||||
|
|
||||||
template< typename T >
|
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 >
|
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 );
|
"retrieve", t );
|
||||||
}
|
}
|
||||||
|
|
||||||
template< typename 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
|
namespace detail
|
||||||
{
|
{
|
||||||
class nothing
|
class any
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
template< typename Y >
|
template< typename Actual >
|
||||||
bool operator()( const Y& ) const
|
bool operator()( const Actual& ) const
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class negation
|
class negate
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
template< typename Y >
|
template< typename Actual >
|
||||||
bool operator()( const Y& y ) const
|
bool operator()( const Actual& actual ) const
|
||||||
{
|
{
|
||||||
return ! y;
|
return ! actual;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class evaluation
|
class evaluate
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
template< typename Y >
|
template< typename Actual >
|
||||||
bool operator()( const Y& y ) const
|
bool operator()( const Actual& actual ) const
|
||||||
{
|
{
|
||||||
return y();
|
return actual();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template< typename T >
|
template< typename Expected >
|
||||||
class equality
|
class equal
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit equality( const T& t )
|
explicit equal( const Expected& expected )
|
||||||
: t_( t )
|
: expected_( expected )
|
||||||
{}
|
{}
|
||||||
template< typename Y >
|
template< typename Actual >
|
||||||
bool operator()( const Y& y ) const
|
bool operator()( const Actual& actual ) const
|
||||||
{
|
{
|
||||||
return y == t_;
|
return actual == expected_;
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
T t_;
|
Expected expected_;
|
||||||
};
|
};
|
||||||
|
|
||||||
template< typename T >
|
template< typename Expected >
|
||||||
class identity
|
class same
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit identity( const boost::reference_wrapper< T >& t )
|
explicit same( const boost::reference_wrapper< Expected >& expected )
|
||||||
: t_( t )
|
: expected_( expected )
|
||||||
{}
|
{}
|
||||||
template< typename Y >
|
template< typename Actual >
|
||||||
bool operator()( const Y& y ) const
|
bool operator()( const Actual& actual ) const
|
||||||
{
|
{
|
||||||
return &y == t_.get_pointer();
|
return &actual == expected_.get_pointer();
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
boost::reference_wrapper< T > t_;
|
boost::reference_wrapper< Expected > expected_;
|
||||||
};
|
};
|
||||||
|
|
||||||
template< typename T >
|
template< typename Expected >
|
||||||
class inferiority
|
class less
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit inferiority( const T& t )
|
explicit less( const Expected& expected )
|
||||||
: t_( t )
|
: expected_( expected )
|
||||||
{}
|
{}
|
||||||
template< typename Y >
|
template< typename Actual >
|
||||||
bool operator()( const Y& y ) const
|
bool operator()( const Actual& actual ) const
|
||||||
{
|
{
|
||||||
return y < t_;
|
return actual < expected_;
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
T t_;
|
Expected expected_;
|
||||||
};
|
};
|
||||||
|
|
||||||
template< typename T >
|
template< typename Expected >
|
||||||
class superiority
|
class greater
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit superiority( const T& t )
|
explicit greater( const Expected& expected )
|
||||||
: t_( t )
|
: expected_( expected )
|
||||||
{}
|
{}
|
||||||
template< typename Y >
|
template< typename Actual >
|
||||||
bool operator()( const Y& y ) const
|
bool operator()( const Actual& actual ) const
|
||||||
{
|
{
|
||||||
return y > t_;
|
return actual > expected_;
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
T t_;
|
Expected expected_;
|
||||||
};
|
};
|
||||||
|
|
||||||
template< typename T >
|
template< typename Expected >
|
||||||
class assignment
|
class assign
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit assignment( const T& t )
|
explicit assign( const Expected& expected )
|
||||||
: t_( t )
|
: expected_( expected )
|
||||||
{}
|
{}
|
||||||
template< typename Y >
|
template< typename Actual >
|
||||||
bool operator()( Y& y ) const
|
bool operator()( Actual& actual ) const
|
||||||
{
|
{
|
||||||
y = t_;
|
actual = expected_;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
T t_;
|
Expected expected_;
|
||||||
};
|
};
|
||||||
|
|
||||||
template< typename T >
|
template< typename Expected >
|
||||||
class retrieval
|
class retrieve
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit retrieval( const boost::reference_wrapper< T >& t )
|
explicit retrieve( const boost::reference_wrapper< Expected >& expected )
|
||||||
: t_( t )
|
: expected_( expected )
|
||||||
{}
|
{}
|
||||||
template< typename Y >
|
template< typename Actual >
|
||||||
bool operator()( const Y& y,
|
bool operator()( const Actual& actual,
|
||||||
BOOST_DEDUCED_TYPENAME boost::disable_if<
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
template< typename Y >
|
template< typename Actual >
|
||||||
bool operator()( Y& y,
|
bool operator()( Actual& actual,
|
||||||
BOOST_DEDUCED_TYPENAME boost::enable_if<
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
boost::reference_wrapper< T > t_;
|
boost::reference_wrapper< Expected > expected_;
|
||||||
};
|
};
|
||||||
|
|
||||||
template< typename T >
|
template< typename Expected >
|
||||||
class container
|
class contains
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit container( const T& t )
|
explicit contains( const Expected& expected )
|
||||||
: t_( t )
|
: expected_( expected )
|
||||||
{}
|
{}
|
||||||
template< typename Y >
|
template< typename Actual >
|
||||||
bool operator()( const Y& y ) const
|
bool operator()( const Actual& actual ) const
|
||||||
{
|
{
|
||||||
return boost::algorithm::contains( y, t_ );
|
return boost::algorithm::contains( actual, expected_ );
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
T t_;
|
Expected expected_;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -173,7 +173,7 @@ namespace detail
|
||||||
n \
|
n \
|
||||||
>::type arg##n##_type; \
|
>::type arg##n##_type; \
|
||||||
typedef detail::check< arg##n##_type > constraint##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_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_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
|
#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