Use std smart pointers in code

This commit is contained in:
Alexander Grund 2020-07-09 19:09:54 +02:00
parent 2f72d5639e
commit 35fa6e63e6
No known key found for this signature in database
GPG key ID: AA48A0760367A42B
15 changed files with 53 additions and 55 deletions

View file

@ -11,10 +11,10 @@
#include "../config.hpp" #include "../config.hpp"
#include <boost/noncopyable.hpp> #include <boost/noncopyable.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/bind.hpp> #include <boost/bind.hpp>
#include <boost/ref.hpp> #include <boost/ref.hpp>
#include <functional> #include <functional>
#include <memory>
#include <type_traits> #include <type_traits>
namespace mock namespace mock
@ -154,7 +154,7 @@ namespace detail
return static_cast< value_imp< Result >& >( *v_ ).t_; return static_cast< value_imp< Result >& >( *v_ ).t_;
} }
boost::shared_ptr< value > v_; std::shared_ptr< value > v_;
}; };
template< typename Signature > template< typename Signature >

View file

@ -133,9 +133,9 @@ namespace detail
{ {
public: public:
expectation() expectation()
: invocation_( boost::make_shared< unlimited >() ) : invocation_( std::make_shared< unlimited >() )
, matcher_( , matcher_(
boost::make_shared< std::make_shared<
default_matcher< default_matcher<
void( BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, T) ) void( BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, T) )
> >
@ -144,9 +144,9 @@ namespace detail
, line_( 0 ) , line_( 0 )
{} {}
expectation( const char* file, int line ) expectation( const char* file, int line )
: invocation_( boost::make_shared< unlimited >() ) : invocation_( std::make_shared< unlimited >() )
, matcher_( , matcher_(
boost::make_shared< std::make_shared<
default_matcher< default_matcher<
void( BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, T) ) void( BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, T) )
> >
@ -167,7 +167,7 @@ namespace detail
(*it)->remove( this ); (*it)->remove( this );
} }
void invoke( const boost::shared_ptr< invocation >& i ) void invoke( const std::shared_ptr< invocation >& i )
{ {
invocation_ = i; invocation_ = i;
} }
@ -253,12 +253,12 @@ namespace detail
private: private:
typedef std::vector< typedef std::vector<
boost::shared_ptr< sequence_impl > std::shared_ptr< sequence_impl >
> sequences_type; > sequences_type;
typedef sequences_type::const_iterator sequences_cit; typedef sequences_type::const_iterator sequences_cit;
boost::shared_ptr< invocation > invocation_; std::shared_ptr< invocation > invocation_;
boost::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) )
> >

View file

@ -31,7 +31,6 @@
#include <boost/test/utils/basic_cstring/basic_cstring.hpp> #include <boost/test/utils/basic_cstring/basic_cstring.hpp>
#include <boost/test/utils/lazy_ostream.hpp> #include <boost/test/utils/lazy_ostream.hpp>
#include <boost/call_traits.hpp> #include <boost/call_traits.hpp>
#include <boost/make_shared.hpp>
#include <boost/noncopyable.hpp> #include <boost/noncopyable.hpp>
#include <boost/optional.hpp> #include <boost/optional.hpp>
#include <ostream> #include <ostream>

View file

