| 228 xmlFreeDoc(ms->doc); |
228 xmlFreeDoc(ms->doc); |
| 229 cxMempoolFree(ms->mp); |
229 cxMempoolFree(ms->mp); |
| 230 } |
230 } |
| 231 |
231 |
| 232 |
232 |
| 233 UCX_TEST(test_pg_conn) { |
233 CX_TEST(test_pg_conn) { |
| 234 char *msg = test_connection ? PQerrorMessage(test_connection) : "no connection"; |
234 char *msg = test_connection ? PQerrorMessage(test_connection) : "no connection"; |
| 235 |
235 |
| 236 UCX_TEST_BEGIN; |
236 CX_TEST_DO { |
| 237 |
237 |
| 238 if(abort_pg_tests) { |
238 if(abort_pg_tests) { |
| 239 int msglen = strlen(msg); |
239 int msglen = strlen(msg); |
| 240 if(msglen > 0 && msg[msglen-1] == '\n') { |
240 if(msglen > 0 && msg[msglen-1] == '\n') { |
| 241 msglen--; |
241 msglen--; |
| |
242 } |
| |
243 fprintf(stdout, "%.*s: ", msglen, msg); |
| |
244 CX_TEST_ASSERT(1 == 0); |
| |
245 } else { |
| |
246 CX_TEST_ASSERT(1 == 1); |
| 242 } |
247 } |
| 243 fprintf(stdout, "%.*s: ", msglen, msg); |
248 |
| 244 UCX_TEST_ASSERT(1 == 0, "skip pg tests"); |
249 } |
| 245 } else { |
250 } |
| 246 UCX_TEST_ASSERT(1 == 1, "ok"); |
251 |
| 247 } |
252 CX_TEST(test_pg_lookup_root) { |
| 248 |
253 CX_TEST_DO { |
| 249 UCX_TEST_END; |
254 // test already done in test_root_lookup() |
| 250 } |
255 CX_TEST_ASSERT(!abort_pg_tests); |
| 251 |
256 } |
| 252 UCX_TEST(test_pg_lookup_root) { |
|
| 253 UCX_TEST_BEGIN; |
|
| 254 |
|
| 255 // test already done in test_root_lookup() |
|
| 256 UCX_TEST_ASSERT(!abort_pg_tests, "Lookup failed"); |
|
| 257 |
|
| 258 UCX_TEST_END; |
|
| 259 } |
257 } |
| 260 |
258 |
| 261 |
259 |
| 262 static VFS* create_test_pgvfs(Session *sn, Request *rq) { |
260 static VFS* create_test_pgvfs(Session *sn, Request *rq) { |
| 263 return pg_vfs_create_from_resourcedata(sn, rq, &test_repo, &resdata); |
261 return pg_vfs_create_from_resourcedata(sn, rq, &test_repo, &resdata); |
| 264 } |
262 } |
| 265 |
263 |
| 266 |
264 |
| 267 UCX_TEST(test_pg_vfs_open) { |
265 CX_TEST(test_pg_vfs_open) { |
| 268 Session *sn = testutil_session(); |
266 Session *sn = testutil_session(); |
| 269 Request *rq = testutil_request(sn->pool, "PUT", "/"); |
267 Request *rq = testutil_request(sn->pool, "PUT", "/"); |
| 270 rq->vfs = create_test_pgvfs(sn, rq); |
268 rq->vfs = create_test_pgvfs(sn, rq); |
| 271 VFSContext *vfs = vfs_request_context(sn, rq); |
269 VFSContext *vfs = vfs_request_context(sn, rq); |
| 272 SYS_FILE file; |
270 SYS_FILE file; |
| 273 |
271 |
| 274 UCX_TEST_BEGIN; |
272 CX_TEST_DO { |
| 275 |
273 |
| 276 file = vfs_open(vfs, "/test_notfound1", O_RDONLY); |
274 file = vfs_open(vfs, "/test_notfound1", O_RDONLY); |
| 277 UCX_TEST_ASSERT(!file, "/test_notfound should not exist"); |
275 CX_TEST_ASSERT(!file); |
| 278 |
276 |
| 279 file = vfs_open(vfs, "/test_file1", O_RDWR | O_CREAT); |
277 file = vfs_open(vfs, "/test_file1", O_RDWR | O_CREAT); |
| 280 UCX_TEST_ASSERT(file, "cannot create file 1"); |
278 CX_TEST_ASSERT(file); |
| 281 |
279 |
| 282 vfs_close(file); |
280 vfs_close(file); |
| 283 |
281 |
| 284 UCX_TEST_END; |
282 } |
| 285 |
283 |
| 286 testutil_destroy_session(sn); |
284 testutil_destroy_session(sn); |
| 287 } |
285 } |
| 288 |
286 |
| 289 UCX_TEST(test_pg_vfs_io) { |
287 CX_TEST(test_pg_vfs_io) { |
| 290 Session *sn = testutil_session(); |
288 Session *sn = testutil_session(); |
| 291 Request *rq = testutil_request(sn->pool, "PUT", "/"); |
289 Request *rq = testutil_request(sn->pool, "PUT", "/"); |
| 292 rq->vfs = create_test_pgvfs(sn, rq); |
290 rq->vfs = create_test_pgvfs(sn, rq); |
| 293 VFSContext *vfs = vfs_request_context(sn, rq); |
291 VFSContext *vfs = vfs_request_context(sn, rq); |
| 294 SYS_FILE file; |
292 SYS_FILE file; |
| 295 SYS_FILE file2; |
293 SYS_FILE file2; |
| 296 |
294 |
| 297 UCX_TEST_BEGIN; |
295 CX_TEST_DO { |
| 298 |
296 |
| 299 file = vfs_open(vfs, "/test_f1", O_WRONLY | O_CREAT); |
297 file = vfs_open(vfs, "/test_f1", O_WRONLY | O_CREAT); |
| 300 UCX_TEST_ASSERT(file, "cannot open file1"); |
298 CX_TEST_ASSERT(file); |
| 301 |
299 |
| 302 int w = system_fwrite(file, "test1\n", 6); |
300 int w = system_fwrite(file, "test1\n", 6); |
| 303 UCX_TEST_ASSERT(w == 6, "fwrite ret (1)"); |
301 CX_TEST_ASSERT(w == 6); |
| 304 w = system_fwrite(file, "2", 1); |
302 w = system_fwrite(file, "2", 1); |
| 305 UCX_TEST_ASSERT(w == 1, "fwrite ret (2)"); |
303 CX_TEST_ASSERT(w == 1); |
| 306 |
304 |
| 307 vfs_close(file); |
305 vfs_close(file); |
| 308 |
306 |
| 309 file = vfs_open(vfs, "/test_f1", O_RDONLY); |
307 file = vfs_open(vfs, "/test_f1", O_RDONLY); |
| 310 file2 = vfs_open(vfs, "/test_f2", O_WRONLY | O_CREAT); |
308 file2 = vfs_open(vfs, "/test_f2", O_WRONLY | O_CREAT); |
| 311 UCX_TEST_ASSERT(file, "cannot open file1"); |
309 CX_TEST_ASSERT(file); |
| 312 UCX_TEST_ASSERT(file2, "cannot open file2"); |
310 CX_TEST_ASSERT(file2); |
| 313 |
311 |
| 314 char buf[128]; |
312 char buf[128]; |
| 315 int r = system_fread(file, buf, 128); |
313 int r = system_fread(file, buf, 128); |
| 316 UCX_TEST_ASSERT(r == 7, "cannot read from file1"); |
314 CX_TEST_ASSERT(r == 7); |
| 317 |
315 |
| 318 w = system_fwrite(file2, buf, r); |
316 w = system_fwrite(file2, buf, r); |
| 319 UCX_TEST_ASSERT(w == 7, "cannot write to file2"); |
317 CX_TEST_ASSERT(w == 7); |
| 320 |
318 |
| 321 vfs_close(file); |
319 vfs_close(file); |
| 322 vfs_close(file2); |
320 vfs_close(file2); |
| 323 |
321 |
| 324 file2 = vfs_open(vfs, "/test_f2", O_RDONLY); |
322 file2 = vfs_open(vfs, "/test_f2", O_RDONLY); |
| 325 |
323 |
| 326 r = system_fread(file, buf, 128); |
324 r = system_fread(file, buf, 128); |
| 327 UCX_TEST_ASSERT(r == 7, "fread ret"); |
325 CX_TEST_ASSERT(r == 7); |
| 328 UCX_TEST_ASSERT(!memcmp(buf, "test1\n2", 7), "wrong buffer content after read"); |
326 CX_TEST_ASSERT(!memcmp(buf, "test1\n2", 7)); |
| 329 |
327 |
| 330 vfs_close(file2); |
328 vfs_close(file2); |
| 331 |
329 |
| 332 |
330 |
| 333 UCX_TEST_END; |
331 } |
| 334 |
332 |
| 335 testutil_destroy_session(sn); |
333 testutil_destroy_session(sn); |
| 336 } |
334 } |
| 337 |
335 |
| 338 UCX_TEST(test_pg_vfs_stat) { |
336 CX_TEST(test_pg_vfs_stat) { |
| 339 Session *sn = testutil_session(); |
337 Session *sn = testutil_session(); |
| 340 Request *rq = testutil_request(sn->pool, "PUT", "/"); |
338 Request *rq = testutil_request(sn->pool, "PUT", "/"); |
| 341 rq->vfs = create_test_pgvfs(sn, rq); |
339 rq->vfs = create_test_pgvfs(sn, rq); |
| 342 VFSContext *vfs = vfs_request_context(sn, rq); |
340 VFSContext *vfs = vfs_request_context(sn, rq); |
| 343 |
341 |
| 344 UCX_TEST_BEGIN; |
342 CX_TEST_DO { |
| 345 |
343 |
| 346 // testdata, content doesn't matter |
344 // testdata, content doesn't matter |
| 347 char test1[512]; |
345 char test1[512]; |
| 348 memset(test1, 'x', 512); |
346 memset(test1, 'x', 512); |
| 349 const int test_len1 = 200; |
347 const int test_len1 = 200; |
| 350 const int test_len2 = 432; |
348 const int test_len2 = 432; |
| 351 |
349 |
| 352 SYS_FILE f1 = vfs_open(vfs, "/test_s1", O_WRONLY|O_CREAT); |
350 SYS_FILE f1 = vfs_open(vfs, "/test_s1", O_WRONLY|O_CREAT); |
| 353 UCX_TEST_ASSERT(f1, "cannot open test_s1"); |
351 CX_TEST_ASSERT(f1); |
| 354 system_fwrite(f1, test1, test_len1); |
352 system_fwrite(f1, test1, test_len1); |
| 355 vfs_close(f1); |
353 vfs_close(f1); |
| 356 |
354 |
| 357 SYS_FILE f2 = vfs_open(vfs, "/test_s2", O_RDWR|O_CREAT); |
355 SYS_FILE f2 = vfs_open(vfs, "/test_s2", O_RDWR|O_CREAT); |
| 358 UCX_TEST_ASSERT(f2, "cannot open test_s2"); |
356 CX_TEST_ASSERT(f2); |
| 359 system_fwrite(f2, test1, test_len2); |
357 system_fwrite(f2, test1, test_len2); |
| 360 vfs_close(f2); |
358 vfs_close(f2); |
| 361 |
359 |
| 362 struct stat st1, st2; |
360 struct stat st1, st2; |
| 363 int r1 = vfs_stat(vfs, "/test_s1", &st1); |
361 int r1 = vfs_stat(vfs, "/test_s1", &st1); |
| 364 int r2 = vfs_stat(vfs, "/test_s2", &st2); |
362 int r2 = vfs_stat(vfs, "/test_s2", &st2); |
| 365 |
363 |
| 366 UCX_TEST_ASSERT(r1 == 0, "stat1 failed"); |
364 CX_TEST_ASSERT(r1 == 0); |
| 367 UCX_TEST_ASSERT(r2 == 0, "stat2 failed"); |
365 CX_TEST_ASSERT(r2 == 0); |
| 368 |
366 |
| 369 UCX_TEST_ASSERT(st1.st_size == test_len1, "s1 wrong length"); |
367 CX_TEST_ASSERT(st1.st_size == test_len1); |
| 370 UCX_TEST_ASSERT(st2.st_size == test_len2, "s2 wrong length"); |
368 CX_TEST_ASSERT(st2.st_size == test_len2); |
| 371 |
369 |
| 372 int testfail = vfs_stat(vfs, "/test_stat_fail", &st1); |
370 int testfail = vfs_stat(vfs, "/test_stat_fail", &st1); |
| 373 UCX_TEST_ASSERT(testfail != 0, "stat 3 should fail"); |
371 CX_TEST_ASSERT(testfail != 0); |
| 374 |
372 |
| 375 UCX_TEST_END; |
373 } |
| 376 |
374 |
| 377 testutil_destroy_session(sn); |
375 testutil_destroy_session(sn); |
| 378 } |
376 } |
| 379 |
377 |
| 380 UCX_TEST(test_pg_vfs_mkdir) { |
378 CX_TEST(test_pg_vfs_mkdir) { |
| 381 Session *sn = testutil_session(); |
379 Session *sn = testutil_session(); |
| 382 Request *rq = testutil_request(sn->pool, "PUT", "/"); |
380 Request *rq = testutil_request(sn->pool, "PUT", "/"); |
| 383 rq->vfs = create_test_pgvfs(sn, rq); |
381 rq->vfs = create_test_pgvfs(sn, rq); |
| 384 VFSContext *vfs = vfs_request_context(sn, rq); |
382 VFSContext *vfs = vfs_request_context(sn, rq); |
| 385 |
383 |
| 386 UCX_TEST_BEGIN; |
384 CX_TEST_DO { |
| 387 |
385 |
| 388 struct stat s; |
386 struct stat s; |
| 389 |
387 |
| 390 SYS_FILE f1 = vfs_open(vfs, "/test_mkdir/file", O_WRONLY|O_CREAT); |
388 SYS_FILE f1 = vfs_open(vfs, "/test_mkdir/file", O_WRONLY|O_CREAT); |
| 391 UCX_TEST_ASSERT(f1 == NULL, "open should fail"); |
389 CX_TEST_ASSERT(f1 == NULL); |
| 392 |
390 |
| 393 int r = vfs_mkdir(vfs, "/test_mkdir"); |
391 int r = vfs_mkdir(vfs, "/test_mkdir"); |
| 394 UCX_TEST_ASSERT(r == 0, "mkdir failed"); |
392 CX_TEST_ASSERT(r == 0); |
| 395 |
393 |
| 396 r = vfs_stat(vfs, "/test_mkdir", &s); |
394 r = vfs_stat(vfs, "/test_mkdir", &s); |
| 397 UCX_TEST_ASSERT(r == 0, "stat (1) failed"); |
395 CX_TEST_ASSERT(r == 0); |
| 398 |
396 |
| 399 UCX_TEST_ASSERT(S_ISDIR(s.st_mode), "/test_mkdir is not a directory"); |
397 CX_TEST_ASSERT(S_ISDIR(s.st_mode)); |
| 400 |
398 |
| 401 f1 = vfs_open(vfs, "/test_mkdir/file", O_WRONLY|O_CREAT); |
399 f1 = vfs_open(vfs, "/test_mkdir/file", O_WRONLY|O_CREAT); |
| 402 vfs_close(f1); |
400 vfs_close(f1); |
| 403 UCX_TEST_ASSERT(f1, "open failed"); |
401 CX_TEST_ASSERT(f1); |
| 404 |
402 |
| 405 r = vfs_stat(vfs, "/test_mkdir/file", &s); |
403 r = vfs_stat(vfs, "/test_mkdir/file", &s); |
| 406 UCX_TEST_ASSERT(r == 0, "stat (2) failed"); |
404 CX_TEST_ASSERT(r == 0); |
| 407 |
405 |
| 408 r = vfs_mkdir(vfs, "/test_mkdir/test_sub"); |
406 r = vfs_mkdir(vfs, "/test_mkdir/test_sub"); |
| 409 UCX_TEST_ASSERT(r == 0, "mkdir failed (2)"); |
407 CX_TEST_ASSERT(r == 0); |
| 410 |
408 |
| 411 r = vfs_stat(vfs, "/test_mkdir/test_sub", &s); |
409 r = vfs_stat(vfs, "/test_mkdir/test_sub", &s); |
| 412 UCX_TEST_ASSERT(r == 0, "stat (3) failed"); |
410 CX_TEST_ASSERT(r == 0); |
| 413 UCX_TEST_ASSERT(S_ISDIR(s.st_mode), "/test_mkdir/test_sub is not a directory"); |
411 CX_TEST_ASSERT(S_ISDIR(s.st_mode)); |
| 414 |
412 |
| 415 r = vfs_mkdir(vfs, "/test_mkdir/test_sub/test_sub2/"); |
413 r = vfs_mkdir(vfs, "/test_mkdir/test_sub/test_sub2/"); |
| 416 UCX_TEST_ASSERT(r == 0, "mkdir failed (4)"); |
414 CX_TEST_ASSERT(r == 0); |
| 417 |
415 |
| 418 r = vfs_stat(vfs, "/test_mkdir/test_sub/test_sub2/", &s); |
416 r = vfs_stat(vfs, "/test_mkdir/test_sub/test_sub2/", &s); |
| 419 UCX_TEST_ASSERT(r == 0, "stat (4) failed"); |
417 CX_TEST_ASSERT(r == 0); |
| 420 UCX_TEST_ASSERT(S_ISDIR(s.st_mode), "/test_mkdir/test_sub/test_sub2/ is not a directory"); |
418 CX_TEST_ASSERT(S_ISDIR(s.st_mode)); |
| 421 |
419 |
| 422 UCX_TEST_END; |
420 } |
| 423 |
421 |
| 424 testutil_destroy_session(sn); |
422 testutil_destroy_session(sn); |
| 425 } |
423 } |
| 426 |
424 |
| 427 UCX_TEST(test_pg_vfs_unlink) { |
425 CX_TEST(test_pg_vfs_unlink) { |
| 428 Session *sn = testutil_session(); |
426 Session *sn = testutil_session(); |
| 429 Request *rq = testutil_request(sn->pool, "PUT", "/"); |
427 Request *rq = testutil_request(sn->pool, "PUT", "/"); |
| 430 rq->vfs = create_test_pgvfs(sn, rq); |
428 rq->vfs = create_test_pgvfs(sn, rq); |
| 431 VFSContext *vfs = vfs_request_context(sn, rq); |
429 VFSContext *vfs = vfs_request_context(sn, rq); |
| 432 |
430 |
| 433 UCX_TEST_BEGIN; |
431 CX_TEST_DO { |
| 434 |
432 |
| 435 SYS_FILE f1 = vfs_open(vfs, "/test_unlink1", O_WRONLY|O_CREAT); |
433 SYS_FILE f1 = vfs_open(vfs, "/test_unlink1", O_WRONLY|O_CREAT); |
| 436 UCX_TEST_ASSERT(f1, "cannot create test file"); |
434 CX_TEST_ASSERT(f1); |
| 437 system_fwrite(f1, "test", 4); |
435 system_fwrite(f1, "test", 4); |
| 438 |
436 |
| 439 PgFile *pgfile = f1->data; |
437 PgFile *pgfile = f1->data; |
| 440 Oid oid = pgfile->oid; |
438 Oid oid = pgfile->oid; |
| 441 |
439 |
| 442 vfs_close(f1); |
440 vfs_close(f1); |
| 443 |
441 |
| 444 int r = vfs_unlink(vfs, "/test_unlink1"); |
442 int r = vfs_unlink(vfs, "/test_unlink1"); |
| 445 UCX_TEST_ASSERT(r == 0, "unlink failed"); |
443 CX_TEST_ASSERT(r == 0); |
| 446 |
444 |
| 447 f1 = vfs_open(vfs, "/test_unlink1", O_RDONLY); |
445 f1 = vfs_open(vfs, "/test_unlink1", O_RDONLY); |
| 448 UCX_TEST_ASSERT(f1 == NULL, "test file not deleted"); |
446 CX_TEST_ASSERT(f1 == NULL); |
| 449 |
447 |
| 450 PGresult *result = PQexec(test_connection, "savepoint sp;"); |
448 PGresult *result = PQexec(test_connection, "savepoint sp;"); |
| 451 PQclear(result); |
449 PQclear(result); |
| 452 int pgfd = lo_open(test_connection, oid, INV_READ); |
450 int pgfd = lo_open(test_connection, oid, INV_READ); |
| 453 UCX_TEST_ASSERT(pgfd < 0, "large object not deleted"); |
451 CX_TEST_ASSERT(pgfd < 0); |
| 454 result = PQexec(test_connection, "rollback to savepoint sp;"); |
452 result = PQexec(test_connection, "rollback to savepoint sp;"); |
| 455 PQclear(result); |
453 PQclear(result); |
| 456 |
454 |
| 457 r = vfs_unlink(vfs, "/test_unlink1"); |
455 r = vfs_unlink(vfs, "/test_unlink1"); |
| 458 UCX_TEST_ASSERT(r, "unlink should fail"); |
456 CX_TEST_ASSERT(r); |
| 459 |
457 |
| 460 UCX_TEST_END; |
458 } |
| 461 |
459 |
| 462 testutil_destroy_session(sn); |
460 testutil_destroy_session(sn); |
| 463 } |
461 } |
| 464 |
462 |
| 465 UCX_TEST(test_pg_vfs_rmdir) { |
463 CX_TEST(test_pg_vfs_rmdir) { |
| 466 Session *sn = testutil_session(); |
464 Session *sn = testutil_session(); |
| 467 Request *rq = testutil_request(sn->pool, "PUT", "/"); |
465 Request *rq = testutil_request(sn->pool, "PUT", "/"); |
| 468 rq->vfs = create_test_pgvfs(sn, rq); |
466 rq->vfs = create_test_pgvfs(sn, rq); |
| 469 VFSContext *vfs = vfs_request_context(sn, rq); |
467 VFSContext *vfs = vfs_request_context(sn, rq); |
| 470 |
468 |
| 471 PQexec(test_connection, "delete from Resource where parent_id is not null;"); |
469 PQexec(test_connection, "delete from Resource where parent_id is not null;"); |
| 472 |
470 |
| 473 UCX_TEST_BEGIN; |
471 CX_TEST_DO { |
| 474 |
472 |
| 475 int r; |
473 int r; |
| 476 SYS_FILE f1; |
474 SYS_FILE f1; |
| 477 |
475 |
| 478 // prepare some dirs/files |
476 // prepare some dirs/files |
| 479 r = vfs_mkdir(vfs, "/rmdir_test"); |
477 r = vfs_mkdir(vfs, "/rmdir_test"); |
| 480 UCX_TEST_ASSERT(r == 0, "mkdir failed (1)"); |
478 CX_TEST_ASSERT(r == 0); |
| 481 r = vfs_mkdir(vfs, "/rmdir_test/subdir1"); |
479 r = vfs_mkdir(vfs, "/rmdir_test/subdir1"); |
| 482 UCX_TEST_ASSERT(r == 0, "mkdir failed (2)"); |
480 CX_TEST_ASSERT(r == 0); |
| 483 r = vfs_mkdir(vfs, "/rmdir_test/subdir2"); |
481 r = vfs_mkdir(vfs, "/rmdir_test/subdir2"); |
| 484 UCX_TEST_ASSERT(r == 0, "mkdir failed (3)"); |
482 CX_TEST_ASSERT(r == 0); |
| 485 |
483 |
| 486 f1 = vfs_open(vfs, "/rmdir_test/subdir2/file", O_CREAT|O_WRONLY); |
484 f1 = vfs_open(vfs, "/rmdir_test/subdir2/file", O_CREAT|O_WRONLY); |
| 487 UCX_TEST_ASSERT(f1, "open failed"); |
485 CX_TEST_ASSERT(f1); |
| 488 vfs_close(f1); |
486 vfs_close(f1); |
| 489 |
487 |
| 490 // test rmdir |
488 // test rmdir |
| 491 r = vfs_rmdir(vfs, "/rmdir_test/subdir1"); |
489 r = vfs_rmdir(vfs, "/rmdir_test/subdir1"); |
| 492 UCX_TEST_ASSERT(r == 0, "rmdir failed");; |
490 CX_TEST_ASSERT(r == 0); |
| 493 |
491 |
| 494 r = vfs_rmdir(vfs, "/rmdir_test/subdir2"); |
492 r = vfs_rmdir(vfs, "/rmdir_test/subdir2"); |
| 495 UCX_TEST_ASSERT(r != 0, "rmdir should fail if the dir is not empty"); |
493 CX_TEST_ASSERT(r != 0); |
| 496 |
494 |
| 497 r = vfs_unlink(vfs, "/rmdir_test/subdir2/file"); |
495 r = vfs_unlink(vfs, "/rmdir_test/subdir2/file"); |
| 498 UCX_TEST_ASSERT(r == 0, "unlink failed"); |
496 CX_TEST_ASSERT(r == 0); |
| 499 |
497 |
| 500 r = vfs_rmdir(vfs, "/rmdir_test/subdir2"); |
498 r = vfs_rmdir(vfs, "/rmdir_test/subdir2"); |
| 501 UCX_TEST_ASSERT(r == 0, "rmdir failed 2"); |
499 CX_TEST_ASSERT(r == 0); |
| 502 |
500 |
| 503 UCX_TEST_END; |
501 } |
| 504 |
502 |
| 505 testutil_destroy_session(sn); |
503 testutil_destroy_session(sn); |
| 506 } |
504 } |
| 507 |
505 |
| 508 /* ----------------------------- WebDAV tests ----------------------------- */ |
506 /* ----------------------------- WebDAV tests ----------------------------- */ |
| 510 |
508 |
| 511 static WebdavBackend* create_test_pgdav(Session *sn, Request *rq) { |
509 static WebdavBackend* create_test_pgdav(Session *sn, Request *rq) { |
| 512 return pg_webdav_create_from_resdata(sn, rq, &test_repo, &resdata); |
510 return pg_webdav_create_from_resdata(sn, rq, &test_repo, &resdata); |
| 513 } |
511 } |
| 514 |
512 |
| 515 UCX_TEST(test_pg_webdav_create_from_resdata) { |
513 CX_TEST(test_pg_webdav_create_from_resdata) { |
| 516 Session *sn = testutil_session(); |
514 Session *sn = testutil_session(); |
| 517 Request *rq = testutil_request(sn->pool, "PROPFIND", "/"); |
515 Request *rq = testutil_request(sn->pool, "PROPFIND", "/"); |
| 518 |
516 |
| 519 UCX_TEST_BEGIN; |
517 CX_TEST_DO { |
| 520 |
518 |
| 521 WebdavBackend *dav = create_test_pgdav(sn, rq); |
519 WebdavBackend *dav = create_test_pgdav(sn, rq); |
| 522 UCX_TEST_ASSERT(dav, "cannot create pg dav backend"); |
520 CX_TEST_ASSERT(dav); |
| 523 |
521 |
| 524 UCX_TEST_END; |
522 } |
| 525 } |
523 } |
| 526 |
524 |
| 527 UCX_TEST(test_pg_prepare_tests) { |
525 CX_TEST(test_pg_prepare_tests) { |
| 528 Session *sn = testutil_session(); |
526 Session *sn = testutil_session(); |
| 529 Request *rq = testutil_request(sn->pool, "PUT", "/"); |
527 Request *rq = testutil_request(sn->pool, "PUT", "/"); |
| 530 rq->vfs = create_test_pgvfs(sn, rq); |
528 rq->vfs = create_test_pgvfs(sn, rq); |
| 531 VFSContext *vfs = vfs_request_context(sn, rq); |
529 VFSContext *vfs = vfs_request_context(sn, rq); |
| 532 |
530 |
| 533 UCX_TEST_BEGIN; |
531 CX_TEST_DO { |
| 534 |
532 |
| 535 vfs_mkdir(vfs, "/propfind"); |
533 vfs_mkdir(vfs, "/propfind"); |
| 536 vfs_mkdir(vfs, "/proppatch"); |
534 vfs_mkdir(vfs, "/proppatch"); |
| 537 SYS_FILE f1; |
535 SYS_FILE f1; |
| 538 |
536 |
| 539 int64_t res1_id, res2_id; |
537 int64_t res1_id, res2_id; |
| 540 |
538 |
| 541 f1 = vfs_open(vfs, "/propfind/res1", O_WRONLY|O_CREAT); |
539 f1 = vfs_open(vfs, "/propfind/res1", O_WRONLY|O_CREAT); |
| 542 UCX_TEST_ASSERT(f1, "res1 create failed"); |
540 CX_TEST_ASSERT(f1); |
| 543 res1_id = ((PgFile*)f1->data)->resource_id; |
541 res1_id = ((PgFile*)f1->data)->resource_id; |
| 544 vfs_close(f1); |
542 vfs_close(f1); |
| 545 |
543 |
| 546 f1 = vfs_open(vfs, "/propfind/res2", O_WRONLY|O_CREAT); |
544 f1 = vfs_open(vfs, "/propfind/res2", O_WRONLY|O_CREAT); |
| 547 UCX_TEST_ASSERT(f1, "res2 create failed"); |
545 CX_TEST_ASSERT(f1); |
| 548 res2_id = ((PgFile*)f1->data)->resource_id; |
546 res2_id = ((PgFile*)f1->data)->resource_id; |
| 549 vfs_close(f1); |
547 vfs_close(f1); |
| 550 |
548 |
| 551 f1 = vfs_open(vfs, "/propfind/res3", O_WRONLY|O_CREAT); |
549 f1 = vfs_open(vfs, "/propfind/res3", O_WRONLY|O_CREAT); |
| 552 UCX_TEST_ASSERT(f1, "res3 create failed"); |
550 CX_TEST_ASSERT(f1); |
| 553 vfs_close(f1); |
551 vfs_close(f1); |
| 554 |
552 |
| 555 int r = vfs_mkdir(vfs, "/propfind/sub"); |
553 int r = vfs_mkdir(vfs, "/propfind/sub"); |
| 556 UCX_TEST_ASSERT(r == 0, "sub create failed"); |
554 CX_TEST_ASSERT(r == 0); |
| 557 |
555 |
| 558 f1 = vfs_open(vfs, "/propfind/sub/res4", O_WRONLY|O_CREAT); |
556 f1 = vfs_open(vfs, "/propfind/sub/res4", O_WRONLY|O_CREAT); |
| 559 UCX_TEST_ASSERT(f1, "res4 create failed"); |
557 CX_TEST_ASSERT(f1); |
| 560 vfs_close(f1); |
558 vfs_close(f1); |
| 561 |
559 |
| 562 f1 = vfs_open(vfs, "/proppatch/pp1", O_WRONLY|O_CREAT); |
560 f1 = vfs_open(vfs, "/proppatch/pp1", O_WRONLY|O_CREAT); |
| 563 UCX_TEST_ASSERT(f1, "pp1 create failed"); |
561 CX_TEST_ASSERT(f1); |
| 564 vfs_close(f1); |
562 vfs_close(f1); |
| 565 |
563 |
| 566 // 2 properties for res1 |
564 // 2 properties for res1 |
| 567 char idstr[32]; |
565 char idstr[32]; |
| 568 snprintf(idstr, 32, "%" PRId64, res1_id); |
566 snprintf(idstr, 32, "%" PRId64, res1_id); |
| 569 const char* params[1] = { idstr }; |
567 const char* params[1] = { idstr }; |
| 570 PGresult *result = PQexecParams( |
568 PGresult *result = PQexecParams( |
| 571 test_connection, |
569 test_connection, |
| 572 "insert into Property(resource_id, prefix, xmlns, pname, pvalue) values ($1, 'x', 'http://example.com/', 'test', 'testvalue');", |
570 "insert into Property(resource_id, prefix, xmlns, pname, pvalue) values ($1, 'x', 'http://example.com/', 'test', 'testvalue');", |
| 573 1, // number of parameters |
571 1, // number of parameters |
| 574 NULL, |
572 NULL, |
| 575 params, // parameter value |
573 params, // parameter value |
| 576 NULL, |
574 NULL, |
| 577 NULL, |
575 NULL, |
| 578 0); // 0: result in text format |
576 0); // 0: result in text format |
| 579 |
577 |
| 580 UCX_TEST_ASSERT(PQresultStatus(result) == PGRES_COMMAND_OK, "cannot create property 1"); |
578 CX_TEST_ASSERT(PQresultStatus(result) == PGRES_COMMAND_OK); |
| 581 PQclear(result); |
579 PQclear(result); |
| 582 |
580 |
| 583 result = PQexecParams( |
581 result = PQexecParams( |
| 584 test_connection, |
582 test_connection, |
| 585 "insert into Property(resource_id, prefix, xmlns, pname, pvalue) values ($1, 'x', 'http://example.com/', 'prop2', 'value2');", |
583 "insert into Property(resource_id, prefix, xmlns, pname, pvalue) values ($1, 'x', 'http://example.com/', 'prop2', 'value2');", |
| 586 1, // number of parameters |
584 1, // number of parameters |
| 587 NULL, |
585 NULL, |
| 588 params, // parameter value |
586 params, // parameter value |
| 589 NULL, |
587 NULL, |
| 590 NULL, |
588 NULL, |
| 591 0); // 0: result in text format |
589 0); // 0: result in text format |
| 592 |
590 |
| 593 UCX_TEST_ASSERT(PQresultStatus(result) == PGRES_COMMAND_OK, "cannot create property 1"); |
591 CX_TEST_ASSERT(PQresultStatus(result) == PGRES_COMMAND_OK); |
| 594 PQclear(result); |
592 PQclear(result); |
| 595 |
593 |
| 596 // 1 property for res2 |
594 // 1 property for res2 |
| 597 snprintf(idstr, 32, "%" PRId64, res2_id); |
595 snprintf(idstr, 32, "%" PRId64, res2_id); |
| 598 result = PQexecParams( |
596 result = PQexecParams( |
| 599 test_connection, |
597 test_connection, |
| 600 "insert into Property(resource_id, prefix, xmlns, pname, pvalue) values ($1, 'x', 'http://example.com/', 'test', 'res2test');", |
598 "insert into Property(resource_id, prefix, xmlns, pname, pvalue) values ($1, 'x', 'http://example.com/', 'test', 'res2test');", |
| 601 1, // number of parameters |
599 1, // number of parameters |
| 602 NULL, |
600 NULL, |
| 603 params, // parameter value |
601 params, // parameter value |
| 604 NULL, |
602 NULL, |
| 605 NULL, |
603 NULL, |
| 606 0); // 0: result in text format |
604 0); // 0: result in text format |
| 607 |
605 |
| 608 UCX_TEST_ASSERT(PQresultStatus(result) == PGRES_COMMAND_OK, "cannot create property 1"); |
606 CX_TEST_ASSERT(PQresultStatus(result) == PGRES_COMMAND_OK); |
| 609 PQclear(result); |
607 PQclear(result); |
| 610 |
608 |
| 611 UCX_TEST_END; |
609 } |
| 612 |
610 |
| 613 testutil_destroy_session(sn); |
611 testutil_destroy_session(sn); |
| 614 } |
612 } |
| 615 |
613 |
| 616 UCX_TEST(test_pg_webdav_propfind) { |
614 CX_TEST(test_pg_webdav_propfind) { |
| 617 Session *sn; |
615 Session *sn; |
| 618 Request *rq; |
616 Request *rq; |
| 619 TestIOStream *st; |
617 TestIOStream *st; |
| 620 pblock *pb; |
618 pblock *pb; |
| 621 |
619 |
| 622 UCX_TEST_BEGIN; |
620 CX_TEST_DO { |
| 623 |
621 |
| 624 // test data: |
622 // test data: |
| 625 // |
623 // |
| 626 // /propfind/ |
624 // /propfind/ |
| 627 // /propfind/res1 (2 properties: test, prop2) |
625 // /propfind/res1 (2 properties: test, prop2) |
| 628 // /propfind/res2 (1 property: test) |
626 // /propfind/res2 (1 property: test) |
| 629 // /propfind/res3 |
627 // /propfind/res3 |
| 630 // /propfind/sub |
628 // /propfind/sub |
| 631 // /propfind/sub/res4 |
629 // /propfind/sub/res4 |
| 632 |
630 |
| 633 int ret; |
631 int ret; |
| 634 // Test 1 |
632 // Test 1 |
| 635 init_test_webdav_method(&sn, &rq, &st, &pb, "PROPFIND", "/propfind/", PG_TEST_PROPFIND1); |
633 init_test_webdav_method(&sn, &rq, &st, &pb, "PROPFIND", "/propfind/", PG_TEST_PROPFIND1); |
| 636 rq->davCollection = create_test_pgdav(sn, rq); |
634 rq->davCollection = create_test_pgdav(sn, rq); |
| 637 pblock_nvinsert("depth", "0", rq->headers); |
635 pblock_nvinsert("depth", "0", rq->headers); |
| 638 |
636 |
| 639 ret = webdav_propfind(pb, sn, rq); |
637 ret = webdav_propfind(pb, sn, rq); |
| 640 |
638 |
| 641 UCX_TEST_ASSERT(ret == REQ_PROCEED, "webdav_propfind (1) failed"); |
639 CX_TEST_ASSERT(ret == REQ_PROCEED); |
| 642 |
640 |
| 643 TestMultistatus *ms = test_parse_multistatus(st->buf->space, st->buf->size); |
641 TestMultistatus *ms = test_parse_multistatus(st->buf->space, st->buf->size); |
| 644 UCX_TEST_ASSERT(ms, "propfind1: response is not valid xml"); |
642 CX_TEST_ASSERT(ms); |
| 645 |
643 |
| 646 TestResponse *r1 = MAP_GET(ms->responses, "/propfind/"); |
644 TestResponse *r1 = MAP_GET(ms->responses, "/propfind/"); |
| 647 UCX_TEST_ASSERT(r1, "propfind1: missing /propfind/ response"); |
645 CX_TEST_ASSERT(r1); |
| 648 |
646 |
| 649 UCX_TEST_ASSERT(cxMapSize(ms->responses) == 1, "propfind1: wrong response count"); |
647 CX_TEST_ASSERT(cxMapSize(ms->responses) == 1); |
| 650 |
648 |
| 651 TestProperty *p = MAP_GET(r1->properties, "DAV:resourcetype"); |
649 TestProperty *p = MAP_GET(r1->properties, "DAV:resourcetype"); |
| 652 UCX_TEST_ASSERT(p, "propfind1: missing property 'resourcetype'"); |
650 CX_TEST_ASSERT(p); |
| 653 UCX_TEST_ASSERT(p->status == 200, "propfind1: wrong status code for property 'resourcetype'"); |
651 CX_TEST_ASSERT(p->status == 200); |
| 654 |
652 |
| 655 p = MAP_GET(r1->properties, "DAV:getlastmodified"); |
653 p = MAP_GET(r1->properties, "DAV:getlastmodified"); |
| 656 UCX_TEST_ASSERT(p, "propfind1: missing property 'getlastmodified'"); |
654 CX_TEST_ASSERT(p); |
| 657 UCX_TEST_ASSERT(p->status == 200, "propfind1: wrong status code for property 'getlastmodified'"); |
655 CX_TEST_ASSERT(p->status == 200); |
| 658 |
656 |
| 659 testutil_destroy_session(sn); |
657 testutil_destroy_session(sn); |
| 660 test_multistatus_destroy(ms); |
658 test_multistatus_destroy(ms); |
| 661 testutil_iostream_destroy(st); |
659 testutil_iostream_destroy(st); |
| 662 |
660 |
| 663 |
661 |
| 664 // Test 2 |
662 // Test 2 |
| 665 init_test_webdav_method(&sn, &rq, &st, &pb, "PROPFIND", "/propfind/", PG_TEST_PROPFIND2); |
663 init_test_webdav_method(&sn, &rq, &st, &pb, "PROPFIND", "/propfind/", PG_TEST_PROPFIND2); |
| 666 rq->davCollection = create_test_pgdav(sn, rq); |
664 rq->davCollection = create_test_pgdav(sn, rq); |
| 667 pblock_nvinsert("depth", "1", rq->headers); |
665 pblock_nvinsert("depth", "1", rq->headers); |
| 668 |
666 |
| 669 ret = webdav_propfind(pb, sn, rq); |
667 ret = webdav_propfind(pb, sn, rq); |
| 670 |
668 |
| 671 //printf("\n\n%.*s\n", (int)st->buf->size, st->buf->space); |
669 //printf("\n\n%.*s\n", (int)st->buf->size, st->buf->space); |
| 672 |
670 |
| 673 UCX_TEST_ASSERT(ret == REQ_PROCEED, "webdav_propfind (2) failed"); |
671 CX_TEST_ASSERT(ret == REQ_PROCEED); |
| 674 |
672 |
| 675 ms = test_parse_multistatus(st->buf->space, st->buf->size); |
673 ms = test_parse_multistatus(st->buf->space, st->buf->size); |
| 676 UCX_TEST_ASSERT(ms, "propfind2: response is not valid xml"); |
674 CX_TEST_ASSERT(ms); |
| 677 |
675 |
| 678 r1 = MAP_GET(ms->responses, "/propfind/"); |
676 r1 = MAP_GET(ms->responses, "/propfind/"); |
| 679 UCX_TEST_ASSERT(r1, "propfind2: missing /propfind/ response"); |
677 CX_TEST_ASSERT(r1); |
| 680 |
678 |
| 681 UCX_TEST_ASSERT(cxMapSize(ms->responses) == 5, "propfind2: wrong response count"); |
679 CX_TEST_ASSERT(cxMapSize(ms->responses) == 5); |
| 682 |
680 |
| 683 r1 = MAP_GET(ms->responses, "/propfind/res2"); |
681 r1 = MAP_GET(ms->responses, "/propfind/res2"); |
| 684 UCX_TEST_ASSERT(r1, "propfind2: missing /propfind/res2 response"); |
682 CX_TEST_ASSERT(r1); |
| 685 |
683 |
| 686 p = MAP_GET(r1->properties, "http://example.com/test"); |
684 p = MAP_GET(r1->properties, "http://example.com/test"); |
| 687 UCX_TEST_ASSERT(p, "propfind2: missing property 'test'"); |
685 CX_TEST_ASSERT(p); |
| 688 UCX_TEST_ASSERT(p->status == 200, "propfind2: wrong status code for property 'test'"); |
686 CX_TEST_ASSERT(p->status == 200); |
| 689 UCX_TEST_ASSERT(!strcmp(p->value, "res2test"), "propfind2: wrong property value"); |
687 CX_TEST_ASSERT(!strcmp(p->value, "res2test")); |
| 690 |
688 |
| 691 |
689 |
| 692 testutil_destroy_session(sn); |
690 testutil_destroy_session(sn); |
| 693 test_multistatus_destroy(ms); |
691 test_multistatus_destroy(ms); |
| 694 testutil_iostream_destroy(st); |
692 testutil_iostream_destroy(st); |
| 695 |
693 |
| 696 |
694 |
| 697 |
695 |
| 698 // Test 3 |
696 // Test 3 |
| 699 init_test_webdav_method(&sn, &rq, &st, &pb, "PROPFIND", "/propfind/", PG_TEST_PROPFIND2); |
697 init_test_webdav_method(&sn, &rq, &st, &pb, "PROPFIND", "/propfind/", PG_TEST_PROPFIND2); |
| 700 rq->davCollection = create_test_pgdav(sn, rq); |
698 rq->davCollection = create_test_pgdav(sn, rq); |
| 701 pblock_nvinsert("depth", "infinity", rq->headers); |
699 pblock_nvinsert("depth", "infinity", rq->headers); |
| 702 |
700 |
| 703 ret = webdav_propfind(pb, sn, rq); |
701 ret = webdav_propfind(pb, sn, rq); |
| 704 |
702 |
| 705 //printf("\n\n%.*s\n", (int)st->buf->size, st->buf->space); |
703 //printf("\n\n%.*s\n", (int)st->buf->size, st->buf->space); |
| 706 |
704 |
| 707 UCX_TEST_ASSERT(ret == REQ_PROCEED, "webdav_propfind (3) failed"); |
705 CX_TEST_ASSERT(ret == REQ_PROCEED); |
| 708 |
706 |
| 709 ms = test_parse_multistatus(st->buf->space, st->buf->size); |
707 ms = test_parse_multistatus(st->buf->space, st->buf->size); |
| 710 UCX_TEST_ASSERT(ms, "propfind3: response is not valid xml"); |
708 CX_TEST_ASSERT(ms); |
| 711 |
709 |
| 712 r1 = MAP_GET(ms->responses, "/propfind/"); |
710 r1 = MAP_GET(ms->responses, "/propfind/"); |
| 713 UCX_TEST_ASSERT(r1, "propfind3: missing /propfind/ response"); |
711 CX_TEST_ASSERT(r1); |
| 714 |
712 |
| 715 UCX_TEST_ASSERT(cxMapSize(ms->responses) == 6, "propfind3: wrong response count"); |
713 CX_TEST_ASSERT(cxMapSize(ms->responses) == 6); |
| 716 |
714 |
| 717 |
715 |
| 718 r1 = MAP_GET(ms->responses, "/propfind/res1"); |
716 r1 = MAP_GET(ms->responses, "/propfind/res1"); |
| 719 UCX_TEST_ASSERT(r1, "propfind3: missing /propfind/sub/res1 response"); |
717 CX_TEST_ASSERT(r1); |
| 720 |
718 |
| 721 p = MAP_GET(r1->properties, "http://example.com/test"); |
719 p = MAP_GET(r1->properties, "http://example.com/test"); |
| 722 UCX_TEST_ASSERT(p, "propfind3: missing property 'test'"); |
720 CX_TEST_ASSERT(p); |
| 723 UCX_TEST_ASSERT(p->status == 200, "propfind3: wrong status code for property 'test'"); |
721 CX_TEST_ASSERT(p->status == 200); |
| 724 UCX_TEST_ASSERT(!strcmp(p->value, "testvalue"), "propfind3: wrong property value"); |
722 CX_TEST_ASSERT(!strcmp(p->value, "testvalue")); |
| 725 |
723 |
| 726 p = MAP_GET(r1->properties, "http://example.com/prop2"); |
724 p = MAP_GET(r1->properties, "http://example.com/prop2"); |
| 727 UCX_TEST_ASSERT(p, "propfind3: missing property 'prop2'"); |
725 CX_TEST_ASSERT(p); |
| 728 UCX_TEST_ASSERT(p->status == 200, "propfind3: wrong status code for property 'prop2'"); |
726 CX_TEST_ASSERT(p->status == 200); |
| 729 UCX_TEST_ASSERT(!strcmp(p->value, "value2"), "propfind3: wrong property value"); |
727 CX_TEST_ASSERT(!strcmp(p->value, "value2")); |
| 730 |
728 |
| 731 |
729 |
| 732 r1 = MAP_GET(ms->responses, "/propfind/sub/res4"); |
730 r1 = MAP_GET(ms->responses, "/propfind/sub/res4"); |
| 733 UCX_TEST_ASSERT(r1, "propfind3: missing /propfind/sub/res4 response"); |
731 CX_TEST_ASSERT(r1); |
| 734 |
732 |
| 735 testutil_destroy_session(sn); |
733 testutil_destroy_session(sn); |
| 736 test_multistatus_destroy(ms); |
734 test_multistatus_destroy(ms); |
| 737 testutil_iostream_destroy(st); |
735 testutil_iostream_destroy(st); |
| 738 |
736 |
| 739 UCX_TEST_END; |
737 } |
| 740 } |
738 } |
| 741 |
739 |
| 742 |
740 |
| 743 UCX_TEST(test_pg_webdav_propfind_allprop) { |
741 CX_TEST(test_pg_webdav_propfind_allprop) { |
| 744 Session *sn; |
742 Session *sn; |
| 745 Request *rq; |
743 Request *rq; |
| 746 TestIOStream *st; |
744 TestIOStream *st; |
| 747 pblock *pb; |
745 pblock *pb; |
| 748 |
746 |
| 749 UCX_TEST_BEGIN; |
747 CX_TEST_DO { |
| 750 |
748 |
| 751 // test data: |
749 // test data: |
| 752 // |
750 // |
| 753 // /propfind/ |
751 // /propfind/ |
| 754 // /propfind/res1 (2 properties: test, prop2) |
752 // /propfind/res1 (2 properties: test, prop2) |
| 755 // /propfind/res2 (1 property: test) |
753 // /propfind/res2 (1 property: test) |
| 756 // /propfind/res3 |
754 // /propfind/res3 |
| 757 // /propfind/sub |
755 // /propfind/sub |
| 758 // /propfind/sub/res4 |
756 // /propfind/sub/res4 |
| 759 |
757 |
| 760 int ret; |
758 int ret; |
| 761 TestResponse *r1; |
759 TestResponse *r1; |
| 762 TestProperty *p; |
760 TestProperty *p; |
| 763 // Test 1 |
761 // Test 1 |
| 764 init_test_webdav_method(&sn, &rq, &st, &pb, "PROPFIND", "/propfind/", PG_TEST_ALLPROP); |
762 init_test_webdav_method(&sn, &rq, &st, &pb, "PROPFIND", "/propfind/", PG_TEST_ALLPROP); |
| 765 rq->davCollection = create_test_pgdav(sn, rq); |
763 rq->davCollection = create_test_pgdav(sn, rq); |
| 766 pblock_nvinsert("depth", "0", rq->headers); |
764 pblock_nvinsert("depth", "0", rq->headers); |
| 767 |
765 |
| 768 ret = webdav_propfind(pb, sn, rq); |
766 ret = webdav_propfind(pb, sn, rq); |
| 769 |
767 |
| 770 UCX_TEST_ASSERT(ret == REQ_PROCEED, "webdav_propfind (1) failed"); |
768 CX_TEST_ASSERT(ret == REQ_PROCEED); |
| 771 |
769 |
| 772 TestMultistatus *ms = test_parse_multistatus(st->buf->space, st->buf->size); |
770 TestMultistatus *ms = test_parse_multistatus(st->buf->space, st->buf->size); |
| 773 UCX_TEST_ASSERT(ms, "propfind1: response is not valid xml"); |
771 CX_TEST_ASSERT(ms); |
| 774 |
772 |
| 775 r1 = MAP_GET(ms->responses, "/propfind/"); |
773 r1 = MAP_GET(ms->responses, "/propfind/"); |
| 776 UCX_TEST_ASSERT(r1, "propfind1: missing /propfind/ response"); |
774 CX_TEST_ASSERT(r1); |
| 777 UCX_TEST_ASSERT(cxMapSize(ms->responses) == 1, "propfind1: wrong response count"); |
775 CX_TEST_ASSERT(cxMapSize(ms->responses) == 1); |
| 778 |
776 |
| 779 p = MAP_GET(r1->properties, "DAV:resourcetype"); |
777 p = MAP_GET(r1->properties, "DAV:resourcetype"); |
| 780 UCX_TEST_ASSERT(r1, "propfind1: missing resourcetype property"); |
778 CX_TEST_ASSERT(r1); |
| 781 |
779 |
| 782 testutil_destroy_session(sn); |
780 testutil_destroy_session(sn); |
| 783 test_multistatus_destroy(ms); |
781 test_multistatus_destroy(ms); |
| 784 testutil_iostream_destroy(st); |
782 testutil_iostream_destroy(st); |
| 785 |
783 |
| 786 // Test 2 |
784 // Test 2 |
| 787 init_test_webdav_method(&sn, &rq, &st, &pb, "PROPFIND", "/propfind/", PG_TEST_ALLPROP); |
785 init_test_webdav_method(&sn, &rq, &st, &pb, "PROPFIND", "/propfind/", PG_TEST_ALLPROP); |
| 788 rq->davCollection = create_test_pgdav(sn, rq); |
786 rq->davCollection = create_test_pgdav(sn, rq); |
| 789 pblock_nvinsert("depth", "1", rq->headers); |
787 pblock_nvinsert("depth", "1", rq->headers); |
| 790 |
788 |
| 791 ret = webdav_propfind(pb, sn, rq); |
789 ret = webdav_propfind(pb, sn, rq); |
| 792 |
790 |
| 793 //printf("\n\n%.*s\n", (int)st->buf->size, st->buf->space); |
791 //printf("\n\n%.*s\n", (int)st->buf->size, st->buf->space); |
| 794 |
792 |
| 795 UCX_TEST_ASSERT(ret == REQ_PROCEED, "webdav_propfind (2) failed"); |
793 CX_TEST_ASSERT(ret == REQ_PROCEED); |
| 796 |
794 |
| 797 ms = test_parse_multistatus(st->buf->space, st->buf->size); |
795 ms = test_parse_multistatus(st->buf->space, st->buf->size); |
| 798 UCX_TEST_ASSERT(ms, "propfind2: response is not valid xml"); |
796 CX_TEST_ASSERT(ms); |
| 799 |
797 |
| 800 r1 = MAP_GET(ms->responses, "/propfind/"); |
798 r1 = MAP_GET(ms->responses, "/propfind/"); |
| 801 UCX_TEST_ASSERT(r1, "propfind2: missing /propfind/ response"); |
799 CX_TEST_ASSERT(r1); |
| 802 UCX_TEST_ASSERT(cxMapSize(ms->responses) == 5, "propfind2: wrong response count"); |
800 CX_TEST_ASSERT(cxMapSize(ms->responses) == 5); |
| 803 |
801 |
| 804 r1 = MAP_GET(ms->responses, "/propfind/res1"); |
802 r1 = MAP_GET(ms->responses, "/propfind/res1"); |
| 805 UCX_TEST_ASSERT(r1, "propfind2: missing /propfind/res1 response"); |
803 CX_TEST_ASSERT(r1); |
| 806 |
804 |
| 807 p = MAP_GET(r1->properties, "DAV:resourcetype"); |
805 p = MAP_GET(r1->properties, "DAV:resourcetype"); |
| 808 UCX_TEST_ASSERT(r1, "propfind2: missing resourcetype property"); |
806 CX_TEST_ASSERT(r1); |
| 809 p = MAP_GET(r1->properties, "http://example.com/test"); |
807 p = MAP_GET(r1->properties, "http://example.com/test"); |
| 810 UCX_TEST_ASSERT(r1, "propfind2: missing test property"); |
808 CX_TEST_ASSERT(r1); |
| 811 p = MAP_GET(r1->properties, "http://example.com/prop2"); |
809 p = MAP_GET(r1->properties, "http://example.com/prop2"); |
| 812 UCX_TEST_ASSERT(r1, "propfind2: missing prop2 property"); |
810 CX_TEST_ASSERT(r1); |
| 813 |
811 |
| 814 UCX_TEST_ASSERT(MAP_GET(ms->responses, "/propfind/res2"), "propfind2: missing /propfind/res2 response"); |
812 CX_TEST_ASSERT(MAP_GET(ms->responses, "/propfind/res2")); |
| 815 UCX_TEST_ASSERT(MAP_GET(ms->responses, "/propfind/res3"), "propfind2: missing /propfind/res3 response"); |
813 CX_TEST_ASSERT(MAP_GET(ms->responses, "/propfind/res3")); |
| 816 UCX_TEST_ASSERT(MAP_GET(ms->responses, "/propfind/sub/"), "propfind2: missing /propfind/sub response"); |
814 CX_TEST_ASSERT(MAP_GET(ms->responses, "/propfind/sub/")); |
| 817 |
815 |
| 818 testutil_destroy_session(sn); |
816 testutil_destroy_session(sn); |
| 819 test_multistatus_destroy(ms); |
817 test_multistatus_destroy(ms); |
| 820 testutil_iostream_destroy(st); |
818 testutil_iostream_destroy(st); |
| 821 |
819 |
| 822 // Test 3 |
820 // Test 3 |
| 823 init_test_webdav_method(&sn, &rq, &st, &pb, "PROPFIND", "/propfind/", PG_TEST_ALLPROP); |
821 init_test_webdav_method(&sn, &rq, &st, &pb, "PROPFIND", "/propfind/", PG_TEST_ALLPROP); |
| 824 rq->davCollection = create_test_pgdav(sn, rq); |
822 rq->davCollection = create_test_pgdav(sn, rq); |
| 825 pblock_nvinsert("depth", "infinity", rq->headers); |
823 pblock_nvinsert("depth", "infinity", rq->headers); |
| 826 |
824 |
| 827 ret = webdav_propfind(pb, sn, rq); |
825 ret = webdav_propfind(pb, sn, rq); |
| 828 |
826 |
| 829 UCX_TEST_ASSERT(ret == REQ_PROCEED, "webdav_propfind (2) failed"); |
827 CX_TEST_ASSERT(ret == REQ_PROCEED); |
| 830 |
828 |
| 831 ms = test_parse_multistatus(st->buf->space, st->buf->size); |
829 ms = test_parse_multistatus(st->buf->space, st->buf->size); |
| 832 UCX_TEST_ASSERT(ms, "propfind3: response is not valid xml"); |
830 CX_TEST_ASSERT(ms); |
| 833 |
831 |
| 834 r1 = MAP_GET(ms->responses, "/propfind/"); |
832 r1 = MAP_GET(ms->responses, "/propfind/"); |
| 835 UCX_TEST_ASSERT(r1, "propfind3: missing /propfind/ response"); |
833 CX_TEST_ASSERT(r1); |
| 836 UCX_TEST_ASSERT(cxMapSize(ms->responses) == 6, "propfind3: wrong response count"); |
834 CX_TEST_ASSERT(cxMapSize(ms->responses) == 6); |
| 837 |
835 |
| 838 r1 = MAP_GET(ms->responses, "/propfind/res1"); |
836 r1 = MAP_GET(ms->responses, "/propfind/res1"); |
| 839 UCX_TEST_ASSERT(r1, "propfind3: missing /propfind/res1 response"); |
837 CX_TEST_ASSERT(r1); |
| 840 |
838 |
| 841 p = MAP_GET(r1->properties, "DAV:resourcetype"); |
839 p = MAP_GET(r1->properties, "DAV:resourcetype"); |
| 842 UCX_TEST_ASSERT(r1, "propfind3: missing resourcetype property"); |
840 CX_TEST_ASSERT(r1); |
| 843 p = MAP_GET(r1->properties, "http://example.com/test"); |
841 p = MAP_GET(r1->properties, "http://example.com/test"); |
| 844 UCX_TEST_ASSERT(r1, "propfind3: missing test property"); |
842 CX_TEST_ASSERT(r1); |
| 845 p = MAP_GET(r1->properties, "http://example.com/prop2"); |
843 p = MAP_GET(r1->properties, "http://example.com/prop2"); |
| 846 UCX_TEST_ASSERT(r1, "propfind3: missing prop2 property"); |
844 CX_TEST_ASSERT(r1); |
| 847 |
845 |
| 848 UCX_TEST_ASSERT(MAP_GET(ms->responses, "/propfind/res2"), "propfind3: missing /propfind/res2 response"); |
846 CX_TEST_ASSERT(MAP_GET(ms->responses, "/propfind/res2")); |
| 849 UCX_TEST_ASSERT(MAP_GET(ms->responses, "/propfind/res3"), "propfind3: missing /propfind/res3 response"); |
847 CX_TEST_ASSERT(MAP_GET(ms->responses, "/propfind/res3")); |
| 850 UCX_TEST_ASSERT(MAP_GET(ms->responses, "/propfind/sub/"), "propfind3: missing /propfind/sub response"); |
848 CX_TEST_ASSERT(MAP_GET(ms->responses, "/propfind/sub/")); |
| 851 UCX_TEST_ASSERT(MAP_GET(ms->responses, "/propfind/sub/res4"), "propfind3: missing /propfind/sub/res4 response"); |
849 CX_TEST_ASSERT(MAP_GET(ms->responses, "/propfind/sub/res4")); |
| 852 |
850 |
| 853 testutil_destroy_session(sn); |
851 testutil_destroy_session(sn); |
| 854 test_multistatus_destroy(ms); |
852 test_multistatus_destroy(ms); |
| 855 testutil_iostream_destroy(st); |
853 testutil_iostream_destroy(st); |
| 856 |
854 } |
| 857 |
855 } |
| 858 UCX_TEST_END; |
856 |
| 859 } |
857 CX_TEST(test_pg_webdav_proppatch_set) { |
| 860 |
|
| 861 UCX_TEST(test_pg_webdav_proppatch_set) { |
|
| 862 Session *sn; |
858 Session *sn; |
| 863 Request *rq; |
859 Request *rq; |
| 864 TestIOStream *st; |
860 TestIOStream *st; |
| 865 pblock *pb; |
861 pblock *pb; |
| 866 |
862 |
| 867 UCX_TEST_BEGIN; |
863 CX_TEST_DO { |
| 868 |
864 |
| 869 // test data: |
865 // test data: |
| 870 // |
866 // |
| 871 // /propfind/ |
867 // /propfind/ |
| 872 // /propfind/res1 (2 properties: test, prop2) |
868 // /propfind/res1 (2 properties: test, prop2) |
| 873 // /propfind/res2 (1 property: test) |
869 // /propfind/res2 (1 property: test) |
| 874 // /propfind/res3 |
870 // /propfind/res3 |
| 875 // /propfind/sub |
871 // /propfind/sub |
| 876 // /propfind/sub/res4 |
872 // /propfind/sub/res4 |
| 877 |
873 |
| 878 int ret; |
874 int ret; |
| 879 TestResponse *r1; |
875 TestResponse *r1; |
| 880 TestProperty *p; |
876 TestProperty *p; |
| 881 // Test 1 |
877 // Test 1 |
| 882 init_test_webdav_method(&sn, &rq, &st, &pb, "PROPPATCH", "/proppatch/pp1", PG_TEST_PROPPATCH1); |
878 init_test_webdav_method(&sn, &rq, &st, &pb, "PROPPATCH", "/proppatch/pp1", PG_TEST_PROPPATCH1); |
| 883 rq->davCollection = create_test_pgdav(sn, rq); |
879 rq->davCollection = create_test_pgdav(sn, rq); |
| 884 |
880 |
| 885 ret = webdav_proppatch(pb, sn, rq); |
881 ret = webdav_proppatch(pb, sn, rq); |
| 886 UCX_TEST_ASSERT(ret == REQ_PROCEED, "proppatch1 failed"); |
882 CX_TEST_ASSERT(ret == REQ_PROCEED); |
| 887 |
883 |
| 888 //printf("\n\n%.*s\n", (int)st->buf->size, st->buf->space); |
884 //printf("\n\n%.*s\n", (int)st->buf->size, st->buf->space); |
| 889 |
885 |
| 890 TestMultistatus *ms = test_parse_multistatus(st->buf->space, st->buf->size); |
886 TestMultistatus *ms = test_parse_multistatus(st->buf->space, st->buf->size); |
| 891 UCX_TEST_ASSERT(ms, "proppatch1 response is not valid xml"); |
887 CX_TEST_ASSERT(ms); |
| 892 |
888 |
| 893 testutil_destroy_session(sn); |
889 testutil_destroy_session(sn); |
| 894 test_multistatus_destroy(ms); |
890 test_multistatus_destroy(ms); |
| 895 testutil_iostream_destroy(st); |
891 testutil_iostream_destroy(st); |
| 896 |
892 |
| 897 // Test 2: xml property value |
893 // Test 2: xml property value |
| 898 init_test_webdav_method(&sn, &rq, &st, &pb, "PROPPATCH", "/proppatch/pp1", PG_TEST_PROPPATCH2); |
894 init_test_webdav_method(&sn, &rq, &st, &pb, "PROPPATCH", "/proppatch/pp1", PG_TEST_PROPPATCH2); |
| 899 rq->davCollection = create_test_pgdav(sn, rq); |
895 rq->davCollection = create_test_pgdav(sn, rq); |
| 900 |
896 |
| 901 ret = webdav_proppatch(pb, sn, rq); |
897 ret = webdav_proppatch(pb, sn, rq); |
| 902 UCX_TEST_ASSERT(ret == REQ_PROCEED, "proppatch2 failed"); |
898 CX_TEST_ASSERT(ret == REQ_PROCEED); |
| 903 |
899 |
| 904 //printf("\n\n%.*s\n", (int)st->buf->size, st->buf->space); |
900 //printf("\n\n%.*s\n", (int)st->buf->size, st->buf->space); |
| 905 |
901 |
| 906 ms = test_parse_multistatus(st->buf->space, st->buf->size); |
902 ms = test_parse_multistatus(st->buf->space, st->buf->size); |
| 907 UCX_TEST_ASSERT(ms, "proppatch2 response is not valid xml"); |
903 CX_TEST_ASSERT(ms); |
| 908 |
904 |
| 909 testutil_destroy_session(sn); |
905 testutil_destroy_session(sn); |
| 910 test_multistatus_destroy(ms); |
906 test_multistatus_destroy(ms); |
| 911 testutil_iostream_destroy(st); |
907 testutil_iostream_destroy(st); |
| 912 |
908 |
| 913 |
909 } |
| 914 UCX_TEST_END; |
910 } |
| 915 } |
|