src/server/test/xml.c

branch
webdav
changeset 319
a9b9344875aa
parent 232
499711b2a970
child 324
44cf877b3d9f
equal deleted inserted replaced
318:60870dbac94f 319:a9b9344875aa
201 201
202 xmlFreeDoc(doc); 202 xmlFreeDoc(doc);
203 xmlFreeDoc(doc2); 203 xmlFreeDoc(doc2);
204 xmlFreeDoc(doc6); 204 xmlFreeDoc(doc6);
205 UCX_TEST_END; 205 UCX_TEST_END;
206
207 testutil_destroy_session(sn);
206 } 208 }
207 209
208 // checks if the namespace list contains the test namespaces x1, x2, x3 and x4 210 // checks if the namespace list contains the test namespaces x1, x2, x3 and x4
209 static void check_ns_list(WebdavNSList *list, int *x1, int *x2, int *x3, int *x4) { 211 static void check_ns_list(WebdavNSList *list, int *x1, int *x2, int *x3, int *x4) {
210 *x1 = 0; 212 *x1 = 0;
298 300
299 xmlFreeDoc(doc3); 301 xmlFreeDoc(doc3);
300 xmlFreeDoc(doc4); 302 xmlFreeDoc(doc4);
301 xmlFreeDoc(doc5); 303 xmlFreeDoc(doc5);
302 UCX_TEST_END; 304 UCX_TEST_END;
305
306 testutil_destroy_session(sn);
303 } 307 }
304 308
305 UCX_TEST(test_wsxml_write_nodes) { 309 UCX_TEST(test_wsxml_write_nodes) {
306 Session *sn = testutil_session(); 310 Session *sn = testutil_session();
307 TestIOStream *st = testutil_iostream(2048, TRUE); 311 TestIOStream *st = testutil_iostream(2048, TRUE);
332 xmlFreeDoc(doc); 336 xmlFreeDoc(doc);
333 xmlFreeDoc(genDoc); 337 xmlFreeDoc(genDoc);
334 338
335 UCX_TEST_END; 339 UCX_TEST_END;
336 testutil_iostream_destroy(st); 340 testutil_iostream_destroy(st);
337 } 341 testutil_destroy_session(sn);
342 }
343
344 UCX_TEST(test_wsxml_nslist2string) {
345 Session *sn = testutil_session();
346
347 UCX_TEST_BEGIN;
348
349 WSNamespace ns1;
350 WSNamespace ns2;
351 WSNamespace ns3;
352 memset(&ns1, 0, sizeof(WSNamespace));
353 memset(&ns2, 0, sizeof(WSNamespace));
354 memset(&ns3, 0, sizeof(WSNamespace));
355 ns1.prefix = (const xmlChar*)"x";
356 ns1.href = (const xmlChar*)"ns1";
357 ns2.prefix = (const xmlChar*)"y";
358 ns2.href = (const xmlChar*)"ns2";
359 ns3.prefix = (const xmlChar*)"z";
360 ns3.href = (const xmlChar*)"ns3";
361
362 WebdavNSList elm1 = { &ns1, NULL, NULL };
363 WebdavNSList elm2 = { &ns2, NULL, NULL };
364 WebdavNSList elm3 = { &ns3, NULL, NULL };
365
366 // single elm test
367 char *str1 = wsxml_nslist2string(sn->pool, &elm1);
368 UCX_TEST_ASSERT(str1, "str1 is null");
369 UCX_TEST_ASSERT(!strcmp(str1, "x:ns1"), "str1: wrong content");
370
371 // 2 elm test
372 elm1.next = &elm2;
373 char *str2 = wsxml_nslist2string(sn->pool, &elm1);
374 UCX_TEST_ASSERT(str2, "str2 is null");
375 UCX_TEST_ASSERT(!strcmp(str2, "x:ns1\ny:ns2"), "str2: wrong content");
376
377 // 3 elm test
378 elm2.next = &elm3;
379 char *str3 = wsxml_nslist2string(sn->pool, &elm1);
380 UCX_TEST_ASSERT(str3, "str3 is null");
381 UCX_TEST_ASSERT(!strcmp(str3, "x:ns1\ny:ns2\nz:ns3"), "str3: wrong content");
382
383 // empty prefix test
384 ns1.prefix = NULL;
385 char *str4 = wsxml_nslist2string(sn->pool, &elm1);
386 UCX_TEST_ASSERT(str4, "str3 is null");
387 UCX_TEST_ASSERT(!strcmp(str4, ":ns1\ny:ns2\nz:ns3"), "str4: wrong content");
388
389 UCX_TEST_END;
390 testutil_destroy_session(sn);
391 }
392
393 UCX_TEST(test_wsxml_string2nslist) {
394 Session *sn = testutil_session();
395
396 UCX_TEST_BEGIN;
397
398 // empty list
399 WebdavNSList *list1 = wsxml_string2nslist(sn->pool, "");
400 UCX_TEST_ASSERT(!list1, "list1 should be NULL");
401
402 // 1 elm list
403 WebdavNSList *list2 = wsxml_string2nslist(sn->pool, "x:ns1");
404 UCX_TEST_ASSERT(list2, "list2 is NULL");
405 UCX_TEST_ASSERT(list2->namespace, "list2 namespace is NULL");
406 UCX_TEST_ASSERT(!strcmp((const char*)list2->namespace->prefix, "x"), "list2: wrong prefix");
407 UCX_TEST_ASSERT(!strcmp((const char*)list2->namespace->href, "ns1"), "list2: wrong href");
408
409 // 2 elm list
410 WebdavNSList *list3 = wsxml_string2nslist(sn->pool, "x:ns1\ny:ns2");
411 UCX_TEST_ASSERT(list3, "list3 is NULL");
412 UCX_TEST_ASSERT(list3->namespace, "list3 namespace is NULL");
413 UCX_TEST_ASSERT(!strcmp((const char*)list3->namespace->prefix, "x"), "list3: wrong prefix");
414 UCX_TEST_ASSERT(!strcmp((const char*)list3->namespace->href, "ns1"), "list3: wrong href");
415 UCX_TEST_ASSERT(list3->next, "list3 elm2 is NULL");
416 UCX_TEST_ASSERT(list3->next->namespace, "list3 namespace 2 is NULL");
417 UCX_TEST_ASSERT(!strcmp((const char*)list3->namespace->prefix, "x"), "list3: elm2 wrong prefix");
418 UCX_TEST_ASSERT(!strcmp((const char*)list3->namespace->href, "ns1"), "list3: elm2 wrong href");
419
420 // empty prefix
421 WebdavNSList *list4 = wsxml_string2nslist(sn->pool, ":x\ny:ns2");
422 UCX_TEST_ASSERT(list4, "list4 is NULL");
423 UCX_TEST_ASSERT(list4->namespace, "list4 namespace is NULL");
424 UCX_TEST_ASSERT(!list4->namespace->prefix, "list4 elm1 prefix should be NULL");
425 UCX_TEST_ASSERT(!strcmp((const char*)list3->namespace->href, "ns1"), "list3: wrong href");
426
427
428 UCX_TEST_END;
429 //testutil_destroy_session(sn);
430 }

mercurial