]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
tests: Test message-parser better with nonblocking input.
authorTimo Sirainen <tss@iki.fi>
Thu, 12 Jun 2008 02:28:17 +0000 (05:28 +0300)
committerTimo Sirainen <tss@iki.fi>
Thu, 12 Jun 2008 02:28:17 +0000 (05:28 +0300)
--HG--
branch : HEAD

src/tests/test-common.c
src/tests/test-common.h
src/tests/test-mail.c

index 982da10bf71df3a62aab496fcd4518e1d03bd380..663db7e0a2ee747973261a05ecfbfe91fc72bcd7 100644 (file)
@@ -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);
index 3d8cb6d5457cc1cfe912f33ab79d78654c35aa8a..a97b8d466b7ec2dfc3e5097be9f37100d8c8a4bf 100644 (file)
@@ -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);
index c8030b6a536c38cf20ee927e07b4808c1e6f0d29..04b65102d761f4fed437005ba497f8e312f2c50d 100644 (file)
@@ -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;
                }