23 #define __func__ __FUNCTION__ 26 #define inline __inline 33 int __stdcall IsDebuggerPresent();
61 # if (defined(__x86_64__) && !defined(__ILP32__)) || defined(__sparc_v9__) || defined(__sparcv9) 62 # define __WORDSIZE 64 64 # define __WORDSIZE 32 75 #ifndef LargestIntegralType 76 # if __WORDSIZE == 64 && !defined(_WIN64) 77 # define LargestIntegralType unsigned long int 79 # define LargestIntegralType unsigned long long int 85 #ifndef LargestIntegralTypePrintfFormat 87 # define LargestIntegralTypePrintfFormat "0x%I64x" 90 # define LargestIntegralTypePrintfFormat "%#lx" 92 # define LargestIntegralTypePrintfFormat "%#llx" 98 #ifndef LargestIntegralTypePrintfFormatDecimal 100 # define LargestIntegralTypePrintfFormatDecimal "%I64u" 102 # if __WORDSIZE == 64 103 # define LargestIntegralTypePrintfFormatDecimal "%lu" 105 # define LargestIntegralTypePrintfFormatDecimal "%llu" 110 #ifndef FloatPrintfFormat 111 # define FloatPrintfFormat "%f" 115 #define cast_to_largest_integral_type(value) \ 116 ((LargestIntegralType)(value)) 119 #if !defined(_UINTPTR_T) && !defined(_UINTPTR_T_DEFINED) 122 typedef unsigned int uintptr_t;
123 # elif defined(_WIN64) 124 typedef unsigned long int uintptr_t;
129 # if __WORDSIZE == 64 130 typedef unsigned long int uintptr_t;
132 typedef unsigned int uintptr_t;
135 # if defined(_LP64) || defined(_I32LPx) 136 typedef unsigned long int uintptr_t;
138 typedef unsigned int uintptr_t;
144 # define _UINTPTR_T_DEFINED 148 #define cast_to_pointer_integral_type(value) \ 149 ((uintptr_t)((size_t)(value))) 152 #define cast_ptr_to_largest_integral_type(value) \ 153 cast_to_largest_integral_type(cast_to_pointer_integral_type(value)) 157 #define CMOCKA_PRINTF_ATTRIBUTE(a,b) \ 158 __attribute__ ((__format__ (__printf__, a, b))) 160 #define CMOCKA_PRINTF_ATTRIBUTE(a,b) 163 #if defined(__GNUC__) 164 #define CMOCKA_DEPRECATED __attribute__ ((deprecated)) 165 #elif defined(_MSC_VER) 166 #define CMOCKA_DEPRECATED __declspec(deprecated) 168 #define CMOCKA_DEPRECATED 171 #define WILL_RETURN_ALWAYS -1 172 #define WILL_RETURN_ONCE -2 232 #define mock() _mock(__func__, __FILE__, __LINE__) 256 #type mock_type(#type); 258 #define mock_type(type) ((type) mock()) 285 #define mock_ptr_type(type) ((type) (uintptr_t) mock()) 316 #define will_return(function, value) \ 317 _will_return(#function, __FILE__, __LINE__, \ 318 cast_to_largest_integral_type(value), 1) 339 #define will_return_count(function, value, count) \ 340 _will_return(#function, __FILE__, __LINE__, \ 341 cast_to_largest_integral_type(value), count) 362 #define will_return_always(function, value) \ 363 will_return_count(function, (value), WILL_RETURN_ALWAYS) 390 #define will_return_maybe(function, value) \ 391 will_return_count(function, (value), WILL_RETURN_ONCE) 462 void expect_check(#
function, #parameter, #check_function,
const void *check_data);
464 #define expect_check(function, parameter, check_function, check_data) \ 465 _expect_check(#function, #parameter, __FILE__, __LINE__, check_function, \ 466 cast_to_largest_integral_type(check_data), NULL, 1) 486 #define expect_in_set(function, parameter, value_array) \ 487 expect_in_set_count(function, parameter, value_array, 1) 511 #define expect_in_set_count(function, parameter, value_array, count) \ 512 _expect_in_set(#function, #parameter, __FILE__, __LINE__, value_array, \ 513 sizeof(value_array) / sizeof((value_array)[0]), count) 533 #define expect_not_in_set(function, parameter, value_array) \ 534 expect_not_in_set_count(function, parameter, value_array, 1) 558 #define expect_not_in_set_count(function, parameter, value_array, count) \ 559 _expect_not_in_set( \ 560 #function, #parameter, __FILE__, __LINE__, value_array, \ 561 sizeof(value_array) / sizeof((value_array)[0]), count) 584 #define expect_in_range(function, parameter, minimum, maximum) \ 585 expect_in_range_count(function, parameter, minimum, maximum, 1) 611 #define expect_in_range_count(function, parameter, minimum, maximum, count) \ 612 _expect_in_range(#function, #parameter, __FILE__, __LINE__, minimum, \ 635 #define expect_not_in_range(function, parameter, minimum, maximum) \ 636 expect_not_in_range_count(function, parameter, minimum, maximum, 1) 662 #define expect_not_in_range_count(function, parameter, minimum, maximum, \ 664 _expect_not_in_range(#function, #parameter, __FILE__, __LINE__, \ 665 minimum, maximum, count) 684 #define expect_value(function, parameter, value) \ 685 expect_value_count(function, parameter, value, 1) 708 #define expect_value_count(function, parameter, value, count) \ 709 _expect_value(#function, #parameter, __FILE__, __LINE__, \ 710 cast_to_largest_integral_type(value), count) 729 #define expect_not_value(function, parameter, value) \ 730 expect_not_value_count(function, parameter, value, 1) 753 #define expect_not_value_count(function, parameter, value, count) \ 754 _expect_not_value(#function, #parameter, __FILE__, __LINE__, \ 755 cast_to_largest_integral_type(value), count) 773 void expect_string(#
function, #parameter,
const char *
string);
775 #define expect_string(function, parameter, string) \ 776 expect_string_count(function, parameter, string, 1) 800 #define expect_string_count(function, parameter, string, count) \ 801 _expect_string(#function, #parameter, __FILE__, __LINE__, \ 802 (const char*)(string), count) 822 #define expect_not_string(function, parameter, string) \ 823 expect_not_string_count(function, parameter, string, 1) 847 #define expect_not_string_count(function, parameter, string, count) \ 848 _expect_not_string(#function, #parameter, __FILE__, __LINE__, \ 849 (const char*)(string), count) 868 void expect_memory(#
function, #parameter,
void *memory,
size_t size);
870 #define expect_memory(function, parameter, memory, size) \ 871 expect_memory_count(function, parameter, memory, size, 1) 897 #define expect_memory_count(function, parameter, memory, size, count) \ 898 _expect_memory(#function, #parameter, __FILE__, __LINE__, \ 899 (const void*)(memory), size, count) 921 #define expect_not_memory(function, parameter, memory, size) \ 922 expect_not_memory_count(function, parameter, memory, size, 1) 948 #define expect_not_memory_count(function, parameter, memory, size, count) \ 949 _expect_not_memory(#function, #parameter, __FILE__, __LINE__, \ 950 (const void*)(memory), size, count) 968 #define expect_any(function, parameter) \ 969 expect_any_count(function, parameter, 1) 986 #define expect_any_always(function, parameter) \ 987 expect_any_count(function, parameter, WILL_RETURN_ALWAYS) 1009 #define expect_any_count(function, parameter, count) \ 1010 _expect_any(#function, #parameter, __FILE__, __LINE__, count) 1026 #define check_expected(parameter) \ 1027 _check_expected(__func__, #parameter, __FILE__, __LINE__, \ 1028 cast_to_largest_integral_type(parameter)) 1044 #define check_expected_ptr(parameter) \ 1045 _check_expected(__func__, #parameter, __FILE__, __LINE__, \ 1046 cast_ptr_to_largest_integral_type(parameter)) 1085 #define assert_true(c) _assert_true(cast_to_largest_integral_type(c), #c, \ 1103 #define assert_false(c) _assert_true(!(cast_to_largest_integral_type(c)), #c, \ 1122 #define assert_return_code(rc, error) \ 1123 _assert_return_code(cast_to_largest_integral_type(rc), \ 1125 cast_to_largest_integral_type(error), \ 1126 #rc, __FILE__, __LINE__) 1142 #define assert_non_null(c) _assert_true(cast_ptr_to_largest_integral_type(c), #c, \ 1159 #define assert_null(c) _assert_true(!(cast_ptr_to_largest_integral_type(c)), #c, \ 1176 #define assert_ptr_equal(a, b) \ 1177 _assert_int_equal(cast_ptr_to_largest_integral_type(a), \ 1178 cast_ptr_to_largest_integral_type(b), \ 1195 #define assert_ptr_not_equal(a, b) \ 1196 _assert_int_not_equal(cast_ptr_to_largest_integral_type(a), \ 1197 cast_ptr_to_largest_integral_type(b), \ 1214 #define assert_int_equal(a, b) \ 1215 _assert_int_equal(cast_to_largest_integral_type(a), \ 1216 cast_to_largest_integral_type(b), \ 1235 #define assert_int_not_equal(a, b) \ 1236 _assert_int_not_equal(cast_to_largest_integral_type(a), \ 1237 cast_to_largest_integral_type(b), \ 1256 #define assert_float_equal(a, b, epsilon) \ 1257 _assert_float_equal((float)a, \ 1278 #define assert_float_not_equal(a, b, epsilon) \ 1279 _assert_float_not_equal((float)a, \ 1299 #define assert_string_equal(a, b) \ 1300 _assert_string_equal((const char*)(a), (const char*)(b), __FILE__, \ 1317 #define assert_string_not_equal(a, b) \ 1318 _assert_string_not_equal((const char*)(a), (const char*)(b), __FILE__, \ 1339 #define assert_memory_equal(a, b, size) \ 1340 _assert_memory_equal((const void*)(a), (const void*)(b), size, __FILE__, \ 1361 #define assert_memory_not_equal(a, b, size) \ 1362 _assert_memory_not_equal((const void*)(a), (const void*)(b), size, \ 1382 #define assert_in_range(value, minimum, maximum) \ 1384 cast_to_largest_integral_type(value), \ 1385 cast_to_largest_integral_type(minimum), \ 1386 cast_to_largest_integral_type(maximum), __FILE__, __LINE__) 1405 #define assert_not_in_range(value, minimum, maximum) \ 1406 _assert_not_in_range( \ 1407 cast_to_largest_integral_type(value), \ 1408 cast_to_largest_integral_type(minimum), \ 1409 cast_to_largest_integral_type(maximum), __FILE__, __LINE__) 1427 #define assert_in_set(value, values, number_of_values) \ 1428 _assert_in_set(value, values, number_of_values, __FILE__, __LINE__) 1446 #define assert_not_in_set(value, values, number_of_values) \ 1447 _assert_not_in_set(value, values, number_of_values, __FILE__, __LINE__) 1519 #define function_called() _function_called(__func__, __FILE__, __LINE__) 1535 #define expect_function_calls(function, times) \ 1536 _expect_function_call(#function, __FILE__, __LINE__, times) 1550 #define expect_function_call(function) \ 1551 _expect_function_call(#function, __FILE__, __LINE__, 1) 1564 #define expect_function_call_any(function) \ 1565 _expect_function_call(#function, __FILE__, __LINE__, -1) 1578 #define ignore_function_calls(function) \ 1579 _expect_function_call(#function, __FILE__, __LINE__, -2) 1616 #define fail() _fail(__FILE__, __LINE__) 1625 #define skip() _skip(__FILE__, __LINE__) 1643 void fail_msg(
const char *msg, ...);
1645 #define fail_msg(msg, ...) do { \ 1646 print_error("ERROR: " msg "\n", ##__VA_ARGS__); \ 1673 #define run_test(f) _run_test(#f, f, NULL, UNIT_TEST_FUNCTION_TYPE_TEST, NULL) 1676 static inline void _unit_test_dummy(
void **state) {
1684 #define unit_test(f) { #f, f, UNIT_TEST_FUNCTION_TYPE_TEST } 1686 #define _unit_test_setup(test, setup) \ 1687 { #test "_" #setup, setup, UNIT_TEST_FUNCTION_TYPE_SETUP } 1693 #define unit_test_setup(test, setup) \ 1694 _unit_test_setup(test, setup), \ 1696 _unit_test_teardown(test, _unit_test_dummy) 1698 #define _unit_test_teardown(test, teardown) \ 1699 { #test "_" #teardown, teardown, UNIT_TEST_FUNCTION_TYPE_TEARDOWN } 1705 #define unit_test_teardown(test, teardown) \ 1706 _unit_test_setup(test, _unit_test_dummy), \ 1708 _unit_test_teardown(test, teardown) 1714 #define group_test_setup(setup) \ 1715 { "group_" #setup, setup, UNIT_TEST_FUNCTION_TYPE_GROUP_SETUP } 1721 #define group_test_teardown(teardown) \ 1722 { "group_" #teardown, teardown, UNIT_TEST_FUNCTION_TYPE_GROUP_TEARDOWN } 1731 #define unit_test_setup_teardown(test, setup, teardown) \ 1732 _unit_test_setup(test, setup), \ 1734 _unit_test_teardown(test, teardown) 1738 #define cmocka_unit_test(f) { #f, f, NULL, NULL, NULL } 1741 #define cmocka_unit_test_setup(f, setup) { #f, f, setup, NULL, NULL } 1744 #define cmocka_unit_test_teardown(f, teardown) { #f, f, NULL, teardown, NULL } 1750 #define cmocka_unit_test_setup_teardown(f, setup, teardown) { #f, f, setup, teardown, NULL } 1759 #define cmocka_unit_test_prestate(f, state) { #f, f, NULL, NULL, state } 1768 #define cmocka_unit_test_prestate_setup_teardown(f, setup, teardown, state) { #f, f, setup, teardown, state } 1770 #define run_tests(tests) _run_tests(tests, sizeof(tests) / sizeof((tests)[0])) 1771 #define run_group_tests(tests) _run_group_tests(tests, sizeof(tests) / sizeof((tests)[0])) 1831 CMFixtureFunction group_setup,
1832 CMFixtureFunction group_teardown);
1834 # define cmocka_run_group_tests(group_tests, group_setup, group_teardown) \ 1835 _cmocka_run_group_tests(#group_tests, group_tests, sizeof(group_tests) / sizeof((group_tests)[0]), group_setup, group_teardown) 1900 CMFixtureFunction group_setup,
1901 CMFixtureFunction group_teardown);
1903 # define cmocka_run_group_tests_name(group_name, group_tests, group_setup, group_teardown) \ 1904 _cmocka_run_group_tests(group_name, group_tests, sizeof(group_tests) / sizeof((group_tests)[0]), group_setup, group_teardown) 1957 #define test_malloc(size) _test_malloc(size, __FILE__, __LINE__) 1976 #define test_calloc(num, size) _test_calloc(num, size, __FILE__, __LINE__) 1992 #define test_realloc(ptr, size) _test_realloc(ptr, size, __FILE__, __LINE__) 2005 #define test_free(ptr) _test_free(ptr, __FILE__, __LINE__) 2010 #define malloc test_malloc 2011 #define realloc test_realloc 2012 #define calloc test_calloc 2013 #define free test_free 2069 void mock_assert(
const int result,
const char*
const expression,
2070 const char *
const file,
const int line);
2097 #define expect_assert_failure(function_call) \ 2099 const int result = setjmp(global_expect_assert_env); \ 2100 global_expecting_assert = 1; \ 2102 print_message("Expected assertion %s occurred\n", \ 2103 global_last_failed_assert); \ 2104 global_expecting_assert = 0; \ 2107 global_expecting_assert = 0; \ 2108 print_error("Expected assert in %s\n", #function_call); \ 2109 _fail(__FILE__, __LINE__); \ 2117 typedef void (*UnitTestFunction)(
void **state);
2124 typedef enum UnitTestFunctionType {
2125 UNIT_TEST_FUNCTION_TYPE_TEST = 0,
2126 UNIT_TEST_FUNCTION_TYPE_SETUP,
2127 UNIT_TEST_FUNCTION_TYPE_TEARDOWN,
2128 UNIT_TEST_FUNCTION_TYPE_GROUP_SETUP,
2129 UNIT_TEST_FUNCTION_TYPE_GROUP_TEARDOWN,
2130 } UnitTestFunctionType;
2139 UnitTestFunction
function;
2140 UnitTestFunctionType function_type;
2144 UnitTestFunction setup;
2145 UnitTestFunction teardown;
2147 const size_t number_of_tests;
2151 typedef void (*CMUnitTestFunction)(
void **state);
2154 typedef int (*CMFixtureFunction)(
void **state);
2158 CMUnitTestFunction test_func;
2159 CMFixtureFunction setup_func;
2160 CMFixtureFunction teardown_func;
2161 void *initial_state;
2173 const char *parameter_name;
2174 CheckParameterValue check_value;
2179 extern int global_expecting_assert;
2180 extern jmp_buf global_expect_assert_env;
2181 extern const char * global_last_failed_assert;
2187 void _expect_function_call(
2188 const char *
const function_name,
2189 const char *
const file,
2193 void _function_called(
const char *
const function,
const char*
const file,
2197 const char*
const function,
const char*
const parameter,
2198 const char*
const file,
const int line,
2199 const CheckParameterValue check_function,
2203 void _expect_in_set(
2204 const char*
const function,
const char*
const parameter,
2206 const size_t number_of_values,
const int count);
2207 void _expect_not_in_set(
2208 const char*
const function,
const char*
const parameter,
2210 const size_t number_of_values,
const int count);
2212 void _expect_in_range(
2213 const char*
const function,
const char*
const parameter,
2214 const char*
const file,
const int line,
2217 void _expect_not_in_range(
2218 const char*
const function,
const char*
const parameter,
2219 const char*
const file,
const int line,
2224 const char*
const function,
const char*
const parameter,
2227 void _expect_not_value(
2228 const char*
const function,
const char*
const parameter,
2232 void _expect_string(
2233 const char*
const function,
const char*
const parameter,
2234 const char*
const file,
const int line,
const char*
string,
2236 void _expect_not_string(
2237 const char*
const function,
const char*
const parameter,
2238 const char*
const file,
const int line,
const char*
string,
2241 void _expect_memory(
2242 const char*
const function,
const char*
const parameter,
2243 const char*
const file,
const int line,
const void*
const memory,
2244 const size_t size,
const int count);
2245 void _expect_not_memory(
2246 const char*
const function,
const char*
const parameter,
2247 const char*
const file,
const int line,
const void*
const memory,
2248 const size_t size,
const int count);
2251 const char*
const function,
const char*
const parameter,
2252 const char*
const file,
const int line,
const int count);
2254 void _check_expected(
2255 const char *
const function_name,
const char *
const parameter_name,
2258 void _will_return(
const char *
const function_name,
const char *
const file,
2262 const char*
const expression,
2263 const char *
const file,
const int line);
2267 const char *
const expression,
2268 const char *
const file,
2270 void _assert_float_equal(
const float a,
const float n,
2271 const float epsilon,
const char*
const file,
2273 void _assert_float_not_equal(
const float a,
const float n,
2274 const float epsilon,
const char*
const file,
2276 void _assert_int_equal(
2278 const char *
const file,
const int line);
2279 void _assert_int_not_equal(
2281 const char *
const file,
const int line);
2282 void _assert_string_equal(
const char *
const a,
const char *
const b,
2283 const char *
const file,
const int line);
2284 void _assert_string_not_equal(
const char *
const a,
const char *
const b,
2285 const char *file,
const int line);
2286 void _assert_memory_equal(
const void *
const a,
const void *
const b,
2287 const size_t size,
const char*
const file,
2289 void _assert_memory_not_equal(
const void *
const a,
const void *
const b,
2290 const size_t size,
const char*
const file,
2292 void _assert_in_range(
2295 void _assert_not_in_range(
2298 void _assert_in_set(
2300 const size_t number_of_values,
const char*
const file,
const int line);
2301 void _assert_not_in_set(
2303 const size_t number_of_values,
const char*
const file,
const int line);
2305 void* _test_malloc(
const size_t size,
const char* file,
const int line);
2306 void* _test_realloc(
void *ptr,
const size_t size,
const char* file,
const int line);
2307 void* _test_calloc(
const size_t number_of_elements,
const size_t size,
2308 const char* file,
const int line);
2309 void _test_free(
void*
const ptr,
const char* file,
const int line);
2311 void _fail(
const char *
const file,
const int line);
2313 void _skip(
const char *
const file,
const int line);
2316 const char *
const function_name,
const UnitTestFunction Function,
2317 void **
const volatile state,
const UnitTestFunctionType function_type,
2318 const void*
const heap_check_point);
2319 CMOCKA_DEPRECATED
int _run_tests(
const UnitTest *
const tests,
2320 const size_t number_of_tests);
2321 CMOCKA_DEPRECATED
int _run_group_tests(
const UnitTest *
const tests,
2322 const size_t number_of_tests);
2325 int _cmocka_run_group_tests(
const char *group_name,
2327 const size_t num_tests,
2328 CMFixtureFunction group_setup,
2329 CMFixtureFunction group_teardown);
2332 void print_message(
const char*
const format, ...) CMOCKA_PRINTF_ATTRIBUTE(1, 2);
2333 void print_error(const
char* const format, ...) CMOCKA_PRINTF_ATTRIBUTE(1, 2);
2334 void vprint_message(const
char* const format, va_list args) CMOCKA_PRINTF_ATTRIBUTE(1, 0);
2335 void vprint_error(const
char* const format, va_list args) CMOCKA_PRINTF_ATTRIBUTE(1, 0);
2337 enum cm_message_output {
void assert_null(void *pointer)
Assert that the given pointer is NULL.
void fail(void)
Forces the test to fail immediately and quit.
void expect_any(#function, #parameter)
Add an event to check if a parameter (of any value) has been passed.
void expect_not_memory_count(#function, #parameter, void *memory, size_t size, size_t count)
Add an event to repeatedly check if the parameter doesn't match an area of memory.
void expect_not_string_count(#function, #parameter, const char *string, size_t count)
Add an event to check if the parameter value isn't equal to the provided string.
void will_return_always(#function, LargestIntegralType value)
Store a value that will be always returned by mock().
void expect_any_count(#function, #parameter, size_t count)
Add an event to repeatedly check if a parameter (of any value) has been passed.
void assert_float_not_equal(float a, float b, float epsilon)
Assert that the two given float are not equal given an epsilon.
void expect_check(#function, #parameter, #check_function, const void *check_data)
Add a custom parameter checking function.
void assert_memory_not_equal(const void *a, const void *b, size_t size)
Assert that the two given areas of memory are not equal.
void expect_in_set(#function, #parameter, LargestIntegralType value_array[])
Add an event to check if the parameter value is part of the provided array.
void expect_not_in_set_count(#function, #parameter, LargestIntegralType value_array[], size_t count)
Add an event to check if the parameter value is not part of the provided array.
void expect_memory(#function, #parameter, void *memory, size_t size)
Add an event to check if the parameter does match an area of memory.
LargestIntegralType mock(void)
Retrieve a return value of the current function.
void fail_msg(const char *msg,...)
Forces the test to fail immediately and quit, printing the reason.
void assert_in_range(LargestIntegralType value, LargestIntegralType minimum, LargestIntegralType maximum)
Assert that the specified value is not smaller than the minimum and and not greater than the maximum.
void expect_in_range(#function, #parameter, LargestIntegralType minimum, LargestIntegralType maximum)
Add an event to check a parameter is inside a numerical range. The check would succeed if minimum <= ...
void will_return(#function, LargestIntegralType value)
Store a value to be returned by mock() later.
void assert_ptr_equal(void *a, void *b)
Assert that the two given pointers are equal.
void will_return_count(#function, LargestIntegralType value, int count)
Store a value to be returned by mock() later.
void expect_function_call(#function)
Store expected single call to a mock to be checked by function_called() later.
void mock_assert(const int result, const char *const expression, const char *const file, const int line)
Function to replace assert(3) in tested code.
Definition: cmocka.c:1711
int cmocka_run_group_tests(const struct CMUnitTest group_tests[], CMFixtureFunction group_setup, CMFixtureFunction group_teardown)
Run tests specified by an array of CMUnitTest structures.
void expect_in_range_count(#function, #parameter, LargestIntegralType minimum, LargestIntegralType maximum, size_t count)
Add an event to repeatedly check a parameter is inside a numerical range. The check would succeed if ...
void will_return_maybe(#function, LargestIntegralType value)
Store a value that may be always returned by mock().
void expect_string_count(#function, #parameter, const char *string, size_t count)
Add an event to check if the parameter value is equal to the provided string.
void expect_function_call_any(#function)
Expects function_called() from given mock at least once.
void expect_not_string(#function, #parameter, const char *string)
Add an event to check if the parameter value isn't equal to the provided string.
void expect_not_in_range(#function, #parameter, LargestIntegralType minimum, LargestIntegralType maximum)
Add an event to check a parameter is outside a numerical range. The check would succeed if minimum > ...
void assert_string_equal(const char *a, const char *b)
Assert that the two given strings are equal.
void * test_malloc(size_t size)
Test function overriding malloc.
void assert_return_code(int rc, int error)
Assert that the return_code is greater than or equal to 0.
void assert_float_equal(float a, float b, float epsilon)
Assert that the two given float are equal given an epsilon.
void assert_non_null(void *pointer)
Assert that the given pointer is non-NULL.
void assert_not_in_set(LargestIntegralType value, LargestIntegralType values[], size_t count)
Assert that the specified value is not within a set.
uintmax_t LargestIntegralType
Definition: cmocka.h:73
void expect_in_set_count(#function, #parameter, LargestIntegralType value_array[], size_t count)
Add an event to check if the parameter value is part of the provided array.
void assert_true(scalar expression)
Assert that the given expression is true.
void assert_string_not_equal(const char *a, const char *b)
Assert that the two given strings are not equal.
void assert_false(scalar expression)
Assert that the given expression is false.
void check_expected_ptr(#parameter)
Determine whether a function parameter is correct.
void expect_function_calls(#function, const int times)
Store expected call(s) to a mock to be checked by function_called() later.
type mock_ptr_type(#type)
Retrieve a typed return value of the current function.
Definition: cmocka.h:2143
void cmocka_set_skip_filter(const char *pattern)
Set a pattern to skip tests matching the pattern.
Definition: cmocka.c:2698
void expect_not_in_range_count(#function, #parameter, LargestIntegralType minimum, LargestIntegralType maximum, size_t count)
Add an event to repeatedly check a parameter is outside a numerical range. The check would succeed if...
int cmocka_run_group_tests_name(const char *group_name, const struct CMUnitTest group_tests[], CMFixtureFunction group_setup, CMFixtureFunction group_teardown)
Run tests specified by an array of CMUnitTest structures and specify a name.
void assert_ptr_not_equal(void *a, void *b)
Assert that the two given pointers are not equal.
void assert_int_not_equal(int a, int b)
Assert that the two given integers are not equal.
void expect_memory_count(#function, #parameter, void *memory, size_t size, size_t count)
Add an event to repeatedly check if the parameter does match an area of memory.
int run_test(#function)
Generic method to run a single test.
void function_called(void)
Check that current mocked function is being called in the expected order.
void skip(void)
Forces the test to not be executed, but marked as skipped.
Definition: cmocka.h:2165
void cmocka_set_message_output(enum cm_message_output output)
Function to set the output format for a test.
Definition: cmocka.c:2688
void * test_calloc(size_t nmemb, size_t size)
Test function overriding calloc.
void assert_not_in_range(LargestIntegralType value, LargestIntegralType minimum, LargestIntegralType maximum)
Assert that the specified value is smaller than the minimum or greater than the maximum.
void ignore_function_calls(#function)
Ignores function_called() invocations from given mock function.
Definition: cmocka.h:2156
void expect_not_in_set(#function, #parameter, LargestIntegralType value_array[])
Add an event to check if the parameter value is not part of the provided array.
void assert_int_equal(int a, int b)
Assert that the two given integers are equal.
void assert_memory_equal(const void *a, const void *b, size_t size)
Assert that the two given areas of memory are equal, otherwise fail.
void check_expected(#parameter)
Determine whether a function parameter is correct.
void expect_not_value(#function, #parameter, LargestIntegralType value)
Add an event to check if a parameter isn't the given value.
void expect_any_always(#function, #parameter)
Add an event to always check if a parameter (of any value) has been passed.
void * test_realloc(void *ptr, size_t size)
Test function overriding realloc which detects buffer overruns and memoery leaks.
void expect_not_value_count(#function, #parameter, LargestIntegralType value, size_t count)
Add an event to repeatedly check if a parameter isn't the given value.
void expect_not_memory(#function, #parameter, void *memory, size_t size)
Add an event to check if the parameter doesn't match an area of memory.
void expect_string(#function, #parameter, const char *string)
Add an event to check if the parameter value is equal to the provided string.
void expect_value(#function, #parameter, LargestIntegralType value)
Add an event to check if a parameter is the given value.
void test_free(void *ptr)
Test function overriding free(3).
void expect_assert_failure(function fn_call)
Ensure that mock_assert() is called.
Definition: cmocka.h:2137
void cmocka_set_test_filter(const char *pattern)
Set a pattern to only run the test matching the pattern.
Definition: cmocka.c:2693
void expect_value_count(#function, #parameter, LargestIntegralType value, size_t count)
Add an event to repeatedly check if a parameter is the given value.
Definition: cmocka.h:2171
void assert_in_set(LargestIntegralType value, LargestIntegralType values[], size_t count)
Assert that the specified value is within a set.