pacemaker  2.1.4-dc6eb4362
Scalable High-Availability cluster resource manager
pcmk__xe_attr_is_true_test.c
Go to the documentation of this file.
1 /*
2  * Copyright 2021 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 Lesser General Public License
7  * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
8  */
9 
10 #include <crm_internal.h>
12 
13 #include <stdarg.h>
14 #include <stddef.h>
15 #include <stdint.h>
16 #include <stdlib.h>
17 #include <string.h>
18 #include <setjmp.h>
19 #include <cmocka.h>
20 
21 static void
22 empty_input(void **state)
23 {
24  xmlNode *node = string2xml("<node/>");
25 
26  assert_false(pcmk__xe_attr_is_true(NULL, NULL));
27  assert_false(pcmk__xe_attr_is_true(NULL, "whatever"));
28  assert_false(pcmk__xe_attr_is_true(node, NULL));
29 
30  free_xml(node);
31 }
32 
33 static void
34 attr_missing(void **state)
35 {
36  xmlNode *node = string2xml("<node a=\"true\" b=\"false\"/>");
37 
38  assert_false(pcmk__xe_attr_is_true(node, "c"));
39  free_xml(node);
40 }
41 
42 static void
43 attr_present(void **state)
44 {
45  xmlNode *node = string2xml("<node a=\"true\" b=\"false\"/>");
46 
47  assert_true(pcmk__xe_attr_is_true(node, "a"));
48  assert_false(pcmk__xe_attr_is_true(node, "b"));
49 
50  free_xml(node);
51 }
52 
53 int
54 main(int argc, char **argv)
55 {
56  const struct CMUnitTest tests[] = {
57  cmocka_unit_test(empty_input),
58  cmocka_unit_test(attr_missing),
59  cmocka_unit_test(attr_present),
60  };
61 
62  cmocka_set_message_output(CM_OUTPUT_TAP);
63  return cmocka_run_group_tests(tests, NULL, NULL);
64 }
int main(int argc, char **argv)
xmlNode * string2xml(const char *input)
Definition: xml.c:869
void free_xml(xmlNode *child)
Definition: xml.c:824
bool pcmk__xe_attr_is_true(xmlNodePtr node, const char *name)
Definition: nvpair.c:986