mirror of
https://github.com/mat007/turtle.git
synced 2026-06-22 12:13:43 +00:00
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:
parent
50f74c1eaf
commit
7b0cde6b53
2 changed files with 27 additions and 1 deletions
|
|
@ -20,6 +20,12 @@
|
||||||
|
|
||||||
namespace mock
|
namespace mock
|
||||||
{
|
{
|
||||||
|
template< typename Actual, typename Expected >
|
||||||
|
bool compare( const Actual& actual, const Expected& expected )
|
||||||
|
{
|
||||||
|
return actual == expected;
|
||||||
|
}
|
||||||
|
|
||||||
namespace detail
|
namespace detail
|
||||||
{
|
{
|
||||||
template< typename Actual >
|
template< typename Actual >
|
||||||
|
|
@ -49,7 +55,7 @@ namespace detail
|
||||||
private:
|
private:
|
||||||
virtual bool operator()( Actual actual )
|
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
|
virtual void serialize( std::ostream& s ) const
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -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 ) );
|
BOOST_CHECK( MOCK_VERIFY( some_template_class< int >::some_static_method ) );
|
||||||
MOCK_RESET( 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() );
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue