Mocking a method with a throw() specifier

749 views
Skip to first unread message

J R

unread,
Feb 24, 2011, 2:25:52 PM2/24/11
to Google C++ Mocking Framework
I am trying to Google mock a virtual method which has a throw()
specifier. The original function looks like this:

virtual ReturnValue FunctionName() const throw();
I am getting the compiler error: looser throw specifier for 'virtual
FunctionSignature' when I try to mock it.

Here is the code I have tried thus far:

MOCK_CONST_METHOD0( FunctionName, ReturnValue() );
MOCK_CONST_METHOD0( FunctionName, ReturnValue() throw() );
MOCK_CONST_METHOD0( FunctionName, ReturnValue() ) throw(); // Gives a
different error entirely.

I've tried just about every other combination I can think of, but
these are the ones which seem most logical. How do I go about mocking
a method with a throw() specifier?

Zhanyong Wan (λx.x x)

unread,
Feb 24, 2011, 3:08:49 PM2/24/11
to J R, Google C++ Mocking Framework
It's not supported currently. See
http://code.google.com/p/googlemock/issues/detail?id=122

--
Zhanyong

J R

unread,
Mar 2, 2011, 12:17:19 PM3/2/11
to Google C++ Mocking Framework
My solution: create an implementation of the virtual function which
consists solely of passing through to a mocked method.

MOCK_CONST_METHOD0( MockFunctionName, ReturnValue() );
virtual ReturnValue FunctionName() const throw()
{
return MockFunctionName();
}

Then, whenever you need to write an Expect_Call or do anything for
that method, just refer to MockFunctionName.

On Feb 24, 2:08 pm, Zhanyong Wan (λx.x x) <w...@google.com> wrote:
> It's not supported currently.  Seehttp://code.google.com/p/googlemock/issues/detail?id=122
Reply all
Reply to author
Forward
0 new messages