mirror of
https://github.com/mat007/turtle.git
synced 2026-06-22 12:13:43 +00:00
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
This commit is contained in:
parent
57848d082c
commit
9a74e73a03
2 changed files with 30 additions and 11 deletions
|
|
@ -15,6 +15,7 @@
|
|||
#include "log.hpp"
|
||||
#include <boost/utility/enable_if.hpp>
|
||||
#include <boost/concept_check.hpp>
|
||||
#include <boost/ref.hpp>
|
||||
|
||||
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
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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" );
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue