cmocka  1.1.6
Unit testing library with mock support
Loading...
Searching...
No Matches
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.
 
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.
 

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");
}
void expect_string(#function, #parameter, const char *string)
Add an event to check if the parameter value is equal to the provided string.

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)
{
}
void check_expected(#parameter)
Determine whether a function parameter is correct.

For a complete example please take a look 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_always()

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.

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 integer based 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_string()
expect_memory()
expect_any()

◆ 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 integer based 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_not_string()
expect_not_memory()