src/server/test/xml.c

branch
webdav
changeset 319
a9b9344875aa
parent 232
499711b2a970
child 324
44cf877b3d9f
--- a/src/server/test/xml.c	Sat Apr 30 20:44:38 2022 +0200
+++ b/src/server/test/xml.c	Sun May 01 10:48:20 2022 +0200
@@ -203,6 +203,8 @@
     xmlFreeDoc(doc2);
     xmlFreeDoc(doc6);
     UCX_TEST_END;
+    
+    testutil_destroy_session(sn);
 }
 
 // checks if the namespace list contains the test namespaces x1, x2, x3 and x4
@@ -300,6 +302,8 @@
     xmlFreeDoc(doc4);
     xmlFreeDoc(doc5);
     UCX_TEST_END;
+    
+    testutil_destroy_session(sn);
 }
 
 UCX_TEST(test_wsxml_write_nodes) {
@@ -334,4 +338,93 @@
     
     UCX_TEST_END;
     testutil_iostream_destroy(st);
+    testutil_destroy_session(sn);
 }
+
+UCX_TEST(test_wsxml_nslist2string) {
+    Session *sn = testutil_session();
+    
+    UCX_TEST_BEGIN;
+    
+    WSNamespace ns1;
+    WSNamespace ns2;
+    WSNamespace ns3;  
+    memset(&ns1, 0, sizeof(WSNamespace));
+    memset(&ns2, 0, sizeof(WSNamespace));
+    memset(&ns3, 0, sizeof(WSNamespace));
+    ns1.prefix = (const xmlChar*)"x";
+    ns1.href = (const xmlChar*)"ns1";
+    ns2.prefix = (const xmlChar*)"y";
+    ns2.href = (const xmlChar*)"ns2";
+    ns3.prefix = (const xmlChar*)"z";
+    ns3.href = (const xmlChar*)"ns3";
+    
+    WebdavNSList elm1 = { &ns1, NULL, NULL };
+    WebdavNSList elm2 = { &ns2, NULL, NULL };
+    WebdavNSList elm3 = { &ns3, NULL, NULL };
+    
+    // single elm test
+    char *str1 = wsxml_nslist2string(sn->pool, &elm1);
+    UCX_TEST_ASSERT(str1, "str1 is null");
+    UCX_TEST_ASSERT(!strcmp(str1, "x:ns1"), "str1: wrong content");
+    
+    // 2 elm test
+    elm1.next = &elm2;
+    char *str2 = wsxml_nslist2string(sn->pool, &elm1);
+    UCX_TEST_ASSERT(str2, "str2 is null");
+    UCX_TEST_ASSERT(!strcmp(str2, "x:ns1\ny:ns2"), "str2: wrong content");
+    
+    // 3 elm test
+    elm2.next = &elm3;
+    char *str3 = wsxml_nslist2string(sn->pool, &elm1);
+    UCX_TEST_ASSERT(str3, "str3 is null");
+    UCX_TEST_ASSERT(!strcmp(str3, "x:ns1\ny:ns2\nz:ns3"), "str3: wrong content");
+    
+    // empty prefix test
+    ns1.prefix = NULL;
+    char *str4 = wsxml_nslist2string(sn->pool, &elm1);
+    UCX_TEST_ASSERT(str4, "str3 is null");
+    UCX_TEST_ASSERT(!strcmp(str4, ":ns1\ny:ns2\nz:ns3"), "str4: wrong content");
+    
+    UCX_TEST_END;
+    testutil_destroy_session(sn);
+}
+
+UCX_TEST(test_wsxml_string2nslist) {
+    Session *sn = testutil_session();
+    
+    UCX_TEST_BEGIN;
+    
+    // empty list
+    WebdavNSList *list1 = wsxml_string2nslist(sn->pool, "");
+    UCX_TEST_ASSERT(!list1, "list1 should be NULL");
+    
+    // 1 elm list
+    WebdavNSList *list2 = wsxml_string2nslist(sn->pool, "x:ns1");
+    UCX_TEST_ASSERT(list2, "list2 is NULL");
+    UCX_TEST_ASSERT(list2->namespace, "list2 namespace is NULL");
+    UCX_TEST_ASSERT(!strcmp((const char*)list2->namespace->prefix, "x"), "list2: wrong prefix");
+    UCX_TEST_ASSERT(!strcmp((const char*)list2->namespace->href, "ns1"), "list2: wrong href");
+    
+    // 2 elm list
+    WebdavNSList *list3 = wsxml_string2nslist(sn->pool, "x:ns1\ny:ns2");
+    UCX_TEST_ASSERT(list3, "list3 is NULL");
+    UCX_TEST_ASSERT(list3->namespace, "list3 namespace is NULL");
+    UCX_TEST_ASSERT(!strcmp((const char*)list3->namespace->prefix, "x"), "list3: wrong prefix");
+    UCX_TEST_ASSERT(!strcmp((const char*)list3->namespace->href, "ns1"), "list3: wrong href");
+    UCX_TEST_ASSERT(list3->next, "list3 elm2 is NULL");
+    UCX_TEST_ASSERT(list3->next->namespace, "list3 namespace 2 is NULL");
+    UCX_TEST_ASSERT(!strcmp((const char*)list3->namespace->prefix, "x"), "list3: elm2 wrong prefix");
+    UCX_TEST_ASSERT(!strcmp((const char*)list3->namespace->href, "ns1"), "list3: elm2 wrong href");
+    
+    // empty prefix
+    WebdavNSList *list4 = wsxml_string2nslist(sn->pool, ":x\ny:ns2");
+    UCX_TEST_ASSERT(list4, "list4 is NULL");
+    UCX_TEST_ASSERT(list4->namespace, "list4 namespace is NULL");
+    UCX_TEST_ASSERT(!list4->namespace->prefix, "list4 elm1 prefix should be NULL");
+    UCX_TEST_ASSERT(!strcmp((const char*)list3->namespace->href, "ns1"), "list3: wrong href");
+    
+    
+    UCX_TEST_END;
+    //testutil_destroy_session(sn);
+}

mercurial