src/server/plugins/postgresql/pgtest.c

Sun, 17 Apr 2022 11:51:37 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 17 Apr 2022 11:51:37 +0200
branch
webdav
changeset 292
7c31bcd5b4be
parent 290
efc10acf539f
child 293
d3899857a81d
permissions
-rw-r--r--

update pg resource metadata on close

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>
a171da778817 prepare build system for postgresql plugin tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
30
289
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
31 #include "../../util/util.h"
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
32 #include "../../test/testutils.h"
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
33 #include "../../public/nsapi.h"
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
34
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
35 #include <ucx/string.h>
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
36 #include <ucx/utils.h>
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
37
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
38 #include "pgtest.h"
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
39 #include "vfs.h"
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
40
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
41 #include <libpq-fe.h>
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
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
44 static char *pg_connstr = "postgresql://localhost/test1";
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
45 static int abort_pg_tests = 0;
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
46 static PGconn *test_connection;
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
47 static ResourceData resdata;
287
a171da778817 prepare build system for postgresql plugin tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
48
a171da778817 prepare build system for postgresql plugin tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
49 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
50
289
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
51 test_connection = PQconnectdb(pg_connstr);
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
52 if(!test_connection) {
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
53 abort_pg_tests = 1;
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
54 }
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
55
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
56 if(PQstatus(test_connection) != CONNECTION_OK) {
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
57 abort_pg_tests = 1;
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
58 }
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
59
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
60 ucx_test_register(suite, test_pg_conn);
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
61 if(!abort_pg_tests) {
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
62 resdata.data = test_connection;
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
63
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
64 ucx_test_register(suite, test_pg_vfs_open);
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
65 ucx_test_register(suite, test_pg_vfs_io);
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
66
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
67 PGresult *result = PQexec(test_connection, "BEGIN");
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
68 }
287
a171da778817 prepare build system for postgresql plugin tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
69 }
289
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
70
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
71 UCX_TEST(test_pg_conn) {
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
72 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
73
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
74 UCX_TEST_BEGIN;
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
75
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
76 if(abort_pg_tests) {
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
77 int msglen = strlen(msg);
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
78 if(msglen > 0 && msg[msglen-1] == '\n') {
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
79 msglen--;
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 fprintf(stdout, "%.*s: ", msglen, msg);
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
82 UCX_TEST_ASSERT(1 == 0, "skip pg tests");
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
83 } else {
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
84 UCX_TEST_ASSERT(1 == 1, "ok");
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
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
87 UCX_TEST_END;
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
88 }
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
89
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
90
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
91 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
92 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
93 }
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
94
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
95
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
96 UCX_TEST(test_pg_vfs_open) {
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
97 Session *sn = testutil_session();
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
98 Request *rq = testutil_request(sn->pool, "PUT", "/");
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
99 rq->vfs = create_test_pgvfs(sn, rq);
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
100 VFSContext *vfs = vfs_request_context(sn, rq);
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
101 SYS_FILE file;
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_BEGIN;
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
104
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
105 file = vfs_open(vfs, "/test_notfound1", O_RDONLY);
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
106 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
107
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
108 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
109 UCX_TEST_ASSERT(file, "cannot create file 1");
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
110
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
111 vfs_close(file);
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 UCX_TEST_END;
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
114 }
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
115
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
116 UCX_TEST(test_pg_vfs_io) {
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
117 Session *sn = testutil_session();
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
118 Request *rq = testutil_request(sn->pool, "PUT", "/");
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
119 rq->vfs = create_test_pgvfs(sn, rq);
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
120 VFSContext *vfs = vfs_request_context(sn, rq);
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
121 SYS_FILE file;
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
122 SYS_FILE file2;
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
123
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
124 UCX_TEST_BEGIN;
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 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
127 UCX_TEST_ASSERT(file, "cannot open file1");
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
128
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
129 int w = system_fwrite(file, "test1\n", 6);
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
130 UCX_TEST_ASSERT(w == 6, "fwrite ret (1)");
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
131 w = system_fwrite(file, "2", 1);
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
132 UCX_TEST_ASSERT(w == 1, "fwrite ret (2)");
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
133
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
134 vfs_close(file);
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
135
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
136 file = vfs_open(vfs, "/test_f1", O_RDONLY);
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
137 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
138 UCX_TEST_ASSERT(file, "cannot open file1");
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
139 UCX_TEST_ASSERT(file2, "cannot open file2");
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
140
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
141 char buf[128];
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
142 int r = system_fread(file, buf, 128);
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
143 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
144
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
145 w = system_fwrite(file2, buf, r);
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
146 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
147
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
148 vfs_close(file);
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
149 vfs_close(file2);
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
150
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
151 file2 = vfs_open(vfs, "/test_f2", O_RDONLY);
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
152
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
153 r = system_fread(file, buf, 128);
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
154 UCX_TEST_ASSERT(r == 7, "fread ret");
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
155 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
156
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
157 vfs_close(file2);
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
158
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 UCX_TEST_END;
285d483db2fb add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 287
diff changeset
161
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
290
efc10acf539f implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 289
diff changeset
164 UCX_TEST(test_pg_vfs_stat) {
efc10acf539f implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 289
diff changeset
165 Session *sn = testutil_session();
efc10acf539f implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 289
diff changeset
166 Request *rq = testutil_request(sn->pool, "PUT", "/");
efc10acf539f implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 289
diff changeset
167 rq->vfs = create_test_pgvfs(sn, rq);
efc10acf539f implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 289
diff changeset
168 VFSContext *vfs = vfs_request_context(sn, rq);
efc10acf539f implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 289
diff changeset
169 SYS_FILE file;
efc10acf539f implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 289
diff changeset
170 SYS_FILE file2;
efc10acf539f implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 289
diff changeset
171
efc10acf539f implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 289
diff changeset
172 UCX_TEST_BEGIN;
efc10acf539f implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 289
diff changeset
173
efc10acf539f implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 289
diff changeset
174 UCX_TEST_END;
efc10acf539f implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 289
diff changeset
175 }
efc10acf539f implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 289
diff changeset
176
efc10acf539f implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 289
diff changeset
177 UCX_TEST(test_pg_vfs_mkdir) {
efc10acf539f implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 289
diff changeset
178
efc10acf539f implement pg vfs mkdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 289
diff changeset
179 }

mercurial