git-svn-id: https://svn.code.sf.net/p/turtle/code/trunk@581 860be788-9bd5-4423-9f1e-828f051e677b
This commit is contained in:
mat007 2013-01-07 16:16:38 +00:00
parent 970b9b6b7b
commit 3c0bb8e16e
8 changed files with 79 additions and 82 deletions

View file

@ -43,8 +43,8 @@ BOOST_AUTO_TEST_CASE( constraints_can_be_combined_using_the_and_operator )
BOOST_AUTO_TEST_CASE( equal ) BOOST_AUTO_TEST_CASE( equal )
{ {
BOOST_CHECK( mock::equal( std::string( "string" ) ).f_( "string" ) ); BOOST_CHECK( mock::equal( std::string( "string" ) ).c_( "string" ) );
BOOST_CHECK( ! mock::equal( std::string( "string" ) ).f_( "not string" ) ); BOOST_CHECK( ! mock::equal( std::string( "string" ) ).c_( "not string" ) );
{ {
std::string s; std::string s;
mock::constraint< mock::constraint<
@ -53,7 +53,7 @@ BOOST_AUTO_TEST_CASE( equal )
> >
> c = mock::equal( boost::cref( s ) ); > c = mock::equal( boost::cref( s ) );
s = "string"; s = "string";
BOOST_CHECK( c.f_( "string" ) ); BOOST_CHECK( c.c_( "string" ) );
} }
} }
@ -63,8 +63,8 @@ BOOST_AUTO_TEST_CASE( same )
int i = 0; int i = 0;
int j = 0; int j = 0;
BOOST_CHECK_EQUAL( i, j ); BOOST_CHECK_EQUAL( i, j );
BOOST_CHECK( ! mock::same( i ).f_( j ) ); BOOST_CHECK( ! mock::same( i ).c_( j ) );
BOOST_CHECK( mock::same( i ).f_( i ) ); BOOST_CHECK( mock::same( i ).c_( i ) );
} }
{ {
int i = 0; int i = 0;
@ -75,8 +75,8 @@ BOOST_AUTO_TEST_CASE( same )
const boost::reference_wrapper< const int > const boost::reference_wrapper< const int >
> >
> c = mock::same( boost::cref( i ) ); > c = mock::same( boost::cref( i ) );
BOOST_CHECK( ! c.f_( j ) ); BOOST_CHECK( ! c.c_( j ) );
BOOST_CHECK( c.f_( i ) ); BOOST_CHECK( c.c_( i ) );
} }
} }
@ -84,18 +84,18 @@ BOOST_AUTO_TEST_CASE( assign )
{ {
{ {
int i = 0; int i = 0;
BOOST_CHECK( mock::assign( 3 ).f_( i ) ); BOOST_CHECK( mock::assign( 3 ).c_( i ) );
BOOST_CHECK_EQUAL( 3, i ); BOOST_CHECK_EQUAL( 3, i );
} }
{ {
int i = 0; int i = 0;
BOOST_CHECK( mock::assign( 3 ).f_( &i ) ); BOOST_CHECK( mock::assign( 3 ).c_( &i ) );
BOOST_CHECK_EQUAL( 3, i ); BOOST_CHECK_EQUAL( 3, i );
} }
{ {
const int* i = 0; const int* i = 0;
const int j = 1; const int j = 1;
BOOST_CHECK( mock::assign( &j ).f_( i ) ); BOOST_CHECK( mock::assign( &j ).c_( i ) );
BOOST_CHECK_EQUAL( &j, i ); BOOST_CHECK_EQUAL( &j, i );
} }
{ {
@ -106,10 +106,10 @@ BOOST_AUTO_TEST_CASE( assign )
boost::reference_wrapper< const int > boost::reference_wrapper< const int >
> >
> c = mock::assign( boost::cref( j ) ); > c = mock::assign( boost::cref( j ) );
BOOST_CHECK( c.f_( i ) ); BOOST_CHECK( c.c_( i ) );
BOOST_CHECK_EQUAL( 1, i ); BOOST_CHECK_EQUAL( 1, i );
j = 3; j = 3;
BOOST_CHECK( c.f_( i ) ); BOOST_CHECK( c.c_( i ) );
BOOST_CHECK_EQUAL( 3, i ); BOOST_CHECK_EQUAL( 3, i );
} }
{ {
@ -120,10 +120,10 @@ BOOST_AUTO_TEST_CASE( assign )
boost::reference_wrapper< const int > boost::reference_wrapper< const int >
> >
> c = mock::assign( boost::cref( j ) ); > c = mock::assign( boost::cref( j ) );
BOOST_CHECK( c.f_( &i ) ); BOOST_CHECK( c.c_( &i ) );
BOOST_CHECK_EQUAL( 1, i ); BOOST_CHECK_EQUAL( 1, i );
j = 3; j = 3;
BOOST_CHECK( c.f_( &i ) ); BOOST_CHECK( c.c_( &i ) );
BOOST_CHECK_EQUAL( 3, i ); BOOST_CHECK_EQUAL( 3, i );
} }
{ {
@ -135,10 +135,10 @@ BOOST_AUTO_TEST_CASE( assign )
boost::reference_wrapper< int* const > boost::reference_wrapper< int* const >
> >
> c = mock::assign( boost::cref( j ) ); > c = mock::assign( boost::cref( j ) );
BOOST_CHECK( c.f_( i ) ); BOOST_CHECK( c.c_( i ) );
BOOST_CHECK_EQUAL( j, i ); BOOST_CHECK_EQUAL( j, i );
j = 0; j = 0;
BOOST_CHECK( c.f_( i ) ); BOOST_CHECK( c.c_( i ) );
BOOST_CHECK_EQUAL( j, i ); BOOST_CHECK_EQUAL( j, i );
} }
} }
@ -148,61 +148,61 @@ BOOST_AUTO_TEST_CASE( retrieve )
{ {
int i = 0; int i = 0;
const int j = 1; const int j = 1;
BOOST_CHECK( mock::retrieve( i ).f_( j ) ); BOOST_CHECK( mock::retrieve( i ).c_( j ) );
BOOST_CHECK_EQUAL( i, j ); BOOST_CHECK_EQUAL( i, j );
} }
{ {
int* i = 0; int* i = 0;
int j = 1; int j = 1;
BOOST_CHECK( mock::retrieve( i ).f_( &j ) ); BOOST_CHECK( mock::retrieve( i ).c_( &j ) );
BOOST_CHECK_EQUAL( i, &j ); BOOST_CHECK_EQUAL( i, &j );
} }
{ {
const int* i = 0; const int* i = 0;
const int j = 1; const int j = 1;
BOOST_CHECK( mock::retrieve( i ).f_( j ) ); BOOST_CHECK( mock::retrieve( i ).c_( j ) );
BOOST_CHECK_EQUAL( i, &j ); BOOST_CHECK_EQUAL( i, &j );
} }
{ {
const int* i = 0; const int* i = 0;
int j = 1; int j = 1;
BOOST_CHECK( mock::retrieve( i ).f_( j ) ); BOOST_CHECK( mock::retrieve( i ).c_( j ) );
BOOST_CHECK_EQUAL( i, &j ); BOOST_CHECK_EQUAL( i, &j );
} }
{ {
int* i = 0; int* i = 0;
int j = 1; int j = 1;
BOOST_CHECK( mock::retrieve( i ).f_( j ) ); BOOST_CHECK( mock::retrieve( i ).c_( j ) );
BOOST_CHECK_EQUAL( i, &j ); BOOST_CHECK_EQUAL( i, &j );
} }
{ {
const int* i = 0; const int* i = 0;
const int j = 1; const int j = 1;
BOOST_CHECK( mock::retrieve( i ).f_( j ) ); BOOST_CHECK( mock::retrieve( i ).c_( j ) );
BOOST_CHECK_EQUAL( i, &j ); BOOST_CHECK_EQUAL( i, &j );
} }
{ {
int** i = 0; int** i = 0;
int* j = 0; int* j = 0;
BOOST_CHECK( mock::retrieve( i ).f_( j ) ); BOOST_CHECK( mock::retrieve( i ).c_( j ) );
BOOST_CHECK_EQUAL( i, &j ); BOOST_CHECK_EQUAL( i, &j );
} }
{ {
const int** i = 0; const int** i = 0;
const int* j = 0; const int* j = 0;
BOOST_CHECK( mock::retrieve( i ).f_( j ) ); BOOST_CHECK( mock::retrieve( i ).c_( j ) );
BOOST_CHECK_EQUAL( i, &j ); BOOST_CHECK_EQUAL( i, &j );
} }
{ {
int i = 0; int i = 0;
const int j = 1; const int j = 1;
BOOST_CHECK( mock::retrieve( boost::ref( i ) ).f_( j ) ); BOOST_CHECK( mock::retrieve( boost::ref( i ) ).c_( j ) );
BOOST_CHECK_EQUAL( i, j ); BOOST_CHECK_EQUAL( i, j );
} }
{ {
const int* i = 0; const int* i = 0;
const int j = 1; const int j = 1;
BOOST_CHECK( mock::retrieve( boost::ref( i ) ).f_( j ) ); BOOST_CHECK( mock::retrieve( boost::ref( i ) ).c_( j ) );
BOOST_CHECK_EQUAL( i, &j ); BOOST_CHECK_EQUAL( i, &j );
} }
} }
@ -225,23 +225,23 @@ BOOST_AUTO_TEST_CASE( retrieve_uses_assignment_operator )
{ {
B b; B b;
const A a = A(); const A a = A();
mock::retrieve( b ).f_( a ); mock::retrieve( b ).c_( a );
} }
BOOST_AUTO_TEST_CASE( affirm ) BOOST_AUTO_TEST_CASE( affirm )
{ {
int* i = 0; int* i = 0;
int j; int j;
BOOST_CHECK( ! mock::affirm.f_( i ) ); BOOST_CHECK( ! mock::affirm.c_( i ) );
BOOST_CHECK( mock::affirm.f_( &j ) ); BOOST_CHECK( mock::affirm.c_( &j ) );
} }
BOOST_AUTO_TEST_CASE( negate ) BOOST_AUTO_TEST_CASE( negate )
{ {
int* i = 0; int* i = 0;
int j; int j;
BOOST_CHECK( mock::negate.f_( i ) ); BOOST_CHECK( mock::negate.c_( i ) );
BOOST_CHECK( ! mock::negate.f_( &j ) ); BOOST_CHECK( ! mock::negate.c_( &j ) );
} }
namespace namespace
@ -258,22 +258,22 @@ namespace
BOOST_AUTO_TEST_CASE( call ) BOOST_AUTO_TEST_CASE( call )
{ {
BOOST_CHECK( mock::call( &return_true ).f_() ); BOOST_CHECK( mock::call( &return_true ).c_() );
BOOST_CHECK( ! mock::call( &return_false ).f_() ); BOOST_CHECK( ! mock::call( &return_false ).c_() );
} }
BOOST_AUTO_TEST_CASE( evaluate ) BOOST_AUTO_TEST_CASE( evaluate )
{ {
BOOST_CHECK( mock::evaluate.f_( &return_true ) ); BOOST_CHECK( mock::evaluate.c_( &return_true ) );
BOOST_CHECK( ! mock::evaluate.f_( &return_false ) ); BOOST_CHECK( ! mock::evaluate.c_( &return_false ) );
} }
BOOST_AUTO_TEST_CASE( contain_with_const_char_ptr ) BOOST_AUTO_TEST_CASE( contain_with_const_char_ptr )
{ {
BOOST_CHECK( mock::contain( "string" ).f_( "this is a string" ) ); BOOST_CHECK( mock::contain( "string" ).c_( "this is a string" ) );
BOOST_CHECK( mock::contain( "string" ).f_( std::string( "this is a string" ) ) ); BOOST_CHECK( mock::contain( "string" ).c_( std::string( "this is a string" ) ) );
BOOST_CHECK( ! mock::contain( "not found" ).f_( "this is a string" ) ); BOOST_CHECK( ! mock::contain( "not found" ).c_( "this is a string" ) );
BOOST_CHECK( ! mock::contain( "not found" ).f_( std::string( "this is a string" ) ) ); BOOST_CHECK( ! mock::contain( "not found" ).c_( std::string( "this is a string" ) ) );
{ {
const char* s = 0; const char* s = 0;
mock::constraint< mock::constraint<
@ -282,20 +282,20 @@ BOOST_AUTO_TEST_CASE( contain_with_const_char_ptr )
> >
> c = mock::contain( boost::cref( s ) ); > c = mock::contain( boost::cref( s ) );
s = "string"; s = "string";
BOOST_CHECK( c.f_( "this is a string" ) ); BOOST_CHECK( c.c_( "this is a string" ) );
BOOST_CHECK( c.f_( std::string( "this is a string" ) ) ); BOOST_CHECK( c.c_( std::string( "this is a string" ) ) );
s = "not found"; s = "not found";
BOOST_CHECK( ! c.f_( "this is a string" ) ); BOOST_CHECK( ! c.c_( "this is a string" ) );
BOOST_CHECK( ! c.f_( std::string( "this is a string" ) ) ); BOOST_CHECK( ! c.c_( std::string( "this is a string" ) ) );
} }
} }
BOOST_AUTO_TEST_CASE( contain_with_strings ) BOOST_AUTO_TEST_CASE( contain_with_strings )
{ {
BOOST_CHECK( mock::contain( std::string( "string" ) ).f_( "this is a string" ) ); BOOST_CHECK( mock::contain( std::string( "string" ) ).c_( "this is a string" ) );
BOOST_CHECK( mock::contain( std::string( "string" ) ).f_( std::string( "this is a string" ) ) ); BOOST_CHECK( mock::contain( std::string( "string" ) ).c_( std::string( "this is a string" ) ) );
BOOST_CHECK( ! mock::contain( std::string( "not found" ) ).f_( "this is a string" ) ); BOOST_CHECK( ! mock::contain( std::string( "not found" ) ).c_( "this is a string" ) );
BOOST_CHECK( ! mock::contain( std::string( "not found" ) ).f_( std::string( "this is a string" ) ) ); BOOST_CHECK( ! mock::contain( std::string( "not found" ) ).c_( std::string( "this is a string" ) ) );
{ {
std::string s; std::string s;
mock::constraint< mock::constraint<
@ -304,11 +304,11 @@ BOOST_AUTO_TEST_CASE( contain_with_strings )
> >
> c = mock::contain( boost::cref( s ) ); > c = mock::contain( boost::cref( s ) );
s = "string"; s = "string";
BOOST_CHECK( c.f_( "this is a string" ) ); BOOST_CHECK( c.c_( "this is a string" ) );
BOOST_CHECK( c.f_( std::string( "this is a string" ) ) ); BOOST_CHECK( c.c_( std::string( "this is a string" ) ) );
s = "not found"; s = "not found";
BOOST_CHECK( ! c.f_( "this is a string" ) ); BOOST_CHECK( ! c.c_( "this is a string" ) );
BOOST_CHECK( ! c.f_( std::string( "this is a string" ) ) ); BOOST_CHECK( ! c.c_( std::string( "this is a string" ) ) );
} }
} }
@ -324,8 +324,8 @@ namespace
BOOST_AUTO_TEST_CASE( type_with_overloaded_address_operator_can_be_used_in_constraints ) BOOST_AUTO_TEST_CASE( type_with_overloaded_address_operator_can_be_used_in_constraints )
{ {
type_with_overloaded_address_operator t; type_with_overloaded_address_operator t;
mock::same( t ).f_( t ); mock::same( t ).c_( t );
mock::retrieve( t ).f_( t ); mock::retrieve( t ).c_( t );
type_with_overloaded_address_operator* pt; type_with_overloaded_address_operator* pt;
mock::retrieve( pt ).f_( t ); mock::retrieve( pt ).c_( t );
} }

