cmocka
1.1.6
Unit testing library with mock support
|
Functions | |
void | assert_true (scalar expression) |
Assert that the given expression is true. | |
void | assert_false (scalar expression) |
Assert that the given expression is false. | |
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_null (void *pointer) |
Assert that the given pointer is NULL. | |
void | assert_ptr_equal (void *a, void *b) |
Assert that the two given pointers are equal. | |
void | assert_ptr_not_equal (void *a, void *b) |
Assert that the two given pointers are not equal. | |
void | assert_int_equal (int a, int b) |
Assert that the two given integers are equal. | |
void | assert_int_not_equal (int a, int b) |
Assert that the two given integers are not equal. | |
void | assert_float_equal (float a, float b, float epsilon) |
Assert that the two given float are equal given an epsilon. | |
void | assert_float_not_equal (float a, float b, float epsilon) |
Assert that the two given float are not equal given an epsilon. | |
void | assert_double_equal (double a, double b, double epsilon) |
Assert that the two given double are equal given an epsilon. | |
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_string_equal (const char *a, const char *b) |
Assert that the two given strings are equal. | |
void | assert_string_not_equal (const char *a, const char *b) |
Assert that the two given strings are not 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 | 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 | 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 | 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 | assert_in_set (LargestIntegralType value, LargestIntegralType values[], size_t count) |
Assert that the specified value is within a set. | |
void | assert_not_in_set (LargestIntegralType value, LargestIntegralType values[], size_t count) |
Assert that the specified value is not within a set. | |
This is a set of useful assert macros like the standard C libary's assert(3) macro.
On an assertion failure a cmocka assert macro will write the failure to the standard error stream and signal a test failure. Due to limitations of the C language the general C standard library assert() and cmocka's assert_true() and assert_false() macros can only display the expression that caused the assert failure. cmocka's type specific assert macros, assert_{type}_equal() and assert_{type}_not_equal(), display the data that caused the assertion failure which increases data visibility aiding debugging of failing test cases.
void assert_double_equal | ( | double | a, |
double | b, | ||
double | epsilon | ||
) |
Assert that the two given double are equal given an epsilon.
The function prints an error message to standard error and terminates the test by calling fail() if the double are not equal (given an epsilon).
[in] | a | The first double to compare. |
[in] | b | The double to compare against the first one. |
[in] | epsilon | The epsilon used as margin for double comparison. |
void assert_double_not_equal | ( | double | a, |
double | b, | ||
double | epsilon | ||
) |
Assert that the two given double are not equal given an epsilon.
The function prints an error message to standard error and terminates the test by calling fail() if the double are not equal (given an epsilon).
[in] | a | The first double to compare. |
[in] | b | The double to compare against the first one. |
[in] | epsilon | The epsilon used as margin for double comparison. |
void assert_false | ( | scalar | expression | ) |
Assert that the given expression is false.
The function prints an error message to standard error and terminates the test by calling fail() if expression is true.
[in] | expression | The expression to evaluate. |
void assert_float_equal | ( | float | a, |
float | b, | ||
float | epsilon | ||
) |
Assert that the two given float are equal given an epsilon.
The function prints an error message to standard error and terminates the test by calling fail() if the float are not equal (given an epsilon).
[in] | a | The first float to compare. |
[in] | b | The float to compare against the first one. |
[in] | epsilon | The epsilon used as margin for float comparison. |
void assert_float_not_equal | ( | float | a, |
float | b, | ||
float | epsilon | ||
) |
Assert that the two given float are not equal given an epsilon.
The function prints an error message to standard error and terminates the test by calling fail() if the float are not equal (given an epsilon).
[in] | a | The first float to compare. |
[in] | b | The float to compare against the first one. |
[in] | epsilon | The epsilon used as margin for float comparison. |
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.
The function prints an error message to standard error and terminates the test by calling fail() if value is not in range.
[in] | value | The value to check. |
[in] | minimum | The minimum value allowed. |
[in] | maximum | The maximum value allowed. |
void assert_in_set | ( | LargestIntegralType | value, |
LargestIntegralType | values[], | ||
size_t | count | ||
) |
Assert that the specified value is within a set.
The function prints an error message to standard error and terminates the test by calling fail() if value is not within a set.
[in] | value | The value to look up |
[in] | values[] | The array to check for the value. |
[in] | count | The size of the values array. |
void assert_int_equal | ( | int | a, |
int | b | ||
) |
Assert that the two given integers are equal.
The function prints an error message to standard error and terminates the test by calling fail() if the integers are not equal.
[in] | a | The first integer to compare. |
[in] | b | The integer to compare against the first one. |
void assert_int_not_equal | ( | int | a, |
int | b | ||
) |
Assert that the two given integers are not equal.
The function prints an error message to standard error and terminates the test by calling fail() if the integers are equal.
[in] | a | The first integer to compare. |
[in] | b | The integer to compare against the first one. |
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.
The function prints an error message to standard error and terminates the test by calling fail() if the memory is not equal.
[in] | a | The first memory area to compare (interpreted as unsigned char). |
[in] | b | The second memory area to compare (interpreted as unsigned char). |
[in] | size | The first n bytes of the memory areas to compare. |
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.
The function prints an error message to standard error and terminates the test by calling fail() if the memory is equal.
[in] | a | The first memory area to compare (interpreted as unsigned char). |
[in] | b | The second memory area to compare (interpreted as unsigned char). |
[in] | size | The first n bytes of the memory areas to compare. |
void assert_non_null | ( | void * | pointer | ) |
Assert that the given pointer is non-NULL.
The function prints an error message to standard error and terminates the test by calling fail() if the pointer is NULL.
[in] | pointer | The pointer to evaluate. |
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.
The function prints an error message to standard error and terminates the test by calling fail() if value is in range.
[in] | value | The value to check. |
[in] | minimum | The minimum value to compare. |
[in] | maximum | The maximum value to compare. |
void assert_not_in_set | ( | LargestIntegralType | value, |
LargestIntegralType | values[], | ||
size_t | count | ||
) |
Assert that the specified value is not within a set.
The function prints an error message to standard error and terminates the test by calling fail() if value is within a set.
[in] | value | The value to look up |
[in] | values[] | The array to check for the value. |
[in] | count | The size of the values array. |
void assert_null | ( | void * | pointer | ) |
Assert that the given pointer is NULL.
The function prints an error message to standard error and terminates the test by calling fail() if the pointer is non-NULL.
[in] | pointer | The pointer to evaluate. |
void assert_ptr_equal | ( | void * | a, |
void * | b | ||
) |
Assert that the two given pointers are equal.
The function prints an error message and terminates the test by calling fail() if the pointers are not equal.
[in] | a | The first pointer to compare. |
[in] | b | The pointer to compare against the first one. |
void assert_ptr_not_equal | ( | void * | a, |
void * | b | ||
) |
Assert that the two given pointers are not equal.
The function prints an error message and terminates the test by calling fail() if the pointers are equal.
[in] | a | The first pointer to compare. |
[in] | b | The pointer to compare against the first one. |
void assert_return_code | ( | int | rc, |
int | error | ||
) |
Assert that the return_code is greater than or equal to 0.
The function prints an error message to standard error and terminates the test by calling fail() if the return code is smaller than 0. If the function you check sets an errno if it fails you can pass it to the function and it will be printed as part of the error message.
[in] | rc | The return code to evaluate. |
[in] | error | Pass errno here or 0. |
void assert_string_equal | ( | const char * | a, |
const char * | b | ||
) |
Assert that the two given strings are equal.
The function prints an error message to standard error and terminates the test by calling fail() if the strings are not equal.
[in] | a | The string to check. |
[in] | b | The other string to compare. |
void assert_string_not_equal | ( | const char * | a, |
const char * | b | ||
) |
Assert that the two given strings are not equal.
The function prints an error message to standard error and terminates the test by calling fail() if the strings are equal.
[in] | a | The string to check. |
[in] | b | The other string to compare. |
void assert_true | ( | scalar | expression | ) |
Assert that the given expression is true.
The function prints an error message to standard error and terminates the test by calling fail() if expression is false (i.e., compares equal to zero).
[in] | expression | The expression to evaluate. |