23 #define __func__ __FUNCTION__ 26 #define inline __inline 33 int __stdcall IsDebuggerPresent();
62 # if (defined(__x86_64__) && !defined(__ILP32__)) || defined(__sparc_v9__) || defined(__sparcv9) 63 # define __WORDSIZE 64 65 # define __WORDSIZE 32 76 #ifndef LargestIntegralType 77 # if __WORDSIZE == 64 && !defined(_WIN64) 78 # define LargestIntegralType unsigned long int 80 # define LargestIntegralType unsigned long long int 86 #ifndef LargestIntegralTypePrintfFormat 88 # define LargestIntegralTypePrintfFormat "0x%I64x" 91 # define LargestIntegralTypePrintfFormat "%#lx" 93 # define LargestIntegralTypePrintfFormat "%#llx" 99 #ifndef LargestIntegralTypePrintfFormatDecimal 101 # define LargestIntegralTypePrintfFormatDecimal "%I64u" 103 # if __WORDSIZE == 64 104 # define LargestIntegralTypePrintfFormatDecimal "%lu" 106 # define LargestIntegralTypePrintfFormatDecimal "%llu" 111 #ifndef FloatPrintfFormat 112 # define FloatPrintfFormat "%f" 115 #ifndef DoublePrintfFormat 116 # define DoublePrintfFormat "%f" 120 #define cast_to_largest_integral_type(value) \ 121 ((LargestIntegralType)(value)) 124 #if !defined(_UINTPTR_T) && !defined(_UINTPTR_T_DEFINED) && !defined(HAVE_UINTPTR_T) 127 typedef unsigned int uintptr_t;
128 # elif defined(_WIN64) 129 typedef unsigned long int uintptr_t;
134 # if __WORDSIZE == 64 135 typedef unsigned long int uintptr_t;
137 typedef unsigned int uintptr_t;
140 # if defined(_LP64) || defined(_I32LPx) 141 typedef unsigned long int uintptr_t;
143 typedef unsigned int uintptr_t;
149 # define _UINTPTR_T_DEFINED 153 #define cast_to_pointer_integral_type(value) \ 154 ((uintptr_t)((size_t)(value))) 157 #define cast_ptr_to_largest_integral_type(value) \ 158 cast_to_largest_integral_type(cast_to_pointer_integral_type(value)) 162 #define CMOCKA_PRINTF_ATTRIBUTE(a,b) \ 163 __attribute__ ((__format__ (__printf__, a, b))) 165 #define CMOCKA_PRINTF_ATTRIBUTE(a,b) 168 #if defined(__GNUC__) 169 #define CMOCKA_DEPRECATED __attribute__ ((deprecated)) 170 #elif defined(_MSC_VER) 171 #define CMOCKA_DEPRECATED __declspec(deprecated) 173 #define CMOCKA_DEPRECATED 176 #if defined(__GNUC__) 177 #define CMOCKA_NORETURN __attribute__ ((noreturn)) 178 #elif defined(_MSC_VER) 179 #define CMOCKA_NORETURN __declspec(noreturn) 181 #define CMOCKA_NORETURN 184 #define WILL_RETURN_ALWAYS -1 185 #define WILL_RETURN_ONCE -2 245 #define mock() _mock(__func__, __FILE__, __LINE__) 269 #type mock_type(#type); 271 #define mock_type(type) ((type) mock()) 298 #define mock_ptr_type(type) ((type) (uintptr_t) mock()) 329 #define will_return(function, value) \ 330 _will_return(#function, __FILE__, __LINE__, \ 331 cast_to_largest_integral_type(value), 1) 352 #define will_return_count(function, value, count) \ 353 _will_return(#function, __FILE__, __LINE__, \ 354 cast_to_largest_integral_type(value), count) 375 #define will_return_always(function, value) \ 376 will_return_count(function, (value), WILL_RETURN_ALWAYS) 403 #define will_return_maybe(function, value) \ 404 will_return_count(function, (value), WILL_RETURN_ONCE) 475 void expect_check(#
function, #parameter, #check_function,
const void *check_data);
477 #define expect_check(function, parameter, check_function, check_data) \ 478 _expect_check(#function, #parameter, __FILE__, __LINE__, check_function, \ 479 cast_to_largest_integral_type(check_data), NULL, 1) 499 #define expect_in_set(function, parameter, value_array) \ 500 expect_in_set_count(function, parameter, value_array, 1) 524 #define expect_in_set_count(function, parameter, value_array, count) \ 525 _expect_in_set(#function, #parameter, __FILE__, __LINE__, value_array, \ 526 sizeof(value_array) / sizeof((value_array)[0]), count) 546 #define expect_not_in_set(function, parameter, value_array) \ 547 expect_not_in_set_count(function, parameter, value_array, 1) 571 #define expect_not_in_set_count(function, parameter, value_array, count) \ 572 _expect_not_in_set( \ 573 #function, #parameter, __FILE__, __LINE__, value_array, \ 574 sizeof(value_array) / sizeof((value_array)[0]), count) 597 #define expect_in_range(function, parameter, minimum, maximum) \ 598 expect_in_range_count(function, parameter, minimum, maximum, 1) 624 #define expect_in_range_count(function, parameter, minimum, maximum, count) \ 625 _expect_in_range(#function, #parameter, __FILE__, __LINE__, minimum, \ 648 #define expect_not_in_range(function, parameter, minimum, maximum) \ 649 expect_not_in_range_count(function, parameter, minimum, maximum, 1) 675 #define expect_not_in_range_count(function, parameter, minimum, maximum, \ 677 _expect_not_in_range(#function, #parameter, __FILE__, __LINE__, \ 678 minimum, maximum, count) 700 #define expect_value(function, parameter, value) \ 701 expect_value_count(function, parameter, value, 1) 727 #define expect_value_count(function, parameter, value, count) \ 728 _expect_value(#function, #parameter, __FILE__, __LINE__, \ 729 cast_to_largest_integral_type(value), count) 748 #define expect_not_value(function, parameter, value) \ 749 expect_not_value_count(function, parameter, value, 1) 772 #define expect_not_value_count(function, parameter, value, count) \ 773 _expect_not_value(#function, #parameter, __FILE__, __LINE__, \ 774 cast_to_largest_integral_type(value), count) 792 void expect_string(#
function, #parameter,
const char *
string);
794 #define expect_string(function, parameter, string) \ 795 expect_string_count(function, parameter, string, 1) 819 #define expect_string_count(function, parameter, string, count) \ 820 _expect_string(#function, #parameter, __FILE__, __LINE__, \ 821 (const char*)(string), count) 841 #define expect_not_string(function, parameter, string) \ 842 expect_not_string_count(function, parameter, string, 1) 866 #define expect_not_string_count(function, parameter, string, count) \ 867 _expect_not_string(#function, #parameter, __FILE__, __LINE__, \ 868 (const char*)(string), count) 887 void expect_memory(#
function, #parameter,
void *memory,
size_t size);
889 #define expect_memory(function, parameter, memory, size) \ 890 expect_memory_count(function, parameter, memory, size, 1) 916 #define expect_memory_count(function, parameter, memory, size, count) \ 917 _expect_memory(#function, #parameter, __FILE__, __LINE__, \ 918 (const void*)(memory), size, count) 940 #define expect_not_memory(function, parameter, memory, size) \ 941 expect_not_memory_count(function, parameter, memory, size, 1) 967 #define expect_not_memory_count(function, parameter, memory, size, count) \ 968 _expect_not_memory(#function, #parameter, __FILE__, __LINE__, \ 969 (const void*)(memory), size, count) 987 #define expect_any(function, parameter) \ 988 expect_any_count(function, parameter, 1) 1005 #define expect_any_always(function, parameter) \ 1006 expect_any_count(function, parameter, WILL_RETURN_ALWAYS) 1028 #define expect_any_count(function, parameter, count) \ 1029 _expect_any(#function, #parameter, __FILE__, __LINE__, count) 1045 #define check_expected(parameter) \ 1046 _check_expected(__func__, #parameter, __FILE__, __LINE__, \ 1047 cast_to_largest_integral_type(parameter)) 1063 #define check_expected_ptr(parameter) \ 1064 _check_expected(__func__, #parameter, __FILE__, __LINE__, \ 1065 cast_ptr_to_largest_integral_type(parameter)) 1104 #define assert_true(c) _assert_true(cast_to_largest_integral_type(c), #c, \ 1122 #define assert_false(c) _assert_true(!(cast_to_largest_integral_type(c)), #c, \ 1141 #define assert_return_code(rc, error) \ 1142 _assert_return_code(cast_to_largest_integral_type(rc), \ 1144 cast_to_largest_integral_type(error), \ 1145 #rc, __FILE__, __LINE__) 1161 #define assert_non_null(c) _assert_true(cast_ptr_to_largest_integral_type(c), #c, \ 1178 #define assert_null(c) _assert_true(!(cast_ptr_to_largest_integral_type(c)), #c, \ 1195 #define assert_ptr_equal(a, b) \ 1196 _assert_int_equal(cast_ptr_to_largest_integral_type(a), \ 1197 cast_ptr_to_largest_integral_type(b), \ 1214 #define assert_ptr_not_equal(a, b) \ 1215 _assert_int_not_equal(cast_ptr_to_largest_integral_type(a), \ 1216 cast_ptr_to_largest_integral_type(b), \ 1233 #define assert_int_equal(a, b) \ 1234 _assert_int_equal(cast_to_largest_integral_type(a), \ 1235 cast_to_largest_integral_type(b), \ 1254 #define assert_int_not_equal(a, b) \ 1255 _assert_int_not_equal(cast_to_largest_integral_type(a), \ 1256 cast_to_largest_integral_type(b), \ 1275 #define assert_float_equal(a, b, epsilon) \ 1276 _assert_float_equal((float)a, \ 1297 #define assert_float_not_equal(a, b, epsilon) \ 1298 _assert_float_not_equal((float)a, \ 1319 #define assert_double_equal(a, b, epsilon) \ 1320 _assert_double_equal((double)a, \ 1341 #define assert_double_not_equal(a, b, epsilon) \ 1342 _assert_double_not_equal((float)a, \ 1362 #define assert_string_equal(a, b) \ 1363 _assert_string_equal((a), (b), __FILE__, __LINE__) 1379 #define assert_string_not_equal(a, b) \ 1380 _assert_string_not_equal((a), (b), __FILE__, __LINE__) 1400 #define assert_memory_equal(a, b, size) \ 1401 _assert_memory_equal((const void*)(a), (const void*)(b), size, __FILE__, \ 1422 #define assert_memory_not_equal(a, b, size) \ 1423 _assert_memory_not_equal((const void*)(a), (const void*)(b), size, \ 1443 #define assert_in_range(value, minimum, maximum) \ 1445 cast_to_largest_integral_type(value), \ 1446 cast_to_largest_integral_type(minimum), \ 1447 cast_to_largest_integral_type(maximum), __FILE__, __LINE__) 1466 #define assert_not_in_range(value, minimum, maximum) \ 1467 _assert_not_in_range( \ 1468 cast_to_largest_integral_type(value), \ 1469 cast_to_largest_integral_type(minimum), \ 1470 cast_to_largest_integral_type(maximum), __FILE__, __LINE__) 1488 #define assert_in_set(value, values, number_of_values) \ 1489 _assert_in_set(value, values, number_of_values, __FILE__, __LINE__) 1507 #define assert_not_in_set(value, values, number_of_values) \ 1508 _assert_not_in_set(value, values, number_of_values, __FILE__, __LINE__) 1583 #define function_called() _function_called(__func__, __FILE__, __LINE__) 1599 #define expect_function_calls(function, times) \ 1600 _expect_function_call(#function, __FILE__, __LINE__, times) 1614 #define expect_function_call(function) \ 1615 _expect_function_call(#function, __FILE__, __LINE__, 1) 1628 #define expect_function_call_any(function) \ 1629 _expect_function_call(#function, __FILE__, __LINE__, -1) 1642 #define ignore_function_calls(function) \ 1643 _expect_function_call(#function, __FILE__, __LINE__, -2) 1680 #define fail() _fail(__FILE__, __LINE__) 1689 #define skip() _skip(__FILE__, __LINE__) 1707 void fail_msg(
const char *msg, ...);
1709 #define fail_msg(msg, ...) do { \ 1710 cm_print_error("ERROR: " msg "\n", ##__VA_ARGS__); \ 1737 #define run_test(f) _run_test(#f, f, NULL, UNIT_TEST_FUNCTION_TYPE_TEST, NULL) 1740 static inline void _unit_test_dummy(
void **state) {
1748 #define unit_test(f) { #f, f, UNIT_TEST_FUNCTION_TYPE_TEST } 1750 #define _unit_test_setup(test, setup) \ 1751 { #test "_" #setup, setup, UNIT_TEST_FUNCTION_TYPE_SETUP } 1757 #define unit_test_setup(test, setup) \ 1758 _unit_test_setup(test, setup), \ 1760 _unit_test_teardown(test, _unit_test_dummy) 1762 #define _unit_test_teardown(test, teardown) \ 1763 { #test "_" #teardown, teardown, UNIT_TEST_FUNCTION_TYPE_TEARDOWN } 1769 #define unit_test_teardown(test, teardown) \ 1770 _unit_test_setup(test, _unit_test_dummy), \ 1772 _unit_test_teardown(test, teardown) 1778 #define group_test_setup(setup) \ 1779 { "group_" #setup, setup, UNIT_TEST_FUNCTION_TYPE_GROUP_SETUP } 1785 #define group_test_teardown(teardown) \ 1786 { "group_" #teardown, teardown, UNIT_TEST_FUNCTION_TYPE_GROUP_TEARDOWN } 1795 #define unit_test_setup_teardown(test, setup, teardown) \ 1796 _unit_test_setup(test, setup), \ 1798 _unit_test_teardown(test, teardown) 1802 #define cmocka_unit_test(f) { #f, f, NULL, NULL, NULL } 1805 #define cmocka_unit_test_setup(f, setup) { #f, f, setup, NULL, NULL } 1808 #define cmocka_unit_test_teardown(f, teardown) { #f, f, NULL, teardown, NULL } 1814 #define cmocka_unit_test_setup_teardown(f, setup, teardown) { #f, f, setup, teardown, NULL } 1823 #define cmocka_unit_test_prestate(f, state) { #f, f, NULL, NULL, state } 1832 #define cmocka_unit_test_prestate_setup_teardown(f, setup, teardown, state) { #f, f, setup, teardown, state } 1834 #define run_tests(tests) _run_tests(tests, sizeof(tests) / sizeof((tests)[0])) 1835 #define run_group_tests(tests) _run_group_tests(tests, sizeof(tests) / sizeof((tests)[0])) 1895 CMFixtureFunction group_setup,
1896 CMFixtureFunction group_teardown);
1898 # define cmocka_run_group_tests(group_tests, group_setup, group_teardown) \ 1899 _cmocka_run_group_tests(#group_tests, group_tests, sizeof(group_tests) / sizeof((group_tests)[0]), group_setup, group_teardown) 1964 CMFixtureFunction group_setup,
1965 CMFixtureFunction group_teardown);
1967 # define cmocka_run_group_tests_name(group_name, group_tests, group_setup, group_teardown) \ 1968 _cmocka_run_group_tests(group_name, group_tests, sizeof(group_tests) / sizeof((group_tests)[0]), group_setup, group_teardown) 2021 #define test_malloc(size) _test_malloc(size, __FILE__, __LINE__) 2040 #define test_calloc(num, size) _test_calloc(num, size, __FILE__, __LINE__) 2056 #define test_realloc(ptr, size) _test_realloc(ptr, size, __FILE__, __LINE__) 2069 #define test_free(ptr) _test_free(ptr, __FILE__, __LINE__) 2074 #define malloc test_malloc 2075 #define realloc test_realloc 2076 #define calloc test_calloc 2077 #define free test_free 2133 void mock_assert(
const int result,
const char*
const expression,
2134 const char *
const file,
const int line);
2161 #define expect_assert_failure(function_call) \ 2163 const int result = setjmp(global_expect_assert_env); \ 2164 global_expecting_assert = 1; \ 2166 print_message("Expected assertion %s occurred\n", \ 2167 global_last_failed_assert); \ 2168 global_expecting_assert = 0; \ 2171 global_expecting_assert = 0; \ 2172 print_error("Expected assert in %s\n", #function_call); \ 2173 _fail(__FILE__, __LINE__); \ 2181 typedef void (*UnitTestFunction)(
void **state);
2188 typedef enum UnitTestFunctionType {
2189 UNIT_TEST_FUNCTION_TYPE_TEST = 0,
2190 UNIT_TEST_FUNCTION_TYPE_SETUP,
2191 UNIT_TEST_FUNCTION_TYPE_TEARDOWN,
2192 UNIT_TEST_FUNCTION_TYPE_GROUP_SETUP,
2193 UNIT_TEST_FUNCTION_TYPE_GROUP_TEARDOWN,
2194 } UnitTestFunctionType;
2203 UnitTestFunction
function;
2204 UnitTestFunctionType function_type;
2208 UnitTestFunction setup;
2209 UnitTestFunction teardown;
2211 const size_t number_of_tests;
2215 typedef void (*CMUnitTestFunction)(
void **state);
2218 typedef int (*CMFixtureFunction)(
void **state);
2222 CMUnitTestFunction test_func;
2223 CMFixtureFunction setup_func;
2224 CMFixtureFunction teardown_func;
2225 void *initial_state;
2237 const char *parameter_name;
2238 CheckParameterValue check_value;
2243 extern int global_expecting_assert;
2244 extern jmp_buf global_expect_assert_env;
2245 extern const char * global_last_failed_assert;
2251 void _expect_function_call(
2252 const char *
const function_name,
2253 const char *
const file,
2257 void _function_called(
const char *
const function,
const char*
const file,
2261 const char*
const function,
const char*
const parameter,
2262 const char*
const file,
const int line,
2263 const CheckParameterValue check_function,
2267 void _expect_in_set(
2268 const char*
const function,
const char*
const parameter,
2270 const size_t number_of_values,
const int count);
2271 void _expect_not_in_set(
2272 const char*
const function,
const char*
const parameter,
2274 const size_t number_of_values,
const int count);
2276 void _expect_in_range(
2277 const char*
const function,
const char*
const parameter,
2278 const char*
const file,
const int line,
2281 void _expect_not_in_range(
2282 const char*
const function,
const char*
const parameter,
2283 const char*
const file,
const int line,
2288 const char*
const function,
const char*
const parameter,
2291 void _expect_not_value(
2292 const char*
const function,
const char*
const parameter,
2296 void _expect_string(
2297 const char*
const function,
const char*
const parameter,
2298 const char*
const file,
const int line,
const char*
string,
2300 void _expect_not_string(
2301 const char*
const function,
const char*
const parameter,
2302 const char*
const file,
const int line,
const char*
string,
2305 void _expect_memory(
2306 const char*
const function,
const char*
const parameter,
2307 const char*
const file,
const int line,
const void*
const memory,
2308 const size_t size,
const int count);
2309 void _expect_not_memory(
2310 const char*
const function,
const char*
const parameter,
2311 const char*
const file,
const int line,
const void*
const memory,
2312 const size_t size,
const int count);
2315 const char*
const function,
const char*
const parameter,
2316 const char*
const file,
const int line,
const int count);
2318 void _check_expected(
2319 const char *
const function_name,
const char *
const parameter_name,
2322 void _will_return(
const char *
const function_name,
const char *
const file,
2326 const char*
const expression,
2327 const char *
const file,
const int line);
2331 const char *
const expression,
2332 const char *
const file,
2334 void _assert_float_equal(
const float a,
const float n,
2335 const float epsilon,
const char*
const file,
2337 void _assert_float_not_equal(
const float a,
const float n,
2338 const float epsilon,
const char*
const file,
2340 void _assert_double_equal(
const double a,
const double n,
2341 const double epsilon,
const char*
const file,
2343 void _assert_double_not_equal(
const double a,
const double n,
2344 const double epsilon,
const char*
const file,
2346 void _assert_int_equal(
2348 const char *
const file,
const int line);
2349 void _assert_int_not_equal(
2351 const char *
const file,
const int line);
2352 void _assert_string_equal(
const char *
const a,
const char *
const b,
2353 const char *
const file,
const int line);
2354 void _assert_string_not_equal(
const char *
const a,
const char *
const b,
2355 const char *file,
const int line);
2356 void _assert_memory_equal(
const void *
const a,
const void *
const b,
2357 const size_t size,
const char*
const file,
2359 void _assert_memory_not_equal(
const void *
const a,
const void *
const b,
2360 const size_t size,
const char*
const file,
2362 void _assert_in_range(
2365 void _assert_not_in_range(
2368 void _assert_in_set(
2370 const size_t number_of_values,
const char*
const file,
const int line);
2371 void _assert_not_in_set(
2373 const size_t number_of_values,
const char*
const file,
const int line);
2375 void* _test_malloc(
const size_t size,
const char* file,
const int line);
2376 void* _test_realloc(
void *ptr,
const size_t size,
const char* file,
const int line);
2377 void* _test_calloc(
const size_t number_of_elements,
const size_t size,
2378 const char* file,
const int line);
2379 void _test_free(
void*
const ptr,
const char* file,
const int line);
2381 CMOCKA_NORETURN
void _fail(
const char *
const file,
const int line);
2383 CMOCKA_NORETURN
void _skip(
const char *
const file,
const int line);
2386 const char *
const function_name,
const UnitTestFunction Function,
2387 void **
const volatile state,
const UnitTestFunctionType function_type,
2388 const void*
const heap_check_point);
2389 CMOCKA_DEPRECATED
int _run_tests(
const UnitTest *
const tests,
2390 const size_t number_of_tests);
2391 CMOCKA_DEPRECATED
int _run_group_tests(
const UnitTest *
const tests,
2392 const size_t number_of_tests);
2395 int _cmocka_run_group_tests(
const char *group_name,
2397 const size_t num_tests,
2398 CMFixtureFunction group_setup,
2399 CMFixtureFunction group_teardown);
2402 void print_message(
const char*
const format, ...) CMOCKA_PRINTF_ATTRIBUTE(1, 2);
2403 void print_error(const
char* const format, ...) CMOCKA_PRINTF_ATTRIBUTE(1, 2);
2404 void vprint_message(const
char* const format, va_list args) CMOCKA_PRINTF_ATTRIBUTE(1, 0);
2405 void vprint_error(const
char* const format, va_list args) CMOCKA_PRINTF_ATTRIBUTE(1, 0);
2406 void cm_print_error(const
char* const format, ...) CMOCKA_PRINTF_ATTRIBUTE(1, 2);
2408 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:1769
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:74
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:2207
void cmocka_set_skip_filter(const char *pattern)
Set a pattern to skip tests matching the pattern.
Definition: cmocka.c:2806
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_double_not_equal(double a, double b, double epsilon)
Assert that the two given double are not equal given an epsilon.
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 assert_double_equal(double a, double b, double epsilon)
Assert that the two given double are equal given an epsilon.
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:2229
void cmocka_set_message_output(enum cm_message_output output)
Function to set the output format for a test.
Definition: cmocka.c:2796
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:2220
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 integer based 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:2201
void cmocka_set_test_filter(const char *pattern)
Set a pattern to only run the test matching the pattern.
Definition: cmocka.c:2801
void expect_value_count(#function, #parameter, LargestIntegralType value, size_t count)
Add an event to repeatedly check if a parameter is the given integer based value. ...
Definition: cmocka.h:2235
void assert_in_set(LargestIntegralType value, LargestIntegralType values[], size_t count)
Assert that the specified value is within a set.