OpenVPN
test.c
Go to the documentation of this file.
1 #include <stdio.h>
2 #include <unistd.h>
3 #include <stdlib.h>
4 #include <stdarg.h>
5 #include <string.h>
6 #include <setjmp.h>
7 #include <cmocka.h>
8 
9 static int
10 setup(void **state)
11 {
12  int *answer = malloc(sizeof(int));
13 
14  *answer = 42;
15  *state = answer;
16 
17  return 0;
18 }
19 
20 static int
21 teardown(void **state)
22 {
23  free(*state);
24 
25  return 0;
26 }
27 
28 static void
29 null_test_success(void **state)
30 {
31  (void) state;
32 }
33 
34 static void
35 int_test_success(void **state)
36 {
37  int *answer = *state;
38  assert_int_equal(*answer, 42);
39 }
40 
41 __attribute__((unused))
42 static void
43 failing_test(void **state)
44 {
45  /* This tests fails to test that make check fails */
46  assert_int_equal(0, 42);
47 }
48 
49 int
50 main(void)
51 {
52  const struct CMUnitTest tests[] = {
55 /* cmocka_unit_test(failing_test), */
56  };
57 
58  return cmocka_run_group_tests_name("success_test", tests, NULL, NULL);
59 }
#define cmocka_unit_test(f)
Initializes a CMUnitTest structure.
Definition: cmocka.h:1653
static int teardown(void **state)
Definition: test.c:21
static void null_test_success(void **state)
Definition: test.c:29
static int setup(void **state)
Definition: test.c:10
#define cmocka_run_group_tests_name(group_name, group_tests, group_setup, group_teardown)
Definition: cmocka.h:1818
int main(void)
Definition: test.c:50
#define malloc
Definition: cmocka.c:1795
__attribute__((unused))
Definition: test.c:41
static void int_test_success(void **state)
Definition: test.c:35
#define cmocka_unit_test_setup_teardown(f, setup, teardown)
Initialize an array of CMUnitTest structures with a setup function for a test and a teardown function...
Definition: cmocka.h:1665
#define free
Definition: cmocka.c:1850
#define assert_int_equal(a, b)
Definition: cmocka.h:1174