Mock function with class template parameter in signature

Is it possible with gmock to make fun of a function that contains a class template parameter in it? For instance:

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&)); }; 
+9
source share
1 answer

I found the answer, you need to designate layout methods, in particular, as layout templates using _T

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

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

+18
source

Source: https://habr.com/ru/post/1496718/


All Articles