OpenVPN
Modules | Data Structures | Macros | Typedefs | Enumerations | Functions | Variables
The CMocka API

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

Collaboration diagram for The CMocka API:

Modules

 Mock Objects
 Mock objects mock objects are simulated objects that mimic the behavior of real objects.
 
 Checking Parameters
 Functionality to store expected values for mock function parameters.
 
 Assert Macros
 This is a set of useful assert macros like the standard C libary's assert(3) macro.
 
 Call Ordering
 It is often beneficial to make sure that functions are called in an order.
 
 Running Tests
 This is the way tests are executed with CMocka.
 
 Dynamic Memory Allocation
 Memory leaks, buffer overflows and underflows can be checked using cmocka.
 
 Standard Assertions
 How to handle assert(3) of the standard C library.
 

Data Structures

struct  UnitTest
 
struct  GroupTest
 
struct  CMUnitTest
 
struct  SourceLocation
 
struct  CheckParameterEvent
 

Macros

#define __WORDSIZE   32
 
#define LargestIntegralType   unsigned long long int
 
#define LargestIntegralTypePrintfFormat   "0x%I64x"
 
#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
 

Typedefs

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_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)
 
void _fail (const char *const file, const int line)
 
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 cmocka_set_message_output (enum cm_message_output output)
 Function to set the output format for a test. More...
 

Variables

int global_expecting_assert
 
jmp_buf global_expect_assert_env
 
const char * global_last_failed_assert
 

Detailed Description

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

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

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

Macro Definition Documentation

◆ __WORDSIZE

#define __WORDSIZE   32

Definition at line 62 of file cmocka.h.

◆ _UINTPTR_T

#define _UINTPTR_T

Definition at line 124 of file cmocka.h.

◆ _UINTPTR_T_DEFINED

#define _UINTPTR_T_DEFINED

Definition at line 125 of file cmocka.h.

◆ cast_ptr_to_largest_integral_type

#define cast_ptr_to_largest_integral_type (   value)    cast_to_largest_integral_type(cast_to_pointer_integral_type(value))

◆ cast_to_largest_integral_type

#define cast_to_largest_integral_type (   value)    ((LargestIntegralType)(value))

Definition at line 96 of file cmocka.h.

◆ cast_to_pointer_integral_type

#define cast_to_pointer_integral_type (   value)    ((uintptr_t)((size_t)(value)))

Definition at line 129 of file cmocka.h.

◆ CMOCKA_DEPRECATED

#define CMOCKA_DEPRECATED

Definition at line 149 of file cmocka.h.

◆ CMOCKA_PRINTF_ATTRIBUTE

#define CMOCKA_PRINTF_ATTRIBUTE (   a,
 
)

Definition at line 141 of file cmocka.h.

Referenced by libc_realloc().

◆ LargestIntegralType

#define LargestIntegralType   unsigned long long int

Definition at line 77 of file cmocka.h.

◆ LargestIntegralTypePrintfFormat

#define LargestIntegralTypePrintfFormat   "0x%I64x"

Definition at line 85 of file cmocka.h.

Referenced by values_equal_display_error(), and values_not_equal_display_error().

Typedef Documentation

◆ CheckParameterEvent

◆ CheckParameterValue

typedef int(* CheckParameterValue) (const LargestIntegralType value, const LargestIntegralType check_value_data)

Definition at line 2035 of file cmocka.h.

◆ CMFixtureFunction

typedef int(* CMFixtureFunction) (void **state)

Definition at line 2069 of file cmocka.h.

◆ CMUnitTestFunction

typedef void(* CMUnitTestFunction) (void **state)

Definition at line 2066 of file cmocka.h.

◆ GroupTest

typedef struct GroupTest GroupTest

◆ SourceLocation

◆ uintptr_t

typedef unsigned int uintptr_t

Definition at line 103 of file cmocka.h.

◆ UnitTest

typedef struct UnitTest UnitTest

◆ UnitTestFunction

typedef void(* UnitTestFunction) (void **state)

Definition at line 2032 of file cmocka.h.

◆ UnitTestFunctionType

Enumeration Type Documentation

◆ cm_message_output

