This source file includes following definitions.
- bad_input
- not_found
- find_attrB
- find_attrA_matching
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 const char *str1 =
17 "<xml>\n"
18 " <!-- This is an A node -->\n"
19 " <nodeA attrA=\"123\" " PCMK_XA_ID "=\"1\">\n"
20 " content\n"
21 " </nodeA>\n"
22 " <!-- This is an A node -->\n"
23 " <nodeA attrA=\"456\" " PCMK_XA_ID "=\"2\">\n"
24 " content\n"
25 " </nodeA>\n"
26 " <!-- This is an A node -->\n"
27 " <nodeA attrB=\"XYZ\" " PCMK_XA_ID "=\"3\">\n"
28 " content\n"
29 " </nodeA>\n"
30 " <!-- This is a B node -->\n"
31 " <nodeB attrA=\"123\" " PCMK_XA_ID "=\"4\">\n"
32 " content\n"
33 " </nodeA>\n"
34 " <!-- This is a B node -->\n"
35 " <nodeB attrB=\"ABC\" " PCMK_XA_ID "=\"5\">\n"
36 " content\n"
37 " </nodeA>\n"
38 "</xml>";
39
40 static void
41 bad_input(void **state) {
42 xmlNode *xml = pcmk__xml_parse(str1);
43
44 assert_null(pcmk__xe_first_child(NULL, NULL, NULL, NULL));
45 assert_null(pcmk__xe_first_child(NULL, NULL, NULL, "attrX"));
46
47 free_xml(xml);
48 }
49
50 static void
51 not_found(void **state) {
52 xmlNode *xml = pcmk__xml_parse(str1);
53
54
55 assert_null(pcmk__xe_first_child(xml, NULL, "attrX", NULL));
56
57 assert_null(pcmk__xe_first_child(xml, "nodeX", NULL, NULL));
58
59 assert_null(pcmk__xe_first_child(xml, "nodeA", "attrX", NULL));
60
61 assert_null(pcmk__xe_first_child(xml, "nodeA", "attrA", "XYZ"));
62
63 free_xml(xml);
64 }
65
66 static void
67 find_attrB(void **state) {
68 xmlNode *xml = pcmk__xml_parse(str1);
69 xmlNode *result = NULL;
70
71
72 result = pcmk__xe_first_child(xml, NULL, "attrB", NULL);
73 assert_non_null(result);
74 assert_string_equal(crm_element_value(result, PCMK_XA_ID), "3");
75
76
77 result = pcmk__xe_first_child(xml, "nodeB", "attrB", NULL);
78 assert_non_null(result);
79 assert_string_equal(crm_element_value(result, PCMK_XA_ID), "5");
80
81 free_xml(xml);
82 }
83
84 static void
85 find_attrA_matching(void **state) {
86 xmlNode *xml = pcmk__xml_parse(str1);
87 xmlNode *result = NULL;
88
89
90 result = pcmk__xe_first_child(xml, NULL, "attrA", "456");
91 assert_non_null(result);
92 assert_string_equal(crm_element_value(result, PCMK_XA_ID), "2");
93
94
95 result = pcmk__xe_first_child(xml, "nodeB", "attrA", "123");
96 assert_non_null(result);
97 assert_string_equal(crm_element_value(result, PCMK_XA_ID), "4");
98
99 free_xml(xml);
100 }
101
102 PCMK__UNIT_TEST(pcmk__xml_test_setup_group, NULL,
103 cmocka_unit_test(bad_input),
104 cmocka_unit_test(not_found),
105 cmocka_unit_test(find_attrB),
106 cmocka_unit_test(find_attrA_matching));