From 9a74e73a03f357fde8a96758281bd016543fd14b Mon Sep 17 00:00:00 2001 From: mat007 Date: Tue, 5 Apr 2011 22:11:08 +0000 Subject: [PATCH] Added support for boost::cref and boost::ref in built-in constraints and mock::format git-svn-id: https://svn.code.sf.net/p/turtle/code/trunk@284 860be788-9bd5-4423-9f1e-828f051e677b --- src/libraries/turtle/check.hpp | 6 ++-- src/tests/turtle_test/integration_test.cpp | 35 ++++++++++++++++------ 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/src/libraries/turtle/check.hpp b/src/libraries/turtle/check.hpp index 5846ec9..5232dd8 100644 --- a/src/libraries/turtle/check.hpp +++ b/src/libraries/turtle/check.hpp @@ -15,6 +15,7 @@ #include "log.hpp" #include #include +#include namespace mock { @@ -52,7 +53,8 @@ namespace detail } private: EqualityComparable( int ) {} - Expected expected_argument_type; + BOOST_DEDUCED_TYPENAME + boost::unwrap_reference< Expected >::type expected_argument_type; Actual actual_argument_type; }; @@ -85,7 +87,7 @@ namespace detail private: virtual bool operator()( Actual actual ) const { - return actual == expected_; + return 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 f9e75d8..cf2abfa 100644 --- a/src/tests/turtle_test/integration_test.cpp +++ b/src/tests/turtle_test/integration_test.cpp @@ -63,16 +63,22 @@ namespace BOOST_AUTO_TEST_CASE( basic_mock_object_usage ) { my_mock m; - MOCK_EXPECT( m, my_method ).once().returns( 0 ); - BOOST_CHECK_EQUAL( 0, m.my_method( 13 ) ); + { + MOCK_EXPECT( m, my_method ).once().returns( 0 ); + BOOST_CHECK_EQUAL( 0, m.my_method( 13 ) ); + } mock::verify(); mock::reset(); - MOCK_EXPECT( m, my_method ).once().with( 42 ).returns( 7 ); - BOOST_CHECK_EQUAL( 7, m.my_method( 42 ) ); + { + MOCK_EXPECT( m, my_method ).once().with( 42 ).returns( 7 ); + BOOST_CHECK_EQUAL( 7, m.my_method( 42 ) ); + } mock::verify(); mock::reset(); - MOCK_EXPECT( m, my_method ).once().returns( 51 ); - BOOST_CHECK_EQUAL( 51, m.my_method( 27 ) ); + { + MOCK_EXPECT( m, my_method ).once().returns( 51 ); + BOOST_CHECK_EQUAL( 51, m.my_method( 27 ) ); + } } namespace @@ -377,12 +383,14 @@ namespace template< typename Actual > bool operator()( Actual actual ) const { - return std::abs( actual - expected_ ) < threshold_; + return std::abs( actual - boost::unwrap_ref( expected_ ) ) + < boost::unwrap_ref( threshold_ ); } friend std::ostream& operator<<( std::ostream& s, const near_constraint& c ) { - return s << "near( " << c.expected_ << ", " << c.threshold_ << " )"; + return s << "near( " << mock::format( c.expected_ ) + << ", " << mock::format( c.threshold_ ) << " )"; } //template< typename Actual > @@ -401,7 +409,7 @@ namespace } } -BOOST_AUTO_TEST_CASE( writing_custom_constraint ) +BOOST_AUTO_TEST_CASE( using_custom_constraint ) { MOCK_FUNCTOR( void( float ) ) f; MOCK_EXPECT( f, _ ).with( near( 3.f, 0.01f ) ); @@ -412,3 +420,12 @@ BOOST_AUTO_TEST_CASE( writing_custom_constraint ) s << f; BOOST_CHECK_EQUAL( expected, s.str() ); } + +BOOST_AUTO_TEST_CASE( boost_reference_wrapper_is_supported_in_value_constraint ) +{ + MOCK_FUNCTOR( void( const std::string& ) ) f; + std::string s; + MOCK_EXPECT( f, _ ).once().with( boost::cref( s ) ); + s = "string"; + f( "string" ); +}