OpenVPN
Macros | Functions
Running Tests

This is the way tests are executed with CMocka. More...

Collaboration diagram for Running Tests:

Macros

#define fail()   _fail(__FILE__, __LINE__)
 
#define skip()   _skip(__FILE__, __LINE__)
 
#define fail_msg(msg, ...)
 
#define run_test(f)   _run_test(#f, f, NULL, UNIT_TEST_FUNCTION_TYPE_TEST, NULL)
 
#define unit_test(f)   { #f, f, UNIT_TEST_FUNCTION_TYPE_TEST }
 Initializes a UnitTest structure. More...
 
#define _unit_test_setup(test, setup)   { #test "_" #setup, setup, UNIT_TEST_FUNCTION_TYPE_SETUP }
 
#define unit_test_setup(test, setup)
 Initializes a UnitTest structure with a setup function. More...
 
#define _unit_test_teardown(test, teardown)   { #test "_" #teardown, teardown, UNIT_TEST_FUNCTION_TYPE_TEARDOWN }
 
#define unit_test_teardown(test, teardown)
 Initializes a UnitTest structure with a teardown function. More...
 
#define group_test_setup(setup)   { "group_" #setup, setup, UNIT_TEST_FUNCTION_TYPE_GROUP_SETUP }
 Initializes a UnitTest structure for a group setup function. More...
 
#define group_test_teardown(teardown)   { "group_" #teardown, teardown, UNIT_TEST_FUNCTION_TYPE_GROUP_TEARDOWN }
 Initializes a UnitTest structure for a group teardown function. More...
 
#define unit_test_setup_teardown(test, setup, teardown)
 Initialize an array of UnitTest structures with a setup function for a test and a teardown function. More...
 
#define cmocka_unit_test(f)   { #f, f, NULL, NULL, NULL }
 Initializes a CMUnitTest structure. More...
 
#define cmocka_unit_test_setup(f, setup)   { #f, f, setup, NULL, NULL }
 Initializes a CMUnitTest structure with a setup function. More...
 
#define cmocka_unit_test_teardown(f, teardown)   { #f, f, NULL, teardown, NULL }
 Initializes a CMUnitTest structure with a teardown function. More...
 
#define cmocka_unit_test_setup_teardown(f, setup, teardown)   { #f, f, setup, teardown, NULL }
 Initialize an array of CMUnitTest structures with a setup function for a test and a teardown function. More...
 
#define cmocka_unit_test_prestate(f, state)   { #f, f, NULL, NULL, state }
 Initialize a CMUnitTest structure with given initial state. More...
 
#define cmocka_unit_test_prestate_setup_teardown(f, setup, teardown, state)   { #f, f, setup, teardown, state }
 Initialize a CMUnitTest structure with given initial state, setup and teardown function. More...
 
#define run_tests(tests)   _run_tests(tests, sizeof(tests) / sizeof(tests)[0])
 
#define run_group_tests(tests)   _run_group_tests(tests, sizeof(tests) / sizeof(tests)[0])
 
#define cmocka_run_group_tests(group_tests, group_setup, group_teardown)   _cmocka_run_group_tests(#group_tests, group_tests, sizeof(group_tests) / sizeof(group_tests)[0], group_setup, group_teardown)
 
#define cmocka_run_group_tests_name(group_name, group_tests, group_setup, group_teardown)   _cmocka_run_group_tests(group_name, group_tests, sizeof(group_tests) / sizeof(group_tests)[0], group_setup, group_teardown)
 

Functions

static void _unit_test_dummy (void **state)
 

Detailed Description

This is the way tests are executed with CMocka.

The following example illustrates this macro's use with the unit_test macro.

void Test0(void **state);
void Test1(void **state);
int main(void)
{
const struct CMUnitTest tests[] = {
};
return cmocka_run_group_tests(tests, NULL, NULL);
}

Macro Definition Documentation

◆ _unit_test_setup

#define _unit_test_setup (   test,
  setup 
)    { #test "_" #setup, setup, UNIT_TEST_FUNCTION_TYPE_SETUP }

Definition at line 1601 of file cmocka.h.

◆ _unit_test_teardown

#define _unit_test_teardown (   test,
  teardown 
)    { #test "_" #teardown, teardown, UNIT_TEST_FUNCTION_TYPE_TEARDOWN }

Definition at line 1613 of file cmocka.h.

◆ cmocka_run_group_tests

#define cmocka_run_group_tests (   group_tests,
  group_setup,
  group_teardown 
)    _cmocka_run_group_tests(#group_tests, group_tests, sizeof(group_tests) / sizeof(group_tests)[0], group_setup, group_teardown)

Definition at line 1749 of file cmocka.h.

Referenced by main().

◆ cmocka_run_group_tests_name

#define cmocka_run_group_tests_name (   group_name,
  group_tests,
  group_setup,
  group_teardown 
)    _cmocka_run_group_tests(group_name, group_tests, sizeof(group_tests) / sizeof(group_tests)[0], group_setup, group_teardown)

Definition at line 1818 of file cmocka.h.

Referenced by main().

◆ cmocka_unit_test

#define cmocka_unit_test (   f)    { #f, f, NULL, NULL, NULL }

Initializes a CMUnitTest structure.

Definition at line 1653 of file cmocka.h.

Referenced by main().

◆ cmocka_unit_test_prestate

