Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect default return type causes segmentation fault #19

Open
asterkrans opened this issue Mar 3, 2018 · 0 comments
Open

Incorrect default return type causes segmentation fault #19

asterkrans opened this issue Mar 3, 2018 · 0 comments

Comments

@asterkrans
Copy link

asterkrans commented Mar 3, 2018

Below example is taken from the GUnit examples directory. I uncommented the EXPECT_CALL() line.

TEST(GMock, ShouldFailDueToUninterestingGetCall) {
  using namespace testing;
  StrictGMock<interface> mock;
  //EXPECT_CALL(mock, (get)())
  //    .WillOnce(Return(true));  // Comment to get an UNINTERESTING CALL
  static_cast<interface&>(mock).get();
}

GMock gives this output:

Uninteresting mock function call - returning default value.
    Function call: ()
          Returns: NULL

get() have boolean return type, so returning NULL is wrong. If I instead mock the interface the usual GMock way using MOCK_CONST_METHOD0(get, bool());, I get the expected:

Uninteresting mock function call - returning default value.
    Function call: get()
          Returns: false

Replace bool with e.g. std::string in the GUnit case, and you will get a segmentation fault when a 0 is interpreted as a std::string. (GMock will correctly return an empty string.)

Maybe the right thing to do in GUnit would be to have the default method trigger an assert instead of this non-working call to the wrong version of GMock:s default actions? It's still nicer to use GUnit even if you always have to do EXPECT_CALL() to set default return values in the tests. What is your thoughts about this?

Are there any RTTI information available for method names, that would make it possible to print the name of the stubbed method invoked?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant