pacemaker 2.1.5-a3f44794f94
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 Lesser General Public License
7 * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
8 */
9
10#include <crm_internal.h>
11
13
14#include <glib.h>
15
16static void
17element_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
46PCMK__UNIT_TEST(NULL, NULL,
47 cmocka_unit_test(element_nodes))
const char * crm_element_value(const xmlNode *data, const char *name)
Retrieve the value of an XML attribute.
Definition: nvpair.c:517
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:323
#define PCMK__UNIT_TEST(group_setup, group_teardown,...)
xmlNode * pcmk_create_xml_text_node(xmlNode *parent, const char *name, const char *content)
Definition: xml.c:774
void fix_plus_plus_recursive(xmlNode *target)
Parse integer assignment statements on this node and all its child nodes.
Definition: xml.c:578
xmlNode * string2xml(const char *input)
Definition: xml.c:930
xmlNode * create_xml_node(xmlNode *parent, const char *name)
Definition: xml.c:749