This source file includes following definitions.
- setup
- teardown
- buffer_scheme_test
- create_document_node
- create_element_node
- create_attr_node
- create_comment_node
- create_text_node
- create_dtd_node
- create_cdata_node
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 #include "crmcommon_private.h"
17
18
19 #define XML_DOC_PRIVATE_MAGIC 0x81726354UL
20 #define XML_NODE_PRIVATE_MAGIC 0x54637281UL
21
22 static int
23 setup(void **state) {
24 crm_xml_init();
25 return 0;
26 }
27
28 static int
29 teardown(void **state) {
30 crm_xml_cleanup();
31 return 0;
32 }
33
34 static void
35 buffer_scheme_test(void **state) {
36 assert_int_equal(XML_BUFFER_ALLOC_DOUBLEIT, xmlGetBufferAllocationScheme());
37 }
38
39
40
41
42
43
44
45
46
47
48
49 static void
50 create_document_node(void **state) {
51 xml_doc_private_t *docpriv = NULL;
52 xmlDocPtr doc = xmlNewDoc(PCMK__XML_VERSION);
53
54
55 assert_non_null(doc);
56 assert_int_equal(doc->type, XML_DOCUMENT_NODE);
57
58
59 docpriv = doc->_private;
60 assert_non_null(docpriv);
61 assert_int_equal(docpriv->check, XML_DOC_PRIVATE_MAGIC);
62 assert_true(pcmk_all_flags_set(docpriv->flags, pcmk__xf_dirty|pcmk__xf_created));
63
64
65 xmlFreeDoc(doc);
66 }
67
68 static void
69 create_element_node(void **state) {
70 xml_doc_private_t *docpriv = NULL;
71 xml_node_private_t *priv = NULL;
72 xmlDocPtr doc = xmlNewDoc(PCMK__XML_VERSION);
73 xmlNodePtr node = xmlNewDocNode(doc, NULL, (pcmkXmlStr) "test", NULL);
74
75
76 docpriv = doc->_private;
77 assert_true(pcmk_all_flags_set(docpriv->flags, pcmk__xf_dirty));
78
79
80 assert_non_null(node);
81 assert_int_equal(node->type, XML_ELEMENT_NODE);
82
83
84 priv = node->_private;
85 assert_non_null(priv);
86 assert_int_equal(priv->check, XML_NODE_PRIVATE_MAGIC);
87 assert_true(pcmk_all_flags_set(priv->flags, pcmk__xf_dirty|pcmk__xf_created));
88
89
90 xmlFreeNode(node);
91 xmlFreeDoc(doc);
92 }
93
94 static void
95 create_attr_node(void **state) {
96 xml_doc_private_t *docpriv = NULL;
97 xml_node_private_t *priv = NULL;
98 xmlDocPtr doc = xmlNewDoc(PCMK__XML_VERSION);
99 xmlNodePtr node = xmlNewDocNode(doc, NULL, (pcmkXmlStr) "test", NULL);
100 xmlAttrPtr attr = xmlNewProp(node, (pcmkXmlStr) PCMK_XA_NAME,
101 (pcmkXmlStr) "dummy-value");
102
103
104 docpriv = doc->_private;
105 assert_true(pcmk_all_flags_set(docpriv->flags, pcmk__xf_dirty));
106
107
108 assert_non_null(attr);
109 assert_int_equal(attr->type, XML_ATTRIBUTE_NODE);
110
111
112 priv = attr->_private;
113 assert_non_null(priv);
114 assert_int_equal(priv->check, XML_NODE_PRIVATE_MAGIC);
115 assert_true(pcmk_all_flags_set(priv->flags, pcmk__xf_dirty|pcmk__xf_created));
116
117
118 xmlFreeNode(node);
119 xmlFreeDoc(doc);
120 }
121
122 static void
123 create_comment_node(void **state) {
124 xml_doc_private_t *docpriv = NULL;
125 xml_node_private_t *priv = NULL;
126 xmlDocPtr doc = xmlNewDoc(PCMK__XML_VERSION);
127 xmlNodePtr node = xmlNewDocComment(doc, (pcmkXmlStr) "blahblah");
128
129
130 docpriv = doc->_private;
131 assert_true(pcmk_all_flags_set(docpriv->flags, pcmk__xf_dirty));
132
133
134 assert_non_null(node);
135 assert_int_equal(node->type, XML_COMMENT_NODE);
136
137
138 priv = node->_private;
139 assert_non_null(priv);
140 assert_int_equal(priv->check, XML_NODE_PRIVATE_MAGIC);
141 assert_true(pcmk_all_flags_set(priv->flags, pcmk__xf_dirty|pcmk__xf_created));
142
143
144 xmlFreeNode(node);
145 xmlFreeDoc(doc);
146 }
147
148 static void
149 create_text_node(void **state) {
150 xml_doc_private_t *docpriv = NULL;
151 xml_node_private_t *priv = NULL;
152 xmlDocPtr doc = xmlNewDoc(PCMK__XML_VERSION);
153 xmlNodePtr node = xmlNewDocText(doc, (pcmkXmlStr) "blahblah");
154
155
156 docpriv = doc->_private;
157 assert_true(pcmk_all_flags_set(docpriv->flags, pcmk__xf_dirty));
158
159
160 assert_non_null(node);
161 assert_int_equal(node->type, XML_TEXT_NODE);
162
163
164 priv = node->_private;
165 assert_null(priv);
166
167
168 xmlFreeNode(node);
169 xmlFreeDoc(doc);
170 }
171
172 static void
173 create_dtd_node(void **state) {
174 xml_doc_private_t *docpriv = NULL;
175 xml_node_private_t *priv = NULL;
176 xmlDocPtr doc = xmlNewDoc(PCMK__XML_VERSION);
177 xmlDtdPtr dtd = xmlNewDtd(doc, (pcmkXmlStr) PCMK_XA_NAME,
178 (pcmkXmlStr) "externalId",
179 (pcmkXmlStr) "systemId");
180
181
182 docpriv = doc->_private;
183 assert_true(pcmk_all_flags_set(docpriv->flags, pcmk__xf_dirty));
184
185
186 assert_non_null(dtd);
187 assert_int_equal(dtd->type, XML_DTD_NODE);
188
189
190 priv = dtd->_private;
191 assert_null(priv);
192
193
194
195 xmlFreeDoc(doc);
196 }
197
198 static void
199 create_cdata_node(void **state) {
200 xml_doc_private_t *docpriv = NULL;
201 xml_node_private_t *priv = NULL;
202 xmlDocPtr doc = xmlNewDoc(PCMK__XML_VERSION);
203 xmlNodePtr node = xmlNewCDataBlock(doc, (pcmkXmlStr) "blahblah", 8);
204
205
206 docpriv = doc->_private;
207 assert_true(pcmk_all_flags_set(docpriv->flags, pcmk__xf_dirty));
208
209
210 assert_non_null(node);
211 assert_int_equal(node->type, XML_CDATA_SECTION_NODE);
212
213
214 priv = node->_private;
215 assert_null(priv);
216
217
218 xmlFreeNode(node);
219 xmlFreeDoc(doc);
220 }
221
222 PCMK__UNIT_TEST(setup, teardown,
223 cmocka_unit_test(buffer_scheme_test),
224 cmocka_unit_test(create_document_node),
225 cmocka_unit_test(create_element_node),
226 cmocka_unit_test(create_attr_node),
227 cmocka_unit_test(create_comment_node),
228 cmocka_unit_test(create_text_node),
229 cmocka_unit_test(create_dtd_node),
230 cmocka_unit_test(create_cdata_node));