This source file includes following definitions.
- deliver_fn1
- deliver_fn2
- null_cluster
- null_fn
- previous_fn_null
- previous_fn_nonnull
1
2
3
4
5
6
7
8
9
10 #include <crm_internal.h>
11
12 #include <stdint.h>
13 #include <sys/types.h>
14
15 #include <crm/cluster.h>
16 #include <crm/common/unittest_internal.h>
17
18 #if SUPPORT_COROSYNC
19 #include <corosync/cpg.h>
20
21 static void
22 deliver_fn1(cpg_handle_t handle, const struct cpg_name *group_name,
23 uint32_t nodeid, uint32_t pid, void *msg, size_t msg_len)
24 {
25 return;
26 }
27
28 static void
29 deliver_fn2(cpg_handle_t handle, const struct cpg_name *group_name,
30 uint32_t nodeid, uint32_t pid, void *msg, size_t msg_len)
31 {
32 return;
33 }
34
35 static void
36 null_cluster(void **state)
37 {
38 assert_int_equal(pcmk_cpg_set_deliver_fn(NULL, NULL), EINVAL);
39 assert_int_equal(pcmk_cpg_set_deliver_fn(NULL, deliver_fn1), EINVAL);
40 }
41
42 static void
43 null_fn(void **state)
44 {
45 pcmk_cluster_t cluster = {
46 .cpg = {
47 .cpg_deliver_fn = NULL,
48 },
49 };
50
51 assert_int_equal(pcmk_cpg_set_deliver_fn(&cluster, NULL), pcmk_rc_ok);
52 assert_ptr_equal(cluster.cpg.cpg_deliver_fn, NULL);
53
54 cluster.cpg.cpg_deliver_fn = deliver_fn1;
55 assert_int_equal(pcmk_cpg_set_deliver_fn(&cluster, NULL), pcmk_rc_ok);
56 assert_ptr_equal(cluster.cpg.cpg_deliver_fn, NULL);
57 }
58
59 static void
60 previous_fn_null(void **state)
61 {
62 pcmk_cluster_t cluster = {
63 .cpg = {
64 .cpg_deliver_fn = NULL,
65 },
66 };
67
68 assert_int_equal(pcmk_cpg_set_deliver_fn(&cluster, deliver_fn1),
69 pcmk_rc_ok);
70 assert_ptr_equal(cluster.cpg.cpg_deliver_fn, deliver_fn1);
71 }
72
73 static void
74 previous_fn_nonnull(void **state)
75 {
76 pcmk_cluster_t cluster = {
77 .cpg = {
78 .cpg_deliver_fn = deliver_fn2,
79 },
80 };
81
82 assert_int_equal(pcmk_cpg_set_deliver_fn(&cluster, deliver_fn1),
83 pcmk_rc_ok);
84 assert_ptr_equal(cluster.cpg.cpg_deliver_fn, deliver_fn1);
85 }
86
87 PCMK__UNIT_TEST(NULL, NULL,
88 cmocka_unit_test(null_cluster),
89 cmocka_unit_test(null_fn),
90 cmocka_unit_test(previous_fn_null),
91 cmocka_unit_test(previous_fn_nonnull))
92 #else
93 PCMK__UNIT_TEST(NULL, NULL)
94 #endif