test-istream-chain.c revision bac6427712674cd4b6146ef51f90c14eb9603db6
6509aa7306649042e828fef9e2f280f4535ea137Timo Sirainen/* Copyright (c) 2016 Dovecot authors, see the included COPYING file */
6509aa7306649042e828fef9e2f280f4535ea137Timo Sirainen struct istream *input, *test_input, *test_input2;
6509aa7306649042e828fef9e2f280f4535ea137Timo Sirainen const unsigned char *data;
6509aa7306649042e828fef9e2f280f4535ea137Timo Sirainen /* no input */
6509aa7306649042e828fef9e2f280f4535ea137Timo Sirainen /* stream1 input */
6509aa7306649042e828fef9e2f280f4535ea137Timo Sirainen test_assert(size == 7 && memcmp(data, "stream1", 7) == 0);
6509aa7306649042e828fef9e2f280f4535ea137Timo Sirainen test_assert(size == 7 && memcmp(data, "stream1", 7) == 0);
6509aa7306649042e828fef9e2f280f4535ea137Timo Sirainen /* STREAM2 input */
6509aa7306649042e828fef9e2f280f4535ea137Timo Sirainen test_assert(size == 14 && memcmp(data, "stream1STREAM2", 14) == 0);
6509aa7306649042e828fef9e2f280f4535ea137Timo Sirainen test_assert(size == 14 && memcmp(data, "stream1STREAM2", 14) == 0);
6509aa7306649042e828fef9e2f280f4535ea137Timo Sirainen test_assert(size == 14 && memcmp(data, "stream1STREAM2", 14) == 0);
6509aa7306649042e828fef9e2f280f4535ea137Timo Sirainen test_istream_set_allow_eof(test_input, FALSE);
6509aa7306649042e828fef9e2f280f4535ea137Timo Sirainen /* with current implementation we could skip less than 5 and have
6509aa7306649042e828fef9e2f280f4535ea137Timo Sirainen v_offset<5, but I don't think that can work in all situations.
6509aa7306649042e828fef9e2f280f4535ea137Timo Sirainen the normal case is anyway that we'll read everything up until some
6509aa7306649042e828fef9e2f280f4535ea137Timo Sirainen point and skip over all the data up to there. */
6509aa7306649042e828fef9e2f280f4535ea137Timo Sirainenstatic void test_istream_chain_accumulate(void)
6509aa7306649042e828fef9e2f280f4535ea137Timo Sirainen struct istream *test_input, *test_input2, *test_input3, *test_input4,
6509aa7306649042e828fef9e2f280f4535ea137Timo Sirainen const unsigned char *data;
6509aa7306649042e828fef9e2f280f4535ea137Timo Sirainen test_input = test_istream_create("aaaaaaaaaaaaaaaaaaaa");
6509aa7306649042e828fef9e2f280f4535ea137Timo Sirainen test_input2 = test_istream_create("bbbbbbbbbbbbbbbbbbbbbbbbb");
6509aa7306649042e828fef9e2f280f4535ea137Timo Sirainen test_input3 = test_istream_create("cccccccccccccccccccccccccccccc");
6509aa7306649042e828fef9e2f280f4535ea137Timo Sirainen test_input4 = test_istream_create("ddddddddddddddddddddddddd");
6509aa7306649042e828fef9e2f280f4535ea137Timo Sirainen test_input5 = test_istream_create("eeeeeeeeeeeeeeeeeeee");
6509aa7306649042e828fef9e2f280f4535ea137Timo Sirainen /* no input */
6509aa7306649042e828fef9e2f280f4535ea137Timo Sirainen /* first stream */
6509aa7306649042e828fef9e2f280f4535ea137Timo Sirainen test_assert(i_stream_read_data(input, &data, &size, 0) == 1);
6509aa7306649042e828fef9e2f280f4535ea137Timo Sirainen test_assert(memcmp(data, "aaaaaaaaaaaaaaaaaaaa", 20) == 0);
6509aa7306649042e828fef9e2f280f4535ea137Timo Sirainen /* partially skip */
6509aa7306649042e828fef9e2f280f4535ea137Timo Sirainen /* second stream */
6509aa7306649042e828fef9e2f280f4535ea137Timo Sirainen test_assert(i_stream_read_data(input, &data, &size, 10) == 1);
6509aa7306649042e828fef9e2f280f4535ea137Timo Sirainen /* partially skip */
6509aa7306649042e828fef9e2f280f4535ea137Timo Sirainen /* third stream */
6509aa7306649042e828fef9e2f280f4535ea137Timo Sirainen test_assert(i_stream_read_data(input, &data, &size, 25) == 1);
6509aa7306649042e828fef9e2f280f4535ea137Timo Sirainen test_assert(memcmp(data, "bbbbbbbbbbbbbbbbbbbbb"
6509aa7306649042e828fef9e2f280f4535ea137Timo Sirainen /* partially skip */
6509aa7306649042e828fef9e2f280f4535ea137Timo Sirainen /* forth stream */
6509aa7306649042e828fef9e2f280f4535ea137Timo Sirainen test_assert(i_stream_read_data(input, &data, &size, 40) == 1);
6509aa7306649042e828fef9e2f280f4535ea137Timo Sirainen "cccccccccccccccccccccccccccccc"
6509aa7306649042e828fef9e2f280f4535ea137Timo Sirainen /* partially skip */
6509aa7306649042e828fef9e2f280f4535ea137Timo Sirainen /* fifth stream */
6509aa7306649042e828fef9e2f280f4535ea137Timo Sirainen test_assert(i_stream_read_data(input, &data, &size, 60) == 1);
test_end();
void test_istream_chain(void)