This source file includes following definitions.
- destroy_fn1
- destroy_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 <glib.h>
13
14 #include <crm/cluster.h>
15 #include <crm/common/unittest_internal.h>
16
17 static void
18 destroy_fn1(gpointer arg)
19 {
20 return;
21 }
22
23 static void
24 destroy_fn2(gpointer arg)
25 {
26 return;
27 }
28
29 static void
30 null_cluster(void **state)
31 {
32 assert_int_equal(pcmk_cluster_set_destroy_fn(NULL, NULL), EINVAL);
33 assert_int_equal(pcmk_cluster_set_destroy_fn(NULL, destroy_fn1), EINVAL);
34 }
35
36 static void
37 null_fn(void **state)
38 {
39 pcmk_cluster_t cluster = {
40 .destroy = NULL,
41 };
42
43 assert_int_equal(pcmk_cluster_set_destroy_fn(&cluster, NULL), pcmk_rc_ok);
44 assert_ptr_equal(cluster.destroy, NULL);
45
46 cluster.destroy = destroy_fn1;
47 assert_int_equal(pcmk_cluster_set_destroy_fn(&cluster, NULL), pcmk_rc_ok);
48 assert_ptr_equal(cluster.destroy, NULL);
49 }
50
51 static void
52 previous_fn_null(void **state)
53 {
54 pcmk_cluster_t cluster = {
55 .destroy = NULL,
56 };
57
58 assert_int_equal(pcmk_cluster_set_destroy_fn(&cluster, destroy_fn1),
59 pcmk_rc_ok);
60 assert_ptr_equal(cluster.destroy, destroy_fn1);
61 }
62
63 static void
64 previous_fn_nonnull(void **state)
65 {
66 pcmk_cluster_t cluster = {
67 .destroy = destroy_fn2,
68 };
69
70 assert_int_equal(pcmk_cluster_set_destroy_fn(&cluster, destroy_fn1),
71 pcmk_rc_ok);
72 assert_ptr_equal(cluster.destroy, destroy_fn1);
73 }
74
75 PCMK__UNIT_TEST(NULL, NULL,
76 cmocka_unit_test(null_cluster),
77 cmocka_unit_test(null_fn),
78 cmocka_unit_test(previous_fn_null),
79 cmocka_unit_test(previous_fn_nonnull))