Added mock::compare to customise comparison between data types without messing with existing operator==

git-svn-id: https://svn.code.sf.net/p/turtle/code/trunk@439 860be788-9bd5-4423-9f1e-828f051e677b
This commit is contained in:
mat007 2012-04-12 14:28:41 +00:00
parent 50f74c1eaf
commit 7b0cde6b53
2 changed files with 27 additions and 1 deletions

View file

@ -20,6 +20,12 @@
namespace mock
{
template< typename Actual, typename Expected >
bool compare( const Actual& actual, const Expected& expected )
{
return actual == expected;
}
namespace detail
{
template< typename Actual >
@ -49,7 +55,7 @@ namespace detail
private:
virtual bool operator()( Actual actual )
{
return actual == boost::unwrap_ref( expected_ );
return mock::compare( actual, boost::unwrap_ref( expected_ ) );
}
virtual void serialize( std::ostream& s ) const
{

View file

@ -535,3 +535,23 @@ BOOST_AUTO_TEST_CASE( a_static_method_in_a_template_class_can_be_mocked )
BOOST_CHECK( MOCK_VERIFY( some_template_class< int >::some_static_method ) );
MOCK_RESET( some_template_class< int >::some_static_method );
}
namespace
{
struct non_comparable_type
{};
}
namespace mock
{
bool compare( non_comparable_type, non_comparable_type )
{
return true;
}
}
BOOST_AUTO_TEST_CASE( compare_function_can_be_used_to_customize_validation )
{
MOCK_FUNCTOR( f, void( non_comparable_type ) );
MOCK_EXPECT( f ).with( non_comparable_type() );
}