From c830e13c83ff8053a0c8aafd09639d92d58ba77a Mon Sep 17 00:00:00 2001 From: mat007 Date: Fri, 2 Mar 2012 22:53:48 +0000 Subject: [PATCH] Added support for mocking static methods of template classes git-svn-id: https://svn.code.sf.net/p/turtle/code/trunk@416 860be788-9bd5-4423-9f1e-828f051e677b --- src/libraries/turtle/mock.hpp | 10 ++++++---- src/tests/turtle_test/integration_test.cpp | 17 +++++++++++++++++ 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/libraries/turtle/mock.hpp b/src/libraries/turtle/mock.hpp index ed499bb..6ff37d8 100644 --- a/src/libraries/turtle/mock.hpp +++ b/src/libraries/turtle/mock.hpp @@ -152,21 +152,23 @@ namespace detail operator T() { return MOCK_ANONYMOUS_MOCKER(t)(); } \ MOCK_METHOD_EXPECTATION(T(), t) -#define MOCK_FUNCTION_STUB(F, n, S, t, s) \ +#define MOCK_FUNCTION_STUB(F, n, S, t, s, tpn) \ s mock::function< S >& t##_mocker( mock::detail::context& context, \ boost::unit_test::const_string instance ) \ { \ static mock::function< S > f; \ return f( context, instance ); \ } \ - s MOCK_DECL(F, n, S,,) \ + s MOCK_DECL(F, n, S,,tpn) \ { \ return MOCK_MOCKER(t)( BOOST_PP_ENUM_PARAMS(n, p) ); \ } #define MOCK_FUNCTION(F, n, S, t) \ - MOCK_FUNCTION_STUB(F, n, S, t,) + MOCK_FUNCTION_STUB(F, n, S, t,,) #define MOCK_STATIC_FUNCTION(F, n, S, t) \ - MOCK_FUNCTION_STUB(F, n, S, t, static) + MOCK_FUNCTION_STUB(F, n, S, t, static,) +#define MOCK_STATIC_FUNCTION_TPL(F, n, S, t) \ + MOCK_FUNCTION_STUB(F, n, S, t, static, BOOST_DEDUCED_TYPENAME) #define MOCK_EXPECT(t) MOCK_MOCKER(t).expect( __FILE__, __LINE__ ) #define MOCK_RESET(t) MOCK_MOCKER(t).reset( __FILE__, __LINE__ ) diff --git a/src/tests/turtle_test/integration_test.cpp b/src/tests/turtle_test/integration_test.cpp index 3fc4a48..6b2feac 100644 --- a/src/tests/turtle_test/integration_test.cpp +++ b/src/tests/turtle_test/integration_test.cpp @@ -478,3 +478,20 @@ BOOST_AUTO_TEST_CASE( a_static_method_can_be_mocked ) MOCK_RESET( some_class::some_static_method ); BOOST_CHECK( MOCK_VERIFY( some_class::some_static_method ) ); } + +namespace +{ + template< typename T > + struct some_template_class + { + MOCK_STATIC_FUNCTION_TPL( some_static_method, 1, float( T ), some_static_method ) + }; +} + +BOOST_AUTO_TEST_CASE( a_static_method_in_a_template_class_can_be_mocked ) +{ + MOCK_EXPECT( some_template_class< int >::some_static_method ).once(); + BOOST_CHECK( ! MOCK_VERIFY( some_template_class< int >::some_static_method ) ); + MOCK_RESET( some_template_class< int >::some_static_method ); + BOOST_CHECK( MOCK_VERIFY( some_template_class< int >::some_static_method ) ); +}