]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-compression: test-compression - Convert from ostream-buffer to iostream-temp
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Mon, 14 Sep 2020 07:27:26 +0000 (10:27 +0300)
committerTimo Sirainen <timo.sirainen@open-xchange.com>
Mon, 14 Sep 2020 09:22:40 +0000 (12:22 +0300)
Using ostream-buffer required 48083d9e7fdbe257b0be33043ecf0ca87489eef9
change, but this broke some code that assumed the original behavior.

src/lib-compression/test-compression.c

index 9873db543f23ad02b88c1c93d2392b2c151cbd9c..1d65426c1f61594aae61946b99b0253ef9bd725e 100644 (file)
@@ -3,7 +3,7 @@
 #include "lib.h"
 #include "buffer.h"
 #include "istream.h"
-#include "istream-hash.h"
+#include "iostream-temp.h"
 #include "ostream.h"
 #include "sha1.h"
 #include "randgen.h"
@@ -533,8 +533,7 @@ test_compression_handler_large_random_io(const struct compression_handler *handl
 #define RANDOMNESS_SIZE (1024*1024)
        unsigned char *randomness;
        struct istream *input, *dec_input;
-       struct ostream *buf_output, *output;
-       buffer_t *buf;
+       struct ostream *temp_output, *output;
        const unsigned char *data;
        size_t size;
        int ret;
@@ -546,9 +545,8 @@ test_compression_handler_large_random_io(const struct compression_handler *handl
        /* write 1 MB of randomness to buffer */
        input = i_stream_create_from_data(randomness, RANDOMNESS_SIZE);
 
-       buf = buffer_create_dynamic(default_pool, 1024);
-       buf_output = o_stream_create_buffer(buf);
-       output = handler->create_ostream(buf_output, i_rand_minmax(1, 6));
+       temp_output = iostream_temp_create(".temp.", 0);
+       output = handler->create_ostream(temp_output, i_rand_minmax(1, 6));
 
        switch (o_stream_send_istream(output, input)) {
        case OSTREAM_SEND_ISTREAM_RESULT_ERROR_INPUT:
@@ -564,13 +562,12 @@ test_compression_handler_large_random_io(const struct compression_handler *handl
        }
        test_assert(output->offset == RANDOMNESS_SIZE);
        test_assert(output->stream_errno == 0);
-       o_stream_unref(&buf_output);
-       o_stream_unref(&output);
        i_stream_unref(&input);
 
+       input = iostream_temp_finish(&temp_output, SIZE_MAX);
+
        /* verify that reading the input works */
 
-       input = i_stream_create_from_data(buf->data, buf->used);
        dec_input = handler->create_istream(input, FALSE);
 
        while ((ret = i_stream_read_more(dec_input, &data, &size)) > 0) {
@@ -583,7 +580,6 @@ test_compression_handler_large_random_io(const struct compression_handler *handl
 
        i_stream_unref(&dec_input);
        i_stream_unref(&input);
-       buffer_free(&buf);
        i_free(randomness);
        test_end();
 }