diff -r 4714468b9b7e -r 499711b2a970 src/server/test/testutils.c --- a/src/server/test/testutils.c Fri Jan 17 22:23:30 2020 +0100 +++ b/src/server/test/testutils.c Sat Jan 18 13:48:59 2020 +0100 @@ -34,6 +34,8 @@ #include "../util/pblock.h" +#include "../util/io.h" + #include "testutils.h" Session* testutil_session(void) { @@ -92,3 +94,54 @@ void testutil_destroy_session(Session *sn) { pool_destroy(sn->pool); } + + +static ssize_t test_io_write(IOStream *io, void *buf, size_t size) { + TestIOStream *st = (TestIOStream*)io; + return ucx_buffer_write(buf, 1, size, st->buf); +} + +static ssize_t test_io_writev(IOStream *io, struct iovec *iovec, int iovctn) { + return -1; +} + +static ssize_t test_io_read(IOStream *io, void *buf, size_t size) { + return -1; +} + +static void test_io_close(IOStream *io) { + +} + +static void test_io_finish(IOStream *io) { + +} + +static void test_io_setmode(IOStream *io, int mode) { + +} + +static int test_io_poll(IOStream *io, EventHandler *ev, int events , Event *event) { + return 1; +} + +TestIOStream* testutil_iostream(size_t size, int autoextend) { + TestIOStream *stream = calloc(1, sizeof(TestIOStream)); + int flags = 0; + if(autoextend) { + flags = UCX_BUFFER_AUTOEXTEND; + } + stream->buf = ucx_buffer_new(NULL, size, flags); + + stream->io.write = test_io_write; + stream->io.writev = test_io_writev; + stream->io.close = test_io_close; + stream->io.finish = test_io_finish; + + return stream; +} + +void testutil_iostream_destroy(TestIOStream *stream) { + ucx_buffer_free(stream->buf); + free(stream); +}