19 #include <sys/int_types.h> 24 #define __func__ __FUNCTION__ 27 #define inline __inline 34 int __stdcall IsDebuggerPresent();
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" 111 #define cast_to_largest_integral_type(value) \ 112 ((LargestIntegralType)(value)) 115 #if !defined(_UINTPTR_T) && !defined(_UINTPTR_T_DEFINED) 118 typedef unsigned int uintptr_t;
119 # elif defined(_WIN64) 120 typedef unsigned long int uintptr_t
125 # if __WORDSIZE == 64 126 typedef unsigned long int uintptr_t;
128 typedef unsigned int uintptr_t;
131 # if defined(_LP64) || defined(_I32LPx) 132 typedef unsigned long int uintptr_t;
134 typedef unsigned int uintptr_t;
140 # define _UINTPTR_T_DEFINED 144 #define cast_to_pointer_integral_type(value) \ 145 ((uintptr_t)((size_t)(value))) 148 #define cast_ptr_to_largest_integral_type(value) \ 149 cast_to_largest_integral_type(cast_to_pointer_integral_type(value)) 153 #define CMOCKA_PRINTF_ATTRIBUTE(a,b) \ 154 __attribute__ ((__format__ (__printf__, a, b))) 156 #define CMOCKA_PRINTF_ATTRIBUTE(a,b) 159 #if defined(__GNUC__) 160 #define CMOCKA_DEPRECATED __attribute__ ((deprecated)) 161 #elif defined(_MSC_VER) 162 #define CMOCKA_DEPRECATED __declspec(deprecated) 164 #define CMOCKA_DEPRECATED 167 #define WILL_RETURN_ALWAYS -1 168 #define WILL_RETURN_ONCE -2 228 #define mock() _mock(__func__, __FILE__, __LINE__) 252 #type mock_type(#type); 254 #define mock_type(type) ((type) mock()) 281 #define mock_ptr_type(type) ((type) (uintptr_t) mock()) 312 #define will_return(function, value) \ 313 _will_return(#function, __FILE__, __LINE__, \ 314 cast_to_largest_integral_type(value), 1) 335 #define will_return_count(function, value, count) \ 336 _will_return(#function, __FILE__, __LINE__, \ 337 cast_to_largest_integral_type(value), count) 358 #define will_return_always(function, value) \ 359 will_return_count(function, (value), WILL_RETURN_ALWAYS) 386 #define will_return_maybe(function, value) \ 387 will_return_count(function, (value), WILL_RETURN_ONCE) 458 void expect_check(#
function, #parameter, #check_function,
const void *check_data);
460 #define expect_check(function, parameter, check_function, check_data) \ 461 _expect_check(#function, #parameter, __FILE__, __LINE__, check_function, \ 462 cast_to_largest_integral_type(check_data), NULL, 1) 482 #define expect_in_set(function, parameter, value_array) \ 483 expect_in_set_count(function, parameter, value_array, 1) 507 #define expect_in_set_count(function, parameter, value_array, count) \ 508 _expect_in_set(#function, #parameter, __FILE__, __LINE__, value_array, \ 509 sizeof(value_array) / sizeof((value_array)[0]), count) 529 #define expect_not_in_set(function, parameter, value_array) \ 530 expect_not_in_set_count(function, parameter, value_array, 1) 554 #define expect_not_in_set_count(function, parameter, value_array, count) \ 555 _expect_not_in_set( \ 556 #function, #parameter, __FILE__, __LINE__, value_array, \ 557 sizeof(value_array) / sizeof((value_array)[0]), count) 580 #define expect_in_range(function, parameter, minimum, maximum) \ 581 expect_in_range_count(function, parameter, minimum, maximum, 1) 607 #define expect_in_range_count(function, parameter, minimum, maximum, count) \ 608 _expect_in_range(#function, #parameter, __FILE__, __LINE__, minimum, \ 631 #define expect_not_in_range(function, parameter, minimum, maximum) \ 632 expect_not_in_range_count(function, parameter, minimum, maximum, 1) 658 #define expect_not_in_range_count(function, parameter, minimum, maximum, \ 660 _expect_not_in_range(#function, #parameter, __FILE__, __LINE__, \ 661 minimum, maximum, count) 680 #define expect_value(function, parameter, value) \ 681 expect_value_count(function, parameter, value, 1) 704 #define expect_value_count(function, parameter, value, count) \ 705 _expect_value(#function, #parameter, __FILE__, __LINE__, \ 706 cast_to_largest_integral_type(value), count) 725 #define expect_not_value(function, parameter, value) \ 726 expect_not_value_count(function, parameter, value, 1) 749 #define expect_not_value_count(function, parameter, value, count) \ 750 _expect_not_value(#function, #parameter, __FILE__, __LINE__, \ 751 cast_to_largest_integral_type(value), count) 769 void expect_string(#
function, #parameter,
const char *
string);
771 #define expect_string(function, parameter, string) \ 772 expect_string_count(function, parameter, string, 1) 796 #define expect_string_count(function, parameter, string, count) \ 797 _expect_string(#function, #parameter, __FILE__, __LINE__, \ 798 (const char*)(string), count) 818 #define expect_not_string(function, parameter, string) \ 819 expect_not_string_count(function, parameter, string, 1) 843 #define expect_not_string_count(function, parameter, string, count) \ 844 _expect_not_string(#function, #parameter, __FILE__, __LINE__, \ 845 (const char*)(string), count) 864 void expect_memory(#
function, #parameter,
void *memory,
size_t size);
866 #define expect_memory(function, parameter, memory, size) \ 867 expect_memory_count(function, parameter, memory, size, 1) 893 #define expect_memory_count(function, parameter, memory, size, count) \ 894 _expect_memory(#function, #parameter, __FILE__, __LINE__, \ 895 (const void*)(memory), size, count) 917 #define expect_not_memory(function, parameter, memory, size) \ 918 expect_not_memory_count(function, parameter, memory, size, 1) 944 #define expect_not_memory_count(function, parameter, memory, size, count) \ 945 _expect_not_memory(#function, #parameter, __FILE__, __LINE__, \ 946 (const void*)(memory), size, count) 964 #define expect_any(function, parameter) \ 965 expect_any_count(function, parameter, 1) 987 #define expect_any_count(function, parameter, count) \ 988 _expect_any(#function, #parameter, __FILE__, __LINE__, count) 1004 #define check_expected(parameter) \ 1005 _check_expected(__func__, #parameter, __FILE__, __LINE__, \ 1006 cast_to_largest_integral_type(parameter)) 1022 #define check_expected_ptr(parameter) \ 1023 _check_expected(__func__, #parameter, __FILE__, __LINE__, \ 1024 cast_ptr_to_largest_integral_type(parameter)) 1063 #define assert_true(c) _assert_true(cast_to_largest_integral_type(c), #c, \ 1081 #define assert_false(c) _assert_true(!(cast_to_largest_integral_type(c)), #c, \ 1100 #define assert_return_code(rc, error) \ 1101 _assert_return_code(cast_to_largest_integral_type(rc), \ 1103 cast_to_largest_integral_type(error), \ 1104 #rc, __FILE__, __LINE__) 1120 #define assert_non_null(c) _assert_true(cast_ptr_to_largest_integral_type(c), #c, \ 1137 #define assert_null(c) _assert_true(!(cast_ptr_to_largest_integral_type(c)), #c, \ 1154 #define assert_ptr_equal(a, b) \ 1155 _assert_int_equal(cast_ptr_to_largest_integral_type(a), \ 1156 cast_ptr_to_largest_integral_type(b), \ 1173 #define assert_ptr_not_equal(a, b) \ 1174 _assert_int_not_equal(cast_ptr_to_largest_integral_type(a), \ 1175 cast_ptr_to_largest_integral_type(b), \ 1192 #define assert_int_equal(a, b) \ 1193 _assert_int_equal(cast_to_largest_integral_type(a), \ 1194 cast_to_largest_integral_type(b), \ 1213 #define assert_int_not_equal(a, b) \ 1214 _assert_int_not_equal(cast_to_largest_integral_type(a), \ 1215 cast_to_largest_integral_type(b), \ 1232 #define assert_string_equal(a, b) \ 1233 _assert_string_equal((const char*)(a), (const char*)(b), __FILE__, \ 1250 #define assert_string_not_equal(a, b) \ 1251 _assert_string_not_equal((const char*)(a), (const char*)(b), __FILE__, \ 1272 #define assert_memory_equal(a, b, size) \ 1273 _assert_memory_equal((const void*)(a), (const void*)(b), size, __FILE__, \ 1294 #define assert_memory_not_equal(a, b, size) \ 1295 _assert_memory_not_equal((const void*)(a), (const void*)(b), size, \ 1315 #define assert_in_range(value, minimum, maximum) \ 1317 cast_to_largest_integral_type(value), \ 1318 cast_to_largest_integral_type(minimum), \ 1319 cast_to_largest_integral_type(maximum), __FILE__, __LINE__) 1338 #define assert_not_in_range(value, minimum, maximum) \ 1339 _assert_not_in_range( \ 1340 cast_to_largest_integral_type(value), \ 1341 cast_to_largest_integral_type(minimum), \ 1342 cast_to_largest_integral_type(maximum), __FILE__, __LINE__) 1360 #define assert_in_set(value, values, number_of_values) \ 1361 _assert_in_set(value, values, number_of_values, __FILE__, __LINE__) 1379 #define assert_not_in_set(value, values, number_of_values) \ 1380 _assert_not_in_set(value, values, number_of_values, __FILE__, __LINE__) 1452 #define function_called() _function_called(__func__, __FILE__, __LINE__) 1468 #define expect_function_calls(function, times) \ 1469 _expect_function_call(#function, __FILE__, __LINE__, times) 1483 #define expect_function_call(function) \ 1484 _expect_function_call(#function, __FILE__, __LINE__, 1) 1497 #define expect_function_call_any(function) \ 1498 _expect_function_call(#function, __FILE__, __LINE__, -1) 1511 #define ignore_function_calls(function) \ 1512 _expect_function_call(#function, __FILE__, __LINE__, -2) 1549 #define fail() _fail(__FILE__, __LINE__) 1558 #define skip() _skip(__FILE__, __LINE__) 1576 void fail_msg(
const char *msg, ...);
1578 #define fail_msg(msg, ...) do { \ 1579 print_error("ERROR: " msg "\n", ##__VA_ARGS__); \ 1606 #define run_test(f) _run_test(#f, f, NULL, UNIT_TEST_FUNCTION_TYPE_TEST, NULL) 1609 static inline void _unit_test_dummy(
void **state) {
1617 #define unit_test(f) { #f, f, UNIT_TEST_FUNCTION_TYPE_TEST } 1619 #define _unit_test_setup(test, setup) \ 1620 { #test "_" #setup, setup, UNIT_TEST_FUNCTION_TYPE_SETUP } 1626 #define unit_test_setup(test, setup) \ 1627 _unit_test_setup(test, setup), \ 1629 _unit_test_teardown(test, _unit_test_dummy) 1631 #define _unit_test_teardown(test, teardown) \ 1632 { #test "_" #teardown, teardown, UNIT_TEST_FUNCTION_TYPE_TEARDOWN } 1638 #define unit_test_teardown(test, teardown) \ 1639 _unit_test_setup(test, _unit_test_dummy), \ 1641 _unit_test_teardown(test, teardown) 1647 #define group_test_setup(setup) \ 1648 { "group_" #setup, setup, UNIT_TEST_FUNCTION_TYPE_GROUP_SETUP } 1654 #define group_test_teardown(teardown) \ 1655 { "group_" #teardown, teardown, UNIT_TEST_FUNCTION_TYPE_GROUP_TEARDOWN } 1664 #define unit_test_setup_teardown(test, setup, teardown) \ 1665 _unit_test_setup(test, setup), \ 1667 _unit_test_teardown(test, teardown) 1671 #define cmocka_unit_test(f) { #f, f, NULL, NULL, NULL } 1674 #define cmocka_unit_test_setup(f, setup) { #f, f, setup, NULL, NULL } 1677 #define cmocka_unit_test_teardown(f, teardown) { #f, f, NULL, teardown, NULL } 1683 #define cmocka_unit_test_setup_teardown(f, setup, teardown) { #f, f, setup, teardown, NULL } 1692 #define cmocka_unit_test_prestate(f, state) { #f, f, NULL, NULL, state } 1701 #define cmocka_unit_test_prestate_setup_teardown(f, setup, teardown, state) { #f, f, setup, teardown, state } 1703 #define run_tests(tests) _run_tests(tests, sizeof(tests) / sizeof(tests)[0]) 1704 #define run_group_tests(tests) _run_group_tests(tests, sizeof(tests) / sizeof(tests)[0]) 1764 CMFixtureFunction group_setup,
1765 CMFixtureFunction group_teardown);
1767 # define cmocka_run_group_tests(group_tests, group_setup, group_teardown) \ 1768 _cmocka_run_group_tests(#group_tests, group_tests, sizeof(group_tests) / sizeof(group_tests)[0], group_setup, group_teardown) 1832 const struct CMUnitTest group_tests[],
1833 CMFixtureFunction group_setup,
1834 CMFixtureFunction group_teardown);
1836 # define cmocka_run_group_tests_name(group_name, group_tests, group_setup, group_teardown) \ 1837 _cmocka_run_group_tests(group_name, group_tests, sizeof(group_tests) / sizeof(group_tests)[0], group_setup, group_teardown) 1890 #define test_malloc(size) _test_malloc(size, __FILE__, __LINE__) 1909 #define test_calloc(num, size) _test_calloc(num, size, __FILE__, __LINE__) 1925 #define test_realloc(ptr, size) _test_realloc(ptr, size, __FILE__, __LINE__) 1938 #define test_free(ptr) _test_free(ptr, __FILE__, __LINE__) 1943 #define malloc test_malloc 1944 #define realloc test_realloc 1945 #define calloc test_calloc 1946 #define free test_free 2002 void mock_assert(
const int result,
const char*
const expression,
2003 const char *
const file,
const int line);
2030 #define expect_assert_failure(function_call) \ 2032 const int result = setjmp(global_expect_assert_env); \ 2033 global_expecting_assert = 1; \ 2035 print_message("Expected assertion %s occurred\n", \ 2036 global_last_failed_assert); \ 2037 global_expecting_assert = 0; \ 2040 global_expecting_assert = 0; \ 2041 print_error("Expected assert in %s\n", #function_call); \ 2042 _fail(__FILE__, __LINE__); \ 2050 typedef void (*UnitTestFunction)(
void **state);
2057 typedef enum UnitTestFunctionType {
2058 UNIT_TEST_FUNCTION_TYPE_TEST = 0,
2059 UNIT_TEST_FUNCTION_TYPE_SETUP,
2060 UNIT_TEST_FUNCTION_TYPE_TEARDOWN,
2061 UNIT_TEST_FUNCTION_TYPE_GROUP_SETUP,
2062 UNIT_TEST_FUNCTION_TYPE_GROUP_TEARDOWN,
2063 } UnitTestFunctionType;
2070 typedef struct UnitTest {
2072 UnitTestFunction
function;
2073 UnitTestFunctionType function_type;
2076 typedef struct GroupTest {
2077 UnitTestFunction setup;
2078 UnitTestFunction teardown;
2079 const UnitTest *tests;
2080 const size_t number_of_tests;
2084 typedef void (*CMUnitTestFunction)(
void **state);
2087 typedef int (*CMFixtureFunction)(
void **state);
2091 CMUnitTestFunction test_func;
2092 CMFixtureFunction setup_func;
2093 CMFixtureFunction teardown_func;
2094 void *initial_state;
2098 typedef struct SourceLocation {
2104 typedef struct CheckParameterEvent {
2105 SourceLocation location;
2106 const char *parameter_name;
2107 CheckParameterValue check_value;
2109 } CheckParameterEvent;
2112 extern int global_expecting_assert;
2113 extern jmp_buf global_expect_assert_env;
2114 extern const char * global_last_failed_assert;
2120 void _expect_function_call(
2121 const char *
const function_name,
2122 const char *
const file,
2126 void _function_called(
const char *
const function,
const char*
const file,
2130 const char*
const function,
const char*
const parameter,
2131 const char*
const file,
const int line,
2132 const CheckParameterValue check_function,
2136 void _expect_in_set(
2137 const char*
const function,
const char*
const parameter,
2139 const size_t number_of_values,
const int count);
2140 void _expect_not_in_set(
2141 const char*
const function,
const char*
const parameter,
2143 const size_t number_of_values,
const int count);
2145 void _expect_in_range(
2146 const char*
const function,
const char*
const parameter,
2147 const char*
const file,
const int line,
2150 void _expect_not_in_range(
2151 const char*
const function,
const char*
const parameter,
2152 const char*
const file,
const int line,
2157 const char*
const function,
const char*
const parameter,
2160 void _expect_not_value(
2161 const char*
const function,
const char*
const parameter,
2165 void _expect_string(
2166 const char*
const function,
const char*
const parameter,
2167 const char*
const file,
const int line,
const char*
string,
2169 void _expect_not_string(
2170 const char*
const function,
const char*
const parameter,
2171 const char*
const file,
const int line,
const char*
string,
2174 void _expect_memory(
2175 const char*
const function,
const char*
const parameter,
2176 const char*
const file,
const int line,
const void*
const memory,
2177 const size_t size,
const int count);
2178 void _expect_not_memory(
2179 const char*
const function,
const char*
const parameter,
2180 const char*
const file,
const int line,
const void*
const memory,
2181 const size_t size,
const int count);
2184 const char*
const function,
const char*
const parameter,
2185 const char*
const file,
const int line,
const int count);
2187 void _check_expected(
2188 const char *
const function_name,
const char *
const parameter_name,
2191 void _will_return(
const char *
const function_name,
const char *
const file,
2195 const char*
const expression,
2196 const char *
const file,
const int line);
2200 const char *
const expression,
2201 const char *
const file,
2203 void _assert_int_equal(
2205 const char *
const file,
const int line);
2206 void _assert_int_not_equal(
2208 const char *
const file,
const int line);
2209 void _assert_string_equal(
const char *
const a,
const char *
const b,
2210 const char *
const file,
const int line);
2211 void _assert_string_not_equal(
const char *
const a,
const char *
const b,
2212 const char *file,
const int line);
2213 void _assert_memory_equal(
const void *
const a,
const void *
const b,
2214 const size_t size,
const char*
const file,
2216 void _assert_memory_not_equal(
const void *
const a,
const void *
const b,
2217 const size_t size,
const char*
const file,
2219 void _assert_in_range(
2222 void _assert_not_in_range(
2225 void _assert_in_set(
2227 const size_t number_of_values,
const char*
const file,
const int line);
2228 void _assert_not_in_set(
2230 const size_t number_of_values,
const char*
const file,
const int line);
2232 void* _test_malloc(
const size_t size,
const char* file,
const int line);
2233 void* _test_realloc(
void *ptr,
const size_t size,
const char* file,
const int line);
2234 void* _test_calloc(
const size_t number_of_elements,
const size_t size,
2235 const char* file,
const int line);
2236 void _test_free(
void*
const ptr,
const char* file,
const int line);
2238 void _fail(
const char *
const file,
const int line);
2240 void _skip(
const char *
const file,
const int line);
2243 const char *
const function_name,
const UnitTestFunction Function,
2244 void **
const volatile state,
const UnitTestFunctionType function_type,
2245 const void*
const heap_check_point);
2246 CMOCKA_DEPRECATED
int _run_tests(
const UnitTest *
const tests,
2247 const size_t number_of_tests);
2248 CMOCKA_DEPRECATED
int _run_group_tests(
const UnitTest *
const tests,
2249 const size_t number_of_tests);
2252 int _cmocka_run_group_tests(
const char *group_name,
2253 const struct CMUnitTest *
const tests,
2254 const size_t num_tests,
2255 CMFixtureFunction group_setup,
2256 CMFixtureFunction group_teardown);
2259 void print_message(
const char*
const format, ...) CMOCKA_PRINTF_ATTRIBUTE(1, 2);
2260 void print_error(const
char* const format, ...) CMOCKA_PRINTF_ATTRIBUTE(1, 2);
2261 void vprint_message(const
char* const format, va_list args) CMOCKA_PRINTF_ATTRIBUTE(1, 0);
2262 void vprint_error(const
char* const format, va_list args) CMOCKA_PRINTF_ATTRIBUTE(1, 0);
2264 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:1571
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: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.
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:2513
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.