cmocka  1.1.3
Unit testing library with mock support
Functions
Checking Parameters
Collaboration diagram for Checking Parameters:

Functions

void expect_check (#function, #parameter, #check_function, const void *check_data)
 Add a custom parameter checking function. More...
 
void expect_in_set (#function, #parameter, LargestIntegralType value_array[])
 Add an event to check if the parameter value is part of the provided array. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
void expect_value (#function, #parameter, LargestIntegralType value)
 Add an event to check if a parameter is the given value. More...
 
void expect_value_count (#function, #parameter, LargestIntegralType value, size_t count)
 Add an event to repeatedly check if a parameter is the given value. More...
 
void expect_not_value (#function, #parameter, LargestIntegralType value)
 Add an event to check if a parameter isn't the given value. More...
 
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. More...
 
void expect_string (#function, #parameter, const char *string)
 Add an event to check if the parameter value is equal to the provided string. More...
 
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. More...
 
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. More...
 
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. More...
 
void expect_memory (#function, #parameter, void *memory, size_t size)
 Add an event to check if the parameter does match an area of memory. More...
 
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. More...
 
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. More...
 
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. More...
 
void expect_any (#function, #parameter)
 Add an event to check if a parameter (of any value) has been passed. More...
 
void expect_any_count (#function, #parameter, size_t count)
 Add an event to repeatedly check if a parameter (of any value) has been passed. More...
 
void check_expected (#parameter)
 Determine whether a function parameter is correct. More...
 
void check_expected_ptr (#parameter)
 Determine whether a function parameter is correct. More...
 

Detailed Description

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:

static void test_driver(void **state)
{
expect_string(chef_cook, order, "hotdog");
}

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:

int chef_cook(const char *order, char **dish_out)
{
}

For a complete example please at a look at here

Function Documentation

◆ check_expected()

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.

Parameters
[in]parameterThe parameter to check.

◆ check_expected_ptr()

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.

Parameters
[in]parameterThe pointer to check.

◆ expect_any()

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.

Parameters
[in]functionThe function to add the check for.
[in]parameterThe name of the parameter passed to the function.
See also
check_expected().

◆ expect_any_count()

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.

Parameters
[in]functionThe function to add the check for.
[in]parameterThe name of the parameter passed to the function.
[in]countThe 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.
See also
check_expected().

◆ expect_check()

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.

Parameters
[in]functionThe function to add a custom parameter checking function for.
[in]parameterThe parameters passed to the function.
[in]check_functionThe check function to call.
[in]check_dataThe data to pass to the check function.

◆ expect_in_range()

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.

Parameters
[in]functionThe function to add the check for.
[in]parameterThe name of the parameter passed to the function.
[in]minimumThe lower boundary of the interval to check against.
[in]maximumThe upper boundary of the interval to check against.
See also
check_expected().

◆ expect_in_range_count()

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.

Parameters
[in]functionThe function to add the check for.
[in]parameterThe name of the parameter passed to the function.
[in]minimumThe lower boundary of the interval to check against.
[in]maximumThe upper boundary of the interval to check against.
[in]countThe 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.
See also
check_expected().

◆ expect_in_set()

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.

Parameters
[in]functionThe function to add the check for.
[in]parameterThe name of the parameter passed to the function.
[in]value_array[]The array to check for the value.
See also
check_expected().

◆ expect_in_set_count()

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.

Parameters
[in]functionThe function to add the check for.
[in]parameterThe name of the parameter passed to the function.
[in]value_array[]The array to check for the value.
[in]countThe 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.
See also
check_expected().

◆ expect_memory()

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.

Parameters
[in]functionThe function to add the check for.
[in]parameterThe name of the parameter passed to the function.
[in]memoryThe memory to compare.
[in]sizeThe size of the memory to compare.
See also
check_expected().

◆ expect_memory_count()

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.

Parameters
[in]functionThe function to add the check for.
[in]parameterThe name of the parameter passed to the function.
[in]memoryThe memory to compare.
[in]sizeThe size of the memory to compare.
[in]countThe 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.
See also
check_expected().

◆ expect_not_in_range()

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.

Parameters
[in]functionThe function to add the check for.
[in]parameterThe name of the parameter passed to the function.
[in]minimumThe lower boundary of the interval to check against.
[in]maximumThe upper boundary of the interval to check against.
See also
check_expected().

◆ expect_not_in_range_count()

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.

Parameters
[in]functionThe function to add the check for.
[in]parameterThe name of the parameter passed to the function.
[in]minimumThe lower boundary of the interval to check against.
[in]maximumThe upper boundary of the interval to check against.
[in]countThe 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.
See also
check_expected().

◆ expect_not_in_set()

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.

Parameters
[in]functionThe function to add the check for.
[in]parameterThe name of the parameter passed to the function.
[in]value_array[]The array to check for the value.
See also
check_expected().

◆ expect_not_in_set_count()

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.

Parameters
[in]functionThe function to add the check for.
[in]parameterThe name of the parameter passed to the function.
[in]value_array[]The array to check for the value.
[in]countThe 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.
See also
check_expected().

◆ expect_not_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.

The event is triggered by calling check_expected() in the mocked function.

Parameters
[in]functionThe function to add the check for.
[in]parameterThe name of the parameter passed to the function.
[in]memoryThe memory to compare.
[in]sizeThe size of the memory to compare.
See also
check_expected().

◆ expect_not_memory_count()

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.

Parameters
[in]functionThe function to add the check for.
[in]parameterThe name of the parameter passed to the function.
[in]memoryThe memory to compare.
[in]sizeThe size of the memory to compare.
[in]countThe 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.
See also
check_expected().

◆ expect_not_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.

The event is triggered by calling check_expected() in the mocked function.

Parameters
[in]functionThe function to add the check for.
[in]parameterThe name of the parameter passed to the function.
[in]stringThe string value to compare.
See also
check_expected().

◆ expect_not_string_count()

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.

Parameters
[in]functionThe function to add the check for.
[in]parameterThe name of the parameter passed to the function.
[in]stringThe string value to compare.
[in]countThe 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.
See also
check_expected().

◆ expect_not_value()

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.

Parameters
[in]functionThe function to add the check for.
[in]parameterThe name of the parameter passed to the function.
[in]valueThe value to check.
See also
check_expected().

◆ expect_not_value_count()

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.

Parameters
[in]functionThe function to add the check for.
[in]parameterThe name of the parameter passed to the function.
[in]valueThe value to check.
[in]countThe 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.
See also
check_expected().

◆ expect_string()

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.

Parameters
[in]functionThe function to add the check for.
[in]parameterThe name of the parameter passed to the function.
[in]stringThe string value to compare.
See also
check_expected().

◆ expect_string_count()

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.

Parameters
[in]functionThe function to add the check for.
[in]parameterThe name of the parameter passed to the function.
[in]stringThe string value to compare.
[in]countThe 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.
See also
check_expected().

◆ expect_value()

void expect_value ( function,
parameter,
LargestIntegralType  value 
)

Add an event to check if a parameter is the given value.

The event is triggered by calling check_expected() in the mocked function.

Parameters
[in]functionThe function to add the check for.
[in]parameterThe name of the parameter passed to the function.
[in]valueThe value to check.
See also
check_expected().

◆ expect_value_count()

void expect_value_count ( function,
parameter,
LargestIntegralType  value,
size_t  count 
)

Add an event to repeatedly check if a parameter is the given value.

The event is triggered by calling check_expected() in the mocked function.

Parameters
[in]functionThe function to add the check for.
[in]parameterThe name of the parameter passed to the function.
[in]valueThe value to check.
[in]countThe 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.
See also
check_expected().