]> 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)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Thu, 13 Oct 2016 08:19:46 +0000 (10:19 +0200)
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 78cf31b7c36457bacd96d4cb71267d98f64eb946..2c4d35993c749d97526ccf08c250792230f0b6e3 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;