22 #define __func__ __FUNCTION__ 25 #define inline __inline 32 int __stdcall IsDebuggerPresent();
59 # if defined(__x86_64__) && !defined(__ILP32__) 60 # define __WORDSIZE 64 62 # define __WORDSIZE 32 73 #ifndef LargestIntegralType 75 # define LargestIntegralType unsigned long int 77 # define LargestIntegralType unsigned long long int 83 #ifndef LargestIntegralTypePrintfFormat 85 # define LargestIntegralTypePrintfFormat "0x%I64x" 88 # define LargestIntegralTypePrintfFormat "%#lx" 90 # define LargestIntegralTypePrintfFormat "%#llx" 96 #ifndef LargestIntegralTypePrintfFormatDecimal 98 # define LargestIntegralTypePrintfFormatDecimal "%I64u" 100 # if __WORDSIZE == 64 101 # define LargestIntegralTypePrintfFormatDecimal "%lu" 103 # define LargestIntegralTypePrintfFormatDecimal "%llu" 109 #define cast_to_largest_integral_type(value) \ 110 ((LargestIntegralType)(value)) 113 #if !defined(_UINTPTR_T) && !defined(_UINTPTR_T_DEFINED) 116 typedef unsigned int uintptr_t;
117 # elif defined(_WIN64) 118 typedef unsigned long int uintptr_t
123 # if __WORDSIZE == 64 124 typedef unsigned long int uintptr_t;
126 typedef unsigned int uintptr_t;
129 # if defined(_LP64) || defined(_I32LPx) 130 typedef unsigned long int uintptr_t;
132 typedef unsigned int uintptr_t;
138 # define _UINTPTR_T_DEFINED 142 #define cast_to_pointer_integral_type(value) \ 143 ((uintptr_t)((size_t)(value))) 146 #define cast_ptr_to_largest_integral_type(value) \ 147 cast_to_largest_integral_type(cast_to_pointer_integral_type(value)) 151 #define CMOCKA_PRINTF_ATTRIBUTE(a,b) \ 152 __attribute__ ((__format__ (__printf__, a, b))) 154 #define CMOCKA_PRINTF_ATTRIBUTE(a,b) 157 #if defined(__GNUC__) 158 #define CMOCKA_DEPRECATED __attribute__ ((deprecated)) 159 #elif defined(_MSC_VER) 160 #define CMOCKA_DEPRECATED __declspec(deprecated) 162 #define CMOCKA_DEPRECATED 165 #define WILL_RETURN_ALWAYS -1 166 #define WILL_RETURN_ONCE -2 226 #define mock() _mock(__func__, __FILE__, __LINE__) 250 #type mock_type(#type); 252 #define mock_type(type) ((type) mock()) 279 #define mock_ptr_type(type) ((type) (uintptr_t) mock()) 310 #define will_return(function, value) \ 311 _will_return(#function, __FILE__, __LINE__, \ 312 cast_to_largest_integral_type(value), 1) 333 #define will_return_count(function, value, count) \ 334 _will_return(#function, __FILE__, __LINE__, \ 335 cast_to_largest_integral_type(value), count) 356 #define will_return_always(function, value) \ 357 will_return_count(function, (value), WILL_RETURN_ALWAYS) 384 #define will_return_maybe(function, value) \ 385 will_return_count(function, (value), WILL_RETURN_ONCE) 456 void expect_check(#
function, #parameter, #check_function,
const void *check_data);
458 #define expect_check(function, parameter, check_function, check_data) \ 459 _expect_check(#function, #parameter, __FILE__, __LINE__, check_function, \ 460 cast_to_largest_integral_type(check_data), NULL, 1) 480 #define expect_in_set(function, parameter, value_array) \ 481 expect_in_set_count(function, parameter, value_array, 1) 505 #define expect_in_set_count(function, parameter, value_array, count) \ 506 _expect_in_set(#function, #parameter, __FILE__, __LINE__, value_array, \ 507 sizeof(value_array) / sizeof((value_array)[0]), count) 527 #define expect_not_in_set(function, parameter, value_array) \ 528 expect_not_in_set_count(function, parameter, value_array, 1) 552 #define expect_not_in_set_count(function, parameter, value_array, count) \ 553 _expect_not_in_set( \ 554 #function, #parameter, __FILE__, __LINE__, value_array, \ 555 sizeof(value_array) / sizeof((value_array)[0]), count) 578 #define expect_in_range(function, parameter, minimum, maximum) \ 579 expect_in_range_count(function, parameter, minimum, maximum, 1) 605 #define expect_in_range_count(function, parameter, minimum, maximum, count) \ 606 _expect_in_range(#function, #parameter, __FILE__, __LINE__, minimum, \ 629 #define expect_not_in_range(function, parameter, minimum, maximum) \ 630 expect_not_in_range_count(function, parameter, minimum, maximum, 1) 656 #define expect_not_in_range_count(function, parameter, minimum, maximum, \ 658 _expect_not_in_range(#function, #parameter, __FILE__, __LINE__, \ 659 minimum, maximum, count) 678 #define expect_value(function, parameter, value) \ 679 expect_value_count(function, parameter, value, 1) 702 #define expect_value_count(function, parameter, value, count) \ 703 _expect_value(#function, #parameter, __FILE__, __LINE__, \ 704 cast_to_largest_integral_type(value), count) 723 #define expect_not_value(function, parameter, value) \ 724 expect_not_value_count(function, parameter, value, 1) 747 #define expect_not_value_count(function, parameter, value, count) \ 748 _expect_not_value(#function, #parameter, __FILE__, __LINE__, \ 749 cast_to_largest_integral_type(value), count) 767 void expect_string(#
function, #parameter,
const char *
string);
769 #define expect_string(function, parameter, string) \ 770 expect_string_count(function, parameter, string, 1) 794 #define expect_string_count(function, parameter, string, count) \ 795 _expect_string(#function, #parameter, __FILE__, __LINE__, \ 796 (const char*)(string), count) 816 #define expect_not_string(function, parameter, string) \ 817 expect_not_string_count(function, parameter, string, 1) 841 #define expect_not_string_count(function, parameter, string, count) \ 842 _expect_not_string(#function, #parameter, __FILE__, __LINE__, \ 843 (const char*)(string), count) 862 void expect_memory(#
function, #parameter,
void *memory,
size_t size);
864 #define expect_memory(function, parameter, memory, size) \ 865 expect_memory_count(function, parameter, memory, size, 1) 891 #define expect_memory_count(function, parameter, memory, size, count) \ 892 _expect_memory(#function, #parameter, __FILE__, __LINE__, \ 893 (const void*)(memory), size, count) 915 #define expect_not_memory(function, parameter, memory, size) \ 916 expect_not_memory_count(function, parameter, memory, size, 1) 942 #define expect_not_memory_count(function, parameter, memory, size, count) \ 943 _expect_not_memory(#function, #parameter, __FILE__, __LINE__, \ 944 (const void*)(memory), size, count) 962 #define expect_any(function, parameter) \ 963 expect_any_count(function, parameter, 1) 985 #define expect_any_count(function, parameter, count) \ 986 _expect_any(#function, #parameter, __FILE__, __LINE__, count) 1002 #define check_expected(parameter) \ 1003 _check_expected(__func__, #parameter, __FILE__, __LINE__, \ 1004 cast_to_largest_integral_type(parameter)) 1020 #define check_expected_ptr(parameter) \ 1021 _check_expected(__func__, #parameter, __FILE__, __LINE__, \ 1022 cast_ptr_to_largest_integral_type(parameter)) 1061 #define assert_true(c) _assert_true(cast_to_largest_integral_type(c), #c, \ 1079 #define assert_false(c) _assert_true(!(cast_to_largest_integral_type(c)), #c, \ 1098 #define assert_return_code(rc, error) \ 1099 _assert_return_code(cast_to_largest_integral_type(rc), \ 1101 cast_to_largest_integral_type(error), \ 1102 #rc, __FILE__, __LINE__) 1118 #define assert_non_null(c) _assert_true(cast_ptr_to_largest_integral_type(c), #c, \ 1135 #define assert_null(c) _assert_true(!(cast_ptr_to_largest_integral_type(c)), #c, \ 1152 #define assert_ptr_equal(a, b) \ 1153 _assert_int_equal(cast_ptr_to_largest_integral_type(a), \ 1154 cast_ptr_to_largest_integral_type(b), \ 1171 #define assert_ptr_not_equal(a, b) \ 1172 _assert_int_not_equal(cast_ptr_to_largest_integral_type(a), \ 1173 cast_ptr_to_largest_integral_type(b), \ 1190 #define assert_int_equal(a, b) \ 1191 _assert_int_equal(cast_to_largest_integral_type(a), \ 1192 cast_to_largest_integral_type(b), \ 1211 #define assert_int_not_equal(a, b) \ 1212 _assert_int_not_equal(cast_to_largest_integral_type(a), \ 1213 cast_to_largest_integral_type(b), \ 1230 #define assert_string_equal(a, b) \ 1231 _assert_string_equal((const char*)(a), (const char*)(b), __FILE__, \ 1248 #define assert_string_not_equal(a, b) \ 1249 _assert_string_not_equal((const char*)(a), (const char*)(b), __FILE__, \ 1270 #define assert_memory_equal(a, b, size) \ 1271 _assert_memory_equal((const void*)(a), (const void*)(b), size, __FILE__, \ 1292 #define assert_memory_not_equal(a, b, size) \ 1293 _assert_memory_not_equal((const void*)(a), (const void*)(b), size, \ 1313 #define assert_in_range(value, minimum, maximum) \ 1315 cast_to_largest_integral_type(value), \ 1316 cast_to_largest_integral_type(minimum), \ 1317 cast_to_largest_integral_type(maximum), __FILE__, __LINE__) 1336 #define assert_not_in_range(value, minimum, maximum) \ 1337 _assert_not_in_range( \ 1338 cast_to_largest_integral_type(value), \ 1339 cast_to_largest_integral_type(minimum), \ 1340 cast_to_largest_integral_type(maximum), __FILE__, __LINE__) 1358 #define assert_in_set(value, values, number_of_values) \ 1359 _assert_in_set(value, values, number_of_values, __FILE__, __LINE__) 1377 #define assert_not_in_set(value, values, number_of_values) \ 1378 _assert_not_in_set(value, values, number_of_values, __FILE__, __LINE__) 1450 #define function_called() _function_called(__func__, __FILE__, __LINE__) 1466 #define expect_function_calls(function, times) \ 1467 _expect_function_call(#function, __FILE__, __LINE__, times) 1481 #define expect_function_call(function) \ 1482 _expect_function_call(#function, __FILE__, __LINE__, 1) 1495 #define expect_function_call_any(function) \ 1496 _expect_function_call(#function, __FILE__, __LINE__, -1) 1509 #define ignore_function_calls(function) \ 1510 _expect_function_call(#function, __FILE__, __LINE__, -2) 1547 #define fail() _fail(__FILE__, __LINE__) 1556 #define skip() _skip(__FILE__, __LINE__) 1574 void fail_msg(
const char *msg, ...);
1576 #define fail_msg(msg, ...) do { \ 1577 print_error("ERROR: " msg "\n", ##__VA_ARGS__); \ 1604 #define run_test(f) _run_test(#f, f, NULL, UNIT_TEST_FUNCTION_TYPE_TEST, NULL) 1607 static inline void _unit_test_dummy(
void **state) {
1615 #define unit_test(f) { #f, f, UNIT_TEST_FUNCTION_TYPE_TEST } 1617 #define _unit_test_setup(test, setup) \ 1618 { #test "_" #setup, setup, UNIT_TEST_FUNCTION_TYPE_SETUP } 1624 #define unit_test_setup(test, setup) \ 1625 _unit_test_setup(test, setup), \ 1627 _unit_test_teardown(test, _unit_test_dummy) 1629 #define _unit_test_teardown(test, teardown) \ 1630 { #test "_" #teardown, teardown, UNIT_TEST_FUNCTION_TYPE_TEARDOWN } 1636 #define unit_test_teardown(test, teardown) \ 1637 _unit_test_setup(test, _unit_test_dummy), \ 1639 _unit_test_teardown(test, teardown) 1645 #define group_test_setup(setup) \ 1646 { "group_" #setup, setup, UNIT_TEST_FUNCTION_TYPE_GROUP_SETUP } 1652 #define group_test_teardown(teardown) \ 1653 { "group_" #teardown, teardown, UNIT_TEST_FUNCTION_TYPE_GROUP_TEARDOWN } 1662 #define unit_test_setup_teardown(test, setup, teardown) \ 1663 _unit_test_setup(test, setup), \ 1665 _unit_test_teardown(test, teardown) 1669 #define cmocka_unit_test(f) { #f, f, NULL, NULL, NULL } 1672 #define cmocka_unit_test_setup(f, setup) { #f, f, setup, NULL, NULL } 1675 #define cmocka_unit_test_teardown(f, teardown) { #f, f, NULL, teardown, NULL } 1681 #define cmocka_unit_test_setup_teardown(f, setup, teardown) { #f, f, setup, teardown, NULL } 1690 #define cmocka_unit_test_prestate(f, state) { #f, f, NULL, NULL, state } 1699 #define cmocka_unit_test_prestate_setup_teardown(f, setup, teardown, state) { #f, f, setup, teardown, state } 1701 #define run_tests(tests) _run_tests(tests, sizeof(tests) / sizeof(tests)[0]) 1702 #define run_group_tests(tests) _run_group_tests(tests, sizeof(tests) / sizeof(tests)[0]) 1762 CMFixtureFunction group_setup,
1763 CMFixtureFunction group_teardown);
1765 # define cmocka_run_group_tests(group_tests, group_setup, group_teardown) \ 1766 _cmocka_run_group_tests(#group_tests, group_tests, sizeof(group_tests) / sizeof(group_tests)[0], group_setup, group_teardown) 1830 const struct CMUnitTest group_tests[],
1831 CMFixtureFunction group_setup,
1832 CMFixtureFunction group_teardown);
1834 # define cmocka_run_group_tests_name(group_name, group_tests, group_setup, group_teardown) \ 1835 _cmocka_run_group_tests(group_name, group_tests, sizeof(group_tests) / sizeof(group_tests)[0], group_setup, group_teardown) 1888 #define test_malloc(size) _test_malloc(size, __FILE__, __LINE__) 1907 #define test_calloc(num, size) _test_calloc(num, size, __FILE__, __LINE__) 1923 #define test_realloc(ptr, size) _test_realloc(ptr, size, __FILE__, __LINE__) 1936 #define test_free(ptr) _test_free(ptr, __FILE__, __LINE__) 1941 #define malloc test_malloc 1942 #define realloc test_realloc 1943 #define calloc test_calloc 1944 #define free test_free 2000 void mock_assert(
const int result,
const char*
const expression,
2001 const char *
const file,
const int line);
2028 #define expect_assert_failure(function_call) \ 2030 const int result = setjmp(global_expect_assert_env); \ 2031 global_expecting_assert = 1; \ 2033 print_message("Expected assertion %s occurred\n", \ 2034 global_last_failed_assert); \ 2035 global_expecting_assert = 0; \ 2038 global_expecting_assert = 0; \ 2039 print_error("Expected assert in %s\n", #function_call); \ 2040 _fail(__FILE__, __LINE__); \ 2048 typedef void (*UnitTestFunction)(
void **state);
2055 typedef enum UnitTestFunctionType {
2056 UNIT_TEST_FUNCTION_TYPE_TEST = 0,
2057 UNIT_TEST_FUNCTION_TYPE_SETUP,
2058 UNIT_TEST_FUNCTION_TYPE_TEARDOWN,
2059 UNIT_TEST_FUNCTION_TYPE_GROUP_SETUP,
2060 UNIT_TEST_FUNCTION_TYPE_GROUP_TEARDOWN,
2061 } UnitTestFunctionType;
2068 typedef struct UnitTest {
2070 UnitTestFunction
function;
2071 UnitTestFunctionType function_type;
2074 typedef struct GroupTest {
2075 UnitTestFunction setup;
2076 UnitTestFunction teardown;
2077 const UnitTest *tests;
2078 const size_t number_of_tests;
2082 typedef void (*CMUnitTestFunction)(
void **state);
2085 typedef int (*CMFixtureFunction)(
void **state);
2089 CMUnitTestFunction test_func;
2090 CMFixtureFunction setup_func;
2091 CMFixtureFunction teardown_func;
2092 void *initial_state;
2096 typedef struct SourceLocation {
2102 typedef struct CheckParameterEvent {
2103 SourceLocation location;
2104 const char *parameter_name;
2105 CheckParameterValue check_value;
2107 } CheckParameterEvent;
2110 extern int global_expecting_assert;
2111 extern jmp_buf global_expect_assert_env;
2112 extern const char * global_last_failed_assert;
2118 void _expect_function_call(
2119 const char *
const function_name,
2120 const char *
const file,
2124 void _function_called(
const char *
const function,
const char*
const file,
2128 const char*
const function,
const char*
const parameter,
2129 const char*
const file,
const int line,
2130 const CheckParameterValue check_function,
2134 void _expect_in_set(
2135 const char*
const function,
const char*
const parameter,
2137 const size_t number_of_values,
const int count);
2138 void _expect_not_in_set(
2139 const char*
const function,
const char*
const parameter,
2141 const size_t number_of_values,
const int count);
2143 void _expect_in_range(
2144 const char*
const function,
const char*
const parameter,
2145 const char*
const file,
const int line,
2148 void _expect_not_in_range(
2149 const char*
const function,
const char*
const parameter,
2150 const char*
const file,
const int line,
2155 const char*
const function,
const char*
const parameter,
2158 void _expect_not_value(
2159 const char*
const function,
const char*
const parameter,
2163 void _expect_string(
2164 const char*
const function,
const char*
const parameter,
2165 const char*
const file,
const int line,
const char*
string,
2167 void _expect_not_string(
2168 const char*
const function,
const char*
const parameter,
2169 const char*
const file,
const int line,
const char*
string,
2172 void _expect_memory(
2173 const char*
const function,
const char*
const parameter,
2174 const char*
const file,
const int line,
const void*
const memory,
2175 const size_t size,
const int count);
2176 void _expect_not_memory(
2177 const char*
const function,
const char*
const parameter,
2178 const char*
const file,
const int line,
const void*
const memory,
2179 const size_t size,
const int count);
2182 const char*
const function,
const char*
const parameter,
2183 const char*
const file,
const int line,
const int count);
2185 void _check_expected(
2186 const char *
const function_name,
const char *
const parameter_name,
2189 void _will_return(
const char *
const function_name,
const char *
const file,
2193 const char*
const expression,
2194 const char *
const file,
const int line);
2198 const char *
const expression,
2199 const char *
const file,
2201 void _assert_int_equal(
2203 const char *
const file,
const int line);
2204 void _assert_int_not_equal(
2206 const char *
const file,
const int line);
2207 void _assert_string_equal(
const char *
const a,
const char *
const b,
2208 const char *
const file,
const int line);
2209 void _assert_string_not_equal(
const char *
const a,
const char *
const b,
2210 const char *file,
const int line);
2211 void _assert_memory_equal(
const void *
const a,
const void *
const b,
2212 const size_t size,
const char*
const file,
2214 void _assert_memory_not_equal(
const void *
const a,
const void *
const b,
2215 const size_t size,
const char*
const file,
2217 void _assert_in_range(
2220 void _assert_not_in_range(
2223 void _assert_in_set(
2225 const size_t number_of_values,
const char*
const file,
const int line);
2226 void _assert_not_in_set(
2228 const size_t number_of_values,
const char*
const file,
const int line);
2230 void* _test_malloc(
const size_t size,
const char* file,
const int line);
2231 void* _test_realloc(
void *ptr,
const size_t size,
const char* file,
const int line);
2232 void* _test_calloc(
const size_t number_of_elements,
const size_t size,
2233 const char* file,
const int line);
2234 void _test_free(
void*
const ptr,
const char* file,
const int line);
2236 void _fail(
const char *
const file,
const int line);
2238 void _skip(
const char *
const file,
const int line);
2241 const char *
const function_name,
const UnitTestFunction Function,
2242 void **
const volatile state,
const UnitTestFunctionType function_type,
2243 const void*
const heap_check_point);
2244 CMOCKA_DEPRECATED
int _run_tests(
const UnitTest *
const tests,
2245 const size_t number_of_tests);
2246 CMOCKA_DEPRECATED
int _run_group_tests(
const UnitTest *
const tests,
2247 const size_t number_of_tests);
2250 int _cmocka_run_group_tests(
const char *group_name,
2251 const struct CMUnitTest *
const tests,
2252 const size_t num_tests,
2253 CMFixtureFunction group_setup,
2254 CMFixtureFunction group_teardown);
2257 void print_message(
const char*
const format, ...) CMOCKA_PRINTF_ATTRIBUTE(1, 2);
2258 void print_error(const
char* const format, ...) CMOCKA_PRINTF_ATTRIBUTE(1, 2);
2259 void vprint_message(const
char* const format, va_list args) CMOCKA_PRINTF_ATTRIBUTE(1, 0);
2260 void vprint_error(const
char* const format, va_list args) CMOCKA_PRINTF_ATTRIBUTE(1, 0);
2262 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 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.
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:1570
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.
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.
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_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
Largest integral type.
Definition: cmocka.h:71
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.
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.
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.
void cmocka_set_message_output(enum cm_message_output output)
Function to set the output format for a test.
Definition: cmocka.c:2512
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.
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 * 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.
void expect_value_count(#function, #parameter, LargestIntegralType value, size_t count)
Add an event to repeatedly check if a parameter is the given value.
void assert_in_set(LargestIntegralType value, LargestIntegralType values[], size_t count)
Assert that the specified value is within a set.