OpenVPN
test_setup_fail.c
Go to the documentation of this file.
1 #define UNIT_TESTING 1
2 
3 #include <stdarg.h>
4 #include <stddef.h>
5 #include <setjmp.h>
6 #include <cmocka.h>
7 
8 static int setup_fail(void **state) {
9  *state = NULL;
10 
11  /* We need to fail in setup */
12  return -1;
13 }
14 
15 static void int_test_ignored(void **state) {
16  /* should not be called */
17  assert_non_null(*state);
18 }
19 
20 static int setup_ok(void **state) {
21  int *answer;
22 
23  answer = malloc(sizeof(int));
24  if (answer == NULL) {
25  return -1;
26  }
27  *answer = 42;
28 
29  *state = answer;
30 
31  return 0;
32 }
33 
34 /* A test case that does check if an int is equal. */
35 static void int_test_success(void **state) {
36  int *answer = *state;
37 
38  assert_int_equal(*answer, 42);
39 }
40 
41 static int teardown(void **state) {
42  free(*state);
43 
44  return 0;
45 }
46 
47 int main(void) {
48  const struct CMUnitTest tests[] = {
51  };
52 
53  return cmocka_run_group_tests(tests, NULL, NULL);
54 }
#define assert_non_null(c)
Definition: cmocka.h:1102
static void int_test_ignored(void **state)
#define malloc
Definition: cmocka.c:1795
static int setup_fail(void **state)
#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
static int teardown(void **state)
#define cmocka_run_group_tests(group_tests, group_setup, group_teardown)
Definition: cmocka.h:1749
static void int_test_success(void **state)
#define free
Definition: cmocka.c:1850
static int setup_ok(void **state)
int main(void)
#define assert_int_equal(a, b)
Definition: cmocka.h:1174