33 #include "testutils.h" |
33 #include "testutils.h" |
34 |
34 |
35 #include "../webdav/requestparser.h" |
35 #include "../webdav/requestparser.h" |
36 #include "../webdav/webdav.h" |
36 #include "../webdav/webdav.h" |
37 #include "../webdav/multistatus.h" |
37 #include "../webdav/multistatus.h" |
|
38 #include "../webdav/operation.h" |
38 |
39 |
39 #include "webdav.h" |
40 #include "webdav.h" |
40 |
41 |
41 /* ----------------------------- Test Backends --------------------------*/ |
42 /* ----------------------------- Test Backends --------------------------*/ |
|
43 |
|
44 static int backend2_init_called = 0; |
|
45 static int backend2_propfind_do_called = 0; |
|
46 static int backend2_propfind_finish_called = 0; |
42 |
47 |
43 // backend2 |
48 // backend2 |
44 static int backend2_propfind_init( |
49 static int backend2_propfind_init( |
45 WebdavPropfindRequest *propfind, |
50 WebdavPropfindRequest *propfind, |
46 const char *path, |
51 const char *path, |
47 WebdavPList **outPList) |
52 WebdavPList **outPList) |
48 { |
53 { |
|
54 backend2_init_called = 1; |
49 return 0; |
55 return 0; |
50 } |
56 } |
51 |
57 |
52 static int backend2_propfind_do( |
58 static int backend2_propfind_do( |
53 WebdavPropfindRequest *propfind, |
59 WebdavPropfindRequest *propfind, |
54 WebdavResponse *response, |
60 WebdavResponse *response, |
55 VFS_DIR parent, |
61 VFS_DIR parent, |
56 WebdavResource *resource, |
62 WebdavResource *resource, |
57 struct stat *s) |
63 struct stat *s) |
58 { |
64 { |
|
65 backend2_propfind_do_called = 1; |
59 return 0; |
66 return 0; |
60 } |
67 } |
61 |
68 |
62 static int backend2_propfind_finish(WebdavPropfindRequest *propfind) { |
69 static int backend2_propfind_finish(WebdavPropfindRequest *propfind) { |
|
70 backend2_propfind_finish_called = 1; |
63 return 0; |
71 return 0; |
64 } |
72 } |
65 |
73 |
66 static WebdavBackend backend2 = { |
74 static WebdavBackend backend2 = { |
67 backend2_propfind_init, |
75 backend2_propfind_init, |
70 0, |
78 0, |
71 NULL |
79 NULL |
72 }; |
80 }; |
73 |
81 |
74 // backend1 |
82 // backend1 |
|
83 |
|
84 static int backend1_init_called = 0; |
|
85 static int backend1_propfind_do_called = 0; |
|
86 static int backend1_propfind_finish_called = 0; |
|
87 |
|
88 |
75 static int backend1_propfind_init( |
89 static int backend1_propfind_init( |
76 WebdavPropfindRequest *propfind, |
90 WebdavPropfindRequest *propfind, |
77 const char *path, |
91 const char *path, |
78 WebdavPList **outPList) |
92 WebdavPList **outPList) |
79 { |
93 { |
|
94 backend1_init_called = 1; |
|
95 |
80 WebdavPList *plist = *outPList; |
96 WebdavPList *plist = *outPList; |
81 WebdavProperty *p = plist->property; |
97 WebdavProperty *p = plist->property; |
82 if(!strcmp(p->name, "displayname")) { |
98 if(!strcmp(p->name, "displayname")) { |
83 plist->next->prev = NULL; |
99 plist->next->prev = NULL; |
84 *outPList = plist->next; // remove first item from plist |
100 *outPList = plist->next; // remove first item from plist |
94 WebdavResponse *response, |
110 WebdavResponse *response, |
95 VFS_DIR parent, |
111 VFS_DIR parent, |
96 WebdavResource *resource, |
112 WebdavResource *resource, |
97 struct stat *s) |
113 struct stat *s) |
98 { |
114 { |
|
115 backend1_propfind_do_called = 1; |
99 return 0; |
116 return 0; |
100 } |
117 } |
101 |
118 |
102 static int backend1_propfind_finish(WebdavPropfindRequest *propfind) { |
119 static int backend1_propfind_finish(WebdavPropfindRequest *propfind) { |
|
120 backend1_propfind_finish_called = 1; |
103 return 0; |
121 return 0; |
104 } |
122 } |
105 |
123 |
106 WebdavBackend backend1 = { |
124 WebdavBackend backend1 = { |
107 backend1_propfind_init, |
125 backend1_propfind_init, |
108 backend1_propfind_do, |
126 backend1_propfind_do, |
109 backend1_propfind_finish, |
127 backend1_propfind_finish, |
110 0, |
128 0, |
111 &backend2 |
129 &backend2 |
112 }; |
130 }; |
|
131 |
|
132 static void reset_backends(void) { |
|
133 backend1_init_called = 0; |
|
134 backend1_propfind_do_called = 0; |
|
135 backend1_propfind_finish_called = 0; |
|
136 backend2_init_called = 0; |
|
137 backend2_propfind_do_called = 0; |
|
138 backend2_propfind_finish_called = 0; |
|
139 } |
113 |
140 |
114 /* ----------------------------------------------------------------------*/ |
141 /* ----------------------------------------------------------------------*/ |
115 |
142 |
116 |
143 |
117 static int test_init( |
144 static int test_init( |
144 *out_rq = rq; |
171 *out_rq = rq; |
145 *out_propfind = propfind; |
172 *out_propfind = propfind; |
146 return 0; |
173 return 0; |
147 } |
174 } |
148 |
175 |
|
176 static WebdavOperation* test_propfind_op( |
|
177 Session **out_sn, |
|
178 Request **out_rq, |
|
179 const char *xml) |
|
180 { |
|
181 WebdavPropfindRequest *propfind; |
|
182 if(test_init(out_sn, out_rq, &propfind, xml)) { |
|
183 return NULL; |
|
184 } |
|
185 |
|
186 Multistatus *ms = multistatus_response(*out_sn, *out_rq); |
|
187 if(!ms) { |
|
188 return NULL; |
|
189 } |
|
190 // WebdavResponse is the public interface used by Backends |
|
191 // for adding resources to the response |
|
192 WebdavResponse *response = (WebdavResponse*)ms; |
|
193 |
|
194 UcxList *requests = NULL; |
|
195 |
|
196 // Initialize all Webdav Backends |
|
197 if(webdav_propfind_init(&backend1, propfind, "/", &requests)) { |
|
198 return NULL; |
|
199 } |
|
200 |
|
201 return webdav_operation_create( |
|
202 (*out_sn)->pool, |
|
203 &backend1, |
|
204 requests, |
|
205 response); |
|
206 } |
149 |
207 |
150 UCX_TEST(test_propfind_parse) { |
208 UCX_TEST(test_propfind_parse) { |
151 Session *sn = testutil_session(); |
209 Session *sn = testutil_session(); |
152 Request *rq = testutil_request(sn->pool, "PROPFIND", "/"); |
210 Request *rq = testutil_request(sn->pool, "PROPFIND", "/"); |
153 |
211 |
679 |
737 |
680 UCX_TEST_END; |
738 UCX_TEST_END; |
681 } |
739 } |
682 |
740 |
683 UCX_TEST(test_webdav_propfind_init) { |
741 UCX_TEST(test_webdav_propfind_init) { |
|
742 reset_backends(); |
|
743 |
684 Session *sn; |
744 Session *sn; |
685 Request *rq; |
745 Request *rq; |
686 WebdavPropfindRequest *propfind; |
746 WebdavPropfindRequest *propfind; |
687 UCX_TEST_BEGIN; |
747 UCX_TEST_BEGIN; |
688 UCX_TEST_ASSERT(!test_init(&sn, &rq, &propfind, TEST_PROPFIND1), "init failed"); |
748 UCX_TEST_ASSERT(!test_init(&sn, &rq, &propfind, TEST_PROPFIND1), "init failed"); |
703 UCX_TEST_ASSERT(p1 && p2, "missing requests objects"); |
763 UCX_TEST_ASSERT(p1 && p2, "missing requests objects"); |
704 UCX_TEST_ASSERT(p1 != p2, "request objects equal"); |
764 UCX_TEST_ASSERT(p1 != p2, "request objects equal"); |
705 UCX_TEST_ASSERT(p1->properties != p2->properties, "plists equal"); |
765 UCX_TEST_ASSERT(p1->properties != p2->properties, "plists equal"); |
706 UCX_TEST_ASSERT(p1->propcount == p2->propcount + 1, "first property not removed"); |
766 UCX_TEST_ASSERT(p1->propcount == p2->propcount + 1, "first property not removed"); |
707 |
767 |
|
768 UCX_TEST_ASSERT(backend1_init_called == 1, "backend1 init not called"); |
|
769 UCX_TEST_ASSERT(backend2_init_called == 1, "backend2 init not called"); |
|
770 |
708 UCX_TEST_END; |
771 UCX_TEST_END; |
709 |
772 |
710 pool_destroy(sn->pool); |
773 pool_destroy(sn->pool); |
711 } |
774 } |
|
775 |
|
776 UCX_TEST(test_webdav_op_propfind_begin) { |
|
777 reset_backends(); |
|
778 |
|
779 Session *sn; |
|
780 Request *rq; |
|
781 |
|
782 UCX_TEST_BEGIN; |
|
783 WebdavOperation *op = test_propfind_op(&sn, &rq, TEST_PROPFIND1); |
|
784 UCX_TEST_ASSERT(op, "WebdavOperation not created"); |
|
785 |
|
786 int err = webdav_op_propfind_begin(op, "/", NULL, NULL); |
|
787 UCX_TEST_ASSERT(err == 0, "err not 0"); |
|
788 UCX_TEST_ASSERT(backend1_propfind_do_called == 1, "backend1 propfind_do not called"); |
|
789 UCX_TEST_ASSERT(backend2_propfind_do_called == 1, "backend2 propfind_do not called"); |
|
790 |
|
791 |
|
792 UCX_TEST_END; |
|
793 } |