From: Timo Sirainen Date: Fri, 30 Sep 2016 10:04:48 +0000 (+0300) Subject: lib-test: Allow test_istream_set_*() for test-istream's children. X-Git-Tag: 2.2.26~193 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3def8e553c987012d4030e9ee5aa3eb8a2142e5e;p=thirdparty%2Fdovecot%2Fcore.git 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. --- diff --git a/src/lib-test/test-common.c b/src/lib-test/test-common.c index 78cf31b7c3..2c4d35993c 100644 --- a/src/lib-test/test-common.c +++ b/src/lib-test/test-common.c @@ -126,26 +126,34 @@ struct istream *test_istream_create(const char *data) 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;