This is the way tests are executed with CMocka.
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(f) { #f, f, UNIT_TEST_FUNCTION_TYPE_TEST } |
| Initializes a UnitTest structure. More...
|
|
#define | unit_test_setup(test, setup) |
| Initializes a UnitTest structure with a setup 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 | unit_test_teardown(test, teardown) |
| Initializes a UnitTest structure with a teardown function. More...
|
|
|
void | fail (void) |
| Forces the test to fail immediately and quit.
|
|
void | fail_msg (const char *msg,...) |
| Forces the test to fail immediately and quit, printing the reason. More...
|
|
int | run_test (#function) |
| Generic method to run a single test. More...
|
|
int | run_tests (const UnitTest tests[]) |
| Run tests specified by an array of UnitTest structures. More...
|
|
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 UnitTest tests[] = {
};
}
#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 |
|
) |
| |
Value:_unit_test_setup(test, setup), \
unit_test(test), \
_unit_test_teardown(test, _unit_test_dummy)
Initializes a UnitTest structure with a setup function.
#define unit_test_setup_teardown |
( |
|
test, |
|
|
|
setup, |
|
|
|
teardown |
|
) |
| |
Value:_unit_test_setup(test, setup), \
unit_test(test), \
_unit_test_teardown(test, 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 |
|
) |
| |
Value:_unit_test_setup(test, _unit_test_dummy), \
unit_test(test), \
_unit_test_teardown(test, teardown)
Initializes a UnitTest structure with a teardown function.
void fail_msg |
( |
const char * |
msg, |
|
|
|
... |
|
) |
| |
Forces the test to fail immediately and quit, printing the reason.
fail_msg(
"This is some error message for test");
or
char *error_msg = "This is some error message for test";
int run_test |
( |
# |
function | ) |
|
Generic method to run a single test.
- Parameters
-
[in] | | function | The function to test. |
- Returns
- 0 on success, 1 if an error occured.
void null_test_success(void **state) {
}
int main(void) {
}
int run_tests |
( |
const UnitTest |
tests[] | ) |
|
Run tests specified by an array of UnitTest structures.
- Parameters
-
[in] | tests[] | The array of unit tests to execute. |
- Returns
- 0 on success, 1 if an error occured.
static void setup(void **state) {
int *answer = malloc(sizeof(int));
*answer = 42;
*state = answer;
}
static void teardown(void **state) {
free(*state);
}
static void null_test_success(void **state) {
(void) state;
}
static void int_test_success(void **state) {
int *answer = *state;
}
int main(void) {
const UnitTest tests[] = {
};
}
- See Also
- unit_test
-
unit_test_setup
-
unit_test_teardown
-
unit_test_setup_teardown