Enumerator
CM_OUTPUT_STDOUT 
CM_OUTPUT_SUBUNIT 
CM_OUTPUT_TAP 
CM_OUTPUT_XML 

Definition at line 2246 of file cmocka.h.

◆ UnitTestFunctionType

Enumerator
UNIT_TEST_FUNCTION_TYPE_TEST 
UNIT_TEST_FUNCTION_TYPE_SETUP 
UNIT_TEST_FUNCTION_TYPE_TEARDOWN 
UNIT_TEST_FUNCTION_TYPE_GROUP_SETUP 
UNIT_TEST_FUNCTION_TYPE_GROUP_TEARDOWN 

Definition at line 2039 of file cmocka.h.

Function Documentation

◆ _assert_in_range()

void _assert_in_range ( const LargestIntegralType  value,
const LargestIntegralType  minimum,
const LargestIntegralType  maximum,
const char *const  file,
const int  line 
)

Definition at line 60 of file coverity_assert_model.c.

References _fail(), and integer_in_range_display_error().

◆ _assert_in_set()

void _assert_in_set ( const LargestIntegralType  value,
const LargestIntegralType  values[],
const size_t  number_of_values,
const char *const  file,
const int  line 
)

◆ _assert_int_equal()

void _assert_int_equal ( const LargestIntegralType  a,
const LargestIntegralType  b,
const char *const  file,
const int  line 
)

Definition at line 10 of file coverity_assert_model.c.

References _fail(), and values_equal_display_error().

◆ _assert_int_not_equal()

void _assert_int_not_equal ( const LargestIntegralType  a,
const LargestIntegralType  b,
const char *const  file,
const int  line 
)

Definition at line 17 of file coverity_assert_model.c.

References _fail(), and values_not_equal_display_error().

◆ _assert_memory_equal()

void _assert_memory_equal ( const void *const  a,
const void *const  b,
const size_t  size,
const char *const  file,
const int  line 
)

Definition at line 46 of file coverity_assert_model.c.

References _fail(), and memory_equal_display_error().

◆ _assert_memory_not_equal()

void _assert_memory_not_equal ( const void *const  a,
const void *const  b,
const size_t  size,
const char *const  file,
const int  line 
)

Definition at line 53 of file coverity_assert_model.c.

References _fail(), and memory_not_equal_display_error().

◆ _assert_not_in_range()

void _assert_not_in_range ( const LargestIntegralType  value,
const LargestIntegralType  minimum,
const LargestIntegralType  maximum,
const char *const  file,
const int  line 
)

Definition at line 67 of file coverity_assert_model.c.

References _fail(), and integer_not_in_range_display_error().

◆ _assert_not_in_set()

void _assert_not_in_set ( const LargestIntegralType  value,
const LargestIntegralType  values[],
const size_t  number_of_values,
const char *const  file,
const int  line 
)

◆ _assert_return_code()

void _assert_return_code ( const LargestIntegralType  result,
size_t  rlen,
const LargestIntegralType  error,
const char *const  expression,
const char *const  file,
const int  line 
)

Definition at line 24 of file coverity_assert_model.c.

References _fail(), cm_print_error(), LargestIntegralType, and PRIu64.

◆ _assert_string_equal()

void _assert_string_equal ( const char *const  a,
const char *const  b,
const char *const  file,
const int  line 
)

Definition at line 34 of file coverity_assert_model.c.

References _fail(), and string_equal_display_error().

◆ _assert_string_not_equal()

void _assert_string_not_equal ( const char *const  a,
const char *const  b,
const char *  file,
const int  line 
)

Definition at line 40 of file coverity_assert_model.c.

References _fail(), and string_not_equal_display_error().

◆ _assert_true()

void _assert_true ( const LargestIntegralType  result,
const char *const  expression,
const char *const  file,
const int  line 
)

Definition at line 3 of file coverity_assert_model.c.

References _fail(), and cm_print_error().

Referenced by _test_free().

◆ _check_expected()

void _check_expected ( const char *const  function_name,
const char *const  parameter_name,
const char *  file,
const int  line,
const LargestIntegralType  value 
)

◆ _cmocka_run_group_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 
)

◆ _expect_any()

void _expect_any ( const char *const  function,
const char *const  parameter,
const char *const  file,
const int  line,
const int  count 
)

