Skip to content

Incorrect default return type causes segmentation fault #19

Open

Description

@asterkrans

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?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions