diff -r 8ed14d76db42 -r 2ba512b284b9 src/server/test/webdav.c --- a/src/server/test/webdav.c Tue Dec 31 10:01:32 2019 +0100 +++ b/src/server/test/webdav.c Tue Dec 31 11:57:02 2019 +0100 @@ -35,17 +35,23 @@ #include "../webdav/requestparser.h" #include "../webdav/webdav.h" #include "../webdav/multistatus.h" +#include "../webdav/operation.h" #include "webdav.h" /* ----------------------------- Test Backends --------------------------*/ +static int backend2_init_called = 0; +static int backend2_propfind_do_called = 0; +static int backend2_propfind_finish_called = 0; + // backend2 static int backend2_propfind_init( WebdavPropfindRequest *propfind, const char *path, WebdavPList **outPList) { + backend2_init_called = 1; return 0; } @@ -56,10 +62,12 @@ WebdavResource *resource, struct stat *s) { + backend2_propfind_do_called = 1; return 0; } static int backend2_propfind_finish(WebdavPropfindRequest *propfind) { + backend2_propfind_finish_called = 1; return 0; } @@ -72,11 +80,19 @@ }; // backend1 + +static int backend1_init_called = 0; +static int backend1_propfind_do_called = 0; +static int backend1_propfind_finish_called = 0; + + static int backend1_propfind_init( WebdavPropfindRequest *propfind, const char *path, WebdavPList **outPList) { + backend1_init_called = 1; + WebdavPList *plist = *outPList; WebdavProperty *p = plist->property; if(!strcmp(p->name, "displayname")) { @@ -96,10 +112,12 @@ WebdavResource *resource, struct stat *s) { + backend1_propfind_do_called = 1; return 0; } static int backend1_propfind_finish(WebdavPropfindRequest *propfind) { + backend1_propfind_finish_called = 1; return 0; } @@ -111,6 +129,15 @@ &backend2 }; +static void reset_backends(void) { + backend1_init_called = 0; + backend1_propfind_do_called = 0; + backend1_propfind_finish_called = 0; + backend2_init_called = 0; + backend2_propfind_do_called = 0; + backend2_propfind_finish_called = 0; +} + /* ----------------------------------------------------------------------*/ @@ -146,6 +173,37 @@ return 0; } +static WebdavOperation* test_propfind_op( + Session **out_sn, + Request **out_rq, + const char *xml) +{ + WebdavPropfindRequest *propfind; + if(test_init(out_sn, out_rq, &propfind, xml)) { + return NULL; + } + + Multistatus *ms = multistatus_response(*out_sn, *out_rq); + if(!ms) { + return NULL; + } + // WebdavResponse is the public interface used by Backends + // for adding resources to the response + WebdavResponse *response = (WebdavResponse*)ms; + + UcxList *requests = NULL; + + // Initialize all Webdav Backends + if(webdav_propfind_init(&backend1, propfind, "/", &requests)) { + return NULL; + } + + return webdav_operation_create( + (*out_sn)->pool, + &backend1, + requests, + response); +} UCX_TEST(test_propfind_parse) { Session *sn = testutil_session(); @@ -681,6 +739,8 @@ } UCX_TEST(test_webdav_propfind_init) { + reset_backends(); + Session *sn; Request *rq; WebdavPropfindRequest *propfind; @@ -705,7 +765,29 @@ UCX_TEST_ASSERT(p1->properties != p2->properties, "plists equal"); UCX_TEST_ASSERT(p1->propcount == p2->propcount + 1, "first property not removed"); + UCX_TEST_ASSERT(backend1_init_called == 1, "backend1 init not called"); + UCX_TEST_ASSERT(backend2_init_called == 1, "backend2 init not called"); + UCX_TEST_END; pool_destroy(sn->pool); } + +UCX_TEST(test_webdav_op_propfind_begin) { + reset_backends(); + + Session *sn; + Request *rq; + + UCX_TEST_BEGIN; + WebdavOperation *op = test_propfind_op(&sn, &rq, TEST_PROPFIND1); + UCX_TEST_ASSERT(op, "WebdavOperation not created"); + + int err = webdav_op_propfind_begin(op, "/", NULL, NULL); + UCX_TEST_ASSERT(err == 0, "err not 0"); + UCX_TEST_ASSERT(backend1_propfind_do_called == 1, "backend1 propfind_do not called"); + UCX_TEST_ASSERT(backend2_propfind_do_called == 1, "backend2 propfind_do not called"); + + + UCX_TEST_END; +}