| 27 */ |
27 */ |
| 28 |
28 |
| 29 #include "webdav.h" |
29 #include "webdav.h" |
| 30 #include "webdav_resource.h" |
30 #include "webdav_resource.h" |
| 31 |
31 |
| |
32 CX_TEST_SUBROUTINE(test_default_properties, DavResource *res) { |
| |
33 CX_TEST_ASSERT(res->contentlength > 0); |
| |
34 CX_TEST_ASSERT(res->creationdate > 0); |
| |
35 CX_TEST_ASSERT(res->lastmodified > 0); |
| |
36 CX_TEST_ASSERT(res->exists); |
| |
37 CX_TEST_ASSERT(res->contenttype); |
| |
38 CX_TEST_ASSERT(!res->iscollection); |
| |
39 CX_TEST_ASSERT(res->href); |
| |
40 } |
| |
41 |
| 32 CX_TEST(test_dav_load_webdav) { |
42 CX_TEST(test_dav_load_webdav) { |
| 33 CX_TEST_DO { |
43 CX_TEST_DO { |
| 34 DavSession *sn = get_test_webdav_session(); |
44 DavSession *sn = get_test_webdav_session(); |
| 35 DavResource *res = dav_resource_new(sn, "/hello.txt"); |
45 DavResource *res = dav_resource_new(sn, "/hello.txt"); |
| 36 CX_TEST_ASSERT(res); |
46 CX_TEST_ASSERT(res); |
| 37 int ret = dav_load(res); |
47 int ret = dav_load(res); |
| 38 CX_TEST_ASSERT(ret == 0); |
48 CX_TEST_ASSERT(ret == 0); |
| 39 CX_TEST_ASSERT(res->contentlength > 0); |
49 CX_TEST_CALL_SUBROUTINE(test_default_properties, res); |
| 40 CX_TEST_ASSERT(res->creationdate > 0); |
50 dav_session_destroy(sn); |
| 41 CX_TEST_ASSERT(res->lastmodified > 0); |
|
| 42 CX_TEST_ASSERT(res->exists); |
|
| 43 CX_TEST_ASSERT(res->contenttype); |
|
| 44 CX_TEST_ASSERT(!res->iscollection); |
|
| 45 CX_TEST_ASSERT(res->href); |
|
| 46 } |
51 } |
| 47 } |
52 } |
| |
53 |
| |
54 CX_TEST(test_dav_exists_webdav) { |
| |
55 CX_TEST_DO { |
| |
56 DavSession *sn = get_test_webdav_session(); |
| |
57 DavResource *res = dav_resource_new(sn, "/hello.txt"); |
| |
58 CX_TEST_ASSERT(res); |
| |
59 int exists = dav_exists(res); |
| |
60 CX_TEST_ASSERT(exists); |
| |
61 CX_TEST_CALL_SUBROUTINE(test_default_properties, res); |
| |
62 dav_session_destroy(sn); |
| |
63 } |
| |
64 } |
| |
65 |
| |
66 CX_TEST(test_dav_create_webdav) { |
| |
67 CX_TEST_DO { |
| |
68 DavSession *sn = get_test_webdav_session(); |
| |
69 // test1: check if the resource exists and create it after that |
| |
70 DavResource *res = dav_resource_new(sn, "/test_create.txt"); |
| |
71 CX_TEST_ASSERT(res); |
| |
72 int exists = dav_exists(res); // the resource should not exist yet |
| |
73 CX_TEST_ASSERT(!exists); |
| |
74 int ret = dav_create(res); // create the resource |
| |
75 CX_TEST_ASSERT(!ret); |
| |
76 exists = dav_exists(res); // the resource should exist now |
| |
77 CX_TEST_ASSERT(exists); |
| |
78 CX_TEST_ASSERT(res->lastmodified > 0); // some properties should be loaded by dav_exists() |
| |
79 CX_TEST_ASSERT(res->contenttype); |
| |
80 |
| |
81 // test2: create a resource without calling dav_exists first |
| |
82 DavResource *res2 = dav_resource_new(sn, "/test_create2.txt"); |
| |
83 ret = dav_create(res2); |
| |
84 CX_TEST_ASSERT(!ret); |
| |
85 CX_TEST_ASSERT(dav_exists(res2)); |
| |
86 CX_TEST_ASSERT(res2->lastmodified > 0); |
| |
87 CX_TEST_ASSERT(res2->contenttype); |
| |
88 |
| |
89 dav_session_destroy(sn); |
| |
90 } |
| |
91 } |
| |
92 |
| |
93 CX_TEST(test_dav_store_content_webdav) { |
| |
94 CX_TEST_DO { |
| |
95 DavSession *sn = get_test_webdav_session(); |
| |
96 DavResource *res = dav_resource_new(sn, "/test_store_content.txt"); |
| |
97 cxstring content = cx_str("test_store_content test content\n"); |
| |
98 dav_set_content_data(res, content.ptr, content.length); |
| |
99 int ret = dav_store(res); |
| |
100 CX_TEST_ASSERT(!ret); |
| |
101 CX_TEST_ASSERT(!dav_load(res)); |
| |
102 CX_TEST_ASSERT(res->contentlength == content.length); |
| |
103 dav_session_destroy(sn); |
| |
104 } |
| |
105 } |