pacemaker  2.1.7-0f7f88312f
Scalable High-Availability cluster resource manager
fix_plus_plus_recursive_test.c
Go to the documentation of this file.
1 /*
2  * Copyright 2022 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 
13 
14 #include <glib.h>
15 
16 static void
17 element_nodes(void **state)
18 {
19  const char *new_value_root;
20  const char *new_value_child;
21  const char *new_value_grandchild;
22 
23  xmlNode *test_xml_root = create_xml_node(NULL, "test_xml_root");
24  xmlNode *test_xml_child = create_xml_node(test_xml_root, "test_xml_child");
25  xmlNode *test_xml_grandchild = create_xml_node(test_xml_child, "test_xml_grandchild");
26  xmlNode *test_xml_text = pcmk_create_xml_text_node(test_xml_root, "text_xml_text", "content");
27  xmlNode *test_xml_comment = string2xml("<!-- a comment -->");
28 
29  crm_xml_add(test_xml_root, "X", "5");
30  crm_xml_add(test_xml_child, "X", "X++");
31  crm_xml_add(test_xml_grandchild, "X", "X+=2");
32  crm_xml_add(test_xml_text, "X", "X++");
33 
34  fix_plus_plus_recursive(test_xml_root);
35  fix_plus_plus_recursive(test_xml_comment);
36 
37  new_value_root = crm_element_value(test_xml_root, "X");
38  new_value_child = crm_element_value(test_xml_child, "X");
39  new_value_grandchild = crm_element_value(test_xml_grandchild, "X");
40 
41  assert_string_equal(new_value_root, "5");
42  assert_string_equal(new_value_child, "1");
43  assert_string_equal(new_value_grandchild, "2");
44 }
45 
46 PCMK__UNIT_TEST(NULL, NULL,
47  cmocka_unit_test(element_nodes))
const char * crm_xml_add(xmlNode *node, const char *name, const char *value)
Create an XML attribute with specified name and value.
Definition: nvpair.c:302
PCMK__UNIT_TEST(NULL, NULL, cmocka_unit_test(bad_input), cmocka_unit_test(not_found), cmocka_unit_test(find_attrB), cmocka_unit_test(find_attrA_matching))
xmlNode * string2xml(const char *input)
Definition: xml.c:800
const char * crm_element_value(const xmlNode *data, const char *name)
Retrieve the value of an XML attribute.
Definition: nvpair.c:447
xmlNode * pcmk_create_xml_text_node(xmlNode *parent, const char *name, const char *content)
Definition: xml.c:672
xmlNode * create_xml_node(xmlNode *parent, const char *name)
Definition: xml.c:638
void fix_plus_plus_recursive(xmlNode *target)
Parse integer assignment statements on this node and all its child nodes.
Definition: xml.c:489