pacemaker 3.0.1-16e74fc4da
Scalable High-Availability cluster resource manager
Loading...
Searching...
No Matches
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
17static void
18destroy_fn1(gpointer arg)
19{
20 return;
21}
22
23static void
24destroy_fn2(gpointer arg)
25{
26 return;
27}
28
29static void
30null_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
36static void
37null_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
51static void
52previous_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),
60 assert_ptr_equal(cluster.destroy, destroy_fn1);
61}
62
63static void
64previous_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),
72 assert_ptr_equal(cluster.destroy, destroy_fn1);
73}
74
75PCMK__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))
int pcmk_cluster_set_destroy_fn(pcmk_cluster_t *cluster, void(*fn)(gpointer))
Set the destroy function for a cluster object.
Definition cluster.c:184
@ pcmk_rc_ok
Definition results.h:159
void(* destroy)(gpointer)
Definition cluster.h:40
#define PCMK__UNIT_TEST(group_setup, group_teardown,...)