dovecot-1.2: Added some base64 random testing.

dovecot at dovecot.org dovecot at dovecot.org
Sat Nov 1 21:12:05 EET 2008


details:   http://hg.dovecot.org/dovecot-1.2/rev/1a9cda20c462
changeset: 8379:1a9cda20c462
user:      Timo Sirainen <tss at iki.fi>
date:      Sat Nov 01 21:11:26 2008 +0200
description:
Added some base64 random testing.

diffstat:

1 file changed, 19 insertions(+), 2 deletions(-)
src/tests/test-lib.c |   21 +++++++++++++++++++--

diffs (40 lines):

diff -r fcce76948c8a -r 1a9cda20c462 src/tests/test-lib.c
--- a/src/tests/test-lib.c	Sat Nov 01 21:07:12 2008 +0200
+++ b/src/tests/test-lib.c	Sat Nov 01 21:11:26 2008 +0200
@@ -53,17 +53,34 @@ static void test_base64_encode(void)
 		"Zm9vIGJhcml0cw==",
 		"anVzdCBuaWlu"
 	};
-	string_t *str;
-	unsigned int i;
+	string_t *str, *dest;
+	unsigned int i, j, max;
+	char buf[10];
 	bool success;
 
 	str = t_str_new(256);
+	dest = t_str_new(256);
 	for (i = 0; i < N_ELEMENTS(input); i++) {
 		str_truncate(str, 0);
 		base64_encode(input[i], strlen(input[i]), str);
 		success = strcmp(output[i], str_c(str)) == 0;
 		test_out(t_strdup_printf("base64_encode(%d)", i), success);
 	}
+
+	for (i = 0; i < 1000; i++) {
+		max = rand() % sizeof(buf);
+		for (j = 0; j < max; j++)
+			buf[j] = rand();
+
+		str_truncate(str, 0);
+		str_truncate(dest, 0);
+		base64_encode(buf, max, str);
+		base64_decode(str_data(str), str_len(str), NULL, dest);
+		if (str_len(dest) != max &&
+		    memcmp(buf, str_data(dest), max) != 0)
+			break;
+	}
+	test_out("base64 random", success);
 }
 
 struct test_base64_decode_output {


More information about the dovecot-cvs mailing list