cmocka  0.3.2
Functions
Assert Macros

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

Functions

void assert_false (scalar expression)
 Assert that the given expression is false. More...
 
void assert_in_range (uintmax_t value, uintmax_t minimum, uintmax_t maximum)
 Assert that the specified value is bigger than the minimum and smaller than the maximum. More...
 
void assert_in_set (uintmax_t value, uintmax_t 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 (uintmax_t value, uintmax_t minimum, uintmax_t maximum)
 Assert that the specified value is smaller than the minimum and bigger than the maximum. More...
 
void assert_not_in_set (uintmax_t value, uintmax_t 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_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

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()
void assert_in_range ( uintmax_t  value,
uintmax_t  minimum,
uintmax_t  maximum 
)

Assert that the specified value is bigger than the minimum and smaller 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.
void assert_in_set ( uintmax_t  value,
uintmax_t  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.
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.
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()
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.
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.
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()
void assert_not_in_range ( uintmax_t  value,
uintmax_t  minimum,
uintmax_t  maximum 
)

Assert that the specified value is smaller than the minimum and bigger 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.
void assert_not_in_set ( uintmax_t  value,
uintmax_t  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.
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()
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.
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.
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()