This source file includes following definitions.
- null_xml
- no_siblings
- with_siblings
1
2
3
4
5
6
7
8
9
10 #include <crm_internal.h>
11
12 #include <crm/common/xml.h>
13 #include <crm/common/unittest_internal.h>
14 #include <crm/common/xml_internal.h>
15
16 static void
17 null_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
31 static void
32 no_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
59 static void
60 with_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
90 PCMK__UNIT_TEST(pcmk__xml_test_setup_group, pcmk__xml_test_teardown_group,
91 cmocka_unit_test(null_xml),
92 cmocka_unit_test(no_siblings),
93 cmocka_unit_test(with_siblings));