OpenVPN
test_returns.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_maybe_for_no_calls(void **state)
29 {
30  (void) state;
31 
33 }
34 
36 {
37  int value;
38 
39  (void) state;
40 
41  value = rand();
43  mock_function_call_times(1u, value);
44 }
45 
47 {
48  int value;
49  size_t numberOfCalls;
50  (void)state;
51 
52  value = rand();
53  numberOfCalls = (size_t) ((rand()) % 20 + 2);
55  mock_function_call_times(numberOfCalls, value);
56 }
57 
58 int main(int argc, char **argv) {
59  const struct CMUnitTest alloc_tests[] = {
63  };
64 
65  (void)argc;
66  (void)argv;
67 
68  return cmocka_run_group_tests(alloc_tests, NULL, NULL);
69 }
#define cmocka_unit_test(f)
Initializes a CMUnitTest structure.
Definition: cmocka.h:1653
static void test_will_return_maybe_for_more_than_one_call(void **state)
Definition: test_returns.c:46
#define will_return_maybe(function, value)
Definition: cmocka.h:368
void mock_function_call_times(size_t times, int expectedValue)
Definition: test_returns.c:19
int mock_function(void)
Definition: test_returns.c:14
int main(int argc, char **argv)
Definition: test_returns.c:58
static void test_will_return_maybe_for_one_mock_call(void **state)
Definition: test_returns.c:35
static void test_will_return_maybe_for_no_calls(void **state)
Definition: test_returns.c:28
#define mock()
Definition: cmocka.h:210
#define cmocka_run_group_tests(group_tests, group_setup, group_teardown)
Definition: cmocka.h:1749
Definition: argv.h:35
#define assert_int_equal(a, b)
Definition: cmocka.h:1174