src/server/test/webdav.c

branch
webdav
changeset 216
ce2866ec97f6
parent 215
68e824ba4a4f
child 217
8ed14d76db42
--- a/src/server/test/webdav.c	Sun Dec 29 22:39:35 2019 +0100
+++ b/src/server/test/webdav.c	Mon Dec 30 16:33:20 2019 +0100
@@ -453,6 +453,100 @@
     testutil_destroy_session(sn);
 }
 
+UCX_TEST(test_webdav_plist_iterator_remove_current) {
+    Session *sn;
+    Request *rq;
+    WebdavPropfindRequest *propfind;
+    
+    UCX_TEST_BEGIN;
+    UCX_TEST_ASSERT(!test_init(&sn, &rq, &propfind, TEST_PROPFIND1), "init failed");
+    
+    WebdavPList *properties1 = webdav_plist_clone(sn->pool, propfind->properties);
+    WebdavPList *properties2 = webdav_plist_clone(sn->pool, propfind->properties);
+    WebdavPList *properties3 = webdav_plist_clone(sn->pool, propfind->properties);
+    WebdavPList *properties4 = webdav_plist_clone(sn->pool, propfind->properties);
+    
+    WebdavPListIterator i;
+    WebdavPList *cur;
+    
+    // test removal of first element
+    i = webdav_plist_iterator(&properties1);
+    while(webdav_plist_iterator_next(&i, &cur)) {
+        if(i.index == 0) {
+            webdav_plist_iterator_remove_current(&i);
+        }
+    }
+    
+    UCX_TEST_ASSERT(!properties1->prev, "test1: prev not cleared");
+    UCX_TEST_ASSERT(!strcmp(properties1->property->name, "getcontentlength"), "test1: wrong property");
+    UCX_TEST_ASSERT(!strcmp(properties1->next->property->name, "getcontenttype"), "test1: wrong property 2");
+    UCX_TEST_ASSERT(properties1->next->prev == properties1, "test1: wrong link");
+    
+    // test removal of second element
+    i = webdav_plist_iterator(&properties2);
+    while(webdav_plist_iterator_next(&i, &cur)) {
+        if(i.index == 1) {
+            webdav_plist_iterator_remove_current(&i);
+        }
+    }
+    
+    UCX_TEST_ASSERT(!strcmp(properties2->next->property->name, "getcontenttype"), "test2: wrong property");
+    UCX_TEST_ASSERT(properties2->next->prev == properties2, "test2: wrong link");
+    UCX_TEST_ASSERT(webdav_plist_size(properties2) == 5, "test2: wrong size");
+    
+    // remove last element
+    i = webdav_plist_iterator(&properties3);
+    while(webdav_plist_iterator_next(&i, &cur)) {
+        if(i.index == 5) {
+            webdav_plist_iterator_remove_current(&i);
+        }
+    }
+    
+    UCX_TEST_ASSERT(webdav_plist_size(properties3) == 5, "test3: wrong size");
+    UCX_TEST_ASSERT(!strcmp(properties3->next->next->next->next->property->name, "resourcetype"), "test2: wrong property");
+    
+    // remove all elements
+    i = webdav_plist_iterator(&properties4);
+    while(webdav_plist_iterator_next(&i, &cur)) {
+        webdav_plist_iterator_remove_current(&i);
+        switch(i.index) {
+            case 0: {
+                UCX_TEST_ASSERT(!strcmp(properties4->property->name, "getcontentlength"), "test4: wrong property 2");
+                UCX_TEST_ASSERT(properties4->prev == NULL, "test4: prev not NULL (0)");
+                break;
+            }
+            case 1: {
+                UCX_TEST_ASSERT(!strcmp(properties4->property->name, "getcontenttype"), "test4: wrong property 3");
+                UCX_TEST_ASSERT(properties4->prev == NULL, "test4: prev not NULL (1)");
+                break;
+            }
+            case 2: {
+                UCX_TEST_ASSERT(!strcmp(properties4->property->name, "getlastmodified"), "test4: wrong property 4");
+                UCX_TEST_ASSERT(properties4->prev == NULL, "test4: prev not NULL (2)");
+                break;
+            }
+            case 3: {
+                UCX_TEST_ASSERT(!strcmp(properties4->property->name, "resourcetype"), "test4: wrong property 5");
+                UCX_TEST_ASSERT(properties4->prev == NULL, "test4: prev not NULL (3)");
+                break;
+            }
+            case 4: {
+                UCX_TEST_ASSERT(!strcmp(properties4->property->name, "getetag"), "test4: wrong property 6");
+                UCX_TEST_ASSERT(properties4->prev == NULL, "test4: prev not NULL (4)");
+                break;
+            }
+            default: {
+                UCX_TEST_ASSERT(i.index <= 5, "fail");
+            }
+        }
+    }
+    
+    UCX_TEST_ASSERT(properties4 == NULL, "test4: list not NULL");
+    
+    UCX_TEST_END;
+    testutil_destroy_session(sn);
+}
+
 UCX_TEST(test_msresponse_addproperty) {
     Session *sn = testutil_session();
     Request *rq = testutil_request(sn->pool, "PROPFIND", "/");

mercurial