View file

@ -18,9 +18,9 @@ namespace mock
struct constraint struct constraint
{ {
constraint( const Constraint& c ) constraint( const Constraint& c )
: f_( c ) : c_( c )
{} {}
Constraint f_; Constraint c_;
}; };
namespace detail namespace detail
@ -75,20 +75,20 @@ namespace detail
class not_ class not_
{ {
public: public:
explicit not_( const Constraint& f ) explicit not_( const Constraint& c )
: f_( f ) : c_( c )
{} {}
template< typename Actual > template< typename Actual >
bool operator()( const Actual& actual ) const bool operator()( const Actual& actual ) const
{ {
return ! f_( actual ); return ! c_( actual );
} }
friend std::ostream& operator<<( std::ostream& s, const not_& n ) friend std::ostream& operator<<( std::ostream& s, const not_& n )
{ {
return s << "! " << mock::format( n.f_ ); return s << "! " << mock::format( n.c_ );
} }
private: private:
Constraint f_; Constraint c_;
}; };
} }
@ -97,7 +97,7 @@ namespace detail
operator||( const constraint< Constraint1 >& lhs, operator||( const constraint< Constraint1 >& lhs,
const constraint< Constraint2 >& rhs ) const constraint< Constraint2 >& rhs )
{ {
return detail::or_< Constraint1, Constraint2 >( lhs.f_, rhs.f_ ); return detail::or_< Constraint1, Constraint2 >( lhs.c_, rhs.c_ );
} }
template< typename Constraint1, typename Constraint2 > template< typename Constraint1, typename Constraint2 >
@ -105,14 +105,14 @@ namespace detail
operator&&( const constraint< Constraint1 >& lhs, operator&&( const constraint< Constraint1 >& lhs,
const constraint< Constraint2 >& rhs ) const constraint< Constraint2 >& rhs )
{ {
return detail::and_< Constraint1, Constraint2 >( lhs.f_, rhs.f_ ); return detail::and_< Constraint1, Constraint2 >( lhs.c_, rhs.c_ );
} }
template< typename Constraint > template< typename Constraint >
const constraint< detail::not_< Constraint > > const constraint< detail::not_< Constraint > >
operator!( const constraint< Constraint >& c ) operator!( const constraint< Constraint >& c )
{ {
return detail::not_< Constraint >( c.f_ ); return detail::not_< Constraint >( c.c_ );
} }
} // mock } // mock
@ -137,7 +137,7 @@ namespace detail
{ \ { \
constraint() \ constraint() \
{} \ {} \
detail::N f_; \ detail::N c_; \
}; \ }; \
const constraint< detail::N > N; const constraint< detail::N > N;

