dovecot-2.2: lib-mail: Added more tests to test-istream-dot.
dovecot at dovecot.org
dovecot at dovecot.org
Tue Apr 29 10:58:15 UTC 2014
details: http://hg.dovecot.org/dovecot-2.2/rev/59ada187a702
changeset: 17290:59ada187a702
user: Timo Sirainen <tss at iki.fi>
date: Tue Apr 29 13:57:44 2014 +0300
description:
lib-mail: Added more tests to test-istream-dot.
diffstat:
src/lib-mail/test-istream-dot.c | 93 +++++++++++++++++++++++++++++++++++++++-
1 files changed, 90 insertions(+), 3 deletions(-)
diffs (134 lines):
diff -r db216ddbb5c2 -r 59ada187a702 src/lib-mail/test-istream-dot.c
--- a/src/lib-mail/test-istream-dot.c Tue Apr 29 13:35:06 2014 +0300
+++ b/src/lib-mail/test-istream-dot.c Tue Apr 29 13:57:44 2014 +0300
@@ -32,7 +32,8 @@
(test->input[input_len-1] == '\n' ||
strstr(test->input, "\n.\n") != NULL ||
strstr(test->input, "\n.\r\n") != NULL)) {
- if (test->output[output_len-1] == '\n') {
+ if (output_len > 0 &&
+ test->output[output_len-1] == '\n') {
output_len--;
if (output_len > 0 &&
test->output[output_len-1] == '\r')
@@ -90,6 +91,7 @@
data = i_stream_get_data(input, &size);
str_append_n(str, data, size);
}
+ test_assert(input->stream_errno == 0);
test_assert(str_len(str) == output_len);
test_assert(memcmp(str_data(str), test->output, output_len) == 0);
@@ -101,6 +103,61 @@
i_stream_unref(&input);
}
+static void test_istream_dot_error(const char *input_str, bool test_bufsize)
+{
+ struct istream *test_input, *input;
+ unsigned int i, outsize, input_len;
+ uoff_t offset;
+ int ret;
+
+ test_input = test_istream_create(input_str);
+ input = i_stream_create_dot(test_input, FALSE);
+
+ input_len = strlen(input_str);
+
+ if (!test_bufsize) {
+ outsize = 1; i = 0;
+ i_stream_set_max_buffer_size(input, outsize);
+ test_istream_set_size(test_input, 1);
+ while ((ret = i_stream_read(input)) != -1) {
+ switch (ret) {
+ case -2:
+ i_stream_set_max_buffer_size(input, ++outsize);
+ offset = test_input->v_offset;
+ /* seek one byte backwards so stream gets
+ reset */
+ i_stream_seek(test_input, offset - 1);
+ /* go back to original position */
+ test_istream_set_size(test_input, offset);
+ i_stream_skip(test_input, 1);
+ /* and finally allow reading one more byte */
+ test_istream_set_size(test_input, offset + 1);
+ break;
+ case 0:
+ test_istream_set_size(test_input, ++i);
+ break;
+ default:
+ test_assert(ret > 0);
+ }
+ }
+ test_istream_set_size(test_input, input_len);
+ (void)i_stream_read(test_input);
+ } else {
+ test_istream_set_size(test_input, input_len);
+ for (i = 1; i <= input_len; i++) {
+ i_stream_set_max_buffer_size(input, i);
+ (void)i_stream_read(input);
+ (void)i_stream_read(input);
+ }
+ i_stream_set_max_buffer_size(input, i+1);
+ (void)i_stream_read(input);
+ }
+ test_assert(input->stream_errno == EPIPE);
+
+ i_stream_unref(&test_input);
+ i_stream_unref(&input);
+}
+
static void test_istream_dot(void)
{
static struct dot_test tests[] = {
@@ -108,11 +165,37 @@
{ "..foo\r\n..\r\n.foo\r\n.\r\nfoo", ".foo\r\n.\r\nfoo\r\n", "foo" },
{ "\r.\r\n.\r\n", "\r.\r\n", "" },
{ "\n\r.\r\r\n.\r\n", "\n\r.\r\r\n", "" },
+ { "\r\n.\rfoo\n.\n", "\r\n\rfoo\n", "" },
{ "\r\n.\r\n", "\r\n", "" },
{ "\n.\r\n", "\n", "" },
{ "\n.\n", "\n", "" },
- { "\n.", "\n", "" },
- { ".", "", "" }
+ { ".\r\n", "", "" },
+ { ".\n", "", "" }
+ };
+ static const char *error_tests[] = {
+ "",
+ ".",
+ "..",
+ ".\r",
+ ".\rx",
+ "..\r\n",
+ "\r.",
+ "\r.\r",
+ "\r.\rx",
+ "\r.\r\n",
+ "\r.\n",
+ "\r..\n",
+ "\r\n",
+ "\r\n.",
+ "\r\n.\r",
+ "\r\n.\rx",
+ "\r\n.\rx\n",
+ "\r\n..\r\n",
+ "\n",
+ "\n.",
+ "\n.\r",
+ "\n.\rx",
+ "\n..\r\n"
};
unsigned int i;
@@ -123,6 +206,10 @@
test_istream_dot_one(&tests[i], FALSE, TRUE);
test_istream_dot_one(&tests[i], FALSE, FALSE);
}
+ for (i = 0; i < N_ELEMENTS(error_tests); i++) {
+ test_istream_dot_error(error_tests[i], FALSE);
+ test_istream_dot_error(error_tests[i], TRUE);
+ }
test_end();
}
More information about the dovecot-cvs
mailing list