From 7b0cde6b53654ddb5f8efbb8ac6374a8d4f4b21d Mon Sep 17 00:00:00 2001 From: mat007 Date: Thu, 12 Apr 2012 14:28:41 +0000 Subject: [PATCH] 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 --- src/libraries/turtle/check.hpp | 8 +++++++- src/tests/turtle_test/integration_test.cpp | 20 ++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/libraries/turtle/check.hpp b/src/libraries/turtle/check.hpp index 4caca9d..d9410a3 100644 --- a/src/libraries/turtle/check.hpp +++ b/src/libraries/turtle/check.hpp @@ -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 { diff --git a/src/tests/turtle_test/integration_test.cpp b/src/tests/turtle_test/integration_test.cpp index 6abd303..ca7b69d 100644 --- a/src/tests/turtle_test/integration_test.cpp +++ b/src/tests/turtle_test/integration_test.cpp @@ -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() ); +}