View file

@ -50,7 +50,7 @@ namespace detail
void calls( const functor_type& f ) void calls( const functor_type& f )
{ {
if( !f ) if( ! f )
throw std::invalid_argument( "null functor" ); throw std::invalid_argument( "null functor" );
f_ = f; f_ = f;
} }
@ -92,7 +92,7 @@ namespace detail
void calls( const functor_type& f ) void calls( const functor_type& f )
{ {
if( !f ) if( ! f )
throw std::invalid_argument( "null functor" ); throw std::invalid_argument( "null functor" );
f_ = f; f_ = f;
} }
@ -127,7 +127,7 @@ namespace detail
void calls( const functor_type& f ) void calls( const functor_type& f )
{ {
if( !f ) if( ! f )
throw std::invalid_argument( "null functor" ); throw std::invalid_argument( "null functor" );
f_ = f; f_ = f;
} }
@ -173,7 +173,7 @@ namespace detail
void calls( const functor_type& f ) void calls( const functor_type& f )
{ {
if( !f ) if( ! f )
throw std::invalid_argument( "null functor" ); throw std::invalid_argument( "null functor" );
f_ = f; f_ = f;
} }

View file

@ -128,4 +128,3 @@ namespace detail
#undef MOCK_EXPECTATION_ARGS #undef MOCK_EXPECTATION_ARGS
#undef MOCK_EXPECTATION_IS_VALID #undef MOCK_EXPECTATION_IS_VALID
#undef MOCK_EXPECTATION_SERIALIZE #undef MOCK_EXPECTATION_SERIALIZE
#undef MOCK_EXPECTATION

View file

@ -70,7 +70,7 @@ namespace detail
{ {
for( expectations_cit it = expectations_.begin(); for( expectations_cit it = expectations_.begin();
it != expectations_.end(); ++it ) it != expectations_.end(); ++it )
if( !it->verify() ) if( ! it->verify() )
{ {
valid_ = false; valid_ = false;
error_type::fail( "verification failed", error_type::fail( "verification failed",
@ -133,9 +133,9 @@ namespace detail
} }
friend std::ostream& operator<<( friend std::ostream& operator<<(
std::ostream& s, const function_impl& e ) std::ostream& s, const function_impl& impl )
{ {
return s << lazy_context( &e ) << lazy_expectations( &e ); return s << lazy_context( &impl ) << lazy_expectations( &impl );
} }
struct lazy_context struct lazy_context

View file

@ -30,8 +30,7 @@ namespace detail
virtual bool invoked() const = 0; virtual bool invoked() const = 0;
virtual bool exhausted() const = 0; virtual bool exhausted() const = 0;
friend inline std::ostream& operator<<( friend std::ostream& operator<<( std::ostream& s, const invocation& i )
std::ostream& s, const invocation& i )
{ {
return i.serialize( s ); return i.serialize( s );
} }

View file

@ -52,8 +52,7 @@ namespace mock
} }
template< typename Context > template< typename Context >
static void call( const Context& context, static void call( const Context& context, const char* file, int line )
const char* file, int line )
{ {
boost::unit_test::framework::assertion_result( true ); boost::unit_test::framework::assertion_result( true );
boost::unit_test::unit_test_log boost::unit_test::unit_test_log

View file

@ -66,7 +66,7 @@ namespace mock
{ {
public: public:
explicit matcher( const constraint< Constraint >& c ) explicit matcher( const constraint< Constraint >& c )
: c_( c.f_ ) : c_( c.c_ )
{} {}
virtual bool operator()( Actual actual ) virtual bool operator()( Actual actual )
{ {
@ -90,19 +90,19 @@ namespace mock
{ {
public: public:
explicit matcher( const Functor& f ) explicit matcher( const Functor& f )
: f_( f ) : c_( f )
{} {}
virtual bool operator()( Actual actual ) virtual bool operator()( Actual actual )
{ {
return f_( actual ); return c_( actual );
} }
private: private:
virtual void serialize( std::ostream& s ) const virtual void serialize( std::ostream& s ) const
{ {
s << mock::format( f_ ); s << mock::format( c_ );
} }
private: private:
Functor f_; Functor c_;
}; };
} // mock } // mock