cmocka  1.1.6
Unit testing library with mock support
Loading...
Searching...
No Matches
Modules | Data Structures | Macros | Typedefs | Enumerations | Functions | Variables
The CMocka API
Collaboration diagram for The CMocka API:

Modules

 Mock Objects
 
 Checking Parameters
 
 Assert Macros
 
 Call Ordering
 
 Running Tests
 
 Dynamic Memory Allocation
 
 Standard Assertions
 

Data Structures

struct  UnitTest
 
struct  GroupTest
 
struct  CMUnitTest
 
struct  SourceLocation
 
struct  CheckParameterEvent
 

Macros

#define __WORDSIZE   32
 
#define LargestIntegralTypePrintfFormat   "%#llx"
 
#define LargestIntegralTypePrintfFormatDecimal   "%llu"
 
#define FloatPrintfFormat   "%f"
 
#define DoublePrintfFormat   "%f"
 
#define cast_to_largest_integral_type(value)    ((LargestIntegralType)(value))
 
#define _UINTPTR_T
 
#define _UINTPTR_T_DEFINED
 
#define cast_to_pointer_integral_type(value)    ((uintptr_t)((size_t)(value)))
 
#define cast_ptr_to_largest_integral_type(value)   cast_to_largest_integral_type(cast_to_pointer_integral_type(value))
 
#define CMOCKA_PRINTF_ATTRIBUTE(a, b)
 
#define CMOCKA_DEPRECATED
 
#define CMOCKA_NORETURN
 
#define WILL_RETURN_ALWAYS   -1
 
#define WILL_RETURN_ONCE   -2
 

Typedefs

typedef uintmax_t LargestIntegralType
 
typedef unsigned int uintptr_t
 
typedef void(* UnitTestFunction) (void **state)
 
typedef int(* CheckParameterValue) (const LargestIntegralType value, const LargestIntegralType check_value_data)
 
typedef enum UnitTestFunctionType UnitTestFunctionType
 
typedef struct UnitTest UnitTest
 
typedef struct GroupTest GroupTest
 
typedef void(* CMUnitTestFunction) (void **state)
 
typedef int(* CMFixtureFunction) (void **state)
 
typedef struct SourceLocation SourceLocation
 
typedef struct CheckParameterEvent CheckParameterEvent
 

Enumerations

enum  UnitTestFunctionType {
  UNIT_TEST_FUNCTION_TYPE_TEST = 0 , UNIT_TEST_FUNCTION_TYPE_SETUP , UNIT_TEST_FUNCTION_TYPE_TEARDOWN , UNIT_TEST_FUNCTION_TYPE_GROUP_SETUP ,
  UNIT_TEST_FUNCTION_TYPE_GROUP_TEARDOWN
}
 
enum  cm_message_output { CM_OUTPUT_STDOUT , CM_OUTPUT_SUBUNIT , CM_OUTPUT_TAP , CM_OUTPUT_XML }
 

Functions

LargestIntegralType _mock (const char *const function, const char *const file, const int line)
 
void _expect_function_call (const char *const function_name, const char *const file, const int line, const int count)
 
void _function_called (const char *const function, const char *const file, const int line)
 
void _expect_check (const char *const function, const char *const parameter, const char *const file, const int line, const CheckParameterValue check_function, const LargestIntegralType check_data, CheckParameterEvent *const event, const int count)
 
void _expect_in_set (const char *const function, const char *const parameter, const char *const file, const int line, const LargestIntegralType values[], const size_t number_of_values, const int count)
 
void _expect_not_in_set (const char *const function, const char *const parameter, const char *const file, const int line, const LargestIntegralType values[], const size_t number_of_values, const int count)
 
void _expect_in_range (const char *const function, const char *const parameter, const char *const file, const int line, const LargestIntegralType minimum, const LargestIntegralType maximum, const int count)
 
void _expect_not_in_range (const char *const function, const char *const parameter, const char *const file, const int line, const LargestIntegralType minimum, const LargestIntegralType maximum, const int count)
 
void _expect_value (const char *const function, const char *const parameter, const char *const file, const int line, const LargestIntegralType value, const int count)
 
void _expect_not_value (const char *const function, const char *const parameter, const char *const file, const int line, const LargestIntegralType value, const int count)
 
void _expect_string (const char *const function, const char *const parameter, const char *const file, const int line, const char *string, const int count)
 
void _expect_not_string (const char *const function, const char *const parameter, const char *const file, const int line, const char *string, const int count)
 
void _expect_memory (const char *const function, const char *const parameter, const char *const file, const int line, const void *const memory, const size_t size, const int count)
 
void _expect_not_memory (const char *const function, const char *const parameter, const char *const file, const int line, const void *const memory, const size_t size, const int count)
 
void _expect_any (const char *const function, const char *const parameter, const char *const file, const int line, const int count)
 
void _check_expected (const char *const function_name, const char *const parameter_name, const char *file, const int line, const LargestIntegralType value)
 
void _will_return (const char *const function_name, const char *const file, const int line, const LargestIntegralType value, const int count)
 
void _assert_true (const LargestIntegralType result, const char *const expression, const char *const file, const int line)
 
void _assert_return_code (const LargestIntegralType result, size_t rlen, const LargestIntegralType error, const char *const expression, const char *const file, const int line)
 
