Mon, 25 Apr 2022 21:40:26 +0200
add pg propfind cleanup
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 | |
306
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
49 | #include <libxml/tree.h> |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
50 | |
289
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
51 | |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
52 | static char *pg_connstr = "postgresql://localhost/test1"; |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
53 | static int abort_pg_tests = 0; |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
54 | static PGconn *test_connection; |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
55 | static ResourceData resdata; |
287
a171da778817
prepare build system for postgresql plugin tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
56 | |
296
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
57 | void debug_print_resources(void) { |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
58 | PGresult *result = PQexec(test_connection, "select * from Resource;"); |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
59 | int n = PQntuples(result); |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
60 | printf("\nntuples: %d\n-----------------------------------------------\n", n); |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
61 | printf("%10s %10s %s\n", "resource_id", "parent_id", "nodename"); |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
62 | for(int i=0;i<n;i++) { |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
63 | char *res_id = PQgetvalue(result, i, 0); |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
64 | char *parent_id = PQgetvalue(result, i, 1); |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
65 | char *nodename = PQgetvalue(result, i, 2); |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
66 | printf("%10s %10s %s\n", res_id, parent_id, nodename); |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
67 | } |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
68 | printf("\n"); |
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 | |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
71 | |
287
a171da778817
prepare build system for postgresql plugin tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
72 | 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
|
73 | |
289
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
74 | test_connection = PQconnectdb(pg_connstr); |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
75 | if(!test_connection) { |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
76 | abort_pg_tests = 1; |
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 | |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
79 | if(PQstatus(test_connection) != CONNECTION_OK) { |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
80 | abort_pg_tests = 1; |
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 | |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
83 | ucx_test_register(suite, test_pg_conn); |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
84 | if(!abort_pg_tests) { |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
85 | resdata.data = test_connection; |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
86 | |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
87 | ucx_test_register(suite, test_pg_vfs_open); |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
88 | ucx_test_register(suite, test_pg_vfs_io); |
293
d3899857a81d
add pg stat tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
290
diff
changeset
|
89 | ucx_test_register(suite, test_pg_vfs_stat); |
294
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
293
diff
changeset
|
90 | ucx_test_register(suite, test_pg_vfs_mkdir); |
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
293
diff
changeset
|
91 | ucx_test_register(suite, test_pg_vfs_unlink); |
296
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
92 | 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
|
93 | |
306
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
94 | 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
|
95 | 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
|
96 | 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
|
97 | |
289
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
98 | PGresult *result = PQexec(test_connection, "BEGIN"); |
293
d3899857a81d
add pg stat tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
290
diff
changeset
|
99 | PQclear(result); |
289
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
100 | } |
287
a171da778817
prepare build system for postgresql plugin tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
101 | } |
289
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
102 | |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
103 | UCX_TEST(test_pg_conn) { |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
104 | 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
|
105 | |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
106 | UCX_TEST_BEGIN; |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
107 | |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
108 | if(abort_pg_tests) { |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
109 | int msglen = strlen(msg); |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
110 | if(msglen > 0 && msg[msglen-1] == '\n') { |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
111 | msglen--; |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
112 | } |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
113 | fprintf(stdout, "%.*s: ", msglen, msg); |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
114 | UCX_TEST_ASSERT(1 == 0, "skip pg tests"); |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
115 | } else { |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
116 | UCX_TEST_ASSERT(1 == 1, "ok"); |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
117 | } |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
118 | |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
119 | UCX_TEST_END; |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
120 | } |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
121 | |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
122 | |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
123 | 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
|
124 | 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
|
125 | } |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
126 | |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
127 | |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
128 | UCX_TEST(test_pg_vfs_open) { |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
129 | Session *sn = testutil_session(); |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
130 | Request *rq = testutil_request(sn->pool, "PUT", "/"); |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
131 | rq->vfs = create_test_pgvfs(sn, rq); |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
132 | VFSContext *vfs = vfs_request_context(sn, rq); |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
133 | SYS_FILE file; |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
134 | |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
135 | UCX_TEST_BEGIN; |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
136 | |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
137 | file = vfs_open(vfs, "/test_notfound1", O_RDONLY); |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
138 | 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
|
139 | |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
140 | 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
|
141 | UCX_TEST_ASSERT(file, "cannot create file 1"); |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
142 | |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
143 | vfs_close(file); |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
144 | |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
145 | UCX_TEST_END; |
294
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
293
diff
changeset
|
146 | |
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
293
diff
changeset
|
147 | testutil_destroy_session(sn); |
289
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
148 | } |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
149 | |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
150 | UCX_TEST(test_pg_vfs_io) { |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
151 | Session *sn = testutil_session(); |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
152 | Request *rq = testutil_request(sn->pool, "PUT", "/"); |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
153 | rq->vfs = create_test_pgvfs(sn, rq); |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
154 | VFSContext *vfs = vfs_request_context(sn, rq); |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
155 | SYS_FILE file; |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
156 | SYS_FILE file2; |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
157 | |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
158 | UCX_TEST_BEGIN; |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
159 | |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
160 | 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
|
161 | UCX_TEST_ASSERT(file, "cannot open file1"); |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
162 | |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
163 | int w = system_fwrite(file, "test1\n", 6); |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
164 | UCX_TEST_ASSERT(w == 6, "fwrite ret (1)"); |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
165 | w = system_fwrite(file, "2", 1); |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
166 | UCX_TEST_ASSERT(w == 1, "fwrite ret (2)"); |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
167 | |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
168 | vfs_close(file); |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
169 | |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
170 | file = vfs_open(vfs, "/test_f1", O_RDONLY); |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
171 | 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
|
172 | UCX_TEST_ASSERT(file, "cannot open file1"); |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
173 | UCX_TEST_ASSERT(file2, "cannot open file2"); |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
174 | |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
175 | char buf[128]; |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
176 | int r = system_fread(file, buf, 128); |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
177 | 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
|
178 | |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
179 | w = system_fwrite(file2, buf, r); |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
180 | 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
|
181 | |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
182 | vfs_close(file); |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
183 | vfs_close(file2); |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
184 | |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
185 | file2 = vfs_open(vfs, "/test_f2", O_RDONLY); |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
186 | |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
187 | r = system_fread(file, buf, 128); |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
188 | UCX_TEST_ASSERT(r == 7, "fread ret"); |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
189 | 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
|
190 | |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
191 | vfs_close(file2); |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
192 | |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
193 | |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
194 | UCX_TEST_END; |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
195 | |
294
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
293
diff
changeset
|
196 | testutil_destroy_session(sn); |
289
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
197 | } |
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
287
diff
changeset
|
198 | |
290
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
199 | UCX_TEST(test_pg_vfs_stat) { |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
200 | Session *sn = testutil_session(); |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
201 | Request *rq = testutil_request(sn->pool, "PUT", "/"); |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
202 | rq->vfs = create_test_pgvfs(sn, rq); |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
203 | VFSContext *vfs = vfs_request_context(sn, rq); |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
204 | |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
205 | UCX_TEST_BEGIN; |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
206 | |
293
d3899857a81d
add pg stat tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
290
diff
changeset
|
207 | // testdata, content doesn't matter |
d3899857a81d
add pg stat tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
290
diff
changeset
|
208 | char test1[512]; |
d3899857a81d
add pg stat tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
290
diff
changeset
|
209 | memset(test1, 'x', 512); |
d3899857a81d
add pg stat tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
290
diff
changeset
|
210 | const int test_len1 = 200; |
d3899857a81d
add pg stat tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
290
diff
changeset
|
211 | const int test_len2 = 432; |
d3899857a81d
add pg stat tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
290
diff
changeset
|
212 | |
d3899857a81d
add pg stat tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
290
diff
changeset
|
213 | 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
|
214 | UCX_TEST_ASSERT(f1, "cannot open test_s1"); |
d3899857a81d
add pg stat tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
290
diff
changeset
|
215 | system_fwrite(f1, test1, test_len1); |
d3899857a81d
add pg stat tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
290
diff
changeset
|
216 | vfs_close(f1); |
d3899857a81d
add pg stat tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
290
diff
changeset
|
217 | |
d3899857a81d
add pg stat tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
290
diff
changeset
|
218 | 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
|
219 | UCX_TEST_ASSERT(f2, "cannot open test_s2"); |
d3899857a81d
add pg stat tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
290
diff
changeset
|
220 | system_fwrite(f2, test1, test_len2); |
d3899857a81d
add pg stat tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
290
diff
changeset
|
221 | vfs_close(f2); |
d3899857a81d
add pg stat tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
290
diff
changeset
|
222 | |
d3899857a81d
add pg stat tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
290
diff
changeset
|
223 | struct stat st1, st2; |
d3899857a81d
add pg stat tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
290
diff
changeset
|
224 | int r1 = vfs_stat(vfs, "/test_s1", &st1); |
d3899857a81d
add pg stat tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
290
diff
changeset
|
225 | int r2 = vfs_stat(vfs, "/test_s2", &st2); |
d3899857a81d
add pg stat tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
290
diff
changeset
|
226 | |
d3899857a81d
add pg stat tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
290
diff
changeset
|
227 | UCX_TEST_ASSERT(r1 == 0, "stat1 failed"); |
d3899857a81d
add pg stat tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
290
diff
changeset
|
228 | UCX_TEST_ASSERT(r2 == 0, "stat2 failed"); |
d3899857a81d
add pg stat tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
290
diff
changeset
|
229 | |
d3899857a81d
add pg stat tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
290
diff
changeset
|
230 | 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
|
231 | 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
|
232 | |
d3899857a81d
add pg stat tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
290
diff
changeset
|
233 | int testfail = vfs_stat(vfs, "/test_stat_fail", &st1); |
d3899857a81d
add pg stat tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
290
diff
changeset
|
234 | UCX_TEST_ASSERT(testfail != 0, "stat 3 should fail"); |
d3899857a81d
add pg stat tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
290
diff
changeset
|
235 | |
290
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
236 | UCX_TEST_END; |
294
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
293
diff
changeset
|
237 | |
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
293
diff
changeset
|
238 | testutil_destroy_session(sn); |
290
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
239 | } |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
240 | |
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
241 | UCX_TEST(test_pg_vfs_mkdir) { |
295
73a1243fce15
add pg mkdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
242 | Session *sn = testutil_session(); |
73a1243fce15
add pg mkdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
243 | Request *rq = testutil_request(sn->pool, "PUT", "/"); |
73a1243fce15
add pg mkdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
244 | rq->vfs = create_test_pgvfs(sn, rq); |
73a1243fce15
add pg mkdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
245 | VFSContext *vfs = vfs_request_context(sn, rq); |
290
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
246 | |
295
73a1243fce15
add pg mkdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
247 | UCX_TEST_BEGIN; |
73a1243fce15
add pg mkdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
248 | |
73a1243fce15
add pg mkdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
249 | 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
|
250 | UCX_TEST_ASSERT(f1 == NULL, "open should fail"); |
73a1243fce15
add pg mkdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
251 | |
73a1243fce15
add pg mkdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
252 | int r = vfs_mkdir(vfs, "/test_mkdir"); |
73a1243fce15
add pg mkdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
253 | UCX_TEST_ASSERT(r == 0, "mkdir failed"); |
73a1243fce15
add pg mkdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
254 | |
73a1243fce15
add pg mkdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
255 | 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
|
256 | UCX_TEST_ASSERT(f1, "open failed"); |
73a1243fce15
add pg mkdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
257 | |
73a1243fce15
add pg mkdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
258 | r = vfs_mkdir(vfs, "/test_mkdir/test_sub"); |
73a1243fce15
add pg mkdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
259 | UCX_TEST_ASSERT(r == 0, "mkdir failed (2)"); |
73a1243fce15
add pg mkdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
260 | |
73a1243fce15
add pg mkdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
261 | UCX_TEST_END; |
73a1243fce15
add pg mkdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
262 | |
73a1243fce15
add pg mkdir tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
263 | testutil_destroy_session(sn); |
290
efc10acf539f
implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
264 | } |
294
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
293
diff
changeset
|
265 | |
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
293
diff
changeset
|
266 | UCX_TEST(test_pg_vfs_unlink) { |
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
293
diff
changeset
|
267 | Session *sn = testutil_session(); |
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
293
diff
changeset
|
268 | Request *rq = testutil_request(sn->pool, "PUT", "/"); |
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
293
diff
changeset
|
269 | rq->vfs = create_test_pgvfs(sn, rq); |
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
293
diff
changeset
|
270 | VFSContext *vfs = vfs_request_context(sn, rq); |
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
293
diff
changeset
|
271 | |
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
293
diff
changeset
|
272 | UCX_TEST_BEGIN; |
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
293
diff
changeset
|
273 | |
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
293
diff
changeset
|
274 | 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
|
275 | UCX_TEST_ASSERT(f1, "cannot create test file"); |
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
293
diff
changeset
|
276 | system_fwrite(f1, "test", 4); |
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
293
diff
changeset
|
277 | |
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
293
diff
changeset
|
278 | PgFile *pgfile = f1->data; |
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
293
diff
changeset
|
279 | Oid oid = pgfile->oid; |
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
293
diff
changeset
|
280 | |
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
293
diff
changeset
|
281 | vfs_close(f1); |
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
293
diff
changeset
|
282 | |
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
293
diff
changeset
|
283 | int r = vfs_unlink(vfs, "/test_unlink1"); |
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
293
diff
changeset
|
284 | UCX_TEST_ASSERT(r == 0, "unlink failed"); |
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
293
diff
changeset
|
285 | |
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
293
diff
changeset
|
286 | f1 = vfs_open(vfs, "/test_unlink1", O_RDONLY); |
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
293
diff
changeset
|
287 | UCX_TEST_ASSERT(f1 == NULL, "test file not deleted"); |
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
293
diff
changeset
|
288 | |
298
8f5c556120a5
fix error handling in pg_remove_res
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
297
diff
changeset
|
289 | 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
|
290 | PQclear(result); |
8f5c556120a5
fix error handling in pg_remove_res
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
297
diff
changeset
|
291 | 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
|
292 | 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
|
293 | 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
|
294 | PQclear(result); |
294
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
293
diff
changeset
|
295 | |
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
293
diff
changeset
|
296 | r = vfs_unlink(vfs, "/test_unlink1"); |
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
293
diff
changeset
|
297 | UCX_TEST_ASSERT(r, "unlink should fail"); |
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
293
diff
changeset
|
298 | |
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
293
diff
changeset
|
299 | UCX_TEST_END; |
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
293
diff
changeset
|
300 | |
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
293
diff
changeset
|
301 | testutil_destroy_session(sn); |
277a5896a2ec
implement pg unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
293
diff
changeset
|
302 | } |
296
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
303 | |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
304 | UCX_TEST(test_pg_vfs_rmdir) { |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
305 | Session *sn = testutil_session(); |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
306 | Request *rq = testutil_request(sn->pool, "PUT", "/"); |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
307 | rq->vfs = create_test_pgvfs(sn, rq); |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
308 | VFSContext *vfs = vfs_request_context(sn, rq); |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
309 | |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
310 | 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
|
311 | |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
312 | UCX_TEST_BEGIN; |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
313 | |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
314 | int r; |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
315 | SYS_FILE f1; |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
316 | |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
317 | // prepare some dirs/files |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
318 | r = vfs_mkdir(vfs, "/rmdir_test"); |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
319 | UCX_TEST_ASSERT(r == 0, "mkdir failed (1)"); |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
320 | r = vfs_mkdir(vfs, "/rmdir_test/subdir1"); |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
321 | UCX_TEST_ASSERT(r == 0, "mkdir failed (2)"); |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
322 | r = vfs_mkdir(vfs, "/rmdir_test/subdir2"); |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
323 | UCX_TEST_ASSERT(r == 0, "mkdir failed (3)"); |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
324 | |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
325 | 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
|
326 | UCX_TEST_ASSERT(f1, "open failed"); |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
327 | vfs_close(f1); |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
328 | |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
329 | // test rmdir |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
330 | r = vfs_rmdir(vfs, "/rmdir_test/subdir1"); |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
331 | UCX_TEST_ASSERT(r == 0, "rmdir failed");; |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
332 | |
297
14cd7137a3a8
handle sql error in pg_remove_res
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
296
diff
changeset
|
333 | 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
|
334 | 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
|
335 | |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
336 | r = vfs_unlink(vfs, "/rmdir_test/subdir2/file"); |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
337 | UCX_TEST_ASSERT(r == 0, "unlink failed"); |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
338 | |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
339 | r = vfs_rmdir(vfs, "/rmdir_test/subdir2"); |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
340 | UCX_TEST_ASSERT(r == 0, "rmdir failed 2"); |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
341 | |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
342 | UCX_TEST_END; |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
343 | |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
344 | testutil_destroy_session(sn); |
78e92337fa4e
implement pg rmdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
295
diff
changeset
|
345 | } |
306
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
346 | |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
347 | /* ----------------------------- WebDAV tests ----------------------------- */ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
348 | |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
349 | |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
350 | 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
|
351 | 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
|
352 | } |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
353 | |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
354 | 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
|
355 | Session *sn = testutil_session(); |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
356 | Request *rq = testutil_request(sn->pool, "PROPFIND", "/"); |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
357 | |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
358 | UCX_TEST_BEGIN; |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
359 | |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
360 | WebdavBackend *dav = create_test_pgdav(sn, rq); |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
361 | 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
|
362 | |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
363 | UCX_TEST_END; |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
364 | } |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
365 | |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
366 | UCX_TEST(test_pg_prepare_tests) { |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
367 | Session *sn = testutil_session(); |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
368 | Request *rq = testutil_request(sn->pool, "PUT", "/"); |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
369 | rq->vfs = create_test_pgvfs(sn, rq); |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
370 | VFSContext *vfs = vfs_request_context(sn, rq); |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
371 | |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
372 | UCX_TEST_BEGIN; |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
373 | |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
374 | vfs_mkdir(vfs, "/propfind"); |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
375 | SYS_FILE f1; |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
376 | |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
377 | int64_t res1_id, res2_id; |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
378 | |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
379 | 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
|
380 | UCX_TEST_ASSERT(f1, "res1 create failed"); |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
381 | res1_id = ((PgFile*)f1->data)->resource_id; |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
382 | vfs_close(f1); |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
383 | |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
384 | 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
|
385 | UCX_TEST_ASSERT(f1, "res2 create failed"); |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
386 | res2_id = ((PgFile*)f1->data)->resource_id; |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
387 | vfs_close(f1); |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
388 | |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
389 | 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
|
390 | UCX_TEST_ASSERT(f1, "res3 create failed"); |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
391 | vfs_close(f1); |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
392 | |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
393 | // 2 properties for res1 |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
394 | char idstr[32]; |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
395 | snprintf(idstr, 32, "%" PRId64, res1_id); |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
396 | const char* params[1] = { idstr }; |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
397 | PGresult *result = PQexecParams( |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
398 | test_connection, |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
399 | "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
|
400 | 1, // number of parameters |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
401 | NULL, |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
402 | params, // parameter value |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
403 | NULL, |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
404 | NULL, |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
405 | 0); // 0: result in text format |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
406 | |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
407 | 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
|
408 | PQclear(result); |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
409 | |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
410 | result = PQexecParams( |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
411 | test_connection, |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
412 | "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
|
413 | 1, // number of parameters |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
414 | NULL, |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
415 | params, // parameter value |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
416 | NULL, |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
417 | NULL, |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
418 | 0); // 0: result in text format |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
419 | |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
420 | 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
|
421 | PQclear(result); |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
422 | |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
423 | // 1 property for res2 |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
424 | snprintf(idstr, 32, "%" PRId64, res2_id); |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
425 | result = PQexecParams( |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
426 | test_connection, |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
427 | "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
|
428 | 1, // number of parameters |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
429 | NULL, |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
430 | params, // parameter value |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
431 | NULL, |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
432 | NULL, |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
433 | 0); // 0: result in text format |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
434 | |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
435 | 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
|
436 | PQclear(result); |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
437 | |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
438 | UCX_TEST_END; |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
439 | |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
440 | testutil_destroy_session(sn); |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
441 | } |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
442 | |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
443 | UCX_TEST(test_pg_webdav_propfind) { |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
444 | Session *sn; |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
445 | Request *rq; |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
446 | TestIOStream *st; |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
447 | pblock *pb; |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
448 | |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
449 | UCX_TEST_BEGIN; |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
450 | |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
451 | // test data: |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
452 | // |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
453 | // /propfind/ |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
454 | // /propfind/res1 (2 properties) |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
455 | // /propfind/res2 (1 property) |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
456 | // /propfind/res3 |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
457 | |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
458 | int ret; |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
459 | // Test 1 |
307
8787cb5ebab3
fix href in pg propfind response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
306
diff
changeset
|
460 | 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
|
461 | rq->davCollection = create_test_pgdav(sn, rq); |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
462 | |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
463 | ret = webdav_propfind(pb, sn, rq); |
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_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
|
466 | |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
467 | xmlDoc *doc = xmlReadMemory( |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
468 | st->buf->space, st->buf->size, NULL, NULL, 0); |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
469 | UCX_TEST_ASSERT(doc, "propfind1: response is not valid xml"); |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
470 | |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
471 | 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
|
472 | |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
473 | |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
474 | testutil_destroy_session(sn); |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
475 | xmlFreeDoc(doc); |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
476 | testutil_iostream_destroy(st); |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
477 | |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
478 | UCX_TEST_END; |
e03737cea6e2
add semi functional pg propfind handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
479 | } |