src/server/test/testutils.c

Tue, 09 Aug 2022 19:01:54 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Tue, 09 Aug 2022 19:01:54 +0200
branch
webdav
changeset 367
1592224f6059
parent 321
9bf375c4b5bd
child 415
d938228c382e
permissions
-rw-r--r--

add support for name/value config args

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
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
32 #include <ucx/string.h>
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
33 #include <ucx/utils.h>
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
34
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
35 #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
36
232
499711b2a970 add xml writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
37 #include "../util/io.h"
499711b2a970 add xml writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
38
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
39 #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
40
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
41 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
42 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
43 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
44 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
45
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
46 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
47 }
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 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
50 NSAPIRequest *rq = pool_malloc(pool, sizeof(NSAPIRequest));
321
9bf375c4b5bd fix test request memory initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 251
diff changeset
51 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
52
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
53 HTTPRequest httprequest;
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
54 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
55 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
56
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
57 sstr_t clf = ucx_sprintf("%s %s HTTP/1.1", method, uri);
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
58 pblock_kvinsert(
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
59 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
60 clf.ptr,
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
61 clf.length,
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
62 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
63 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
64
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
65 pblock_nvinsert(
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
66 "method",
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 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
69
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
70 pblock_nvinsert(
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
71 "protocol",
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
72 "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
73 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
74
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
75 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
76
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
77 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
78 }
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
79
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
80 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
81 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
82 }
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 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
85 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
86 }
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 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
89
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 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
94 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
95 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
96 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
97 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
98 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
99 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
100 }
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
211
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
102 void testutil_request_body(Session *sn, Request *rq, const char *body, size_t len) {
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
103 sstr_t cl = ucx_sprintf("%d", (int)len);
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
104 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
105 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
106
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
107 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
108 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
109 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
110 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
111 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
112 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
113 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
114
2160585200ac add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
115 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
116 }
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 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
119 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
120 }
232
499711b2a970 add xml writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
121
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 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
124 TestIOStream *st = (TestIOStream*)io;
499711b2a970 add xml writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
125 return ucx_buffer_write(buf, 1, size, st->buf);
499711b2a970 add xml writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
126 }
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 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
129 return -1;
499711b2a970 add xml writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
130 }
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 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
133 return -1;
499711b2a970 add xml writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
134 }
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 static void test_io_close(IOStream *io) {
499711b2a970 add xml writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
137
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 static void test_io_finish(IOStream *io) {
499711b2a970 add xml writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
141
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 static void test_io_setmode(IOStream *io, int mode) {
499711b2a970 add xml writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
145
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 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
149 return 1;
499711b2a970 add xml writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
150 }
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 TestIOStream* testutil_iostream(size_t size, int autoextend) {
499711b2a970 add xml writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
153 TestIOStream *stream = calloc(1, sizeof(TestIOStream));
499711b2a970 add xml writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
154 int flags = 0;
499711b2a970 add xml writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
155 if(autoextend) {
499711b2a970 add xml writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
156 flags = UCX_BUFFER_AUTOEXTEND;
499711b2a970 add xml writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
157 }
499711b2a970 add xml writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
158 stream->buf = ucx_buffer_new(NULL, size, flags);
499711b2a970 add xml writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
159
251
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 233
diff changeset
160 stream->io.st.write = test_io_write;
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 233
diff changeset
161 stream->io.st.writev = test_io_writev;
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 233
diff changeset
162 stream->io.st.close = test_io_close;
f727a21497bb add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 233
diff changeset
163 stream->io.st.finish = test_io_finish;
232
499711b2a970 add xml writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
164
499711b2a970 add xml writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
165 return stream;
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
499711b2a970 add xml writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
168 void testutil_iostream_destroy(TestIOStream *stream) {
499711b2a970 add xml writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
169 ucx_buffer_free(stream->buf);
499711b2a970 add xml writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
170 free(stream);
499711b2a970 add xml writer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 211
diff changeset
171 }

mercurial