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

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

Open
asgeroverby opened this issue Jun 3, 2019 · 0 comments · May be fixed by #1222
Open

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

asgeroverby opened this issue Jun 3, 2019 · 0 comments · May be fixed by #1222
Labels

Comments

@asgeroverby
Copy link

asgeroverby commented Jun 3, 2019

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();
}
@asgeroverby asgeroverby changed the title The value of .withOutputParameterReturning() is changeable setting the expectation Expectation value of .withOutputParameterReturning() is changeable after the call Jun 4, 2019
@asgeroverby asgeroverby changed the title Expectation value of .withOutputParameterReturning() is changeable after the call The expectation value of .withOutputParameterReturning() is changeable after the call Jun 4, 2019
asgeroverby added a commit to asgeroverby/cpputest that referenced this issue Jun 5, 2019
On expect .withOutputParameterReturning() store content of
output parameter.
@basvodde basvodde added the bug label May 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants