OpenVPN
test_group_fixtures.c
Go to the documentation of this file.
1 /* Use the unit test allocators */
2 #define UNIT_TESTING 1
3 
4 #include <stdarg.h>
5 #include <stddef.h>
6 #include <setjmp.h>
7 #include <cmocka.h>
8 
9 static int group_setup(void **state)
10 {
11  int *answer = malloc(sizeof(int));
12  assert_non_null(answer);
13  *answer = 42;
14 
15  *state = answer;
16  return 0;
17 }
18 
19 static int group_teardown(void **state)
20 {
21  int *answer = (int *)*state;
22 
23  free(answer);
24  return 0;
25 }
26 
27 static void test_value_equal(void **state)
28 {
29  int a = *((int *)*state);
30 
31  assert_int_equal(a, 42);
32 }
33 
34 static void test_value_range(void **state)
35 {
36  int a = *((int *)*state);
37 
38  assert_in_range(a, 0, 100);
39 }
40 
41 int main(void) {
42  int prestate = 1337;
43  const struct CMUnitTest tests[] = {
47  };
48 
50 }
#define assert_non_null(c)
Definition: cmocka.h:1102
#define cmocka_unit_test(f)
Initializes a CMUnitTest structure.
Definition: cmocka.h:1653
static void test_value_equal(void **state)
static int group_teardown(void **state)
#define malloc
Definition: cmocka.c:1795
static void test_value_range(void **state)
int main(void)
#define cmocka_run_group_tests(group_tests, group_setup, group_teardown)
Definition: cmocka.h:1749
#define free
Definition: cmocka.c:1850
#define assert_in_range(value, minimum, maximum)
Definition: cmocka.h:1297
static int group_setup(void **state)
#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