src/server/test/webdav.c

branch
webdav
changeset 215
68e824ba4a4f
parent 214
4d7ac67a1c14
child 216
ce2866ec97f6
--- a/src/server/test/webdav.c	Sun Dec 29 21:43:14 2019 +0100
+++ b/src/server/test/webdav.c	Sun Dec 29 22:39:35 2019 +0100
@@ -38,6 +38,39 @@
 
 #include "webdav.h"
 
+static int test_init(
+        Session **out_sn,
+        Request **out_rq,
+        WebdavPropfindRequest **out_propfind,
+        const char *xml)
+{
+    Session *sn = testutil_session();
+    Request *rq = testutil_request(sn->pool, "PROPFIND", "/");
+    
+    int error = 0;
+    
+    WebdavPropfindRequest *propfind = propfind_parse(
+            sn,
+            rq,
+            xml,
+            strlen(xml),
+            &error);
+    
+    if(error) {
+        return 1;
+    }
+    
+    if(!propfind || !propfind->properties) {
+        return 1;
+    }
+    
+    *out_sn = sn;
+    *out_rq = rq;
+    *out_propfind = propfind;
+    return 0;
+}
+
+
 UCX_TEST(test_propfind_parse) {
     Session *sn = testutil_session();
     Request *rq = testutil_request(sn->pool, "PROPFIND", "/");
@@ -370,6 +403,56 @@
     UCX_TEST_END;
 }
 
+UCX_TEST(test_webdav_plist_iterator) {
+    Session *sn;
+    Request *rq;
+    WebdavPropfindRequest *propfind;
+    
+    UCX_TEST_BEGIN;
+    UCX_TEST_ASSERT(!test_init(&sn, &rq, &propfind, TEST_PROPFIND1), "init failed");
+    
+    WebdavPList *properties = propfind->properties;
+    size_t count = 0;
+    
+    WebdavPListIterator i = webdav_plist_iterator(&properties);
+    WebdavPList *cur;
+    while(webdav_plist_iterator_next(&i, &cur)) {
+        switch(i.index) {
+            case 0: {
+                UCX_TEST_ASSERT(!strcmp(cur->property->name, "displayname"), "wrong property 1");
+                break;
+            }
+            case 1: {
+                UCX_TEST_ASSERT(!strcmp(cur->property->name, "getcontentlength"), "wrong property 2");
+                break;
+            }
+            case 2: {
+                UCX_TEST_ASSERT(!strcmp(cur->property->name, "getcontenttype"), "wrong property 3");
+                break;
+            }
+            case 3: {
+                UCX_TEST_ASSERT(!strcmp(cur->property->name, "getlastmodified"), "wrong property 4");
+                break;
+            }
+            case 4: {
+                UCX_TEST_ASSERT(!strcmp(cur->property->name, "resourcetype"), "wrong property 5");
+                break;
+            }
+            case 5: {
+                UCX_TEST_ASSERT(!strcmp(cur->property->name, "getetag"), "wrong property 6");
+                break;
+            }
+        }
+        count++;
+    }
+    
+    UCX_TEST_ASSERT(count == propfind->propcount, "wrong count");
+    
+    
+    UCX_TEST_END;
+    testutil_destroy_session(sn);
+}
+
 UCX_TEST(test_msresponse_addproperty) {
     Session *sn = testutil_session();
     Request *rq = testutil_request(sn->pool, "PROPFIND", "/");
@@ -502,44 +585,12 @@
 
 /* ----------------------------------------------------------------------*/
 
-static int backend_test_init(
-        Session **out_sn,
-        Request **out_rq,
-        WebdavPropfindRequest **out_propfind,
-        const char *xml)
-{
-    Session *sn = testutil_session();
-    Request *rq = testutil_request(sn->pool, "PROPFIND", "/");
-    
-    int error = 0;
-    
-    WebdavPropfindRequest *propfind = propfind_parse(
-            sn,
-            rq,
-            xml,
-            strlen(xml),
-            &error);
-    
-    if(error) {
-        return 1;
-    }
-    
-    if(!propfind || !propfind->properties) {
-        return 1;
-    }
-    
-    *out_sn = sn;
-    *out_rq = rq;
-    *out_propfind = propfind;
-    return 0;
-}
-
 UCX_TEST(test_webdav_propfind_init) {
     Session *sn;
     Request *rq;
     WebdavPropfindRequest *propfind;
     UCX_TEST_BEGIN;
-    UCX_TEST_ASSERT(!backend_test_init(&sn, &rq, &propfind, TEST_PROPFIND1), "init failed");
+    UCX_TEST_ASSERT(!test_init(&sn, &rq, &propfind, TEST_PROPFIND1), "init failed");
     
     UcxList *requests = NULL;
     int err = webdav_propfind_init(&backend1, propfind, "/", &requests);
@@ -551,6 +602,9 @@
     WebdavPropfindRequest *p1 = requests->data;
     WebdavPropfindRequest *p2 = requests->next->data;
     
+    // backend1 removes the first property from the plist
+    // backend2 should have one property less 
+    
     UCX_TEST_ASSERT(p1 && p2, "missing requests objects");
     UCX_TEST_ASSERT(p1 != p2, "request objects equal");
     UCX_TEST_ASSERT(p1->properties != p2->properties, "plists equal");

mercurial