dovecot-2.2: lib: test-unichar - streamline the unichars test

dovecot at dovecot.org dovecot at dovecot.org
Mon Jun 1 19:18:47 UTC 2015


details:   http://hg.dovecot.org/dovecot-2.2/rev/aa2f464daa66
changeset: 18783:aa2f464daa66
user:      Phil Carmody <phil at dovecot.fi>
date:      Mon Jun 01 22:06:44 2015 +0300
description:
lib: test-unichar - streamline the unichars test
It's doing 2 kinds of tests, split them into separate test cases.

And the first part has started to get expensive, so just make sure
all code paths are tested by skipping most values. Only 3 from each
set of 64 (lowest 6 bits) are tested.

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

diffstat:

 src/lib/test-unichar.c |  12 +++++++++++-
 1 files changed, 11 insertions(+), 1 deletions(-)

diffs (37 lines):

diff -r ff791143d1b4 -r aa2f464daa66 src/lib/test-unichar.c
--- a/src/lib/test-unichar.c	Mon Jun 01 21:59:02 2015 +0300
+++ b/src/lib/test-unichar.c	Mon Jun 01 22:06:44 2015 +0300
@@ -4,6 +4,7 @@
 #include "str.h"
 #include "buffer.h"
 #include "unichar.h"
+#include <stdlib.h>
 
 static void test_unichar_uni_utf8_strlen(void)
 {
@@ -45,15 +46,24 @@
 	unichar_t chr, chr2;
 	string_t *str = t_str_new(16);
 
-	test_begin("unichars");
+	test_begin("unichars encode/decode");
 	for (chr = 0; chr <= 0x10ffff; chr++) {
+		/* The bottom 6 bits should be irrelevant to code coverage,
+		   only test 000000, 111111, and something in between. */
+		if ((chr & 63) == 1)
+			chr += rand() % 62; /* After 0, somewhere between 1 and 62 */
+		else if ((chr & 63) > 0 && (chr & 63) < 63)
+			chr |= 63; /* After random, straight to 63 */
+
 		str_truncate(str, 0);
 		uni_ucs4_to_utf8_c(chr, str);
 		test_assert(uni_utf8_str_is_valid(str_c(str)));
 		test_assert(uni_utf8_get_char(str_c(str), &chr2) > 0);
 		test_assert(chr2 == chr);
 	}
+	test_end();
 
+	test_begin("unichar collation");
 	collate_out = buffer_create_dynamic(default_pool, 32);
 	uni_utf8_to_decomposed_titlecase(collate_in, sizeof(collate_in),
 					 collate_out);


More information about the dovecot-cvs mailing list