Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mock function with class template parameter in signature

Is it possible with gmock to mock a function which contains a class template parameter in it's signature? For example:

template <typename T>
struct Mockable
{
    virtual void do_work(const int num, const T& value) = 0;
};

template <typename T>
struct MockMockable : Mockable<T>
{
    MOCK_METHOD2(do_work, void(const int, const T&));
};
like image 355
Graeme Avatar asked Aug 13 '13 06:08

Graeme


1 Answers

I found the answer, you need to denote the mock methods specifically as template mock methods with a _T

template <typename T>
struct MockMockable : Mockable<T>
{
    MOCK_METHOD2_T(do_work, void(const int, const T&));
};

More information: https://github.com/google/googletest/blob/master/docs/gmock_cheat_sheet.md#mocking-a-class-template-mocktemplate

like image 92
Graeme Avatar answered Oct 20 '22 19:10

Graeme