cmocka
1.1.6
Unit testing library with mock support
|
Functions | |
void | expect_check (#function, #parameter, #check_function, const void *check_data) |
Add a custom parameter checking function. | |
void | expect_in_set (#function, #parameter, LargestIntegralType value_array[]) |
Add an event to check if the parameter value is part of the provided array. | |
void | expect_in_set_count (#function, #parameter, LargestIntegralType value_array[], size_t count) |
Add an event to check if the parameter value is part of the provided array. | |
void | expect_not_in_set (#function, #parameter, LargestIntegralType value_array[]) |
Add an event to check if the parameter value is not part of the provided array. | |
void | expect_not_in_set_count (#function, #parameter, LargestIntegralType value_array[], size_t count) |
Add an event to check if the parameter value is not part of the provided array. | |
void | expect_in_range (#function, #parameter, LargestIntegralType minimum, LargestIntegralType maximum) |
Add an event to check a parameter is inside a numerical range. The check would succeed if minimum <= value <= maximum. | |
void | expect_in_range_count (#function, #parameter, LargestIntegralType minimum, LargestIntegralType maximum, size_t count) |
Add an event to repeatedly check a parameter is inside a numerical range. The check would succeed if minimum <= value <= maximum. | |
void | expect_not_in_range (#function, #parameter, LargestIntegralType minimum, LargestIntegralType maximum) |
Add an event to check a parameter is outside a numerical range. The check would succeed if minimum > value > maximum. | |
void | expect_not_in_range_count (#function, #parameter, LargestIntegralType minimum, LargestIntegralType maximum, size_t count) |
Add an event to repeatedly check a parameter is outside a numerical range. The check would succeed if minimum > value > maximum. | |
void | expect_value (#function, #parameter, LargestIntegralType value) |
Add an event to check if a parameter is the given integer based value. | |
void | expect_value_count (#function, #parameter, LargestIntegralType value, size_t count) |
Add an event to repeatedly check if a parameter is the given integer based value. | |
void | expect_not_value (#function, #parameter, LargestIntegralType value) |
Add an event to check if a parameter isn't the given value. | |
void | expect_not_value_count (#function, #parameter, LargestIntegralType value, size_t count) |
Add an event to repeatedly check if a parameter isn't the given value. | |
void | expect_string (#function, #parameter, const char *string) |
Add an event to check if the parameter value is equal to the provided string. | |
void | expect_string_count (#function, #parameter, const char *string, size_t count) |
Add an event to check if the parameter value is equal to the provided string. | |
void | expect_not_string (#function, #parameter, const char *string) |
Add an event to check if the parameter value isn't equal to the provided string. | |
void | expect_not_string_count (#function, #parameter, const char *string, size_t count) |
Add an event to check if the parameter value isn't equal to the provided string. | |
void | expect_memory (#function, #parameter, void *memory, size_t size) |
Add an event to check if the parameter does match an area of memory. | |
void | expect_memory_count (#function, #parameter, void *memory, size_t size, size_t count) |
Add an event to repeatedly check if the parameter does match an area of memory. | |
void | expect_not_memory (#function, #parameter, void *memory, size_t size) |
Add an event to check if the parameter doesn't match an area of memory. | |
void | expect_not_memory_count (#function, #parameter, void *memory, size_t size, size_t count) |
Add an event to repeatedly check if the parameter doesn't match an area of memory. | |
void | expect_any (#function, #parameter) |
Add an event to check if a parameter (of any value) has been passed. | |
void | expect_any_always (#function, #parameter) |
Add an event to always check if a parameter (of any value) has been passed. | |
void | expect_any_count (#function, #parameter, size_t count) |
Add an event to repeatedly check if a parameter (of any value) has been passed. | |
void | check_expected (#parameter) |
Determine whether a function parameter is correct. | |
void | check_expected_ptr (#parameter) |
Determine whether a function parameter is correct. | |
Functionality to store expected values for mock function parameters.
In addition to storing the return values of mock functions, cmocka provides functionality to store expected values for mock function parameters using the expect_*() functions provided. A mock function parameter can then be validated using the check_expected() macro.
Successive calls to expect_*() macros for a parameter queues values to check the specified parameter. check_expected() checks a function parameter against the next value queued using expect_*(), if the parameter check fails a test failure is signalled. In addition if check_expected() is called and no more parameter values are queued a test failure occurs.
The following test stub illustrates how to do this. First is the the function we call in the test driver:
Now the chef_cook function can check if the parameter we got passed is the parameter which is expected by the test driver. This can be done the following way:
For a complete example please take a look here
void check_expected | ( | # | parameter | ) |
Determine whether a function parameter is correct.
This ensures the next value queued by one of the expect_*() macros matches the specified variable.
This function needs to be called in the mock object.
[in] | parameter | The parameter to check. |
void check_expected_ptr | ( | # | parameter | ) |
Determine whether a function parameter is correct.
This ensures the next value queued by one of the expect_*() macros matches the specified variable.
This function needs to be called in the mock object.
[in] | parameter | The pointer to check. |
void expect_any | ( | # | function, |
# | parameter | ||
) |
Add an event to check if a parameter (of any value) has been passed.
The event is triggered by calling check_expected() in the mocked function.
[in] | function | The function to add the check for. | |
[in] | parameter | The name of the parameter passed to the function. |
void expect_any_always | ( | # | function, |
# | parameter | ||
) |
Add an event to always check if a parameter (of any value) has been passed.
The event is triggered by calling check_expected() in the mocked function.
[in] | function | The function to add the check for. | |
[in] | parameter | The name of the parameter passed to the function. |
void expect_any_count | ( | # | function, |
# | parameter, | ||
size_t | count | ||
) |
Add an event to repeatedly check if a parameter (of any value) has been passed.
The event is triggered by calling check_expected() in the mocked function.
[in] | function | The function to add the check for. | |
[in] | parameter | The name of the parameter passed to the function. | |
[in] | count | The count parameter returns the number of times the value should be returned by check_expected(). If count is set to -1 the value will always be returned. |
void expect_check | ( | # | function, |
# | parameter, | ||
# | check_function, | ||
const void * | check_data | ||
) |
Add a custom parameter checking function.
If the event parameter is NULL the event structure is allocated internally by this function. If the parameter is provided it must be allocated on the heap and doesn't need to be deallocated by the caller.
[in] | function | The function to add a custom parameter checking function for. | |
[in] | parameter | The parameters passed to the function. | |
[in] | check_function | The check function to call. | |
[in] | check_data | The data to pass to the check function. |
void expect_in_range | ( | # | function, |
# | parameter, | ||
LargestIntegralType | minimum, | ||
LargestIntegralType | maximum | ||
) |
Add an event to check a parameter is inside a numerical range. The check would succeed if minimum <= value <= maximum.
The event is triggered by calling check_expected() in the mocked function.
[in] | function | The function to add the check for. | |
[in] | parameter | The name of the parameter passed to the function. | |
[in] | minimum | The lower boundary of the interval to check against. | |
[in] | maximum | The upper boundary of the interval to check against. |
void expect_in_range_count | ( | # | function, |
# | parameter, | ||
LargestIntegralType | minimum, | ||
LargestIntegralType | maximum, | ||
size_t | count | ||
) |
Add an event to repeatedly check a parameter is inside a numerical range. The check would succeed if minimum <= value <= maximum.
The event is triggered by calling check_expected() in the mocked function.
[in] | function | The function to add the check for. | |
[in] | parameter | The name of the parameter passed to the function. | |
[in] | minimum | The lower boundary of the interval to check against. | |
[in] | maximum | The upper boundary of the interval to check against. | |
[in] | count | The count parameter returns the number of times the value should be returned by check_expected(). If count is set to -1 the value will always be returned. |
void expect_in_set | ( | # | function, |
# | parameter, | ||
LargestIntegralType | value_array[] | ||
) |
Add an event to check if the parameter value is part of the provided array.
The event is triggered by calling check_expected() in the mocked function.
[in] | function | The function to add the check for. | |
[in] | parameter | The name of the parameter passed to the function. | |
[in] | value_array[] | The array to check for the value. |
void expect_in_set_count | ( | # | function, |
# | parameter, | ||
LargestIntegralType | value_array[], | ||
size_t | count | ||
) |
Add an event to check if the parameter value is part of the provided array.
The event is triggered by calling check_expected() in the mocked function.
[in] | function | The function to add the check for. | |
[in] | parameter | The name of the parameter passed to the function. | |
[in] | value_array[] | The array to check for the value. | |
[in] | count | The count parameter returns the number of times the value should be returned by check_expected(). If count is set to -1 the value will always be returned. |
void expect_memory | ( | # | function, |
# | parameter, | ||
void * | memory, | ||
size_t | size | ||
) |
Add an event to check if the parameter does match an area of memory.
The event is triggered by calling check_expected() in the mocked function.
[in] | function | The function to add the check for. | |
[in] | parameter | The name of the parameter passed to the function. | |
[in] | memory | The memory to compare. | |
[in] | size | The size of the memory to compare. |
void expect_memory_count | ( | # | function, |
# | parameter, | ||
void * | memory, | ||
size_t | size, | ||
size_t | count | ||
) |
Add an event to repeatedly check if the parameter does match an area of memory.
The event is triggered by calling check_expected() in the mocked function.
[in] | function | The function to add the check for. | |
[in] | parameter | The name of the parameter passed to the function. | |
[in] | memory | The memory to compare. | |
[in] | size | The size of the memory to compare. | |
[in] | count | The count parameter returns the number of times the value should be returned by check_expected(). If count is set to -1 the value will always be returned. |
void expect_not_in_range | ( | # | function, |
# | parameter, | ||
LargestIntegralType | minimum, | ||
LargestIntegralType | maximum | ||
) |
Add an event to check a parameter is outside a numerical range. The check would succeed if minimum > value > maximum.
The event is triggered by calling check_expected() in the mocked function.
[in] | function | The function to add the check for. | |
[in] | parameter | The name of the parameter passed to the function. | |
[in] | minimum | The lower boundary of the interval to check against. | |
[in] | maximum | The upper boundary of the interval to check against. |
void expect_not_in_range_count | ( | # | function, |
# | parameter, | ||
LargestIntegralType | minimum, | ||
LargestIntegralType | maximum, | ||
size_t | count | ||
) |
Add an event to repeatedly check a parameter is outside a numerical range. The check would succeed if minimum > value > maximum.
The event is triggered by calling check_expected() in the mocked function.
[in] | function | The function to add the check for. | |
[in] | parameter | The name of the parameter passed to the function. | |
[in] | minimum | The lower boundary of the interval to check against. | |
[in] | maximum | The upper boundary of the interval to check against. | |
[in] | count | The count parameter returns the number of times the value should be returned by check_expected(). If count is set to -1 the value will always be returned. |
void expect_not_in_set | ( | # | function, |
# | parameter, | ||
LargestIntegralType | value_array[] | ||
) |
Add an event to check if the parameter value is not part of the provided array.
The event is triggered by calling check_expected() in the mocked function.
[in] | function | The function to add the check for. | |
[in] | parameter | The name of the parameter passed to the function. | |
[in] | value_array[] | The array to check for the value. |
void expect_not_in_set_count | ( | # | function, |
# | parameter, | ||
LargestIntegralType | value_array[], | ||
size_t | count | ||
) |
Add an event to check if the parameter value is not part of the provided array.
The event is triggered by calling check_expected() in the mocked function.
[in] | function | The function to add the check for. | |
[in] | parameter | The name of the parameter passed to the function. | |
[in] | value_array[] | The array to check for the value. | |
[in] | count | The count parameter returns the number of times the value should be returned by check_expected(). If count is set to -1 the value will always be returned. |
void expect_not_memory | ( | # | function, |
# | parameter, | ||
void * | memory, | ||
size_t | size | ||
) |
Add an event to check if the parameter doesn't match an area of memory.
The event is triggered by calling check_expected() in the mocked function.
[in] | function | The function to add the check for. | |
[in] | parameter | The name of the parameter passed to the function. | |
[in] | memory | The memory to compare. | |
[in] | size | The size of the memory to compare. |
void expect_not_memory_count | ( | # | function, |
# | parameter, | ||
void * | memory, | ||
size_t | size, | ||
size_t | count | ||
) |
Add an event to repeatedly check if the parameter doesn't match an area of memory.
The event is triggered by calling check_expected() in the mocked function.
[in] | function | The function to add the check for. | |
[in] | parameter | The name of the parameter passed to the function. | |
[in] | memory | The memory to compare. | |
[in] | size | The size of the memory to compare. | |
[in] | count | The count parameter returns the number of times the value should be returned by check_expected(). If count is set to -1 the value will always be returned. |
void expect_not_string | ( | # | function, |
# | parameter, | ||
const char * | string | ||
) |
Add an event to check if the parameter value isn't equal to the provided string.
The event is triggered by calling check_expected() in the mocked function.
[in] | function | The function to add the check for. | |
[in] | parameter | The name of the parameter passed to the function. | |
[in] | string | The string value to compare. |
void expect_not_string_count | ( | # | function, |
# | parameter, | ||
const char * | string, | ||
size_t | count | ||
) |
Add an event to check if the parameter value isn't equal to the provided string.
The event is triggered by calling check_expected() in the mocked function.
[in] | function | The function to add the check for. | |
[in] | parameter | The name of the parameter passed to the function. | |
[in] | string | The string value to compare. | |
[in] | count | The count parameter returns the number of times the value should be returned by check_expected(). If count is set to -1 the value will always be returned. |
void expect_not_value | ( | # | function, |
# | parameter, | ||
LargestIntegralType | value | ||
) |
Add an event to check if a parameter isn't the given value.
The event is triggered by calling check_expected() in the mocked function.
[in] | function | The function to add the check for. | |
[in] | parameter | The name of the parameter passed to the function. | |
[in] | value | The value to check. |
void expect_not_value_count | ( | # | function, |
# | parameter, | ||
LargestIntegralType | value, | ||
size_t | count | ||
) |
Add an event to repeatedly check if a parameter isn't the given value.
The event is triggered by calling check_expected() in the mocked function.
[in] | function | The function to add the check for. | |
[in] | parameter | The name of the parameter passed to the function. | |
[in] | value | The value to check. | |
[in] | count | The count parameter returns the number of times the value should be returned by check_expected(). If count is set to -1 the value will always be returned. |
void expect_string | ( | # | function, |
# | parameter, | ||
const char * | string | ||
) |
Add an event to check if the parameter value is equal to the provided string.
The event is triggered by calling check_expected() in the mocked function.
[in] | function | The function to add the check for. | |
[in] | parameter | The name of the parameter passed to the function. | |
[in] | string | The string value to compare. |
void expect_string_count | ( | # | function, |
# | parameter, | ||
const char * | string, | ||
size_t | count | ||
) |
Add an event to check if the parameter value is equal to the provided string.
The event is triggered by calling check_expected() in the mocked function.
[in] | function | The function to add the check for. | |
[in] | parameter | The name of the parameter passed to the function. | |
[in] | string | The string value to compare. | |
[in] | count | The count parameter returns the number of times the value should be returned by check_expected(). If count is set to -1 the value will always be returned. |
void expect_value | ( | # | function, |
# | parameter, | ||
LargestIntegralType | value | ||
) |
Add an event to check if a parameter is the given integer based value.
The event is triggered by calling check_expected() in the mocked function.
[in] | function | The function to add the check for. | |
[in] | parameter | The name of the parameter passed to the function. | |
[in] | value | The value to check. |
void expect_value_count | ( | # | function, |
# | parameter, | ||
LargestIntegralType | value, | ||
size_t | count | ||
) |
Add an event to repeatedly check if a parameter is the given integer based value.
The event is triggered by calling check_expected() in the mocked function.
[in] | function | The function to add the check for. | |
[in] | parameter | The name of the parameter passed to the function. | |
[in] | value | The value to check. | |
[in] | count | The count parameter returns the number of times the value should be returned by check_expected(). If count is set to -1 the value will always be returned. |