test-istream.c revision f5982bb5b0a704e88fa2b44b0b74e365d13103b9
70N/A/* Copyright (c) 2014 Dovecot authors, see the included COPYING file */
70N/A
1276N/A#include "test-lib.h"
70N/A#include "istream.h"
1665N/A
70N/Astatic void test_istream_children(void)
70N/A{
919N/A struct istream *parent, *child1, *child2;
919N/A const unsigned char *data;
919N/A size_t size;
919N/A
919N/A test_begin("istream children");
919N/A
919N/A parent = test_istream_create_data("123456789", 9);
919N/A test_istream_set_max_buffer_size(parent, 3);
919N/A
919N/A child1 = i_stream_create_limit(parent, (uoff_t)-1);
919N/A child2 = i_stream_create_limit(parent, (uoff_t)-1);
919N/A
919N/A /* child1 read beginning */
919N/A test_assert(i_stream_read(child1) == 3);
919N/A data = i_stream_get_data(child1, &size);
919N/A test_assert(size == 3 && memcmp(data, "123", 3) == 0);
919N/A i_stream_skip(child1, 3);
70N/A /* child1 read middle.. */
70N/A test_assert(i_stream_read(child1) == 3);
70N/A data = i_stream_get_data(child1, &size);
70N/A test_assert(size == 3 && memcmp(data, "456", 3) == 0);
493N/A /* child2 read beginning.. */
70N/A test_assert(i_stream_read(child2) == 3);
70N/A data = i_stream_get_data(child2, &size);
1549N/A test_assert(size == 3 && memcmp(data, "123", 3) == 0);
70N/A /* child1 check middle again.. the parent has been modified,
911N/A so it can't return the original data (without some code changes). */
1549N/A data = i_stream_get_data(child1, &size);
1549N/A test_assert(size == 0);
1549N/A i_stream_skip(child1, 3);
911N/A /* child1 read end */
70N/A test_assert(i_stream_read(child1) == 3);
1665N/A data = i_stream_get_data(child1, &size);
70N/A test_assert(size == 3 && memcmp(data, "789", 3) == 0);
70N/A i_stream_skip(child1, 3);
70N/A test_assert(i_stream_read(child1) == -1);
70N/A /* child2 check beginning again.. */
70N/A data = i_stream_get_data(child2, &size);
70N/A test_assert(size == 0);
493N/A i_stream_skip(child2, 3);
969N/A /* child2 read middle */
70N/A test_assert(i_stream_read(child2) == 3);
70N/A data = i_stream_get_data(child2, &size);
70N/A test_assert(size == 3 && memcmp(data, "456", 3) == 0);
70N/A i_stream_skip(child2, 3);
970N/A
970N/A i_stream_destroy(&child1);
970N/A i_stream_destroy(&child2);
1196N/A i_stream_destroy(&parent);
1196N/A
1425N/A test_end();
1196N/A}
70N/A
void test_istream(void)
{
test_istream_children();
}