Mercurial > dovecot > core-2.2
changeset 20808:93ab8e7c6081
lib-test: Allow test_istream_set_*() for test-istream's children.
It will internally find the test_istream from parents. This simplifies the
testing code so that it doesn't have to keep track of both the test_istream
and the final istream.
author | Timo Sirainen <timo.sirainen@dovecot.fi> |
---|---|
date | Fri, 30 Sep 2016 13:04:48 +0300 |
parents | 9c0efffeb1f3 |
children | 6eb2aadab486 |
files | src/lib-test/test-common.c |
diffstat | 1 files changed, 14 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-test/test-common.c Tue Sep 27 20:21:55 2016 +0300 +++ b/src/lib-test/test-common.c Fri Sep 30 13:04:48 2016 +0300 @@ -126,26 +126,34 @@ return test_istream_create_data(data, strlen(data)); } +static struct test_istream *test_istream_find(struct istream *input) +{ + struct istream *in; + + for (in = input; in != NULL; in = in->real_stream->parent) { + if (in->real_stream->read == test_read) + return (struct test_istream *)in->real_stream; + } + i_panic("%s isn't test-istream", i_stream_get_name(input)); +} + void test_istream_set_allow_eof(struct istream *input, bool allow) { - struct test_istream *tstream = - (struct test_istream *)input->real_stream; + struct test_istream *tstream = test_istream_find(input); tstream->allow_eof = allow; } void test_istream_set_max_buffer_size(struct istream *input, size_t size) { - struct test_istream *tstream = - (struct test_istream *)input->real_stream; + struct test_istream *tstream = test_istream_find(input); tstream->istream.max_buffer_size = size; } void test_istream_set_size(struct istream *input, uoff_t size) { - struct test_istream *tstream = - (struct test_istream *)input->real_stream; + struct test_istream *tstream = test_istream_find(input); if (size > (uoff_t)tstream->istream.statbuf.st_size) size = (uoff_t)tstream->istream.statbuf.st_size;