OpenVPN
test_returns_fail.c
Go to the documentation of this file.
1 #include "config.h"
2 
3 #include <stdarg.h>
4 #include <stddef.h>
5 #include <setjmp.h>
6 #include <cmocka.h>
7 #include <cmocka_private.h>
8 
9 #include <stdlib.h>
10 
11 int mock_function(void);
12 void mock_function_call_times(size_t times, int expectedValue);
13 
14 int mock_function(void)
15 {
16  return (int) mock();
17 }
18 
19 void mock_function_call_times(size_t times, int expectedValue)
20 {
21  size_t i;
22  for (i = 0u; i < times; ++i)
23  {
24  assert_int_equal(expectedValue, mock_function());
25  }
26 }
27 
28 static void test_will_return_fails_for_no_calls(void **state)
29 {
30  (void) state;
31 
33 }
34 
36 {
37  int value;
38  size_t numberOfCalls;
39 
40  (void) state;
41 
42  value = rand();
43  numberOfCalls = (size_t) ((rand()) % 20 + 2);
44 
45  will_return_count(mock_function, value, numberOfCalls);
46  mock_function_call_times(numberOfCalls - 1u, value);
47 }
48 
50 {
51  int value;
52 
53  (void) state;
54 
55  value = rand();
56 
58 }
59 
60 static int teardown(void **state) {
61  free(*state);
62 
63  return 0;
64 }
65 
66 int main(int argc, char **argv) {
67  const struct CMUnitTest alloc_tests[] = {
71  };
72 
73  (void)argc;
74  (void)argv;
75 
76  return cmocka_run_group_tests(alloc_tests, NULL, NULL);
77 }
void mock_function_call_times(size_t times, int expectedValue)
static void test_will_return_count_fails_for_unreturned_items(void **state)
static void test_will_return_fails_for_no_calls(void **state)
static void test_will_return_always_fails_for_no_calls(void **state)
static int teardown(void **state)
#define will_return_count(function, value, count)
Definition: cmocka.h:317
int main(int argc, char **argv)
#define will_return_always(function, value)
Definition: cmocka.h:340
#define will_return(function, value)
Definition: cmocka.h:294
#define mock()
Definition: cmocka.h:210
#define cmocka_run_group_tests(group_tests, group_setup, group_teardown)
Definition: cmocka.h:1749
#define free
Definition: cmocka.c:1850
Definition: argv.h:35
#define cmocka_unit_test_teardown(f, teardown)
Initializes a CMUnitTest structure with a teardown function.
Definition: cmocka.h:1659
#define assert_int_equal(a, b)
Definition: cmocka.h:1174
int mock_function(void)