cmocka
1.1.6
Unit testing library with mock support
|
Macros | |
#define | unit_test(f) { #f, f, UNIT_TEST_FUNCTION_TYPE_TEST } |
#define | _unit_test_setup(test, setup) { #test "_" #setup, setup, UNIT_TEST_FUNCTION_TYPE_SETUP } |
#define | unit_test_setup(test, setup) |
#define | _unit_test_teardown(test, teardown) { #test "_" #teardown, teardown, UNIT_TEST_FUNCTION_TYPE_TEARDOWN } |
#define | unit_test_teardown(test, teardown) |
#define | group_test_setup(setup) { "group_" #setup, setup, UNIT_TEST_FUNCTION_TYPE_GROUP_SETUP } |
#define | group_test_teardown(teardown) { "group_" #teardown, teardown, UNIT_TEST_FUNCTION_TYPE_GROUP_TEARDOWN } |
#define | unit_test_setup_teardown(test, setup, teardown) |
#define | cmocka_unit_test(f) { #f, f, NULL, NULL, NULL } |
#define | cmocka_unit_test_setup(f, setup) { #f, f, setup, NULL, NULL } |
#define | cmocka_unit_test_teardown(f, teardown) { #f, f, NULL, teardown, NULL } |
#define | cmocka_unit_test_setup_teardown(f, setup, teardown) { #f, f, setup, teardown, NULL } |
#define | cmocka_unit_test_prestate(f, state) { #f, f, NULL, NULL, state } |
#define | cmocka_unit_test_prestate_setup_teardown(f, setup, teardown, state) { #f, f, setup, teardown, state } |
#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])) |
Functions | |
void | fail (void) |
Forces the test to fail immediately and quit. | |
void | skip (void) |
Forces the test to not be executed, but marked as skipped. | |
void | fail_msg (const char *msg,...) |
Forces the test to fail immediately and quit, printing the reason. | |
int | run_test (#function) |
Generic method to run a single test. | |
int | cmocka_run_group_tests (const struct CMUnitTest group_tests[], CMFixtureFunction group_setup, CMFixtureFunction group_teardown) |
Run tests specified by an array of CMUnitTest structures. | |
int | cmocka_run_group_tests_name (const char *group_name, const struct CMUnitTest group_tests[], CMFixtureFunction group_setup, CMFixtureFunction group_teardown) |
Run tests specified by an array of CMUnitTest structures and specify a name. | |
This is the way tests are executed with CMocka.
The following example illustrates this macro's use with the unit_test macro.
#define cmocka_unit_test | ( | f | ) | { #f, f, NULL, NULL, NULL } |
Initializes a CMUnitTest structure.
#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.
#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.
#define cmocka_unit_test_setup | ( | f, | |
setup | |||
) | { #f, f, setup, NULL, NULL } |
Initializes a CMUnitTest structure with a setup function.
#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.
#define cmocka_unit_test_teardown | ( | f, | |
teardown | |||
) | { #f, f, NULL, teardown, NULL } |
Initializes a CMUnitTest structure with a teardown function.
#define group_test_setup | ( | setup | ) | { "group_" #setup, setup, UNIT_TEST_FUNCTION_TYPE_GROUP_SETUP } |
Initializes a UnitTest structure for a group setup function.
#define group_test_teardown | ( | teardown | ) | { "group_" #teardown, teardown, UNIT_TEST_FUNCTION_TYPE_GROUP_TEARDOWN } |
Initializes a UnitTest structure for a group teardown function.
#define unit_test | ( | f | ) | { #f, f, UNIT_TEST_FUNCTION_TYPE_TEST } |
Initializes a UnitTest structure.
#define unit_test_setup | ( | test, | |
setup | |||
) |
Initializes a UnitTest structure with a setup function.
#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. Either setup or teardown can be NULL.
#define unit_test_teardown | ( | test, | |
teardown | |||
) |
Initializes a UnitTest structure with a teardown function.
int cmocka_run_group_tests | ( | const struct CMUnitTest | group_tests[], |
CMFixtureFunction | group_setup, | ||
CMFixtureFunction | group_teardown | ||
) |
Run tests specified by an array of CMUnitTest structures.
[in] | group_tests[] | The array of unit tests to execute. |
[in] | group_setup | The setup function which should be called before all unit tests are executed. |
[in] | group_teardown | The teardown function to be called after all tests have finished. |
int cmocka_run_group_tests_name | ( | const char * | group_name, |
const struct CMUnitTest | group_tests[], | ||
CMFixtureFunction | group_setup, | ||
CMFixtureFunction | group_teardown | ||
) |
Run tests specified by an array of CMUnitTest structures and specify a name.
[in] | group_name | The name of the group test. |
[in] | group_tests[] | The array of unit tests to execute. |
[in] | group_setup | The setup function which should be called before all unit tests are executed. |
[in] | group_teardown | The teardown function to be called after all tests have finished. |
void fail_msg | ( | const char * | msg, |
... | |||
) |
Forces the test to fail immediately and quit, printing the reason.
or
int run_test | ( | # | function | ) |
Generic method to run a single test.
[in] | function | The function to test. |