src/server/test/testutils.c

changeset 415
d938228c382e
parent 321
9bf375c4b5bd
child 498
0d80f8a2b29f
equal deleted inserted replaced
414:99a34860c105 415:d938228c382e
27 */ 27 */
28 28
29 #include <stdio.h> 29 #include <stdio.h>
30 #include <stdlib.h> 30 #include <stdlib.h>
31 31
32 #include <ucx/string.h> 32 #include <cx/string.h>
33 #include <ucx/utils.h> 33 #include <cx/utils.h>
34 #include <cx/printf.h>
34 35
35 #include "../util/pblock.h" 36 #include "../util/pblock.h"
36 37
37 #include "../util/io.h" 38 #include "../util/io.h"
38 39
52 53
53 HTTPRequest httprequest; 54 HTTPRequest httprequest;
54 ZERO(&httprequest, sizeof(HTTPRequest)); 55 ZERO(&httprequest, sizeof(HTTPRequest));
55 request_initialize(pool, &httprequest, rq); 56 request_initialize(pool, &httprequest, rq);
56 57
57 sstr_t clf = ucx_sprintf("%s %s HTTP/1.1", method, uri); 58 cxmutstr clf = cx_asprintf("%s %s HTTP/1.1", method, uri);
58 pblock_kvinsert( 59 pblock_kvinsert(
59 pb_key_clf_request, 60 pb_key_clf_request,
60 clf.ptr, 61 clf.ptr,
61 clf.length, 62 clf.length,
62 rq->rq.reqpb); 63 rq->rq.reqpb);
98 conn->close = dummyconn_close; 99 conn->close = dummyconn_close;
99 return conn; 100 return conn;
100 } 101 }
101 102
102 void testutil_request_body(Session *sn, Request *rq, const char *body, size_t len) { 103 void testutil_request_body(Session *sn, Request *rq, const char *body, size_t len) {
103 sstr_t cl = ucx_sprintf("%d", (int)len); 104 cxmutstr cl = cx_asprintf("%d", (int)len);
104 pblock_nvreplace("content-length", cl.ptr, rq->headers); 105 pblock_nvreplace("content-length", cl.ptr, rq->headers);
105 free(cl.ptr); 106 free(cl.ptr);
106 107
107 netbuf *inbuf = pool_malloc(sn->pool, sizeof(netbuf)); 108 netbuf *inbuf = pool_malloc(sn->pool, sizeof(netbuf));
108 inbuf->sd = NULL; 109 inbuf->sd = NULL;
120 } 121 }
121 122
122 123
123 static ssize_t test_io_write(IOStream *io, void *buf, size_t size) { 124 static ssize_t test_io_write(IOStream *io, void *buf, size_t size) {
124 TestIOStream *st = (TestIOStream*)io; 125 TestIOStream *st = (TestIOStream*)io;
125 return ucx_buffer_write(buf, 1, size, st->buf); 126 return cxBufferWrite(buf, 1, size, st->buf);
126 } 127 }
127 128
128 static ssize_t test_io_writev(IOStream *io, struct iovec *iovec, int iovctn) { 129 static ssize_t test_io_writev(IOStream *io, struct iovec *iovec, int iovctn) {
129 return -1; 130 return -1;
130 } 131 }
151 152
152 TestIOStream* testutil_iostream(size_t size, int autoextend) { 153 TestIOStream* testutil_iostream(size_t size, int autoextend) {
153 TestIOStream *stream = calloc(1, sizeof(TestIOStream)); 154 TestIOStream *stream = calloc(1, sizeof(TestIOStream));
154 int flags = 0; 155 int flags = 0;
155 if(autoextend) { 156 if(autoextend) {
156 flags = UCX_BUFFER_AUTOEXTEND; 157 flags = CX_BUFFER_AUTO_EXTEND|CX_BUFFER_FREE_CONTENTS;
157 } 158 }
158 stream->buf = ucx_buffer_new(NULL, size, flags); 159 stream->buf = malloc(sizeof(CxBuffer));
160 cxBufferInit(stream->buf, NULL, size, cxDefaultAllocator, flags);
159 161
160 stream->io.st.write = test_io_write; 162 stream->io.st.write = test_io_write;
161 stream->io.st.writev = test_io_writev; 163 stream->io.st.writev = test_io_writev;
162 stream->io.st.close = test_io_close; 164 stream->io.st.close = test_io_close;
163 stream->io.st.finish = test_io_finish; 165 stream->io.st.finish = test_io_finish;
164 166
165 return stream; 167 return stream;
166 } 168 }
167 169
168 void testutil_iostream_destroy(TestIOStream *stream) { 170 void testutil_iostream_destroy(TestIOStream *stream) {
169 ucx_buffer_free(stream->buf); 171 cxBufferDestroy(stream->buf);
172 free(stream->buf);
170 free(stream); 173 free(stream);
171 } 174 }

mercurial