I am trying to mock out some code that returns information by writing to one of the references passed to the function as a parameter. Is there a good way to mock this behavior such that I can have the test code determine what value is written to that variable?
Google Mock functions changing value of parameter
Asked Answered
ON_CALL - WillByDefault - Invoke, and delegate? –
Santos
groups.google.com/forum/embed/#!topic/googlemock/dtM0M_cTJik if this is what you are referring to –
Plotter
I did a little research and it turns out that GMock has a couple of nice options. From the Google Mock Cheat Sheet
SetArgReferee<N>(value)
SetArgPointee<N>(value)
"Assign value to the variable referenced by the N-th (0-based) argument" and "Assign value to the variable pointed by the N-th (0-based) argument" respectively.
Updated link to cheat sheet: google.github.io/googletest/gmock_cheat_sheet.html –
Tinct
You have quite a few options. SetArgReferee(value) and SetArgPointee(value), as Daniel pointed out in 2015.
Then there's SetArrayArgument(first, last) for arrays.
Or you can use Invoke capabilities to invoke your own functions and do what you want: Invoke, InvokeWithoutArgs, InvokeWithoutArgs, InvokeArgument.
Read their descriptions in the Side Effects and Invoke sections on the Googlemock's cheat sheet page.
© 2022 - 2024 — McMap. All rights reserved.