| 343 ZERO(&p3, sizeof(WebdavProperty)); |
343 ZERO(&p3, sizeof(WebdavProperty)); |
| 344 int r; |
344 int r; |
| 345 |
345 |
| 346 r = webdav_plist_add(sn->pool, &begin, &end, &p1); |
346 r = webdav_plist_add(sn->pool, &begin, &end, &p1); |
| 347 |
347 |
| 348 UCX_TEST_ASSERT(r == 0, "add 1 failed"); |
348 CX_TEST_ASSERT(r == 0); |
| 349 UCX_TEST_ASSERT(begin && end, "ptrs are NULL"); |
349 CX_TEST_ASSERT(begin && end); |
| 350 UCX_TEST_ASSERT(begin == end, "begin != end"); |
350 CX_TEST_ASSERT(begin == end); |
| 351 UCX_TEST_ASSERT(begin->prev == NULL, "begin->prev not NULL"); |
351 CX_TEST_ASSERT(begin->prev == NULL); |
| 352 UCX_TEST_ASSERT(begin->next == NULL, "begin->next not NULL"); |
352 CX_TEST_ASSERT(begin->next == NULL); |
| 353 |
353 |
| 354 r = webdav_plist_add(sn->pool, &begin, &end, &p2); |
354 r = webdav_plist_add(sn->pool, &begin, &end, &p2); |
| 355 |
355 |
| 356 UCX_TEST_ASSERT(r == 0, "add 2 failed"); |
356 CX_TEST_ASSERT(r == 0); |
| 357 UCX_TEST_ASSERT(begin && end, "add2: ptrs are NULL"); |
357 CX_TEST_ASSERT(begin && end); |
| 358 UCX_TEST_ASSERT(begin->next, "begin->next is NULL"); |
358 CX_TEST_ASSERT(begin->next); |
| 359 UCX_TEST_ASSERT(begin->next == end, "begin->next != end"); |
359 CX_TEST_ASSERT(begin->next == end); |
| 360 UCX_TEST_ASSERT(end->prev = begin, "end->prev != begin"); |
360 CX_TEST_ASSERT(end->prev = begin); |
| 361 UCX_TEST_ASSERT(begin->prev == NULL, "add2: begin->prev not NULL"); |
361 CX_TEST_ASSERT(begin->prev == NULL); |
| 362 UCX_TEST_ASSERT(end->next == NULL, "add2: end->next not NULL"); |
362 CX_TEST_ASSERT(end->next == NULL); |
| 363 |
363 |
| 364 r = webdav_plist_add(sn->pool, &begin, &end, &p3); |
364 r = webdav_plist_add(sn->pool, &begin, &end, &p3); |
| 365 |
365 |
| 366 UCX_TEST_ASSERT(r == 0, "add 3 failed"); |
366 CX_TEST_ASSERT(r == 0); |
| 367 UCX_TEST_ASSERT(begin && end, "add3: ptrs are NULL"); |
367 CX_TEST_ASSERT(begin && end); |
| 368 UCX_TEST_ASSERT(begin->next == end->prev, "begin->next != end->prev"); |
368 CX_TEST_ASSERT(begin->next == end->prev); |
| 369 |
369 |
| 370 UCX_TEST_END; |
370 } |
| 371 |
371 |
| 372 testutil_destroy_session(sn); |
372 testutil_destroy_session(sn); |
| 373 } |
373 } |
| 374 |
374 |
| 375 UCX_TEST(test_webdav_plist_size) { |
375 CX_TEST(test_webdav_plist_size) { |
| 376 Session *sn = testutil_session(); |
376 Session *sn = testutil_session(); |
| 377 |
377 |
| 378 UCX_TEST_BEGIN; |
378 CX_TEST_DO { |
| 379 |
379 |
| 380 WebdavPList *begin = NULL; |
380 WebdavPList *begin = NULL; |
| 381 WebdavPList *end = NULL; |
381 WebdavPList *end = NULL; |
| 382 |
382 |
| 383 WebdavProperty p1, p2, p3; |
383 WebdavProperty p1, p2, p3; |
| 384 ZERO(&p1, sizeof(WebdavProperty)); |
384 ZERO(&p1, sizeof(WebdavProperty)); |
| 385 ZERO(&p2, sizeof(WebdavProperty)); |
385 ZERO(&p2, sizeof(WebdavProperty)); |
| 386 ZERO(&p3, sizeof(WebdavProperty)); |
386 ZERO(&p3, sizeof(WebdavProperty)); |
| 387 int r; |
387 int r; |
| 388 |
388 |
| 389 UCX_TEST_ASSERT(webdav_plist_size(begin) == 0, "size != 0"); |
389 CX_TEST_ASSERT(webdav_plist_size(begin) == 0); |
| 390 r = webdav_plist_add(sn->pool, &begin, &end, &p1); |
390 r = webdav_plist_add(sn->pool, &begin, &end, &p1); |
| 391 UCX_TEST_ASSERT(webdav_plist_size(begin) == 1, "size != 1"); |
391 CX_TEST_ASSERT(webdav_plist_size(begin) == 1); |
| 392 r = webdav_plist_add(sn->pool, &begin, &end, &p2); |
392 r = webdav_plist_add(sn->pool, &begin, &end, &p2); |
| 393 UCX_TEST_ASSERT(webdav_plist_size(begin) == 2, "size != 2"); |
393 CX_TEST_ASSERT(webdav_plist_size(begin) == 2); |
| 394 r = webdav_plist_add(sn->pool, &begin, &end, &p3); |
394 r = webdav_plist_add(sn->pool, &begin, &end, &p3); |
| 395 UCX_TEST_ASSERT(webdav_plist_size(begin) == 3, "size != 3"); |
395 CX_TEST_ASSERT(webdav_plist_size(begin) == 3); |
| 396 |
396 |
| 397 UCX_TEST_END; |
397 } |
| 398 |
398 |
| 399 testutil_destroy_session(sn); |
399 testutil_destroy_session(sn); |
| 400 } |
400 } |
| 401 |
401 |
| 402 UCX_TEST(test_propfind_parse) { |
402 CX_TEST(test_propfind_parse) { |
| 403 Session *sn = testutil_session(); |
403 Session *sn = testutil_session(); |
| 404 Request *rq = testutil_request(sn->pool, "PROPFIND", "/"); |
404 Request *rq = testutil_request(sn->pool, "PROPFIND", "/"); |
| 405 |
405 |
| 406 UCX_TEST_BEGIN |
406 CX_TEST_DO { |
| 407 |
407 |
| 408 int error = 0; |
408 int error = 0; |
| 409 |
409 |
| 410 // |
410 // |
| 411 // ----------------- TEST_PROPFIND1 ----------------- |
411 // ----------------- TEST_PROPFIND1 ----------------- |
| 412 // test basic propfind request |
412 // test basic propfind request |
| 413 WebdavPropfindRequest *p1 = propfind_parse( |
413 WebdavPropfindRequest *p1 = propfind_parse( |
| 414 sn, |
414 sn, |
| 415 rq, |
415 rq, |
| 416 TEST_PROPFIND1, |
416 TEST_PROPFIND1, |
| 417 strlen(TEST_PROPFIND1), |
417 strlen(TEST_PROPFIND1), |
| 418 &error); |
418 &error); |
| 419 |
419 |
| 420 UCX_TEST_ASSERT(p1, "p1 is NULL"); |
420 CX_TEST_ASSERT(p1); |
| 421 UCX_TEST_ASSERT(p1->properties, "p1: no props"); |
421 CX_TEST_ASSERT(p1->properties); |
| 422 UCX_TEST_ASSERT(!p1->allprop, "p1: allprop is TRUE"); |
422 CX_TEST_ASSERT(!p1->allprop); |
| 423 UCX_TEST_ASSERT(!p1->propname, "p1: propname is TRUE"); |
423 CX_TEST_ASSERT(!p1->propname); |
| 424 UCX_TEST_ASSERT(p1->propcount == 6, "p1: wrong propcount"); |
424 CX_TEST_ASSERT(p1->propcount == 6); |
| 425 |
425 |
| 426 // property 1: DAV:displayname |
426 // property 1: DAV:displayname |
| 427 WebdavPList *elm = p1->properties; |
427 WebdavPList *elm = p1->properties; |
| 428 UCX_TEST_ASSERT( |
428 CX_TEST_ASSERT( |
| 429 !strcmp(elm->property->name, "displayname"), |
429 !strcmp(elm->property->name, "displayname")); |
| 430 "p1: property 1 has wrong name"); |
430 CX_TEST_ASSERT( |
| 431 UCX_TEST_ASSERT( |
431 !strcmp((char*)elm->property->namespace->href, "DAV:")); |
| 432 !strcmp((char*)elm->property->namespace->href, "DAV:"), |
432 |
| 433 "p1: property 1 has wrong namespace"); |
433 // property 2: DAV:getcontentlength |
| 434 |
434 elm = elm->next; |
| 435 // property 2: DAV:getcontentlength |
435 CX_TEST_ASSERT(elm); |
| 436 elm = elm->next; |
436 CX_TEST_ASSERT( |
| 437 UCX_TEST_ASSERT(elm, "p1: property 2 missing"); |
437 !strcmp(elm->property->name, "getcontentlength")); |
| 438 UCX_TEST_ASSERT( |
438 CX_TEST_ASSERT( |
| 439 !strcmp(elm->property->name, "getcontentlength"), |
439 !strcmp((char*)elm->property->namespace->href, "DAV:")); |
| 440 "p1: property 2 has wrong name"); |
440 |
| 441 UCX_TEST_ASSERT( |
441 elm = elm->next; |
| 442 !strcmp((char*)elm->property->namespace->href, "DAV:"), |
442 CX_TEST_ASSERT(elm); |
| 443 "p1: property 2 has wrong namespace"); |
443 elm = elm->next; |
| 444 |
444 CX_TEST_ASSERT(elm); |
| 445 elm = elm->next; |
445 elm = elm->next; |
| 446 UCX_TEST_ASSERT(elm, "p1: property 3 missing"); |
446 CX_TEST_ASSERT(elm); |
| 447 elm = elm->next; |
447 |
| 448 UCX_TEST_ASSERT(elm, "p1: property 4 missing"); |
448 // property 6: DAV:getetag |
| 449 elm = elm->next; |
449 elm = elm->next; |
| 450 UCX_TEST_ASSERT(elm, "p1: property 5 missing"); |
450 CX_TEST_ASSERT(elm); |
| 451 |
451 CX_TEST_ASSERT( |
| 452 // property 6: DAV:getetag |
452 !strcmp(elm->property->name, "getetag")); |
| 453 elm = elm->next; |
453 CX_TEST_ASSERT( |
| 454 UCX_TEST_ASSERT(elm, "p1: property 6 missing"); |
454 !strcmp((char*)elm->property->namespace->href, "DAV:")); |
| 455 UCX_TEST_ASSERT( |
455 CX_TEST_ASSERT(!elm->next); |
| 456 !strcmp(elm->property->name, "getetag"), |
456 |
| 457 "p1: property 6 has wrong name"); |
457 // |
| 458 UCX_TEST_ASSERT( |
458 // ----------------- TEST_PROPFIND2 ----------------- |
| 459 !strcmp((char*)elm->property->namespace->href, "DAV:"), |
459 // test with multiple namespaces |
| 460 "p1: property 6 has wrong namespace"); |
460 WebdavPropfindRequest *p2 = propfind_parse( |
| 461 UCX_TEST_ASSERT(!elm->next, "p1: should not have property 7"); |
461 sn, |
| 462 |
462 rq, |
| 463 // |
463 TEST_PROPFIND2, |
| 464 // ----------------- TEST_PROPFIND2 ----------------- |
464 strlen(TEST_PROPFIND2), |
| 465 // test with multiple namespaces |
465 &error); |
| 466 WebdavPropfindRequest *p2 = propfind_parse( |
466 |
| 467 sn, |
467 CX_TEST_ASSERT(p2); |
| 468 rq, |
468 CX_TEST_ASSERT(p2->properties); |
| 469 TEST_PROPFIND2, |
469 CX_TEST_ASSERT(!p2->allprop); |
| 470 strlen(TEST_PROPFIND2), |
470 CX_TEST_ASSERT(!p2->propname); |
| 471 &error); |
471 |
| 472 |
472 // property 1: DAV:resourcetype |
| 473 UCX_TEST_ASSERT(p2, "p2 is NULL"); |
473 elm = p2->properties; |
| 474 UCX_TEST_ASSERT(p2->properties, "p2: no props"); |
474 CX_TEST_ASSERT( |
| 475 UCX_TEST_ASSERT(!p2->allprop, "p2: allprop is TRUE"); |
475 !strcmp(elm->property->name, "resourcetype")); |
| 476 UCX_TEST_ASSERT(!p2->propname, "p2: propname is TRUE"); |
476 CX_TEST_ASSERT( |
| 477 |
477 !strcmp((char*)elm->property->namespace->href, "DAV:")); |
| 478 // property 1: DAV:resourcetype |
478 |
| 479 elm = p2->properties; |
479 // property 2: X:testprop |
| 480 UCX_TEST_ASSERT( |
480 elm = elm->next; |
| 481 !strcmp(elm->property->name, "resourcetype"), |
481 CX_TEST_ASSERT(elm); |
| 482 "p2: property 1 has wrong name"); |
482 CX_TEST_ASSERT( |
| 483 UCX_TEST_ASSERT( |
483 !strcmp(elm->property->name, "testprop")); |
| 484 !strcmp((char*)elm->property->namespace->href, "DAV:"), |
484 CX_TEST_ASSERT( |
| 485 "p2: property 1 has wrong namespace"); |
485 !strcmp((char*)elm->property->namespace->href, "http://example.com/")); |
| 486 |
486 |
| 487 // property 2: X:testprop |
487 // property 3: X:name |
| 488 elm = elm->next; |
488 elm = elm->next; |
| 489 UCX_TEST_ASSERT(elm, "p2: property 2 missing"); |
489 CX_TEST_ASSERT(elm); |
| 490 UCX_TEST_ASSERT( |
490 CX_TEST_ASSERT( |
| 491 !strcmp(elm->property->name, "testprop"), |
491 !strcmp(elm->property->name, "name")); |
| 492 "p2: property 2 has wrong name"); |
492 CX_TEST_ASSERT( |
| 493 UCX_TEST_ASSERT( |
493 !strcmp((char*)elm->property->namespace->href, "http://example.com/")); |
| 494 !strcmp((char*)elm->property->namespace->href, "http://example.com/"), |
494 |
| 495 "p2: property 2 has wrong namespace"); |
495 // property 4: Z:testprop |
| 496 |
496 elm = elm->next; |
| 497 // property 3: X:name |
497 CX_TEST_ASSERT(elm); |
| 498 elm = elm->next; |
498 CX_TEST_ASSERT( |
| 499 UCX_TEST_ASSERT(elm, "p2: property 3 missing"); |
499 !strcmp(elm->property->name, "testprop")); |
| 500 UCX_TEST_ASSERT( |
500 CX_TEST_ASSERT( |
| 501 !strcmp(elm->property->name, "name"), |
501 !strcmp((char*)elm->property->namespace->href, "testns")); |
| 502 "p2: property 3 has wrong name"); |
502 |
| 503 UCX_TEST_ASSERT( |
503 |
| 504 !strcmp((char*)elm->property->namespace->href, "http://example.com/"), |
504 // |
| 505 "p2: property 3 has wrong namespace"); |
505 // ----------------- TEST_PROPFIND3 ----------------- |
| 506 |
506 // test allprop |
| 507 // property 4: Z:testprop |
507 WebdavPropfindRequest *p3 = propfind_parse(sn, rq, TEST_PROPFIND3, strlen(TEST_PROPFIND3), &error); |
| 508 elm = elm->next; |
508 |
| 509 UCX_TEST_ASSERT(elm, "p2: property 4 missing"); |
509 CX_TEST_ASSERT(p3); |
| 510 UCX_TEST_ASSERT( |
510 CX_TEST_ASSERT(!p3->properties); |
| 511 !strcmp(elm->property->name, "testprop"), |
511 CX_TEST_ASSERT(p3->allprop); |
| 512 "p2: property 4 has wrong name"); |
512 CX_TEST_ASSERT(!p3->propname); |
| 513 UCX_TEST_ASSERT( |
513 CX_TEST_ASSERT(p3->propcount == 0); |
| 514 !strcmp((char*)elm->property->namespace->href, "testns"), |
514 |
| 515 "p2: property 4 has wrong namespace"); |
515 |
| 516 |
516 // |
| 517 |
517 // ----------------- TEST_PROPFIND4 ----------------- |
| 518 // |
518 // test propname |
| 519 // ----------------- TEST_PROPFIND3 ----------------- |
519 WebdavPropfindRequest *p4 = propfind_parse(sn, rq, TEST_PROPFIND4, strlen(TEST_PROPFIND4), &error); |
| 520 // test allprop |
520 |
| 521 WebdavPropfindRequest *p3 = propfind_parse(sn, rq, TEST_PROPFIND3, strlen(TEST_PROPFIND3), &error); |
521 CX_TEST_ASSERT(p4); |
| 522 |
522 CX_TEST_ASSERT(!p4->properties); |
| 523 UCX_TEST_ASSERT(p3, "p3 is NULL"); |
523 CX_TEST_ASSERT(!p4->allprop); |
| 524 UCX_TEST_ASSERT(!p3->properties, "p2: has props"); |
524 CX_TEST_ASSERT(p4->propname); |
| 525 UCX_TEST_ASSERT(p3->allprop, "p2: allprop is FALSE"); |
525 |
| 526 UCX_TEST_ASSERT(!p3->propname, "p2: propname is TRUE"); |
526 |
| 527 UCX_TEST_ASSERT(p3->propcount == 0, "p2: wrong propcount"); |
527 // |
| 528 |
528 // ----------------- TEST_PROPFIND5 ----------------- |
| 529 |
529 // test duplicate check |
| 530 // |
530 WebdavPropfindRequest *p5 = propfind_parse(sn, rq, TEST_PROPFIND5, strlen(TEST_PROPFIND5), &error); |
| 531 // ----------------- TEST_PROPFIND4 ----------------- |
531 |
| 532 // test propname |
532 CX_TEST_ASSERT(p5); |
| 533 WebdavPropfindRequest *p4 = propfind_parse(sn, rq, TEST_PROPFIND4, strlen(TEST_PROPFIND4), &error); |
533 CX_TEST_ASSERT(p5->properties); |
| 534 |
534 CX_TEST_ASSERT(!p5->allprop); |
| 535 UCX_TEST_ASSERT(p4, "p4 is NULL"); |
535 CX_TEST_ASSERT(!p5->propname); |
| 536 UCX_TEST_ASSERT(!p4->properties, "p2: has props"); |
536 CX_TEST_ASSERT(p5->propcount == 4); |
| 537 UCX_TEST_ASSERT(!p4->allprop, "p2: allprop is TRUE"); |
537 |
| 538 UCX_TEST_ASSERT(p4->propname, "p2: propname is FALSE"); |
538 // property 1: DAV:displayname |
| 539 |
539 elm = p5->properties; |
| 540 |
540 CX_TEST_ASSERT(elm); |
| 541 // |
541 CX_TEST_ASSERT( |
| 542 // ----------------- TEST_PROPFIND5 ----------------- |
542 !strcmp(elm->property->name, "displayname")); |
| 543 // test duplicate check |
543 CX_TEST_ASSERT( |
| 544 WebdavPropfindRequest *p5 = propfind_parse(sn, rq, TEST_PROPFIND5, strlen(TEST_PROPFIND5), &error); |
544 !strcmp((char*)elm->property->namespace->href, "DAV:")); |
| 545 |
545 |
| 546 UCX_TEST_ASSERT(p5, "p5 is NULL"); |
546 elm = elm->next; |
| 547 UCX_TEST_ASSERT(p5->properties, "p5: no props"); |
547 CX_TEST_ASSERT(elm); |
| 548 UCX_TEST_ASSERT(!p5->allprop, "p5: allprop is TRUE"); |
548 elm = elm->next; |
| 549 UCX_TEST_ASSERT(!p5->propname, "p5: propname is TRUE"); |
549 CX_TEST_ASSERT(elm); |
| 550 UCX_TEST_ASSERT(p5->propcount == 4, "p5: wrong propcount"); |
550 |
| 551 |
551 // property 4: DAV:resourcetype |
| 552 // property 1: DAV:displayname |
552 elm = elm->next; |
| 553 elm = p5->properties; |
553 CX_TEST_ASSERT(elm); |
| 554 UCX_TEST_ASSERT(elm, "p5: property 1 missing"); |
554 CX_TEST_ASSERT( |
| 555 UCX_TEST_ASSERT( |
555 !strcmp(elm->property->name, "resourcetype")); |
| 556 !strcmp(elm->property->name, "displayname"), |
556 CX_TEST_ASSERT( |
| 557 "p5: property 1 has wrong name"); |
557 !strcmp((char*)elm->property->namespace->href, "DAV:")); |
| 558 UCX_TEST_ASSERT( |
558 |
| 559 !strcmp((char*)elm->property->namespace->href, "DAV:"), |
559 |
| 560 "p5: property 1 has wrong namespace"); |
560 // |
| 561 |
561 // ----------------- TEST_PROPFIND6 ----------------- |
| 562 elm = elm->next; |
562 // test prop/allprop mix |
| 563 UCX_TEST_ASSERT(elm, "p5: property 2 missing"); |
563 WebdavPropfindRequest *p6 = propfind_parse(sn, rq, TEST_PROPFIND6, strlen(TEST_PROPFIND6), &error); |
| 564 elm = elm->next; |
564 |
| 565 UCX_TEST_ASSERT(elm, "p5: property 3 missing"); |
565 CX_TEST_ASSERT(p6); |
| 566 |
566 CX_TEST_ASSERT(!p6->properties); |
| 567 // property 4: DAV:resourcetype |
567 CX_TEST_ASSERT(p6->allprop); |
| 568 elm = elm->next; |
568 CX_TEST_ASSERT(!p6->propname); |
| 569 UCX_TEST_ASSERT(elm, "p5: property 4 missing"); |
569 CX_TEST_ASSERT(p6->propcount == 0); |
| 570 UCX_TEST_ASSERT( |
570 |
| 571 !strcmp(elm->property->name, "resourcetype"), |
571 } |
| 572 "p5: property 4 has wrong name"); |
|
| 573 UCX_TEST_ASSERT( |
|
| 574 !strcmp((char*)elm->property->namespace->href, "DAV:"), |
|
| 575 "p5: property 4 has wrong namespace"); |
|
| 576 |
|
| 577 |
|
| 578 // |
|
| 579 // ----------------- TEST_PROPFIND6 ----------------- |
|
| 580 // test prop/allprop mix |
|
| 581 WebdavPropfindRequest *p6 = propfind_parse(sn, rq, TEST_PROPFIND6, strlen(TEST_PROPFIND6), &error); |
|
| 582 |
|
| 583 UCX_TEST_ASSERT(p6, "p5 is NULL"); |
|
| 584 UCX_TEST_ASSERT(!p6->properties, "p5: has props"); |
|
| 585 UCX_TEST_ASSERT(p6->allprop, "p5: allprop is FALSE"); |
|
| 586 UCX_TEST_ASSERT(!p6->propname, "p5: propname is TRUE"); |
|
| 587 UCX_TEST_ASSERT(p6->propcount == 0, "p5: wrong propcount"); |
|
| 588 |
|
| 589 UCX_TEST_END |
|
| 590 |
572 |
| 591 pool_destroy(sn->pool); |
573 pool_destroy(sn->pool); |
| 592 } |
574 } |
| 593 |
575 |
| 594 UCX_TEST(test_proppatch_parse) { |
576 CX_TEST(test_proppatch_parse) { |
| 595 Session *sn = testutil_session(); |
577 Session *sn = testutil_session(); |
| 596 Request *rq = testutil_request(sn->pool, "PROPPATCH", "/"); |
578 Request *rq = testutil_request(sn->pool, "PROPPATCH", "/"); |
| 597 |
579 |
| 598 UCX_TEST_BEGIN |
580 CX_TEST_DO { |
| 599 int error = 0; |
581 int error = 0; |
| 600 |
582 |
| 601 WebdavProppatchRequest *p1 = proppatch_parse(sn, rq, TEST_PROPPATCH1, strlen(TEST_PROPPATCH1), &error); |
583 WebdavProppatchRequest *p1 = proppatch_parse(sn, rq, TEST_PROPPATCH1, strlen(TEST_PROPPATCH1), &error); |
| 602 |
584 |
| 603 UCX_TEST_ASSERT(p1->set, "p1: missing set props"); |
585 CX_TEST_ASSERT(p1->set); |
| 604 UCX_TEST_ASSERT(!p1->remove, "p1: has remove props"); |
586 CX_TEST_ASSERT(!p1->remove); |
| 605 UCX_TEST_ASSERT(p1->setcount == 2, "p1: wrong setcount"); |
587 CX_TEST_ASSERT(p1->setcount == 2); |
| 606 UCX_TEST_ASSERT(p1->set->next, "p1: set plist broken"); |
588 CX_TEST_ASSERT(p1->set->next); |
| 607 UCX_TEST_ASSERT(!p1->set->next->next, "p1: set plist has no end"); |
589 CX_TEST_ASSERT(!p1->set->next->next); |
| 608 UCX_TEST_ASSERT(p1->set->property, "p1: missing property ptr in plist"); |
590 CX_TEST_ASSERT(p1->set->property); |
| 609 UCX_TEST_ASSERT( |
591 CX_TEST_ASSERT( |
| 610 !strcmp(p1->set->property->name, "test"), |
592 !strcmp(p1->set->property->name, "test")); |
| 611 "p1: wrong property 1 name"); |
593 |
| 612 |
594 WebdavProppatchRequest *p2 = proppatch_parse(sn, rq, TEST_PROPPATCH2, strlen(TEST_PROPPATCH2), &error); |
| 613 WebdavProppatchRequest *p2 = proppatch_parse(sn, rq, TEST_PROPPATCH2, strlen(TEST_PROPPATCH2), &error); |
595 |
| 614 |
596 CX_TEST_ASSERT(p2->set); |
| 615 UCX_TEST_ASSERT(p2->set, "p2: missing set props"); |
597 CX_TEST_ASSERT(p2->remove); |
| 616 UCX_TEST_ASSERT(p2->remove, "p2: missing remove props"); |
598 CX_TEST_ASSERT(p2->setcount == 4); |
| 617 UCX_TEST_ASSERT(p2->setcount == 4, "p2: wrong setcount"); |
599 CX_TEST_ASSERT(p2->removecount == 1); |
| 618 UCX_TEST_ASSERT(p2->removecount == 1, "p2: wrong removecount"); |
600 |
| 619 |
601 CX_TEST_ASSERT( |
| 620 UCX_TEST_ASSERT( |
602 !strcmp((char*)p2->set->property->namespace->href, "http://example.com/")); |
| 621 !strcmp((char*)p2->set->property->namespace->href, "http://example.com/"), |
603 CX_TEST_ASSERT( |
| 622 "p2: set property 1: wrong namespace"); |
604 !strcmp(p2->set->property->name, "a")); |
| 623 UCX_TEST_ASSERT( |
605 WSXmlNode *p2set1 = p2->set->property->value.node; |
| 624 !strcmp(p2->set->property->name, "a"), |
606 CX_TEST_ASSERT(p2set1->type == WS_NODE_TEXT); |
| 625 "p2: set property 1: wrong name"); |
607 CX_TEST_ASSERT(p2set1->content); |
| 626 WSXmlNode *p2set1 = p2->set->property->value.node; |
608 CX_TEST_ASSERT(!strcmp((char*)p2set1->content, "test")); |
| 627 UCX_TEST_ASSERT( |
609 |
| 628 p2set1->type == WS_NODE_TEXT, |
610 WSXmlNode *p2set3 = p2->set->next->next->property->value.node; |
| 629 "p2: set property 1: wrong type"); |
611 CX_TEST_ASSERT(p2set3); |
| 630 UCX_TEST_ASSERT( |
612 CX_TEST_ASSERT(p2set3->type == WS_NODE_TEXT); |
| 631 p2set1->content, |
613 CX_TEST_ASSERT(p2set3->next); |
| 632 "p2: set property 1: no text"); |
614 |
| 633 UCX_TEST_ASSERT( |
615 CX_TEST_ASSERT(xmlHasProp(p2set3->next, BAD_CAST"test")); |
| 634 !strcmp((char*)p2set1->content, "test"), |
616 |
| 635 "p2: set property 1: wrong value"); |
617 CX_TEST_ASSERT(xmlHasProp(p2set3->next, BAD_CAST"abc")); |
| 636 |
618 |
| 637 WSXmlNode *p2set3 = p2->set->next->next->property->value.node; |
619 xmlChar *value1 = xmlGetProp(p2set3->next, BAD_CAST"test"); |
| 638 UCX_TEST_ASSERT(p2set3, "p2: set property 3 missing"); |
620 CX_TEST_ASSERT(!strcmp((char*) value1, "test1")); |
| 639 UCX_TEST_ASSERT( |
621 xmlFree(value1); |
| 640 p2set3->type == WS_NODE_TEXT, |
622 |
| 641 "p2: set property 3: wrong type"); |
623 xmlChar *value2 = xmlGetProp(p2set3->next, BAD_CAST"abc"); |
| 642 UCX_TEST_ASSERT( |
624 CX_TEST_ASSERT(!strcmp((char*) value2, "def")); |
| 643 p2set3->next, |
625 xmlFree(value2); |
| 644 "p2: set property 3: missing element X:name"); |
626 |
| 645 |
627 CX_TEST_ASSERT(!strcmp(p2->remove->property->name, "e")); |
| 646 UCX_TEST_ASSERT( |
628 |
| 647 xmlHasProp(p2set3->next, BAD_CAST"test"), |
629 } |
| 648 "p2: set property 3: missing attribute 'test'"); |
|
| 649 |
|
| 650 UCX_TEST_ASSERT( |
|
| 651 xmlHasProp(p2set3->next, BAD_CAST"abc"), |
|
| 652 "p2: set property 3: missing attribute 'abc"); |
|
| 653 |
|
| 654 xmlChar *value1 = xmlGetProp(p2set3->next, BAD_CAST"test"); |
|
| 655 UCX_TEST_ASSERT( |
|
| 656 !strcmp((char*) value1, "test1"), |
|
| 657 "p2: set property 3: wrong attribute value 1"); |
|
| 658 xmlFree(value1); |
|
| 659 |
|
| 660 xmlChar *value2 = xmlGetProp(p2set3->next, BAD_CAST"abc"); |
|
| 661 UCX_TEST_ASSERT( |
|
| 662 !strcmp((char*) value2, "def"), |
|
| 663 "p2: set property 3: wrong attribute value 2"); |
|
| 664 xmlFree(value2); |
|
| 665 |
|
| 666 UCX_TEST_ASSERT( |
|
| 667 !strcmp(p2->remove->property->name, "e"), |
|
| 668 "p2: wrong remove property"); |
|
| 669 |
|
| 670 UCX_TEST_END |
|
| 671 |
630 |
| 672 pool_destroy(sn->pool); |
631 pool_destroy(sn->pool); |
| 673 } |
632 } |
| 674 |
633 |
| 675 UCX_TEST(test_lock_parse) { |
634 CX_TEST(test_lock_parse) { |
| 676 Session *sn = testutil_session(); |
635 Session *sn = testutil_session(); |
| 677 Request *rq = testutil_request(sn->pool, "LOCK", "/"); |
636 Request *rq = testutil_request(sn->pool, "LOCK", "/"); |
| 678 |
637 |
| 679 UCX_TEST_BEGIN |
638 CX_TEST_DO { |
| 680 int error = 0; |
639 int error = 0; |
| 681 |
640 |
| 682 WebdavLockRequest *l1 = lock_parse(sn, rq, TEST_LOCK1, strlen(TEST_LOCK1), &error); |
641 WebdavLockRequest *l1 = lock_parse(sn, rq, TEST_LOCK1, strlen(TEST_LOCK1), &error); |
| 683 |
642 |
| 684 UCX_TEST_ASSERT(l1, "l1 is NULL"); |
643 CX_TEST_ASSERT(l1); |
| 685 UCX_TEST_ASSERT(l1->type == WEBDAV_LOCK_WRITE, "l1: wrong type"); |
644 CX_TEST_ASSERT(l1->type == WEBDAV_LOCK_WRITE); |
| 686 UCX_TEST_ASSERT(l1->scope == WEBDAV_LOCK_SHARED, "l1: wrong scope"); |
645 CX_TEST_ASSERT(l1->scope == WEBDAV_LOCK_SHARED); |
| 687 UCX_TEST_ASSERT(l1->owner, "l1: owner is NULL"); |
646 CX_TEST_ASSERT(l1->owner); |
| 688 UCX_TEST_ASSERT(!strcmp((char*)l1->owner->content, "User"), "l1: wrong owner"); |
647 CX_TEST_ASSERT(!strcmp((char*)l1->owner->content, "User")); |
| 689 |
648 |
| 690 UCX_TEST_END |
649 } |
| 691 |
650 |
| 692 pool_destroy(sn->pool); |
651 pool_destroy(sn->pool); |
| 693 } |
652 } |
| 694 |
653 |
| 695 UCX_TEST(test_rqbody2buffer) { |
654 CX_TEST(test_rqbody2buffer) { |
| 696 Session *sn; |
655 Session *sn; |
| 697 Request *rq; |
656 Request *rq; |
| 698 |
657 |
| 699 UCX_TEST_BEGIN; |
658 CX_TEST_DO { |
| 700 // |
659 // |
| 701 // TEST 1 |
660 // TEST 1 |
| 702 sn = testutil_session(); |
661 sn = testutil_session(); |
| 703 rq = testutil_request(sn->pool, "PUT", "/"); |
662 rq = testutil_request(sn->pool, "PUT", "/"); |
| 704 testutil_request_body(sn, rq, "Hello World!", 12); |
663 testutil_request_body(sn, rq, "Hello World!", 12); |
| 705 |
664 |
| 706 CxBuffer b1; |
665 CxBuffer b1; |
| 707 rqbody2buffer(sn, rq, &b1); |
666 rqbody2buffer(sn, rq, &b1); |
| 708 UCX_TEST_ASSERT(b1.size == 12, "b1: wrong size"); |
667 CX_TEST_ASSERT(b1.size == 12); |
| 709 UCX_TEST_ASSERT(!memcmp(b1.space,"Hello World!",12), "b1: wrong content"); |
668 CX_TEST_ASSERT(!memcmp(b1.space,"Hello World!",12)); |
| 710 |
669 |
| 711 cxBufferDestroy(&b1); |
670 cxBufferDestroy(&b1); |
| 712 testutil_destroy_session(sn); |
671 testutil_destroy_session(sn); |
| 713 |
672 |
| 714 // |
673 // |
| 715 // TEST 2 |
674 // TEST 2 |
| 716 size_t len1 = 25000; |
675 size_t len1 = 25000; |
| 717 unsigned char *body1 = malloc(len1); |
676 unsigned char *body1 = malloc(len1); |
| 718 for(int i=0;i<len1;i++) { |
677 for(int i=0;i<len1;i++) { |
| 719 body1[i] = i; |
678 body1[i] = i; |
| 720 } |
679 } |
| 721 sn = testutil_session(); |
680 sn = testutil_session(); |
| 722 rq = testutil_request(sn->pool, "PUT", "/"); |
681 rq = testutil_request(sn->pool, "PUT", "/"); |
| 723 testutil_request_body(sn, rq, (char*)body1, len1); |
682 testutil_request_body(sn, rq, (char*)body1, len1); |
| 724 |
683 |
| 725 CxBuffer b2; |
684 CxBuffer b2; |
| 726 rqbody2buffer(sn, rq, &b2); |
685 rqbody2buffer(sn, rq, &b2); |
| 727 UCX_TEST_ASSERT(b2.size == len1, "b2: wrong size"); |
686 CX_TEST_ASSERT(b2.size == len1); |
| 728 UCX_TEST_ASSERT(!memcmp(b2.space, body1, len1), "b2: wrong content"); |
687 CX_TEST_ASSERT(!memcmp(b2.space, body1, len1)); |
| 729 |
688 |
| 730 cxBufferDestroy(&b2); |
689 cxBufferDestroy(&b2); |
| 731 testutil_destroy_session(sn); |
690 testutil_destroy_session(sn); |
| 732 |
691 |
| 733 UCX_TEST_END; |
692 } |
| 734 } |
693 } |
| 735 |
694 |
| 736 UCX_TEST(test_webdav_plist_iterator) { |
695 CX_TEST(test_webdav_plist_iterator) { |
| 737 Session *sn; |
696 Session *sn; |
| 738 Request *rq; |
697 Request *rq; |
| 739 WebdavPropfindRequest *propfind; |
698 WebdavPropfindRequest *propfind; |
| 740 |
699 |
| 741 UCX_TEST_BEGIN; |
700 CX_TEST_DO { |
| 742 UCX_TEST_ASSERT(!test_init(&sn, &rq, &propfind, TEST_PROPFIND1), "init failed"); |
701 CX_TEST_ASSERT(!test_init(&sn, &rq, &propfind, TEST_PROPFIND1)); |
| 743 |
702 |
| 744 WebdavPList *properties = propfind->properties; |
703 WebdavPList *properties = propfind->properties; |
| 745 size_t count = 0; |
704 size_t count = 0; |
| 746 |
705 |
| 747 WebdavPListIterator i = webdav_plist_iterator(&properties); |
706 WebdavPListIterator i = webdav_plist_iterator(&properties); |
| 748 WebdavPList *cur; |
707 WebdavPList *cur; |
| 749 while(webdav_plist_iterator_next(&i, &cur)) { |
708 while(webdav_plist_iterator_next(&i, &cur)) { |
| 750 switch(i.index) { |
709 switch(i.index) { |
| 751 case 0: { |
710 case 0: { |
| 752 UCX_TEST_ASSERT(!strcmp(cur->property->name, "displayname"), "wrong property 1"); |
711 CX_TEST_ASSERT(!strcmp(cur->property->name, "displayname")); |
| 753 break; |
712 break; |
| |
713 } |
| |
714 case 1: { |
| |
715 CX_TEST_ASSERT(!strcmp(cur->property->name, "getcontentlength")); |
| |
716 break; |
| |
717 } |
| |
718 case 2: { |
| |
719 CX_TEST_ASSERT(!strcmp(cur->property->name, "getcontenttype")); |
| |
720 break; |
| |
721 } |
| |
722 case 3: { |
| |
723 CX_TEST_ASSERT(!strcmp(cur->property->name, "getlastmodified")); |
| |
724 break; |
| |
725 } |
| |
726 case 4: { |
| |
727 CX_TEST_ASSERT(!strcmp(cur->property->name, "resourcetype")); |
| |
728 break; |
| |
729 } |
| |
730 case 5: { |
| |
731 CX_TEST_ASSERT(!strcmp(cur->property->name, "getetag")); |
| |
732 break; |
| |
733 } |
| 754 } |
734 } |
| 755 case 1: { |
735 count++; |
| 756 UCX_TEST_ASSERT(!strcmp(cur->property->name, "getcontentlength"), "wrong property 2"); |
736 } |
| 757 break; |
737 |
| 758 } |
738 CX_TEST_ASSERT(count == propfind->propcount); |
| 759 case 2: { |
739 |
| 760 UCX_TEST_ASSERT(!strcmp(cur->property->name, "getcontenttype"), "wrong property 3"); |
740 |
| 761 break; |
741 } |
| 762 } |
|
| 763 case 3: { |
|
| 764 UCX_TEST_ASSERT(!strcmp(cur->property->name, "getlastmodified"), "wrong property 4"); |
|
| 765 break; |
|
| 766 } |
|
| 767 case 4: { |
|
| 768 UCX_TEST_ASSERT(!strcmp(cur->property->name, "resourcetype"), "wrong property 5"); |
|
| 769 break; |
|
| 770 } |
|
| 771 case 5: { |
|
| 772 UCX_TEST_ASSERT(!strcmp(cur->property->name, "getetag"), "wrong property 6"); |
|
| 773 break; |
|
| 774 } |
|
| 775 } |
|
| 776 count++; |
|
| 777 } |
|
| 778 |
|
| 779 UCX_TEST_ASSERT(count == propfind->propcount, "wrong count"); |
|
| 780 |
|
| 781 |
|
| 782 UCX_TEST_END; |
|
| 783 testutil_destroy_session(sn); |
742 testutil_destroy_session(sn); |
| 784 } |
743 } |
| 785 |
744 |
| 786 UCX_TEST(test_webdav_plist_iterator_remove_current) { |
745 CX_TEST(test_webdav_plist_iterator_remove_current) { |
| 787 Session *sn; |
746 Session *sn; |
| 788 Request *rq; |
747 Request *rq; |
| 789 WebdavPropfindRequest *propfind; |
748 WebdavPropfindRequest *propfind; |
| 790 |
749 |
| 791 UCX_TEST_BEGIN; |
750 CX_TEST_DO { |
| 792 UCX_TEST_ASSERT(!test_init(&sn, &rq, &propfind, TEST_PROPFIND1), "init failed"); |
751 CX_TEST_ASSERT(!test_init(&sn, &rq, &propfind, TEST_PROPFIND1)); |
| 793 |
752 |
| 794 WebdavPList *properties1 = webdav_plist_clone(sn->pool, propfind->properties); |
753 WebdavPList *properties1 = webdav_plist_clone(sn->pool, propfind->properties); |
| 795 WebdavPList *properties2 = webdav_plist_clone(sn->pool, propfind->properties); |
754 WebdavPList *properties2 = webdav_plist_clone(sn->pool, propfind->properties); |
| 796 WebdavPList *properties3 = webdav_plist_clone(sn->pool, propfind->properties); |
755 WebdavPList *properties3 = webdav_plist_clone(sn->pool, propfind->properties); |
| 797 WebdavPList *properties4 = webdav_plist_clone(sn->pool, propfind->properties); |
756 WebdavPList *properties4 = webdav_plist_clone(sn->pool, propfind->properties); |
| 798 |
757 |
| 799 WebdavPListIterator i; |
758 WebdavPListIterator i; |
| 800 WebdavPList *cur; |
759 WebdavPList *cur; |
| 801 |
760 |
| 802 // test removal of first element |
761 // test removal of first element |
| 803 i = webdav_plist_iterator(&properties1); |
762 i = webdav_plist_iterator(&properties1); |
| 804 while(webdav_plist_iterator_next(&i, &cur)) { |
763 while(webdav_plist_iterator_next(&i, &cur)) { |
| 805 if(i.index == 0) { |
764 if(i.index == 0) { |
| |
765 webdav_plist_iterator_remove_current(&i); |
| |
766 } |
| |
767 } |
| |
768 |
| |
769 CX_TEST_ASSERT(!properties1->prev); |
| |
770 CX_TEST_ASSERT(!strcmp(properties1->property->name, "getcontentlength")); |
| |
771 CX_TEST_ASSERT(!strcmp(properties1->next->property->name, "getcontenttype")); |
| |
772 CX_TEST_ASSERT(properties1->next->prev == properties1); |
| |
773 |
| |
774 // test removal of second element |
| |
775 i = webdav_plist_iterator(&properties2); |
| |
776 while(webdav_plist_iterator_next(&i, &cur)) { |
| |
777 if(i.index == 1) { |
| |
778 webdav_plist_iterator_remove_current(&i); |
| |
779 } |
| |
780 } |
| |
781 |
| |
782 CX_TEST_ASSERT(!strcmp(properties2->next->property->name, "getcontenttype")); |
| |
783 CX_TEST_ASSERT(properties2->next->prev == properties2); |
| |
784 CX_TEST_ASSERT(webdav_plist_size(properties2) == 5); |
| |
785 |
| |
786 // remove last element |
| |
787 i = webdav_plist_iterator(&properties3); |
| |
788 while(webdav_plist_iterator_next(&i, &cur)) { |
| |
789 if(i.index == 5) { |
| |
790 webdav_plist_iterator_remove_current(&i); |
| |
791 } |
| |
792 } |
| |
793 |
| |
794 CX_TEST_ASSERT(webdav_plist_size(properties3) == 5); |
| |
795 CX_TEST_ASSERT(!strcmp(properties3->next->next->next->next->property->name, "resourcetype")); |
| |
796 |
| |
797 // remove all elements |
| |
798 i = webdav_plist_iterator(&properties4); |
| |
799 while(webdav_plist_iterator_next(&i, &cur)) { |
| 806 webdav_plist_iterator_remove_current(&i); |
800 webdav_plist_iterator_remove_current(&i); |
| 807 } |
801 switch(i.index) { |
| 808 } |
802 case 0: { |
| 809 |
803 CX_TEST_ASSERT(!strcmp(properties4->property->name, "getcontentlength")); |
| 810 UCX_TEST_ASSERT(!properties1->prev, "test1: prev not cleared"); |
804 CX_TEST_ASSERT(properties4->prev == NULL); |
| 811 UCX_TEST_ASSERT(!strcmp(properties1->property->name, "getcontentlength"), "test1: wrong property"); |
805 break; |
| 812 UCX_TEST_ASSERT(!strcmp(properties1->next->property->name, "getcontenttype"), "test1: wrong property 2"); |
806 } |
| 813 UCX_TEST_ASSERT(properties1->next->prev == properties1, "test1: wrong link"); |
807 case 1: { |
| 814 |
808 CX_TEST_ASSERT(!strcmp(properties4->property->name, "getcontenttype")); |
| 815 // test removal of second element |
809 CX_TEST_ASSERT(properties4->prev == NULL); |
| 816 i = webdav_plist_iterator(&properties2); |
810 break; |
| 817 while(webdav_plist_iterator_next(&i, &cur)) { |
811 } |
| 818 if(i.index == 1) { |
812 case 2: { |
| 819 webdav_plist_iterator_remove_current(&i); |
813 CX_TEST_ASSERT(!strcmp(properties4->property->name, "getlastmodified")); |
| 820 } |
814 CX_TEST_ASSERT(properties4->prev == NULL); |
| 821 } |
815 break; |
| 822 |
816 } |
| 823 UCX_TEST_ASSERT(!strcmp(properties2->next->property->name, "getcontenttype"), "test2: wrong property"); |
817 case 3: { |
| 824 UCX_TEST_ASSERT(properties2->next->prev == properties2, "test2: wrong link"); |
818 CX_TEST_ASSERT(!strcmp(properties4->property->name, "resourcetype")); |
| 825 UCX_TEST_ASSERT(webdav_plist_size(properties2) == 5, "test2: wrong size"); |
819 CX_TEST_ASSERT(properties4->prev == NULL); |
| 826 |
820 break; |
| 827 // remove last element |
821 } |
| 828 i = webdav_plist_iterator(&properties3); |
822 case 4: { |
| 829 while(webdav_plist_iterator_next(&i, &cur)) { |
823 CX_TEST_ASSERT(!strcmp(properties4->property->name, "getetag")); |
| 830 if(i.index == 5) { |
824 CX_TEST_ASSERT(properties4->prev == NULL); |
| 831 webdav_plist_iterator_remove_current(&i); |
825 break; |
| 832 } |
826 } |
| 833 } |
827 default: { |
| 834 |
828 CX_TEST_ASSERT(i.index <= 5); |
| 835 UCX_TEST_ASSERT(webdav_plist_size(properties3) == 5, "test3: wrong size"); |
829 } |
| 836 UCX_TEST_ASSERT(!strcmp(properties3->next->next->next->next->property->name, "resourcetype"), "test2: wrong property"); |
|
| 837 |
|
| 838 // remove all elements |
|
| 839 i = webdav_plist_iterator(&properties4); |
|
| 840 while(webdav_plist_iterator_next(&i, &cur)) { |
|
| 841 webdav_plist_iterator_remove_current(&i); |
|
| 842 switch(i.index) { |
|
| 843 case 0: { |
|
| 844 UCX_TEST_ASSERT(!strcmp(properties4->property->name, "getcontentlength"), "test4: wrong property 2"); |
|
| 845 UCX_TEST_ASSERT(properties4->prev == NULL, "test4: prev not NULL (0)"); |
|
| 846 break; |
|
| 847 } |
830 } |
| 848 case 1: { |
831 } |
| 849 UCX_TEST_ASSERT(!strcmp(properties4->property->name, "getcontenttype"), "test4: wrong property 3"); |
832 |
| 850 UCX_TEST_ASSERT(properties4->prev == NULL, "test4: prev not NULL (1)"); |
833 CX_TEST_ASSERT(properties4 == NULL); |
| 851 break; |
834 |
| 852 } |
835 } |
| 853 case 2: { |
|
| 854 UCX_TEST_ASSERT(!strcmp(properties4->property->name, "getlastmodified"), "test4: wrong property 4"); |
|
| 855 UCX_TEST_ASSERT(properties4->prev == NULL, "test4: prev not NULL (2)"); |
|
| 856 break; |
|
| 857 } |
|
| 858 case 3: { |
|
| 859 UCX_TEST_ASSERT(!strcmp(properties4->property->name, "resourcetype"), "test4: wrong property 5"); |
|
| 860 UCX_TEST_ASSERT(properties4->prev == NULL, "test4: prev not NULL (3)"); |
|
| 861 break; |
|
| 862 } |
|
| 863 case 4: { |
|
| 864 UCX_TEST_ASSERT(!strcmp(properties4->property->name, "getetag"), "test4: wrong property 6"); |
|
| 865 UCX_TEST_ASSERT(properties4->prev == NULL, "test4: prev not NULL (4)"); |
|
| 866 break; |
|
| 867 } |
|
| 868 default: { |
|
| 869 UCX_TEST_ASSERT(i.index <= 5, "fail"); |
|
| 870 } |
|
| 871 } |
|
| 872 } |
|
| 873 |
|
| 874 UCX_TEST_ASSERT(properties4 == NULL, "test4: list not NULL"); |
|
| 875 |
|
| 876 UCX_TEST_END; |
|
| 877 testutil_destroy_session(sn); |
836 testutil_destroy_session(sn); |
| 878 } |
837 } |
| 879 |
838 |
| 880 UCX_TEST(test_msresponse_addproperty) { |
839 CX_TEST(test_msresponse_addproperty) { |
| 881 Session *sn; |
840 Session *sn; |
| 882 Request *rq; |
841 Request *rq; |
| 883 |
842 |
| 884 UCX_TEST_BEGIN; |
843 CX_TEST_DO { |
| 885 |
844 |
| 886 WebdavOperation *op = test_propfind_op(&sn, &rq, TEST_PROPFIND1); |
845 WebdavOperation *op = test_propfind_op(&sn, &rq, TEST_PROPFIND1); |
| 887 UCX_TEST_ASSERT(op, "init failed"); |
846 CX_TEST_ASSERT(op); |
| 888 UCX_TEST_ASSERT(op->response, "no response"); |
847 CX_TEST_ASSERT(op->response); |
| 889 |
848 |
| 890 Multistatus *ms = (Multistatus*)op->response; |
849 Multistatus *ms = (Multistatus*)op->response; |
| 891 MSResponse *r = (MSResponse*)ms->response.addresource((WebdavResponse*)ms, "/"); |
850 MSResponse *r = (MSResponse*)ms->response.addresource((WebdavResponse*)ms, "/"); |
| 892 |
851 |
| 893 WebdavProperty p1; |
852 WebdavProperty p1; |
| 894 WebdavProperty p[16]; |
853 WebdavProperty p[16]; |
| 895 const char *names[] = {"a1", "a2", "a3", "a4", "a5", "a6", "a7", "a8", "a9"}; |
854 const char *names[] = {"a1", "a2", "a3", "a4", "a5", "a6", "a7", "a8", "a9"}; |
| 896 |
855 |
| 897 WSNamespace ns1; |
856 WSNamespace ns1; |
| 898 ZERO(&ns1, sizeof(WSNamespace)); |
857 ZERO(&ns1, sizeof(WSNamespace)); |
| 899 WSNamespace ns2; |
858 WSNamespace ns2; |
| 900 ZERO(&ns2, sizeof(WSNamespace)); |
859 ZERO(&ns2, sizeof(WSNamespace)); |
| 901 ns1.prefix = (xmlChar*)"x1"; |
860 ns1.prefix = (xmlChar*)"x1"; |
| 902 ns1.href = (xmlChar*)"http://example.com/test/"; |
861 ns1.href = (xmlChar*)"http://example.com/test/"; |
| 903 ns2.prefix = (xmlChar*)"x2"; |
862 ns2.prefix = (xmlChar*)"x2"; |
| 904 ns2.href = (xmlChar*)"http://example.com/test/"; |
863 ns2.href = (xmlChar*)"http://example.com/test/"; |
| 905 |
864 |
| 906 WebdavProperty dp1; |
865 WebdavProperty dp1; |
| 907 ZERO(&dp1, sizeof(WebdavProperty)); |
866 ZERO(&dp1, sizeof(WebdavProperty)); |
| 908 dp1.name = "dup"; |
867 dp1.name = "dup"; |
| 909 dp1.namespace = &ns1; |
868 dp1.namespace = &ns1; |
| 910 dp1.value.text.str = "Hello"; |
869 dp1.value.text.str = "Hello"; |
| 911 dp1.value.text.length = 5; |
870 dp1.value.text.length = 5; |
| 912 dp1.vtype = WS_VALUE_TEXT; |
871 dp1.vtype = WS_VALUE_TEXT; |
| 913 |
872 |
| 914 WebdavProperty dp2; |
873 WebdavProperty dp2; |
| 915 ZERO(&dp2, sizeof(WebdavProperty)); |
874 ZERO(&dp2, sizeof(WebdavProperty)); |
| 916 dp2.name = "dup"; |
875 dp2.name = "dup"; |
| 917 dp2.namespace = &ns1; |
876 dp2.namespace = &ns1; |
| 918 dp2.value.text.str = "Hello"; |
877 dp2.value.text.str = "Hello"; |
| 919 dp2.value.text.length = 5; |
878 dp2.value.text.length = 5; |
| 920 dp2.vtype = WS_VALUE_TEXT; |
879 dp2.vtype = WS_VALUE_TEXT; |
| 921 |
880 |
| 922 WebdavProperty dp3; |
881 WebdavProperty dp3; |
| 923 ZERO(&dp3, sizeof(WebdavProperty)); |
882 ZERO(&dp3, sizeof(WebdavProperty)); |
| 924 dp3.name = "dup"; |
883 dp3.name = "dup"; |
| 925 dp3.namespace = &ns2; |
884 dp3.namespace = &ns2; |
| 926 dp3.value.text.str = "Hello"; |
885 dp3.value.text.str = "Hello"; |
| 927 dp3.value.text.length = 5; |
886 dp3.value.text.length = 5; |
| 928 dp3.vtype = WS_VALUE_TEXT; |
887 dp3.vtype = WS_VALUE_TEXT; |
| 929 |
888 |
| 930 // init test data |
889 // init test data |
| 931 p1.namespace = webdav_dav_namespace(); |
890 p1.namespace = webdav_dav_namespace(); |
| 932 p1.lang = NULL; |
891 p1.lang = NULL; |
| 933 p1.name = "test1"; |
892 p1.name = "test1"; |
| 934 p1.value.data = (WSXmlData){ NULL, NULL, 0}; |
893 p1.value.data = (WSXmlData){ NULL, NULL, 0}; |
| 935 p1.vtype = 0; |
894 p1.vtype = 0; |
| 936 |
895 |
| 937 for(int i=0;i<8;i++) { |
896 for(int i=0;i<8;i++) { |
| 938 p[i].namespace = webdav_dav_namespace(); |
897 p[i].namespace = webdav_dav_namespace(); |
| 939 p[i].name = names[i]; |
898 p[i].name = names[i]; |
| 940 p[i].lang = NULL; |
899 p[i].lang = NULL; |
| 941 p[i].value.node = NULL; |
900 p[i].value.node = NULL; |
| 942 p[1].vtype = 0; |
901 p[1].vtype = 0; |
| 943 } |
902 } |
| 944 |
903 |
| 945 UCX_TEST_ASSERT(!r->plist_begin && !r->plist_end, "plist not empty"); |
904 CX_TEST_ASSERT(!r->plist_begin && !r->plist_end); |
| 946 |
905 |
| 947 r->resource.addproperty((WebdavResource*)r, &p1, 200); |
906 r->resource.addproperty((WebdavResource*)r, &p1, 200); |
| 948 UCX_TEST_ASSERT(r->plist_begin, "!plist_begin"); |
907 CX_TEST_ASSERT(r->plist_begin); |
| 949 UCX_TEST_ASSERT(r->plist_begin == r->plist_end, "plist begin != end"); |
908 CX_TEST_ASSERT(r->plist_begin == r->plist_end); |
| 950 |
909 |
| 951 r->resource.addproperty((WebdavResource*)r, &p[0], 404); |
910 r->resource.addproperty((WebdavResource*)r, &p[0], 404); |
| 952 r->resource.addproperty((WebdavResource*)r, &p[1], 404); |
911 r->resource.addproperty((WebdavResource*)r, &p[1], 404); |
| 953 r->resource.addproperty((WebdavResource*)r, &p[2], 403); |
912 r->resource.addproperty((WebdavResource*)r, &p[2], 403); |
| 954 r->resource.addproperty((WebdavResource*)r, &p[3], 403); |
913 r->resource.addproperty((WebdavResource*)r, &p[3], 403); |
| 955 r->resource.addproperty((WebdavResource*)r, &p[4], 403); |
914 r->resource.addproperty((WebdavResource*)r, &p[4], 403); |
| 956 r->resource.addproperty((WebdavResource*)r, &p[5], 403); |
915 r->resource.addproperty((WebdavResource*)r, &p[5], 403); |
| 957 r->resource.addproperty((WebdavResource*)r, &p[6], 500); |
916 r->resource.addproperty((WebdavResource*)r, &p[6], 500); |
| 958 |
917 |
| 959 UCX_TEST_ASSERT(r->plist_begin == r->plist_end, "plist begin != end"); |
918 CX_TEST_ASSERT(r->plist_begin == r->plist_end); |
| 960 |
919 |
| 961 UCX_TEST_ASSERT(r->errors, "no prop errors"); |
920 CX_TEST_ASSERT(r->errors); |
| 962 UCX_TEST_ASSERT(r->errors->next, "no second error code"); |
921 CX_TEST_ASSERT(r->errors->next); |
| 963 UCX_TEST_ASSERT(r->errors->next->next, "no third error code"); |
922 CX_TEST_ASSERT(r->errors->next->next); |
| 964 UCX_TEST_ASSERT(!r->errors->next->next->next, "too many error codes"); |
923 CX_TEST_ASSERT(!r->errors->next->next->next); |
| 965 |
924 |
| 966 UCX_TEST_ASSERT(webdav_plist_size(r->errors->begin) == 2, "404 list size != 2"); |
925 CX_TEST_ASSERT(webdav_plist_size(r->errors->begin) == 2); |
| 967 UCX_TEST_ASSERT(webdav_plist_size(r->errors->next->begin) == 4, "403 list size != 4"); |
926 CX_TEST_ASSERT(webdav_plist_size(r->errors->next->begin) == 4); |
| 968 UCX_TEST_ASSERT(webdav_plist_size(r->errors->next->next->begin) == 1, "500 list size != 1"); |
927 CX_TEST_ASSERT(webdav_plist_size(r->errors->next->next->begin) == 1); |
| 969 |
928 |
| 970 // new resource for prop duplication tests |
929 // new resource for prop duplication tests |
| 971 r = (MSResponse*)ms->response.addresource((WebdavResponse*)ms, "/test"); |
930 r = (MSResponse*)ms->response.addresource((WebdavResponse*)ms, "/test"); |
| 972 UCX_TEST_ASSERT(r, "cannot create second response"); |
931 CX_TEST_ASSERT(r); |
| 973 |
932 |
| 974 r->resource.addproperty((WebdavResource*)r, &dp1, 200); |
933 r->resource.addproperty((WebdavResource*)r, &dp1, 200); |
| 975 UCX_TEST_ASSERT(r->plist_begin, "adding dp1 failed"); |
934 CX_TEST_ASSERT(r->plist_begin); |
| 976 UCX_TEST_ASSERT(!r->plist_begin->next, "dp1: list size not 1"); |
935 CX_TEST_ASSERT(!r->plist_begin->next); |
| 977 |
936 |
| 978 r->resource.addproperty((WebdavResource*)r, &dp2, 200); |
937 r->resource.addproperty((WebdavResource*)r, &dp2, 200); |
| 979 UCX_TEST_ASSERT(!r->plist_begin->next, "dp1: adding dp2 should not work"); |
938 CX_TEST_ASSERT(!r->plist_begin->next); |
| 980 |
939 |
| 981 r->resource.addproperty((WebdavResource*)r, &dp2, 404); |
940 r->resource.addproperty((WebdavResource*)r, &dp2, 404); |
| 982 UCX_TEST_ASSERT(!r->plist_begin->next, "dp1: adding dp2 with different status should not work (1)"); |
941 CX_TEST_ASSERT(!r->plist_begin->next); |
| 983 if(r->errors) { |
942 if(r->errors) { |
| 984 UCX_TEST_ASSERT(webdav_plist_size(r->errors->begin) == 0, "dp1: error list not empty"); |
943 CX_TEST_ASSERT(webdav_plist_size(r->errors->begin) == 0); |
| 985 } |
944 } |
| 986 |
945 |
| 987 r->resource.addproperty((WebdavResource*)r, &dp3, 200); |
946 r->resource.addproperty((WebdavResource*)r, &dp3, 200); |
| 988 UCX_TEST_ASSERT(!r->plist_begin->next, "dp1: adding dp3 should not work"); |
947 CX_TEST_ASSERT(!r->plist_begin->next); |
| 989 |
948 |
| 990 UCX_TEST_END; |
949 } |
| 991 } |
950 } |
| 992 |
951 |
| 993 UCX_TEST(test_webdav_propfind_init) { |
952 CX_TEST(test_webdav_propfind_init) { |
| 994 reset_backends(); |
953 reset_backends(); |
| 995 |
954 |
| 996 Session *sn; |
955 Session *sn; |
| 997 Request *rq; |
956 Request *rq; |
| 998 WebdavPropfindRequest *propfind; |
957 WebdavPropfindRequest *propfind; |
| 999 UCX_TEST_BEGIN; |
958 CX_TEST_DO { |
| 1000 UCX_TEST_ASSERT(!test_init(&sn, &rq, &propfind, TEST_PROPFIND1), "init failed"); |
959 CX_TEST_ASSERT(!test_init(&sn, &rq, &propfind, TEST_PROPFIND1)); |
| 1001 |
960 |
| 1002 WebdavPropfindRequestList *requests = NULL; |
961 WebdavPropfindRequestList *requests = NULL; |
| 1003 int err = webdav_propfind_init(&backend1, propfind, "/", "/", &requests); |
962 int err = webdav_propfind_init(&backend1, propfind, "/", "/", &requests); |
| 1004 |
963 |
| 1005 UCX_TEST_ASSERT(!err, "webdav_propfind_init failed"); |
964 CX_TEST_ASSERT(!err); |
| 1006 UCX_TEST_ASSERT(requests, "request list is empty"); |
965 CX_TEST_ASSERT(requests); |
| 1007 UCX_TEST_ASSERT(cx_linked_list_size(requests, offsetof(WebdavPropfindRequestList, next)), "request list has wrong size"); |
966 CX_TEST_ASSERT(cx_linked_list_size(requests, offsetof(WebdavPropfindRequestList, next))); |
| 1008 |
967 |
| 1009 WebdavPropfindRequest *p1 = requests->propfind; |
968 WebdavPropfindRequest *p1 = requests->propfind; |
| 1010 WebdavPropfindRequest *p2 = requests->next->propfind; |
969 WebdavPropfindRequest *p2 = requests->next->propfind; |
| 1011 |
970 |
| 1012 // backend1 removes the first property from the plist |
971 // backend1 removes the first property from the plist |
| 1013 // backend2 should have one property less |
972 // backend2 should have one property less |
| 1014 |
973 |
| 1015 UCX_TEST_ASSERT(p1 && p2, "missing requests objects"); |
974 CX_TEST_ASSERT(p1 && p2); |
| 1016 UCX_TEST_ASSERT(p1 != p2, "request objects equal"); |
975 CX_TEST_ASSERT(p1 != p2); |
| 1017 UCX_TEST_ASSERT(p1->properties != p2->properties, "plists equal"); |
976 CX_TEST_ASSERT(p1->properties != p2->properties); |
| 1018 UCX_TEST_ASSERT(p1->propcount == p2->propcount + 1, "first property not removed"); |
977 CX_TEST_ASSERT(p1->propcount == p2->propcount + 1); |
| 1019 |
978 |
| 1020 UCX_TEST_ASSERT(backend1_init_called == 1, "backend1 init not called"); |
979 CX_TEST_ASSERT(backend1_init_called == 1); |
| 1021 UCX_TEST_ASSERT(backend2_init_called == 1, "backend2 init not called"); |
980 CX_TEST_ASSERT(backend2_init_called == 1); |
| 1022 |
981 |
| 1023 UCX_TEST_END; |
982 } |
| 1024 |
983 |
| 1025 pool_destroy(sn->pool); |
984 pool_destroy(sn->pool); |
| 1026 } |
985 } |
| 1027 |
986 |
| 1028 UCX_TEST(test_webdav_op_propfind_begin) { |
987 CX_TEST(test_webdav_op_propfind_begin) { |
| 1029 reset_backends(); |
988 reset_backends(); |
| 1030 |
989 |
| 1031 Session *sn; |
990 Session *sn; |
| 1032 Request *rq; |
991 Request *rq; |
| 1033 |
992 |
| 1034 UCX_TEST_BEGIN; |
993 CX_TEST_DO { |
| 1035 WebdavOperation *op = test_propfind_op(&sn, &rq, TEST_PROPFIND1); |
994 WebdavOperation *op = test_propfind_op(&sn, &rq, TEST_PROPFIND1); |
| 1036 UCX_TEST_ASSERT(op, "WebdavOperation not created"); |
995 CX_TEST_ASSERT(op); |
| 1037 |
996 |
| 1038 int err = webdav_op_propfind_begin(op, "/", NULL, NULL); |
997 int err = webdav_op_propfind_begin(op, "/", NULL, NULL); |
| 1039 UCX_TEST_ASSERT(err == 0, "err not 0"); |
998 CX_TEST_ASSERT(err == 0); |
| 1040 UCX_TEST_ASSERT(backend1_propfind_do_count == 1, "backend1 propfind_do not called"); |
999 CX_TEST_ASSERT(backend1_propfind_do_count == 1); |
| 1041 UCX_TEST_ASSERT(backend2_propfind_do_count == 1, "backend2 propfind_do not called"); |
1000 CX_TEST_ASSERT(backend2_propfind_do_count == 1); |
| 1042 |
1001 |
| 1043 |
1002 } |
| 1044 UCX_TEST_END; |
|
| 1045 testutil_destroy_session(sn); |
1003 testutil_destroy_session(sn); |
| 1046 } |
1004 } |
| 1047 |
1005 |
| 1048 UCX_TEST(test_webdav_op_propfind_children) { |
1006 CX_TEST(test_webdav_op_propfind_children) { |
| 1049 reset_backends(); |
1007 reset_backends(); |
| 1050 |
1008 |
| 1051 Session *sn; |
1009 Session *sn; |
| 1052 Request *rq; |
1010 Request *rq; |
| 1053 |
1011 |
| 1054 UCX_TEST_BEGIN; |
1012 CX_TEST_DO { |
| 1055 WebdavOperation *op = test_propfind_op(&sn, &rq, TEST_PROPFIND1); |
1013 WebdavOperation *op = test_propfind_op(&sn, &rq, TEST_PROPFIND1); |
| 1056 UCX_TEST_ASSERT(op, "WebdavOperation not created"); |
1014 CX_TEST_ASSERT(op); |
| 1057 |
1015 |
| 1058 int err = webdav_op_propfind_begin(op, "/", NULL, NULL); |
1016 int err = webdav_op_propfind_begin(op, "/", NULL, NULL); |
| 1059 UCX_TEST_ASSERT(err == 0, "propfind_begin error"); |
1017 CX_TEST_ASSERT(err == 0); |
| 1060 |
1018 |
| 1061 // create test vfs with some files (code from test_vfs_readdir) |
1019 // create test vfs with some files (code from test_vfs_readdir) |
| 1062 rq->vfs = testvfs_create(sn); |
1020 rq->vfs = testvfs_create(sn); |
| 1063 VFSContext *vfs = vfs_request_context(sn, rq); |
1021 VFSContext *vfs = vfs_request_context(sn, rq); |
| 1064 UCX_TEST_ASSERT(vfs, "no vfs"); |
1022 CX_TEST_ASSERT(vfs); |
| 1065 |
1023 |
| 1066 err = vfs_mkdir(vfs, "/dir"); |
1024 err = vfs_mkdir(vfs, "/dir"); |
| 1067 UCX_TEST_ASSERT(err == 0, "error not 0"); |
1025 CX_TEST_ASSERT(err == 0); |
| 1068 |
1026 |
| 1069 // add some test file to /dir |
1027 // add some test file to /dir |
| 1070 UCX_TEST_ASSERT(vfs_open(vfs, "/dir/file1", O_CREAT), "creation of file1 failed"); |
1028 CX_TEST_ASSERT(vfs_open(vfs, "/dir/file1", O_CREAT)); |
| 1071 UCX_TEST_ASSERT(vfs_open(vfs, "/dir/file2", O_CREAT), "creation of file2 failed"); |
1029 CX_TEST_ASSERT(vfs_open(vfs, "/dir/file2", O_CREAT)); |
| 1072 UCX_TEST_ASSERT(vfs_open(vfs, "/dir/file3", O_CREAT), "creation of file3 failed"); |
1030 CX_TEST_ASSERT(vfs_open(vfs, "/dir/file3", O_CREAT)); |
| 1073 UCX_TEST_ASSERT(vfs_open(vfs, "/dir/file4", O_CREAT), "creation of file4 failed"); |
1031 CX_TEST_ASSERT(vfs_open(vfs, "/dir/file4", O_CREAT)); |
| 1074 |
1032 |
| 1075 VFSDir *dir = vfs_opendir(vfs, "/dir"); |
1033 VFSDir *dir = vfs_opendir(vfs, "/dir"); |
| 1076 UCX_TEST_ASSERT(dir, "dir not opened"); |
1034 CX_TEST_ASSERT(dir); |
| 1077 |
1035 |
| 1078 UCX_TEST_ASSERT(backend1_propfind_do_count == 1, "backend1 propfind_do not called"); |
1036 CX_TEST_ASSERT(backend1_propfind_do_count == 1); |
| 1079 UCX_TEST_ASSERT(backend2_propfind_do_count == 1, "backend1 propfind_do not called") |
1037 CX_TEST_ASSERT(backend2_propfind_do_count == 1); |
| 1080 |
1038 |
| 1081 // propfind for all children |
1039 // propfind for all children |
| 1082 err = webdav_op_propfind_children(op, vfs, "/", "/dir"); |
1040 err = webdav_op_propfind_children(op, vfs, "/", "/dir"); |
| 1083 UCX_TEST_ASSERT(err == 0, "webdav_op_propfind_children failed"); |
1041 CX_TEST_ASSERT(err == 0); |
| 1084 |
1042 |
| 1085 // 1 dir + 4 children |
1043 // 1 dir + 4 children |
| 1086 UCX_TEST_ASSERT(backend1_propfind_do_count == 5, "backend1 propfind_do wrong count"); |
1044 CX_TEST_ASSERT(backend1_propfind_do_count == 5); |
| 1087 UCX_TEST_ASSERT(backend2_propfind_do_count == 5, "backend2 propfind_do wrong count"); |
1045 CX_TEST_ASSERT(backend2_propfind_do_count == 5); |
| 1088 |
1046 |
| 1089 UCX_TEST_END; |
1047 } |
| 1090 testutil_destroy_session(sn); |
1048 testutil_destroy_session(sn); |
| 1091 } |
1049 } |
| 1092 |
1050 |
| 1093 void init_test_webdav_method( |
1051 void init_test_webdav_method( |
| 1094 Session **out_sn, |
1052 Session **out_sn, |