src/server/test/webdav.c

branch
webdav
changeset 214
4d7ac67a1c14
parent 212
d7e7ea9c6bc6
child 215
68e824ba4a4f
equal deleted inserted replaced
213:4a6be4f10d5f 214:4d7ac67a1c14
424 UCX_TEST_ASSERT(ucx_list_size(r->errors->next->begin) == 4, "403 list size != 4"); 424 UCX_TEST_ASSERT(ucx_list_size(r->errors->next->begin) == 4, "403 list size != 4");
425 UCX_TEST_ASSERT(ucx_list_size(r->errors->next->next->begin) == 1, "500 list size != 1"); 425 UCX_TEST_ASSERT(ucx_list_size(r->errors->next->next->begin) == 1, "500 list size != 1");
426 426
427 UCX_TEST_END; 427 UCX_TEST_END;
428 } 428 }
429
430 /* ----------------------------- Test Backends --------------------------*/
431
432 // backend2
433 static int backend2_propfind_init(
434 WebdavPropfindRequest *propfind,
435 const char *path,
436 WebdavPList **outPList)
437 {
438 return 0;
439 }
440
441 static int backend2_propfind_do(
442 WebdavPropfindRequest *propfind,
443 WebdavResponse *response,
444 VFS_DIR parent,
445 const char *path,
446 struct stat *s)
447 {
448 return 0;
449 }
450
451 static int backend2_propfind_finish(WebdavPropfindRequest *propfind) {
452 return 0;
453 }
454
455 static WebdavBackend backend2 = {
456 backend2_propfind_init,
457 backend2_propfind_do,
458 backend2_propfind_finish,
459 0,
460 NULL
461 };
462
463 // backend1
464 static int backend1_propfind_init(
465 WebdavPropfindRequest *propfind,
466 const char *path,
467 WebdavPList **outPList)
468 {
469 WebdavPList *plist = *outPList;
470 WebdavProperty *p = plist->property;
471 if(!strcmp(p->name, "displayname")) {
472 plist->next->prev = NULL;
473 *outPList = plist->next; // remove first item from plist
474 } else {
475 return 1;
476 }
477
478 return 0;
479 }
480
481 static int backend1_propfind_do(
482 WebdavPropfindRequest *propfind,
483 WebdavResponse *response,
484 VFS_DIR parent,
485 const char *path,
486 struct stat *s)
487 {
488 return 0;
489 }
490
491 static int backend1_propfind_finish(WebdavPropfindRequest *propfind) {
492 return 0;
493 }
494
495 WebdavBackend backend1 = {
496 backend1_propfind_init,
497 backend1_propfind_do,
498 backend1_propfind_finish,
499 0,
500 &backend2
501 };
502
503 /* ----------------------------------------------------------------------*/
504
505 static int backend_test_init(
506 Session **out_sn,
507 Request **out_rq,
508 WebdavPropfindRequest **out_propfind,
509 const char *xml)
510 {
511 Session *sn = testutil_session();
512 Request *rq = testutil_request(sn->pool, "PROPFIND", "/");
513
514 int error = 0;
515
516 WebdavPropfindRequest *propfind = propfind_parse(
517 sn,
518 rq,
519 xml,
520 strlen(xml),
521 &error);
522
523 if(error) {
524 return 1;
525 }
526
527 if(!propfind || !propfind->properties) {
528 return 1;
529 }
530
531 *out_sn = sn;
532 *out_rq = rq;
533 *out_propfind = propfind;
534 return 0;
535 }
536
537 UCX_TEST(test_webdav_propfind_init) {
538 Session *sn;
539 Request *rq;
540 WebdavPropfindRequest *propfind;
541 UCX_TEST_BEGIN;
542 UCX_TEST_ASSERT(!backend_test_init(&sn, &rq, &propfind, TEST_PROPFIND1), "init failed");
543
544 UcxList *requests = NULL;
545 int err = webdav_propfind_init(&backend1, propfind, "/", &requests);
546
547 UCX_TEST_ASSERT(!err, "webdav_propfind_init failed");
548 UCX_TEST_ASSERT(requests, "request list is empty");
549 UCX_TEST_ASSERT(ucx_list_size(requests), "request list has wrong size");
550
551 WebdavPropfindRequest *p1 = requests->data;
552 WebdavPropfindRequest *p2 = requests->next->data;
553
554 UCX_TEST_ASSERT(p1 && p2, "missing requests objects");
555 UCX_TEST_ASSERT(p1 != p2, "request objects equal");
556 UCX_TEST_ASSERT(p1->properties != p2->properties, "plists equal");
557 UCX_TEST_ASSERT(p1->propcount == p2->propcount + 1, "first property not removed");
558
559 UCX_TEST_END;
560
561 pool_destroy(sn->pool);
562 }

mercurial