]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-test: Allow test_istream_set_*() for test-istream's children.
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Fri, 30 Sep 2016 10:04:48 +0000 (13:04 +0300)
committerGitLab <gitlab@git.dovecot.net>
Fri, 30 Sep 2016 12:02:41 +0000 (15:02 +0300)
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.

src/lib-test/test-common.c

index 7bc950e0b86c90fba59daf81a295902e4ad80584..f3f80929c3eac17dd508d9bf4feafcca9717b142 100644 (file)
@@ -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;