src/server/plugins/postgresql/pgtest.c

Mon, 25 Apr 2022 22:38:05 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Mon, 25 Apr 2022 22:38:05 +0200
branch
webdav
changeset 314
6b1a6066ee43
parent 313
3ad0b65ec838
child 315
b608b7aa43a6
permissions
-rw-r--r--

fix pg propfind for getlastmodified property

287
a171da778817 prepare build system for postgresql plugin tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 /*
a171da778817 prepare build system for postgresql plugin tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
a171da778817 prepare build system for postgresql plugin tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
3 *
a171da778817 prepare build system for postgresql plugin tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
4 * Copyright 2022 Olaf Wintermann. All rights reserved.
a171da778817 prepare build system for postgresql plugin tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
5 *
a171da778817 prepare build system for postgresql plugin tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
a171da778817 prepare build system for postgresql plugin tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
a171da778817 prepare build system for postgresql plugin tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
8 *
a171da778817 prepare build system for postgresql plugin tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
a171da778817 prepare build system for postgresql plugin tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
a171da778817 prepare build system for postgresql plugin tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
11 *
a171da778817 prepare build system for postgresql plugin tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
a171da778817 prepare build system for postgresql plugin tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
a171da778817 prepare build system for postgresql plugin tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
a171da778817 prepare build system for postgresql plugin tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
15 *
a171da778817 prepare build system for postgresql plugin tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
a171da778817 prepare build system for postgresql plugin tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
a171da778817 prepare build system for postgresql plugin tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
a171da778817 prepare build system for postgresql plugin tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
a171da778817 prepare build system for postgresql plugin tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
a171da778817 prepare build system for postgresql plugin tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
a171da778817 prepare build system for postgresql plugin tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
a171da778817 prepare build system for postgresql plugin tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
a171da778817 prepare build system for postgresql plugin tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
a171da778817 prepare build system for postgresql plugin tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
a171da778817 prepare build system for postgresql plugin tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
a171da778817 prepare build system for postgresql plugin tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
27 */
a171da778817 prepare build system for postgresql plugin tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
28
a171da778817 prepare build system for postgresql plugin tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
29 #include <stdio.h>
306
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
30 #include <inttypes.h>
287
a171da778817 prepare build system for postgresql plugin tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
31
289
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
32 #include "../../util/util.h"
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
33 #include "../../test/testutils.h"
306
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
34 #include "../../test/webdav.h"
289
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
35 #include "../../public/nsapi.h"
306
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
36 #include "../../public/webdav.h"
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
37 #include "../../webdav/webdav.h"
289
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
38
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
39 #include <ucx/string.h>
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
40 #include <ucx/utils.h>
306
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
41 #include <ucx/buffer.h>
289
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
42
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
43 #include "pgtest.h"
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
44 #include "vfs.h"
306
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
45 #include "webdav.h"
289
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
46
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
47 #include <libpq-fe.h>
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
48
313
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
49 #define xstreq(a,b) xmlStrEqual(BAD_CAST a, BAD_CAST b)
289
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
50
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
51 static char *pg_connstr = "postgresql://localhost/test1";
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
52 static int abort_pg_tests = 0;
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
53 static PGconn *test_connection;
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
54 static ResourceData resdata;
287
a171da778817 prepare build system for postgresql plugin tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
55
296
78e92337fa4e implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 295
diff changeset
56 void debug_print_resources(void) {
78e92337fa4e implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 295
diff changeset
57 PGresult *result = PQexec(test_connection, "select * from Resource;");
78e92337fa4e implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 295
diff changeset
58 int n = PQntuples(result);
78e92337fa4e implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 295
diff changeset
59 printf("\nntuples: %d\n-----------------------------------------------\n", n);
78e92337fa4e implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 295
diff changeset
60 printf("%10s %10s %s\n", "resource_id", "parent_id", "nodename");
78e92337fa4e implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 295
diff changeset
61 for(int i=0;i<n;i++) {
78e92337fa4e implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 295
diff changeset
62 char *res_id = PQgetvalue(result, i, 0);
78e92337fa4e implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 295
diff changeset
63 char *parent_id = PQgetvalue(result, i, 1);
78e92337fa4e implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 295
diff changeset
64 char *nodename = PQgetvalue(result, i, 2);
78e92337fa4e implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 295
diff changeset
65 printf("%10s %10s %s\n", res_id, parent_id, nodename);
78e92337fa4e implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 295
diff changeset
66 }
78e92337fa4e implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 295
diff changeset
67 printf("\n");
78e92337fa4e implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 295
diff changeset
68 }
78e92337fa4e implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 295
diff changeset
69
78e92337fa4e implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 295
diff changeset
70
287
a171da778817 prepare build system for postgresql plugin tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
71 void register_pg_tests(int argc, char **argv, UcxTestSuite *suite) {
a171da778817 prepare build system for postgresql plugin tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
72
289
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
73 test_connection = PQconnectdb(pg_connstr);
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
74 if(!test_connection) {
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
75 abort_pg_tests = 1;
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
76 }
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
77
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
78 if(PQstatus(test_connection) != CONNECTION_OK) {
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
79 abort_pg_tests = 1;
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
80 }
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
81
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
82 ucx_test_register(suite, test_pg_conn);
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
83 if(!abort_pg_tests) {
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
84 resdata.data = test_connection;
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
85
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
86 ucx_test_register(suite, test_pg_vfs_open);
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
87 ucx_test_register(suite, test_pg_vfs_io);
293
d3899857a81d add pg stat tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 290
diff changeset
88 ucx_test_register(suite, test_pg_vfs_stat);
294
277a5896a2ec implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 293
diff changeset
89 ucx_test_register(suite, test_pg_vfs_mkdir);
277a5896a2ec implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 293
diff changeset
90 ucx_test_register(suite, test_pg_vfs_unlink);
296
78e92337fa4e implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 295
diff changeset
91 ucx_test_register(suite, test_pg_vfs_rmdir);
289
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
92
306
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
93 ucx_test_register(suite, test_pg_webdav_create_from_resdata);
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
94 ucx_test_register(suite, test_pg_prepare_tests);
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
95 ucx_test_register(suite, test_pg_webdav_propfind);
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
96
289
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
97 PGresult *result = PQexec(test_connection, "BEGIN");
293
d3899857a81d add pg stat tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 290
diff changeset
98 PQclear(result);
289
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
99 }
287
a171da778817 prepare build system for postgresql plugin tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
100 }
289
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
101
313
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
102 static void parse_response_tag(TestMultistatus *ms, xmlNode *node) {
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
103 // thanks to dav for some of this code
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
104 UcxAllocator *a = ms->mp->allocator;
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
105 node = node->children;
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
106
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
107 sstr_t href = {NULL, 0};
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
108 UcxMap *properties = ucx_map_new_a(ms->mp->allocator, 16);
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
109
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
110 while(node) {
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
111 if(node->type == XML_ELEMENT_NODE) {
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
112 if(xstreq(node->name, "href")) {
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
113 xmlNode *href_node = node->children;
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
114 if(href_node->type != XML_TEXT_NODE) {
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
115 return;
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
116 }
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
117 href = sstrdup_a(ms->mp->allocator, scstr((const char*)href_node->content));
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
118 } else if(xstreq(node->name, "propstat")) {
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
119 xmlNode *n = node->children;
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
120 xmlNode *prop_node = NULL;
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
121 int status_code = 0;
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
122 while(n) {
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
123 if(n->type == XML_ELEMENT_NODE) {
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
124 if(xstreq(n->name, "prop")) {
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
125 prop_node = n;
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
126 } else if(xstreq(n->name, "status")) {
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
127 xmlNode *status_node = n->children;
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
128 if(status_node->type != XML_TEXT_NODE) {
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
129 return;
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
130 }
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
131 sstr_t status_str = sstr((char*)status_node->content);
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
132 if(status_str.length < 13) {
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
133 return;
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
134 }
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
135 status_str = sstrsubsl(status_str, 9, 3);
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
136 sstr_t status_s = sstrdup(status_str);
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
137 status_code = atoi(status_s.ptr);
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
138 free(status_s.ptr);
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
139 }
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
140 }
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
141 n = n->next;
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
142 }
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
143
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
144 n = prop_node->children;
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
145 while(n) {
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
146 if(n->type == XML_ELEMENT_NODE) {
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
147 TestProperty *property = ucx_mempool_calloc(ms->mp, 1, sizeof(TestProperty));
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
148 if(n->ns) {
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
149 property->prefix = n->ns->prefix ? sstrdup_a(a, scstr((const char*)n->ns->prefix)).ptr : NULL;
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
150 property->namespace = n->ns->href ? sstrdup_a(a, scstr((const char*)n->ns->href)).ptr : NULL;
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
151 }
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
152 property->name = sstrdup_a(a, scstr((const char*)n->name)).ptr;
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
153 property->node = n;
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
154 property->status = status_code;
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
155 xmlNode *value = n->children;
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
156 if(value && value->type == XML_TEXT_NODE) {
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
157 property->value = sstrdup_a(a, scstr((const char*)value->content)).ptr;
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
158 }
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
159 sstr_t pname = sstrcat(3, sstr(property->prefix), S(":"), sstr(property->name));
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
160 ucx_map_sstr_put(properties, pname, property);
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
161 free(pname.ptr);
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
162 }
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
163 n = n->next;
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
164 }
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
165 }
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
166 }
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
167 node = node->next;
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
168 }
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
169
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
170 TestResponse *resp =almalloc(a, sizeof(TestResponse));
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
171 resp->href = href.ptr;
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
172 resp->properties = properties;
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
173
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
174 ucx_map_sstr_put(ms->responses, href, resp);
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
175 }
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
176
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
177 TestMultistatus* test_parse_multistatus(const char *space, size_t size) {
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
178 xmlDoc *doc = xmlReadMemory(space, size, NULL, NULL, 0);
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
179 if(!doc) {
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
180 return NULL;
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
181 }
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
182
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
183 UcxMempool *mp = ucx_mempool_new(64);
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
184 TestMultistatus *ms = ucx_mempool_malloc(mp, sizeof(TestMultistatus));
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
185 ms->doc = doc;
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
186 ms->mp = mp;
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
187 ms->responses = ucx_map_new_a(mp->allocator, 8);
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
188
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
189 // parse response
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
190 xmlNode *xml_root = xmlDocGetRootElement(doc);
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
191 xmlNode *node = xml_root->children;
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
192 while(node) {
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
193 if(node->type == XML_ELEMENT_NODE) {
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
194 if(xstreq(node->name, "response")) {
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
195 parse_response_tag(ms, node);
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
196 }
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
197 }
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
198 node = node->next;
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
199 }
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
200
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
201 return ms;
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
202 }
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
203
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
204
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
205 void test_multistatus_destroy(TestMultistatus *ms) {
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
206
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
207 }
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
208
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
209
289
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
210 UCX_TEST(test_pg_conn) {
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
211 char *msg = test_connection ? PQerrorMessage(test_connection) : "no connection";
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
212
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
213 UCX_TEST_BEGIN;
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
214
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
215 if(abort_pg_tests) {
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
216 int msglen = strlen(msg);
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
217 if(msglen > 0 && msg[msglen-1] == '\n') {
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
218 msglen--;
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
219 }
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
220 fprintf(stdout, "%.*s: ", msglen, msg);
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
221 UCX_TEST_ASSERT(1 == 0, "skip pg tests");
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
222 } else {
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
223 UCX_TEST_ASSERT(1 == 1, "ok");
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
224 }
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
225
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
226 UCX_TEST_END;
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
227 }
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
228
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
229
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
230 static VFS* create_test_pgvfs(Session *sn, Request *rq) {
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
231 return pg_vfs_create_from_resourcedata(sn, rq, &resdata);
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
232 }
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
233
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
234
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
235 UCX_TEST(test_pg_vfs_open) {
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
236 Session *sn = testutil_session();
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
237 Request *rq = testutil_request(sn->pool, "PUT", "/");
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
238 rq->vfs = create_test_pgvfs(sn, rq);
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
239 VFSContext *vfs = vfs_request_context(sn, rq);
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
240 SYS_FILE file;
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
241
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
242 UCX_TEST_BEGIN;
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
243
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
244 file = vfs_open(vfs, "/test_notfound1", O_RDONLY);
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
245 UCX_TEST_ASSERT(!file, "/test_notfound should not exist");
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
246
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
247 file = vfs_open(vfs, "/test_file1", O_RDWR | O_CREAT);
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
248 UCX_TEST_ASSERT(file, "cannot create file 1");
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
249
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
250 vfs_close(file);
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
251
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
252 UCX_TEST_END;
294
277a5896a2ec implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 293
diff changeset
253
277a5896a2ec implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 293
diff changeset
254 testutil_destroy_session(sn);
289
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
255 }
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
256
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
257 UCX_TEST(test_pg_vfs_io) {
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
258 Session *sn = testutil_session();
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
259 Request *rq = testutil_request(sn->pool, "PUT", "/");
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
260 rq->vfs = create_test_pgvfs(sn, rq);
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
261 VFSContext *vfs = vfs_request_context(sn, rq);
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
262 SYS_FILE file;
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
263 SYS_FILE file2;
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
264
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
265 UCX_TEST_BEGIN;
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
266
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
267 file = vfs_open(vfs, "/test_f1", O_WRONLY | O_CREAT);
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
268 UCX_TEST_ASSERT(file, "cannot open file1");
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
269
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
270 int w = system_fwrite(file, "test1\n", 6);
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
271 UCX_TEST_ASSERT(w == 6, "fwrite ret (1)");
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
272 w = system_fwrite(file, "2", 1);
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
273 UCX_TEST_ASSERT(w == 1, "fwrite ret (2)");
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
274
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
275 vfs_close(file);
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
276
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
277 file = vfs_open(vfs, "/test_f1", O_RDONLY);
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
278 file2 = vfs_open(vfs, "/test_f2", O_WRONLY | O_CREAT);
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
279 UCX_TEST_ASSERT(file, "cannot open file1");
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
280 UCX_TEST_ASSERT(file2, "cannot open file2");
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
281
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
282 char buf[128];
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
283 int r = system_fread(file, buf, 128);
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
284 UCX_TEST_ASSERT(r == 7, "cannot read from file1");
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
285
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
286 w = system_fwrite(file2, buf, r);
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
287 UCX_TEST_ASSERT(w == 7, "cannot write to file2");
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
288
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
289 vfs_close(file);
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
290 vfs_close(file2);
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
291
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
292 file2 = vfs_open(vfs, "/test_f2", O_RDONLY);
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
293
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
294 r = system_fread(file, buf, 128);
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
295 UCX_TEST_ASSERT(r == 7, "fread ret");
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
296 UCX_TEST_ASSERT(!memcmp(buf, "test1\n2", 7), "wrong buffer content after read");
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
297
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
298 vfs_close(file2);
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
299
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
300
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
301 UCX_TEST_END;
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
302
294
277a5896a2ec implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 293
diff changeset
303 testutil_destroy_session(sn);
289
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
304 }
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
305
290
efc10acf539f implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 289
diff changeset
306 UCX_TEST(test_pg_vfs_stat) {
efc10acf539f implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 289
diff changeset
307 Session *sn = testutil_session();
efc10acf539f implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 289
diff changeset
308 Request *rq = testutil_request(sn->pool, "PUT", "/");
efc10acf539f implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 289
diff changeset
309 rq->vfs = create_test_pgvfs(sn, rq);
efc10acf539f implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 289
diff changeset
310 VFSContext *vfs = vfs_request_context(sn, rq);
efc10acf539f implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 289
diff changeset
311
efc10acf539f implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 289
diff changeset
312 UCX_TEST_BEGIN;
efc10acf539f implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 289
diff changeset
313
293
d3899857a81d add pg stat tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 290
diff changeset
314 // testdata, content doesn't matter
d3899857a81d add pg stat tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 290
diff changeset
315 char test1[512];
d3899857a81d add pg stat tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 290
diff changeset
316 memset(test1, 'x', 512);
d3899857a81d add pg stat tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 290
diff changeset
317 const int test_len1 = 200;
d3899857a81d add pg stat tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 290
diff changeset
318 const int test_len2 = 432;
d3899857a81d add pg stat tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 290
diff changeset
319
d3899857a81d add pg stat tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 290
diff changeset
320 SYS_FILE f1 = vfs_open(vfs, "/test_s1", O_WRONLY|O_CREAT);
d3899857a81d add pg stat tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 290
diff changeset
321 UCX_TEST_ASSERT(f1, "cannot open test_s1");
d3899857a81d add pg stat tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 290
diff changeset
322 system_fwrite(f1, test1, test_len1);
d3899857a81d add pg stat tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 290
diff changeset
323 vfs_close(f1);
d3899857a81d add pg stat tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 290
diff changeset
324
d3899857a81d add pg stat tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 290
diff changeset
325 SYS_FILE f2 = vfs_open(vfs, "/test_s2", O_RDWR|O_CREAT);
d3899857a81d add pg stat tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 290
diff changeset
326 UCX_TEST_ASSERT(f2, "cannot open test_s2");
d3899857a81d add pg stat tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 290
diff changeset
327 system_fwrite(f2, test1, test_len2);
d3899857a81d add pg stat tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 290
diff changeset
328 vfs_close(f2);
d3899857a81d add pg stat tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 290
diff changeset
329
d3899857a81d add pg stat tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 290
diff changeset
330 struct stat st1, st2;
d3899857a81d add pg stat tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 290
diff changeset
331 int r1 = vfs_stat(vfs, "/test_s1", &st1);
d3899857a81d add pg stat tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 290
diff changeset
332 int r2 = vfs_stat(vfs, "/test_s2", &st2);
d3899857a81d add pg stat tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 290
diff changeset
333
d3899857a81d add pg stat tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 290
diff changeset
334 UCX_TEST_ASSERT(r1 == 0, "stat1 failed");
d3899857a81d add pg stat tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 290
diff changeset
335 UCX_TEST_ASSERT(r2 == 0, "stat2 failed");
d3899857a81d add pg stat tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 290
diff changeset
336
d3899857a81d add pg stat tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 290
diff changeset
337 UCX_TEST_ASSERT(st1.st_size == test_len1, "s1 wrong length");
d3899857a81d add pg stat tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 290
diff changeset
338 UCX_TEST_ASSERT(st2.st_size == test_len2, "s2 wrong length");
d3899857a81d add pg stat tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 290
diff changeset
339
d3899857a81d add pg stat tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 290
diff changeset
340 int testfail = vfs_stat(vfs, "/test_stat_fail", &st1);
d3899857a81d add pg stat tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 290
diff changeset
341 UCX_TEST_ASSERT(testfail != 0, "stat 3 should fail");
d3899857a81d add pg stat tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 290
diff changeset
342
290
efc10acf539f implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 289
diff changeset
343 UCX_TEST_END;
294
277a5896a2ec implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 293
diff changeset
344
277a5896a2ec implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 293
diff changeset
345 testutil_destroy_session(sn);
290
efc10acf539f implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 289
diff changeset
346 }
efc10acf539f implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 289
diff changeset
347
efc10acf539f implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 289
diff changeset
348 UCX_TEST(test_pg_vfs_mkdir) {
295
73a1243fce15 add pg mkdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 294
diff changeset
349 Session *sn = testutil_session();
73a1243fce15 add pg mkdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 294
diff changeset
350 Request *rq = testutil_request(sn->pool, "PUT", "/");
73a1243fce15 add pg mkdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 294
diff changeset
351 rq->vfs = create_test_pgvfs(sn, rq);
73a1243fce15 add pg mkdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 294
diff changeset
352 VFSContext *vfs = vfs_request_context(sn, rq);
290
efc10acf539f implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 289
diff changeset
353
295
73a1243fce15 add pg mkdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 294
diff changeset
354 UCX_TEST_BEGIN;
73a1243fce15 add pg mkdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 294
diff changeset
355
73a1243fce15 add pg mkdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 294
diff changeset
356 SYS_FILE f1 = vfs_open(vfs, "/test_mkdir/file", O_WRONLY|O_CREAT);
73a1243fce15 add pg mkdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 294
diff changeset
357 UCX_TEST_ASSERT(f1 == NULL, "open should fail");
73a1243fce15 add pg mkdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 294
diff changeset
358
73a1243fce15 add pg mkdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 294
diff changeset
359 int r = vfs_mkdir(vfs, "/test_mkdir");
73a1243fce15 add pg mkdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 294
diff changeset
360 UCX_TEST_ASSERT(r == 0, "mkdir failed");
73a1243fce15 add pg mkdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 294
diff changeset
361
73a1243fce15 add pg mkdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 294
diff changeset
362 f1 = vfs_open(vfs, "/test_mkdir/file", O_WRONLY|O_CREAT);
73a1243fce15 add pg mkdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 294
diff changeset
363 UCX_TEST_ASSERT(f1, "open failed");
73a1243fce15 add pg mkdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 294
diff changeset
364
73a1243fce15 add pg mkdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 294
diff changeset
365 r = vfs_mkdir(vfs, "/test_mkdir/test_sub");
73a1243fce15 add pg mkdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 294
diff changeset
366 UCX_TEST_ASSERT(r == 0, "mkdir failed (2)");
73a1243fce15 add pg mkdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 294
diff changeset
367
73a1243fce15 add pg mkdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 294
diff changeset
368 UCX_TEST_END;
73a1243fce15 add pg mkdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 294
diff changeset
369
73a1243fce15 add pg mkdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 294
diff changeset
370 testutil_destroy_session(sn);
290
efc10acf539f implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 289
diff changeset
371 }
294
277a5896a2ec implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 293
diff changeset
372
277a5896a2ec implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 293
diff changeset
373 UCX_TEST(test_pg_vfs_unlink) {
277a5896a2ec implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 293
diff changeset
374 Session *sn = testutil_session();
277a5896a2ec implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 293
diff changeset
375 Request *rq = testutil_request(sn->pool, "PUT", "/");
277a5896a2ec implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 293
diff changeset
376 rq->vfs = create_test_pgvfs(sn, rq);
277a5896a2ec implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 293
diff changeset
377 VFSContext *vfs = vfs_request_context(sn, rq);
277a5896a2ec implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 293
diff changeset
378
277a5896a2ec implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 293
diff changeset
379 UCX_TEST_BEGIN;
277a5896a2ec implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 293
diff changeset
380
277a5896a2ec implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 293
diff changeset
381 SYS_FILE f1 = vfs_open(vfs, "/test_unlink1", O_WRONLY|O_CREAT);
277a5896a2ec implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 293
diff changeset
382 UCX_TEST_ASSERT(f1, "cannot create test file");
277a5896a2ec implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 293
diff changeset
383 system_fwrite(f1, "test", 4);
277a5896a2ec implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 293
diff changeset
384
277a5896a2ec implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 293
diff changeset
385 PgFile *pgfile = f1->data;
277a5896a2ec implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 293
diff changeset
386 Oid oid = pgfile->oid;
277a5896a2ec implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 293
diff changeset
387
277a5896a2ec implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 293
diff changeset
388 vfs_close(f1);
277a5896a2ec implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 293
diff changeset
389
277a5896a2ec implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 293
diff changeset
390 int r = vfs_unlink(vfs, "/test_unlink1");
277a5896a2ec implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 293
diff changeset
391 UCX_TEST_ASSERT(r == 0, "unlink failed");
277a5896a2ec implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 293
diff changeset
392
277a5896a2ec implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 293
diff changeset
393 f1 = vfs_open(vfs, "/test_unlink1", O_RDONLY);
277a5896a2ec implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 293
diff changeset
394 UCX_TEST_ASSERT(f1 == NULL, "test file not deleted");
277a5896a2ec implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 293
diff changeset
395
298
8f5c556120a5 fix error handling in pg_remove_res
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 297
diff changeset
396 PGresult *result = PQexec(test_connection, "savepoint sp;");
8f5c556120a5 fix error handling in pg_remove_res
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 297
diff changeset
397 PQclear(result);
8f5c556120a5 fix error handling in pg_remove_res
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 297
diff changeset
398 int pgfd = lo_open(test_connection, oid, INV_READ);
8f5c556120a5 fix error handling in pg_remove_res
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 297
diff changeset
399 UCX_TEST_ASSERT(pgfd < 0, "large object not deleted");
8f5c556120a5 fix error handling in pg_remove_res
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 297
diff changeset
400 result = PQexec(test_connection, "rollback to savepoint sp;");
8f5c556120a5 fix error handling in pg_remove_res
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 297
diff changeset
401 PQclear(result);
294
277a5896a2ec implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 293
diff changeset
402
277a5896a2ec implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 293
diff changeset
403 r = vfs_unlink(vfs, "/test_unlink1");
277a5896a2ec implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 293
diff changeset
404 UCX_TEST_ASSERT(r, "unlink should fail");
277a5896a2ec implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 293
diff changeset
405
277a5896a2ec implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 293
diff changeset
406 UCX_TEST_END;
277a5896a2ec implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 293
diff changeset
407
277a5896a2ec implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 293
diff changeset
408 testutil_destroy_session(sn);
277a5896a2ec implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 293
diff changeset
409 }
296
78e92337fa4e implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 295
diff changeset
410
78e92337fa4e implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 295
diff changeset
411 UCX_TEST(test_pg_vfs_rmdir) {
78e92337fa4e implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 295
diff changeset
412 Session *sn = testutil_session();
78e92337fa4e implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 295
diff changeset
413 Request *rq = testutil_request(sn->pool, "PUT", "/");
78e92337fa4e implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 295
diff changeset
414 rq->vfs = create_test_pgvfs(sn, rq);
78e92337fa4e implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 295
diff changeset
415 VFSContext *vfs = vfs_request_context(sn, rq);
78e92337fa4e implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 295
diff changeset
416
78e92337fa4e implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 295
diff changeset
417 PQexec(test_connection, "delete from Resource where parent_id is not null;");
78e92337fa4e implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 295
diff changeset
418
78e92337fa4e implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 295
diff changeset
419 UCX_TEST_BEGIN;
78e92337fa4e implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 295
diff changeset
420
78e92337fa4e implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 295
diff changeset
421 int r;
78e92337fa4e implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 295
diff changeset
422 SYS_FILE f1;
78e92337fa4e implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 295
diff changeset
423
78e92337fa4e implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 295
diff changeset
424 // prepare some dirs/files
78e92337fa4e implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 295
diff changeset
425 r = vfs_mkdir(vfs, "/rmdir_test");
78e92337fa4e implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 295
diff changeset
426 UCX_TEST_ASSERT(r == 0, "mkdir failed (1)");
78e92337fa4e implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 295
diff changeset
427 r = vfs_mkdir(vfs, "/rmdir_test/subdir1");
78e92337fa4e implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 295
diff changeset
428 UCX_TEST_ASSERT(r == 0, "mkdir failed (2)");
78e92337fa4e implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 295
diff changeset
429 r = vfs_mkdir(vfs, "/rmdir_test/subdir2");
78e92337fa4e implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 295
diff changeset
430 UCX_TEST_ASSERT(r == 0, "mkdir failed (3)");
78e92337fa4e implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 295
diff changeset
431
78e92337fa4e implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 295
diff changeset
432 f1 = vfs_open(vfs, "/rmdir_test/subdir2/file", O_CREAT|O_WRONLY);
78e92337fa4e implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 295
diff changeset
433 UCX_TEST_ASSERT(f1, "open failed");
78e92337fa4e implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 295
diff changeset
434 vfs_close(f1);
78e92337fa4e implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 295
diff changeset
435
78e92337fa4e implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 295
diff changeset
436 // test rmdir
78e92337fa4e implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 295
diff changeset
437 r = vfs_rmdir(vfs, "/rmdir_test/subdir1");
78e92337fa4e implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 295
diff changeset
438 UCX_TEST_ASSERT(r == 0, "rmdir failed");;
78e92337fa4e implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 295
diff changeset
439
297
14cd7137a3a8 handle sql error in pg_remove_res
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 296
diff changeset
440 r = vfs_rmdir(vfs, "/rmdir_test/subdir2");
14cd7137a3a8 handle sql error in pg_remove_res
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 296
diff changeset
441 UCX_TEST_ASSERT(r != 0, "rmdir should fail if the dir is not empty");
296
78e92337fa4e implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 295
diff changeset
442
78e92337fa4e implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 295
diff changeset
443 r = vfs_unlink(vfs, "/rmdir_test/subdir2/file");
78e92337fa4e implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 295
diff changeset
444 UCX_TEST_ASSERT(r == 0, "unlink failed");
78e92337fa4e implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 295
diff changeset
445
78e92337fa4e implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 295
diff changeset
446 r = vfs_rmdir(vfs, "/rmdir_test/subdir2");
78e92337fa4e implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 295
diff changeset
447 UCX_TEST_ASSERT(r == 0, "rmdir failed 2");
78e92337fa4e implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 295
diff changeset
448
78e92337fa4e implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 295
diff changeset
449 UCX_TEST_END;
78e92337fa4e implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 295
diff changeset
450
78e92337fa4e implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 295
diff changeset
451 testutil_destroy_session(sn);
78e92337fa4e implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 295
diff changeset
452 }
306
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
453
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
454 /* ----------------------------- WebDAV tests ----------------------------- */
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
455
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
456
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
457 static WebdavBackend* create_test_pgdav(Session *sn, Request *rq) {
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
458 return pg_webdav_create_from_resdata(sn, rq, &resdata);
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
459 }
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
460
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
461 UCX_TEST(test_pg_webdav_create_from_resdata) {
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
462 Session *sn = testutil_session();
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
463 Request *rq = testutil_request(sn->pool, "PROPFIND", "/");
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
464
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
465 UCX_TEST_BEGIN;
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
466
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
467 WebdavBackend *dav = create_test_pgdav(sn, rq);
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
468 UCX_TEST_ASSERT(dav, "cannot create pg dav backend");
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
469
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
470 UCX_TEST_END;
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
471 }
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
472
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
473 UCX_TEST(test_pg_prepare_tests) {
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
474 Session *sn = testutil_session();
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
475 Request *rq = testutil_request(sn->pool, "PUT", "/");
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
476 rq->vfs = create_test_pgvfs(sn, rq);
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
477 VFSContext *vfs = vfs_request_context(sn, rq);
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
478
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
479 UCX_TEST_BEGIN;
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
480
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
481 vfs_mkdir(vfs, "/propfind");
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
482 SYS_FILE f1;
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
483
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
484 int64_t res1_id, res2_id;
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
485
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
486 f1 = vfs_open(vfs, "/propfind/res1", O_WRONLY|O_CREAT);
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
487 UCX_TEST_ASSERT(f1, "res1 create failed");
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
488 res1_id = ((PgFile*)f1->data)->resource_id;
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
489 vfs_close(f1);
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
490
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
491 f1 = vfs_open(vfs, "/propfind/res2", O_WRONLY|O_CREAT);
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
492 UCX_TEST_ASSERT(f1, "res2 create failed");
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
493 res2_id = ((PgFile*)f1->data)->resource_id;
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
494 vfs_close(f1);
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
495
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
496 f1 = vfs_open(vfs, "/propfind/res3", O_WRONLY|O_CREAT);
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
497 UCX_TEST_ASSERT(f1, "res3 create failed");
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
498 vfs_close(f1);
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
499
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
500 // 2 properties for res1
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
501 char idstr[32];
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
502 snprintf(idstr, 32, "%" PRId64, res1_id);
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
503 const char* params[1] = { idstr };
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
504 PGresult *result = PQexecParams(
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
505 test_connection,
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
506 "insert into Property(resource_id, xmlns, pname, pvalue) values ($1, 'http://example.com/', 'test', 'testvalue');",
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
507 1, // number of parameters
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
508 NULL,
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
509 params, // parameter value
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
510 NULL,
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
511 NULL,
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
512 0); // 0: result in text format
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
513
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
514 UCX_TEST_ASSERT(PQresultStatus(result) == PGRES_COMMAND_OK, "cannot create property 1");
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
515 PQclear(result);
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
516
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
517 result = PQexecParams(
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
518 test_connection,
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
519 "insert into Property(resource_id, xmlns, pname, pvalue) values ($1, 'http://example.com/', 'prop2', 'value2');",
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
520 1, // number of parameters
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
521 NULL,
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
522 params, // parameter value
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
523 NULL,
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
524 NULL,
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
525 0); // 0: result in text format
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
526
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
527 UCX_TEST_ASSERT(PQresultStatus(result) == PGRES_COMMAND_OK, "cannot create property 1");
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
528 PQclear(result);
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
529
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
530 // 1 property for res2
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
531 snprintf(idstr, 32, "%" PRId64, res2_id);
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
532 result = PQexecParams(
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
533 test_connection,
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
534 "insert into Property(resource_id, xmlns, pname, pvalue) values ($1, 'http://example.com/', 'test', 'res2test');",
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
535 1, // number of parameters
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
536 NULL,
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
537 params, // parameter value
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
538 NULL,
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
539 NULL,
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
540 0); // 0: result in text format
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
541
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
542 UCX_TEST_ASSERT(PQresultStatus(result) == PGRES_COMMAND_OK, "cannot create property 1");
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
543 PQclear(result);
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
544
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
545 UCX_TEST_END;
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
546
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
547 testutil_destroy_session(sn);
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
548 }
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
549
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
550 UCX_TEST(test_pg_webdav_propfind) {
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
551 Session *sn;
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
552 Request *rq;
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
553 TestIOStream *st;
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
554 pblock *pb;
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
555
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
556 UCX_TEST_BEGIN;
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
557
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
558 // test data:
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
559 //
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
560 // /propfind/
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
561 // /propfind/res1 (2 properties)
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
562 // /propfind/res2 (1 property)
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
563 // /propfind/res3
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
564
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
565 int ret;
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
566 // Test 1
307
8787cb5ebab3 fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 306
diff changeset
567 init_test_webdav_method(&sn, &rq, &st, &pb, "PROPFIND", "/propfind/", PG_TEST_PROPFIND1);
306
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
568 rq->davCollection = create_test_pgdav(sn, rq);
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
569
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
570 ret = webdav_propfind(pb, sn, rq);
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
571
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
572 UCX_TEST_ASSERT(ret == REQ_PROCEED, "webdav_propfind (1) failed");
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
573
313
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
574 TestMultistatus *ms = test_parse_multistatus(st->buf->space, st->buf->size);
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
575 UCX_TEST_ASSERT(ms, "propfind1: response is not valid xml");
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
576
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
577 TestResponse *r1 = ucx_map_cstr_get(ms->responses, "/propfind/");
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
578 UCX_TEST_ASSERT(r1, "propfind1: missing /propfind/ response");
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
579
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
580 TestProperty *p = ucx_map_cstr_get(r1->properties, "D:resourcetype");
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
581 UCX_TEST_ASSERT(p, "propfind1: missing property 'resourcetype'");
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
582 UCX_TEST_ASSERT(p->status == 200, "propfind1: wrong status code for property 'resourcetype'");
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
583
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
584 p = ucx_map_cstr_get(r1->properties, "D:getlastmodified");
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
585 UCX_TEST_ASSERT(p, "propfind1: missing property 'getlastmodified'");
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
586 UCX_TEST_ASSERT(p->status == 200, "propfind1: wrong status code for property 'getlastmodified'");
306
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
587
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
588 printf("\n\n%.*s\n", (int)st->buf->size, st->buf->space);
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
589
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
590
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
591 testutil_destroy_session(sn);
313
3ad0b65ec838 test pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 307
diff changeset
592 test_multistatus_destroy(ms);
306
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
593 testutil_iostream_destroy(st);
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
594
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
595 UCX_TEST_END;
e03737cea6e2 add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 298
diff changeset
596 }

mercurial