cmocka
1.1.6
Unit testing library with mock support
|
Functions | |
void | function_called (void) |
Check that current mocked function is being called in the expected order. | |
void | expect_function_calls (#function, const int times) |
Store expected call(s) to a mock to be checked by function_called() later. | |
void | expect_function_call (#function) |
Store expected single call to a mock to be checked by function_called() later. | |
void | expect_function_call_any (#function) |
Expects function_called() from given mock at least once. | |
void | ignore_function_calls (#function) |
Ignores function_called() invocations from given mock function. | |
It is often beneficial to make sure that functions are called in an order. This is independent of mock returns and parameter checking as both of the aforementioned do not check the order in which they are called from different functions.
expect_function_call(function) - The expect_function_call() macro pushes an expectation onto the stack of expected calls.
expect_function_call() and function_called() are intended to be used in pairs. Cmocka will fail a test if there are more or less expected calls created (e.g. expect_function_call()) than consumed with function_called(). There are provisions such as ignore_function_calls() which allow this restriction to be circumvented in tests where mock calls for the code under test are not the focus of the test. function_called() must be called from the same thread as expect_function_call(), and that thread must have been initialized for use by cmocka (see also the Threading section of the main documentation page).
The following example illustrates how a unit test instructs cmocka to expect a function_called() from a particular mock, chef_sing():
The implementation of the mock then must check whether it was meant to be called by invoking function_called():
void expect_function_call | ( | # | function | ) |
Store expected single call to a mock to be checked by function_called() later.
[in] | function | The function which should should be called |
void expect_function_call_any | ( | # | function | ) |
Expects function_called() from given mock at least once.
[in] | function | The function which should should be called |
void expect_function_calls | ( | # | function, |
const int | times | ||
) |
Store expected call(s) to a mock to be checked by function_called() later.
[in] | function | The function which should should be called | |
[in] | times | number of times this mock must be called |
void function_called | ( | void | ) |
Check that current mocked function is being called in the expected order.
void ignore_function_calls | ( | # | function | ) |
Ignores function_called() invocations from given mock function.
[in] | function | The function which should should be called |