#define cmocka_unit_test_prestate (   f,
  state 
)    { #f, f, NULL, NULL, state }

Initialize a CMUnitTest structure with given initial state.

It will be passed to test function as an argument later. It can be used when test state does not need special initialization or was initialized already.

Note
If the group setup function initialized the state already, it won't be overridden by the initial state defined here.

Definition at line 1674 of file cmocka.h.

Referenced by main().

◆ cmocka_unit_test_prestate_setup_teardown

#define cmocka_unit_test_prestate_setup_teardown (   f,
  setup,
  teardown,
  state 
)    { #f, f, setup, teardown, state }

Initialize a CMUnitTest structure with given initial state, setup and teardown function.

Any of these values can be NULL. Initial state is passed later to setup function, or directly to test if none was given.

Note
If the group setup function initialized the state already, it won't be overridden by the initial state defined here.

Definition at line 1683 of file cmocka.h.

Referenced by main().

◆ cmocka_unit_test_setup

#define cmocka_unit_test_setup (   f,
  setup 
)    { #f, f, setup, NULL, NULL }

Initializes a CMUnitTest structure with a setup function.

Definition at line 1656 of file cmocka.h.

Referenced by main().

◆ cmocka_unit_test_setup_teardown

#define cmocka_unit_test_setup_teardown (   f,
  setup,
  teardown 
)    { #f, f, setup, teardown, NULL }

Initialize an array of CMUnitTest structures with a setup function for a test and a teardown function.

Either setup or teardown can be NULL.

Definition at line 1665 of file cmocka.h.

Referenced by main().

◆ cmocka_unit_test_teardown

#define cmocka_unit_test_teardown (   f,
  teardown 
)    { #f, f, NULL, teardown, NULL }

Initializes a CMUnitTest structure with a teardown function.

Definition at line 1659 of file cmocka.h.

Referenced by main().

◆ fail

#define fail ( )    _fail(__FILE__, __LINE__)

Definition at line 1531 of file cmocka.h.

Referenced by init_route(), init_route_ipv6(), and send_push_reply().

◆ fail_msg

#define fail_msg (   msg,
  ... 
)
Value:
do { \
print_error("ERROR: " msg "\n", ##__VA_ARGS__); \
fail(); \
} while (0)
#define msg
Definition: error.h:173

Definition at line 1560 of file cmocka.h.

◆ group_test_setup

#define group_test_setup (   setup)    { "group_" #setup, setup, UNIT_TEST_FUNCTION_TYPE_GROUP_SETUP }

Initializes a UnitTest structure for a group setup function.

Deprecated:
This function was deprecated in favor of cmocka_run_group_tests

Definition at line 1629 of file cmocka.h.

◆ group_test_teardown

#define group_test_teardown (   teardown)    { "group_" #teardown, teardown, UNIT_TEST_FUNCTION_TYPE_GROUP_TEARDOWN }

Initializes a UnitTest structure for a group teardown function.

Deprecated:
This function was deprecated in favor of cmocka_run_group_tests

Definition at line 1636 of file cmocka.h.

◆ run_group_tests

#define run_group_tests (   tests)    _run_group_tests(tests, sizeof(tests) / sizeof(tests)[0])

Definition at line 1686 of file cmocka.h.

◆ run_test

#define run_test (   f)    _run_test(#f, f, NULL, UNIT_TEST_FUNCTION_TYPE_TEST, NULL)

Definition at line 1588 of file cmocka.h.

Referenced by _run_group_tests().

◆ run_tests

#define run_tests (   tests)    _run_tests(tests, sizeof(tests) / sizeof(tests)[0])

Definition at line 1685 of file cmocka.h.

Referenced by main().

◆ skip

#define skip ( )    _skip(__FILE__, __LINE__)

◆ unit_test

#define unit_test (   f)    { #f, f, UNIT_TEST_FUNCTION_TYPE_TEST }

Initializes a UnitTest structure.

Deprecated:
This function was deprecated in favor of cmocka_unit_test

Definition at line 1599 of file cmocka.h.

Referenced by main().

◆ unit_test_setup

#define unit_test_setup (   test,
  setup 
)
Value:
unit_test(test), \
_unit_test_teardown(test, _unit_test_dummy)
static int setup(void **state)
Definition: test.c:10
static void _unit_test_dummy(void **state)
Definition: cmocka.h:1591
#define _unit_test_setup(test, setup)
Definition: cmocka.h:1601

Initializes a UnitTest structure with a setup function.

Deprecated:
This function was deprecated in favor of cmocka_unit_test_setup

Definition at line 1608 of file cmocka.h.

◆ unit_test_setup_teardown

#define unit_test_setup_teardown (   test,
  setup,
  teardown 
)
Value:
unit_test(test), \
_unit_test_teardown(test, teardown)
static int teardown(void **state)
Definition: test.c:20
static int setup(void **state)
Definition: test.c:10
#define _unit_test_setup(test, setup)
Definition: cmocka.h:1601

Initialize an array of UnitTest structures with a setup function for a test and a teardown function.

Either setup or teardown can be NULL.

Deprecated:
This function was deprecated in favor of cmocka_unit_test_setup_teardown

Definition at line 1646 of file cmocka.h.

◆ unit_test_teardown

#define unit_test_teardown (   test,
  teardown 
)
Value:
unit_test(test), \
_unit_test_teardown(test, teardown)
static int teardown(void **state)
Definition: test.c:20
static void _unit_test_dummy(void **state)
Definition: cmocka.h:1591
#define _unit_test_setup(test, setup)
Definition: cmocka.h:1601

Initializes a UnitTest structure with a teardown function.

Deprecated:
This function was deprecated in favor of cmocka_unit_test_teardown

Definition at line 1620 of file cmocka.h.

Function Documentation

◆ _unit_test_dummy()

static void _unit_test_dummy ( void **  state)
inlinestatic

Definition at line 1591 of file cmocka.h.