Skip to content

The expectation value of .withOutputParameterReturning() is changeable after the call #1219

Description

@asgeroverby

I think setting the expectation .withOutputParameterReturning() should copied the value pointed to. However, it stores the pointer and dereferences it on the actualCall().withOutputParameter().

If the call .withOutputParameterReturning() copies the given memory it would allow the memory to be changed between expect and actual calls.

The problem was encountered when trying to mock an interface where the .withOutputParameterReturning() is given a chunk of dynamically allocated memory which is free'd (and reused) before the actual call.

This is the simplest example I can come up with to reproduce the issue.

TEST(MockParameterTest, outputParameterReturningShouldCopyOnExpect)
{
    int param = 1;
    int retval = 2;

    mock().expectOneCall("function").withOutputParameterReturning("parameterName", &retval, sizeof(retval));
    retval = 7; 

    mock().actualCall("function").withOutputParameter("parameterName", &param);
    CHECK_EQUAL(param, 2); // Check fails !!!

    mock().checkExpectations();
}

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions