mirror of
https://github.com/mat007/turtle.git
synced 2026-06-22 12:13:43 +00:00
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
This commit is contained in:
parent
a1d2f27add
commit
c830e13c83
2 changed files with 23 additions and 4 deletions
|
|
@ -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__ )
|
||||
|
|
|
|||
|
|
@ -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 ) );
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue