cmocka.h | cmocka.h | |||
---|---|---|---|---|
skipping to change at line 20 | skipping to change at line 20 | |||
* Unless required by applicable law or agreed to in writing, software | * Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, | * distributed under the License is distributed on an "AS IS" BASIS, | |||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
* See the License for the specific language governing permissions and | * See the License for the specific language governing permissions and | |||
* limitations under the License. | * limitations under the License. | |||
*/ | */ | |||
#ifndef CMOCKA_H_ | #ifndef CMOCKA_H_ | |||
#define CMOCKA_H_ | #define CMOCKA_H_ | |||
#ifdef _WIN32 | #ifdef _WIN32 | |||
#if _MSC_VER < 1500 | # ifdef _MSC_VER | |||
#ifdef __cplusplus | ||||
# ifndef inline | ||||
#define inline __inline | ||||
# endif /* inline */ | ||||
# if _MSC_VER < 1500 | ||||
# ifdef __cplusplus | ||||
extern "C" { | extern "C" { | |||
#endif /* __cplusplus */ | # endif /* __cplusplus */ | |||
int __stdcall IsDebuggerPresent(); | int __stdcall IsDebuggerPresent(); | |||
#ifdef __cplusplus | # ifdef __cplusplus | |||
} /* extern "C" */ | } /* extern "C" */ | |||
#endif /* __cplusplus */ | # endif /* __cplusplus */ | |||
#endif /* _MSC_VER < 1500 */ | # endif /* _MSC_VER < 1500 */ | |||
# endif /* _MSC_VER */ | ||||
#endif /* _WIN32 */ | #endif /* _WIN32 */ | |||
/* | /* | |||
* These headers or their equivalents should be included prior to including | * These headers or their equivalents should be included prior to including | |||
* this header file. | * this header file. | |||
* | * | |||
* #include <stdarg.h> | * #include <stdarg.h> | |||
* #include <stddef.h> | * #include <stddef.h> | |||
* #include <setjmp.h> | * #include <setjmp.h> | |||
* | * | |||
skipping to change at line 50 | skipping to change at line 57 | |||
* library functions and types. | * library functions and types. | |||
*/ | */ | |||
/* For those who are used to __func__ from gcc. */ | /* For those who are used to __func__ from gcc. */ | |||
#ifndef __func__ | #ifndef __func__ | |||
#define __func__ __FUNCTION__ | #define __func__ __FUNCTION__ | |||
#endif | #endif | |||
/* GCC have printf type attribute check. */ | /* GCC have printf type attribute check. */ | |||
#ifdef __GNUC__ | #ifdef __GNUC__ | |||
#define PRINTF_ATTRIBUTE(a,b) __attribute__ ((__format__ (__printf__, a, b) | #define CMOCKA_PRINTF_ATTRIBUTE(a,b) \ | |||
)) | __attribute__ ((__format__ (__printf__, a, b))) | |||
#else | #else | |||
#define PRINTF_ATTRIBUTE(a,b) | #define CMOCKA_PRINTF_ATTRIBUTE(a,b) | |||
#endif /* __GNUC__ */ | #endif /* __GNUC__ */ | |||
/** | /** | |||
* @defgroup cmocka The CMocka API | * @defgroup cmocka The CMocka API | |||
* | * | |||
* TODO Describe cmocka. | * TODO Describe cmocka. | |||
* | * | |||
* @{ | * @{ | |||
*/ | */ | |||
skipping to change at line 74 | skipping to change at line 82 | |||
* Largest integral type. This type should be large enough to hold any | * Largest integral type. This type should be large enough to hold any | |||
* pointer or integer supported by the compiler. | * pointer or integer supported by the compiler. | |||
*/ | */ | |||
#ifndef LargestIntegralType | #ifndef LargestIntegralType | |||
#define LargestIntegralType unsigned long long | #define LargestIntegralType unsigned long long | |||
#endif /* LargestIntegralType */ | #endif /* LargestIntegralType */ | |||
/* Printf format used to display LargestIntegralType. */ | /* Printf format used to display LargestIntegralType. */ | |||
#ifndef LargestIntegralTypePrintfFormat | #ifndef LargestIntegralTypePrintfFormat | |||
#ifdef _WIN32 | #ifdef _WIN32 | |||
#define LargestIntegralTypePrintfFormat "%I64x" | #define LargestIntegralTypePrintfFormat "0x%I64x" | |||
#else | #else | |||
#define LargestIntegralTypePrintfFormat "%llx" | #define LargestIntegralTypePrintfFormat "%#llx" | |||
#endif /* _WIN32 */ | #endif /* _WIN32 */ | |||
#endif /* LargestIntegralTypePrintfFormat */ | #endif /* LargestIntegralTypePrintfFormat */ | |||
/* Perform an unsigned cast to LargestIntegralType. */ | /* Perform an unsigned cast to LargestIntegralType. */ | |||
#define cast_to_largest_integral_type(value) \ | #define cast_to_largest_integral_type(value) \ | |||
((LargestIntegralType)((size_t)(value))) | ((LargestIntegralType)((size_t)(value))) | |||
/* Smallest integral type capable of holding a pointer. */ | /* Smallest integral type capable of holding a pointer. */ | |||
#if !defined(_UINTPTR_T) && !defined(_UINTPTR_T_DEFINED) | #if !defined(_UINTPTR_T) && !defined(_UINTPTR_T_DEFINED) | |||
# if defined(_WIN32) | # if defined(_WIN32) | |||
skipping to change at line 370 | skipping to change at line 378 | |||
* be deallocated by the caller. | * be deallocated by the caller. | |||
*/ | */ | |||
#ifdef DOXYGEN | #ifdef DOXYGEN | |||
/** | /** | |||
* @brief Add a custom parameter checking function. | * @brief Add a custom parameter checking function. | |||
* | * | |||
* If the event parameter is NULL the event structure is allocated internal ly | * If the event parameter is NULL the event structure is allocated internal ly | |||
* by this function. If the parameter is provided it must be allocated on t he | * by this function. If the parameter is provided it must be allocated on t he | |||
* heap and doesn't need to be deallocated by the caller. | * heap and doesn't need to be deallocated by the caller. | |||
* | * | |||
* @param[in] #function The fuction to add a custom paramater checking fu | * @param[in] #function The function to add a custom parameter checking | |||
nction | * function for. | |||
* for. | ||||
* | * | |||
* @param[in] #parameter The parametes passed to the function. | * @param[in] #parameter The parameters passed to the function. | |||
* | * | |||
* @param[in] #check_function The check function to call. | * @param[in] #check_function The check function to call. | |||
* | * | |||
* @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 | #ifdef DOXYGEN | |||
/** | /** | |||
* @brief Add an event to check if the parameter value is part of the provi ded | * @brief Add an event to check if the parameter value is part of the provi ded | |||
* array. | * array. | |||
* | * | |||
* The event is triggered by calling check_expected() in the mocked functio n. | * 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] #function The function to add the check for. | |||
* | * | |||
* @param[in] #parameter The name of the parameter passed to the function. | * @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] value_array[] The array to check for the value. | |||
* | * | |||
* @see check_expected(). | * @see check_expected(). | |||
*/ | */ | |||
void expect_in_set(#function, #parameter, uintmax_t value_array[]); | void expect_in_set(#function, #parameter, uintmax_t value_array[]); | |||
#else | #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 | #endif | |||
#if DOXYGEN | #ifdef DOXYGEN | |||
/** | /** | |||
* @brief Add an event to check if the parameter value is part of the provi ded | * @brief Add an event to check if the parameter value is part of the provi ded | |||
* array. | * array. | |||
* | * | |||
* The event is triggered by calling check_expected() in the mocked functio n. | * 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] #function The function to add the check for. | |||
* | * | |||
* @param[in] #parameter The name of the parameter passed to the function. | * @param[in] #parameter The name of the parameter passed to the function. | |||
* | * | |||
skipping to change at line 433 | skipping to change at line 441 | |||
* | * | |||
* @see check_expected(). | * @see check_expected(). | |||
*/ | */ | |||
void expect_in_set_count(#function, #parameter, uintmax_t value_array[], si ze_t count); | void expect_in_set_count(#function, #parameter, uintmax_t value_array[], si ze_t count); | |||
#else | #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 | #endif | |||
#if DOXYGEN | #ifdef DOXYGEN | |||
/** | /** | |||
* @brief Add an event to check if the parameter value is not part of the | * @brief Add an event to check if the parameter value is not part of the | |||
* provided array. | * provided array. | |||
* | * | |||
* The event is triggered by calling check_expected() in the mocked functio n. | * 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] #function The function to add the check for. | |||
* | * | |||
* @param[in] #parameter The name of the parameter passed to the function. | * @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] value_array[] The array to check for the value. | |||
* | * | |||
* @see check_expected(). | * @see check_expected(). | |||
*/ | */ | |||
void expect_not_in_set(#function, #parameter, uintmax_t value_array[]); | void expect_not_in_set(#function, #parameter, uintmax_t value_array[]); | |||
#else | #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 | #endif | |||
#if DOXYGEN | #ifdef DOXYGEN | |||
/** | /** | |||
* @brief Add an event to check if the parameter value is not part of the | * @brief Add an event to check if the parameter value is not part of the | |||
* provided array. | * provided array. | |||
* | * | |||
* The event is triggered by calling check_expected() in the mocked functio n. | * 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] #function The function to add the check for. | |||
* | * | |||
* @param[in] #parameter The name of the parameter passed to the function. | * @param[in] #parameter The name of the parameter passed to the function. | |||
* | * | |||
skipping to change at line 481 | skipping to change at line 489 | |||
* @see check_expected(). | * @see check_expected(). | |||
*/ | */ | |||
void expect_not_in_set_count(#function, #parameter, uintmax_t value_array[] , size_t count); | void expect_not_in_set_count(#function, #parameter, uintmax_t value_array[] , size_t count); | |||
#else | #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 | #endif | |||
#if DOXYGEN | #ifdef DOXYGEN | |||
/** | /** | |||
* @brief Add an event to check a parameter is inside a numerical range. | * @brief Add an event to check a parameter is inside a numerical range. | |||
* The check would succeed if minimum <= value <= maximum. | * The check would succeed if minimum <= value <= maximum. | |||
* | * | |||
* The event is triggered by calling check_expected() in the mocked functio n. | * 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] #function The function to add the check for. | |||
* | * | |||
* @param[in] #parameter The name of the parameter passed to the function. | * @param[in] #parameter The name of the parameter passed to the function. | |||
* | * | |||
skipping to change at line 504 | skipping to change at line 512 | |||
* @param[in] maximum The upper boundary of the interval to check against . | * @param[in] maximum The upper boundary of the interval to check against . | |||
* | * | |||
* @see check_expected(). | * @see check_expected(). | |||
*/ | */ | |||
void expect_in_range(#function, #parameter, uintmax_t minimum, uintmax_t ma ximum); | void expect_in_range(#function, #parameter, uintmax_t minimum, uintmax_t ma ximum); | |||
#else | #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 | #endif | |||
#if DOXYGEN | #ifdef DOXYGEN | |||
/** | /** | |||
* @brief Add an event to repeatedly check a parameter is inside a | * @brief Add an event to repeatedly check a parameter is inside a | |||
* numerical range. The check would succeed if minimum <= value <= maximum. | * numerical range. The check would succeed if minimum <= value <= maximum. | |||
* | * | |||
* The event is triggered by calling check_expected() in the mocked functio n. | * 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] #function The function to add the check for. | |||
* | * | |||
* @param[in] #parameter The name of the parameter passed to the function. | * @param[in] #parameter The name of the parameter passed to the function. | |||
* | * | |||
skipping to change at line 532 | skipping to change at line 540 | |||
* | * | |||
* @see check_expected(). | * @see check_expected(). | |||
*/ | */ | |||
void expect_in_range_count(#function, #parameter, uintmax_t minimum, uintma x_t maximum, size_t count); | void expect_in_range_count(#function, #parameter, uintmax_t minimum, uintma x_t maximum, size_t count); | |||
#else | #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 | #endif | |||
#if DOXYGEN | #ifdef DOXYGEN | |||
/** | /** | |||
* @brief Add an event to check a parameter is outside a numerical range. | * @brief Add an event to check a parameter is outside a numerical range. | |||
* The check would succeed if minimum > value > maximum. | * The check would succeed if minimum > value > maximum. | |||
* | * | |||
* The event is triggered by calling check_expected() in the mocked functio n. | * 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] #function The function to add the check for. | |||
* | * | |||
* @param[in] #parameter The name of the parameter passed to the function. | * @param[in] #parameter The name of the parameter passed to the function. | |||
* | * | |||
skipping to change at line 555 | skipping to change at line 563 | |||
* @param[in] maximum The upper boundary of the interval to check against . | * @param[in] maximum The upper boundary of the interval to check against . | |||
* | * | |||
* @see check_expected(). | * @see check_expected(). | |||
*/ | */ | |||
void expect_not_in_range(#function, #parameter, uintmax_t minimum, uintmax_ t maximum); | void expect_not_in_range(#function, #parameter, uintmax_t minimum, uintmax_ t maximum); | |||
#else | #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 | #endif | |||
#if DOXYGEN | #ifdef DOXYGEN | |||
/** | /** | |||
* @brief Add an event to repeatedly check a parameter is outside a | * @brief Add an event to repeatedly check a parameter is outside a | |||
* numerical range. The check would succeed if minimum > value > maximum. | * numerical range. The check would succeed if minimum > value > maximum. | |||
* | * | |||
* The event is triggered by calling check_expected() in the mocked functio n. | * 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] #function The function to add the check for. | |||
* | * | |||
* @param[in] #parameter The name of the parameter passed to the function. | * @param[in] #parameter The name of the parameter passed to the function. | |||
* | * | |||
skipping to change at line 584 | skipping to change at line 592 | |||
* @see check_expected(). | * @see check_expected(). | |||
*/ | */ | |||
void expect_not_in_range_count(#function, #parameter, uintmax_t minimum, ui ntmax_t maximum, size_t count); | void expect_not_in_range_count(#function, #parameter, uintmax_t minimum, ui ntmax_t maximum, size_t count); | |||
#else | #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 | #endif | |||
#if DOXYGEN | #ifdef DOXYGEN | |||
/** | /** | |||
* @brief Add an event to check if a parameter is the given value. | * @brief Add an event to check if a parameter is the given value. | |||
* | * | |||
* The event is triggered by calling check_expected() in the mocked functio n. | * 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] #function The function to add the check for. | |||
* | * | |||
* @param[in] #parameter The name of the parameter passed to the function. | * @param[in] #parameter The name of the parameter passed to the function. | |||
* | * | |||
* @param[in] value The value to check. | * @param[in] value The value to check. | |||
* | * | |||
* @see check_expected(). | * @see check_expected(). | |||
*/ | */ | |||
void expect_value(#function, #parameter, uintmax_t value); | void expect_value(#function, #parameter, uintmax_t value); | |||
#else | #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 | #endif | |||
#if DOXYGEN | #ifdef DOXYGEN | |||
/** | /** | |||
* @brief Add an event to repeatedly check if a parameter is the given valu e. | * @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. | * 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] #function The function to add the check for. | |||
* | * | |||
* @param[in] #parameter The name of the parameter passed to the function. | * @param[in] #parameter The name of the parameter passed to the function. | |||
* | * | |||
* @param[in] value The value to check. | * @param[in] value The value to check. | |||
skipping to change at line 629 | skipping to change at line 637 | |||
* | * | |||
* @see check_expected(). | * @see check_expected(). | |||
*/ | */ | |||
void expect_value_count(#function, #parameter, uintmax_t value, size_t coun t); | void expect_value_count(#function, #parameter, uintmax_t value, size_t coun t); | |||
#else | #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 | #endif | |||
#if DOXYGEN | #ifdef DOXYGEN | |||
/** | /** | |||
* @brief Add an event to check if a parameter isn't the given value. | * @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. | * 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] #function The function to add the check for. | |||
* | * | |||
* @param[in] #parameter The name of the parameter passed to the function. | * @param[in] #parameter The name of the parameter passed to the function. | |||
* | * | |||
* @param[in] value The value to check. | * @param[in] value The value to check. | |||
* | * | |||
* @see check_expected(). | * @see check_expected(). | |||
*/ | */ | |||
void expect_not_value(#function, #parameter, uintmax_t value); | void expect_not_value(#function, #parameter, uintmax_t value); | |||
#else | #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 | #endif | |||
#if DOXYGEN | #ifdef DOXYGEN | |||
/** | /** | |||
* @brief Add an event to repeatedly check if a parameter isn't the given v alue. | * @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. | * 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] #function The function to add the check for. | |||
* | * | |||
* @param[in] #parameter The name of the parameter passed to the function. | * @param[in] #parameter The name of the parameter passed to the function. | |||
* | * | |||
* @param[in] value The value to check. | * @param[in] value The value to check. | |||
skipping to change at line 674 | skipping to change at line 682 | |||
* | * | |||
* @see check_expected(). | * @see check_expected(). | |||
*/ | */ | |||
void expect_not_value_count(#function, #parameter, uintmax_t value, size_t count); | void expect_not_value_count(#function, #parameter, uintmax_t value, size_t count); | |||
#else | #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 | #endif | |||
#if DOXYGEN | #ifdef DOXYGEN | |||
/** | /** | |||
* @brief Add an event to check if the parameter value is equal to the | * @brief Add an event to check if the parameter value is equal to the | |||
* provided string. | * provided string. | |||
* | * | |||
* The event is triggered by calling check_expected() in the mocked functio n. | * 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] #function The function to add the check for. | |||
* | * | |||
* @param[in] #parameter The name of the parameter passed to the function. | * @param[in] #parameter The name of the parameter passed to the function. | |||
* | * | |||
* @param[in] string The string value to compare. | * @param[in] string The string value to compare. | |||
* | * | |||
* @see check_expected(). | * @see check_expected(). | |||
*/ | */ | |||
void expect_string(#function, #parameter, const char *string); | void expect_string(#function, #parameter, const char *string); | |||
#else | #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 | #endif | |||
#if DOXYGEN | #ifdef DOXYGEN | |||
/** | /** | |||
* @brief Add an event to check if the parameter value is equal to the | * @brief Add an event to check if the parameter value is equal to the | |||
* provided string. | * provided string. | |||
* | * | |||
* The event is triggered by calling check_expected() in the mocked functio n. | * 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] #function The function to add the check for. | |||
* | * | |||
* @param[in] #parameter The name of the parameter passed to the function. | * @param[in] #parameter The name of the parameter passed to the function. | |||
* | * | |||
skipping to change at line 721 | skipping to change at line 729 | |||
* | * | |||
* @see check_expected(). | * @see check_expected(). | |||
*/ | */ | |||
void expect_string_count(#function, #parameter, const char *string, size_t count); | void expect_string_count(#function, #parameter, const char *string, size_t count); | |||
#else | #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 | #endif | |||
#if DOXYGEN | #ifdef DOXYGEN | |||
/** | /** | |||
* @brief Add an event to check if the parameter value isn't equal to the | * @brief Add an event to check if the parameter value isn't equal to the | |||
* provided string. | * provided string. | |||
* | * | |||
* The event is triggered by calling check_expected() in the mocked functio n. | * 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] #function The function to add the check for. | |||
* | * | |||
* @param[in] #parameter The name of the parameter passed to the function. | * @param[in] #parameter The name of the parameter passed to the function. | |||
* | * | |||
* @param[in] string The string value to compare. | * @param[in] string The string value to compare. | |||
* | * | |||
* @see check_expected(). | * @see check_expected(). | |||
*/ | */ | |||
void expect_not_string(#function, #parameter, const char *string); | void expect_not_string(#function, #parameter, const char *string); | |||
#else | #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 | #endif | |||
#if DOXYGEN | #ifdef DOXYGEN | |||
/** | /** | |||
* @brief Add an event to check if the parameter value isn't equal to the | * @brief Add an event to check if the parameter value isn't equal to the | |||
* provided string. | * provided string. | |||
* | * | |||
* The event is triggered by calling check_expected() in the mocked functio n. | * 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] #function The function to add the check for. | |||
* | * | |||
* @param[in] #parameter The name of the parameter passed to the function. | * @param[in] #parameter The name of the parameter passed to the function. | |||
* | * | |||
skipping to change at line 768 | skipping to change at line 776 | |||
* | * | |||
* @see check_expected(). | * @see check_expected(). | |||
*/ | */ | |||
void expect_not_string_count(#function, #parameter, const char *string, siz e_t count); | void expect_not_string_count(#function, #parameter, const char *string, siz e_t count); | |||
#else | #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 | #endif | |||
#if DOXYGEN | #ifdef DOXYGEN | |||
/** | /** | |||
* @brief Add an event to check if the parameter does match an area of memo ry. | * @brief Add an event to check if the parameter does match an area of memo ry. | |||
* | * | |||
* The event is triggered by calling check_expected() in the mocked functio n. | * 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] #function The function to add the check for. | |||
* | * | |||
* @param[in] #parameter The name of the parameter passed to the function. | * @param[in] #parameter The name of the parameter passed to the function. | |||
* | * | |||
* @param[in] memory The memory to compare. | * @param[in] memory The memory to compare. | |||
skipping to change at line 790 | skipping to change at line 798 | |||
* @param[in] size The size of the memory to compare. | * @param[in] size The size of the memory to compare. | |||
* | * | |||
* @see check_expected(). | * @see check_expected(). | |||
*/ | */ | |||
void expect_memory(#function, #parameter, void *memory, size_t size); | void expect_memory(#function, #parameter, void *memory, size_t size); | |||
#else | #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 | #endif | |||
#if DOXYGEN | #ifdef DOXYGEN | |||
/** | /** | |||
* @brief Add an event to repeatedly check if the parameter does match an a rea | * @brief Add an event to repeatedly check if the parameter does match an a rea | |||
* of memory. | * of memory. | |||
* | * | |||
* The event is triggered by calling check_expected() in the mocked functio n. | * 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] #function The function to add the check for. | |||
* | * | |||
* @param[in] #parameter The name of the parameter passed to the function. | * @param[in] #parameter The name of the parameter passed to the function. | |||
* | * | |||
skipping to change at line 818 | skipping to change at line 826 | |||
* | * | |||
* @see check_expected(). | * @see check_expected(). | |||
*/ | */ | |||
void expect_memory_count(#function, #parameter, void *memory, size_t size, size_t count); | void expect_memory_count(#function, #parameter, void *memory, size_t size, size_t count); | |||
#else | #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 | #endif | |||
#if DOXYGEN | #ifdef DOXYGEN | |||
/** | /** | |||
* @brief Add an event to check if the parameter doesn't match an area of | * @brief Add an event to check if the parameter doesn't match an area of | |||
* memory. | * memory. | |||
* | * | |||
* The event is triggered by calling check_expected() in the mocked functio n. | * 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] #function The function to add the check for. | |||
* | * | |||
* @param[in] #parameter The name of the parameter passed to the function. | * @param[in] #parameter The name of the parameter passed to the function. | |||
* | * | |||
skipping to change at line 841 | skipping to change at line 849 | |||
* @param[in] size The size of the memory to compare. | * @param[in] size The size of the memory to compare. | |||
* | * | |||
* @see check_expected(). | * @see check_expected(). | |||
*/ | */ | |||
void expect_not_memory(#function, #parameter, void *memory, size_t size); | void expect_not_memory(#function, #parameter, void *memory, size_t size); | |||
#else | #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 | #endif | |||
#if DOXYGEN | #ifdef DOXYGEN | |||
/** | /** | |||
* @brief Add an event to repeatedly check if the parameter doesn't match a n | * @brief Add an event to repeatedly check if the parameter doesn't match a n | |||
* area of memory. | * area of memory. | |||
* | * | |||
* The event is triggered by calling check_expected() in the mocked functio n. | * 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] #function The function to add the check for. | |||
* | * | |||
* @param[in] #parameter The name of the parameter passed to the function. | * @param[in] #parameter The name of the parameter passed to the function. | |||
* | * | |||
skipping to change at line 869 | skipping to change at line 877 | |||
* | * | |||
* @see check_expected(). | * @see check_expected(). | |||
*/ | */ | |||
void expect_not_memory_count(#function, #parameter, void *memory, size_t si ze, size_t count); | void expect_not_memory_count(#function, #parameter, void *memory, size_t si ze, size_t count); | |||
#else | #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 | #endif | |||
#if DOXYGEN | #ifdef DOXYGEN | |||
/** | /** | |||
* @brief Add an event to check if a parameter (of any value) has been pass ed. | * @brief Add an event to check if a parameter (of any value) has been pass ed. | |||
* | * | |||
* The event is triggered by calling check_expected() in the mocked functio n. | * 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] #function The function to add the check for. | |||
* | * | |||
* @param[in] #parameter The name of the parameter passed to the function. | * @param[in] #parameter The name of the parameter passed to the function. | |||
* | * | |||
* @see check_expected(). | * @see check_expected(). | |||
*/ | */ | |||
void expect_any(#function, #parameter); | void expect_any(#function, #parameter); | |||
#else | #else | |||
#define expect_any(function, parameter) \ | #define expect_any(function, parameter) \ | |||
expect_any_count(function, parameter, 1) | expect_any_count(function, parameter, 1) | |||
#endif | #endif | |||
#if DOXYGEN | #ifdef DOXYGEN | |||
/** | /** | |||
* @brief Add an event to repeatedly check if a parameter (of any value) ha s | * @brief Add an event to repeatedly check if a parameter (of any value) ha s | |||
* been passed. | * been passed. | |||
* | * | |||
* The event is triggered by calling check_expected() in the mocked functio n. | * 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] #function The function to add the check for. | |||
* | * | |||
* @param[in] #parameter The name of the parameter passed to the function. | * @param[in] #parameter The name of the parameter passed to the function. | |||
* | * | |||
skipping to change at line 910 | skipping to change at line 918 | |||
* to -1 the value will always be returned. | * to -1 the value will always be returned. | |||
* | * | |||
* @see check_expected(). | * @see check_expected(). | |||
*/ | */ | |||
void expect_any_count(#function, #parameter, size_t count); | void expect_any_count(#function, #parameter, size_t count); | |||
#else | #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 | #endif | |||
#if DOXYGEN | #ifdef 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. | * This function needs to be called in the mock object. | |||
* | * | |||
* @param[in] #parameter The parameter to check. | * @param[in] #parameter The parameter to check. | |||
*/ | */ | |||
skipping to change at line 988 | skipping to change at line 996 | |||
* @see assert_string_equal() | * @see assert_string_equal() | |||
*/ | */ | |||
void assert_false(scalar expression); | void assert_false(scalar expression); | |||
#else | #else | |||
#define assert_false(c) _assert_true(!(cast_to_largest_integral_type(c)), # c, \ | #define assert_false(c) _assert_true(!(cast_to_largest_integral_type(c)), # c, \ | |||
__FILE__, __LINE__) | __FILE__, __LINE__) | |||
#endif | #endif | |||
#ifdef DOXYGEN | #ifdef DOXYGEN | |||
/** | /** | |||
* @brief Assert if the return_code is smaller than 0. | ||||
* | ||||
* The function prints an error message to standard error and terminates th | ||||
e | ||||
* test by calling fail() if the return code is smaller than 0. If the func | ||||
tion | ||||
* you check sets an errno if it fails you can pass it to the function and | ||||
* it will be printed as part of the error message. | ||||
* | ||||
* @param[in] rc The return code to evaluate. | ||||
* | ||||
* @param[in] error Pass errno here or 0. | ||||
*/ | ||||
void assert_return_code(int rc, int error); | ||||
#else | ||||
#define assert_return_code(rc, error) \ | ||||
_assert_return_code(cast_to_largest_integral_type(rc), \ | ||||
sizeof(rc), \ | ||||
cast_to_largest_integral_type(error), \ | ||||
#rc, __FILE__, __LINE__) | ||||
#endif | ||||
#ifdef DOXYGEN | ||||
/** | ||||
* @brief Assert that the given pointer is non-NULL. | * @brief Assert that the given pointer is non-NULL. | |||
* | * | |||
* The function prints an error message to standard error and terminates th e | * The function prints an error message to standard error and terminates th e | |||
* test by calling fail() if the pointer is non-NULL. | * test by calling fail() if the pointer is non-NULL. | |||
* | * | |||
* @param[in] pointer The pointer to evaluate. | * @param[in] pointer The pointer to evaluate. | |||
* | * | |||
* @see assert_null() | * @see assert_null() | |||
*/ | */ | |||
void assert_non_null(void *pointer); | void assert_non_null(void *pointer); | |||
skipping to change at line 1296 | skipping to change at line 1326 | |||
* int main(void) { | * int main(void) { | |||
* return run_test(null_test_success); | * return run_test(null_test_success); | |||
* } | * } | |||
* @endcode | * @endcode | |||
*/ | */ | |||
int run_test(#function); | int run_test(#function); | |||
#else | #else | |||
#define run_test(f) _run_test(#f, f, NULL, UNIT_TEST_FUNCTION_TYPE_TEST, NU LL) | #define run_test(f) _run_test(#f, f, NULL, UNIT_TEST_FUNCTION_TYPE_TEST, NU LL) | |||
#endif | #endif | |||
static inline void _unit_test_dummy(void **state) { | ||||
(void)state; | ||||
} | ||||
/** Initializes a UnitTest structure. */ | /** Initializes a UnitTest structure. */ | |||
#define unit_test(f) { #f, f, UNIT_TEST_FUNCTION_TYPE_TEST } | #define unit_test(f) { #f, f, UNIT_TEST_FUNCTION_TYPE_TEST } | |||
#define _unit_test_setup(test, setup) \ | #define _unit_test_setup(test, setup) \ | |||
{ #test "_" #setup, setup, UNIT_TEST_FUNCTION_TYPE_SETUP } | { #test "_" #setup, setup, UNIT_TEST_FUNCTION_TYPE_SETUP } | |||
/** Initializes a UnitTest structure with a setup function. */ | /** Initializes a UnitTest structure with a setup function. */ | |||
#define unit_test_setup(test, setup) \ | #define unit_test_setup(test, setup) \ | |||
_unit_test_setup(test, setup), \ | _unit_test_setup(test, setup), \ | |||
unit_test(test) | unit_test(test), \ | |||
_unit_test_teardown(test, _unit_test_dummy) | ||||
#define _unit_test_teardown(test, teardown) \ | #define _unit_test_teardown(test, teardown) \ | |||
{ #test "_" #teardown, teardown, UNIT_TEST_FUNCTION_TYPE_TEARDOWN } | { #test "_" #teardown, teardown, UNIT_TEST_FUNCTION_TYPE_TEARDOWN } | |||
/** Initializes a UnitTest structure with a teardown function. */ | /** Initializes a UnitTest structure with a teardown function. */ | |||
#define unit_test_teardown(test, teardown) \ | #define unit_test_teardown(test, teardown) \ | |||
_unit_test_setup(test, _unit_test_dummy), \ | ||||
unit_test(test), \ | unit_test(test), \ | |||
_unit_test_teardown(test, teardown) | _unit_test_teardown(test, teardown) | |||
#define group_test_setup(setup) \ | ||||
{ "group_" #setup, setup, UNIT_TEST_FUNCTION_TYPE_GROUP_SETUP } | ||||
#define group_test_teardown(teardown) \ | ||||
{ "group_" #teardown, teardown, UNIT_TEST_FUNCTION_TYPE_GROUP_TEARDOWN | ||||
} | ||||
/** | /** | |||
* Initialize an array of UnitTest structures with a setup function for a t est | * Initialize an array of UnitTest structures with a setup function for a t est | |||
* and a teardown function. Either setup or teardown can be NULL. | * and a teardown function. Either setup or teardown can be NULL. | |||
*/ | */ | |||
#define unit_test_setup_teardown(test, setup, teardown) \ | #define unit_test_setup_teardown(test, setup, teardown) \ | |||
_unit_test_setup(test, setup), \ | _unit_test_setup(test, setup), \ | |||
unit_test(test), \ | unit_test(test), \ | |||
_unit_test_teardown(test, teardown) | _unit_test_teardown(test, teardown) | |||
#ifdef DOXYGEN | #ifdef DOXYGEN | |||
skipping to change at line 1375 | skipping to change at line 1417 | |||
* @see unit_test | * @see unit_test | |||
* @see unit_test_setup | * @see unit_test_setup | |||
* @see unit_test_teardown | * @see unit_test_teardown | |||
* @see unit_test_setup_teardown | * @see unit_test_setup_teardown | |||
*/ | */ | |||
int run_tests(const UnitTest tests[]); | int run_tests(const UnitTest tests[]); | |||
#else | #else | |||
#define run_tests(tests) _run_tests(tests, sizeof(tests) / sizeof(tests)[0] ) | #define run_tests(tests) _run_tests(tests, sizeof(tests) / sizeof(tests)[0] ) | |||
#endif | #endif | |||
#define run_group_tests(tests) _run_group_tests(tests, sizeof(tests) / size | ||||
of(tests)[0]) | ||||
/** @} */ | /** @} */ | |||
/** | /** | |||
* @defgroup cmocka_alloc Dynamic Memory Allocation | * @defgroup cmocka_alloc Dynamic Memory Allocation | |||
* @ingroup cmocka | * @ingroup cmocka | |||
* | * | |||
* Memory leaks, buffer overflows and underflows can be checked using cmock a. | * Memory leaks, buffer overflows and underflows can be checked using cmock a. | |||
* | * | |||
* To test for memory leaks, buffer overflows and underflows a module being | * To test for memory leaks, buffer overflows and underflows a module being | |||
* tested by cmocka should replace calls to malloc(), calloc() and free() t o | * tested by cmocka should replace calls to malloc(), calloc() and free() t o | |||
skipping to change at line 1409 | skipping to change at line 1453 | |||
#ifdef DOXYGEN | #ifdef DOXYGEN | |||
/** | /** | |||
* @brief Test function overriding malloc. | * @brief Test function overriding malloc. | |||
* | * | |||
* @param[in] size The bytes which should be allocated. | * @param[in] size The bytes which should be allocated. | |||
* | * | |||
* @return A pointer to the allocated memory or NULL on error. | * @return A pointer to the allocated memory or NULL on error. | |||
* | * | |||
* @code | * @code | |||
* #if UNIT_TESTING | * #ifdef UNIT_TESTING | |||
* extern void* _test_malloc(const size_t size, const char* file, const int line); | * extern void* _test_malloc(const size_t size, const char* file, const int line); | |||
* | * | |||
* #define malloc(size) _test_malloc(size, __FILE__, __LINE__) | * #define malloc(size) _test_malloc(size, __FILE__, __LINE__) | |||
* #endif | * #endif | |||
* | * | |||
* void leak_memory() { | * void leak_memory() { | |||
* int * const temporary = (int*)malloc(sizeof(int)); | * int * const temporary = (int*)malloc(sizeof(int)); | |||
* *temporary = 0; | * *temporary = 0; | |||
* } | * } | |||
* @endcode | * @endcode | |||
skipping to change at line 1461 | skipping to change at line 1505 | |||
* @param[in] ptr The pointer to the memory space to free. | * @param[in] ptr The pointer to the memory space to free. | |||
* | * | |||
* @see free(3). | * @see free(3). | |||
*/ | */ | |||
void test_free(void *ptr); | void test_free(void *ptr); | |||
#else | #else | |||
#define test_free(ptr) _test_free(ptr, __FILE__, __LINE__) | #define test_free(ptr) _test_free(ptr, __FILE__, __LINE__) | |||
#endif | #endif | |||
/* Redirect malloc, calloc and free to the unit test allocators. */ | /* Redirect malloc, calloc and free to the unit test allocators. */ | |||
#if UNIT_TESTING | #ifdef UNIT_TESTING | |||
#define malloc test_malloc | #define malloc test_malloc | |||
#define calloc test_calloc | #define calloc test_calloc | |||
#define free test_free | #define free test_free | |||
#endif /* UNIT_TESTING */ | #endif /* UNIT_TESTING */ | |||
/** @} */ | /** @} */ | |||
/** | /** | |||
* @defgroup cmocka_mock_assert Standard Assertions | * @defgroup cmocka_mock_assert Standard Assertions | |||
* @ingroup cmocka | * @ingroup cmocka | |||
skipping to change at line 1501 | skipping to change at line 1545 | |||
* | * | |||
* @param[in] result The expression to assert. | * @param[in] result The expression to assert. | |||
* | * | |||
* @param[in] expression The expression as string. | * @param[in] expression The expression as string. | |||
* | * | |||
* @param[in] file The file mock_assert() is called. | * @param[in] file The file mock_assert() is called. | |||
* | * | |||
* @param[in] line The line mock_assert() is called. | * @param[in] line The line mock_assert() is called. | |||
* | * | |||
* @code | * @code | |||
* #if UNIT_TESTING | * #ifdef UNIT_TESTING | |||
* extern void mock_assert(const int result, const char* const expression, | * extern void mock_assert(const int result, const char* const expression, | |||
* const char * const file, const int line); | * const char * const file, const int line); | |||
* | * | |||
* #undef assert | * #undef assert | |||
* #define assert(expression) \ | * #define assert(expression) \ | |||
* mock_assert((int)(expression), #expression, __FILE__, __LINE__); | * mock_assert((int)(expression), #expression, __FILE__, __LINE__); | |||
* #endif | * #endif | |||
* | * | |||
* void increment_value(int * const value) { | * void increment_value(int * const value) { | |||
* assert(value); | * assert(value); | |||
skipping to change at line 1578 | skipping to change at line 1622 | |||
/* Function that determines whether a function parameter value is correct. */ | /* Function that determines whether a function parameter value is correct. */ | |||
typedef int (*CheckParameterValue)(const LargestIntegralType value, | typedef int (*CheckParameterValue)(const LargestIntegralType value, | |||
const LargestIntegralType check_value_da ta); | const LargestIntegralType check_value_da ta); | |||
/* Type of the unit test function. */ | /* Type of the unit test function. */ | |||
typedef enum UnitTestFunctionType { | typedef enum UnitTestFunctionType { | |||
UNIT_TEST_FUNCTION_TYPE_TEST = 0, | UNIT_TEST_FUNCTION_TYPE_TEST = 0, | |||
UNIT_TEST_FUNCTION_TYPE_SETUP, | UNIT_TEST_FUNCTION_TYPE_SETUP, | |||
UNIT_TEST_FUNCTION_TYPE_TEARDOWN, | UNIT_TEST_FUNCTION_TYPE_TEARDOWN, | |||
UNIT_TEST_FUNCTION_TYPE_GROUP_SETUP, | ||||
UNIT_TEST_FUNCTION_TYPE_GROUP_TEARDOWN, | ||||
} UnitTestFunctionType; | } UnitTestFunctionType; | |||
/* | /* | |||
* Stores a unit test function with its name and type. | * Stores a unit test function with its name and type. | |||
* NOTE: Every setup function must be paired with a teardown function. It' s | * NOTE: Every setup function must be paired with a teardown function. It' s | |||
* possible to specify NULL function pointers. | * possible to specify NULL function pointers. | |||
*/ | */ | |||
typedef struct UnitTest { | typedef struct UnitTest { | |||
const char* name; | const char* name; | |||
UnitTestFunction function; | UnitTestFunction function; | |||
UnitTestFunctionType function_type; | UnitTestFunctionType function_type; | |||
} UnitTest; | } UnitTest; | |||
typedef struct GroupTest { | ||||
UnitTestFunction setup; | ||||
UnitTestFunction teardown; | ||||
const UnitTest *tests; | ||||
const size_t number_of_tests; | ||||
} GroupTest; | ||||
/* Location within some source code. */ | /* Location within some source code. */ | |||
typedef struct SourceLocation { | typedef struct SourceLocation { | |||
const char* file; | const char* file; | |||
int line; | int line; | |||
} SourceLocation; | } SourceLocation; | |||
/* Event that's called to check a parameter value. */ | /* Event that's called to check a parameter value. */ | |||
typedef struct CheckParameterEvent { | typedef struct CheckParameterEvent { | |||
SourceLocation location; | SourceLocation location; | |||
const char *parameter_name; | const char *parameter_name; | |||
skipping to change at line 1682 | skipping to change at line 1735 | |||
void _check_expected( | void _check_expected( | |||
const char * const function_name, const char * const parameter_name, | const char * const function_name, const char * const parameter_name, | |||
const char* file, const int line, const LargestIntegralType value); | const char* file, const int line, const LargestIntegralType value); | |||
void _will_return(const char * const function_name, const char * const file , | void _will_return(const char * const function_name, const char * const file , | |||
const int line, const LargestIntegralType value, | const int line, const LargestIntegralType value, | |||
const int count); | const int count); | |||
void _assert_true(const LargestIntegralType result, | void _assert_true(const LargestIntegralType result, | |||
const char* const expression, | const char* const expression, | |||
const char * const file, const int line); | const char * const file, const int line); | |||
void _assert_return_code(const LargestIntegralType result, | ||||
size_t rlen, | ||||
const LargestIntegralType error, | ||||
const char * const expression, | ||||
const char * const file, | ||||
const int line); | ||||
void _assert_int_equal( | void _assert_int_equal( | |||
const LargestIntegralType a, const LargestIntegralType b, | const LargestIntegralType a, const LargestIntegralType b, | |||
const char * const file, const int line); | const char * const file, const int line); | |||
void _assert_int_not_equal( | void _assert_int_not_equal( | |||
const LargestIntegralType a, const LargestIntegralType b, | const LargestIntegralType a, const LargestIntegralType b, | |||
const char * const file, const int line); | const char * const file, const int line); | |||
void _assert_string_equal(const char * const a, const char * const b, | void _assert_string_equal(const char * const a, const char * const b, | |||
const char * const file, const int line); | const char * const file, const int line); | |||
void _assert_string_not_equal(const char * const a, const char * const b, | void _assert_string_not_equal(const char * const a, const char * const b, | |||
const char *file, const int line); | const char *file, const int line); | |||
skipping to change at line 1722 | skipping to change at line 1781 | |||
void* _test_calloc(const size_t number_of_elements, const size_t size, | void* _test_calloc(const size_t number_of_elements, const size_t size, | |||
const char* file, const int line); | const char* file, const int line); | |||
void _test_free(void* const ptr, const char* file, const int line); | void _test_free(void* const ptr, const char* file, const int line); | |||
void _fail(const char * const file, const int line); | void _fail(const char * const file, const int line); | |||
int _run_test( | int _run_test( | |||
const char * const function_name, const UnitTestFunction Function, | const char * const function_name, const UnitTestFunction Function, | |||
void ** const volatile state, const UnitTestFunctionType function_type, | void ** const volatile state, const UnitTestFunctionType function_type, | |||
const void* const heap_check_point); | const void* const heap_check_point); | |||
int _run_tests(const UnitTest * const tests, const size_t number_of_tests); | int _run_tests(const UnitTest * const tests, const size_t number_of_tests); | |||
int _run_group_tests(const UnitTest * const tests, | ||||
const size_t number_of_tests); | ||||
/* Standard output and error print methods. */ | /* Standard output and error print methods. */ | |||
void print_message(const char* const format, ...) PRINTF_ATTRIBUTE(1, 2); | void print_message(const char* const format, ...) CMOCKA_PRINTF_ATTRIBUTE(1 | |||
void print_error(const char* const format, ...) PRINTF_ATTRIBUTE(1, 2); | , 2); | |||
void vprint_message(const char* const format, va_list args) PRINTF_ATTRIBUT | void print_error(const char* const format, ...) CMOCKA_PRINTF_ATTRIBUTE(1, | |||
E(1, 0); | 2); | |||
void vprint_error(const char* const format, va_list args) PRINTF_ATTRIBUTE( | void vprint_message(const char* const format, va_list args) CMOCKA_PRINTF_A | |||
1, 0); | TTRIBUTE(1, 0); | |||
void vprint_error(const char* const format, va_list args) CMOCKA_PRINTF_ATT | ||||
RIBUTE(1, 0); | ||||
/** @} */ | /** @} */ | |||
#endif /* CMOCKA_H_ */ | #endif /* CMOCKA_H_ */ | |||
End of changes. 47 change blocks. | ||||
48 lines changed or deleted | 113 lines changed or added | |||