@ -36,7 +36,7 @@ namespace detail
template< typename R template< typename R
BOOST_PP_ENUM_TRAILING_PARAMS(MOCK_NUM_ARGS, typename T) > BOOST_PP_ENUM_TRAILING_PARAMS(MOCK_NUM_ARGS, typename T) >
class function_impl< R ( BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, T) ) > class function_impl< R ( BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, T) ) >
: public verifiable, public boost::enable_shared_from_this< : public verifiable, public std::enable_shared_from_this<
function_impl< R ( BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, T) )> > function_impl< R ( BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, T) )> >
{ {
public: public:
@ -47,7 +47,7 @@ namespace detail
: context_( 0 ) : context_( 0 )
, valid_( true ) , valid_( true )
, exceptions_( exceptions() ) , exceptions_( exceptions() )
, mutex_( boost::make_shared< mutex >() ) , mutex_( std::make_shared< mutex >() )
{} {}
virtual ~function_impl() virtual ~function_impl()
{ {
@ -85,7 +85,7 @@ namespace detail
{ {
lock _( mutex_ ); lock _( mutex_ );
valid_ = true; valid_ = true;
boost::shared_ptr< function_impl > guard = std::shared_ptr< function_impl > guard =
this->shared_from_this(); this->shared_from_this();
expectations_.clear(); expectations_.clear();
} }
@ -101,7 +101,7 @@ namespace detail
typedef wrapper_base< R, expectation_type > base_type; typedef wrapper_base< R, expectation_type > base_type;
public: public:
wrapper( const boost::shared_ptr< mutex >& m, expectation_type& e ) wrapper( const std::shared_ptr< mutex >& m, expectation_type& e )
: base_type( e ) : base_type( e )
, lock_( m ) , lock_( m )
{} {}
@ -119,36 +119,36 @@ namespace detail
} }
wrapper& once() wrapper& once()
{ {
this->e_->invoke( boost::make_shared< detail::once >() ); this->e_->invoke( std::make_shared< detail::once >() );
return *this; return *this;
} }
wrapper& never() wrapper& never()
{ {
this->e_->invoke( boost::make_shared< detail::never >() ); this->e_->invoke( std::make_shared< detail::never >() );
return *this; return *this;
} }
wrapper& exactly( std::size_t count ) wrapper& exactly( std::size_t count )
{ {
this->e_->invoke( this->e_->invoke(
boost::make_shared< detail::exactly >( count ) ); std::make_shared< detail::exactly >( count ) );
return *this; return *this;
} }
wrapper& at_least( std::size_t min ) wrapper& at_least( std::size_t min )
{ {
this->e_->invoke( this->e_->invoke(
boost::make_shared< detail::at_least >( min ) ); std::make_shared< detail::at_least >( min ) );
return *this; return *this;
} }
wrapper& at_most( std::size_t max ) wrapper& at_most( std::size_t max )
{ {
this->e_->invoke( this->e_->invoke(
boost::make_shared< detail::at_most >( max ) ); std::make_shared< detail::at_most >( max ) );
return *this; return *this;
} }
wrapper& between( std::size_t min, std::size_t max ) wrapper& between( std::size_t min, std::size_t max )
{ {
this->e_->invoke( this->e_->invoke(
boost::make_shared< detail::between >( min, max ) ); std::make_shared< detail::between >( min, max ) );
return *this; return *this;
} }
@ -320,7 +320,7 @@ namespace detail
context* context_; context* context_;
mutable bool valid_; mutable bool valid_;
const int exceptions_; const int exceptions_;
const boost::shared_ptr< mutex > mutex_; const std::shared_ptr< mutex > mutex_;
}; };
} }
} // mock } // mock

View file

@ -39,7 +39,7 @@ namespace detail
public: public:
function() function()
: impl_( boost::make_shared< impl_type >() ) : impl_( std::make_shared< impl_type >() )
{} {}
bool verify() const bool verify() const
@ -98,7 +98,7 @@ namespace detail
} }
private: private:
boost::shared_ptr< impl_type > impl_; std::shared_ptr< impl_type > impl_;
}; };
} }
} // mock } // mock

View file

