mirror of
https://github.com/mat007/turtle.git
synced 2026-06-22 12:13:43 +00:00
Refactoring
git-svn-id: https://svn.code.sf.net/p/turtle/code/trunk@473 860be788-9bd5-4423-9f1e-828f051e677b
This commit is contained in:
parent
39009f6e52
commit
37572bf825
2 changed files with 63 additions and 67 deletions
|
|
@ -21,4 +21,57 @@ namespace mock
|
||||||
};
|
};
|
||||||
} // mock
|
} // mock
|
||||||
|
|
||||||
|
#define MOCK_UNARY_CONSTRAINT(N,Expr) \
|
||||||
|
namespace detail \
|
||||||
|
{ \
|
||||||
|
struct N \
|
||||||
|
{ \
|
||||||
|
template< typename Actual > \
|
||||||
|
bool operator()( const Actual& actual ) const \
|
||||||
|
{ \
|
||||||
|
return Expr; \
|
||||||
|
} \
|
||||||
|
friend std::ostream& operator<<( std::ostream& s, const N& ) \
|
||||||
|
{ \
|
||||||
|
return s << BOOST_STRINGIZE(N); \
|
||||||
|
} \
|
||||||
|
}; \
|
||||||
|
} \
|
||||||
|
template<> \
|
||||||
|
struct constraint< detail::N > \
|
||||||
|
{ \
|
||||||
|
constraint() \
|
||||||
|
{} \
|
||||||
|
detail::N f_; \
|
||||||
|
}; \
|
||||||
|
const constraint< detail::N > N;
|
||||||
|
|
||||||
|
#define MOCK_BINARY_CONSTRAINT(N,Expr) \
|
||||||
|
namespace detail \
|
||||||
|
{ \
|
||||||
|
template< typename Expected > \
|
||||||
|
struct N \
|
||||||
|
{ \
|
||||||
|
explicit N( const Expected& expected ) \
|
||||||
|
: expected_( expected ) \
|
||||||
|
{} \
|
||||||
|
template< typename Actual > \
|
||||||
|
bool operator()( const Actual& actual ) const \
|
||||||
|
{ \
|
||||||
|
return Expr; \
|
||||||
|
} \
|
||||||
|
friend std::ostream& operator<<( std::ostream& s, const N& n ) \
|
||||||
|
{ \
|
||||||
|
return s << BOOST_STRINGIZE(N) \
|
||||||
|
<< "( " << mock::format( n.expected_ ) << " )"; \
|
||||||
|
} \
|
||||||
|
Expected expected_; \
|
||||||
|
}; \
|
||||||
|
} \
|
||||||
|
template< typename T > \
|
||||||
|
constraint< detail::N< T > > N( T t ) \
|
||||||
|
{ \
|
||||||
|
return detail::N< T >( t ); \
|
||||||
|
}
|
||||||
|
|
||||||
#endif // MOCK_CONSTRAINT_HPP_INCLUDED
|
#endif // MOCK_CONSTRAINT_HPP_INCLUDED
|
||||||
|
|
|
||||||
|
|
@ -19,73 +19,16 @@
|
||||||
|
|
||||||
namespace mock
|
namespace mock
|
||||||
{
|
{
|
||||||
#define MOCK_CONSTRAINT(N,Expr) \
|
MOCK_UNARY_CONSTRAINT( any, true && &actual )
|
||||||
namespace detail \
|
MOCK_UNARY_CONSTRAINT( affirm, !! actual )
|
||||||
{ \
|
MOCK_UNARY_CONSTRAINT( negate, ! actual )
|
||||||
struct N \
|
MOCK_UNARY_CONSTRAINT( evaluate, actual() )
|
||||||
{ \
|
|
||||||
template< typename Actual > \
|
|
||||||
bool operator()( const Actual& actual ) const \
|
|
||||||
{ \
|
|
||||||
return Expr; \
|
|
||||||
} \
|
|
||||||
friend std::ostream& operator<<( std::ostream& s, const N& ) \
|
|
||||||
{ \
|
|
||||||
return s << BOOST_STRINGIZE(N); \
|
|
||||||
} \
|
|
||||||
}; \
|
|
||||||
} \
|
|
||||||
template<> \
|
|
||||||
struct constraint< detail::N > \
|
|
||||||
{ \
|
|
||||||
constraint() \
|
|
||||||
{} \
|
|
||||||
detail::N f_; \
|
|
||||||
}; \
|
|
||||||
const constraint< detail::N > N;
|
|
||||||
|
|
||||||
MOCK_CONSTRAINT(any, true && &actual)
|
MOCK_BINARY_CONSTRAINT( equal, actual == boost::unwrap_ref( expected_ ) )
|
||||||
MOCK_CONSTRAINT(affirm, !! actual)
|
MOCK_BINARY_CONSTRAINT( less, actual < boost::unwrap_ref( expected_ ) )
|
||||||
MOCK_CONSTRAINT(negate, ! actual)
|
MOCK_BINARY_CONSTRAINT( greater, actual > boost::unwrap_ref( expected_ ) )
|
||||||
MOCK_CONSTRAINT(evaluate, actual())
|
MOCK_BINARY_CONSTRAINT( less_equal, actual <= boost::unwrap_ref( expected_ ) )
|
||||||
|
MOCK_BINARY_CONSTRAINT( greater_equal, actual >= boost::unwrap_ref( expected_ ) )
|
||||||
#undef MOCK_CONSTRAINT
|
|
||||||
|
|
||||||
#define MOCK_CONSTRAINT(N,Expr) \
|
|
||||||
namespace detail \
|
|
||||||
{ \
|
|
||||||
template< typename Expected > \
|
|
||||||
struct N \
|
|
||||||
{ \
|
|
||||||
explicit N( const Expected& expected ) \
|
|
||||||
: expected_( expected ) \
|
|
||||||
{} \
|
|
||||||
template< typename Actual > \
|
|
||||||
bool operator()( const Actual& actual ) const \
|
|
||||||
{ \
|
|
||||||
return Expr; \
|
|
||||||
} \
|
|
||||||
friend std::ostream& operator<<( std::ostream& s, const N& n ) \
|
|
||||||
{ \
|
|
||||||
return s << BOOST_STRINGIZE(N) \
|
|
||||||
<< "( " << mock::format( n.expected_ ) << " )"; \
|
|
||||||
} \
|
|
||||||
Expected expected_; \
|
|
||||||
}; \
|
|
||||||
} \
|
|
||||||
template< typename T > \
|
|
||||||
constraint< detail::N< T > > N( T t ) \
|
|
||||||
{ \
|
|
||||||
return detail::N< T >( t ); \
|
|
||||||
}
|
|
||||||
|
|
||||||
MOCK_CONSTRAINT(equal, actual == boost::unwrap_ref( expected_ ))
|
|
||||||
MOCK_CONSTRAINT(less, actual < boost::unwrap_ref( expected_ ))
|
|
||||||
MOCK_CONSTRAINT(greater, actual > boost::unwrap_ref( expected_ ))
|
|
||||||
MOCK_CONSTRAINT(less_equal, actual <= boost::unwrap_ref( expected_ ))
|
|
||||||
MOCK_CONSTRAINT(greater_equal, actual >= boost::unwrap_ref( expected_ ))
|
|
||||||
|
|
||||||
#undef MOCK_CONSTRAINT
|
|
||||||
|
|
||||||
namespace detail
|
namespace detail
|
||||||
{
|
{
|
||||||
|
|
@ -222,7 +165,7 @@ namespace detail
|
||||||
template< typename T >
|
template< typename T >
|
||||||
constraint< T > call( T t )
|
constraint< T > call( T t )
|
||||||
{
|
{
|
||||||
return t;
|
return constraint< T >( t );
|
||||||
}
|
}
|
||||||
} // mock
|
} // mock
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue