|
cmocka 2.0.1
Unit testing library with mock support
|
Ensure functions are called in the correct sequence. More...
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. | |
Ensure functions are called in the correct sequence.
Verify that functions are called in the expected order.
This module provides functionality to ensure functions are called in a specific sequence, independent of mock return values and parameter checking. Both of the aforementioned do not verify the order in which functions are called.
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 |