From: Timo Sirainen Date: Thu, 12 Jun 2008 02:28:17 +0000 (+0300) Subject: tests: Test message-parser better with nonblocking input. X-Git-Tag: 1.2.alpha1~327 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=e6cc3420643d034b4e5cbb999cf3c6989045bd53;p=thirdparty%2Fdovecot%2Fcore.git tests: Test message-parser better with nonblocking input. --HG-- branch : HEAD --- diff --git a/src/tests/test-common.c b/src/tests/test-common.c index 982da10bf7..663db7e0a2 100644 --- a/src/tests/test-common.c +++ b/src/tests/test-common.c @@ -20,6 +20,11 @@ static ssize_t test_read(struct istream_private *stream) return -1; } +static ssize_t test_noread(struct istream_private *stream ATTR_UNUSED) +{ + return 0; +} + struct istream *test_istream_create(const char *data) { struct istream *input; @@ -37,6 +42,11 @@ void test_istream_set_size(struct istream *input, uoff_t size) input->real_stream->pos = size; } +void test_istream_set_allow_eof(struct istream *input, bool allow) +{ + input->real_stream->read = allow ? test_read : test_noread; +} + void test_out(const char *name, bool success) { test_out_reason(name, success, NULL); diff --git a/src/tests/test-common.h b/src/tests/test-common.h index 3d8cb6d545..a97b8d466b 100644 --- a/src/tests/test-common.h +++ b/src/tests/test-common.h @@ -3,6 +3,7 @@ struct istream *test_istream_create(const char *data); void test_istream_set_size(struct istream *input, uoff_t size); +void test_istream_set_allow_eof(struct istream *input, bool allow); void test_out(const char *name, bool success); void test_out_reason(const char *name, bool success, const char *reason); diff --git a/src/tests/test-mail.c b/src/tests/test-mail.c index c8030b6a53..04b65102d7 100644 --- a/src/tests/test-mail.c +++ b/src/tests/test-mail.c @@ -224,13 +224,16 @@ static void test_message_parser(void) i_stream_unref(&input); input = test_istream_create(test_msg); + test_istream_set_allow_eof(input, FALSE); parser = message_parser_init(pool, input, 0, 0); - for (i = 1; i <= TEST_MSG_LEN; i++) { - test_istream_set_size(input, i); + for (i = 1; i <= TEST_MSG_LEN*2+1; i++) { + test_istream_set_size(input, i/2); + if (i > TEST_MSG_LEN*2) + test_istream_set_allow_eof(input, TRUE); while ((ret = message_parser_parse_next_block(parser, &block)) > 0) ; - if (ret < 0 && i < TEST_MSG_LEN) { + if (ret < 0 && i < TEST_MSG_LEN*2) { success = FALSE; break; }