mirror of
https://github.com/mat007/turtle.git
synced 2026-06-22 12:13:43 +00:00
Fixed a crash due to static deinitialization order fiasco on some platforms
git-svn-id: https://svn.code.sf.net/p/turtle/code/trunk@144 860be788-9bd5-4423-9f1e-828f051e677b
This commit is contained in:
parent
4647bfd007
commit
f0fd0428d8
5 changed files with 36 additions and 6 deletions
|
|
@ -127,7 +127,8 @@ namespace mock
|
||||||
}
|
}
|
||||||
virtual ~function_impl()
|
virtual ~function_impl()
|
||||||
{
|
{
|
||||||
parent_->remove( *this );
|
if( parent_ )
|
||||||
|
parent_->remove( *this );
|
||||||
if( ! std::uncaught_exception() )
|
if( ! std::uncaught_exception() )
|
||||||
for( expectations_cit it = expectations_.begin();
|
for( expectations_cit it = expectations_.begin();
|
||||||
it != expectations_.end(); ++it )
|
it != expectations_.end(); ++it )
|
||||||
|
|
@ -146,7 +147,8 @@ namespace mock
|
||||||
}
|
}
|
||||||
void set_parent( node& parent )
|
void set_parent( node& parent )
|
||||||
{
|
{
|
||||||
parent_->remove( *this );
|
if( parent_ )
|
||||||
|
parent_->remove( *this );
|
||||||
parent.add( *this );
|
parent.add( *this );
|
||||||
parent_ = &parent;
|
parent_ = &parent;
|
||||||
}
|
}
|
||||||
|
|
@ -168,6 +170,10 @@ namespace mock
|
||||||
valid_ = true;
|
valid_ = true;
|
||||||
expectations_.clear();
|
expectations_.clear();
|
||||||
}
|
}
|
||||||
|
virtual void untie()
|
||||||
|
{
|
||||||
|
parent_ = 0;
|
||||||
|
}
|
||||||
|
|
||||||
expectation_type& expect( const std::string& file, int line )
|
expectation_type& expect( const std::string& file, int line )
|
||||||
{
|
{
|
||||||
|
|
@ -285,7 +291,9 @@ namespace mock
|
||||||
void serialize( std::ostream& s,
|
void serialize( std::ostream& s,
|
||||||
const std::string& parameters ) const
|
const std::string& parameters ) const
|
||||||
{
|
{
|
||||||
s << parent_->tag() << name_ << parameters;
|
if( parent_ )
|
||||||
|
s << parent_->tag();
|
||||||
|
s << name_ << parameters;
|
||||||
for( expectations_cit it = expectations_.begin();
|
for( expectations_cit it = expectations_.begin();
|
||||||
it != expectations_.end(); ++it )
|
it != expectations_.end(); ++it )
|
||||||
s << std::endl << *it;
|
s << std::endl << *it;
|
||||||
|
|
|
||||||
|
|
@ -42,6 +42,8 @@ namespace mock
|
||||||
std::for_each( v_.begin(), v_.end(),
|
std::for_each( v_.begin(), v_.end(),
|
||||||
std::mem_fun( &verifiable::reset ) );
|
std::mem_fun( &verifiable::reset ) );
|
||||||
}
|
}
|
||||||
|
virtual void untie()
|
||||||
|
{}
|
||||||
|
|
||||||
void tag( const std::string& name )
|
void tag( const std::string& name )
|
||||||
{
|
{
|
||||||
|
|
@ -54,7 +56,10 @@ namespace mock
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual ~node()
|
virtual ~node()
|
||||||
{}
|
{
|
||||||
|
std::for_each( v_.begin(), v_.end(),
|
||||||
|
std::mem_fun( &verifiable::untie ) );
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
typedef std::vector< verifiable* > verifiables_type;
|
typedef std::vector< verifiable* > verifiables_type;
|
||||||
|
|
|
||||||
|
|
@ -19,11 +19,11 @@ namespace mock
|
||||||
verifiable() {}
|
verifiable() {}
|
||||||
virtual ~verifiable() {}
|
virtual ~verifiable() {}
|
||||||
|
|
||||||
// return false if verification fails
|
|
||||||
virtual bool verify() const = 0;
|
virtual bool verify() const = 0;
|
||||||
|
|
||||||
// return to the initial state
|
|
||||||
virtual void reset() = 0;
|
virtual void reset() = 0;
|
||||||
|
|
||||||
|
virtual void untie() = 0;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -53,6 +53,13 @@ namespace
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// static
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
boost::function< void() > static_f;
|
||||||
|
}
|
||||||
|
|
||||||
// functor
|
// functor
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE( a_function_can_be_passed_as_functor, error_fixture )
|
BOOST_FIXTURE_TEST_CASE( a_function_can_be_passed_as_functor, error_fixture )
|
||||||
|
|
|
||||||
|
|
@ -81,3 +81,13 @@ BOOST_AUTO_TEST_CASE( an_object_is_copiable_by_sharing_its_state )
|
||||||
o2.reset();
|
o2.reset();
|
||||||
BOOST_CHECK( ! o1.verify() );
|
BOOST_CHECK( ! o1.verify() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE( an_object_can_be_destroyed_before_its_children_functions )
|
||||||
|
{
|
||||||
|
mock::function< void() > f;
|
||||||
|
{
|
||||||
|
mock::object o;
|
||||||
|
o.set_child( f );
|
||||||
|
}
|
||||||
|
f.test();
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue