cmocka  1.1.0
Functions
Assert Macros

This is a set of useful assert macros like the standard C libary's assert(3) macro. More...

Collaboration diagram for Assert Macros:

Functions

void assert_false (scalar expression)
 Assert that the given expression is false. More...
 
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. More...
 
void assert_in_set (LargestIntegralType value, LargestIntegralType values[], size_t count)
 Assert that the specified value is within a set. More...
 
void assert_int_equal (int a, int b)
 Assert that the two given integers are equal. More...
 
void assert_int_not_equal (int a, int b)
 Assert that the two given integers are not equal. More...
 
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. More...
 
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. More...
 
void assert_non_null (void *pointer)
 Assert that the given pointer is non-NULL. More...
 
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. More...
 
void assert_not_in_set (LargestIntegralType value, LargestIntegralType values[], size_t count)
 Assert that the specified value is not within a set. More...
 
void assert_null (void *pointer)
 Assert that the given pointer is NULL. More...
 
void assert_ptr_equal (void *a, void *b)
 Assert that the two given pointers are equal. More...
 
void assert_ptr_not_equal (void *a, void *b)
 Assert that the two given pointers are not equal. More...
 
void assert_return_code (int rc, int error)
 Assert that the return_code is greater than or equal to 0. More...
 
void assert_string_equal (const char *a, const char *b)
 Assert that the two given strings are equal. More...
 
void assert_string_not_equal (const char *a, const char *b)
 Assert that the two given strings are not equal. More...
 
void assert_true (scalar expression)
 Assert that the given expression is true. More...
 

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_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_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 non-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()