This source file includes following definitions.
- confchg_fn1
- confchg_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 confchg_fn1(cpg_handle_t handle, const struct cpg_name *group_name,
23 const struct cpg_address *member_list, size_t member_list_entries,
24 const struct cpg_address *left_list, size_t left_list_entries,
25 const struct cpg_address *joined_list, size_t joined_list_entries)
26 {
27 return;
28 }
29
30 static void
31 confchg_fn2(cpg_handle_t handle, const struct cpg_name *group_name,
32 const struct cpg_address *member_list, size_t member_list_entries,
33 const struct cpg_address *left_list, size_t left_list_entries,
34 const struct cpg_address *joined_list, size_t joined_list_entries)
35 {
36 return;
37 }
38
39 static void
40 null_cluster(void **state)
41 {
42 assert_int_equal(pcmk_cpg_set_confchg_fn(NULL, NULL), EINVAL);
43 assert_int_equal(pcmk_cpg_set_confchg_fn(NULL, confchg_fn1), EINVAL);
44 }
45
46 static void
47 null_fn(void **state)
48 {
49 pcmk_cluster_t cluster = {
50 .cpg = {
51 .cpg_confchg_fn = NULL,
52 },
53 };
54
55 assert_int_equal(pcmk_cpg_set_confchg_fn(&cluster, NULL), pcmk_rc_ok);
56 assert_ptr_equal(cluster.cpg.cpg_confchg_fn, NULL);
57
58 cluster.cpg.cpg_confchg_fn = confchg_fn1;
59 assert_int_equal(pcmk_cpg_set_confchg_fn(&cluster, NULL), pcmk_rc_ok);
60 assert_ptr_equal(cluster.cpg.cpg_confchg_fn, NULL);
61 }
62
63 static void
64 previous_fn_null(void **state)
65 {
66 pcmk_cluster_t cluster = {
67 .cpg = {
68 .cpg_confchg_fn = NULL,
69 },
70 };
71
72 assert_int_equal(pcmk_cpg_set_confchg_fn(&cluster, confchg_fn1),
73 pcmk_rc_ok);
74 assert_ptr_equal(cluster.cpg.cpg_confchg_fn, confchg_fn1);
75 }
76
77 static void
78 previous_fn_nonnull(void **state)
79 {
80 pcmk_cluster_t cluster = {
81 .cpg = {
82 .cpg_confchg_fn = confchg_fn2,
83 },
84 };
85
86 assert_int_equal(pcmk_cpg_set_confchg_fn(&cluster, confchg_fn1),
87 pcmk_rc_ok);
88 assert_ptr_equal(cluster.cpg.cpg_confchg_fn, confchg_fn1);
89 }
90
91 PCMK__UNIT_TEST(NULL, NULL,
92 cmocka_unit_test(null_cluster),
93 cmocka_unit_test(null_fn),
94 cmocka_unit_test(previous_fn_null),
95 cmocka_unit_test(previous_fn_nonnull))
96 #else
97 PCMK__UNIT_TEST(NULL, NULL)
98 #endif