This source file includes following definitions.
- __wrap_uname
- uname_succeeded_test
- uname_failed_test
- main
1
2
3
4
5
6
7
8
9
10 #include <crm_internal.h>
11 #include "mock_private.h"
12
13 #include <stdarg.h>
14 #include <stddef.h>
15 #include <stdint.h>
16 #include <stdlib.h>
17 #include <string.h>
18 #include <setjmp.h>
19 #include <cmocka.h>
20
21 #include <sys/utsname.h>
22
23 int
24 __wrap_uname(struct utsname *buf)
25 {
26 int retval = mock_type(int);
27
28 if (retval == 0) {
29 strcpy(buf->nodename, mock_ptr_type(char *));
30 }
31
32 return retval;
33 }
34
35 static void
36 uname_succeeded_test(void **state)
37 {
38 char *retval;
39
40 will_return(__wrap_uname, 0);
41 will_return(__wrap_uname, "somename");
42
43 retval = pcmk_hostname();
44 assert_non_null(retval);
45 assert_string_equal("somename", retval);
46
47 free(retval);
48 }
49
50 static void
51 uname_failed_test(void **state)
52 {
53 char *retval;
54
55 will_return(__wrap_uname, -1);
56
57 retval = pcmk_hostname();
58 assert_null(retval);
59 }
60
61 int
62 main(int argc, char **argv)
63 {
64 const struct CMUnitTest tests[] = {
65 cmocka_unit_test(uname_succeeded_test),
66 cmocka_unit_test(uname_failed_test),
67 };
68
69 cmocka_set_message_output(CM_OUTPUT_TAP);
70 return cmocka_run_group_tests(tests, NULL, NULL);
71 }