src/server/test/testutils.c

branch
webdav
changeset 232
499711b2a970
parent 211
2160585200ac
child 233
c5985d2fc19a
equal deleted inserted replaced
231:4714468b9b7e 232:499711b2a970
31 31
32 #include <ucx/string.h> 32 #include <ucx/string.h>
33 #include <ucx/utils.h> 33 #include <ucx/utils.h>
34 34
35 #include "../util/pblock.h" 35 #include "../util/pblock.h"
36
37 #include "../util/io.h"
36 38
37 #include "testutils.h" 39 #include "testutils.h"
38 40
39 Session* testutil_session(void) { 41 Session* testutil_session(void) {
40 pool_handle_t *pool = pool_create(); 42 pool_handle_t *pool = pool_create();
90 } 92 }
91 93
92 void testutil_destroy_session(Session *sn) { 94 void testutil_destroy_session(Session *sn) {
93 pool_destroy(sn->pool); 95 pool_destroy(sn->pool);
94 } 96 }
97
98
99 static ssize_t test_io_write(IOStream *io, void *buf, size_t size) {
100 TestIOStream *st = (TestIOStream*)io;
101 return ucx_buffer_write(buf, 1, size, st->buf);
102 }
103
104 static ssize_t test_io_writev(IOStream *io, struct iovec *iovec, int iovctn) {
105 return -1;
106 }
107
108 static ssize_t test_io_read(IOStream *io, void *buf, size_t size) {
109 return -1;
110 }
111
112 static void test_io_close(IOStream *io) {
113
114 }
115
116 static void test_io_finish(IOStream *io) {
117
118 }
119
120 static void test_io_setmode(IOStream *io, int mode) {
121
122 }
123
124 static int test_io_poll(IOStream *io, EventHandler *ev, int events , Event *event) {
125 return 1;
126 }
127
128 TestIOStream* testutil_iostream(size_t size, int autoextend) {
129 TestIOStream *stream = calloc(1, sizeof(TestIOStream));
130 int flags = 0;
131 if(autoextend) {
132 flags = UCX_BUFFER_AUTOEXTEND;
133 }
134 stream->buf = ucx_buffer_new(NULL, size, flags);
135
136 stream->io.write = test_io_write;
137 stream->io.writev = test_io_writev;
138 stream->io.close = test_io_close;
139 stream->io.finish = test_io_finish;
140
141 return stream;
142 }
143
144 void testutil_iostream_destroy(TestIOStream *stream) {
145 ucx_buffer_free(stream->buf);
146 free(stream);
147 }

mercurial