@ -12,7 +12,7 @@
#include "../config.hpp" #include "../config.hpp"
#include "singleton.hpp" #include "singleton.hpp"
#include <boost/noncopyable.hpp> #include <boost/noncopyable.hpp>
#include <boost/shared_ptr.hpp> #include <memory>
#ifdef MOCK_THREAD_SAFE #ifdef MOCK_THREAD_SAFE
@ -38,7 +38,7 @@ namespace detail
struct lock struct lock
{ {
public: public:
lock( const boost::shared_ptr< mutex >& m ) lock( const std::shared_ptr< mutex >& m )
: m_( m ) : m_( m )
{ {
m_->lock(); m_->lock();
@ -64,7 +64,7 @@ namespace detail
} }
private: private:
boost::shared_ptr< mutex > m_; std::shared_ptr< mutex > m_;
}; };
} }
} // mock } // mock
@ -94,7 +94,7 @@ namespace detail
class lock class lock
{ {
public: public:
lock( const boost::shared_ptr< mutex >& ) lock( const std::shared_ptr< mutex >& )
{} {}
~lock() ~lock()
{} {}

View file

@ -17,8 +17,6 @@
#include "child.hpp" #include "child.hpp"
#include "mutex.hpp" #include "mutex.hpp"
#include <boost/test/utils/basic_cstring/basic_cstring.hpp> #include <boost/test/utils/basic_cstring/basic_cstring.hpp>
#include <boost/enable_shared_from_this.hpp>
#include <boost/make_shared.hpp>
#include <boost/optional.hpp> #include <boost/optional.hpp>
namespace mock namespace mock
@ -26,11 +24,11 @@ namespace mock
namespace detail namespace detail
{ {
class object_impl : public context, public verifiable, class object_impl : public context, public verifiable,
public boost::enable_shared_from_this< object_impl > public std::enable_shared_from_this< object_impl >
{ {
public: public:
object_impl() object_impl()
: mutex_( boost::make_shared< mutex >() ) : mutex_( std::make_shared< mutex >() )
{} {}
virtual void add( const void* /*p*/, verifiable& v, virtual void add( const void* /*p*/, verifiable& v,
@ -75,7 +73,7 @@ namespace detail
virtual void reset() virtual void reset()
{ {
lock _( mutex_ ); lock _( mutex_ );
boost::shared_ptr< object_impl > guard = shared_from_this(); std::shared_ptr< object_impl > guard = shared_from_this();
group_.reset(); group_.reset();
} }
@ -86,7 +84,7 @@ namespace detail
group group_; group group_;
parent parent_; parent parent_;
children_t children_; children_t children_;
const boost::shared_ptr< mutex > mutex_; const std::shared_ptr< mutex > mutex_;
}; };
} }
} // mock } // mock

View file

@ -12,8 +12,8 @@
#include "../config.hpp" #include "../config.hpp"
#include "mutex.hpp" #include "mutex.hpp"
#include <boost/noncopyable.hpp> #include <boost/noncopyable.hpp>
#include <boost/make_shared.hpp>
#include <algorithm> #include <algorithm>
#include <memory>
#include <vector> #include <vector>
namespace mock namespace mock
@ -24,7 +24,7 @@ namespace detail
{ {
public: public:
sequence_impl() sequence_impl()
: mutex_( boost::make_shared< mutex >() ) : mutex_( std::make_shared< mutex >() )
{} {}
void add( void* e ) void add( void* e )
@ -59,7 +59,7 @@ namespace detail
typedef std::vector< void* > elements_type; typedef std::vector< void* > elements_type;
elements_type elements_; elements_type elements_;
const boost::shared_ptr< mutex > mutex_; const std::shared_ptr< mutex > mutex_;
}; };
} }
} // mock } // mock

View file

@ -24,8 +24,8 @@
# define MOCK_TYPEID( t ) BOOST_SP_TYPEID(t) # define MOCK_TYPEID( t ) BOOST_SP_TYPEID(t)
# define MOCK_TYPEINFO boost::detail::sp_typeinfo # define MOCK_TYPEINFO boost::detail::sp_typeinfo
#endif #endif
#include <boost/shared_ptr.hpp>
#include <stdexcept> #include <stdexcept>
#include <memory>
#include <typeinfo> #include <typeinfo>
#include <ostream> #include <ostream>
#ifdef __GNUC__ #ifdef __GNUC__
@ -57,7 +57,7 @@ namespace detail
const char* name = info.name(); const char* name = info.name();
#ifdef __GNUC__ #ifdef __GNUC__
int status = 0; int status = 0;
boost::shared_ptr< char > demangled( std::shared_ptr< char > demangled(
abi::__cxa_demangle( name, 0, 0, &status ), abi::__cxa_demangle( name, 0, 0, &status ),
&std::free ); &std::free );
if( ! status && demangled ) if( ! status && demangled )

View file

@ -14,8 +14,8 @@
#include "detail/type_name.hpp" #include "detail/type_name.hpp"
#include "detail/object_impl.hpp" #include "detail/object_impl.hpp"
#include <boost/test/utils/basic_cstring/basic_cstring.hpp> #include <boost/test/utils/basic_cstring/basic_cstring.hpp>
#include <boost/make_shared.hpp>
#include <boost/optional.hpp> #include <boost/optional.hpp>
#include <memory>
#include <type_traits> #include <type_traits>
namespace mock namespace mock
@ -45,13 +45,13 @@ namespace detail
{ {
public: public:
object() object()
: impl_( boost::make_shared< detail::object_impl >() ) : impl_( std::make_shared< detail::object_impl >() )
{} {}
protected: protected:
~object() ~object()
{} {}
public: public:
boost::shared_ptr< detail::object_impl > impl_; std::shared_ptr< detail::object_impl > impl_;
}; };
namespace detail namespace detail

View file

