pacemaker  2.1.5-b7adf64e51
Scalable High-Availability cluster resource manager
pcmk__xe_get_bool_attr_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>
11 
14 
15 static void
16 empty_input(void **state)
17 {
18  xmlNode *node = string2xml("<node/>");
19  bool value;
20 
21  assert_int_equal(pcmk__xe_get_bool_attr(NULL, NULL, &value), ENODATA);
22  assert_int_equal(pcmk__xe_get_bool_attr(NULL, "whatever", &value), ENODATA);
23  assert_int_equal(pcmk__xe_get_bool_attr(node, NULL, &value), EINVAL);
24  assert_int_equal(pcmk__xe_get_bool_attr(node, "whatever", NULL), EINVAL);
25 
26  free_xml(node);
27 }
28 
29 static void
30 attr_missing(void **state)
31 {
32  xmlNode *node = string2xml("<node a=\"true\" b=\"false\"/>");
33  bool value;
34 
35  assert_int_equal(pcmk__xe_get_bool_attr(node, "c", &value), ENODATA);
36  free_xml(node);
37 }
38 
39 static void
40 attr_present(void **state)
41 {
42  xmlNode *node = string2xml("<node a=\"true\" b=\"false\" c=\"blah\"/>");
43  bool value;
44 
45  value = false;
46  assert_int_equal(pcmk__xe_get_bool_attr(node, "a", &value), pcmk_rc_ok);
47  assert_true(value);
48  value = true;
49  assert_int_equal(pcmk__xe_get_bool_attr(node, "b", &value), pcmk_rc_ok);
50  assert_false(value);
51  assert_int_equal(pcmk__xe_get_bool_attr(node, "c", &value), pcmk_rc_unknown_format);
52 
53  free_xml(node);
54 }
55 
56 PCMK__UNIT_TEST(NULL, NULL,
57  cmocka_unit_test(empty_input),
58  cmocka_unit_test(attr_missing),
59  cmocka_unit_test(attr_present))
#define PCMK__UNIT_TEST(group_setup, group_teardown,...)
xmlNode * string2xml(const char *input)
Definition: xml.c:930
int pcmk__xe_get_bool_attr(const xmlNode *node, const char *name, bool *value)
Definition: nvpair.c:948
void free_xml(xmlNode *child)
Definition: xml.c:885
#define ENODATA
Definition: portability.h:145