/* Copyright (c) 2016-2018 Dovecot authors, see the included COPYING file */
#include "test-lib.h"
#include "ioloop.h"
#include "str.h"
#include "crc32.h"
#include "randgen.h"
#include "istream-private.h"
#include "istream-multiplex.h"
#include "ostream.h"
#include <unistd.h>
static void test_istream_multiplex_simple(void)
{
test_begin("istream multiplex (simple)");
"\x01\x00\x00\x00\x03Wor"
"\x00\x00\x00\x00\x00"
"\x01\x00\x00\x00\x03ld\x00";
/* nothing to read until the first byte */
}
/* partial read of the first packet */
siz == 3);
/* read the rest of the first packet and the second packet.
read chan1 before chan0 to see that it works. */
siz == 6);
siz == 3);
/* 0-sized packet is ignored */
/* read the final packet */
/* we should have the final data in all channels now */
siz == 6);
siz == 6);
/* all channels should return EOF */
test_end();
}
static void test_istream_multiplex_maxbuf(void)
{
test_begin("istream multiplex (maxbuf)");
"\x01\x00\x00\x00\x06World\x00";
/* we get data for channel 0 and congest */
/* we read data for channel 0 */
/* and now it's congested */
siz == 5);
/* consume data */
/* we read data for channel 1 */
siz == 5);
/* consume data */
/* read last byte */
/* now we get byte for channel 1 */
/* now we read byte for channel 1 */
/* and everything should return EOF now */
test_end();
}
static void test_istream_multiplex_random(void)
{
test_begin("istream multiplex (random)");
unsigned int i;
for (i = 0; i < packets_count; i++) {
bytes_written += len;
}
for (i = 1; i < max_channel; i++)
/* read from each stream, 1 byte at a time */
for (i = 0;;) {
if (ret > 0) {
const unsigned char *data =
bytes_read += size;
}
if (++i < read_max_channel)
;
else if (max_ret == 0 && !something_read &&
} else {
if (max_ret <= -1) {
break;
}
if (max_ret == 0)
i = 0;
max_ret = -3;
}
}
for (i = 0; i < max_channel; i++) {
chan[i]->stream_errno == 0, i);
i_stream_unref(&chan[i]);
}
buffer_free(&buf);
test_end();
}
static const char *msgs[] = {
"",
"a",
"bb",
"ccc",
"dddd",
"eeeee",
"ffffff"
};
{
const char *line;
if (i_stream_read(channel) < 0)
return;
}
channel_counter[cid]++;
}
}
{
{ "\n", 1 } /* newline added for i_stream_next_line */
};
}
{
}
}
static void test_istream_multiplex_stream(void)
{
test_begin("istream multiplex (stream)");
i_stream_unref(&is);
o_stream_unref(&os);
i_close_fd(&fds[0]);
test_end();
}
static void test_istream_multiplex_close_channel(void)
{
test_begin("istream multiplex (close channel)");
"\x01\x00\x00\x00\x06World\x00";
siz == 6);
/* this is needed to populate chan1 data */
(void)i_stream_read(chan0);
siz == 6);
test_end();
}
void test_istream_multiplex(void)
{
}