From 068f73b0bcd731568f102fc9b070e22e0425f9af Mon Sep 17 00:00:00 2001 From: mat007 Date: Tue, 9 Jul 2013 06:58:18 +0000 Subject: [PATCH] Added support for movable only types as parameters git-svn-id: https://svn.code.sf.net/p/turtle/code/trunk@676 860be788-9bd5-4423-9f1e-828f051e677b --- build/boost/doc/changelog.qbk | 1 + test/detail/test_function.cpp | 13 +++++++++++++ turtle/config.hpp | 6 ++++++ turtle/detail/function.hpp | 1 + turtle/detail/function_template.hpp | 16 ++++++++++++++-- 5 files changed, 35 insertions(+), 2 deletions(-) diff --git a/build/boost/doc/changelog.qbk b/build/boost/doc/changelog.qbk index 50e1d63..c5a3707 100644 --- a/build/boost/doc/changelog.qbk +++ b/build/boost/doc/changelog.qbk @@ -5,6 +5,7 @@ Not yet released * Reworked MOCK_CONSTRAINT to be able to provide names to parameters * Added MOCK_NO_VARIADIC_MACROS to deactivate variadic macros support +* Added support for movable only types as parameters [endsect] diff --git a/test/detail/test_function.cpp b/test/detail/test_function.cpp index f438449..b2ca526 100644 --- a/test/detail/test_function.cpp +++ b/test/detail/test_function.cpp @@ -361,6 +361,19 @@ BOOST_FIXTURE_TEST_CASE( nullptr_can_be_used_in_place_of_null_pointers_in_constr #endif +#ifdef MOCK_SMART_PTR + +BOOST_FIXTURE_TEST_CASE( unique_ptr_is_supported_as_parameter, error_fixture ) +{ + mock::detail::function< void( std::unique_ptr< int > ) > f; + f.expect(); + std::unique_ptr< int > p( new int ); + f( std::move( p ) ); + CHECK_CALLS( 1 ); +} + +#endif // MOCK_SMART_PTR + // result handling BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_with_no_return_set_calls_missing_action, error_fixture ) diff --git a/turtle/config.hpp b/turtle/config.hpp index 173c5b9..a7e4d76 100644 --- a/turtle/config.hpp +++ b/turtle/config.hpp @@ -71,4 +71,10 @@ # endif #endif +#if !defined(BOOST_NO_CXX11_SMART_PTR) && !defined(BOOST_NO_SMART_PTR) +# ifndef MOCK_NO_SMART_PTR +# define MOCK_SMART_PTR +# endif +#endif + #endif // MOCK_CONFIG_HPP_INCLUDED diff --git a/turtle/detail/function.hpp b/turtle/detail/function.hpp index d9fea6d..96239a5 100644 --- a/turtle/detail/function.hpp +++ b/turtle/detail/function.hpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include diff --git a/turtle/detail/function_template.hpp b/turtle/detail/function_template.hpp index ac6d61a..8ce331c 100644 --- a/turtle/detail/function_template.hpp +++ b/turtle/detail/function_template.hpp @@ -8,6 +8,13 @@ #include "function_impl_template.hpp" +#define MOCK_FUNCTION_CALL(z, n, d ) \ + BOOST_PP_COMMA_IF(n) BOOST_DEDUCED_TYPENAME \ + boost::call_traits< T##n >::param_type + +#define MOCK_FUNCTION_PARAM(z, n, d) \ + MOCK_FUNCTION_CALL(z, n, d) t##n + namespace mock { namespace detail @@ -29,7 +36,8 @@ namespace detail private: typedef function_impl< - R ( BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, T) ) > impl_type; + R ( BOOST_PP_REPEAT(MOCK_NUM_ARGS, MOCK_FUNCTION_CALL, _) ) + > impl_type; typedef BOOST_DEDUCED_TYPENAME impl_type::expectation_type expectation_type; typedef BOOST_DEDUCED_TYPENAME impl_type::error_type error_type; @@ -68,7 +76,8 @@ namespace detail return impl_->expect(); } - R operator()( BOOST_PP_ENUM_BINARY_PARAMS(MOCK_NUM_ARGS, T, t) ) const + R operator()( + BOOST_PP_REPEAT(MOCK_NUM_ARGS, MOCK_FUNCTION_PARAM, _) ) const { return (*impl_)( BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, t) ); } @@ -105,3 +114,6 @@ namespace detail }; } } // mock + +#undef MOCK_FUNCTION_CALL +#undef MOCK_FUNCTION_PARAM