Unit testing library with mock support
|Check that current mocked function is being called in the expected order. More...|
|void||expect_function_calls (#function, const int times)|
|Store expected call(s) to a mock to be checked by function_called() later. More...|
|Store expected single call to a mock to be checked by function_called() later. More...|
|Expects function_called() from given mock at least once. More...|
|Ignores function_called() invocations from given mock function. More...|
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.
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():
Check that current mocked function is being called in the expected order.