add tests for webdav_propfind_init and fix wrong backend call webdav

Sun, 29 Dec 2019 21:43:14 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 29 Dec 2019 21:43:14 +0100
branch
webdav
changeset 214
4d7ac67a1c14
parent 213
4a6be4f10d5f
child 215
68e824ba4a4f

add tests for webdav_propfind_init and fix wrong backend call

src/server/test/main.c file | annotate | diff | comparison | revisions
src/server/test/webdav.c file | annotate | diff | comparison | revisions
src/server/test/webdav.h file | annotate | diff | comparison | revisions
src/server/webdav/webdav.c file | annotate | diff | comparison | revisions
--- a/src/server/test/main.c	Sun Dec 29 21:06:02 2019 +0100
+++ b/src/server/test/main.c	Sun Dec 29 21:43:14 2019 +0100
@@ -67,6 +67,7 @@
     ucx_test_register(suite, test_lock_parse);
     ucx_test_register(suite, test_rqbody2buffer);
     ucx_test_register(suite, test_msresponse_addproperty);
+    ucx_test_register(suite, test_webdav_propfind_init);
     
     // run tests
     ucx_test_run(suite, stdout);
--- a/src/server/test/webdav.c	Sun Dec 29 21:06:02 2019 +0100
+++ b/src/server/test/webdav.c	Sun Dec 29 21:43:14 2019 +0100
@@ -426,3 +426,137 @@
     
     UCX_TEST_END;
 }
+
+/* ----------------------------- Test Backends --------------------------*/
+
+// backend2
+static int backend2_propfind_init(
+        WebdavPropfindRequest *propfind,
+        const char *path,
+        WebdavPList **outPList)
+{
+    return 0;
+}
+
+static int backend2_propfind_do(
+            WebdavPropfindRequest *propfind,
+            WebdavResponse *response,
+            VFS_DIR parent,
+            const char *path,
+            struct stat *s)
+{
+    return 0;
+}
+
+static int backend2_propfind_finish(WebdavPropfindRequest *propfind) {
+    return 0;
+}
+
+static WebdavBackend backend2 = {
+    backend2_propfind_init,
+    backend2_propfind_do,
+    backend2_propfind_finish,
+    0,
+    NULL
+};
+
+// backend1
+static int backend1_propfind_init(
+        WebdavPropfindRequest *propfind,
+        const char *path,
+        WebdavPList **outPList)
+{
+    WebdavPList *plist = *outPList;
+    WebdavProperty *p = plist->property;
+    if(!strcmp(p->name, "displayname")) {
+        plist->next->prev = NULL;
+        *outPList = plist->next; // remove first item from plist
+    } else {
+        return 1;
+    }
+    
+    return 0;
+}
+
+static int backend1_propfind_do(
+            WebdavPropfindRequest *propfind,
+            WebdavResponse *response,
+            VFS_DIR parent,
+            const char *path,
+            struct stat *s)
+{
+    return 0;
+}
+
+static int backend1_propfind_finish(WebdavPropfindRequest *propfind) {
+    return 0;
+}
+
+WebdavBackend backend1 = {
+    backend1_propfind_init,
+    backend1_propfind_do,
+    backend1_propfind_finish,
+    0,
+    &backend2
+};
+
+/* ----------------------------------------------------------------------*/
+
+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");
+    
+    UcxList *requests = NULL;
+    int err = webdav_propfind_init(&backend1, propfind, "/", &requests);
+    
+    UCX_TEST_ASSERT(!err, "webdav_propfind_init failed");
+    UCX_TEST_ASSERT(requests, "request list is empty");
+    UCX_TEST_ASSERT(ucx_list_size(requests), "request list has wrong size");
+    
+    WebdavPropfindRequest *p1 = requests->data;
+    WebdavPropfindRequest *p2 = requests->next->data;
+    
+    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");
+    UCX_TEST_ASSERT(p1->propcount == p2->propcount + 1, "first property not removed");
+    
+    UCX_TEST_END;
+    
+    pool_destroy(sn->pool);
+}
--- a/src/server/test/webdav.h	Sun Dec 29 21:06:02 2019 +0100
+++ b/src/server/test/webdav.h	Sun Dec 29 21:43:14 2019 +0100
@@ -46,7 +46,7 @@
 
 UCX_TEST(test_msresponse_addproperty);
 
-UCX_TEST(test_msresponse_addproperty);
+UCX_TEST(test_webdav_propfind_init);
 
 /* --------------------------- PROPFIND --------------------------- */
 
--- a/src/server/webdav/webdav.c	Sun Dec 29 21:06:02 2019 +0100
+++ b/src/server/webdav/webdav.c	Sun Dec 29 21:43:14 2019 +0100
@@ -306,7 +306,7 @@
         
         // run init: this can generate a new properties list (newProp)
         //           which will be passed to the next backend
-        if(dav->propfind_init(pReq, path, &newProp)) {
+        if(davList->propfind_init(pReq, path, &newProp)) {
             return REQ_ABORTED;
         }
         
@@ -326,19 +326,19 @@
  * of all backends
  */
 int webdav_propfind_do(
-        WebdavBackend *webdav,
+        WebdavBackend *dav,
         UcxList *requests,
         WebdavResponse *response,
         VFS_DIR parent,
         const char *path,
         struct stat *s)
 {
-    while(webdav && requests) {
-        if(webdav->propfind_do(requests->data, response, parent, path, s)) {
+    while(dav && requests) {
+        if(dav->propfind_do(requests->data, response, parent, path, s)) {
             return REQ_ABORTED;
         }
         
-        webdav = webdav->next;
+        dav = dav->next;
         requests = requests->next;
     }
     return REQ_PROCEED;
@@ -347,14 +347,14 @@
 /*
  * Executes propfind_finish for each Backend
  */
-int webdav_propfind_finish(WebdavBackend *webdav, UcxList *requests) {
+int webdav_propfind_finish(WebdavBackend *dav, UcxList *requests) {
     int ret = REQ_PROCEED;
-    while(webdav && requests) {
-        if(webdav->propfind_finish(requests->data)) {
+    while(dav && requests) {
+        if(dav->propfind_finish(requests->data)) {
             ret = REQ_ABORTED;
         }
         
-        webdav = webdav->next;
+        dav = dav->next;
         requests = requests->next;
     }
     return ret;

mercurial