Refactoring

git-svn-id: https://svn.code.sf.net/p/turtle/code/trunk@473 860be788-9bd5-4423-9f1e-828f051e677b
This commit is contained in:
mat007 2012-06-22 17:23:19 +00:00
parent 39009f6e52
commit 37572bf825
2 changed files with 63 additions and 67 deletions

View file

@ -21,4 +21,57 @@ namespace 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

View file

@ -19,73 +19,16 @@
namespace mock
{
#define MOCK_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;
MOCK_UNARY_CONSTRAINT( any, true && &actual )
MOCK_UNARY_CONSTRAINT( affirm, !! actual )
MOCK_UNARY_CONSTRAINT( negate, ! actual )
MOCK_UNARY_CONSTRAINT( evaluate, actual() )
MOCK_CONSTRAINT(any, true && &actual)
MOCK_CONSTRAINT(affirm, !! actual)
MOCK_CONSTRAINT(negate, ! actual)
MOCK_CONSTRAINT(evaluate, actual())
#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
MOCK_BINARY_CONSTRAINT( equal, actual == boost::unwrap_ref( expected_ ) )
MOCK_BINARY_CONSTRAINT( less, actual < boost::unwrap_ref( expected_ ) )
MOCK_BINARY_CONSTRAINT( greater, actual > boost::unwrap_ref( expected_ ) )
MOCK_BINARY_CONSTRAINT( less_equal, actual <= boost::unwrap_ref( expected_ ) )
MOCK_BINARY_CONSTRAINT( greater_equal, actual >= boost::unwrap_ref( expected_ ) )
namespace detail
{
@ -222,7 +165,7 @@ namespace detail
template< typename T >
constraint< T > call( T t )
{
return t;
return constraint< T >( t );
}
} // mock