src/server/test/webdav.c

branch
webdav
changeset 215
68e824ba4a4f
parent 214
4d7ac67a1c14
child 216
ce2866ec97f6
equal deleted inserted replaced
214:4d7ac67a1c14 215:68e824ba4a4f
36 #include "../webdav/webdav.h" 36 #include "../webdav/webdav.h"
37 #include "../webdav/multistatus.h" 37 #include "../webdav/multistatus.h"
38 38
39 #include "webdav.h" 39 #include "webdav.h"
40 40
41 static int test_init(
42 Session **out_sn,
43 Request **out_rq,
44 WebdavPropfindRequest **out_propfind,
45 const char *xml)
46 {
47 Session *sn = testutil_session();
48 Request *rq = testutil_request(sn->pool, "PROPFIND", "/");
49
50 int error = 0;
51
52 WebdavPropfindRequest *propfind = propfind_parse(
53 sn,
54 rq,
55 xml,
56 strlen(xml),
57 &error);
58
59 if(error) {
60 return 1;
61 }
62
63 if(!propfind || !propfind->properties) {
64 return 1;
65 }
66
67 *out_sn = sn;
68 *out_rq = rq;
69 *out_propfind = propfind;
70 return 0;
71 }
72
73
41 UCX_TEST(test_propfind_parse) { 74 UCX_TEST(test_propfind_parse) {
42 Session *sn = testutil_session(); 75 Session *sn = testutil_session();
43 Request *rq = testutil_request(sn->pool, "PROPFIND", "/"); 76 Request *rq = testutil_request(sn->pool, "PROPFIND", "/");
44 77
45 UCX_TEST_BEGIN 78 UCX_TEST_BEGIN
366 399
367 ucx_buffer_free(b2); 400 ucx_buffer_free(b2);
368 testutil_destroy_session(sn); 401 testutil_destroy_session(sn);
369 402
370 UCX_TEST_END; 403 UCX_TEST_END;
404 }
405
406 UCX_TEST(test_webdav_plist_iterator) {
407 Session *sn;
408 Request *rq;
409 WebdavPropfindRequest *propfind;
410
411 UCX_TEST_BEGIN;
412 UCX_TEST_ASSERT(!test_init(&sn, &rq, &propfind, TEST_PROPFIND1), "init failed");
413
414 WebdavPList *properties = propfind->properties;
415 size_t count = 0;
416
417 WebdavPListIterator i = webdav_plist_iterator(&properties);
418 WebdavPList *cur;
419 while(webdav_plist_iterator_next(&i, &cur)) {
420 switch(i.index) {
421 case 0: {
422 UCX_TEST_ASSERT(!strcmp(cur->property->name, "displayname"), "wrong property 1");
423 break;
424 }
425 case 1: {
426 UCX_TEST_ASSERT(!strcmp(cur->property->name, "getcontentlength"), "wrong property 2");
427 break;
428 }
429 case 2: {
430 UCX_TEST_ASSERT(!strcmp(cur->property->name, "getcontenttype"), "wrong property 3");
431 break;
432 }
433 case 3: {
434 UCX_TEST_ASSERT(!strcmp(cur->property->name, "getlastmodified"), "wrong property 4");
435 break;
436 }
437 case 4: {
438 UCX_TEST_ASSERT(!strcmp(cur->property->name, "resourcetype"), "wrong property 5");
439 break;
440 }
441 case 5: {
442 UCX_TEST_ASSERT(!strcmp(cur->property->name, "getetag"), "wrong property 6");
443 break;
444 }
445 }
446 count++;
447 }
448
449 UCX_TEST_ASSERT(count == propfind->propcount, "wrong count");
450
451
452 UCX_TEST_END;
453 testutil_destroy_session(sn);
371 } 454 }
372 455
373 UCX_TEST(test_msresponse_addproperty) { 456 UCX_TEST(test_msresponse_addproperty) {
374 Session *sn = testutil_session(); 457 Session *sn = testutil_session();
375 Request *rq = testutil_request(sn->pool, "PROPFIND", "/"); 458 Request *rq = testutil_request(sn->pool, "PROPFIND", "/");
500 &backend2 583 &backend2
501 }; 584 };
502 585
503 /* ----------------------------------------------------------------------*/ 586 /* ----------------------------------------------------------------------*/
504 587
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) { 588 UCX_TEST(test_webdav_propfind_init) {
538 Session *sn; 589 Session *sn;
539 Request *rq; 590 Request *rq;
540 WebdavPropfindRequest *propfind; 591 WebdavPropfindRequest *propfind;
541 UCX_TEST_BEGIN; 592 UCX_TEST_BEGIN;
542 UCX_TEST_ASSERT(!backend_test_init(&sn, &rq, &propfind, TEST_PROPFIND1), "init failed"); 593 UCX_TEST_ASSERT(!test_init(&sn, &rq, &propfind, TEST_PROPFIND1), "init failed");
543 594
544 UcxList *requests = NULL; 595 UcxList *requests = NULL;
545 int err = webdav_propfind_init(&backend1, propfind, "/", &requests); 596 int err = webdav_propfind_init(&backend1, propfind, "/", &requests);
546 597
547 UCX_TEST_ASSERT(!err, "webdav_propfind_init failed"); 598 UCX_TEST_ASSERT(!err, "webdav_propfind_init failed");
548 UCX_TEST_ASSERT(requests, "request list is empty"); 599 UCX_TEST_ASSERT(requests, "request list is empty");
549 UCX_TEST_ASSERT(ucx_list_size(requests), "request list has wrong size"); 600 UCX_TEST_ASSERT(ucx_list_size(requests), "request list has wrong size");
550 601
551 WebdavPropfindRequest *p1 = requests->data; 602 WebdavPropfindRequest *p1 = requests->data;
552 WebdavPropfindRequest *p2 = requests->next->data; 603 WebdavPropfindRequest *p2 = requests->next->data;
604
605 // backend1 removes the first property from the plist
606 // backend2 should have one property less
553 607
554 UCX_TEST_ASSERT(p1 && p2, "missing requests objects"); 608 UCX_TEST_ASSERT(p1 && p2, "missing requests objects");
555 UCX_TEST_ASSERT(p1 != p2, "request objects equal"); 609 UCX_TEST_ASSERT(p1 != p2, "request objects equal");
556 UCX_TEST_ASSERT(p1->properties != p2->properties, "plists equal"); 610 UCX_TEST_ASSERT(p1->properties != p2->properties, "plists equal");
557 UCX_TEST_ASSERT(p1->propcount == p2->propcount + 1, "first property not removed"); 611 UCX_TEST_ASSERT(p1->propcount == p2->propcount + 1, "first property not removed");

mercurial