Macro
FAKE
Redirects all function calls to a mock function.
Parameters 🔗
FUNC | in | Function to be mocked. |
FAKE | in | Fake function. |
Discussion 🔗
This macro redirects function calls made to FUNC
to the fake function FAKE
. The signature of the fake function must be identical to the original function otherwise the behavior is undefined. Depending upon what compiler extensions are available and the version of the C standard being built against, Audition can error if the signatures do not match.
This function-like macro is intended to be called from the body of a test case or fixture. Invoking it elsewhere will produce a runtime error.
The implementation of the fake function can perform parameter validation and return its own return value. If the only purpose of the fake function is to return a value, then consider using STUB instead.
int foo(void); // forward declaration
static int fake_foo(void) // fake function
{
return 123; // hard-coded return value
}
/* ... */
FAKE(foo, fake_foo) // redirect foo() to fake_foo()
Fake functions are discussed in detail in Mocking with Fakes.