dovecot-2.0: lib-test: Added test_istream_set_max_buffer_size().

dovecot at dovecot.org dovecot at dovecot.org
Sat Aug 15 00:36:34 EEST 2009


details:   http://hg.dovecot.org/dovecot-2.0/rev/0287c38ba6bf
changeset: 9792:0287c38ba6bf
user:      Timo Sirainen <tss at iki.fi>
date:      Fri Aug 14 17:36:27 2009 -0400
description:
lib-test: Added test_istream_set_max_buffer_size().

diffstat:

2 files changed, 14 insertions(+), 1 deletion(-)
src/lib-test/test-common.c |   14 +++++++++++++-
src/lib-test/test-common.h |    1 +

diffs (56 lines):

diff -r 26a351f8ed07 -r 0287c38ba6bf src/lib-test/test-common.c
--- a/src/lib-test/test-common.c	Fri Aug 14 14:18:15 2009 -0400
+++ b/src/lib-test/test-common.c	Fri Aug 14 17:36:27 2009 -0400
@@ -17,7 +17,7 @@ struct test_istream {
 struct test_istream {
 	struct istream_private istream;
 	unsigned int skip_diff;
-	size_t max_pos;
+	size_t max_pos, max_buffer_size;
 	bool allow_eof;
 };
 
@@ -28,6 +28,9 @@ static ssize_t test_read(struct istream_
 	ssize_t ret;
 
 	i_assert(stream->skip <= stream->pos);
+
+	if (stream->pos - stream->skip >= tstream->max_buffer_size)
+		return -2;
 
 	if (tstream->max_pos < stream->pos) {
 		/* we seeked past the end of file. */
@@ -85,6 +88,7 @@ struct istream *test_istream_create(cons
 	(void)i_stream_create(&tstream->istream, NULL, -1);
 	tstream->istream.statbuf.st_size = tstream->max_pos = strlen(data);
 	tstream->allow_eof = TRUE;
+	tstream->max_buffer_size = (size_t)-1;
 	return &tstream->istream.istream;
 }
 
@@ -94,6 +98,14 @@ void test_istream_set_allow_eof(struct i
 		(struct test_istream *)input->real_stream;
 
 	tstream->allow_eof = allow;
+}
+
+void test_istream_set_max_buffer_size(struct istream *input, size_t size)
+{
+	struct test_istream *tstream =
+		(struct test_istream *)input->real_stream;
+
+	tstream->max_buffer_size = size;
 }
 
 void test_istream_set_size(struct istream *input, uoff_t size)
diff -r 26a351f8ed07 -r 0287c38ba6bf src/lib-test/test-common.h
--- a/src/lib-test/test-common.h	Fri Aug 14 14:18:15 2009 -0400
+++ b/src/lib-test/test-common.h	Fri Aug 14 17:36:27 2009 -0400
@@ -4,6 +4,7 @@ struct istream *test_istream_create(cons
 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_istream_set_max_buffer_size(struct istream *input, size_t size);
 
 void test_begin(const char *name);
 #define test_assert(code) STMT_START { \


More information about the dovecot-cvs mailing list