diff --git a/doc/changelog.qbk b/doc/changelog.qbk index d84a352..1fb51b5 100644 --- a/doc/changelog.qbk +++ b/doc/changelog.qbk @@ -11,6 +11,7 @@ Not yet released * Fixed mocking of a function returning a reference for gcc 4.1 +* Added MOCK_NO_AUTO_PTR to deactivate std::auto_ptr support [endsect] diff --git a/include/turtle/config.hpp b/include/turtle/config.hpp index 54000f6..1bd4a6b 100644 --- a/include/turtle/config.hpp +++ b/include/turtle/config.hpp @@ -82,4 +82,10 @@ # endif #endif +#if !defined(BOOST_NO_AUTO_PTR) +# ifndef MOCK_NO_AUTO_PTR +# define MOCK_AUTO_PTR +# endif +#endif + #endif // MOCK_CONFIG_HPP_INCLUDED diff --git a/include/turtle/detail/action.hpp b/include/turtle/detail/action.hpp index 92cd75e..53f830f 100644 --- a/include/turtle/detail/action.hpp +++ b/include/turtle/detail/action.hpp @@ -173,6 +173,7 @@ namespace detail {} }; +#ifdef MOCK_AUTO_PTR template< typename Result, typename Signature > class action< std::auto_ptr< Result >, Signature > : public action_base< std::auto_ptr< Result >, Signature > @@ -208,6 +209,7 @@ namespace detail private: mutable std::auto_ptr< Result > v_; }; +#endif // MOCK_AUTO_PTR } } // mock diff --git a/include/turtle/log.hpp b/include/turtle/log.hpp index 0faff6a..104c9fe 100644 --- a/include/turtle/log.hpp +++ b/include/turtle/log.hpp @@ -53,11 +53,14 @@ namespace detail } } +#ifdef MOCK_AUTO_PTR template< typename T > stream& operator<<( stream& s, const std::auto_ptr< T >& t ) { return s << mock::format( t.get() ); } +#endif // MOCK_AUTO_PTR + template< typename T1, typename T2 > stream& operator<<( stream& s, const std::pair< T1, T2 >& p ) { diff --git a/test/detail/test_function.cpp b/test/detail/test_function.cpp index d1e9808..e31235a 100644 --- a/test/detail/test_function.cpp +++ b/test/detail/test_function.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include @@ -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 ) { { @@ -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 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 ) { - 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(); 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 ) { - 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, "?()" ); 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 44fdd31..4915534 100644 --- a/test/test_log.cpp +++ b/test/test_log.cpp @@ -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 ) ) ); } +#ifdef MOCK_AUTO_PTR + 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 >( new int( 42 ) ) ) ); } +#endif // MOCK_AUTO_PTR + BOOST_AUTO_TEST_CASE( boost_shared_ptr_are_serialized ) { BOOST_CHECK_NE( "?", to_string( boost::shared_ptr< int >() ) ); diff --git a/test/test_mock.cpp b/test/test_mock.cpp index af1fb2e..98b148b 100644 --- a/test/test_mock.cpp +++ b/test/test_mock.cpp @@ -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 ) ) ); } +#ifdef MOCK_AUTO_PTR + BOOST_FIXTURE_TEST_CASE( mock_object_auto_pointer_is_named, mock_error_fixture ) { 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 ) ) ); } +#endif // MOCK_AUTO_PTR + BOOST_FIXTURE_TEST_CASE( mock_object_shared_pointer_is_named, mock_error_fixture ) { boost::shared_ptr< my_mock > m( new my_mock ); diff --git a/test/test_object.cpp b/test/test_object.cpp index e33da4b..84e1094 100644 --- a/test/test_object.cpp +++ b/test/test_object.cpp @@ -11,6 +11,7 @@ #include #include #include +#include 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 ) { - std::auto_ptr< object > o2( new object ); + boost::scoped_ptr< object > o2( new object ); const object o1( *o2 ); mock::detail::function< void() > e; mock::detail::configure( *o2, e, "instance", MOCK_TYPE_NAME(*o2), "name" );