void _assert_float_equal (const float a, const float n, const float epsilon, const char *const file, const int line)
 
void _assert_float_not_equal (const float a, const float n, const float epsilon, const char *const file, const int line)
 
void _assert_double_equal (const double a, const double n, const double epsilon, const char *const file, const int line)
 
void _assert_double_not_equal (const double a, const double n, const double epsilon, const char *const file, const int line)
 
void _assert_int_equal (const LargestIntegralType a, const LargestIntegralType b, const char *const file, const int line)
 
void _assert_int_not_equal (const LargestIntegralType a, const LargestIntegralType b, const char *const file, const int line)
 
void _assert_string_equal (const char *const a, const char *const b, const char *const file, const int line)
 
void _assert_string_not_equal (const char *const a, const char *const b, const char *file, const int line)
 
void _assert_memory_equal (const void *const a, const void *const b, const size_t size, const char *const file, const int line)
 
void _assert_memory_not_equal (const void *const a, const void *const b, const size_t size, const char *const file, const int line)
 
void _assert_in_range (const LargestIntegralType value, const LargestIntegralType minimum, const LargestIntegralType maximum, const char *const file, const int line)
 
void _assert_not_in_range (const LargestIntegralType value, const LargestIntegralType minimum, const LargestIntegralType maximum, const char *const file, const int line)
 
void _assert_in_set (const LargestIntegralType value, const LargestIntegralType values[], const size_t number_of_values, const char *const file, const int line)
 
void _assert_not_in_set (const LargestIntegralType value, const LargestIntegralType values[], const size_t number_of_values, const char *const file, const int line)
 
void * _test_malloc (const size_t size, const char *file, const int line)
 
void * _test_realloc (void *ptr, const size_t size, const char *file, const int line)
 
void * _test_calloc (const size_t number_of_elements, const size_t size, const char *file, const int line)
 
void _test_free (void *const ptr, const char *file, const int line)
 
CMOCKA_NORETURN void _fail (const char *const file, const int line)
 
CMOCKA_NORETURN void _skip (const char *const file, const int line)
 
int _run_test (const char *const function_name, const UnitTestFunction Function, void **const volatile state, const UnitTestFunctionType function_type, const void *const heap_check_point)
 
CMOCKA_DEPRECATED int _run_tests (const UnitTest *const tests, const size_t number_of_tests)
 
CMOCKA_DEPRECATED int _run_group_tests (const UnitTest *const tests, const size_t number_of_tests)
 
int _cmocka_run_group_tests (const char *group_name, const struct CMUnitTest *const tests, const size_t num_tests, CMFixtureFunction group_setup, CMFixtureFunction group_teardown)
 
void print_message (const char *const format,...) CMOCKA_PRINTF_ATTRIBUTE(1
 
void void print_error (const char *const format,...) CMOCKA_PRINTF_ATTRIBUTE(1
 
void void void vprint_message (const char *const format, va_list args) CMOCKA_PRINTF_ATTRIBUTE(1
 
void void void void vprint_error (const char *const format, va_list args) CMOCKA_PRINTF_ATTRIBUTE(1
 
void void void void void cm_print_error (const char *const format,...) CMOCKA_PRINTF_ATTRIBUTE(1
 
void cmocka_set_message_output (enum cm_message_output output)
 Function to set the output format for a test.
 
void cmocka_set_test_filter (const char *pattern)
 Set a pattern to only run the test matching the pattern.
 
void cmocka_set_skip_filter (const char *pattern)
 Set a pattern to skip tests matching the pattern.
 

Variables

int global_expecting_assert
 
jmp_buf global_expect_assert_env
 
const char * global_last_failed_assert
 

Detailed Description

These headers or their equivalents MUST be included prior to including this header file.

#include <stdarg.h>
#include <stddef.h>
#include <stdint.h>
#include <setjmp.h>
#include <stdint.h>

This allows test applications to use custom definitions of C standard library functions and types.

Typedef Documentation

◆ LargestIntegralType

typedef uintmax_t LargestIntegralType

Largest integral type. This type should be large enough to hold any pointer or integer supported by the compiler.

Function Documentation

◆ cmocka_set_message_output()

void cmocka_set_message_output ( enum cm_message_output  output)

Function to set the output format for a test.

The ouput format for the test can either be set globally using this function or overriden with environment variable CMOCKA_MESSAGE_OUTPUT.

The environment variable can be set to either STDOUT, SUBUNIT, TAP or XML.

Parameters
[in]outputThe output format to use for the test.

◆ cmocka_set_skip_filter()

void cmocka_set_skip_filter ( const char *  pattern)

Set a pattern to skip tests matching the pattern.

This allows to filter tests and skip the ones matching the pattern. The pattern can include two wildards. The first is '*', a wildcard that matches zero or more characters, or ‘?’, a wildcard that matches exactly one character.

Parameters
[in]patternThe pattern to match, e.g. "test_wurst*"

◆ cmocka_set_test_filter()

void cmocka_set_test_filter ( const char *  pattern)

Set a pattern to only run the test matching the pattern.

This allows to filter tests and only run the ones matching the pattern. The pattern can include two wildards. The first is '*', a wildcard that matches zero or more characters, or ‘?’, a wildcard that matches exactly one character.

Parameters
[in]patternThe pattern to match, e.g. "test_wurst*"