#include "lib.h"
#include "buffer.h"
+#include "memarea.h"
#include "istream-private.h"
#include "istream-concat.h"
/* we already verified that the data size is less than the
maximum buffer size */
+ cstream->istream.skip = 0;
cstream->istream.pos = 0;
if (data_size > 0) {
+ if (cstream->istream.memarea != NULL &&
+ memarea_get_refcount(cstream->istream.memarea) > 1)
+ i_stream_memarea_detach(&cstream->istream);
if (!i_stream_try_alloc(&cstream->istream, data_size, &size))
i_unreached();
i_assert(size >= data_size);
cstream->istream.istream.readable_fd = FALSE;
cstream->istream.istream.blocking = blocking;
cstream->istream.istream.seekable = seekable;
- return i_stream_create(&cstream->istream, NULL, -1,
- ISTREAM_CREATE_FLAG_NOOP_SNAPSHOT);
+ return i_stream_create(&cstream->istream, NULL, -1, 0);
}
for (j = 0; j < size; j++) {
test_assert((char)data[j] == input_string[(input->v_offset + j) % STREAM_BYTES]);
}
+ test_assert(i_stream_read(input) <= 0);
}
test_assert(i_stream_read(input) == -1);
i_stream_skip(input, i_stream_get_data_size(input));
test_end();
}
+static void test_istream_concat_snapshot(void)
+{
+ struct istream *input;
+ const unsigned char *data;
+ size_t size;
+
+ test_begin("istream concat snapshot");
+
+ struct istream *test_istreams[] = {
+ test_istream_create("abcdefghijklmnopqrst"),
+ test_istream_create("ABCDEFGHIJKLMNOPQRSTUVWXY"),
+ test_istream_create("!\"#$%&'()*+,-./01234567890:;<="),
+ NULL
+ };
+
+ input = i_stream_create_concat(test_istreams);
+ test_istream_set_size(test_istreams[0], 20);
+ test_istream_set_size(test_istreams[1], 0);
+ test_istream_set_size(test_istreams[2], 0);
+
+ /* first stream */
+ test_istream_set_allow_eof(test_istreams[0], FALSE);
+ test_assert(i_stream_read_data(input, &data, &size, 0) == 1);
+ test_assert(size == 20);
+ test_assert(memcmp(data, "abcdefghijklmnopqrst", 20) == 0);
+
+ /* partially skip */
+ i_stream_skip(input, 12);
+
+ /* second stream */
+ test_assert(i_stream_read_data(input, &data, &size, 10) == 0);
+ test_assert(size == 8);
+ test_istream_set_allow_eof(test_istreams[0], TRUE);
+ test_istream_set_size(test_istreams[0], 0);
+ test_assert(i_stream_read_data(input, &data, &size, 10) == 0);
+ test_assert(size == 8);
+ test_istream_set_size(test_istreams[1], 10);
+ test_assert(i_stream_read_data(input, &data, &size, 10) == 1);
+ test_assert(size == 18);
+ test_istream_set_allow_eof(test_istreams[1], FALSE);
+ test_assert(i_stream_read(input) == 0);
+ test_istream_set_size(test_istreams[1], 25);
+ test_istream_set_allow_eof(test_istreams[1], TRUE);
+ test_assert(i_stream_read_data(input, &data, &size, 30) == 1);
+ test_assert(size == 33);
+ test_assert(memcmp(data, "mnopqrst"
+ "ABCDEFGHIJKLMNOPQRSTUVWXY", 33) == 0);
+
+ /* partially skip */
+ i_stream_skip(input, 12);
+
+ /* third stream */
+ test_istream_set_size(test_istreams[2], 0);
+ test_assert(i_stream_read(input) == 0);
+ test_istream_set_size(test_istreams[2], 30);
+ test_assert(i_stream_read_data(input, &data, &size, 25) == 1);
+ test_assert(size == 51);
+ test_assert(memcmp(data, "EFGHIJKLMNOPQRSTUVWXY"
+ "!\"#$%&'()*+,-./01234567890:;<=", 51) == 0);
+
+ i_stream_unref(&input);
+ for (unsigned int i = 0; test_istreams[i] != NULL; i++)
+ i_stream_unref(&test_istreams[i]);
+ test_end();
+}
+
void test_istream_concat(void)
{
unsigned int i;
test_istream_concat_seek_end();
test_istream_concat_early_end();
+ test_istream_concat_snapshot();
}