bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2009-2018 Dovecot authors, see the included COPYING file */
7d548d4984752d74bfea8dc4bf1781a8996f43e7Timo Sirainenstatic void test_istream_concat_one(unsigned int buffer_size)
7d548d4984752d74bfea8dc4bf1781a8996f43e7Timo Sirainen unsigned int i, j;
7d548d4984752d74bfea8dc4bf1781a8996f43e7Timo Sirainen for (i = 0; i < STREAM_COUNT; i++) {
7d548d4984752d74bfea8dc4bf1781a8996f43e7Timo Sirainen streams[i] = test_istream_create(input_string);
7d548d4984752d74bfea8dc4bf1781a8996f43e7Timo Sirainen for (i = 0; i/STREAM_BYTES < STREAM_COUNT; i++) {
7d548d4984752d74bfea8dc4bf1781a8996f43e7Timo Sirainen test_istream_set_size(streams[i/STREAM_BYTES], (i%STREAM_BYTES) + 1);
7d548d4984752d74bfea8dc4bf1781a8996f43e7Timo Sirainen for (j = 0; j < size; j++) {
4efba37e4f27b93832f6147c3a353d6d22c855c7Timo Sirainen test_assert((char)data[j] == input_string[(input->v_offset + j) % STREAM_BYTES]);
5c92436a61569c0b56a9374e60e779fa4455edefTimo Sirainen i_stream_skip(input, i_stream_get_data_size(input));
5c92436a61569c0b56a9374e60e779fa4455edefTimo Sirainen for (i = 0; i < STREAM_COUNT; i++) {
a05250bd599fca0cb8b761c4fd69f91bc1c3667eTimo Sirainen test_assert(streams[i]->eof && streams[i]->stream_errno == 0);
1d020f1c116ce86af2ebd108a453f7bb31240adaPhil Carmody struct istream **streams, *concat, **limits = NULL;
1d020f1c116ce86af2ebd108a453f7bb31240adaPhil Carmody unsigned int i, j, offset, stream_count, data_len, simult;
191153d1a5b0eb0c129139570e3aa5212f28d2acJosef 'Jeff' Sipek stream_count = i_rand_minmax(2, TEST_MAX_ISTREAM_COUNT + 2 - 1);
7d548d4984752d74bfea8dc4bf1781a8996f43e7Timo Sirainen streams = t_new(struct istream *, stream_count + 1);
7d548d4984752d74bfea8dc4bf1781a8996f43e7Timo Sirainen for (i = 0, offset = 0; i < stream_count; i++) {
191153d1a5b0eb0c129139570e3aa5212f28d2acJosef 'Jeff' Sipek data_len = i_rand_minmax(1, TEST_MAX_ISTREAM_SIZE);
7d548d4984752d74bfea8dc4bf1781a8996f43e7Timo Sirainen for (j = 0; j < data_len; j++)
7d548d4984752d74bfea8dc4bf1781a8996f43e7Timo Sirainen streams[i] = test_istream_create_data(w_data, data_len);
1d020f1c116ce86af2ebd108a453f7bb31240adaPhil Carmody i_stream_set_max_buffer_size(concat, TEST_MAX_BUFFER_SIZE);
191153d1a5b0eb0c129139570e3aa5212f28d2acJosef 'Jeff' Sipek simult = i_rand_limit(TEST_MAX_ISTREAM_COUNT);
1d020f1c116ce86af2ebd108a453f7bb31240adaPhil Carmody for (i = 0; i < simult; i++)
1d020f1c116ce86af2ebd108a453f7bb31240adaPhil Carmody limits[i] = i_stream_create_limit(concat, (uoff_t)-1);
32142dc3b19a1dff23ef351596703f1a43ea51a0Timo Sirainen for (i = 0; i < 1000; i++) {
191153d1a5b0eb0c129139570e3aa5212f28d2acJosef 'Jeff' Sipek struct istream *input = (simult == 0) ? concat : limits[i_rand_limit(simult)];
191153d1a5b0eb0c129139570e3aa5212f28d2acJosef 'Jeff' Sipek i_stream_seek(input, i_rand_limit(offset));
32142dc3b19a1dff23ef351596703f1a43ea51a0Timo Sirainen } else if (input->v_offset + size != offset) {
7d548d4984752d74bfea8dc4bf1781a8996f43e7Timo Sirainen for (j = 0; j < size; j++) {
7d548d4984752d74bfea8dc4bf1781a8996f43e7Timo Sirainen test_assert(data[j] == (input->v_offset + j) % 256);
7d548d4984752d74bfea8dc4bf1781a8996f43e7Timo Sirainen for (i = 0; i < stream_count; i++)
1d020f1c116ce86af2ebd108a453f7bb31240adaPhil Carmody for (i = 0; i < simult; i++)
16b5dc27e7db42849510403d37e3629aba14de21Timo Sirainen struct istream *input = i_stream_create_concat(streams);
5c92436a61569c0b56a9374e60e779fa4455edefTimo Sirainenstatic void test_istream_concat_early_end(void)
5c92436a61569c0b56a9374e60e779fa4455edefTimo Sirainen test_istream_set_allow_eof(streams[0], FALSE);
7d548d4984752d74bfea8dc4bf1781a8996f43e7Timo Sirainen unsigned int i;
7d548d4984752d74bfea8dc4bf1781a8996f43e7Timo Sirainen for (i = 1; i < STREAM_BYTES*STREAM_COUNT; i++) {