This source file includes following definitions.
- uname_succeeded_test
- uname_failed_test
1
2
3
4
5
6
7
8
9
10 #include <crm_internal.h>
11
12 #include <crm/common/unittest_internal.h>
13
14 #include "mock_private.h"
15
16 #include <sys/utsname.h>
17
18 static void
19 uname_succeeded_test(void **state)
20 {
21 char *retval;
22
23
24 pcmk__mock_uname = true;
25
26 expect_any(__wrap_uname, buf);
27 will_return(__wrap_uname, 0);
28 will_return(__wrap_uname, "somename");
29
30 retval = pcmk_hostname();
31 assert_non_null(retval);
32 assert_string_equal("somename", retval);
33
34 free(retval);
35
36 pcmk__mock_uname = false;
37 }
38
39 static void
40 uname_failed_test(void **state)
41 {
42
43 pcmk__mock_uname = true;
44
45 expect_any(__wrap_uname, buf);
46 will_return(__wrap_uname, -1);
47 will_return(__wrap_uname, NULL);
48
49 assert_null(pcmk_hostname());
50
51 pcmk__mock_uname = false;
52 }
53
54 PCMK__UNIT_TEST(NULL, NULL,
55 cmocka_unit_test(uname_succeeded_test),
56 cmocka_unit_test(uname_failed_test))