src/server/test/xml.c

branch
webdav
changeset 225
e4f3e1433098
parent 224
0de1ec82628e
child 232
499711b2a970
--- a/src/server/test/xml.c	Thu Jan 16 19:14:53 2020 +0100
+++ b/src/server/test/xml.c	Thu Jan 16 21:31:16 2020 +0100
@@ -165,3 +165,97 @@
     xmlFreeDoc(doc2);
     UCX_TEST_END;
 }
+
+// checks if the namespace list contains the test namespaces x1, x2, x3 and x4
+static void check_ns_list(WebdavNSList *list, int *x1, int *x2, int *x3, int *x4) {
+    *x1 = 0;
+    *x2 = 0;
+    *x3 = 0;
+    *x4 = 0;
+    
+    WebdavNSList *elm = list;
+    while(elm) {
+        if(!strcmp((const char*)elm->namespace->prefix, "x1") &&
+           !strcmp((const char*)elm->namespace->href, "http://example.com/ns1/"))
+        {
+            *x1 = 1;
+        } else if(!strcmp((const char*)elm->namespace->prefix, "x2") &&
+                  !strcmp((const char*)elm->namespace->href, "http://example.com/ns2/"))
+        {
+            *x2 = 1;
+        } else if(!strcmp((const char*)elm->namespace->prefix, "x3") &&
+                  !strcmp((const char*)elm->namespace->href, "http://example.com/ns_0/"))
+        {
+            *x3 = 1;
+        } else if(!strcmp((const char*)elm->namespace->prefix, "x4") &&
+                  !strcmp((const char*)elm->namespace->href, "http://example.com/ns_0/"))
+        {
+            *x4 = 1;
+        }
+            
+        elm = elm->next;
+    }
+}
+
+UCX_TEST(test_wsxml_get_required_namespaces) {
+    Session *sn = testutil_session();
+    
+    UCX_TEST_BEGIN;
+    
+    xmlDoc *doc3 = xmlReadMemory(
+            XML_TESTDATA3, strlen(XML_TESTDATA3), NULL, NULL, 0);
+    xmlDoc *doc4 = xmlReadMemory(
+            XML_TESTDATA4, strlen(XML_TESTDATA4), NULL, NULL, 0);
+    xmlDoc *doc5 = xmlReadMemory(
+            XML_TESTDATA5, strlen(XML_TESTDATA5), NULL, NULL, 0);
+    
+    xmlNode *node0 = xmlDocGetRootElement(doc3);
+    xmlNode *node1 = xmlDocGetRootElement(doc3)->children;
+    xmlNode *node2 = xmlDocGetRootElement(doc4)->children;
+    xmlNode *node3 = xmlDocGetRootElement(doc5)->children;
+    
+    UCX_TEST_ASSERT(doc3, "doc3 is NULL");
+    UCX_TEST_ASSERT(doc4, "doc4 is NULL");
+    UCX_TEST_ASSERT(doc5, "doc5 is NULL");
+    
+    int err0, err1, err2, err3;
+    int x1 = 0;
+    int x2 = 0;
+    int x3 = 0;
+    int x4 = 0;
+    WebdavNSList *elm = NULL;
+    
+    // Test 0: 
+    WebdavNSList *ns0 = wsxml_get_required_namespaces(sn->pool, node0, &err0);
+    UCX_TEST_ASSERT(!err0, "ns0 failed");
+    UCX_TEST_ASSERT(!ns0, "ns0: nsdefs should be ignored");
+    
+    WebdavNSList *ns1 = wsxml_get_required_namespaces(sn->pool, node1, &err1);
+    check_ns_list(ns1, &x1, &x2, &x3, &x4);
+    UCX_TEST_ASSERT(!err1, "ns1 failed");
+    UCX_TEST_ASSERT(ns1, "ns1: no list");
+    UCX_TEST_ASSERT(x1, "ns1: x1 missing");
+    UCX_TEST_ASSERT(x2, "ns1: x2 missing");
+    UCX_TEST_ASSERT(x3, "ns1: x3 missing");
+    UCX_TEST_ASSERT(x4, "ns1: x4 missing");
+    
+    WebdavNSList *ns2 = wsxml_get_required_namespaces(sn->pool, node2, &err2);
+    check_ns_list(ns2, &x1, &x2, &x3, &x4);
+    UCX_TEST_ASSERT(!err2, "ns2 failed");
+    UCX_TEST_ASSERT(ns2, "ns2: no list");
+    UCX_TEST_ASSERT(x1, "ns2: x1 missing");
+    UCX_TEST_ASSERT(x2, "ns2: x2 missing");
+    UCX_TEST_ASSERT(!x3, "ns2: x3");
+    UCX_TEST_ASSERT(!x4, "ns2: x4");
+    
+    WebdavNSList *ns3 = wsxml_get_required_namespaces(sn->pool, node3, &err3);
+    check_ns_list(ns3, &x1, &x2, &x3, &x4);
+    UCX_TEST_ASSERT(!err3, "ns3 failed");
+    UCX_TEST_ASSERT(ns3, "ns3: no list");
+    UCX_TEST_ASSERT(x1, "ns3: x1 missing");
+    UCX_TEST_ASSERT(x2, "ns3: x2 missing");
+    UCX_TEST_ASSERT(!x3, "ns3: x3");
+    UCX_TEST_ASSERT(!x4, "ns3: x4");
+    
+    UCX_TEST_END;
+}

mercurial