OpenVPN
Macros
Checking Parameters

Functionality to store expected values for mock function parameters. More...

Collaboration diagram for Checking Parameters:

Macros

#define expect_check(function, parameter, check_function, check_data)
 
#define expect_in_set(function, parameter, value_array)   expect_in_set_count(function, parameter, value_array, 1)
 
#define expect_in_set_count(function, parameter, value_array, count)
 
#define expect_not_in_set(function, parameter, value_array)   expect_not_in_set_count(function, parameter, value_array, 1)
 
#define expect_not_in_set_count(function, parameter, value_array, count)
 
#define expect_in_range(function, parameter, minimum, maximum)   expect_in_range_count(function, parameter, minimum, maximum, 1)
 
#define expect_in_range_count(function, parameter, minimum, maximum, count)
 
#define expect_not_in_range(function, parameter, minimum, maximum)   expect_not_in_range_count(function, parameter, minimum, maximum, 1)
 
#define expect_not_in_range_count(function, parameter, minimum, maximum, count)
 
#define expect_value(function, parameter, value)   expect_value_count(function, parameter, value, 1)
 
#define expect_value_count(function, parameter, value, count)
 
#define expect_not_value(function, parameter, value)   expect_not_value_count(function, parameter, value, 1)
 
#define expect_not_value_count(function, parameter, value, count)
 
#define expect_string(function, parameter, string)   expect_string_count(function, parameter, string, 1)
 
#define expect_string_count(function, parameter, string, count)
 
#define expect_not_string(function, parameter, string)   expect_not_string_count(function, parameter, string, 1)
 
#define expect_not_string_count(function, parameter, string, count)
 
#define expect_memory(function, parameter, memory, size)   expect_memory_count(function, parameter, memory, size, 1)
 
#define expect_memory_count(function, parameter, memory, size, count)
 
#define expect_not_memory(function, parameter, memory, size)   expect_not_memory_count(function, parameter, memory, size, 1)
 
#define expect_not_memory_count(function, parameter, memory, size, count)
 
#define expect_any(function, parameter)   expect_any_count(function, parameter, 1)
 
#define expect_any_count(function, parameter, count)   _expect_any(#function, #parameter, __FILE__, __LINE__, count)
 
#define check_expected(parameter)
 
#define check_expected_ptr(parameter)
 

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

Macro Definition Documentation

◆ check_expected

#define check_expected (   parameter)
Value:
_check_expected(__func__, #parameter, __FILE__, __LINE__, \
#define cast_to_largest_integral_type(value)
Definition: cmocka.h:96
void _check_expected(const char *const function_name, const char *const parameter_name, const char *file, const int line, const LargestIntegralType value)
Definition: cmocka.c:1475

Definition at line 986 of file cmocka.h.

Referenced by __wrap_buffer_read_from_file(), __wrap_buffer_write_file(), binary_operator(), and connect_to_database().

◆ check_expected_ptr

#define check_expected_ptr (   parameter)
Value:
_check_expected(__func__, #parameter, __FILE__, __LINE__, \
#define cast_ptr_to_largest_integral_type(value)
Definition: cmocka.h:133
void _check_expected(const char *const function_name, const char *const parameter_name, const char *file, const int line, const LargestIntegralType value)
Definition: cmocka.c:1475

Definition at line 1004 of file cmocka.h.

Referenced by __wrap_chef_cook(), connect_to_database(), example_test_fprintf(), and example_test_printf().

◆ expect_any

#define expect_any (   function,
  parameter 
)    expect_any_count(function, parameter, 1)

Definition at line 946 of file cmocka.h.

◆ expect_any_count

#define expect_any_count (   function,
  parameter,
  count 
)    _expect_any(#function, #parameter, __FILE__, __LINE__, count)

Definition at line 969 of file cmocka.h.

◆ expect_check

#define expect_check (   function,
  parameter,
  check_function,
  check_data 
)
Value:
_expect_check(#function, #parameter, __FILE__, __LINE__, check_function, \
cast_to_largest_integral_type(check_data), NULL, 1)
#define cast_to_largest_integral_type(value)
Definition: cmocka.h:96
void _expect_check(const char *const function, const char *const parameter, const char *const file, const int line, const CheckParameterValue check_function, const LargestIntegralType check_data, CheckParameterEvent *const event, const int count)
Definition: cmocka.c:962

Definition at line 442 of file cmocka.h.

◆ expect_in_range

#define expect_in_range (   function,
  parameter,
  minimum,
  maximum 
)    expect_in_range_count(function, parameter, minimum, maximum, 1)

Definition at line 562 of file cmocka.h.

◆ expect_in_range_count

#define expect_in_range_count (   function,
  parameter,
  minimum,
  maximum,
  count 
)
Value:
_expect_in_range(#function, #parameter, __FILE__, __LINE__, minimum, \
maximum, count)
void _expect_in_range(const char *const function, const char *const parameter, const char *const file, const int line, const LargestIntegralType minimum, const LargestIntegralType maximum, const int count)
Definition: cmocka.c:1290

Definition at line 589 of file cmocka.h.

◆ expect_in_set

#define expect_in_set (   function,
  parameter,
  value_array 
)    expect_in_set_count(function, parameter, value_array, 1)

Definition at line 464 of file cmocka.h.

◆ expect_in_set_count

