pacemaker  2.1.8-3980678f03
Scalable High-Availability cluster resource manager
pcmk_set_scheduler_cib_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 <crm/common/scheduler.h>
14 
15 static void
16 null_scheduler(void **state)
17 {
18  xmlNode *cib = pcmk__xe_create(NULL, "test");
19 
20  assert_int_equal(pcmk_set_scheduler_cib(NULL, NULL), EINVAL);
21  assert_int_equal(pcmk_set_scheduler_cib(NULL, cib), EINVAL);
22 
23  free_xml(cib);
24 }
25 
26 static void
27 null_cib(void **state)
28 {
30  .input = NULL,
31  };
32 
33  assert_int_equal(pcmk_set_scheduler_cib(&scheduler, NULL), pcmk_rc_ok);
34  assert_null(scheduler.input);
35 }
36 
37 static void
38 previous_cib_null(void **state)
39 {
41  .input = NULL,
42  };
43  xmlNode *cib = pcmk__xe_create(NULL, "test");
44 
45  assert_int_equal(pcmk_set_scheduler_cib(&scheduler, cib), pcmk_rc_ok);
46  assert_ptr_equal(scheduler.input, cib);
47 
48  free_xml(cib);
49 }
50 
51 static void
52 previous_cib_nonnull(void **state)
53 {
54  xmlNode *old_cib = pcmk__xe_create(NULL, "old");
55  xmlNode *new_cib = pcmk__xe_create(NULL, "new");
57  .input = old_cib,
58  };
59 
60  assert_int_equal(pcmk_set_scheduler_cib(&scheduler, new_cib), pcmk_rc_ok);
61  assert_ptr_equal(scheduler.input, new_cib);
62 
63  free_xml(old_cib);
64  free_xml(new_cib);
65 }
66 
67 PCMK__UNIT_TEST(NULL, NULL,
68  cmocka_unit_test(null_scheduler),
69  cmocka_unit_test(null_cib),
70  cmocka_unit_test(previous_cib_null),
71  cmocka_unit_test(previous_cib_nonnull))
#define PCMK__UNIT_TEST(group_setup, group_teardown,...)
Scheduler API.
void free_xml(xmlNode *child)
Definition: xml.c:867
xmlNode * input
Definition: scheduler.h:196
pcmk_scheduler_t * scheduler
int pcmk_set_scheduler_cib(pcmk_scheduler_t *scheduler, xmlNode *cib)
Definition: scheduler.c:67
xmlNode * pcmk__xe_create(xmlNode *parent, const char *name)
Definition: xml.c:720