test-istream-concat.c revision 16b5dc27e7db42849510403d37e3629aba14de21
a8c5a86d183db25a57bf193c06b41e092ec2e151Timo Sirainen/* Copyright (c) 2009-2017 Dovecot authors, see the included COPYING file */
c99fe55d4535d839a6ad0735c4719e076a1adb2cTimo Sirainenstatic void test_istream_concat_one(unsigned int buffer_size)
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen const unsigned char *data;
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen unsigned int i, j;
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen for (i = 0; i < STREAM_COUNT; i++) {
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen streams[i] = test_istream_create(input_string);
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen for (i = 0; i/STREAM_BYTES < STREAM_COUNT; i++) {
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen test_istream_set_size(streams[i/STREAM_BYTES], (i%STREAM_BYTES) + 1);
4d4d6d4745682790c20d759ba93dbea46b812c5dTimo Sirainen for (j = 0; j < size; j++) {
4d4d6d4745682790c20d759ba93dbea46b812c5dTimo Sirainen test_assert((char)data[j] == input_string[(input->v_offset + j) % STREAM_BYTES]);
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen i_stream_skip(input, i_stream_get_data_size(input));
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen for (i = 0; i < STREAM_COUNT; i++) {
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen struct istream **streams, *concat, **limits = NULL;
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen const unsigned char *data;
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen unsigned char *w_data;
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen unsigned int i, j, offset, stream_count, data_len, simult;
f46363f428d8f2784146d36692b21936a48a7006Timo Sirainen stream_count = (rand() % TEST_MAX_ISTREAM_COUNT) + 2;
f46363f428d8f2784146d36692b21936a48a7006Timo Sirainen streams = t_new(struct istream *, stream_count + 1);
f46363f428d8f2784146d36692b21936a48a7006Timo Sirainen for (i = 0, offset = 0; i < stream_count; i++) {
b437874782ad048daa155e0ac863c2326c3f5e43Timo Sirainen data_len = rand() % TEST_MAX_ISTREAM_SIZE + 1;
b437874782ad048daa155e0ac863c2326c3f5e43Timo Sirainen for (j = 0; j < data_len; j++)
b437874782ad048daa155e0ac863c2326c3f5e43Timo Sirainen streams[i] = test_istream_create_data(w_data, data_len);
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainen i_stream_set_max_buffer_size(concat, TEST_MAX_BUFFER_SIZE);
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen for (i = 0; i < simult; i++)
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen limits[i] = i_stream_create_limit(concat, (uoff_t)-1);
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen for (i = 0; i < 1000; i++) {
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen struct istream *input = (simult == 0) ? concat : limits[rand() % simult];
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen } else if (input->v_offset + size != offset) {
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen for (j = 0; j < size; j++) {
a3fe8c0c54d87822f4b4f8f0d10caac611861b2bTimo Sirainen test_assert(data[j] == (input->v_offset + j) % 256);
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen for (i = 0; i < stream_count; i++)
0c22bef8f5b35c645de8affd8746307fc53bd222Timo Sirainen for (i = 0; i < simult; i++)
8451c4b5afc1ff5366438b2766f75b592c33e1ecTimo Sirainen struct istream *input = i_stream_create_concat(streams);
ca4526e3b5fbf5ea3dd477a2098522a44c9ac52cTimo Sirainenstatic void test_istream_concat_early_end(void)
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen test_istream_set_allow_eof(streams[0], FALSE);
6efdbeab167483597bef087f70ea852d1256a082Timo Sirainen unsigned int i;
6efdbeab167483597bef087f70ea852d1256a082Timo Sirainen for (i = 1; i < STREAM_BYTES*STREAM_COUNT; i++) {