Re: Mocked methods with enumerated return results in crash

949 views
Skip to first unread message

Corrin Meyer

unread,
May 23, 2013, 9:47:24 AM5/23/13
to googl...@googlegroups.com
I have also tested this with the trunk version of GMock and get the same result.

Vlad Losev

unread,
May 23, 2013, 12:20:02 PM5/23/13
to Google C++ Mocking Framework
The error message should be a clue:

Unexpected mock function call - returning default value.
    Function call: foo(NULL, 0, 0)
    The mock function has no default action set, and its return type has no default value set.

In general, you should specify the default action: what the mock should do if no expectation matches or if a matched expectation does not specify an action. Google Mock tries to provide a default action where it's safe. In methods that return values, it's returning the default value of the return type. But it's not done for enums, where the default value (0) may not even be among the values specified in the enum.

You don't specify a default action in your program, and the expectation you provide doesn't match, so its action is not used. At this point the framework doesn't know what to return from the mock call, which it considers a fatal error and aborts the program.

On Thu, May 23, 2013 at 6:47 AM, Corrin Meyer <corrin...@gmail.com> wrote:
I have also tested this with the trunk version of GMock and get the same result.

--
 
---
You received this message because you are subscribed to the Google Groups "Google C++ Mocking Framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to googlemock+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Corrin Meyer

unread,
May 23, 2013, 3:38:56 PM5/23/13
to googl...@googlegroups.com
I had not expected that to result in a fatal error and abort the program (std::runtime_error).  Once I added "testing::DefaultValue<App::Error>::Set(App::ERR_A)" everything started working again, so thank you.

It is interesting to note that that message output does not show up when running under Windows, only when running under Linux.  Even though I had run it under Ubuntu I didn't pay much attention to the message as most of my development had been under windows so I just, erroneously, glossed over the message printed.
Reply all
Reply to author
Forward
0 new messages