src/server/test/testutils.c

Sun, 19 Mar 2023 16:48:19 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 19 Mar 2023 16:48:19 +0100
changeset 484
c036a8b242a8
parent 415
d938228c382e
child 498
0d80f8a2b29f
permissions
-rw-r--r--

implement webdav xattr namespace lists

211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 /*
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
3 *
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
4 * Copyright 2019 Olaf Wintermann. All rights reserved.
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
5 *
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
8 *
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
11 *
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
15 *
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
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
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
27 */
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
28
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
29 #include <stdio.h>
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
30 #include <stdlib.h>
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
31
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 321
diff changeset
32 #include <cx/string.h>
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 321
diff changeset
33 #include <cx/utils.h>
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 321
diff changeset
34 #include <cx/printf.h>
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
35
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
36 #include "../util/pblock.h"
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
37
232
499711b2a970 add xml writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
38 #include "../util/io.h"
499711b2a970 add xml writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
39
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
40 #include "testutils.h"
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
41
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
42 Session* testutil_session(void) {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
43 pool_handle_t *pool = pool_create();
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
44 NSAPISession *sn = nsapisession_create(pool);
233
c5985d2fc19a add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 232
diff changeset
45 sn->connection = testutil_dummy_connection(pool);
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
46
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
47 return &sn->sn;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
48 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
49
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
50 Request* testutil_request(pool_handle_t *pool, const char *method, const char *uri) {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
51 NSAPIRequest *rq = pool_malloc(pool, sizeof(NSAPIRequest));
321
9bf375c4b5bd fix test request memory initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
52 ZERO(rq, sizeof(NSAPIRequest));
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
53
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
54 HTTPRequest httprequest;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
55 ZERO(&httprequest, sizeof(HTTPRequest));
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
56 request_initialize(pool, &httprequest, rq);
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
57
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 321
diff changeset
58 cxmutstr clf = cx_asprintf("%s %s HTTP/1.1", method, uri);
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
59 pblock_kvinsert(
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
60 pb_key_clf_request,
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
61 clf.ptr,
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
62 clf.length,
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
63 rq->rq.reqpb);
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
64 free(clf.ptr);
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
65
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
66 pblock_nvinsert(
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
67 "method",
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
68 method,
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
69 rq->rq.reqpb);
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
70
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
71 pblock_nvinsert(
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
72 "protocol",
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
73 "HTTP/1.1",
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
74 rq->rq.reqpb);
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
75
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
76 pblock_nvinsert("uri", uri, rq->rq.reqpb);
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
77
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
78 return &rq->rq;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
79 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
80
233
c5985d2fc19a add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 232
diff changeset
81 static int dummyconn_read(Connection *conn, void *buf, int len) {
c5985d2fc19a add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 232
diff changeset
82 return len;
c5985d2fc19a add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 232
diff changeset
83 }
c5985d2fc19a add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 232
diff changeset
84
c5985d2fc19a add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 232
diff changeset
85 static int dummyconn_write(Connection *conn, const void *buf, int len) {
c5985d2fc19a add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 232
diff changeset
86 return len;
c5985d2fc19a add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 232
diff changeset
87 }
c5985d2fc19a add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 232
diff changeset
88
c5985d2fc19a add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 232
diff changeset
89 static void dummyconn_close(Connection *conn) {
c5985d2fc19a add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 232
diff changeset
90
c5985d2fc19a add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 232
diff changeset
91 }
c5985d2fc19a add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 232
diff changeset
92
c5985d2fc19a add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 232
diff changeset
93
c5985d2fc19a add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 232
diff changeset
94 Connection* testutil_dummy_connection(pool_handle_t *pool) {
c5985d2fc19a add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 232
diff changeset
95 Connection *conn = pool_malloc(pool, sizeof(Connection));
c5985d2fc19a add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 232
diff changeset
96 ZERO(conn, sizeof(Connection));
c5985d2fc19a add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 232
diff changeset
97 conn->read = dummyconn_read;
c5985d2fc19a add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 232
diff changeset
98 conn->write = dummyconn_write;
c5985d2fc19a add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 232
diff changeset
99 conn->close = dummyconn_close;
c5985d2fc19a add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 232
diff changeset
100 return conn;
c5985d2fc19a add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 232
diff changeset
101 }
c5985d2fc19a add test for webdav_propfind() that checks if the response is valid xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 232
diff changeset
102
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
103 void testutil_request_body(Session *sn, Request *rq, const char *body, size_t len) {
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 321
diff changeset
104 cxmutstr cl = cx_asprintf("%d", (int)len);
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
105 pblock_nvreplace("content-length", cl.ptr, rq->headers);
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
106 free(cl.ptr);
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
107
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
108 netbuf *inbuf = pool_malloc(sn->pool, sizeof(netbuf));
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
109 inbuf->sd = NULL;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
110 inbuf->inbuf = pool_malloc(sn->pool, len);
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
111 inbuf->pos = 0;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
112 inbuf->maxsize = len;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
113 inbuf->cursize = len;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
114 sn->inbuf = inbuf;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
115
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
116 memcpy(inbuf->inbuf, body, len);
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
117 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
118
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
119 void testutil_destroy_session(Session *sn) {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
120 pool_destroy(sn->pool);
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
121 }
232
499711b2a970 add xml writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
122
499711b2a970 add xml writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
123
499711b2a970 add xml writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
124 static ssize_t test_io_write(IOStream *io, void *buf, size_t size) {
499711b2a970 add xml writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
125 TestIOStream *st = (TestIOStream*)io;
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 321
diff changeset
126 return cxBufferWrite(buf, 1, size, st->buf);
232
499711b2a970 add xml writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
127 }
499711b2a970 add xml writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
128
499711b2a970 add xml writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
129 static ssize_t test_io_writev(IOStream *io, struct iovec *iovec, int iovctn) {
499711b2a970 add xml writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
130 return -1;
499711b2a970 add xml writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
131 }
499711b2a970 add xml writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
132
499711b2a970 add xml writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
133 static ssize_t test_io_read(IOStream *io, void *buf, size_t size) {
499711b2a970 add xml writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
134 return -1;
499711b2a970 add xml writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
135 }
499711b2a970 add xml writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
136
499711b2a970 add xml writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
137 static void test_io_close(IOStream *io) {
499711b2a970 add xml writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
138
499711b2a970 add xml writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
139 }
499711b2a970 add xml writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
140
499711b2a970 add xml writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
141 static void test_io_finish(IOStream *io) {
499711b2a970 add xml writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
142
499711b2a970 add xml writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
143 }
499711b2a970 add xml writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
144
499711b2a970 add xml writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
145 static void test_io_setmode(IOStream *io, int mode) {
499711b2a970 add xml writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
146
499711b2a970 add xml writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
147 }
499711b2a970 add xml writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
148
499711b2a970 add xml writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
149 static int test_io_poll(IOStream *io, EventHandler *ev, int events , Event *event) {
499711b2a970 add xml writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
150 return 1;
499711b2a970 add xml writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
151 }
499711b2a970 add xml writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
152
499711b2a970 add xml writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
153 TestIOStream* testutil_iostream(size_t size, int autoextend) {
499711b2a970 add xml writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
154 TestIOStream *stream = calloc(1, sizeof(TestIOStream));
499711b2a970 add xml writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
155 int flags = 0;
499711b2a970 add xml writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
156 if(autoextend) {
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 321
diff changeset
157 flags = CX_BUFFER_AUTO_EXTEND|CX_BUFFER_FREE_CONTENTS;
232
499711b2a970 add xml writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
158 }
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 321
diff changeset
159 stream->buf = malloc(sizeof(CxBuffer));
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 321
diff changeset
160 cxBufferInit(stream->buf, NULL, size, cxDefaultAllocator, flags);
232
499711b2a970 add xml writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
161
251
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 233
diff changeset
162 stream->io.st.write = test_io_write;
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 233
diff changeset
163 stream->io.st.writev = test_io_writev;
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 233
diff changeset
164 stream->io.st.close = test_io_close;
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 233
diff changeset
165 stream->io.st.finish = test_io_finish;
232
499711b2a970 add xml writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
166
499711b2a970 add xml writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
167 return stream;
499711b2a970 add xml writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
168 }
499711b2a970 add xml writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
169
499711b2a970 add xml writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
170 void testutil_iostream_destroy(TestIOStream *stream) {
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 321
diff changeset
171 cxBufferDestroy(stream->buf);
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 321
diff changeset
172 free(stream->buf);
232
499711b2a970 add xml writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
173 free(stream);
499711b2a970 add xml writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
174 }

mercurial