cmocka  1.1.6
Unit testing library with mock support
Loading...
Searching...
No Matches
Functions
Assert Macros
Collaboration diagram for Assert Macros:

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.
 

Detailed Description

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.

Function Documentation

◆ assert_double_equal()

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).

Parameters
[in]aThe first double to compare.
[in]bThe double to compare against the first one.
[in]epsilonThe epsilon used as margin for double comparison.

◆ assert_double_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.

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).

Parameters
[in]aThe first double to compare.
[in]bThe double to compare against the first one.
[in]epsilonThe epsilon used as margin for double comparison.

◆ assert_false()

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.

Parameters
[in]expressionThe expression to evaluate.
See also
assert_int_equal()
assert_string_equal()

◆ assert_float_equal()

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).

Parameters
[in]aThe first float to compare.
[in]bThe float to compare against the first one.
[in]epsilonThe epsilon used as margin for float comparison.

◆ assert_float_not_equal()

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).

Parameters
[in]aThe first float to compare.
[in]bThe float to compare against the first one.
[in]epsilonThe epsilon used as margin for float comparison.

◆ assert_in_range()

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.

Parameters
[in]valueThe value to check.
[in]minimumThe minimum value allowed.
[in]maximumThe maximum value allowed.

◆ assert_in_set()

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.

Parameters
[in]valueThe value to look up
[in]values[]The array to check for the value.
[in]countThe size of the values array.

◆ assert_int_equal()

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.

Parameters
[in]aThe first integer to compare.
[in]bThe integer to compare against the first one.

◆ assert_int_not_equal()

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.

Parameters
[in]aThe first integer to compare.
[in]bThe integer to compare against the first one.
See also
assert_int_equal()

◆ assert_memory_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.

The function prints an error message to standard error and terminates the test by calling fail() if the memory is not equal.

Parameters
[in]aThe first memory area to compare (interpreted as unsigned char).
[in]bThe second memory area to compare (interpreted as unsigned char).
[in]sizeThe first n bytes of the memory areas to compare.

◆ assert_memory_not_equal()

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.

Parameters
[in]aThe first memory area to compare (interpreted as unsigned char).
[in]bThe second memory area to compare (interpreted as unsigned char).
[in]sizeThe first n bytes of the memory areas to compare.

◆ assert_non_null()

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.

Parameters
[in]pointerThe pointer to evaluate.
See also
assert_null()

◆ assert_not_in_range()

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.

Parameters
[in]valueThe value to check.
[in]minimumThe minimum value to compare.
[in]maximumThe maximum value to compare.

◆ assert_not_in_set()

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.

Parameters
[in]valueThe value to look up
[in]values[]The array to check for the value.
[in]countThe size of the values array.

◆ assert_null()

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.

Parameters
[in]pointerThe pointer to evaluate.
See also
assert_non_null()

◆ assert_ptr_equal()

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.

Parameters
[in]aThe first pointer to compare.
[in]bThe pointer to compare against the first one.

◆ assert_ptr_not_equal()

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.

Parameters
[in]aThe first pointer to compare.
[in]bThe pointer to compare against the first one.

◆ assert_return_code()

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.

Parameters
[in]rcThe return code to evaluate.
[in]errorPass errno here or 0.

◆ assert_string_equal()

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.

Parameters
[in]aThe string to check.
[in]bThe other string to compare.

◆ assert_string_not_equal()

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.

Parameters
[in]aThe string to check.
[in]bThe other string to compare.

◆ assert_true()

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).

Parameters
[in]expressionThe expression to evaluate.
See also
assert_int_equal()
assert_string_equal()