mocking a template function

1,150 views
Skip to first unread message

Paul Hansen

unread,
Feb 7, 2012, 4:41:32 PM2/7/12
to Google C++ Mocking Framework
Hi
The cookbook has an example of how to mock a template class.
But how do I mock a template function that is part of a normal class?
Thanks
Paul

Vlad Losev

unread,
Feb 7, 2012, 8:27:59 PM2/7/12
to Google C++ Mocking Framework
How about a combined approach - write a template class that delegates to the template method of the original class?

Paul Hansen

unread,
Feb 8, 2012, 11:50:29 AM2/8/12
to Google C++ Mocking Framework
Thank you for your response.
However, I think your suggestion implies changes to the production
code class.
I have some production code that I cannot change:
class C
{ public:
void Func(void) { ... }
template <class T> T* TFunc() { ...; return pT; }
};
The above class I don't have to test. But I have to test some code
that uses this class. So I want to make a class C stub. I tried:
class C
{ public:
MOCK_METHOD0(Func, void());
template <class T>
MOCK_METHOD0_T(TFunc, T*());
};
but it does not work.

Probably I will have to copy the original template function into my
stub.

Cheers, Paul

On Feb 8, 2:27 am, Vlad Losev <v...@losev.com> wrote:
> How about a combined approach - write a template class that delegates to
> the template method of the original class?
>
Reply all
Reply to author
Forward
0 new messages