src/server/test/xml.c

branch
webdav
changeset 225
e4f3e1433098
parent 224
0de1ec82628e
child 232
499711b2a970
equal deleted inserted replaced
224:0de1ec82628e 225:e4f3e1433098
163 163
164 xmlFreeDoc(doc); 164 xmlFreeDoc(doc);
165 xmlFreeDoc(doc2); 165 xmlFreeDoc(doc2);
166 UCX_TEST_END; 166 UCX_TEST_END;
167 } 167 }
168
169 // checks if the namespace list contains the test namespaces x1, x2, x3 and x4
170 static void check_ns_list(WebdavNSList *list, int *x1, int *x2, int *x3, int *x4) {
171 *x1 = 0;
172 *x2 = 0;
173 *x3 = 0;
174 *x4 = 0;
175
176 WebdavNSList *elm = list;
177 while(elm) {
178 if(!strcmp((const char*)elm->namespace->prefix, "x1") &&
179 !strcmp((const char*)elm->namespace->href, "http://example.com/ns1/"))
180 {
181 *x1 = 1;
182 } else if(!strcmp((const char*)elm->namespace->prefix, "x2") &&
183 !strcmp((const char*)elm->namespace->href, "http://example.com/ns2/"))
184 {
185 *x2 = 1;
186 } else if(!strcmp((const char*)elm->namespace->prefix, "x3") &&
187 !strcmp((const char*)elm->namespace->href, "http://example.com/ns_0/"))
188 {
189 *x3 = 1;
190 } else if(!strcmp((const char*)elm->namespace->prefix, "x4") &&
191 !strcmp((const char*)elm->namespace->href, "http://example.com/ns_0/"))
192 {
193 *x4 = 1;
194 }
195
196 elm = elm->next;
197 }
198 }
199
200 UCX_TEST(test_wsxml_get_required_namespaces) {
201 Session *sn = testutil_session();
202
203 UCX_TEST_BEGIN;
204
205 xmlDoc *doc3 = xmlReadMemory(
206 XML_TESTDATA3, strlen(XML_TESTDATA3), NULL, NULL, 0);
207 xmlDoc *doc4 = xmlReadMemory(
208 XML_TESTDATA4, strlen(XML_TESTDATA4), NULL, NULL, 0);
209 xmlDoc *doc5 = xmlReadMemory(
210 XML_TESTDATA5, strlen(XML_TESTDATA5), NULL, NULL, 0);
211
212 xmlNode *node0 = xmlDocGetRootElement(doc3);
213 xmlNode *node1 = xmlDocGetRootElement(doc3)->children;
214 xmlNode *node2 = xmlDocGetRootElement(doc4)->children;
215 xmlNode *node3 = xmlDocGetRootElement(doc5)->children;
216
217 UCX_TEST_ASSERT(doc3, "doc3 is NULL");
218 UCX_TEST_ASSERT(doc4, "doc4 is NULL");
219 UCX_TEST_ASSERT(doc5, "doc5 is NULL");
220
221 int err0, err1, err2, err3;
222 int x1 = 0;
223 int x2 = 0;
224 int x3 = 0;
225 int x4 = 0;
226 WebdavNSList *elm = NULL;
227
228 // Test 0:
229 WebdavNSList *ns0 = wsxml_get_required_namespaces(sn->pool, node0, &err0);
230 UCX_TEST_ASSERT(!err0, "ns0 failed");
231 UCX_TEST_ASSERT(!ns0, "ns0: nsdefs should be ignored");
232
233 WebdavNSList *ns1 = wsxml_get_required_namespaces(sn->pool, node1, &err1);
234 check_ns_list(ns1, &x1, &x2, &x3, &x4);
235 UCX_TEST_ASSERT(!err1, "ns1 failed");
236 UCX_TEST_ASSERT(ns1, "ns1: no list");
237 UCX_TEST_ASSERT(x1, "ns1: x1 missing");
238 UCX_TEST_ASSERT(x2, "ns1: x2 missing");
239 UCX_TEST_ASSERT(x3, "ns1: x3 missing");
240 UCX_TEST_ASSERT(x4, "ns1: x4 missing");
241
242 WebdavNSList *ns2 = wsxml_get_required_namespaces(sn->pool, node2, &err2);
243 check_ns_list(ns2, &x1, &x2, &x3, &x4);
244 UCX_TEST_ASSERT(!err2, "ns2 failed");
245 UCX_TEST_ASSERT(ns2, "ns2: no list");
246 UCX_TEST_ASSERT(x1, "ns2: x1 missing");
247 UCX_TEST_ASSERT(x2, "ns2: x2 missing");
248 UCX_TEST_ASSERT(!x3, "ns2: x3");
249 UCX_TEST_ASSERT(!x4, "ns2: x4");
250
251 WebdavNSList *ns3 = wsxml_get_required_namespaces(sn->pool, node3, &err3);
252 check_ns_list(ns3, &x1, &x2, &x3, &x4);
253 UCX_TEST_ASSERT(!err3, "ns3 failed");
254 UCX_TEST_ASSERT(ns3, "ns3: no list");
255 UCX_TEST_ASSERT(x1, "ns3: x1 missing");
256 UCX_TEST_ASSERT(x2, "ns3: x2 missing");
257 UCX_TEST_ASSERT(!x3, "ns3: x3");
258 UCX_TEST_ASSERT(!x4, "ns3: x4");
259
260 UCX_TEST_END;
261 }

mercurial