test-istream.c revision d47bd663deb1846980e6759c87297741a5459890
7cb128dc4cae2a03a742f63ba7afee23c78e3af0Phil Carmody/* Copyright (c) 2014-2015 Dovecot authors, see the included COPYING file */
f5982bb5b0a704e88fa2b44b0b74e365d13103b9Timo Sirainen const unsigned char *data;
f5982bb5b0a704e88fa2b44b0b74e365d13103b9Timo Sirainen parent = test_istream_create_data("123456789", 9);
f5982bb5b0a704e88fa2b44b0b74e365d13103b9Timo Sirainen child1 = i_stream_create_limit(parent, (uoff_t)-1);
f5982bb5b0a704e88fa2b44b0b74e365d13103b9Timo Sirainen child2 = i_stream_create_limit(parent, (uoff_t)-1);
f5982bb5b0a704e88fa2b44b0b74e365d13103b9Timo Sirainen /* child1 read beginning */
f5982bb5b0a704e88fa2b44b0b74e365d13103b9Timo Sirainen test_assert(size == 3 && memcmp(data, "123", 3) == 0);
f5982bb5b0a704e88fa2b44b0b74e365d13103b9Timo Sirainen /* child1 read middle.. */
f5982bb5b0a704e88fa2b44b0b74e365d13103b9Timo Sirainen test_assert(size == 3 && memcmp(data, "456", 3) == 0);
f5982bb5b0a704e88fa2b44b0b74e365d13103b9Timo Sirainen /* child2 read beginning.. */
f5982bb5b0a704e88fa2b44b0b74e365d13103b9Timo Sirainen test_assert(size == 3 && memcmp(data, "123", 3) == 0);
f5982bb5b0a704e88fa2b44b0b74e365d13103b9Timo Sirainen /* child1 check middle again.. the parent has been modified,
f5982bb5b0a704e88fa2b44b0b74e365d13103b9Timo Sirainen so it can't return the original data (without some code changes). */
d47bd663deb1846980e6759c87297741a5459890Timo Sirainen test_assert(i_stream_get_data_size(child1) == 0);
f5982bb5b0a704e88fa2b44b0b74e365d13103b9Timo Sirainen /* child1 read end */
f5982bb5b0a704e88fa2b44b0b74e365d13103b9Timo Sirainen test_assert(size == 3 && memcmp(data, "789", 3) == 0);
f5982bb5b0a704e88fa2b44b0b74e365d13103b9Timo Sirainen /* child2 check beginning again.. */
d47bd663deb1846980e6759c87297741a5459890Timo Sirainen test_assert(i_stream_get_data_size(child1) == 0);
f5982bb5b0a704e88fa2b44b0b74e365d13103b9Timo Sirainen /* child2 read middle */
f5982bb5b0a704e88fa2b44b0b74e365d13103b9Timo Sirainen test_assert(size == 3 && memcmp(data, "456", 3) == 0);