mirror of
https://github.com/mat007/turtle.git
synced 2026-06-22 12:13:43 +00:00
Fixed a crash due to static initialization order fiasco on some platforms
git-svn-id: https://svn.code.sf.net/p/turtle/code/trunk@146 860be788-9bd5-4423-9f1e-828f051e677b
This commit is contained in:
parent
f1030c6dfd
commit
a91d0975bc
5 changed files with 47 additions and 23 deletions
|
|
@ -120,11 +120,9 @@ namespace mock
|
||||||
public:
|
public:
|
||||||
function_impl()
|
function_impl()
|
||||||
: name_( "?" )
|
: name_( "?" )
|
||||||
, parent_( &root() )
|
, parent_( 0 )
|
||||||
, valid_( true )
|
, valid_( true )
|
||||||
{
|
{}
|
||||||
parent_->add( *this );
|
|
||||||
}
|
|
||||||
virtual ~function_impl()
|
virtual ~function_impl()
|
||||||
{
|
{
|
||||||
if( parent_ )
|
if( parent_ )
|
||||||
|
|
@ -177,13 +175,14 @@ namespace mock
|
||||||
|
|
||||||
expectation_type& expect( const std::string& file, int line )
|
expectation_type& expect( const std::string& file, int line )
|
||||||
{
|
{
|
||||||
expectations_.push_back( expectation_type() );
|
expectation_type& e = expect();
|
||||||
expectations_.back().set_location( file, line );
|
e.set_location( file, line );
|
||||||
valid_ = true;
|
return e;
|
||||||
return expectations_.back();
|
|
||||||
}
|
}
|
||||||
expectation_type& expect()
|
expectation_type& expect()
|
||||||
{
|
{
|
||||||
|
if( ! parent_ )
|
||||||
|
set_parent( root );
|
||||||
expectations_.push_back( expectation_type() );
|
expectations_.push_back( expectation_type() );
|
||||||
valid_ = true;
|
valid_ = true;
|
||||||
return expectations_.back();
|
return expectations_.back();
|
||||||
|
|
|
||||||
|
|
@ -58,10 +58,6 @@ namespace mock
|
||||||
std::mem_fun( &verifiable::reset ) );
|
std::mem_fun( &verifiable::reset ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
|
||||||
virtual void untie()
|
|
||||||
{}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
typedef std::vector< verifiable* > verifiables_type;
|
typedef std::vector< verifiable* > verifiables_type;
|
||||||
typedef verifiables_type::const_iterator verifiables_cit;
|
typedef verifiables_type::const_iterator verifiables_cit;
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ namespace mock
|
||||||
template< typename T >
|
template< typename T >
|
||||||
void set_child( T& t ) const
|
void set_child( T& t ) const
|
||||||
{
|
{
|
||||||
t.set_parent( *impl_ );
|
impl_->set_child( t );
|
||||||
}
|
}
|
||||||
void tag( const std::string& name ) const
|
void tag( const std::string& name ) const
|
||||||
{
|
{
|
||||||
|
|
@ -48,13 +48,32 @@ namespace mock
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
object_impl()
|
object_impl()
|
||||||
{
|
: parent_( 0 )
|
||||||
root().add( *this );
|
{}
|
||||||
}
|
|
||||||
virtual ~object_impl()
|
virtual ~object_impl()
|
||||||
{
|
{
|
||||||
root().remove( *this );
|
if( parent_ )
|
||||||
|
parent_->remove( *this );
|
||||||
}
|
}
|
||||||
|
template< typename T >
|
||||||
|
void set_child( T& t )
|
||||||
|
{
|
||||||
|
if( ! parent_ )
|
||||||
|
{
|
||||||
|
root.add( *this );
|
||||||
|
parent_ = &root;
|
||||||
|
}
|
||||||
|
t.set_parent( *this );
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void untie()
|
||||||
|
{
|
||||||
|
parent_ = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
node* parent_;
|
||||||
};
|
};
|
||||||
|
|
||||||
boost::shared_ptr< object_impl > impl_;
|
boost::shared_ptr< object_impl > impl_;
|
||||||
|
|
|
||||||
|
|
@ -11,22 +11,27 @@
|
||||||
|
|
||||||
#include "config.hpp"
|
#include "config.hpp"
|
||||||
#include "node.hpp"
|
#include "node.hpp"
|
||||||
|
#include <boost/test/utils/trivial_singleton.hpp>
|
||||||
|
|
||||||
namespace mock
|
namespace mock
|
||||||
{
|
{
|
||||||
inline node& root()
|
class root_t : public boost::unit_test::singleton< root_t >, public node
|
||||||
{
|
{
|
||||||
static node r;
|
protected:
|
||||||
return r;
|
virtual void untie()
|
||||||
}
|
{}
|
||||||
|
private:
|
||||||
|
BOOST_TEST_SINGLETON_CONS( root_t );
|
||||||
|
};
|
||||||
|
BOOST_TEST_SINGLETON_INST( root )
|
||||||
|
|
||||||
inline bool verify()
|
inline bool verify()
|
||||||
{
|
{
|
||||||
return root().verify();
|
return root.verify();
|
||||||
}
|
}
|
||||||
inline void reset()
|
inline void reset()
|
||||||
{
|
{
|
||||||
root().reset();
|
root.reset();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,11 @@
|
||||||
#include <turtle/object.hpp>
|
#include <turtle/object.hpp>
|
||||||
#include <turtle/function.hpp>
|
#include <turtle/function.hpp>
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
mock::object static_o;
|
||||||
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE( verifying_an_empty_object_succeeds )
|
BOOST_AUTO_TEST_CASE( verifying_an_empty_object_succeeds )
|
||||||
{
|
{
|
||||||
mock::object o;
|
mock::object o;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue