OpenVPN
test_fixtures.c
Go to the documentation of this file.
1 #include <stdarg.h>
2 #include <stddef.h>
3 #include <setjmp.h>
4 #include <cmocka.h>
5 
6 #include <stdlib.h>
7 
8 static int setup_only(void **state)
9 {
10  *state = malloc(1);
11 
12  return 0;
13 }
14 
15 static int teardown_only(void **state)
16 {
17  free(*state);
18 
19  return 0;
20 }
21 
22 static void malloc_setup_test(void **state)
23 {
24  assert_non_null(*state);
25  free(*state);
26 }
27 
28 static void malloc_teardown_test(void **state)
29 {
30  *state = malloc(1);
31  assert_non_null(*state);
32 }
33 
34 static int prestate_setup(void **state)
35 {
36  int *val = (int *)*state, *a;
37 
38  a = malloc(sizeof(int));
39  *a = *val + 1;
40  *state = a;
41 
42  return 0;
43 }
44 
45 static int prestate_teardown(void **state)
46 {
47  free(*state);
48 
49  return 0;
50 }
51 
52 static void prestate_setup_test(void **state)
53 {
54  int *a = (int *)*state;
55 
56  assert_non_null(a);
57  assert_int_equal(*a, 43);
58 }
59 
60 static void prestate_test(void **state)
61 {
62  int *a = (int *)*state;
63 
64  assert_non_null(a);
65  assert_int_equal(*a, 42);
66 }
67 
68 int main(void) {
69  int prestate = 42;
70  const struct CMUnitTest tests[] = {
79  };
80 
81  return cmocka_run_group_tests(tests, NULL, NULL);
82 }
#define assert_non_null(c)
Definition: cmocka.h:1102
static int prestate_teardown(void **state)
Definition: test_fixtures.c:45
static int prestate_setup(void **state)
Definition: test_fixtures.c:34
static void prestate_setup_test(void **state)
Definition: test_fixtures.c:52
#define cmocka_unit_test_prestate_setup_teardown(f, setup, teardown, state)
Initialize a CMUnitTest structure with given initial state, setup and teardown function.
Definition: cmocka.h:1683
#define malloc
Definition: cmocka.c:1795
static int teardown_only(void **state)
Definition: test_fixtures.c:15
static void malloc_teardown_test(void **state)
Definition: test_fixtures.c:28
static int setup_only(void **state)
Definition: test_fixtures.c:8
static void prestate_test(void **state)
Definition: test_fixtures.c:60
int main(void)
Definition: test_fixtures.c:68
#define cmocka_run_group_tests(group_tests, group_setup, group_teardown)
Definition: cmocka.h:1749
#define free
Definition: cmocka.c:1850
static void malloc_setup_test(void **state)
Definition: test_fixtures.c:22
#define cmocka_unit_test_setup(f, setup)
Initializes a CMUnitTest structure with a setup function.
Definition: cmocka.h:1656
#define cmocka_unit_test_teardown(f, teardown)
Initializes a CMUnitTest structure with a teardown function.
Definition: cmocka.h:1659
#define cmocka_unit_test_prestate(f, state)
Initialize a CMUnitTest structure with given initial state.
Definition: cmocka.h:1674
#define assert_int_equal(a, b)
Definition: cmocka.h:1174