Loading...
Searching...
No Matches
🎪 Mock Objects
📚 The CMocka API

Simulate objects and control function return values in tests. More...

## Macros

#define | WILL_RETURN_ALWAYS -1
| Return a value indefinitely when used with will_return_count().
#define | WILL_RETURN_ONCE -2
| Return a value once when used with will_return_count().
#define | EXPECT_ALWAYS -1
| Check a parameter every time when used with expect_check_data_count().
#define | EXPECT_MAYBE -2
| Optionally check a parameter when used with expect_check_data_count().

## Functions

uintmax_t | mock (void)
| Retrieve a return value of the current function.
type | mock_type (#type)
| Retrieve a value of the current function and cast it to given type.
bool | has_mock (void)
| Check if data is available for the current mock function.
intmax_t | mock_int ()
| Retrieve an integer return value of the current function.
uintmax_t | mock_uint (void)
| Retrieve an unsigned integer return value of the current function.
float | mock_float (void)
| Retrieve a float return value of the current function.
double | mock_double (void)
| Retrieve a double precision floating point return value of the current function.
type | mock_ptr_type (#type)
| Retrieve a typed return value of the current function.
type | mock_ptr_type_checked (#type)
| Retrieve a typed return value of the current function with type checking.
uintmax_t | mock_parameter (#name)
| Retrieve a named value for the current function.
intmax_t | mock_parameter_int (#name)
| Retrieve a named value for the current function and cast it to given type.
uintmax_t | mock_parameter_uint (#name)
| Retrieve an unsigned integer return value of the current function.
float | mock_parameter_float (#name)
| Retrieve a named float value for the current function.
double | mock_parameter_double (#name)
| Retrieve a named double precision floating point value for the current function.
void * | mock_parameter_ptr (#name)
| Retrieve a named pointer for the current function.
type | mock_parameter_ptr_type (#name, #type)
| Retrieve a named pointer for the current function.
void | mock_errno (void)
| set errno for the current function.
void | will_return (#function, uintmax_t value)
| Store a value to be returned by mock() later.
void | will_return_int (#function, intmax_t value)
| Store an integer value to be returned by mock() later.
void | will_return_int_count (#function, intmax_t value, int count)
| Store an integer value to be returned a specified number of times by mock() later.
void | will_return_uint (#function, uintmax_t value)
| Store a unsigned integer value to be returned by mock() later.
void | will_return_uint_count (#function, uintmax_t value, int count)
| Store an unsigned integer value to be returned a specified number of times by mock() later.
void | will_return_float (#function, float value)
| Store a float value to be returned by mock() later.
void | will_return_float_count (#function, float value, int count)
| Store a float value to be returned a specified number of times by mock() later.
void | will_return_double (#function, double value)
| Store a double precision floating point value to be returned by mock() later.
void | will_return_double_count (#function, double value, int count)
| Store a double precision floating point value to be returned a specified number of times by mock() later.
void | will_return_int_always (#function, intmax_t value)
| Store an integer value that will always be returned by mock_int().
void | will_return_uint_always (#function, uintmax_t value)
| Store an unsigned integer value that will always be returned by mock_uint().
void | will_return_float_always (#function, float value)
| Store a float value that will always be returned by mock_float().
void | will_return_double_always (#function, double value)
| Store a double value that will always be returned by mock_double().
void | will_return_count (#function, uintmax_t value, int count)
void | will_return_always (#function, uintmax_t value)
void | will_return_int_maybe (#function, intmax_t value)
| Store an integer value that may always be returned by mock_int().
void | will_return_uint_maybe (#function, uintmax_t value)
| Store an unsigned integer value that may always be returned by mock_uint().
void | will_return_float_maybe (#function, float value)
| Store a float value that may always be returned by mock_float().
void | will_return_double_maybe (#function, double value)
| Store a double value that may always be returned by mock_double().
void | will_return_maybe (#function, uintmax_t value)
void | will_return_ptr (#function, void *value)
| Store a pointer value to be returned by mock_ptr_type() later.
void | will_return_ptr_type (#function, void *value, type)
| Store a pointer value to be returned by mock_ptr_type_checked() later.
void | will_return_ptr_count (#function, void *value, int count)
| Store a pointer value to be returned by mock_ptr_type() later.
void | will_return_ptr_always (#function, void *value)
| Store a value that will be always returned by mock_ptr_type().
void | will_return_ptr_maybe (#function, void *value)
| Store a value that may be always returned by mock_ptr_type().
void | will_set_parameter (#function, #name, uintmax_t value)
| Store a named value to be returned by mock_parameter() later.
void | will_set_parameter_int (#function, #name, intmax_t value)
| Store a named integer value to be returned by mock_parameter() later.
void | will_set_parameter_uint (#function, #name, uintmax_t value)
| Store a named unsigned integer value to be returned by mock_parameter() later.
void | will_set_parameter_float (#function, #name, float value)
| Store a named float value to be returned by mock_parameter() later.
void | will_set_parameter_double (#function, #name, double value)
| Store a named double precision floating point value to be returned by mock_parameter() later.
void | will_set_parameter_int_count (#function, #name, intmax_t value, int count)
| Store a named integer value to be returned a specified number of times by mock_parameter_int() later.
void | will_set_parameter_uint_count (#function, uintmax_t value, int count)
| Store a named unsigned integer value to be returned a specified number of times by mock_parameter_uint() later.
void | will_set_parameter_float_count (#function, #name, float value, int count)
| Store a named float value to be returned a specified number of times by mock_parameter_float() later.
void | will_set_parameter_double_count (#function, #name, double value, int count)
| Store a named double value to be returned a specified number of times by mock_parameter_double() later.
void | will_set_parameter_count (#function, #name, uintmax_t value, int count)
void | will_set_parameter_int_always (#function, #name, intmax_t value)
| Store a named integer value that will always be returned by mock_parameter_int().
void | will_set_parameter_uint_always (#function, #name, uintmax_t value)
| Store a named unsigned integer value that will always be returned by mock_parameter_uint().
void | will_set_parameter_float_always (#function, #name, float value)
| Store a named float value that will always be returned by mock_parameter_float().
void | will_set_parameter_double_always (#function, #name, double value)
| Store a named double value that will always be returned by mock_parameter_double().
void | will_set_parameter_always (#function, #name, uintmax_t value)
void | will_set_parameter_int_maybe (#function, #name, intmax_t value)
| Store a named integer value that may always be returned by mock_parameter_int().
void | will_set_parameter_uint_maybe (#function, #name, uintmax_t value)
| Store a named unsigned integer value that may always be returned by mock_parameter_uint().
void | will_set_parameter_float_maybe (#function, #name, float value)
| Store a named float value that may always be returned by mock_parameter_float().
void | will_set_parameter_double_maybe (#function, #name, double value)
| Store a named double value that may always be returned by mock_parameter_double().
void | will_set_parameter_maybe (#function, #name, uintmax_t value)
void | will_set_parameter_ptr (#function, #name, void *value)
| Store a named pointer value to be returned by mock_parameter() later.
void | will_set_parameter_ptr_type (#function, #name, void *value, #type)
| Store a named pointer value to be returned by mock_parameter() later.
void | will_set_parameter_ptr_count (#function, #name, void *value, int count)
| Store a named pointer value to be returned a specified number of times by mock_parameter_ptr() later.
void | will_set_parameter_ptr_always (#function, #name, void *value)
| Store a named pointer value that will be always returned by mock_parameter_ptr().
void | will_set_parameter_ptr_maybe (#function, #name, void *value)
| Store a named pointer value that may be always returned by mock_parameter_ptr().
void | will_set_errno (#function, intmax_t value)
| Store an integer value to set errno to by mock_errno() later.
void | will_set_errno_count (#function, intmax_t value, size_t count)
| Store an integer value to always set errno to by mock_errno().
void | will_set_errno_always (#function, intmax_t value)
| Store an integer value to set errno to by mock_errno() later, for a specified number of times.
void | will_set_errno_maybe (#function, intmax_t value)
| Store an integer value to set errno to by mock_errno() later, for a specified number of times.

## Detailed Description

Simulate objects and control function return values in tests.

Mock objects are simulated objects that mimic the behavior of real objects. Instead of calling the real objects, the tested object calls a mock object that merely asserts that the correct methods were called, with the expected parameters, in the correct order.

- will_return(function, value) - The will_return() macro pushes a value onto a queue of mock values. This macro is intended to be used by the unit test itself, while programming the behaviour of the mocked object.

- mock() - the mock macro pops a value from a queue of test values. The user of the mock() macro is the mocked object that uses it to learn how it should behave.

Because the will_return() and mock() are intended to be used in pairs, the cmocka library would fail the test if there are more values pushed onto the queue using will_return() than consumed with mock() and vice-versa.

The following unit test stub illustrates how would a unit test instruct the mock object to return a particular value:

will_return_ptr_type(chef_cook, "hotdog", const char *);
will_return_int(chef_cook, 0);
will_return_int
void will_return_int(#function, intmax_t value)
Store an integer value to be returned by mock() later.
will_return_ptr_type
void will_return_ptr_type(#function, void *value, type)
Store a pointer value to be returned by mock_ptr_type_checked() later.

Now the mock object can check if the parameter it received 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)
{
*dish_out = mock_ptr_type(char *); // "hotdog"
int return_code = mock_int(); // 0
return return_code;
}
mock_int
intmax_t mock_int()
Retrieve an integer return value of the current function.
mock_ptr_type
type mock_ptr_type(#type)
Retrieve a typed return value of the current function.

For a complete example please take a look here.

## Macro Definition Documentation

## EXPECT_ALWAYS

#define EXPECT_ALWAYS -1

Check a parameter every time when used with expect_check_data_count().

This constant can be passed as the count parameter to expect_check_data_count() to indicate that the parameter check should be performed every time the mocked function is called. The test will fail if the function is never called.

See also
  expect_check_data_count()

## EXPECT_MAYBE

#define EXPECT_MAYBE -2

Optionally check a parameter when used with expect_check_data_count().

This constant can be passed as the count parameter to expect_check_data_count() to indicate that the parameter check is optional. The check will be performed if the function is called, but the test will not fail if it's never called.

See also
  expect_check_data_count()

## WILL_RETURN_ALWAYS

#define WILL_RETURN_ALWAYS -1

Return a value indefinitely when used with will_return_count().

This constant can be passed as the count parameter to will_return_count() and related functions to indicate that the specified value should be returned every time the mocked function is called, without limit.

See also
  will_return_count()
  will_return_int_count()
  will_return_uint_count()
  will_return_ptr_count()

## WILL_RETURN_ONCE

#define WILL_RETURN_ONCE -2

Return a value once when used with will_return_count().

This constant can be passed as the count parameter to will_return_count() and related functions to indicate that the specified value should be returned only the next time the mocked function is called. This is the default behavior of will_return() and related macros.

See also
  will_return_count()
  will_return()

## Function Documentation

## has_mock()

bool has_mock | ( | void |  | ) |

Check if data is available for the current mock function.

This function checks if there is data available for the current mock function which calls has_mock() without consuming it. This is useful when you want to check if mock data has been set up before calling mock().

Returns
  true if mock data is available, false otherwise.

int example_mock_function(void)
{
if (has_mock()) {
return mock_int();
}
return default_value;
}
has_mock
bool has_mock(void)
Check if data is available for the current mock function.

See also
  mock()
  mock_int()
  mock_uint()
  mock_float()
  will_return()

## mock()

uintmax_t mock | ( | void |  | ) |

Retrieve a return value of the current function.

Returns
  The value which was stored to return by this function.

See also
  will_return()

## mock_double()

double mock_double | ( | void |  | ) |

Retrieve a double precision floating point return value of the current function.

Returns
  The double value which was stored to return by this function.

See also
  will_return_double()

## mock_errno()

void mock_errno | ( | void |  | ) |

set errno for the current function.

mock_errno();
mock_errno
void mock_errno(void)
set errno for the current function.

## mock_float()

float mock_float | ( | void |  | ) |

Retrieve a float return value of the current function.

Returns
  The float value which was stored to return by this function.

See also
  will_return_float()

## mock_int()

intmax_t mock_int | ( |  | ) |

Retrieve an integer return value of the current function.

Returns
  The value which was stored to return by this function.

intmax_t param;
param = mock_int();

See also
  will_return_int()

## mock_parameter()

uintmax_t mock_parameter | ( | # | name | ) |

Retrieve a named value for the current function.

Parameters

  [in] |  | name | The name under which to look for the value

Returns
  The value which was stored under the given name for this function.

int param;
param = (int)mock_parameter(number);
mock_parameter
uintmax_t mock_parameter(#name)
Retrieve a named value for the current function.

See also
  mock()
  mock_parameter_type()
  mock_parameter_int()
  mock_parameter_uint()
  mock_parameter_float()
  mock_parameter_ptr()
  mock_parameter_ptr_type()
  will_return()
  will_set_parameter()
  will_set_parameter_int()
  will_set_parameter_uint()
  will_set_parameter_float()
  will_set_parameter_count()
  will_set_parameter_always()
  will_set_parameter_maybe()
  will_set_parameter_ptr()
  will_set_parameter_ptr_type()
  will_set_parameter_ptr_count()
  will_set_parameter_ptr_always()
  will_set_parameter_ptr_maybe()

## mock_parameter_double()

double mock_parameter_double | ( | # | name | ) |

Retrieve a named double precision floating point value for the current function.

Parameters

  [in] |  | name | The name under which to look for the value

Returns
  The double value which was stored to return by this function.

double param;
param = mock_parameter_double(param);
mock_parameter_double
double mock_parameter_double(#name)
Retrieve a named double precision floating point value for the current function.

See also
  mock_parameter()
  will_set_parameter_double()

## mock_parameter_float()

float mock_parameter_float | ( | # | name | ) |

Retrieve a named float value for the current function.

Parameters

  [in] |  | name | The name under which to look for the value

Returns
  The float value which was stored to return by this function.

float param;
param = mock_parameter_float(param);
mock_parameter_float
float mock_parameter_float(#name)
Retrieve a named float value for the current function.

See also
  mock_parameter()
  will_set_parameter()
  will_set_parameter_float()

## mock_parameter_int()

intmax_t mock_parameter_int | ( | # | name | ) |

Retrieve a named value for the current function and cast it to given type.

The value would be casted to type internally to avoid having the caller to do the cast manually. Type safety checks are disabled with that function.

Parameters

  [in] |  | name | The name under which to look for the value
  [in] |  | type | The expected type of the named value

Returns
  The value which was stored under name for this function.

int param;
param = mock_parameter_type(param, int);

See also
  mock_parameter()
  will_set_parameter()

Retrieve a named integer value for the current function.

Parameters

  [in] |  | name | The name under which to look for the value

Returns
  The integer value which was stored under the given name for this function.

intmax_t param;
param = mock_parameter_int(param);
mock_parameter_int
intmax_t mock_parameter_int(#name)
Retrieve a named value for the current function and cast it to given type.

See also
  mock_parameter()
  will_set_parameter()
  will_set_parameter_int()

## mock_parameter_ptr()

void * mock_parameter_ptr | ( | # | name | ) |

Retrieve a named pointer for the current function.

Parameters

  [in] |  | name | The name under which to look for the pointer

Returns
  The pointer which was stored to return by this function.

int *result
result = (int*)mock_parameter_ptr(result);
mock_parameter_ptr
void * mock_parameter_ptr(#name)
Retrieve a named pointer for the current function.

See also
  mock_parameter()
  will_set_parameter()
  will_set_parameter_ptr()

## mock_parameter_ptr_type()

type mock_parameter_ptr_type | ( | # | name,
|  | # | type )

Retrieve a named pointer for the current function.

In addition it checks if if the type specified by the call to will_return_ptr_type() is the same. And casts it to that type.

Parameters

  [in] |  | name | The name under which to look for the pointer

Returns
  The pointer which was stored to return by this function.

int *result
result = mock_parameter_ptr_type(result, int*);
mock_parameter_ptr_type
type mock_parameter_ptr_type(#name, #type)
Retrieve a named pointer for the current function.

See also
  mock_parameter()
  will_set_parameter()
  will_set_parameter_ptr_type()

## mock_parameter_uint()

uintmax_t mock_parameter_uint | ( | # | name | ) |

Retrieve an unsigned integer return value of the current function.

Parameters

  [in] |  | name | The name under which to look for the value

Returns
  The value which was stored to return by this function.

uintmax_t param;
param = mock_parameter_uint(param);
mock_parameter_uint
uintmax_t mock_parameter_uint(#name)
Retrieve an unsigned integer return value of the current function.

See also
  mock_parameter()
  will_set_parameter()
  will_set_parameter_uint()

## mock_ptr_type()

type mock_ptr_type | ( | # | type | ) |

Retrieve a typed return value of the current function.

The value would be casted to type internally to avoid having the caller to do the cast manually. This macro does NOT perform type checking. For type-safe pointer retrieval, use mock_ptr_type_checked() instead.

Parameters

  [in] |  | type | The expected type of the return value

Returns
  The value which was stored to return by this function.

char *param;
param = mock_ptr_type(char *);

See also
  will_return_ptr()
  mock_ptr_type_checked()

## mock_ptr_type_checked()

type mock_ptr_type_checked | ( | # | type | ) |

Retrieve a typed return value of the current function with type checking.

The value would be casted to type internally to avoid having the caller to do the cast manually. This macro DOES perform type checking and will fail the test if the type used with will_return_ptr_type() does not match the type passed to this macro.

Parameters

  [in] |  | type | The expected type of the return value

Returns
  The value which was stored to return by this function.

char *param;
param = mock_ptr_type_checked(char *);
mock_ptr_type_checked
type mock_ptr_type_checked(#type)
Retrieve a typed return value of the current function with type checking.

See also
  will_return_ptr_type()
  mock_ptr_type()

## mock_type()

type mock_type | ( | # | type | ) |

Retrieve a value of the current function and cast it to given type.

The value would be casted to type internally to avoid having the caller to do the cast manually. Type safety checks are disabled with that function.

Parameters

  [in] |  | type | The expected type of the return value

Returns
  The value which was stored to return by this function casted to the specified type.

int param;
param = mock_type(int);
mock_type
type mock_type(#type)
Retrieve a value of the current function and cast it to given type.

See also
  will_return()

## mock_uint()

uintmax_t mock_uint | ( | void |  | ) |

Retrieve an unsigned integer return value of the current function.

Returns
  The value which was stored to return by this function.

uintmax_t param;
param = mock_uint();
mock_uint
uintmax_t mock_uint(void)
Retrieve an unsigned integer return value of the current function.

See also
  will_return_uint()

## will_return()

void will_return | ( | # | function,
|  | uintmax_t | value )

Store a value to be returned by mock() later.

Parameters

  [in] |  | function | The function which should return the given value.
  [in] |  | value | The value to be returned by mock().

int return_integer(void)
{
return (int)mock();
}
static void test_integer_return(void **state)
{
will_return(return_integer, 42);
assert_int_equal(my_function_calling_return_integer(), 42);
}
assert_int_equal
void assert_int_equal(intmax_t a, intmax_t b)
Assert that the two given integers are equal.
will_return
void will_return(#function, uintmax_t value)
Store a value to be returned by mock() later.
mock
uintmax_t mock(void)
Retrieve a return value of the current function.

See also
  mock()
  mock_int()
  mock_uint()
  mock_float()
  will_return_int()
  will_return_uint()
  will_return_float()
  will_return_ptr_type()
  will_return_count()
  will_return_always()
  will_return_ptr_always()

## will_return_always()

void will_return_always | ( | # | function,
|  | uintmax_t | value )

Deprecated
  Use will_return_int_always() or will_return_uint_always()

## will_return_count()

void will_return_count | ( | # | function,
|  | uintmax_t | value,
|  | int | count )

Deprecated
  Use will_return_int_count() or will_return_uint_count()

## will_return_double()

void will_return_double | ( | # | function,
|  | double | value )

Store a double precision floating point value to be returned by mock() later.

Parameters

  [in] |  | function | The function which should return the given value.
  [in] |  | value | The double value to be returned by mock().

double return_double(void)
{
return mock_double();
}
static void test_double_return(void **state)
{
will_return_double(return_double, 2.5);
assert_double_equal(my_function_calling_return_double(), 2.5, 0.01);
}
assert_double_equal
void assert_double_equal(double a, double b, double epsilon)
Assert that the two given double are equal given an epsilon.
mock_double
double mock_double(void)
Retrieve a double precision floating point return value of the current function.
will_return_double
void will_return_double(#function, double value)
Store a double precision floating point value to be returned by mock() later.

See also
  mock_double()

## will_return_double_always()

void will_return_double_always | ( | # | function,
|  | double | value )

Store a double value that will always be returned by mock_double().

Parameters

  [in] |  | function | The function which should return the given value.
  [in] |  | value | The value to be returned by mock_double().

This is equivalent to:

will_return_double_count(function, value, -1);
will_return_double_count
void will_return_double_count(#function, double value, int count)
Store a double precision floating point value to be returned a specified number of times by mock() la...

See also
  will_return_double_count()
  mock_double()

## will_return_double_count()

void will_return_double_count | ( | # | function,
|  | double | value,
|  | int | count )

Store a double precision floating point value to be returned a specified number of times by mock() later.

Parameters

  [in] |  | function | The function which should return the given value.
  [in] |  | value | The double value to be returned by mock().
  [in] |  | count | The parameter indicates the number of times the value should be returned by mock_double(). If count is set to -1, the value will always be returned but must be returned at least once. If count is set to -2, the value will always be returned by mock_double(), but is not required to be returned.

double return_double(void)
{
return mock_double();
}
static void test_double_return(void **state)
{
will_return_double_count(return_double, 2.5, 3);
assert_double_equal(my_function_calling_return_double(), 2.5, 0.01);
assert_double_equal(my_function_calling_return_double(), 2.5, 0.01);
assert_double_equal(my_function_calling_return_double(), 2.5, 0.01);
}

See also
  mock_double()
  will_return_double()

## will_return_double_maybe()

void will_return_double_maybe | ( | # | function,
|  | double | value )

Store a double value that may always be returned by mock_double().

This stores a value which will always be returned by mock_double() but is not required to be returned by at least one call to mock_double(). Therefore, in contrast to will_return_double_always() which causes a test failure if it is not returned at least once, will_return_double_maybe() will never cause a test to fail if its value is not returned.

Parameters

  [in] |  | function | The function which should return the given value.
  [in] |  | value | The value to be returned by mock_double().

This is equivalent to:

will_return_double_count(function, value, -2);

See also
  will_return_double_count()
  mock_double()

## will_return_float()

void will_return_float | ( | # | function,
|  | float | value )

Store a float value to be returned by mock() later.

Parameters

  [in] |  | function | The function which should return the given value.
  [in] |  | value | The float value to be returned by mock().

float return_float(void)
{
return mock_float();
}
static void test_float_return(void **state)
{
will_return_float(return_float, 1.0f);
assert_float_equal(my_function_calling_return_float(), 1.0f, 0.01f);
}
assert_float_equal
void assert_float_equal(float a, float b, float epsilon)
Assert that the two given float are equal given an epsilon.
will_return_float
void will_return_float(#function, float value)
Store a float value to be returned by mock() later.
mock_float
float mock_float(void)
Retrieve a float return value of the current function.

See also
  mock_float()
  mock_double()

## will_return_float_always()

void will_return_float_always | ( | # | function,
|  | float | value )

Store a float value that will always be returned by mock_float().

Parameters

  [in] |  | function | The function which should return the given value.
  [in] |  | value | The value to be returned by mock_float().

This is equivalent to:

will_return_float_count(function, value, -1);
will_return_float_count
void will_return_float_count(#function, float value, int count)
Store a float value to be returned a specified number of times by mock() later.

See also
  will_return_float_count()
  mock_float()

## will_return_float_count()

void will_return_float_count | ( | # | function,
|  | float | value,
|  | int | count )

Store a float value to be returned a specified number of times by mock() later.

Parameters

  [in] |  | function | The function which should return the given value.
  [in] |  | value | The float value to be returned by mock().
  [in] |  | count | The parameter indicates the number of times the value should be returned by mock_float(). If count is set to -1, the value will always be returned but must be returned at least once. If count is set to -2, the value will always be returned by mock_float(), but is not required to be returned.

float return_float(void)
{
return mock_float();
}
static void test_float_return(void **state)
{
will_return_float_count(return_float, 1.0f, 3);
assert_float_equal(my_function_calling_return_float(), 1.0f, 0.01f);
assert_float_equal(my_function_calling_return_float(), 1.0f, 0.01f);
assert_float_equal(my_function_calling_return_float(), 1.0f, 0.01f);
}

See also
  mock_float()
  will_return_float()

## will_return_float_maybe()

void will_return_float_maybe | ( | # | function,
|  | float | value )

Store a float value that may always be returned by mock_float().

This stores a value which will always be returned by mock_float() but is not required to be returned by at least one call to mock_float(). Therefore, in contrast to will_return_float_always() which causes a test failure if it is not returned at least once, will_return_float_maybe() will never cause a test to fail if its value is not returned.

Parameters

  [in] |  | function | The function which should return the given value.
  [in] |  | value | The value to be returned by mock_float().

This is equivalent to:

will_return_float_count(function, value, -2);

See also
  will_return_float_count()
  mock_float()

## will_return_int()

void will_return_int | ( | # | function,
|  | intmax_t | value )

Store an integer value to be returned by mock() later.

Parameters

  [in] |  | function | The function which should return the given value.
  [in] |  | value | The value to be returned by mock().

int32_t return_int32(void)
{
return (int32_t)mock_int();
}
static void test_integer_return(void **state)
{
will_return_int(return_int32, -42);
assert_int_equal(my_function_calling_return_int32(), -42);
}

See also
  mock_int()

## will_return_int_always()

void will_return_int_always | ( | # | function,
|  | intmax_t | value )

Store an integer value that will always be returned by mock_int().

Parameters

  [in] |  | function | The function which should return the given value.
  [in] |  | value | The value to be returned by mock_int().

This is equivalent to:

will_return_int_count(function, value, -1);
will_return_int_count
void will_return_int_count(#function, intmax_t value, int count)
Store an integer value to be returned a specified number of times by mock() later.

See also
  will_return_int_count()
  mock_int()

## will_return_int_count()

void will_return_int_count | ( | # | function,
|  | intmax_t | value,
|  | int | count )

Store an integer value to be returned a specified number of times by mock() later.

Parameters

  [in] |  | function | The function which should return the given value.
  [in] |  | value | The value to be returned by mock().
  [in] |  | count | The parameter indicates the number of times the value should be returned by mock_int(). If count is set to -1, the value will always be returned but must be returned at least once. If count is set to -2, the value will always be returned by mock_int(), but is not required to be returned.

int32_t return_int32(void)
{
return (int32_t)mock_int();
}
static void test_integer_return(void **state)
{
will_return_int_count(return_int32, -42, 3);
assert_int_equal(my_function_calling_return_int32(), -42);
assert_int_equal(my_function_calling_return_int32(), -42);
assert_int_equal(my_function_calling_return_int32(), -42);
}

See also
  mock_int()
  will_return_int()

## will_return_int_maybe()

void will_return_int_maybe | ( | # | function,
|  | intmax_t | value )

Store an integer value that may always be returned by mock_int().

This stores a value which will always be returned by mock_int() but is not required to be returned by at least one call to mock_int(). Therefore, in contrast to will_return_int_always() which causes a test failure if it is not returned at least once, will_return_int_maybe() will never cause a test to fail if its value is not returned.

Parameters

  [in] |  | function | The function which should return the given value.
  [in] |  | value | The value to be returned by mock_int().

This is equivalent to:

will_return_int_count(function, value, -2);

See also
  will_return_int_count()
  mock_int()

## will_return_maybe()

void will_return_maybe | ( | # | function,
|  | uintmax_t | value )

Deprecated
  Use will_return_int_maybe() or will_return_uint_maybe()

## will_return_ptr()

void will_return_ptr | ( | # | function,
|  | void * | value )

Store a pointer value to be returned by mock_ptr_type() later.

Parameters

  [in] |  | function | The function which should return the given value.
  [in] |  | value | The value to be returned by mock_ptr_type().

const char * return_pointer(void)
{
return mock_ptr_type(const char *);
}
static void test_pointer_return(void **state)
{
will_return_ptr_type(return_pointer, "hello world", const char *);
assert_string_equal(my_func_calling_return_pointer(), "hello world");
}
assert_string_equal
void assert_string_equal(const char *a, const char *b)
Assert that the two given strings are equal.

See also
  mock_ptr_type()
  will_return_ptr_count()

## will_return_ptr_always()

void will_return_ptr_always | ( | # | function,
|  | void * | value )

Store a value that will be always returned by mock_ptr_type().

Parameters

  [in] |  | function | The function which should return the given value.
  [in] |  | value | The value to be returned by mock_ptr_type().

This is equivalent to:

will_return_ptr_count(function, value, -1);
will_return_ptr_count
void will_return_ptr_count(#function, void *value, int count)
Store a pointer value to be returned by mock_ptr_type() later.

See also
  will_return_ptr_count()
  mock_ptr_type()

## will_return_ptr_count()

void will_return_ptr_count | ( | # | function,
|  | void * | value,
|  | int | count )

Store a pointer value to be returned by mock_ptr_type() later.

Parameters

  [in] |  | function | The function which should return the given value.
  [in] |  | value | The value to be returned by mock_ptr_type().
  [in] |  | count | The parameter indicates the number of times the value should be returned by mock(). If count is set to -1, the value will always be returned but must be returned at least once. If count is set to -2, the value will always be returned by mock(), but is not required to be returned.

See also
  mock_ptr_type()

## will_return_ptr_maybe()

void will_return_ptr_maybe | ( | # | function,
|  | void * | value )

Store a value that may be always returned by mock_ptr_type().

This stores a value which will always be returned by mock_ptr_type() but is not required to be returned by at least one call to mock_ptr_type(). Therefore, in contrast to will_return_ptr_always() which causes a test failure if it is not returned at least once, will_return_ptr_maybe() will never cause a test to fail if its value is not returned.

Parameters

  [in] |  | function | The function which should return the given value.
  [in] |  | value | The value to be returned by mock_ptr_type().

This is equivalent to:

will_return_ptr_count(function, value, -2);

See also
  will_return_ptr_count()
  mock_ptr_type()

## will_return_ptr_type()

void will_return_ptr_type | ( | # | function,
|  | void * | value,
|  | type | )

Store a pointer value to be returned by mock_ptr_type_checked() later.

This will also check that the type matches and if not will fail(). The type checking only works when used in conjunction with mock_ptr_type_checked(). If you use mock_ptr_type() to retrieve the value, no type checking will occur.

Parameters

  [in] |  | function | The function which should return the given value.
  [in] |  | value | The value to be returned by mock_ptr_type_checked().
  [in] |  | type | The type of the pointer. const char *return_pointer(void) { return mock_ptr_type_checked(const char *); } static void test_pointer_return(void **state) { will_return_ptr_type(return_pointer, "hello world", const char *); assert_string_equal(my_func_calling_return_pointer(), "hello world"); }

See also
  mock_ptr_type_checked()

## will_return_uint()

void will_return_uint | ( | # | function,
|  | uintmax_t | value )

Store a unsigned integer value to be returned by mock() later.

Parameters

  [in] |  | function | The function which should return the given value.
  [in] |  | value | The value to be returned by mock().

uint32_t return_uint32(void)
{
return (uint32_t)mock_uint();
}
static void test_integer_return(void **state)
{
will_return_uint(return_uint32, 42);
assert_uint_equal(my_function_calling_return_uint32(), 42);
}
assert_uint_equal
void assert_uint_equal(uintmax_t a, uintmax_t b)
Assert that the two given unsigned integers are equal.
will_return_uint
void will_return_uint(#function, uintmax_t value)
Store a unsigned integer value to be returned by mock() later.

See also
  mock_uint()
  will_return_count()

## will_return_uint_always()

void will_return_uint_always | ( | # | function,
|  | uintmax_t | value )

Store an unsigned integer value that will always be returned by mock_uint().

Parameters

  [in] |  | function | The function which should return the given value.
  [in] |  | value | The value to be returned by mock_uint().

This is equivalent to:

will_return_uint_count(function, value, -1);
will_return_uint_count
void will_return_uint_count(#function, uintmax_t value, int count)
Store an unsigned integer value to be returned a specified number of times by mock() later.

See also
  will_return_uint_count()
  mock_uint()

## will_return_uint_count()

void will_return_uint_count | ( | # | function,
|  | uintmax_t | value,
|  | int | count )

Store an unsigned integer value to be returned a specified number of times by mock() later.

Parameters

  [in] |  | function | The function which should return the given value.
  [in] |  | value | The value to be returned by mock().
  [in] |  | count | The parameter indicates the number of times the value should be returned by mock_uint(). If count is set to -1, the value will always be returned but must be returned at least once. If count is set to -2, the value will always be returned by mock_uint(), but is not required to be returned.

uint32_t return_uint32(void)
{
return (uint32_t)mock_uint();
}
static void test_integer_return(void **state)
{
will_return_uint_count(return_uint32, 42, 3);
assert_uint_equal(my_function_calling_return_uint32(), 42);
assert_uint_equal(my_function_calling_return_uint32(), 42);
assert_uint_equal(my_function_calling_return_uint32(), 42);
}

See also
  mock_uint()
  will_return_uint()

## will_return_uint_maybe()

void will_return_uint_maybe | ( | # | function,
|  | uintmax_t | value )

Store an unsigned integer value that may always be returned by mock_uint().

This stores a value which will always be returned by mock_uint() but is not required to be returned by at least one call to mock_uint(). Therefore, in contrast to will_return_uint_always() which causes a test failure if it is not returned at least once, will_return_uint_maybe() will never cause a test to fail if its value is not returned.

Parameters

  [in] |  | function | The function which should return the given value.
  [in] |  | value | The value to be returned by mock_uint().

This is equivalent to:

will_return_uint_count(function, value, -2);

See also
  will_return_uint_count()
  mock_uint()

## will_set_errno()

void will_set_errno | ( | # | function,
|  | intmax_t | value )

Store an integer value to set errno to by mock_errno() later.

Parameters

  [in] |  | function | The function in which errno should be set to the given value.
  [in] |  | value | The value to set errno to by the call to mock_errno().

void sets_errno(void)
{
mock_errno();
}
static void test_sets_errno(void **state)
{
will_set_errno(sets_errno, -3);
assert_int_equal(errno, -3);
}
will_set_errno
void will_set_errno(#function, intmax_t value)
Store an integer value to set errno to by mock_errno() later.

See also
  mock_errno()

## will_set_errno_always()

void will_set_errno_always | ( | # | function,
|  | intmax_t | value )

Store an integer value to set errno to by mock_errno() later, for a specified number of times.

This stores a value which will errno will always be set to by mock_errno() but is required to be set least once by a call to mock_errno().

Parameters

  [in] |  | function | The function in which errno should be set to the given value.
  [in] |  | value | The value to set errno to by the call to mock_errno().

This is equivalent to:

will_set_parameter_count(function, name, value, -1);
will_set_parameter_count
void will_set_parameter_count(#function, #name, uintmax_t value, int count)

See also
  mock_errno()
  will_set_errno()
  will_set_errno_count()
  will_set_errno_maybe()

## will_set_errno_count()

void will_set_errno_count | ( | # | function,
|  | intmax_t | value,
|  | size_t | count )

Store an integer value to always set errno to by mock_errno().

Parameters

  [in] |  | function | The function in which errno should be set to the given value.
  [in] |  | value | The value to set errno to by the call to mock_errno().
  [in] |  | count | The count parameter gives the number of times the value should be validated by check_expected(). If count is set to EXPECT_ALWAYS the value will always be returned, and cmocka expects check_expected() to be issued at least once. If count is set to EXPECT_MAYBE, any number of calls to check_expected() is accepted, including zero.

void sets_errno(void)
{
mock_errno();
}
static void test_sets_errno(void **state)
{
will_set_errno_count(sets_errno, -3, 2);
sets_errno();
assert_int_equal(errno, -3);
errno = 0;
sets_errno();
assert_int_equal(errno, -3);
}
will_set_errno_count
void will_set_errno_count(#function, intmax_t value, size_t count)
Store an integer value to always set errno to by mock_errno().

See also
  mock_errno()
  will_set_errno()
  will_set_errno_always()
  will_set_errno_maybe()

## will_set_errno_maybe()

void will_set_errno_maybe | ( | # | function,
|  | intmax_t | value )

Store an integer value to set errno to by mock_errno() later, for a specified number of times.

This stores a value which will errno will always be set to by mock_errno() and won't fail if mock_errno() is never called.

Parameters

  [in] |  | function | The function in which errno should be set to the given value.
  [in] |  | value | The value to set errno to by the call to mock_errno().

This is equivalent to:

will_set_parameter_count(function, name, value, -2);

See also
  mock_errno()
  will_set_errno()
  will_set_errno_count()
  will_set_errno_always()

## will_set_parameter()

void will_set_parameter | ( | # | function,
|  | # | name,
|  | uintmax_t | value )

Store a named value to be returned by mock_parameter() later.

Parameters

  [in] |  | function | The function in which the given value should be return.
  [in] |  | name | The name under which the given value should be returned.
  [in] |  | value | The value to be returned by mock_parameter().

void return_integer(int *result)
{
*result = (int)mock_parameter(result);
}
static void test_integer_return(void **state)
{
will_set_parameter(return_integer, result, 42);
int retVal = 0;
my_function_calling_return_integer(&retVal);
assert_int_equal(result, 42);
}
will_set_parameter
void will_set_parameter(#function, #name, uintmax_t value)
Store a named value to be returned by mock_parameter() later.

See also
  mock_parameter()
  mock_parameter()
  mock_parameter_int()
  mock_parameter_uint()
  mock_parameter_float()
  mock_parameter_ptr()
  mock_parameter_ptr_type()
  will_set_parameter_int()
  will_set_parameter_uint()
  will_set_parameter_float()
  will_set_parameter_ptr()
  will_set_parameter_ptr_type()
  will_set_parameter_count()
  will_set_parameter_always()
  will_set_parameter_maybe()
  will_set_parameter_ptr_count()
  will_set_parameter_ptr_always()
  will_set_parameter_ptr_maybe()

## will_set_parameter_always()

void will_set_parameter_always | ( | # | function,
|  | # | name,
|  | uintmax_t | value )

Deprecated
  Use will_set_parameter_int_always() or will_set_parameter_uint_always()

## will_set_parameter_count()

void will_set_parameter_count | ( | # | function,
|  | # | name,
|  | uintmax_t | value,
|  | int | count )

Deprecated
  Use will_set_parameter_int_count() or will_set_parameter_uint_count()

## will_set_parameter_double()

void will_set_parameter_double | ( | # | function,
|  | # | name,
|  | double | value )

Store a named double precision floating point value to be returned by mock_parameter() later.

And adds some type checking information to be able to check with call to mock_parameter_double().

Parameters

  [in] |  | function | The function in which the given value should be return.
  [in] |  | name | The name under which the given value should be returned.
  [in] |  | value | The double value to be returned by mock_parameter().

void return_double(double *result)
{
*result = mock_parameter_double(result);
}
static void test_double_return(void **state)
{
will_set_parameter_double(return_double, result, 34.7);
double result_param = NAN;
return_double(&result_param);
assert_double_equal(result_param, 34.7, 0.0);
}
will_set_parameter_double
void will_set_parameter_double(#function, #name, double value)
Store a named double precision floating point value to be returned by mock_parameter() later.

See also
  mock_parameter()
  mock_parameter_double()
  will_set_parameter()

## will_set_parameter_double_always()

void will_set_parameter_double_always | ( | # | function,
|  | # | name,
|  | double | value )

Store a named double value that will always be returned by mock_parameter_double().

Parameters

  [in] |  | function | The function in which the given value should be return.
  [in] |  | name | The name under which the given value should be returned.
  [in] |  | value | The value to be returned by mock_parameter_double().

This is equivalent to:

will_set_parameter_double_count(function, name, value, -1);
will_set_parameter_double_count
void will_set_parameter_double_count(#function, #name, double value, int count)
Store a named double value to be returned a specified number of times by mock_parameter_double() late...

See also
  mock_parameter_double()
  will_set_parameter_double_count()

## will_set_parameter_double_count()

void will_set_parameter_double_count | ( | # | function,
|  | # | name,
|  | double | value,
|  | int | count )

Store a named double value to be returned a specified number of times by mock_parameter_double() later.

Parameters

  [in] |  | function | The function in which the given value should be return.
  [in] |  | name | The name under which the given value should be returned.
  [in] |  | value | The value to be returned by mock_parameter_double().
  [in] |  | count | The parameter indicates the number of times the value should be returned. If count is set to -1, the value will always be returned but must be returned at least once. If count is set to -2, the value will always be returned, but is not required to be returned.

See also
  mock_parameter_double()
  will_set_parameter_double()

## will_set_parameter_double_maybe()

void will_set_parameter_double_maybe | ( | # | function,
|  | # | name,
|  | double | value )

Store a named double value that may always be returned by mock_parameter_double().

This stores a value which will always be returned by mock_parameter_double() but is not required to be returned by at least one call to mock_parameter_double().

Parameters

  [in] |  | function | The function in which the given value should be return.
  [in] |  | name | The name under which the given value should be returned.
  [in] |  | value | The value to be returned by mock_parameter_double().

This is equivalent to:

will_set_parameter_double_count(function, name, value, -2);

See also
  mock_parameter_double()
  will_set_parameter_double_count()

## will_set_parameter_float()

void will_set_parameter_float | ( | # | function,
|  | # | name,
|  | float | value )

Store a named float value to be returned by mock_parameter() later.

And adds some type checking information to be able to check with call to mock_parameter_float().

Parameters

  [in] |  | function | The function in which the given value should be return.
  [in] |  | name | The name under which the given value should be returned.
  [in] |  | value | The float value to be returned by mock_parameter().

void return_float(float *result)
{
*result = mock_parameter_float(result);
}
static void test_float_return(void **state)
{
will_set_parameter_float(return_float, result, 34.7f);
float result_param = NAN;
return_float(&result_param);
assert_float_equal(result_param, 34.7f, 0.01f);
}
will_set_parameter_float
void will_set_parameter_float(#function, #name, float value)
Store a named float value to be returned by mock_parameter() later.

See also
  mock_parameter()
  mock_parameter_float()
  will_set_parameter()

## will_set_parameter_float_always()

void will_set_parameter_float_always | ( | # | function,
|  | # | name,
|  | float | value )

Store a named float value that will always be returned by mock_parameter_float().

Parameters

  [in] |  | function | The function in which the given value should be return.
  [in] |  | name | The name under which the given value should be returned.
  [in] |  | value | The value to be returned by mock_parameter_float().

This is equivalent to:

will_set_parameter_float_count(function, name, value, -1);
will_set_parameter_float_count
void will_set_parameter_float_count(#function, #name, float value, int count)
Store a named float value to be returned a specified number of times by mock_parameter_float() later.

See also
  mock_parameter_float()
  will_set_parameter_float_count()

## will_set_parameter_float_count()

void will_set_parameter_float_count | ( | # | function,
|  | # | name,
|  | float | value,
|  | int | count )

Store a named float value to be returned a specified number of times by mock_parameter_float() later.

Parameters

  [in] |  | function | The function in which the given value should be return.
  [in] |  | name | The name under which the given value should be returned.
  [in] |  | value | The value to be returned by mock_parameter_float().
  [in] |  | count | The parameter indicates the number of times the value should be returned. If count is set to -1, the value will always be returned but must be returned at least once. If count is set to -2, the value will always be returned, but is not required to be returned.

See also
  mock_parameter_float()
  will_set_parameter_float()

## will_set_parameter_float_maybe()

void will_set_parameter_float_maybe | ( | # | function,
|  | # | name,
|  | float | value )

Store a named float value that may always be returned by mock_parameter_float().

This stores a value which will always be returned by mock_parameter_float() but is not required to be returned by at least one call to mock_parameter_float().

Parameters

  [in] |  | function | The function in which the given value should be return.
  [in] |  | name | The name under which the given value should be returned.
  [in] |  | value | The value to be returned by mock_parameter_float().

This is equivalent to:

will_set_parameter_float_count(function, name, value, -2);

See also
  mock_parameter_float()
  will_set_parameter_float_count()

## will_set_parameter_int()

void will_set_parameter_int | ( | # | function,
|  | # | name,
|  | intmax_t | value )

Store a named integer value to be returned by mock_parameter() later.

And adds some type checking information to be able to check with call to mock_parameter_int().

Parameters

  [in] |  | function | The function in which the given value should be return.
  [in] |  | name | The name under which the given value should be returned.
  [in] |  | value | The value to be returned by mock_parameter().

void return_int32(int32_t *result)
{
*result = (int32_t)mock_parameter_int(result);
}
static void test_integer_return(void **state)
{
will_set_parameter_int(return_int32, result, -42);
int32_t result_param = 0;
return_int32(&result_param);
assert_int_equal(result_param, -42);
}
will_set_parameter_int
void will_set_parameter_int(#function, #name, intmax_t value)
Store a named integer value to be returned by mock_parameter() later.

See also
  mock_parameter()
  mock_parameter_int()
  will_set_parameter()

## will_set_parameter_int_always()

void will_set_parameter_int_always | ( | # | function,
|  | # | name,
|  | intmax_t | value )

Store a named integer value that will always be returned by mock_parameter_int().

Parameters

  [in] |  | function | The function in which the given value should be return.
  [in] |  | name | The name under which the given value should be returned.
  [in] |  | value | The value to be returned by mock_parameter_int().

This is equivalent to:

will_set_parameter_int_count(function, name, value, -1);
will_set_parameter_int_count
void will_set_parameter_int_count(#function, #name, intmax_t value, int count)
Store a named integer value to be returned a specified number of times by mock_parameter_int() later.

See also
  mock_parameter_int()
  will_set_parameter_int_count()

## will_set_parameter_int_count()

void will_set_parameter_int_count | ( | # | function,
|  | # | name,
|  | intmax_t | value,
|  | int | count )

Store a named integer value to be returned a specified number of times by mock_parameter_int() later.

Parameters

  [in] |  | function | The function in which the given value should be return.
  [in] |  | name | The name under which the given value should be returned.
  [in] |  | value | The value to be returned by mock_parameter_int().
  [in] |  | count | The parameter indicates the number of times the value should be returned. If count is set to -1, the value will always be returned but must be returned at least once. If count is set to -2, the value will always be returned, but is not required to be returned.

See also
  mock_parameter_int()
  will_set_parameter_int()

## will_set_parameter_int_maybe()

void will_set_parameter_int_maybe | ( | # | function,
|  | # | name,
|  | intmax_t | value )

Store a named integer value that may always be returned by mock_parameter_int().

This stores a value which will always be returned by mock_parameter_int() but is not required to be returned by at least one call to mock_parameter_int().

Parameters

  [in] |  | function | The function in which the given value should be return.
  [in] |  | name | The name under which the given value should be returned.
  [in] |  | value | The value to be returned by mock_parameter_int().

This is equivalent to:

will_set_parameter_int_count(function, name, value, -2);

See also
  mock_parameter_int()
  will_set_parameter_int_count()

## will_set_parameter_maybe()

void will_set_parameter_maybe | ( | # | function,
|  | # | name,
|  | uintmax_t | value )

Deprecated
  Use will_set_parameter_int_maybe() or will_set_parameter_uint_maybe()

## will_set_parameter_ptr()

void will_set_parameter_ptr | ( | # | function,
|  | # | name,
|  | void * | value )

Store a named pointer value to be returned by mock_parameter() later.

Parameters

  [in] |  | function | The function in which the given value should be return.
  [in] |  | name | The name under which the given value should be returned.
  [in] |  | value | The value to be returned by mock_parameter().

void return_pointer(const char **result)
{
*result = (const char *)mock_parameter_ptr(result);
}
static void test_pointer_return(void **state)
{
will_set_parameter_ptr(return_pointer, result, "hello world");
const char *returned = NULL;
my_func_calling_return_pointer(&returned);
assert_string_equal(returned, "hello world");
}
will_set_parameter_ptr
void will_set_parameter_ptr(#function, #name, void *value)
Store a named pointer value to be returned by mock_parameter() later.

See also
  mock_parameter()
  mock_parameter_ptr()
  will_set_parameter()

## will_set_parameter_ptr_always()

void will_set_parameter_ptr_always | ( | # | function,
|  | # | name,
|  | void * | value )

Store a named pointer value that will be always returned by mock_parameter_ptr().

This stores a value which will always be returned by mock_parameter_ptr() and is required to be returned by at least one call to mock_parameter_ptr(). If it is not returned at least once the test will fail.

Parameters

  [in] |  | function | The function in which the given value should be return.
  [in] |  | name | The name under which the given value should be returned.
  [in] |  | value | The value to be returned by mock_parameter_ptr().

This is equivalent to:

will_set_parameter_ptr_count(function, name, value, -1);
will_set_parameter_ptr_count
void will_set_parameter_ptr_count(#function, #name, void *value, int count)
Store a named pointer value to be returned a specified number of times by mock_parameter_ptr() later.

See also
  mock_parameter()
  mock_parameter_ptr()
  will_set_parameter()
  will_set_parameter_ptr()
  will_set_parameter_ptr_count()

## will_set_parameter_ptr_count()

void will_set_parameter_ptr_count | ( | # | function,
|  | # | name,
|  | void * | value,
|  | int | count )

Store a named pointer value to be returned a specified number of times by mock_parameter_ptr() later.

Parameters

  [in] |  | function | The function in which the given value should be return.
  [in] |  | name | The name under which the given value should be returned.
  [in] |  | value | The value to be returned by mock_parameter_ptr().
  [in] |  | count | The parameter indicates the number of times the value should be returned by mock_parameter_ptr(). If count is set to -1, the value will always be returned but must be returned at least once. If count is set to -2, the value will always be returned by mock_parameter_ptr(), but is not required to be returned.

void return_pointer(const char **resultA, const char **resultB)
{
*resultA = (const char *)mock_parameter_ptr(result);
*resultB = (const char *)mock_parameter_ptr(result);
}
static void test_pointer_return(void **state)
{
will_set_parameter_ptr_count(return_pointer, result, "hello world", const char*, 2);
const char *returnedA = NULL;
const char *returnedB = NULL;
my_func_calling_return_pointer(&returnedA, &returnedB);
assert_string_equal(returnedA, "hello world");
assert_string_equal(returnedB, "hello world");
}

See also
  mock_parameter()
  mock_parameter_ptr()
  will_named_return()
  will_named_return_ptr()

## will_set_parameter_ptr_maybe()

void will_set_parameter_ptr_maybe | ( | # | function,
|  | # | name,
|  | void * | value )

Store a named pointer value that may be always returned by mock_parameter_ptr().

This stores a value which will always be returned by mock_parameter_ptr() but is not required to be returned by at least one call to mock_parameter_ptr(). Therefore, in contrast to will_set_parameter_ptr_always() which causes a test failure if it is not returned at least once, will_set_parameter_ptr_maybe() will never cause a test to fail if its value is not returned.

Parameters

  [in] |  | function | The function in which the given value should be return.
  [in] |  | name | The name under which the given value should be returned.
  [in] |  | value | The value to be returned by mock_parameter_ptr().

This is equivalent to:

will_set_parameter_ptr_count(function, name, value, -2);

See also
  mock_parameter()
  mock_parameter_ptr()
  will_set_parameter()
  will_set_parameter_ptr()
  will_set_parameter_ptr_count()

## will_set_parameter_ptr_type()

void will_set_parameter_ptr_type | ( | # | function,
|  | # | name,
|  | void * | value,
|  | # | type )

Store a named pointer value to be returned by mock_parameter() later.

This will also check that the type matches and if not will fail().

Parameters

  [in] |  | function | The function in which the given value should be return.
  [in] |  | name | The name under which the given value should be returned.
  [in] |  | value | The value to be returned by mock_parameter().
  [in] |  | type | The type of the pointer.

void return_pointer(const char **result)
{
*result = mock_parameter_ptr_typed(result, const char*);
}
static void test_pointer_return(void **state)
{
will_set_parameter_ptr_type(return_pointer, result, "hello world", const char*);
const char *returned = NULL;
my_func_calling_return_pointer(&returned);
assert_string_equal(returned, "hello world");
}
will_set_parameter_ptr_type
void will_set_parameter_ptr_type(#function, #name, void *value, #type)
Store a named pointer value to be returned by mock_parameter() later.

See also
  mock_parameter()
  mock_parameter_ptr()
  mock_parameter_ptr_type()
  will_set_parameter()
  will_set_parameter_ptr()

## will_set_parameter_uint()

void will_set_parameter_uint | ( | # | function,
|  | # | name,
|  | uintmax_t | value )

Store a named unsigned integer value to be returned by mock_parameter() later.

And adds some type checking information to be able to check with call to mock_parameter_uint().

Parameters

  [in] |  | function | The function in which the given value should be return.
  [in] |  | name | The name under which the given value should be returned.
  [in] |  | value | The value to be returned by mock_parameter().

void return_uint32(uint32_t *result)
{
*result =(uint32_t)mock_parameter_uint(result);
}
static void test_integer_return(void **state)
{
will_set_parameter_uint(return_uint32, result, 42);
uint32_t result_param = 0;
return_uint32(&result_param);
assert_uint_equal(result_param, 42);
}
will_set_parameter_uint
void will_set_parameter_uint(#function, #name, uintmax_t value)
Store a named unsigned integer value to be returned by mock_parameter() later.

See also
  mock_parameter()
  mock_parameter_uint()
  will_set_parameter()

## will_set_parameter_uint_always()

void will_set_parameter_uint_always | ( | # | function,
|  | # | name,
|  | uintmax_t | value )

Store a named unsigned integer value that will always be returned by mock_parameter_uint().

Parameters

  [in] |  | function | The function in which the given value should be return.
  [in] |  | name | The name under which the given value should be returned.
  [in] |  | value | The value to be returned by mock_parameter_uint().

This is equivalent to:

will_set_parameter_uint_count(function, name, value, -1);
will_set_parameter_uint_count
void will_set_parameter_uint_count(#function, uintmax_t value, int count)
Store a named unsigned integer value to be returned a specified number of times by mock_parameter_uin...

See also
  mock_parameter_uint()
  will_set_parameter_uint_count()

## will_set_parameter_uint_count()

void will_set_parameter_uint_count | ( | # | function,
|  | uintmax_t | value,
|  | int | count )

Store a named unsigned integer value to be returned a specified number of times by mock_parameter_uint() later.

Parameters

  [in] |  | function | The function in which the given value should be return.
  [in] |  | name | The name under which the given value should be returned.
  [in] |  | value | The value to be returned by mock_parameter_uint().
  [in] |  | count | The parameter indicates the number of times the value should be returned. If count is set to -1, the value will always be returned but must be returned at least once. If count is set to -2, the value will always be returned, but is not required to be returned.

See also
  mock_parameter_uint()
  will_set_parameter_uint()

## will_set_parameter_uint_maybe()

void will_set_parameter_uint_maybe | ( | # | function,
|  | # | name,
|  | uintmax_t | value )

Store a named unsigned integer value that may always be returned by mock_parameter_uint().

This stores a value which will always be returned by mock_parameter_uint() but is not required to be returned by at least one call to mock_parameter_uint().

Parameters

  [in] |  | function | The function in which the given value should be return.
  [in] |  | name | The name under which the given value should be returned.
  [in] |  | value | The value to be returned by mock_parameter_uint().

This is equivalent to:

will_set_parameter_uint_count(function, name, value, -2);

See also
  mock_parameter_uint()
  will_set_parameter_uint_count()