pacemaker  2.1.8-3980678f03
Scalable High-Availability cluster resource manager
pcmk_cluster_set_destroy_fn_test.c
Go to the documentation of this file.
1 /*
2  * Copyright 2024 the Pacemaker project contributors
3  *
4  * The version control history for this file may have further details.
5  *
6  * This source code is licensed under the GNU General Public License version 2
7  * or later (GPLv2+) WITHOUT ANY WARRANTY.
8  */
9 
10 #include <crm_internal.h>
11 
12 #include <glib.h> // gpointer
13 
14 #include <crm/cluster.h> // pcmk_cluster_t, etc.
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))
void(* destroy)(gpointer)
Definition: cluster.h:146
#define PCMK__UNIT_TEST(group_setup, group_teardown,...)
int pcmk_cluster_set_destroy_fn(pcmk_cluster_t *cluster, void(*fn)(gpointer))
Set the destroy function for a cluster object.
Definition: cluster.c:216