@ -11,6 +11,7 @@
#include "config.hpp" #include "config.hpp"
#include "detail/sequence_impl.hpp" #include "detail/sequence_impl.hpp"
#include <memory>
namespace mock namespace mock
{ {
@ -18,10 +19,10 @@ namespace mock
{ {
public: public:
sequence() sequence()
: impl_( boost::make_shared< detail::sequence_impl >() ) : impl_( std::make_shared< detail::sequence_impl >() )
{} {}
boost::shared_ptr< detail::sequence_impl > impl_; std::shared_ptr< detail::sequence_impl > impl_;
}; };
} // mock } // mock

View file

@ -12,9 +12,9 @@
#include <turtle/constraints.hpp> #include <turtle/constraints.hpp>
#include <boost/test/auto_unit_test.hpp> #include <boost/test/auto_unit_test.hpp>
#include <boost/utility/result_of.hpp> #include <boost/utility/result_of.hpp>
#include <boost/scoped_ptr.hpp>
#include <boost/bind.hpp> #include <boost/bind.hpp>
#include <functional> #include <functional>
#include <memory>
#include <type_traits> #include <type_traits>
// static // static
@ -611,19 +611,19 @@ BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_moves_the_set_unique_ptr_rval
BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_returns_the_set_shared_ptr_value, mock_error_fixture ) BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_returns_the_set_shared_ptr_value, mock_error_fixture )
{ {
{ {
mock::detail::function< boost::shared_ptr< base >() > f; mock::detail::function< std::shared_ptr< base >() > f;
f.expect().returns( new derived ); f.expect().returns( new derived );
BOOST_CHECK_NO_THROW( f() ); BOOST_CHECK_NO_THROW( f() );
CHECK_CALLS( 1 ); CHECK_CALLS( 1 );
} }
{ {
mock::detail::function< const boost::shared_ptr< base >&() > f; mock::detail::function< const std::shared_ptr< base >&() > f;
f.expect().returns( new derived ); f.expect().returns( new derived );
BOOST_CHECK_NO_THROW( f() ); BOOST_CHECK_NO_THROW( f() );
CHECK_CALLS( 1 ); CHECK_CALLS( 1 );
} }
{ {
mock::detail::function< boost::shared_ptr< base >&() > f; mock::detail::function< std::shared_ptr< base >&() > f;
f.expect().returns( new derived ); f.expect().returns( new derived );
BOOST_CHECK_NO_THROW( f() ); BOOST_CHECK_NO_THROW( f() );
CHECK_CALLS( 1 ); CHECK_CALLS( 1 );
@ -844,7 +844,7 @@ BOOST_FIXTURE_TEST_CASE( expectation_can_be_serialized_to_be_human_readable, moc
BOOST_FIXTURE_TEST_CASE( expectation_with_remaining_untriggered_matches_upon_destruction_calls_untriggered_expectation, mock_error_fixture ) BOOST_FIXTURE_TEST_CASE( expectation_with_remaining_untriggered_matches_upon_destruction_calls_untriggered_expectation, mock_error_fixture )
{ {
boost::scoped_ptr< mock::detail::function< void() > > f( new mock::detail::function< void() > ); auto f = std::make_unique<mock::detail::function< void() >>();
f->expect().once(); f->expect().once();
CHECK_ERROR( f.reset(), "untriggered expectation", 0, "?\n. once()" ); CHECK_ERROR( f.reset(), "untriggered expectation", 0, "?\n. once()" );
} }
@ -864,7 +864,7 @@ BOOST_FIXTURE_TEST_CASE( triggering_unexpected_call_call_disables_the_automatic_
BOOST_FIXTURE_TEST_CASE( adding_an_expectation_reactivates_the_verification_upon_destruction, mock_error_fixture ) BOOST_FIXTURE_TEST_CASE( adding_an_expectation_reactivates_the_verification_upon_destruction, mock_error_fixture )
{ {
boost::scoped_ptr< mock::detail::function< void() > > f( new mock::detail::function< void() > ); auto f = std::make_unique<mock::detail::function< void() >>();
CHECK_ERROR( (*f)(), "unexpected call", 0, "?()" ); CHECK_ERROR( (*f)(), "unexpected call", 0, "?()" );
f->expect().once(); f->expect().once();
CHECK_ERROR( f.reset(), "untriggered expectation", 0, "?\n. once()" ); CHECK_ERROR( f.reset(), "untriggered expectation", 0, "?\n. once()" );

View file

@ -9,7 +9,6 @@
#include <turtle/log.hpp> #include <turtle/log.hpp>
#include <boost/test/auto_unit_test.hpp> #include <boost/test/auto_unit_test.hpp>
#include <boost/assign.hpp> #include <boost/assign.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/weak_ptr.hpp> #include <boost/weak_ptr.hpp>
#include <boost/lexical_cast.hpp> #include <boost/lexical_cast.hpp>
#include <boost/optional.hpp> #include <boost/optional.hpp>
@ -30,6 +29,7 @@
#include <deque> #include <deque>
#include <list> #include <list>
#include <map> #include <map>
#include <memory>
#include <set> #include <set>
namespace namespace

View file

@ -231,7 +231,7 @@ BOOST_FIXTURE_TEST_CASE( mock_object_const_auto_pointer_is_named, mock_error_fix
BOOST_FIXTURE_TEST_CASE( mock_object_shared_pointer_is_named, mock_error_fixture ) BOOST_FIXTURE_TEST_CASE( mock_object_shared_pointer_is_named, mock_error_fixture )
{ {
boost::shared_ptr< my_mock > m( new my_mock ); std::shared_ptr< my_mock > m( new my_mock );
BOOST_CHECK_EQUAL( "?.my_mock::my_method", to_string( MOCK_ANONYMOUS_HELPER( m->my_method ) ) ); BOOST_CHECK_EQUAL( "?.my_mock::my_method", to_string( MOCK_ANONYMOUS_HELPER( m->my_method ) ) );
BOOST_CHECK_EQUAL( "m->my_mock::my_method", to_string( MOCK_HELPER( m->my_method ) ) ); BOOST_CHECK_EQUAL( "m->my_mock::my_method", to_string( MOCK_HELPER( m->my_method ) ) );
BOOST_CHECK_EQUAL( "m->my_mock::my_method", to_string( MOCK_ANONYMOUS_HELPER( m->my_method ) ) ); BOOST_CHECK_EQUAL( "m->my_mock::my_method", to_string( MOCK_ANONYMOUS_HELPER( m->my_method ) ) );
@ -240,7 +240,7 @@ BOOST_FIXTURE_TEST_CASE( mock_object_shared_pointer_is_named, mock_error_fixture
BOOST_FIXTURE_TEST_CASE( mock_object_const_shared_pointer_is_named, mock_error_fixture ) BOOST_FIXTURE_TEST_CASE( mock_object_const_shared_pointer_is_named, mock_error_fixture )
{ {
const boost::shared_ptr< my_mock > m( new my_mock ); const std::shared_ptr< my_mock > m( new my_mock );
BOOST_CHECK_EQUAL( "?.my_mock::my_method", to_string( MOCK_ANONYMOUS_HELPER( m->my_method ) ) ); BOOST_CHECK_EQUAL( "?.my_mock::my_method", to_string( MOCK_ANONYMOUS_HELPER( m->my_method ) ) );
BOOST_CHECK_EQUAL( "m->my_mock::my_method", to_string( MOCK_HELPER( m->my_method ) ) ); BOOST_CHECK_EQUAL( "m->my_mock::my_method", to_string( MOCK_HELPER( m->my_method ) ) );
BOOST_CHECK_EQUAL( "m->my_mock::my_method", to_string( MOCK_ANONYMOUS_HELPER( m->my_method ) ) ); BOOST_CHECK_EQUAL( "m->my_mock::my_method", to_string( MOCK_ANONYMOUS_HELPER( m->my_method ) ) );

View file

@ -11,7 +11,7 @@
#include <turtle/verify.hpp> #include <turtle/verify.hpp>
#include <turtle/detail/function.hpp> #include <turtle/detail/function.hpp>
#include <boost/test/auto_unit_test.hpp> #include <boost/test/auto_unit_test.hpp>
#include <boost/scoped_ptr.hpp> #include <memory>
namespace namespace
{ {
@ -90,7 +90,7 @@ BOOST_FIXTURE_TEST_CASE( an_object_is_assignable_by_sharing_its_state, mock_erro
BOOST_FIXTURE_TEST_CASE( an_object_is_copiable_by_sharing_its_state, mock_error_fixture ) BOOST_FIXTURE_TEST_CASE( an_object_is_copiable_by_sharing_its_state, mock_error_fixture )
{ {
boost::scoped_ptr< object > o2( new object ); auto o2 = std::make_unique<object>();
const object o1( *o2 ); const object o1( *o2 );
mock::detail::function< void() > e; mock::detail::function< void() > e;
mock::detail::configure( *o2, e, "instance", MOCK_TYPE_NAME(*o2), "name" ); mock::detail::configure( *o2, e, "instance", MOCK_TYPE_NAME(*o2), "name" );