pacemaker 3.0.1-16e74fc4da
Scalable High-Availability cluster resource manager
Loading...
Searching...
No Matches
pcmk__xe_next_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/xml.h>
15
16static void
17null_xml(void **state)
18{
19 assert_null(pcmk__xe_next(NULL, NULL));
20 assert_null(pcmk__xe_next(NULL, "test"));
21}
22
23
24#define XML_NO_SIBLINGS \
25 "<xml>\n" \
26 " <!-- comment -->" \
27 " <foo id='child1'>text</foo>" \
28 " <!-- another comment -->" \
29 "</xml>"
30
31static void
32no_siblings(void **state)
33{
34 xmlNode *xml = pcmk__xml_parse(XML_NO_SIBLINGS);
35 xmlNode *child = NULL;
36
37 assert_non_null(xml);
38
39 child = pcmk__xe_first_child(xml, NULL, NULL, NULL);
40 assert_non_null(child);
41 assert_string_equal(pcmk__xe_id(child), "child1");
42
43 assert_null(pcmk__xe_next(child, NULL));
44 assert_null(pcmk__xe_next(child, "foo"));
45
46 pcmk__xml_free(xml);
47}
48
49#define XML_SIBLINGS \
50 "<xml>\n" \
51 " <!-- comment -->" \
52 " <foo id='child1'>text</foo>" \
53 " <!-- another comment -->" \
54 " <bar id='child2'>text</bar>" \
55 " <!-- yet another comment -->" \
56 " <foo id='child3'>text</foo>" \
57 "</xml>"
58
59static void
60with_siblings(void **state)
61{
62 xmlNode *xml = pcmk__xml_parse(XML_SIBLINGS);
63 xmlNode *child = NULL;
64 xmlNode *next = NULL;
65
66 assert_non_null(xml);
67
68 child = pcmk__xe_first_child(xml, NULL, NULL, NULL);
69 assert_non_null(child);
70 assert_string_equal(pcmk__xe_id(child), "child1");
71
72 next = pcmk__xe_next(child, NULL);
73 assert_non_null(next);
74 assert_string_equal(pcmk__xe_id(next), "child2");
75
76 next = pcmk__xe_next(child, "bar");
77 assert_non_null(next);
78 assert_string_equal(pcmk__xe_id(next), "child2");
79
80 next = pcmk__xe_next(child, "foo");
81 assert_non_null(next);
82 assert_string_equal(pcmk__xe_id(next), "child3");
83
84 next = pcmk__xe_next(child, "foobar");
85 assert_null(next);
86
87 pcmk__xml_free(xml);
88}
89
91 cmocka_unit_test(null_xml),
92 cmocka_unit_test(no_siblings),
93 cmocka_unit_test(with_siblings));
#define XML_NO_SIBLINGS
#define XML_SIBLINGS
int pcmk__xml_test_teardown_group(void **state)
Definition unittest.c:105
#define PCMK__UNIT_TEST(group_setup, group_teardown,...)
int pcmk__xml_test_setup_group(void **state)
Definition unittest.c:87
Wrappers for and extensions to libxml2.
xmlNode * pcmk__xe_first_child(const xmlNode *parent, const char *node_name, const char *attr_n, const char *attr_v)
Definition xml_element.c:43
xmlNode * pcmk__xe_next(const xmlNode *node, const char *element_name)
void pcmk__xml_free(xmlNode *xml)
Definition xml.c:816
xmlNode * pcmk__xml_parse(const char *input)
Definition xml_io.c:167