Faking reference parameters
|Top Previous Next|
In order to fake an out parameter (a value returned from the method, but passed as a parameter), use the RET macro.
Let's look at our introductory example. Let's look at our Product class' method IsExpired:
GetSystemTime is a void method, that returns its result through the supplied parameter now. In its regular implementation it returns as a reference the current time. What we want is to fake the method, and return our custom value instead.
Let's look how we use the RET macro inside WhenCalled to do just that:
Because it's a global method, we use FAKE_GLOBAL, but it's the same use for a static or an instance call. Following that, we're using WHEN_CALLED to ignore the call to GetSystemTime (and not run the regular implementation), and using the RET macro, supply our custom return value.
When GetSystemTime is called, it just returns fakeTime, and the IsExpired returns true.
RET is support with private methods as well, for example
In some cases Isolator is not able to figure out allocation size of an argument, if it's an array, for example. In this case you need to pass a size of an argument in the RET macro:
Note: Use a pointer to the value to RET or use BY_REF
Copyright Typemock Ltd. 2009-2020. All Rights Reserved.