diff -r 4a6be4f10d5f -r 4d7ac67a1c14 src/server/test/webdav.c --- 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); +}