From 35fa6e63e6460c5853bc8ba7177f997e77d20a32 Mon Sep 17 00:00:00 2001 From: Alexander Grund Date: Thu, 9 Jul 2020 19:09:54 +0200 Subject: [PATCH] Use std smart pointers in code --- include/turtle/detail/action.hpp | 4 ++-- .../turtle/detail/expectation_template.hpp | 16 +++++++------- include/turtle/detail/function.hpp | 1 - .../turtle/detail/function_impl_template.hpp | 22 +++++++++---------- include/turtle/detail/function_template.hpp | 4 ++-- include/turtle/detail/mutex.hpp | 8 +++---- include/turtle/detail/object_impl.hpp | 10 ++++----- include/turtle/detail/sequence_impl.hpp | 6 ++--- include/turtle/detail/type_name.hpp | 4 ++-- include/turtle/object.hpp | 6 ++--- include/turtle/sequence.hpp | 5 +++-- test/detail/test_function.cpp | 12 +++++----- test/test_log.cpp | 2 +- test/test_mock.cpp | 4 ++-- test/test_object.cpp | 4 ++-- 15 files changed, 53 insertions(+), 55 deletions(-) diff --git a/include/turtle/detail/action.hpp b/include/turtle/detail/action.hpp index 74bf0b2..1984dac 100644 --- a/include/turtle/detail/action.hpp +++ b/include/turtle/detail/action.hpp @@ -11,10 +11,10 @@ #include "../config.hpp" #include -#include #include #include #include +#include #include namespace mock @@ -154,7 +154,7 @@ namespace detail return static_cast< value_imp< Result >& >( *v_ ).t_; } - boost::shared_ptr< value > v_; + std::shared_ptr< value > v_; }; template< typename Signature > diff --git a/include/turtle/detail/expectation_template.hpp b/include/turtle/detail/expectation_template.hpp index 39e8938..ef8a562 100644 --- a/include/turtle/detail/expectation_template.hpp +++ b/include/turtle/detail/expectation_template.hpp @@ -133,9 +133,9 @@ namespace detail { public: expectation() - : invocation_( boost::make_shared< unlimited >() ) + : invocation_( std::make_shared< unlimited >() ) , matcher_( - boost::make_shared< + std::make_shared< default_matcher< void( BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, T) ) > @@ -144,9 +144,9 @@ namespace detail , line_( 0 ) {} expectation( const char* file, int line ) - : invocation_( boost::make_shared< unlimited >() ) + : invocation_( std::make_shared< unlimited >() ) , matcher_( - boost::make_shared< + std::make_shared< default_matcher< void( BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, T) ) > @@ -167,7 +167,7 @@ namespace detail (*it)->remove( this ); } - void invoke( const boost::shared_ptr< invocation >& i ) + void invoke( const std::shared_ptr< invocation >& i ) { invocation_ = i; } @@ -253,12 +253,12 @@ namespace detail private: typedef std::vector< - boost::shared_ptr< sequence_impl > + std::shared_ptr< sequence_impl > > sequences_type; typedef sequences_type::const_iterator sequences_cit; - boost::shared_ptr< invocation > invocation_; - boost::shared_ptr< + std::shared_ptr< invocation > invocation_; + std::shared_ptr< matcher_base< void( BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, T) ) > diff --git a/include/turtle/detail/function.hpp b/include/turtle/detail/function.hpp index 693a506..6443d16 100644 --- a/include/turtle/detail/function.hpp +++ b/include/turtle/detail/function.hpp @@ -31,7 +31,6 @@ #include #include #include -#include #include #include #include diff --git a/include/turtle/detail/function_impl_template.hpp b/include/turtle/detail/function_impl_template.hpp index b67c124..2cf73cb 100644 --- a/include/turtle/detail/function_impl_template.hpp +++ b/include/turtle/detail/function_impl_template.hpp @@ -36,7 +36,7 @@ namespace detail template< typename R BOOST_PP_ENUM_TRAILING_PARAMS(MOCK_NUM_ARGS, typename 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) )> > { public: @@ -47,7 +47,7 @@ namespace detail : context_( 0 ) , valid_( true ) , exceptions_( exceptions() ) - , mutex_( boost::make_shared< mutex >() ) + , mutex_( std::make_shared< mutex >() ) {} virtual ~function_impl() { @@ -85,7 +85,7 @@ namespace detail { lock _( mutex_ ); valid_ = true; - boost::shared_ptr< function_impl > guard = + std::shared_ptr< function_impl > guard = this->shared_from_this(); expectations_.clear(); } @@ -101,7 +101,7 @@ namespace detail typedef wrapper_base< R, expectation_type > base_type; public: - wrapper( const boost::shared_ptr< mutex >& m, expectation_type& e ) + wrapper( const std::shared_ptr< mutex >& m, expectation_type& e ) : base_type( e ) , lock_( m ) {} @@ -119,36 +119,36 @@ namespace detail } wrapper& once() { - this->e_->invoke( boost::make_shared< detail::once >() ); + this->e_->invoke( std::make_shared< detail::once >() ); return *this; } wrapper& never() { - this->e_->invoke( boost::make_shared< detail::never >() ); + this->e_->invoke( std::make_shared< detail::never >() ); return *this; } wrapper& exactly( std::size_t count ) { this->e_->invoke( - boost::make_shared< detail::exactly >( count ) ); + std::make_shared< detail::exactly >( count ) ); return *this; } wrapper& at_least( std::size_t min ) { this->e_->invoke( - boost::make_shared< detail::at_least >( min ) ); + std::make_shared< detail::at_least >( min ) ); return *this; } wrapper& at_most( std::size_t max ) { this->e_->invoke( - boost::make_shared< detail::at_most >( max ) ); + std::make_shared< detail::at_most >( max ) ); return *this; } wrapper& between( std::size_t min, std::size_t max ) { this->e_->invoke( - boost::make_shared< detail::between >( min, max ) ); + std::make_shared< detail::between >( min, max ) ); return *this; } @@ -320,7 +320,7 @@ namespace detail context* context_; mutable bool valid_; const int exceptions_; - const boost::shared_ptr< mutex > mutex_; + const std::shared_ptr< mutex > mutex_; }; } } // mock diff --git a/include/turtle/detail/function_template.hpp b/include/turtle/detail/function_template.hpp index 6d8a01d..10183ec 100644 --- a/include/turtle/detail/function_template.hpp +++ b/include/turtle/detail/function_template.hpp @@ -39,7 +39,7 @@ namespace detail public: function() - : impl_( boost::make_shared< impl_type >() ) + : impl_( std::make_shared< impl_type >() ) {} bool verify() const @@ -98,7 +98,7 @@ namespace detail } private: - boost::shared_ptr< impl_type > impl_; + std::shared_ptr< impl_type > impl_; }; } } // mock diff --git a/include/turtle/detail/mutex.hpp b/include/turtle/detail/mutex.hpp index 3be9f02..d9f0563 100644 --- a/include/turtle/detail/mutex.hpp +++ b/include/turtle/detail/mutex.hpp @@ -12,7 +12,7 @@ #include "../config.hpp" #include "singleton.hpp" #include -#include +#include #ifdef MOCK_THREAD_SAFE @@ -38,7 +38,7 @@ namespace detail struct lock { public: - lock( const boost::shared_ptr< mutex >& m ) + lock( const std::shared_ptr< mutex >& m ) : m_( m ) { m_->lock(); @@ -64,7 +64,7 @@ namespace detail } private: - boost::shared_ptr< mutex > m_; + std::shared_ptr< mutex > m_; }; } } // mock @@ -94,7 +94,7 @@ namespace detail class lock { public: - lock( const boost::shared_ptr< mutex >& ) + lock( const std::shared_ptr< mutex >& ) {} ~lock() {} diff --git a/include/turtle/detail/object_impl.hpp b/include/turtle/detail/object_impl.hpp index 6aa215f..c411ef6 100644 --- a/include/turtle/detail/object_impl.hpp +++ b/include/turtle/detail/object_impl.hpp @@ -17,8 +17,6 @@ #include "child.hpp" #include "mutex.hpp" #include -#include -#include #include namespace mock @@ -26,11 +24,11 @@ namespace mock namespace detail { class object_impl : public context, public verifiable, - public boost::enable_shared_from_this< object_impl > + public std::enable_shared_from_this< object_impl > { public: object_impl() - : mutex_( boost::make_shared< mutex >() ) + : mutex_( std::make_shared< mutex >() ) {} virtual void add( const void* /*p*/, verifiable& v, @@ -75,7 +73,7 @@ namespace detail virtual void reset() { lock _( mutex_ ); - boost::shared_ptr< object_impl > guard = shared_from_this(); + std::shared_ptr< object_impl > guard = shared_from_this(); group_.reset(); } @@ -86,7 +84,7 @@ namespace detail group group_; parent parent_; children_t children_; - const boost::shared_ptr< mutex > mutex_; + const std::shared_ptr< mutex > mutex_; }; } } // mock diff --git a/include/turtle/detail/sequence_impl.hpp b/include/turtle/detail/sequence_impl.hpp index c7d3ce6..37db2b6 100644 --- a/include/turtle/detail/sequence_impl.hpp +++ b/include/turtle/detail/sequence_impl.hpp @@ -12,8 +12,8 @@ #include "../config.hpp" #include "mutex.hpp" #include -#include #include +#include #include namespace mock @@ -24,7 +24,7 @@ namespace detail { public: sequence_impl() - : mutex_( boost::make_shared< mutex >() ) + : mutex_( std::make_shared< mutex >() ) {} void add( void* e ) @@ -59,7 +59,7 @@ namespace detail typedef std::vector< void* > elements_type; elements_type elements_; - const boost::shared_ptr< mutex > mutex_; + const std::shared_ptr< mutex > mutex_; }; } } // mock diff --git a/include/turtle/detail/type_name.hpp b/include/turtle/detail/type_name.hpp index 8264601..e3b4df9 100644 --- a/include/turtle/detail/type_name.hpp +++ b/include/turtle/detail/type_name.hpp @@ -24,8 +24,8 @@ # define MOCK_TYPEID( t ) BOOST_SP_TYPEID(t) # define MOCK_TYPEINFO boost::detail::sp_typeinfo #endif -#include #include +#include #include #include #ifdef __GNUC__ @@ -57,7 +57,7 @@ namespace detail const char* name = info.name(); #ifdef __GNUC__ int status = 0; - boost::shared_ptr< char > demangled( + std::shared_ptr< char > demangled( abi::__cxa_demangle( name, 0, 0, &status ), &std::free ); if( ! status && demangled ) diff --git a/include/turtle/object.hpp b/include/turtle/object.hpp index 9f473cd..d9f6a47 100644 --- a/include/turtle/object.hpp +++ b/include/turtle/object.hpp @@ -14,8 +14,8 @@ #include "detail/type_name.hpp" #include "detail/object_impl.hpp" #include -#include #include +#include #include namespace mock @@ -45,13 +45,13 @@ namespace detail { public: object() - : impl_( boost::make_shared< detail::object_impl >() ) + : impl_( std::make_shared< detail::object_impl >() ) {} protected: ~object() {} public: - boost::shared_ptr< detail::object_impl > impl_; + std::shared_ptr< detail::object_impl > impl_; }; namespace detail diff --git a/include/turtle/sequence.hpp b/include/turtle/sequence.hpp index 28a2ee9..377e920 100644 --- a/include/turtle/sequence.hpp +++ b/include/turtle/sequence.hpp @@ -11,6 +11,7 @@ #include "config.hpp" #include "detail/sequence_impl.hpp" +#include namespace mock { @@ -18,10 +19,10 @@ namespace mock { public: 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 diff --git a/test/detail/test_function.cpp b/test/detail/test_function.cpp index 661482f..bf862f7 100644 --- a/test/detail/test_function.cpp +++ b/test/detail/test_function.cpp @@ -12,9 +12,9 @@ #include #include #include -#include #include #include +#include #include // 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 ) { { - mock::detail::function< boost::shared_ptr< base >() > f; + mock::detail::function< std::shared_ptr< base >() > f; f.expect().returns( new derived ); BOOST_CHECK_NO_THROW( f() ); 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 ); BOOST_CHECK_NO_THROW( f() ); CHECK_CALLS( 1 ); } { - mock::detail::function< boost::shared_ptr< base >&() > f; + mock::detail::function< std::shared_ptr< base >&() > f; f.expect().returns( new derived ); BOOST_CHECK_NO_THROW( f() ); 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::scoped_ptr< mock::detail::function< void() > > f( new mock::detail::function< void() > ); + auto f = std::make_unique>(); f->expect().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::scoped_ptr< mock::detail::function< void() > > f( new mock::detail::function< void() > ); + auto f = std::make_unique>(); CHECK_ERROR( (*f)(), "unexpected call", 0, "?()" ); f->expect().once(); CHECK_ERROR( f.reset(), "untriggered expectation", 0, "?\n. once()" ); diff --git a/test/test_log.cpp b/test/test_log.cpp index b624734..9fad50b 100644 --- a/test/test_log.cpp +++ b/test/test_log.cpp @@ -9,7 +9,6 @@ #include #include #include -#include #include #include #include @@ -30,6 +29,7 @@ #include #include #include +#include #include namespace diff --git a/test/test_mock.cpp b/test/test_mock.cpp index d73a932..66ae929 100644 --- a/test/test_mock.cpp +++ b/test/test_mock.cpp @@ -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::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( "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 ) ) ); @@ -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 ) { - 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( "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 ) ) ); diff --git a/test/test_object.cpp b/test/test_object.cpp index 84e1094..a2c45de 100644 --- a/test/test_object.cpp +++ b/test/test_object.cpp @@ -11,7 +11,7 @@ #include #include #include -#include +#include 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::scoped_ptr< object > o2( new object ); + auto o2 = std::make_unique(); const object o1( *o2 ); mock::detail::function< void() > e; mock::detail::configure( *o2, e, "instance", MOCK_TYPE_NAME(*o2), "name" );