dovecot-2.2: lib: test-istream-tee - verify _read returns correc...

dovecot at dovecot.org dovecot at dovecot.org
Thu Jul 10 13:02:05 UTC 2014


details:   http://hg.dovecot.org/dovecot-2.2/rev/f87c9ca897a5
changeset: 17617:f87c9ca897a5
user:      Phil Carmody <phil at dovecot.fi>
date:      Thu Jul 10 15:59:53 2014 +0300
description:
lib: test-istream-tee - verify _read returns correct values after _set_size()
Previously, only an increase of 1 in the size was tested. This ensures that
0 and numbers > 1 are also tested.

Also add _idx to the asserts, so we know where in the loop it failed.

Signed-off-by: Phil Carmody <phil at dovecot.fi>

diffstat:

 src/lib/test-istream-tee.c |  18 +++++++++++-------
 1 files changed, 11 insertions(+), 7 deletions(-)

diffs (42 lines):

diff -r 4583a0c2e368 -r f87c9ca897a5 src/lib/test-istream-tee.c
--- a/src/lib/test-istream-tee.c	Thu Jul 10 15:59:53 2014 +0300
+++ b/src/lib/test-istream-tee.c	Thu Jul 10 15:59:53 2014 +0300
@@ -15,7 +15,7 @@
 {
 	struct istream *test_input, *child_input[CHILD_COUNT];
 	struct tee_istream *tee;
-	unsigned int i, len;
+	unsigned int i, len, delta;
 
 	test_input = test_istream_create(str);
 	test_istream_set_max_buffer_size(test_input, TEST_BUF_SIZE);
@@ -26,19 +26,23 @@
 		child_input[i] = tee_i_stream_create_child(tee);
 
 	test_istream_set_allow_eof(test_input, FALSE);
-	for (len = 1; len < TEST_BUF_SIZE; len++) {
+	delta = 1;
+	for (len = 1; len < TEST_BUF_SIZE; len += delta) {
 		test_istream_set_size(test_input, len);
 		for (i = 0; i < CHILD_COUNT; i++) {
-			test_assert(i_stream_read(child_input[i]) == 1);
-			test_assert(!tee_i_stream_child_is_waiting(child_input[i]));
-			test_assert(i_stream_read(child_input[i]) == 0);
-			test_assert(!tee_i_stream_child_is_waiting(child_input[i]));
+			test_assert_idx(i_stream_read(child_input[i]) == delta, len);
+			test_assert_idx(!tee_i_stream_child_is_waiting(child_input[i]), len);
+			test_assert_idx(i_stream_read(child_input[i]) == 0, len);
+			test_assert_idx(!tee_i_stream_child_is_waiting(child_input[i]), len);
 		}
+		delta = rand() % 32; /* may stand still */
+		if(delta > TEST_BUF_SIZE - len)
+			delta = 1;
 	}
 
 	test_istream_set_size(test_input, len);
 	for (i = 0; i < CHILD_COUNT; i++) {
-		test_assert(i_stream_read(child_input[i]) == 1);
+		test_assert(i_stream_read(child_input[i]) == delta);
 		test_assert(i_stream_read(child_input[i]) == -2);
 		test_assert(!tee_i_stream_child_is_waiting(child_input[i]));
 	}


More information about the dovecot-cvs mailing list