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 <stdint.h>
8 #include <cmocka.h>
9 
10 static int
11 setup(void **state)
12 {
13  int *answer = malloc(sizeof(int));
14 
15  *answer = 42;
16  *state = answer;
17 
18  return 0;
19 }
20 
21 static int
22 teardown(void **state)
23 {
24  free(*state);
25 
26  return 0;
27 }
28 
29 static void
30 null_test_success(void **state)
31 {
32  (void) state;
33 }
34 
35 static void
36 int_test_success(void **state)
37 {
38  int *answer = *state;
39  assert_int_equal(*answer, 42);
40 }
41 
42 __attribute__((unused))
43 static void
44 failing_test(void **state)
45 {
46  /* This tests fails to test that make check fails */
47  assert_int_equal(0, 42);
48 }
49 
50 int
51 main(void)
52 {
53  const struct CMUnitTest tests[] = {
54  cmocka_unit_test(null_test_success),
55  cmocka_unit_test_setup_teardown(int_test_success, setup, teardown),
56 /* cmocka_unit_test(failing_test), */
57  };
58 
59  return cmocka_run_group_tests_name("success_test", tests, NULL, NULL);
60 }
teardown
static int teardown(void **state)
Definition: test.c:22
main
int main(void)
Definition: test.c:51
int_test_success
static void int_test_success(void **state)
Definition: test.c:36
setup
static int setup(void **state)
Definition: test.c:11
__attribute__
__attribute__((unused))
Definition: test.c:42
null_test_success
static void null_test_success(void **state)
Definition: test.c:30