cmocka.h | cmocka.h | |||
---|---|---|---|---|
skipping to change at line 135 | skipping to change at line 135 | |||
/** | /** | |||
* @defgroup cmocka_mock Mock Objects | * @defgroup cmocka_mock Mock Objects | |||
* @ingroup cmocka | * @ingroup cmocka | |||
* | * | |||
* Mock objects mock objects are simulated objects that mimic the behavior of | * Mock objects mock objects are simulated objects that mimic the behavior of | |||
* real objects. Instead of calling the real objects, the tested object cal ls a | * real objects. Instead of calling the real objects, the tested object cal ls a | |||
* mock object that merely asserts that the correct methods were called, wi th | * mock object that merely asserts that the correct methods were called, wi th | |||
* the expected parameters, in the correct order. | * the expected parameters, in the correct order. | |||
* | * | |||
* <ul> | ||||
* <li><strong>will_return(function, value)</strong> - The will_return() ma | ||||
cro | ||||
* pushes a value onto a stack of mock values. This macro is intended to be | ||||
* used by the unit test itself, while programming the behaviour of the moc | ||||
ked | ||||
* object.</li> | ||||
* | ||||
* <li><strong>mock()</strong> - the mock macro pops a value from a stack o | ||||
f | ||||
* test values. The user of the mock() macro is the mocked object that uses | ||||
it | ||||
* to learn how it should behave.</li> | ||||
* </ul> | ||||
* | ||||
* Because the will_return() and mock() are intended to be used in pairs, t | ||||
he | ||||
* cmocka library would fail the test if there are more values pushed onto | ||||
the | ||||
* stack 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: | ||||
* | ||||
* @code | ||||
* will_return(chef_cook, "hotdog"); | ||||
* will_return(chef_cook, 0); | ||||
* @endcode | ||||
* | ||||
* Now the mock object can check if the parameter it received is the parame | ||||
ter | ||||
* which is expected by the test driver. This can be done the following way | ||||
: | ||||
* | ||||
* @code | ||||
* int chef_cook(const char *order, char **dish_out) | ||||
* { | ||||
* check_expected(order); | ||||
* } | ||||
* @endcode | ||||
* | ||||
* For a complete example please at a look | ||||
* <a href="http://git.cryptomilk.org/projects/cmocka.git/tree/example/chef | ||||
_wrap/waiter_test_wrap.c">here</a>. | ||||
* | ||||
* @{ | * @{ | |||
*/ | */ | |||
#ifdef DOXYGEN | #ifdef DOXYGEN | |||
/** | /** | |||
* @brief Retrieve a return value of the current function. | * @brief Retrieve a return value of the current function. | |||
* | * | |||
* @return The value which was stored to return by this function. | * @return The value which was stored to return by this function. | |||
* | * | |||
* @see will_return() | * @see will_return() | |||
*/ | */ | |||
void *mock(void); | void *mock(void); | |||
#else | #else | |||
#define mock() _mock(__func__, __FILE__, __LINE__) | #define mock() _mock(__func__, __FILE__, __LINE__) | |||
#endif | #endif | |||
#ifdef DOXYGEN | #ifdef DOXYGEN | |||
/** | /** | |||
* @brief 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. | ||||
* | ||||
* @param[in] #type The expected type of the return value | ||||
* | ||||
* @return The value which was stored to return by this function. | ||||
* | ||||
* @code | ||||
* int param; | ||||
* | ||||
* param = mock_type(int); | ||||
* @endcode | ||||
* | ||||
* @see will_return() | ||||
* @see mock() | ||||
* @see mock_ptr_type() | ||||
*/ | ||||
void *mock_type(#type); | ||||
#else | ||||
#define mock_type(type) ((type) mock()) | ||||
#endif | ||||
#ifdef DOXYGEN | ||||
/** | ||||
* @brief 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 but also casted to uintptr_t to make | ||||
* sure the result has a valid size to be used as a pointer. | ||||
* | ||||
* @param[in] #type The expected type of the return value | ||||
* | ||||
* @return The value which was stored to return by this function. | ||||
* | ||||
* @code | ||||
* char *param; | ||||
* | ||||
* param = mock_ptr_type(char *); | ||||
* @endcode | ||||
* | ||||
* @see will_return() | ||||
* @see mock() | ||||
* @see mock_type() | ||||
*/ | ||||
void *mock_ptr_type(#type); | ||||
#else | ||||
#define mock_ptr_type(type) ((type) (uintptr_t) mock()) | ||||
#endif | ||||
#ifdef DOXYGEN | ||||
/** | ||||
* @brief Store a value to be returned by mock() later. | * @brief Store a value to be returned by mock() later. | |||
* | * | |||
* @param[in] #function The function which should return the given value. | * @param[in] #function The function which should return the given value. | |||
* | * | |||
* @param[in] value The value to be returned by mock(). | * @param[in] value The value to be returned by mock(). | |||
* | * | |||
* @code | * @code | |||
* int return_integer(void) | * int return_integer(void) | |||
* { | * { | |||
* return (int)mock(); | * return (int)mock(); | |||
skipping to change at line 223 | skipping to change at line 312 | |||
* functionality to store expected values for mock function parameters usin g | * functionality to store expected values for mock function parameters usin g | |||
* the expect_*() functions provided. A mock function parameter can then be | * the expect_*() functions provided. A mock function parameter can then be | |||
* validated using the check_expected() macro. | * validated using the check_expected() macro. | |||
* | * | |||
* Successive calls to expect_*() macros for a parameter queues values to c heck | * Successive calls to expect_*() macros for a parameter queues values to c heck | |||
* the specified parameter. check_expected() checks a function parameter | * the specified parameter. check_expected() checks a function parameter | |||
* against the next value queued using expect_*(), if the parameter check f ails | * against the next value queued using expect_*(), if the parameter check f ails | |||
* a test failure is signalled. In addition if check_expected() is called a nd | * a test failure is signalled. In addition if check_expected() is called a nd | |||
* no more parameter values are queued a test failure occurs. | * no more parameter values are queued a test failure occurs. | |||
* | * | |||
* The following test stub illustrates how to do this. First is the the fun | ||||
ction | ||||
* we call in the test driver: | ||||
* | ||||
* @code | ||||
* static void test_driver(void **state) | ||||
* { | ||||
* expect_string(chef_cook, order, "hotdog"); | ||||
* } | ||||
* @endcode | ||||
* | ||||
* Now the chef_cook function can check if the parameter we got passed is t | ||||
he | ||||
* parameter which is expected by the test driver. This can be done the | ||||
* following way: | ||||
* | ||||
* @code | ||||
* int chef_cook(const char *order, char **dish_out) | ||||
* { | ||||
* check_expected(order); | ||||
* } | ||||
* @endcode | ||||
* | ||||
* For a complete example please at a look at | ||||
* <a href="http://git.cryptomilk.org/projects/cmocka.git/tree/example/chef | ||||
_wrap/waiter_test_wrap.c">here</a> | ||||
* | ||||
* @{ | * @{ | |||
*/ | */ | |||
/* | /* | |||
* Add a custom parameter checking function. If the event parameter is NUL L | * Add a custom parameter checking function. If the event parameter is NUL L | |||
* the event structure is allocated internally by this function. If event | * the event structure is allocated internally by this function. If event | |||
* parameter is provided it must be allocated on the heap and doesn't need to | * parameter is provided it must be allocated on the heap and doesn't need to | |||
* be deallocated by the caller. | * be deallocated by the caller. | |||
*/ | */ | |||
#ifdef DOXYGEN | #ifdef DOXYGEN | |||
skipping to change at line 256 | skipping to change at line 369 | |||
* | * | |||
* @param[in] check_data The data to pass to the check function. | * @param[in] check_data The data to pass to the check function. | |||
*/ | */ | |||
void expect_check(#function, #parameter, #check_function, const void *check _data); | void expect_check(#function, #parameter, #check_function, const void *check _data); | |||
#else | #else | |||
#define expect_check(function, parameter, check_function, check_data) \ | #define expect_check(function, parameter, check_function, check_data) \ | |||
_expect_check(#function, #parameter, __FILE__, __LINE__, check_function , \ | _expect_check(#function, #parameter, __FILE__, __LINE__, check_function , \ | |||
cast_to_largest_integral_type(check_data), NULL, 0) | cast_to_largest_integral_type(check_data), NULL, 0) | |||
#endif | #endif | |||
/* | #if DOXYGEN | |||
* Add an event to check a parameter, using check_expected(), against a set | /** | |||
of | * @brief Add an event to check if the parameter value is part of the provi | |||
* values. See will_return() for a description of the count parameter. | ded | |||
* array. | ||||
* | ||||
* The event is triggered by calling check_expected() in the mocked functio | ||||
n. | ||||
* | ||||
* @param[in] #function The function to add the check for. | ||||
* | ||||
* @param[in] #parameter The name of the parameter passed to the function. | ||||
* | ||||
* @param[in] value_array[] The array to check for the value. | ||||
* | ||||
* @see check_expected(). | ||||
*/ | */ | |||
void expect_in_set(#function, #parameter, uintmax_t value_array[]); | ||||
#else | ||||
#define expect_in_set(function, parameter, value_array) \ | #define expect_in_set(function, parameter, value_array) \ | |||
expect_in_set_count(function, parameter, value_array, 1) | expect_in_set_count(function, parameter, value_array, 1) | |||
#endif | ||||
#if DOXYGEN | ||||
/** | ||||
* @brief Add an event to check if the parameter value is part of the provi | ||||
ded | ||||
* array. | ||||
* | ||||
* The event is triggered by calling check_expected() in the mocked functio | ||||
n. | ||||
* | ||||
* @param[in] #function The function to add the check for. | ||||
* | ||||
* @param[in] #parameter The name of the parameter passed to the function. | ||||
* | ||||
* @param[in] value_array[] The array to check for the value. | ||||
* | ||||
* @param[in] count The count parameter returns the number of times the v | ||||
alue | ||||
* should be returned by check_expected(). If count is s | ||||
et | ||||
* to -1 the value will always be returned. | ||||
* | ||||
* @see check_expected(). | ||||
*/ | ||||
void expect_in_set_count(#function, #parameter, uintmax_t value_array[], si | ||||
ze_t count); | ||||
#else | ||||
#define expect_in_set_count(function, parameter, value_array, count) \ | #define expect_in_set_count(function, parameter, value_array, count) \ | |||
_expect_in_set(#function, #parameter, __FILE__, __LINE__, value_array, \ | _expect_in_set(#function, #parameter, __FILE__, __LINE__, value_array, \ | |||
sizeof(value_array) / sizeof((value_array)[0]), count) | sizeof(value_array) / sizeof((value_array)[0]), count) | |||
#endif | ||||
#if DOXYGEN | ||||
/** | ||||
* @brief 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 functio | ||||
n. | ||||
* | ||||
* @param[in] #function The function to add the check for. | ||||
* | ||||
* @param[in] #parameter The name of the parameter passed to the function. | ||||
* | ||||
* @param[in] value_array[] The array to check for the value. | ||||
* | ||||
* @see check_expected(). | ||||
*/ | ||||
void expect_not_in_set(#function, #parameter, uintmax_t value_array[]); | ||||
#else | ||||
#define expect_not_in_set(function, parameter, value_array) \ | #define expect_not_in_set(function, parameter, value_array) \ | |||
expect_not_in_set_count(function, parameter, value_array, 1) | expect_not_in_set_count(function, parameter, value_array, 1) | |||
#endif | ||||
#if DOXYGEN | ||||
/** | ||||
* @brief 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 functio | ||||
n. | ||||
* | ||||
* @param[in] #function The function to add the check for. | ||||
* | ||||
* @param[in] #parameter The name of the parameter passed to the function. | ||||
* | ||||
* @param[in] value_array[] The array to check for the value. | ||||
* | ||||
* @param[in] count The count parameter returns the number of times the v | ||||
alue | ||||
* should be returned by check_expected(). If count is s | ||||
et | ||||
* to -1 the value will always be returned. | ||||
* | ||||
* @see check_expected(). | ||||
*/ | ||||
void expect_not_in_set_count(#function, #parameter, uintmax_t value_array[] | ||||
, size_t count); | ||||
#else | ||||
#define expect_not_in_set_count(function, parameter, value_array, count) \ | #define expect_not_in_set_count(function, parameter, value_array, count) \ | |||
_expect_not_in_set( \ | _expect_not_in_set( \ | |||
#function, #parameter, __FILE__, __LINE__, value_array, \ | #function, #parameter, __FILE__, __LINE__, value_array, \ | |||
sizeof(value_array) / sizeof((value_array)[0]), count) | sizeof(value_array) / sizeof((value_array)[0]), count) | |||
#endif | ||||
/* | #if DOXYGEN | |||
* Add an event to check a parameter, using check_expected(), against a | /** | |||
* signed range. Where range is minimum <= value <= maximum. | * @brief Add an event to check a parameter is inside a numerical range. | |||
* See will_return() for a description of the count parameter. | * The check would succeed if minimum <= value <= maximum. | |||
* | ||||
* The event is triggered by calling check_expected() in the mocked functio | ||||
n. | ||||
* | ||||
* @param[in] #function The function to add the check for. | ||||
* | ||||
* @param[in] #parameter The name of the parameter passed to the function. | ||||
* | ||||
* @param[in] minimum The lower boundary of the interval to check against | ||||
. | ||||
* | ||||
* @param[in] maximum The upper boundary of the interval to check against | ||||
. | ||||
* | ||||
* @see check_expected(). | ||||
*/ | */ | |||
void expect_in_range(#function, #parameter, uintmax_t minimum, uintmax_t ma | ||||
ximum); | ||||
#else | ||||
#define expect_in_range(function, parameter, minimum, maximum) \ | #define expect_in_range(function, parameter, minimum, maximum) \ | |||
expect_in_range_count(function, parameter, minimum, maximum, 1) | expect_in_range_count(function, parameter, minimum, maximum, 1) | |||
#endif | ||||
#if DOXYGEN | ||||
/** | ||||
* @brief 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 functio | ||||
n. | ||||
* | ||||
* @param[in] #function The function to add the check for. | ||||
* | ||||
* @param[in] #parameter The name of the parameter passed to the function. | ||||
* | ||||
* @param[in] minimum The lower boundary of the interval to check against | ||||
. | ||||
* | ||||
* @param[in] maximum The upper boundary of the interval to check against | ||||
. | ||||
* | ||||
* @param[in] count The count parameter returns the number of times the v | ||||
alue | ||||
* should be returned by check_expected(). If count is s | ||||
et | ||||
* to -1 the value will always be returned. | ||||
* | ||||
* @see check_expected(). | ||||
*/ | ||||
void expect_in_range_count(#function, #parameter, uintmax_t minimum, uintma | ||||
x_t maximum, size_t count); | ||||
#else | ||||
#define expect_in_range_count(function, parameter, minimum, maximum, count) \ | #define expect_in_range_count(function, parameter, minimum, maximum, count) \ | |||
_expect_in_range(#function, #parameter, __FILE__, __LINE__, minimum, \ | _expect_in_range(#function, #parameter, __FILE__, __LINE__, minimum, \ | |||
maximum, count) | maximum, count) | |||
#endif | ||||
/* | #if DOXYGEN | |||
* Add an event to check a parameter, using check_expected(), against a | /** | |||
* signed range. Where range is value < minimum or value > maximum. | * @brief Add an event to check a parameter is outside a numerical range. | |||
* See will_return() for a description of the count parameter. | * The check would succeed if minimum > value > maximum. | |||
* | ||||
* The event is triggered by calling check_expected() in the mocked functio | ||||
n. | ||||
* | ||||
* @param[in] #function The function to add the check for. | ||||
* | ||||
* @param[in] #parameter The name of the parameter passed to the function. | ||||
* | ||||
* @param[in] minimum The lower boundary of the interval to check against | ||||
. | ||||
* | ||||
* @param[in] maximum The upper boundary of the interval to check against | ||||
. | ||||
* | ||||
* @see check_expected(). | ||||
*/ | */ | |||
void expect_not_in_range(#function, #parameter, uintmax_t minimum, uintmax_ | ||||
t maximum); | ||||
#else | ||||
#define expect_not_in_range(function, parameter, minimum, maximum) \ | #define expect_not_in_range(function, parameter, minimum, maximum) \ | |||
expect_not_in_range_count(function, parameter, minimum, maximum, 1) | expect_not_in_range_count(function, parameter, minimum, maximum, 1) | |||
#endif | ||||
#if DOXYGEN | ||||
/** | ||||
* @brief 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 functio | ||||
n. | ||||
* | ||||
* @param[in] #function The function to add the check for. | ||||
* | ||||
* @param[in] #parameter The name of the parameter passed to the function. | ||||
* | ||||
* @param[in] minimum The lower boundary of the interval to check against | ||||
. | ||||
* | ||||
* @param[in] maximum The upper boundary of the interval to check against | ||||
. | ||||
* | ||||
* @param[in] count The count parameter returns the number of times the v | ||||
alue | ||||
* should be returned by check_expected(). If count is s | ||||
et | ||||
* to -1 the value will always be returned. | ||||
* | ||||
* @see check_expected(). | ||||
*/ | ||||
void expect_not_in_range_count(#function, #parameter, uintmax_t minimum, ui | ||||
ntmax_t maximum, size_t count); | ||||
#else | ||||
#define expect_not_in_range_count(function, parameter, minimum, maximum, \ | #define expect_not_in_range_count(function, parameter, minimum, maximum, \ | |||
count) \ | count) \ | |||
_expect_not_in_range(#function, #parameter, __FILE__, __LINE__, \ | _expect_not_in_range(#function, #parameter, __FILE__, __LINE__, \ | |||
minimum, maximum, count) | minimum, maximum, count) | |||
#endif | ||||
/* | #if DOXYGEN | |||
* Add an event to check whether a parameter, using check_expected(), is or | /** | |||
* isn't a value. See will_return() for a description of the count paramet | * @brief Add an event to check if a parameter is the given value. | |||
er. | * | |||
* The event is triggered by calling check_expected() in the mocked functio | ||||
n. | ||||
* | ||||
* @param[in] #function The function to add the check for. | ||||
* | ||||
* @param[in] #parameter The name of the parameter passed to the function. | ||||
* | ||||
* @param[in] value The value to check. | ||||
* | ||||
* @see check_expected(). | ||||
*/ | */ | |||
void expect_value(#function, #parameter, uintmax_t value); | ||||
#else | ||||
#define expect_value(function, parameter, value) \ | #define expect_value(function, parameter, value) \ | |||
expect_value_count(function, parameter, value, 1) | expect_value_count(function, parameter, value, 1) | |||
#endif | ||||
#if DOXYGEN | ||||
/** | ||||
* @brief Add an event to repeatedly check if a parameter is the given valu | ||||
e. | ||||
* | ||||
* The event is triggered by calling check_expected() in the mocked functio | ||||
n. | ||||
* | ||||
* @param[in] #function The function to add the check for. | ||||
* | ||||
* @param[in] #parameter The name of the parameter passed to the function. | ||||
* | ||||
* @param[in] value The value to check. | ||||
* | ||||
* @param[in] count The count parameter returns the number of times the v | ||||
alue | ||||
* should be returned by check_expected(). If count is s | ||||
et | ||||
* to -1 the value will always be returned. | ||||
* | ||||
* @see check_expected(). | ||||
*/ | ||||
void expect_value_count(#function, #parameter, uintmax_t value, size_t coun | ||||
t); | ||||
#else | ||||
#define expect_value_count(function, parameter, value, count) \ | #define expect_value_count(function, parameter, value, count) \ | |||
_expect_value(#function, #parameter, __FILE__, __LINE__, \ | _expect_value(#function, #parameter, __FILE__, __LINE__, \ | |||
cast_to_largest_integral_type(value), count) | cast_to_largest_integral_type(value), count) | |||
#endif | ||||
#if DOXYGEN | ||||
/** | ||||
* @brief Add an event to check if a parameter isn't the given value. | ||||
* | ||||
* The event is triggered by calling check_expected() in the mocked functio | ||||
n. | ||||
* | ||||
* @param[in] #function The function to add the check for. | ||||
* | ||||
* @param[in] #parameter The name of the parameter passed to the function. | ||||
* | ||||
* @param[in] value The value to check. | ||||
* | ||||
* @see check_expected(). | ||||
*/ | ||||
void expect_not_value(#function, #parameter, uintmax_t value); | ||||
#else | ||||
#define expect_not_value(function, parameter, value) \ | #define expect_not_value(function, parameter, value) \ | |||
expect_not_value_count(function, parameter, value, 1) | expect_not_value_count(function, parameter, value, 1) | |||
#endif | ||||
#if DOXYGEN | ||||
/** | ||||
* @brief Add an event to repeatedly check if a parameter isn't the given v | ||||
alue. | ||||
* | ||||
* The event is triggered by calling check_expected() in the mocked functio | ||||
n. | ||||
* | ||||
* @param[in] #function The function to add the check for. | ||||
* | ||||
* @param[in] #parameter The name of the parameter passed to the function. | ||||
* | ||||
* @param[in] value The value to check. | ||||
* | ||||
* @param[in] count The count parameter returns the number of times the v | ||||
alue | ||||
* should be returned by check_expected(). If count is s | ||||
et | ||||
* to -1 the value will always be returned. | ||||
* | ||||
* @see check_expected(). | ||||
*/ | ||||
void expect_not_value_count(#function, #parameter, uintmax_t value, size_t | ||||
count); | ||||
#else | ||||
#define expect_not_value_count(function, parameter, value, count) \ | #define expect_not_value_count(function, parameter, value, count) \ | |||
_expect_not_value(#function, #parameter, __FILE__, __LINE__, \ | _expect_not_value(#function, #parameter, __FILE__, __LINE__, \ | |||
cast_to_largest_integral_type(value), count) | cast_to_largest_integral_type(value), count) | |||
#endif | ||||
/* | #if DOXYGEN | |||
* Add an event to check whether a parameter, using check_expected(), | /** | |||
* is or isn't a string. See will_return() for a description of the count | * @brief Add an event to check if the parameter value is equal to the | |||
* parameter. | * provided string. | |||
* | ||||
* The event is triggered by calling check_expected() in the mocked functio | ||||
n. | ||||
* | ||||
* @param[in] #function The function to add the check for. | ||||
* | ||||
* @param[in] #parameter The name of the parameter passed to the function. | ||||
* | ||||
* @param[in] string The string value to compare. | ||||
* | ||||
* @see check_expected(). | ||||
*/ | */ | |||
void expect_string(#function, #parameter, const char *string); | ||||
#else | ||||
#define expect_string(function, parameter, string) \ | #define expect_string(function, parameter, string) \ | |||
expect_string_count(function, parameter, string, 1) | expect_string_count(function, parameter, string, 1) | |||
#endif | ||||
#if DOXYGEN | ||||
/** | ||||
* @brief 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 functio | ||||
n. | ||||
* | ||||
* @param[in] #function The function to add the check for. | ||||
* | ||||
* @param[in] #parameter The name of the parameter passed to the function. | ||||
* | ||||
* @param[in] string The string value to compare. | ||||
* | ||||
* @param[in] count The count parameter returns the number of times the v | ||||
alue | ||||
* should be returned by check_expected(). If count is s | ||||
et | ||||
* to -1 the value will always be returned. | ||||
* | ||||
* @see check_expected(). | ||||
*/ | ||||
void expect_string_count(#function, #parameter, const char *string, size_t | ||||
count); | ||||
#else | ||||
#define expect_string_count(function, parameter, string, count) \ | #define expect_string_count(function, parameter, string, count) \ | |||
_expect_string(#function, #parameter, __FILE__, __LINE__, \ | _expect_string(#function, #parameter, __FILE__, __LINE__, \ | |||
(const char*)(string), count) | (const char*)(string), count) | |||
#endif | ||||
#if DOXYGEN | ||||
/** | ||||
* @brief 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 functio | ||||
n. | ||||
* | ||||
* @param[in] #function The function to add the check for. | ||||
* | ||||
* @param[in] #parameter The name of the parameter passed to the function. | ||||
* | ||||
* @param[in] string The string value to compare. | ||||
* | ||||
* @see check_expected(). | ||||
*/ | ||||
void expect_not_string(#function, #parameter, const char *string); | ||||
#else | ||||
#define expect_not_string(function, parameter, string) \ | #define expect_not_string(function, parameter, string) \ | |||
expect_not_string_count(function, parameter, string, 1) | expect_not_string_count(function, parameter, string, 1) | |||
#endif | ||||
#if DOXYGEN | ||||
/** | ||||
* @brief 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 functio | ||||
n. | ||||
* | ||||
* @param[in] #function The function to add the check for. | ||||
* | ||||
* @param[in] #parameter The name of the parameter passed to the function. | ||||
* | ||||
* @param[in] string The string value to compare. | ||||
* | ||||
* @param[in] count The count parameter returns the number of times the v | ||||
alue | ||||
* should be returned by check_expected(). If count is s | ||||
et | ||||
* to -1 the value will always be returned. | ||||
* | ||||
* @see check_expected(). | ||||
*/ | ||||
void expect_not_string_count(#function, #parameter, const char *string, siz | ||||
e_t count); | ||||
#else | ||||
#define expect_not_string_count(function, parameter, string, count) \ | #define expect_not_string_count(function, parameter, string, count) \ | |||
_expect_not_string(#function, #parameter, __FILE__, __LINE__, \ | _expect_not_string(#function, #parameter, __FILE__, __LINE__, \ | |||
(const char*)(string), count) | (const char*)(string), count) | |||
#endif | ||||
/* | #if DOXYGEN | |||
* Add an event to check whether a parameter, using check_expected() does o | /** | |||
r | * @brief Add an event to check if the parameter does match an area of memo | |||
* doesn't match an area of memory. See will_return() for a description of | ry. | |||
* the count parameter. | * | |||
* The event is triggered by calling check_expected() in the mocked functio | ||||
n. | ||||
* | ||||
* @param[in] #function The function to add the check for. | ||||
* | ||||
* @param[in] #parameter The name of the parameter passed to the function. | ||||
* | ||||
* @param[in] memory The memory to compare. | ||||
* | ||||
* @param[in] size The size of the memory to compare. | ||||
* | ||||
* @see check_expected(). | ||||
*/ | */ | |||
void expect_memory(#function, #parameter, void *memory, size_t size); | ||||
#else | ||||
#define expect_memory(function, parameter, memory, size) \ | #define expect_memory(function, parameter, memory, size) \ | |||
expect_memory_count(function, parameter, memory, size, 1) | expect_memory_count(function, parameter, memory, size, 1) | |||
#endif | ||||
#if DOXYGEN | ||||
/** | ||||
* @brief Add an event to repeatedly check if the parameter does match an a | ||||
rea | ||||
* of memory. | ||||
* | ||||
* The event is triggered by calling check_expected() in the mocked functio | ||||
n. | ||||
* | ||||
* @param[in] #function The function to add the check for. | ||||
* | ||||
* @param[in] #parameter The name of the parameter passed to the function. | ||||
* | ||||
* @param[in] memory The memory to compare. | ||||
* | ||||
* @param[in] size The size of the memory to compare. | ||||
* | ||||
* @param[in] count The count parameter returns the number of times the v | ||||
alue | ||||
* should be returned by check_expected(). If count is s | ||||
et | ||||
* to -1 the value will always be returned. | ||||
* | ||||
* @see check_expected(). | ||||
*/ | ||||
void expect_memory_count(#function, #parameter, void *memory, size_t size, | ||||
size_t count); | ||||
#else | ||||
#define expect_memory_count(function, parameter, memory, size, count) \ | #define expect_memory_count(function, parameter, memory, size, count) \ | |||
_expect_memory(#function, #parameter, __FILE__, __LINE__, \ | _expect_memory(#function, #parameter, __FILE__, __LINE__, \ | |||
(const void*)(memory), size, count) | (const void*)(memory), size, count) | |||
#endif | ||||
#if DOXYGEN | ||||
/** | ||||
* @brief 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 functio | ||||
n. | ||||
* | ||||
* @param[in] #function The function to add the check for. | ||||
* | ||||
* @param[in] #parameter The name of the parameter passed to the function. | ||||
* | ||||
* @param[in] memory The memory to compare. | ||||
* | ||||
* @param[in] size The size of the memory to compare. | ||||
* | ||||
* @see check_expected(). | ||||
*/ | ||||
void expect_not_memory(#function, #parameter, void *memory, size_t size); | ||||
#else | ||||
#define expect_not_memory(function, parameter, memory, size) \ | #define expect_not_memory(function, parameter, memory, size) \ | |||
expect_not_memory_count(function, parameter, memory, size, 1) | expect_not_memory_count(function, parameter, memory, size, 1) | |||
#endif | ||||
#if DOXYGEN | ||||
/** | ||||
* @brief Add an event to repeatedly check if the parameter doesn't match a | ||||
n | ||||
* area of memory. | ||||
* | ||||
* The event is triggered by calling check_expected() in the mocked functio | ||||
n. | ||||
* | ||||
* @param[in] #function The function to add the check for. | ||||
* | ||||
* @param[in] #parameter The name of the parameter passed to the function. | ||||
* | ||||
* @param[in] memory The memory to compare. | ||||
* | ||||
* @param[in] size The size of the memory to compare. | ||||
* | ||||
* @param[in] count The count parameter returns the number of times the v | ||||
alue | ||||
* should be returned by check_expected(). If count is s | ||||
et | ||||
* to -1 the value will always be returned. | ||||
* | ||||
* @see check_expected(). | ||||
*/ | ||||
void expect_not_memory_count(#function, #parameter, void *memory, size_t si | ||||
ze, size_t count); | ||||
#else | ||||
#define expect_not_memory_count(function, parameter, memory, size, count) \ | #define expect_not_memory_count(function, parameter, memory, size, count) \ | |||
_expect_not_memory(#function, #parameter, __FILE__, __LINE__, \ | _expect_not_memory(#function, #parameter, __FILE__, __LINE__, \ | |||
(const void*)(memory), size, count) | (const void*)(memory), size, count) | |||
#endif | ||||
/* | #if DOXYGEN | |||
* Add an event to allow any value for a parameter checked using | /** | |||
* check_expected(). See will_return() for a description of the count | * @brief Add an event to check if a parameter (of any value) has been pass | |||
* parameter. | ed. | |||
* | ||||
* The event is triggered by calling check_expected() in the mocked functio | ||||
n. | ||||
* | ||||
* @param[in] #function The function to add the check for. | ||||
* | ||||
* @param[in] #parameter The name of the parameter passed to the function. | ||||
* | ||||
* @see check_expected(). | ||||
*/ | */ | |||
void expect_any(#function, #parameter); | ||||
#else | ||||
#define expect_any(function, parameter) \ | #define expect_any(function, parameter) \ | |||
expect_any_count(function, parameter, 1) | expect_any_count(function, parameter, 1) | |||
#endif | ||||
#if DOXYGEN | ||||
/** | ||||
* @brief Add an event to repeatedly check if a parameter (of any value) ha | ||||
s | ||||
* been passed. | ||||
* | ||||
* The event is triggered by calling check_expected() in the mocked functio | ||||
n. | ||||
* | ||||
* @param[in] #function The function to add the check for. | ||||
* | ||||
* @param[in] #parameter The name of the parameter passed to the function. | ||||
* | ||||
* @param[in] count The count parameter returns the number of times the v | ||||
alue | ||||
* should be returned by check_expected(). If count is s | ||||
et | ||||
* to -1 the value will always be returned. | ||||
* | ||||
* @see check_expected(). | ||||
*/ | ||||
void expect_any_count(#function, #parameter, size_t count); | ||||
#else | ||||
#define expect_any_count(function, parameter, count) \ | #define expect_any_count(function, parameter, count) \ | |||
_expect_any(#function, #parameter, __FILE__, __LINE__, count) | _expect_any(#function, #parameter, __FILE__, __LINE__, count) | |||
#endif | ||||
#if DOXYGEN | #if DOXYGEN | |||
/** | /** | |||
* @brief Determine whether a function parameter is correct. | * @brief Determine whether a function parameter is correct. | |||
* | * | |||
* This ensures the next value queued by one of the expect_*() macros match es | * This ensures the next value queued by one of the expect_*() macros match es | |||
* the specified variable. | * the specified variable. | |||
* | * | |||
* This function needs to be called in the mock object. | ||||
* | ||||
* @param[in] #parameter The parameter to check. | * @param[in] #parameter The parameter to check. | |||
*/ | */ | |||
void check_expected(#parameter); | void check_expected(#parameter); | |||
#else | #else | |||
#define check_expected(parameter) \ | #define check_expected(parameter) \ | |||
_check_expected(__func__, #parameter, __FILE__, __LINE__, \ | _check_expected(__func__, #parameter, __FILE__, __LINE__, \ | |||
cast_to_largest_integral_type(parameter)) | cast_to_largest_integral_type(parameter)) | |||
#endif | #endif | |||
/** @} */ | /** @} */ | |||
End of changes. 40 change blocks. | ||||
29 lines changed or deleted | 655 lines changed or added | |||