Definition at line 1467 of file cmocka.c.

References _expect_check(), and check_any().

◆ _expect_check()

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 
)

◆ _expect_function_call()

void _expect_function_call ( const char *const  function_name,
const char *const  file,
const int  line,
const int  count 
)

◆ _expect_in_range()

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 
)

Definition at line 1290 of file cmocka.c.

References check_in_range(), and expect_range().

◆ _expect_in_set()

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 
)

Definition at line 1227 of file cmocka.c.

References check_in_set(), and expect_set().

◆ _expect_memory()

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 
)

Definition at line 1424 of file cmocka.c.

References check_memory(), and expect_memory_setup().

◆ _expect_not_in_range()

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 
)

Definition at line 1301 of file cmocka.c.

References check_not_in_range(), and expect_range().

◆ _expect_not_in_set()

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 
)

Definition at line 1238 of file cmocka.c.

References check_not_in_set(), and expect_set().

◆ _expect_not_memory()

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 
)

Definition at line 1448 of file cmocka.c.

References check_not_memory(), and expect_memory_setup().

◆ _expect_not_string()

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 
)

◆ _expect_not_value()

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 
)

Definition at line 1338 of file cmocka.c.

References _expect_check(), and check_not_value().

◆ _expect_string()

void _expect_string ( const char *const  function,
const char *const  parameter,
const char *const  file,
const int  line,
const char *  string,
const int  count 
)

◆ _expect_value()

void _expect_value ( const char *const  function,
const char *const  parameter,
const char *const  file,
const int  line,
const LargestIntegralType  value,
const int  count 
)

Definition at line 1320 of file cmocka.c.

References _expect_check(), and check_value().

◆ _fail()

void _fail ( const char *const  file,
const int  line 
)

◆ _function_called()

void _function_called ( const char *const  function,
const char *const  file,
const int  line 
)

◆ _mock()

LargestIntegralType _mock ( const char *const  function,
const char *const  file,
const int  line 
)

◆ _run_group_tests()

CMOCKA_DEPRECATED int _run_group_tests ( const UnitTest *const  tests,
const size_t  number_of_tests 
)

◆ _run_test()

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 
)

◆ _run_tests()

CMOCKA_DEPRECATED int _run_tests ( const UnitTest *const  tests,
const size_t  number_of_tests 
)

◆ _skip()

void _skip ( const char *const  file,
const int  line 
)

Definition at line 392 of file cmocka.c.

References cm_print_error(), exit_test(), and SOURCE_LOCATION_FORMAT.

◆ _test_calloc()

void* _test_calloc ( const size_t  number_of_elements,
const size_t  size,
const char *  file,
const int  line 
)

Definition at line 1798 of file cmocka.c.

References _test_malloc().

◆ _test_free()

void _test_free ( void *const  ptr,
const char *  file,
const int  line 
)

◆ _test_malloc()

void* _test_malloc ( const size_t  size,
const char *  file,
const int  line 
)

◆ _test_realloc()

void* _test_realloc ( void *  ptr,
const size_t  size,
const char *  file,
const int  line 
)

Definition at line 1853 of file cmocka.c.

References _test_free(), _test_malloc(), MALLOC_GUARD_SIZE, and MallocBlockInfo::size.

◆ _will_return()

void _will_return ( const char *const  function_name,
const char *const  file,
const int  line,
const LargestIntegralType  value,
const int  count 
)

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

Definition at line 2431 of file cmocka.c.

References global_msg_output.

◆ print_error()

void void print_error ( const char *const  format,
  ... 
)

◆ print_message()

void print_message ( const char *const  format,
  ... 
)

◆ vprint_error()

void void void void vprint_error ( const char *const  format,
va_list  args 
)

◆ vprint_message()

void void void vprint_message ( const char *const  format,
va_list  args 
)

Variable Documentation

◆ global_expect_assert_env

jmp_buf global_expect_assert_env

Definition at line 277 of file cmocka.c.

◆ global_expecting_assert

int global_expecting_assert

Definition at line 278 of file cmocka.c.

◆ global_last_failed_assert

const char* global_last_failed_assert

Definition at line 279 of file cmocka.c.

Referenced by mock_assert().