From: Timo Sirainen Date: Thu, 25 Feb 2010 07:54:12 +0000 (+0200) Subject: Removed istream test code that hasn't been tried for years. X-Git-Tag: 2.0.beta4~160 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=0e8fd7a2a52e3682ddfe1b6f52e1bd379fae4c36;p=thirdparty%2Fdovecot%2Fcore.git Removed istream test code that hasn't been tried for years. --HG-- branch : HEAD --- diff --git a/src/lib/istream.c b/src/lib/istream.c index 1d93c23583..6da8a426eb 100644 --- a/src/lib/istream.c +++ b/src/lib/istream.c @@ -583,118 +583,3 @@ i_stream_create(struct istream_private *_stream, struct istream *parent, int fd) io_stream_init(&_stream->iostream); return &_stream->istream; } - -#ifdef STREAM_TEST -/* gcc istream.c -o teststream liblib.a -Wall -DHAVE_CONFIG_H -DSTREAM_TEST -g */ - -#include -#include -#include "ostream.h" - -#define BUF_VALUE(offset) \ - (((offset) % 256) ^ ((offset) / 256)) - -static void check_buffer(const unsigned char *data, size_t size, size_t offset) -{ - size_t i; - - for (i = 0; i < size; i++) - i_assert(data[i] == BUF_VALUE(i+offset)); -} - -int main(void) -{ - struct istream *input, *l_input; - struct ostream *output1, *output2; - int i, fd1, fd2; - unsigned char buf[1024]; - const unsigned char *data; - size_t size; - - lib_init(); - - fd1 = open("teststream.1", O_RDWR | O_CREAT | O_TRUNC, 0600); - if (fd1 < 0) - i_fatal("open() failed: %m"); - fd2 = open("teststream.2", O_RDWR | O_CREAT | O_TRUNC, 0600); - if (fd2 < 0) - i_fatal("open() failed: %m"); - - /* write initial data */ - for (i = 0; i < sizeof(buf); i++) - buf[i] = BUF_VALUE(i); - write(fd1, buf, sizeof(buf)); - - /* test reading */ - input = i_stream_create_fd(fd1, 512, FALSE); - i_assert(i_stream_get_size(input) == sizeof(buf)); - - i_assert(i_stream_read_data(input, &data, &size, 0) > 0); - i_assert(size == 512); - check_buffer(data, size, 0); - - i_stream_seek(input, 256); - i_assert(i_stream_read_data(input, &data, &size, 0) > 0); - i_assert(size == 512); - check_buffer(data, size, 256); - - i_stream_seek(input, 0); - i_assert(i_stream_read_data(input, &data, &size, 512) == -2); - i_assert(size == 512); - check_buffer(data, size, 0); - - i_stream_skip(input, 900); - i_assert(i_stream_read_data(input, &data, &size, 0) > 0); - i_assert(size == sizeof(buf) - 900); - check_buffer(data, size, 900); - - /* test moving data */ - output1 = o_stream_create_fd(fd1, 512, FALSE); - output2 = o_stream_create_fd(fd2, 512, FALSE); - - i_stream_seek(input, 1); size = sizeof(buf)-1; - i_assert(o_stream_send_istream(output2, input) == size); - o_stream_flush(output2); - - lseek(fd2, 0, SEEK_SET); - i_assert(read(fd2, buf, sizeof(buf)) == size); - check_buffer(buf, size, 1); - - i_stream_seek(input, 0); - o_stream_seek(output1, sizeof(buf)); - i_assert(o_stream_send_istream(output1, input) == sizeof(buf)); - - /* test moving with limits */ - l_input = i_stream_create_limit(input, sizeof(buf)/2, 512); - i_stream_seek(l_input, 0); - o_stream_seek(output1, 10); - i_assert(o_stream_send_istream(output1, l_input) == 512); - - i_stream_set_max_buffer_size(input, sizeof(buf)); - - i_stream_seek(input, 0); - i_assert(i_stream_read_data(input, &data, &size, sizeof(buf)-1) > 0); - i_assert(size == sizeof(buf)); - check_buffer(data, 10, 0); - check_buffer(data + 10, 512, sizeof(buf)/2); - check_buffer(data + 10 + 512, - size - (10 + 512), 10 + 512); - - /* reading within limits */ - i_stream_seek(l_input, 0); - i_assert(i_stream_read_data(l_input, &data, &size, 511) > 0); - i_assert(size == 512); - i_assert(i_stream_read_data(l_input, &data, &size, 512) == -2); - i_assert(size == 512); - i_stream_skip(l_input, 511); - i_assert(i_stream_read_data(l_input, &data, &size, 0) > 0); - i_assert(size == 1); - i_stream_skip(l_input, 1); - i_assert(i_stream_read_data(l_input, &data, &size, 0) == -1); - i_assert(size == 0); - - unlink("teststream.1"); - unlink("teststream.2"); - return 0; -} -#endif