Merge pull request #30 from mat007/no-auto-ptr-config-option

Added MOCK_NO_AUTO_PTR to deactivate std::auto_ptr support
This commit is contained in:
Mathieu Champlon 2017-03-20 16:07:41 +01:00 committed by GitHub
commit 5e11124901
8 changed files with 29 additions and 3 deletions

View file

@ -11,6 +11,7 @@
Not yet released Not yet released
* Fixed mocking of a function returning a reference for gcc 4.1 * Fixed mocking of a function returning a reference for gcc 4.1
* Added MOCK_NO_AUTO_PTR to deactivate std::auto_ptr support
[endsect] [endsect]

View file

@ -82,4 +82,10 @@
# endif # endif
#endif #endif
#if !defined(BOOST_NO_AUTO_PTR)
# ifndef MOCK_NO_AUTO_PTR
# define MOCK_AUTO_PTR
# endif
#endif
#endif // MOCK_CONFIG_HPP_INCLUDED #endif // MOCK_CONFIG_HPP_INCLUDED

View file

@ -173,6 +173,7 @@ namespace detail
{} {}
}; };
#ifdef MOCK_AUTO_PTR
template< typename Result, typename Signature > template< typename Result, typename Signature >
class action< std::auto_ptr< Result >, Signature > class action< std::auto_ptr< Result >, Signature >
: public action_base< std::auto_ptr< Result >, Signature > : public action_base< std::auto_ptr< Result >, Signature >
@ -208,6 +209,7 @@ namespace detail
private: private:
mutable std::auto_ptr< Result > v_; mutable std::auto_ptr< Result > v_;
}; };
#endif // MOCK_AUTO_PTR
} }
} // mock } // mock

View file

@ -53,11 +53,14 @@ namespace detail
} }
} }
#ifdef MOCK_AUTO_PTR
template< typename T > template< typename T >
stream& operator<<( stream& s, const std::auto_ptr< T >& t ) stream& operator<<( stream& s, const std::auto_ptr< T >& t )
{ {
return s << mock::format( t.get() ); return s << mock::format( t.get() );
} }
#endif // MOCK_AUTO_PTR
template< typename T1, typename T2 > template< typename T1, typename T2 >
stream& operator<<( stream& s, const std::pair< T1, T2 >& p ) stream& operator<<( stream& s, const std::pair< T1, T2 >& p )
{ {

View file

@ -13,6 +13,7 @@
#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/mpl/assert.hpp> #include <boost/mpl/assert.hpp>
#include <boost/scoped_ptr.hpp>
#include <boost/function.hpp> #include <boost/function.hpp>
#include <boost/bind.hpp> #include <boost/bind.hpp>
@ -480,6 +481,8 @@ namespace
}; };
} }
#ifdef MOCK_AUTO_PTR
BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_returns_the_set_auto_ptr_value, mock_error_fixture ) BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_returns_the_set_auto_ptr_value, mock_error_fixture )
{ {
{ {
@ -535,6 +538,8 @@ BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_returns_the_set_auto_ptr_valu
} }
} }
#endif // MOCK_AUTO_PTR
#ifdef MOCK_RVALUE_REFERENCES #ifdef MOCK_RVALUE_REFERENCES
BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_moves_the_set_lvalue, mock_error_fixture ) BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_moves_the_set_lvalue, mock_error_fixture )
@ -824,7 +829,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 )
{ {
std::auto_ptr< mock::detail::function< void() > > f( new mock::detail::function< void() > ); boost::scoped_ptr< mock::detail::function< void() > > f( new 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()" );
} }
@ -844,7 +849,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 )
{ {
std::auto_ptr< mock::detail::function< void() > > f( new mock::detail::function< void() > ); boost::scoped_ptr< mock::detail::function< void() > > f( new 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

@ -387,12 +387,16 @@ BOOST_AUTO_TEST_CASE( std_pairs_are_serialized )
BOOST_CHECK_EQUAL( "(3,42)", to_string( std::make_pair( 3, 42.f ) ) ); BOOST_CHECK_EQUAL( "(3,42)", to_string( std::make_pair( 3, 42.f ) ) );
} }
#ifdef MOCK_AUTO_PTR
BOOST_AUTO_TEST_CASE( std_auto_ptr_are_serialized ) BOOST_AUTO_TEST_CASE( std_auto_ptr_are_serialized )
{ {
BOOST_CHECK_NE( "?", to_string( std::auto_ptr< int >() ) ); BOOST_CHECK_NE( "?", to_string( std::auto_ptr< int >() ) );
BOOST_CHECK_NE( "?", to_string( std::auto_ptr< int >( new int( 42 ) ) ) ); BOOST_CHECK_NE( "?", to_string( std::auto_ptr< int >( new int( 42 ) ) ) );
} }
#endif // MOCK_AUTO_PTR
BOOST_AUTO_TEST_CASE( boost_shared_ptr_are_serialized ) BOOST_AUTO_TEST_CASE( boost_shared_ptr_are_serialized )
{ {
BOOST_CHECK_NE( "?", to_string( boost::shared_ptr< int >() ) ); BOOST_CHECK_NE( "?", to_string( boost::shared_ptr< int >() ) );

View file

@ -207,6 +207,8 @@ BOOST_FIXTURE_TEST_CASE( mock_object_is_named, mock_error_fixture )
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 ) ) );
} }
#ifdef MOCK_AUTO_PTR
BOOST_FIXTURE_TEST_CASE( mock_object_auto_pointer_is_named, mock_error_fixture ) BOOST_FIXTURE_TEST_CASE( mock_object_auto_pointer_is_named, mock_error_fixture )
{ {
std::auto_ptr< my_mock > m( new my_mock ); std::auto_ptr< my_mock > m( new my_mock );
@ -225,6 +227,8 @@ BOOST_FIXTURE_TEST_CASE( mock_object_const_auto_pointer_is_named, mock_error_fix
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 ) ) );
} }
#endif // MOCK_AUTO_PTR
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 ); boost::shared_ptr< my_mock > m( new my_mock );

View file

@ -11,6 +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>
namespace namespace
{ {
@ -89,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 )
{ {
std::auto_ptr< object > o2( new object ); boost::scoped_ptr< object > o2( new 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" );