#define expect_in_set_count (   function,
  parameter,
  value_array,
  count 
)
Value:
_expect_in_set(#function, #parameter, __FILE__, __LINE__, value_array, \
sizeof(value_array) / sizeof((value_array)[0]), count)
void _expect_in_set(const char *const function, const char *const parameter, const char *const file, const int line, const LargestIntegralType values[], const size_t number_of_values, const int count)
Definition: cmocka.c:1227

Definition at line 489 of file cmocka.h.

◆ expect_memory

#define expect_memory (   function,
  parameter,
  memory,
  size 
)    expect_memory_count(function, parameter, memory, size, 1)

◆ expect_memory_count

#define expect_memory_count (   function,
  parameter,
  memory,
  size,
  count 
)
Value:
_expect_memory(#function, #parameter, __FILE__, __LINE__, \
(const void*)(memory), size, count)
void _expect_memory(const char *const function, const char *const parameter, const char *const file, const int line, const void *const memory, const size_t size, const int count)
Definition: cmocka.c:1424

Definition at line 875 of file cmocka.h.

◆ expect_not_in_range

#define expect_not_in_range (   function,
  parameter,
  minimum,
  maximum 
)    expect_not_in_range_count(function, parameter, minimum, maximum, 1)

Definition at line 613 of file cmocka.h.

◆ expect_not_in_range_count

#define expect_not_in_range_count (   function,
  parameter,
  minimum,
  maximum,
  count 
)
Value:
_expect_not_in_range(#function, #parameter, __FILE__, __LINE__, \
minimum, maximum, count)
void _expect_not_in_range(const char *const function, const char *const parameter, const char *const file, const int line, const LargestIntegralType minimum, const LargestIntegralType maximum, const int count)
Definition: cmocka.c:1301

Definition at line 640 of file cmocka.h.

◆ expect_not_in_set

#define expect_not_in_set (   function,
  parameter,
  value_array 
)    expect_not_in_set_count(function, parameter, value_array, 1)

Definition at line 511 of file cmocka.h.

◆ expect_not_in_set_count

#define expect_not_in_set_count (   function,
  parameter,
  value_array,
  count 
)
Value:
#function, #parameter, __FILE__, __LINE__, value_array, \
sizeof(value_array) / sizeof((value_array)[0]), count)
void _expect_not_in_set(const char *const function, const char *const parameter, const char *const file, const int line, const LargestIntegralType values[], const size_t number_of_values, const int count)
Definition: cmocka.c:1238

Definition at line 536 of file cmocka.h.

◆ expect_not_memory

#define expect_not_memory (   function,
  parameter,
  memory,
  size 
)    expect_not_memory_count(function, parameter, memory, size, 1)

Definition at line 899 of file cmocka.h.

◆ expect_not_memory_count

#define expect_not_memory_count (   function,
  parameter,
  memory,
  size,
  count 
)
Value:
_expect_not_memory(#function, #parameter, __FILE__, __LINE__, \
(const void*)(memory), size, count)
void _expect_not_memory(const char *const function, const char *const parameter, const char *const file, const int line, const void *const memory, const size_t size, const int count)
Definition: cmocka.c:1448

Definition at line 926 of file cmocka.h.

◆ expect_not_string

#define expect_not_string (   function,
  parameter,
  string 
)    expect_not_string_count(function, parameter, string, 1)

Definition at line 800 of file cmocka.h.

◆ expect_not_string_count

#define expect_not_string_count (   function,
  parameter,
  string,
  count 
)
Value:
_expect_not_string(#function, #parameter, __FILE__, __LINE__, \
(const char*)(string), count)
void _expect_not_string(const char *const function, const char *const parameter, const char *const file, const int line, const char *string, const int count)
Definition: cmocka.c:1379

Definition at line 825 of file cmocka.h.

◆ expect_not_value

#define expect_not_value (   function,
  parameter,
  value 
)    expect_not_value_count(function, parameter, value, 1)

Definition at line 707 of file cmocka.h.

◆ expect_not_value_count

#define expect_not_value_count (   function,
  parameter,
  value,
  count 
)
Value:
_expect_not_value(#function, #parameter, __FILE__, __LINE__, \
#define cast_to_largest_integral_type(value)
Definition: cmocka.h:96
void _expect_not_value(const char *const function, const char *const parameter, const char *const file, const int line, const LargestIntegralType value, const int count)
Definition: cmocka.c:1338

Definition at line 731 of file cmocka.h.

◆ expect_string

#define expect_string (   function,
  parameter,
  string 
)    expect_string_count(function, parameter, string, 1)

◆ expect_string_count

#define expect_string_count (   function,
  parameter,
  string,
  count 
)
Value:
_expect_string(#function, #parameter, __FILE__, __LINE__, \
(const char*)(string), count)
void _expect_string(const char *const function, const char *const parameter, const char *const file, const int line, const char *string, const int count)
Definition: cmocka.c:1357

Definition at line 778 of file cmocka.h.

◆ expect_value

#define expect_value (   function,
  parameter,
  value 
)    expect_value_count(function, parameter, value, 1)

◆ expect_value_count

#define expect_value_count (   function,
  parameter,
  value,
  count 
)
Value:
_expect_value(#function, #parameter, __FILE__, __LINE__, \
#define cast_to_largest_integral_type(value)
Definition: cmocka.h:96
void _expect_value(const char *const function, const char *const parameter, const char *const file, const int line, const LargestIntegralType value, const int count)
Definition: cmocka.c:1320

Definition at line 686 of file cmocka.h.