mirror of
https://github.com/mat007/turtle.git
synced 2026-06-22 12:13:43 +00:00
Use range-based for-loops
This commit is contained in:
parent
5ef17d0e33
commit
6702d68940
6 changed files with 51 additions and 67 deletions
|
|
@ -162,9 +162,8 @@ namespace detail
|
||||||
|
|
||||||
~expectation()
|
~expectation()
|
||||||
{
|
{
|
||||||
for( sequences_cit it = sequences_.begin();
|
for( auto& sequence: sequences_)
|
||||||
it != sequences_.end(); ++it )
|
sequence->remove( this );
|
||||||
(*it)->remove( this );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void invoke( const std::shared_ptr< invocation >& i )
|
void invoke( const std::shared_ptr< invocation >& i )
|
||||||
|
|
@ -220,14 +219,14 @@ namespace detail
|
||||||
|
|
||||||
bool invoke() const
|
bool invoke() const
|
||||||
{
|
{
|
||||||
for( sequences_cit it = sequences_.begin();
|
for( auto& sequence: sequences_)
|
||||||
it != sequences_.end(); ++it )
|
{
|
||||||
if( ! (*it)->is_valid( this ) )
|
if( ! sequence->is_valid( this ) )
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
bool result = invocation_->invoke();
|
bool result = invocation_->invoke();
|
||||||
for( sequences_cit it = sequences_.begin();
|
for( auto& sequence: sequences_)
|
||||||
it != sequences_.end(); ++it )
|
sequence->invalidate( this );
|
||||||
(*it)->invalidate( this );
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -251,18 +250,13 @@ namespace detail
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
typedef std::vector<
|
|
||||||
std::shared_ptr< sequence_impl >
|
|
||||||
> sequences_type;
|
|
||||||
typedef sequences_type::const_iterator sequences_cit;
|
|
||||||
|
|
||||||
std::shared_ptr< invocation > invocation_;
|
std::shared_ptr< invocation > invocation_;
|
||||||
std::shared_ptr<
|
std::shared_ptr<
|
||||||
matcher_base<
|
matcher_base<
|
||||||
void( BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, T) )
|
void( BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, T) )
|
||||||
>
|
>
|
||||||
> matcher_;
|
> matcher_;
|
||||||
sequences_type sequences_;
|
std::vector< std::shared_ptr<sequence_impl> > sequences_;
|
||||||
const char* file_;
|
const char* file_;
|
||||||
int line_;
|
int line_;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -52,14 +52,19 @@ namespace detail
|
||||||
virtual ~function_impl()
|
virtual ~function_impl()
|
||||||
{
|
{
|
||||||
if( valid_ && exceptions_ >= exceptions() )
|
if( valid_ && exceptions_ >= exceptions() )
|
||||||
for( expectations_cit it = expectations_.begin();
|
{
|
||||||
it != expectations_.end(); ++it )
|
for( const auto& expectation: expectations_ )
|
||||||
if( ! it->verify() )
|
{
|
||||||
|
if( ! expectation.verify() )
|
||||||
|
{
|
||||||
error_type::fail( "untriggered expectation",
|
error_type::fail( "untriggered expectation",
|
||||||
boost::unit_test::lazy_ostream::instance()
|
boost::unit_test::lazy_ostream::instance()
|
||||||
<< lazy_context( this )
|
<< lazy_context( this )
|
||||||
<< lazy_expectations( this ),
|
<< lazy_expectations( this ),
|
||||||
it->file(), it->line() );
|
expectation.file(), expectation.line() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
if( context_ )
|
if( context_ )
|
||||||
context_->remove( *this );
|
context_->remove( *this );
|
||||||
}
|
}
|
||||||
|
|
@ -67,17 +72,18 @@ namespace detail
|
||||||
virtual bool verify() const
|
virtual bool verify() const
|
||||||
{
|
{
|
||||||
lock _( mutex_ );
|
lock _( mutex_ );
|
||||||
for( expectations_cit it = expectations_.begin();
|
for( const auto& expectation: expectations_ )
|
||||||
it != expectations_.end(); ++it )
|
{
|
||||||
if( ! it->verify() )
|
if( ! expectation.verify() )
|
||||||
{
|
{
|
||||||
valid_ = false;
|
valid_ = false;
|
||||||
error_type::fail( "verification failed",
|
error_type::fail( "verification failed",
|
||||||
boost::unit_test::lazy_ostream::instance()
|
boost::unit_test::lazy_ostream::instance()
|
||||||
<< lazy_context( this )
|
<< lazy_context( this )
|
||||||
<< lazy_expectations( this ),
|
<< lazy_expectations( this ),
|
||||||
it->file(), it->line() );
|
expectation.file(), expectation.line() );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return valid_;
|
return valid_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -228,30 +234,31 @@ namespace detail
|
||||||
{
|
{
|
||||||
lock _( mutex_ );
|
lock _( mutex_ );
|
||||||
valid_ = false;
|
valid_ = false;
|
||||||
for( expectations_cit it = expectations_.begin();
|
for( const auto& expectation: expectations_ )
|
||||||
it != expectations_.end(); ++it )
|
{
|
||||||
if( it->is_valid(
|
if( expectation.is_valid(
|
||||||
BOOST_PP_ENUM(MOCK_NUM_ARGS, MOCK_MOVE, _) ) )
|
BOOST_PP_ENUM(MOCK_NUM_ARGS, MOCK_MOVE, _) ) )
|
||||||
{
|
{
|
||||||
if( ! it->invoke() )
|
if( ! expectation.invoke() )
|
||||||
{
|
{
|
||||||
error_type::fail( "sequence failed",
|
error_type::fail( "sequence failed",
|
||||||
MOCK_FUNCTION_CONTEXT, it->file(), it->line() );
|
MOCK_FUNCTION_CONTEXT, expectation.file(), expectation.line() );
|
||||||
return error_type::abort();
|
return error_type::abort();
|
||||||
}
|
}
|
||||||
if( ! it->valid() )
|
if( ! expectation.valid() )
|
||||||
{
|
{
|
||||||
error_type::fail( "missing action",
|
error_type::fail( "missing action",
|
||||||
MOCK_FUNCTION_CONTEXT, it->file(), it->line() );
|
MOCK_FUNCTION_CONTEXT, expectation.file(), expectation.line() );
|
||||||
return error_type::abort();
|
return error_type::abort();
|
||||||
}
|
}
|
||||||
valid_ = true;
|
valid_ = true;
|
||||||
error_type::call( MOCK_FUNCTION_CONTEXT, it->file(), it->line() );
|
error_type::call( MOCK_FUNCTION_CONTEXT, expectation.file(), expectation.line() );
|
||||||
if( it->functor() )
|
if( expectation.functor() )
|
||||||
return it->functor()(
|
return expectation.functor()(
|
||||||
BOOST_PP_ENUM(MOCK_NUM_ARGS, MOCK_MOVE, _) );
|
BOOST_PP_ENUM(MOCK_NUM_ARGS, MOCK_MOVE, _) );
|
||||||
return it->trigger();
|
return expectation.trigger();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
error_type::fail( "unexpected call", MOCK_FUNCTION_CONTEXT );
|
error_type::fail( "unexpected call", MOCK_FUNCTION_CONTEXT );
|
||||||
return error_type::abort();
|
return error_type::abort();
|
||||||
}
|
}
|
||||||
|
|
@ -297,18 +304,14 @@ namespace detail
|
||||||
{}
|
{}
|
||||||
friend std::ostream& operator<<( std::ostream& s, const lazy_expectations& e )
|
friend std::ostream& operator<<( std::ostream& s, const lazy_expectations& e )
|
||||||
{
|
{
|
||||||
for( expectations_cit it = e.impl_->expectations_.begin();
|
for( const auto& expectation: e.impl_->expectations_ )
|
||||||
it != e.impl_->expectations_.end(); ++it )
|
s << std::endl << expectation;
|
||||||
s << std::endl << *it;
|
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
const function_impl* impl_;
|
const function_impl* impl_;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::list< expectation_type > expectations_type;
|
std::list< expectation_type > expectations_;
|
||||||
typedef typename expectations_type::const_iterator expectations_cit;
|
|
||||||
|
|
||||||
expectations_type expectations_;
|
|
||||||
context* context_;
|
context* context_;
|
||||||
mutable bool valid_;
|
mutable bool valid_;
|
||||||
const int exceptions_;
|
const int exceptions_;
|
||||||
|
|
|
||||||
|
|
@ -36,27 +36,21 @@ namespace detail
|
||||||
bool verify() const
|
bool verify() const
|
||||||
{
|
{
|
||||||
bool valid = true;
|
bool valid = true;
|
||||||
for( verifiables_cit it = verifiables_.begin();
|
for( const auto* verifiable: verifiables_ )
|
||||||
it != verifiables_.end(); ++it )
|
if( ! verifiable->verify() )
|
||||||
if( ! (*it)->verify() )
|
|
||||||
valid = false;
|
valid = false;
|
||||||
return valid;
|
return valid;
|
||||||
}
|
}
|
||||||
void reset()
|
void reset()
|
||||||
{
|
{
|
||||||
const verifiables_t verifiables = verifiables_;
|
const auto verifiables = verifiables_;
|
||||||
for( verifiables_cit it = verifiables.begin();
|
for( auto* verifiable: verifiables )
|
||||||
it != verifiables.end(); ++it )
|
if( std::find( verifiables_.begin(), verifiables_.end(), verifiable ) != verifiables_.end() )
|
||||||
if( std::find( verifiables_.begin(), verifiables_.end(), *it )
|
verifiable->reset();
|
||||||
!= verifiables_.end() )
|
|
||||||
(*it)->reset();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
typedef std::vector< verifiable* > verifiables_t;
|
std::vector< verifiable* > verifiables_;
|
||||||
typedef verifiables_t::const_iterator verifiables_cit;
|
|
||||||
|
|
||||||
verifiables_t verifiables_;
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
} // mock
|
} // mock
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,7 @@ namespace detail
|
||||||
virtual void serialize( std::ostream& s, const verifiable& v ) const
|
virtual void serialize( std::ostream& s, const verifiable& v ) const
|
||||||
{
|
{
|
||||||
lock _( mutex_ );
|
lock _( mutex_ );
|
||||||
children_cit it = children_.find( &v );
|
const auto it = children_.find( &v );
|
||||||
if( it != children_.end() )
|
if( it != children_.end() )
|
||||||
s << it->second;
|
s << it->second;
|
||||||
else
|
else
|
||||||
|
|
@ -78,12 +78,9 @@ namespace detail
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
typedef std::map< const verifiable*, child > children_t;
|
|
||||||
typedef children_t::const_iterator children_cit;
|
|
||||||
|
|
||||||
group group_;
|
group group_;
|
||||||
parent parent_;
|
parent parent_;
|
||||||
children_t children_;
|
std::map< const verifiable*, child > children_;
|
||||||
const std::shared_ptr< mutex > mutex_;
|
const std::shared_ptr< mutex > mutex_;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ namespace detail
|
||||||
boost::unit_test::const_string name )
|
boost::unit_test::const_string name )
|
||||||
{
|
{
|
||||||
scoped_lock _( mutex_ );
|
scoped_lock _( mutex_ );
|
||||||
children_t::iterator it = children_.lower_bound( &v );
|
auto it = children_.lower_bound( &v );
|
||||||
if( it == children_.end() ||
|
if( it == children_.end() ||
|
||||||
children_.key_comp()( &v, it->first ) )
|
children_.key_comp()( &v, it->first ) )
|
||||||
it = children_.insert( it,
|
it = children_.insert( it,
|
||||||
|
|
@ -67,7 +67,7 @@ namespace detail
|
||||||
virtual void serialize( std::ostream& s, const verifiable& v ) const
|
virtual void serialize( std::ostream& s, const verifiable& v ) const
|
||||||
{
|
{
|
||||||
scoped_lock _( mutex_ );
|
scoped_lock _( mutex_ );
|
||||||
children_cit it = children_.find( &v );
|
const auto it = children_.find( &v );
|
||||||
if( it != children_.end() )
|
if( it != children_.end() )
|
||||||
s << it->second;
|
s << it->second;
|
||||||
else
|
else
|
||||||
|
|
@ -120,11 +120,8 @@ namespace detail
|
||||||
child child_;
|
child child_;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::map< const verifiable*, counter_child > children_t;
|
|
||||||
typedef children_t::const_iterator children_cit;
|
|
||||||
|
|
||||||
parents_t parents_;
|
parents_t parents_;
|
||||||
children_t children_;
|
std::map< const verifiable*, counter_child > children_;
|
||||||
group group_;
|
group group_;
|
||||||
mutable mutex mutex_;
|
mutable mutex mutex_;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -48,8 +48,7 @@ namespace detail
|
||||||
void invalidate( const void* e )
|
void invalidate( const void* e )
|
||||||
{
|
{
|
||||||
lock _( mutex_ );
|
lock _( mutex_ );
|
||||||
elements_type::iterator it =
|
const auto it = std::find( elements_.begin(), elements_.end(), e );
|
||||||
std::find( elements_.begin(), elements_.end(), e );
|
|
||||||
if( it != elements_.end() )
|
if( it != elements_.end() )
|
||||||
elements_.erase( elements_.begin(), it );
|
elements_.erase( elements_.begin(), it );
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue