Faking global methods
|Top Previous Next|
Just like instance or static methods, you might find you want to change the behavior of global C methods.
Let's say you want to change the behavior of the global method fopen.
The FAKE_GLOBAL declaration causes fopen to return a default value (in this case a valid pointer to fake FILE* struct see Recursive Fakes), and avoid calls to the original implementation.
But what if I want to return another value?
Combined with the WHEN_CALLED declaration, with the Return command, we can also control the return value. (See Behavior Setting for additional behaviors)
Note: It's safer to use FAKE_GLOBAL as this will cover all implementations in your code. Using only WHEN_CALLED will be faster but it will only fake the current copy of the global method.
Using FAKE_GLOBAL isn't required before using WHEN_CALLED, unless Isolator++ throws an exception that FAKE_GLOBAL is required.
Copyright © Typemock Ltd. 2009-2018. All Rights Reserved.