Removed all copies of the wrapper object

This commit is contained in:
Thomas Bernard 2016-01-16 01:19:43 +01:00
parent 4eadca553b
commit 04497bd5b5
6 changed files with 54 additions and 18 deletions

View file

@ -135,7 +135,7 @@ namespace detail
, file_( "unknown location" )
, line_( 0 )
#if defined(MOCK_THREAD_SAFE)
, blocked(ATOMIC_VAR_INIT(false))
, blocked(false)
#endif
{ }
expectation( const char* file, int line )
@ -149,7 +149,17 @@ namespace detail
, file_( file )
, line_( line )
#if defined(MOCK_THREAD_SAFE)
, blocked(ATOMIC_VAR_INIT(false))
, blocked(false)
#endif
{ }
expectation(expectation && e)
: invocation_ ( e.invocation_)
, matcher_(e.matcher_)
, file_(e.file_)
, line_(e.line_)
#if defined(MOCK_THREAD_SAFE)
, blocked(false)
#endif
{}
@ -197,7 +207,7 @@ namespace detail
expectation &async(const duration timeout)
{
timeout_ = timeout;
blocked = false;
blocked.store(false,std::memory_order_release);
return *this;
}
#endif
@ -220,7 +230,7 @@ namespace detail
{
if (MOCK_THREAD_NAMESPACE::cv_status::timeout == cv->wait_for(lk.get_unique_lock(), *timeout_))
{
std::atomic_store(&blocked,true);
blocked.store(true, std::memory_order_release);
return false;
}
}
@ -232,7 +242,7 @@ namespace detail
BOOST_PP_ENUM_BINARY_PARAMS(MOCK_NUM_ARGS, T, a) ) const
{
#if defined(MOCK_THREAD_SAFE)
return !blocked && !invocation_->exhausted()
return !blocked.load(std::memory_order_acquire) && !invocation_->exhausted()
&& (*matcher_)( BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, a) );
#else
return !invocation_->exhausted()
@ -294,7 +304,7 @@ namespace detail
int line_;
#if defined(MOCK_THREAD_SAFE)
boost::optional<nanoseconds> timeout_;
mutable std::atomic_bool blocked;
mutable std::atomic<bool> blocked;
#endif
};
}

View file

@ -49,6 +49,10 @@ namespace detail
: e_( &e )
{}
wrapper_base( wrapper_base && w )
: e_( w.e_ )
{}
template< typename T >
void returns( T t )
{
@ -64,6 +68,11 @@ namespace detail
: e_( &e )
{}
wrapper_base( wrapper_base && w )
: e_( w.e_ )
{}
E* e_;
};
template< typename R, typename E >
@ -73,6 +82,10 @@ namespace detail
: e_( &e )
{}
wrapper_base( wrapper_base && w )
: e_( w.e_ )
{}
void returns( R* r )
{
e_->returns( r );

View file

@ -115,6 +115,13 @@ namespace detail
wrapper(const wrapper &) = delete;
wrapper( wrapper && w)
: wrapper_base< R, expectation_type > (*w.e_)
, lock_( std::move(w.lock_) )
{
}
wrapper &once()
{
this->e_->invoke( boost::make_shared< detail::once >() );

View file

@ -48,6 +48,12 @@ namespace detail
: lock_base (*m)
, m_(m)
{}
lock(lock && l)
: lock_base(*l.m_)
, m_(l.m_)
{
}
~lock()
{
unlock();

View file

@ -29,7 +29,7 @@ namespace
BOOST_FIXTURE_TEST_CASE( mock_object_asynchonous_call_expectation, mock_error_fixture )
{
#if defined(MOCK_THREAD_SAFE)
const mock_class m;
const mock_class m{};
MOCK_EXPECT( m.my_tag ).async(MOCK_THREAD_NAMESPACE::chrono::milliseconds(50)).once().with( "some parameter" );
MOCK_THREAD_NAMESPACE::thread context([&](){
MOCK_THREAD_NAMESPACE::this_thread::sleep_for(MOCK_THREAD_NAMESPACE::chrono::milliseconds(10));
@ -45,7 +45,7 @@ BOOST_FIXTURE_TEST_CASE( mock_object_asynchonous_call_expectation, mock_error_fi
BOOST_AUTO_TEST_CASE( mock_object_asynchonous_call_expectation_fails )
{
#if defined(MOCK_THREAD_SAFE)
const mock_class m;
const mock_class m{};
bool unexpected_call_received = false;
MOCK_EXPECT( m.my_tag ).async(MOCK_THREAD_NAMESPACE::chrono::milliseconds(50)).once().with( "some parameter" );
MOCK_THREAD_NAMESPACE::thread context([&](){

View file

@ -128,7 +128,7 @@ BOOST_FIXTURE_TEST_CASE( mock_object_method_const_disambiguation, mock_error_fix
my_const_ambiguited_mock mock;
MOCK_EXPECT( mock.tag1 );
BOOST_CHECK_NO_THROW( mock.my_method() );
const my_const_ambiguited_mock const_mock;
const my_const_ambiguited_mock const_mock{};
CHECK_ERROR( const_mock.my_method(), "unexpected call", 1, "?.my_const_ambiguited_mock::tag_2()" );
}