mirror of
https://github.com/mat007/turtle.git
synced 2026-06-22 12:13:43 +00:00
Refactoring
git-svn-id: https://svn.code.sf.net/p/turtle/code/trunk@133 860be788-9bd5-4423-9f1e-828f051e677b
This commit is contained in:
parent
a21b3d2c2f
commit
9a6c43ca6b
3 changed files with 54 additions and 52 deletions
|
|
@ -28,15 +28,15 @@ namespace mock
|
|||
{
|
||||
namespace detail
|
||||
{
|
||||
class matcher_base : private orderable
|
||||
class expectation_base : private orderable
|
||||
{
|
||||
public:
|
||||
matcher_base()
|
||||
expectation_base()
|
||||
: i_( new detail::unlimited() )
|
||||
, file_( "unknown location" )
|
||||
, line_( 0 )
|
||||
{}
|
||||
virtual ~matcher_base()
|
||||
virtual ~expectation_base()
|
||||
{
|
||||
for( sequences_cit it = sequences_.begin();
|
||||
it != sequences_.end(); ++it )
|
||||
|
|
@ -149,7 +149,7 @@ namespace detail
|
|||
|
||||
template< typename Result, typename Signature >
|
||||
class expectation< Result, Signature, 0 >
|
||||
: public matcher_base, public action< Result, Signature >
|
||||
: public expectation_base, public action< Result, Signature >
|
||||
{
|
||||
public:
|
||||
bool is_valid() const
|
||||
|
|
@ -182,7 +182,7 @@ namespace detail
|
|||
#define MOCK_EXPECTATION(z, n, d) \
|
||||
template< typename Result, typename Signature > \
|
||||
class expectation< Result, Signature, n > \
|
||||
: public matcher_base, public action< Result, Signature > \
|
||||
: public expectation_base, public action< Result, Signature > \
|
||||
{ \
|
||||
BOOST_PP_REPEAT_FROM_TO(0, n, MOCK_EXPECTATION_TYPEDEF, BOOST_PP_EMPTY) \
|
||||
public: \
|
||||
|
|
|
|||
|
|
@ -51,7 +51,8 @@ namespace mock
|
|||
};
|
||||
|
||||
private:
|
||||
typedef detail::expectation< result_type, Signature, arity::value > matcher_type;
|
||||
typedef detail::expectation< result_type, Signature, arity::value >
|
||||
expectation_type;
|
||||
|
||||
public:
|
||||
struct expectation_tag
|
||||
|
|
@ -84,11 +85,11 @@ namespace mock
|
|||
impl_->reset();
|
||||
}
|
||||
|
||||
matcher_type& expect( const std::string& file, int line )
|
||||
expectation_type& expect( const std::string& file, int line )
|
||||
{
|
||||
return impl_->expect( file, line );
|
||||
}
|
||||
matcher_type& expect()
|
||||
expectation_type& expect()
|
||||
{
|
||||
return impl_->expect();
|
||||
}
|
||||
|
|
@ -131,8 +132,8 @@ namespace mock
|
|||
{
|
||||
parent_->remove( *this );
|
||||
if( ! std::uncaught_exception() )
|
||||
for( matchers_cit it = matchers_.begin();
|
||||
it != matchers_.end(); ++it )
|
||||
for( expectations_cit it = expectations_.begin();
|
||||
it != expectations_.end(); ++it )
|
||||
if( valid_ && ! it->verify() )
|
||||
ErrorPolicy::untriggered_expectation(
|
||||
context(), it->file(), it->line() );
|
||||
|
|
@ -155,8 +156,8 @@ namespace mock
|
|||
|
||||
virtual bool verify() const
|
||||
{
|
||||
for( matchers_cit it = matchers_.begin();
|
||||
it != matchers_.end(); ++it )
|
||||
for( expectations_cit it = expectations_.begin();
|
||||
it != expectations_.end(); ++it )
|
||||
if( !it->verify() )
|
||||
{
|
||||
valid_ = false;
|
||||
|
|
@ -168,21 +169,21 @@ namespace mock
|
|||
virtual void reset()
|
||||
{
|
||||
valid_ = true;
|
||||
matchers_.clear();
|
||||
expectations_.clear();
|
||||
}
|
||||
|
||||
matcher_type& expect( const std::string& file, int line )
|
||||
expectation_type& expect( const std::string& file, int line )
|
||||
{
|
||||
matchers_.push_back( matcher_type() );
|
||||
matchers_.back().set_location( file, line );
|
||||
expectations_.push_back( expectation_type() );
|
||||
expectations_.back().set_location( file, line );
|
||||
valid_ = true;
|
||||
return matchers_.back();
|
||||
return expectations_.back();
|
||||
}
|
||||
matcher_type& expect()
|
||||
expectation_type& expect()
|
||||
{
|
||||
matchers_.push_back( matcher_type() );
|
||||
expectations_.push_back( expectation_type() );
|
||||
valid_ = true;
|
||||
return matchers_.back();
|
||||
return expectations_.back();
|
||||
}
|
||||
|
||||
struct no_throw_abort
|
||||
|
|
@ -199,13 +200,14 @@ namespace mock
|
|||
return invoke< ErrorPolicy >();
|
||||
}
|
||||
|
||||
#define MOCK_EXPECTATION_FORMAT(z, n, d) BOOST_PP_IF(n, + ", " +,) format( p##n )
|
||||
#define MOCK_EXPECTATION_FORMAT(z, n, d) \
|
||||
BOOST_PP_IF(n, + ", " +,) format( p##n )
|
||||
#define MOCK_EXPECTATION_CONTEXT(n) \
|
||||
context( BOOST_PP_REPEAT_FROM_TO(0, n, MOCK_EXPECTATION_FORMAT, BOOST_PP_EMPTY) )
|
||||
#define MOCK_EXPECTATION_OPERATOR(z, n, d) \
|
||||
MOCK_DECL(operator(), n, Signature, const, BOOST_DEDUCED_TYPENAME) \
|
||||
{ \
|
||||
for( matchers_cit it = matchers_.begin(); it != matchers_.end(); ++it ) \
|
||||
for( expectations_cit it = expectations_.begin(); it != expectations_.end(); ++it ) \
|
||||
if( it->is_valid( BOOST_PP_ENUM_PARAMS(n, p) ) ) \
|
||||
{ \
|
||||
if( ! it->invoke() ) \
|
||||
|
|
@ -239,8 +241,8 @@ namespace mock
|
|||
template< typename T >
|
||||
result_type invoke() const
|
||||
{
|
||||
for( matchers_cit it = matchers_.begin();
|
||||
it != matchers_.end(); ++it )
|
||||
for( expectations_cit it = expectations_.begin();
|
||||
it != expectations_.end(); ++it )
|
||||
if( it->is_valid() )
|
||||
{
|
||||
if( ! it->invoke() )
|
||||
|
|
@ -264,14 +266,14 @@ namespace mock
|
|||
}
|
||||
|
||||
private:
|
||||
typedef std::list< matcher_type > matchers_type;
|
||||
typedef std::list< expectation_type > expectations_type;
|
||||
typedef BOOST_DEDUCED_TYPENAME
|
||||
matchers_type::const_iterator matchers_cit;
|
||||
expectations_type::const_iterator expectations_cit;
|
||||
|
||||
void serialize( std::ostream& s ) const
|
||||
{
|
||||
for( matchers_cit it = matchers_.begin();
|
||||
it != matchers_.end(); ++it )
|
||||
for( expectations_cit it = expectations_.begin();
|
||||
it != expectations_.end(); ++it )
|
||||
s << std::endl << *it;
|
||||
}
|
||||
|
||||
|
|
@ -297,7 +299,7 @@ namespace mock
|
|||
std::string name_;
|
||||
node* parent_;
|
||||
mutable bool valid_;
|
||||
matchers_type matchers_;
|
||||
expectations_type expectations_;
|
||||
};
|
||||
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -530,7 +530,7 @@ BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_throws_the_set_exception, err
|
|||
BOOST_FAIL( "should have thrown" );
|
||||
}
|
||||
|
||||
// multiple matchers
|
||||
// multiple expectations
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE( expecting_twice_a_single_expectation_makes_it_callable_twice, error_fixture )
|
||||
{
|
||||
|
|
@ -552,7 +552,7 @@ BOOST_FIXTURE_TEST_CASE( expecting_twice_a_single_expectation_makes_it_callable_
|
|||
}
|
||||
}
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE( best_matcher_is_selected_first, error_fixture )
|
||||
BOOST_FIXTURE_TEST_CASE( best_expectation_is_selected_first, error_fixture )
|
||||
{
|
||||
{
|
||||
mock::function< void( int ) > e;
|
||||
|
|
@ -704,7 +704,7 @@ BOOST_FIXTURE_TEST_CASE( triggering_no_match_call_disables_the_automatic_verific
|
|||
CHECK_ERROR( e(), no_match );
|
||||
}
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE( adding_a_matcher_reactivates_the_verification_upon_destruction, error_fixture )
|
||||
BOOST_FIXTURE_TEST_CASE( adding_a_expectation_reactivates_the_verification_upon_destruction, error_fixture )
|
||||
{
|
||||
std::auto_ptr< mock::function< void() > > e( new mock::function< void() > );
|
||||
CHECK_ERROR( (*e)(), no_match );
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue