dovecot-2.2: lib: test-strnum - tests for the new partial-string...

dovecot at dovecot.org dovecot at dovecot.org
Wed Jul 2 15:23:20 UTC 2014


details:   http://hg.dovecot.org/dovecot-2.2/rev/85a44b4b121a
changeset: 17555:85a44b4b121a
user:      Phil Carmody <phil at dovecot.fi>
date:      Wed Jul 02 18:21:24 2014 +0300
description:
lib: test-strnum - tests for the new partial-string parser
We can simplify the main tests by always testing whether an appended
non-digit causes parsing to fail at the same time that we test it doesn't
fail with the new more permissive helpers.

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

diffstat:

 src/lib/test-strnum.c |  18 +++++++++++++++++-
 1 files changed, 17 insertions(+), 1 deletions(-)

diffs (42 lines):

diff -r 27006dc092d2 -r 85a44b4b121a src/lib/test-strnum.c
--- a/src/lib/test-strnum.c	Wed Jul 02 18:21:24 2014 +0300
+++ b/src/lib/test-strnum.c	Wed Jul 02 18:21:24 2014 +0300
@@ -19,7 +19,6 @@
 		INVALID(-1),
 		INVALID(foo),
 		VALID(0),
-		{ "0 ", -1, 0 }, /* invalid as doesn't end with a '\0' */
 		VALID(000000000000000000000000000000000000000000000000000000000000000),
 		{ "000000000000000000000000000000000000000000000000000001000000001", 0, 1000000001 },
 		{ "18446744073709551615", 0, 18446744073709551615ULL },
@@ -37,6 +36,19 @@
 			test_assert_idx(val == u64tests[i].val, i);
 		else
 			test_assert_idx(val == 0xBADBEEF15BADF00D, i);
+
+		/* This stanza totally assumes that uintmax_t == uint64_t */
+		if (ret == 0)
+			T_BEGIN {
+				const char *longer = t_strconcat(u64tests[i].input, "x", NULL);
+				const char *endp;
+				ret = str_to_uintmax(longer, &val);
+				test_assert_idx(ret < 0, i);
+				ret = str_parse_uintmax(longer, &val, &endp);
+				test_assert_idx(ret == 0, i);
+				test_assert_idx(val == u64tests[i].val, i);
+				test_assert_idx(*endp == 'x', i);
+			} T_END;
 	}
 	test_end();
 }
@@ -134,6 +146,10 @@
 
 void test_strnum(void)
 {
+	test_begin("test_strnum - size check");
+	test_assert(sizeof(uintmax_t) == sizeof(uint64_t));
+	test_end();
+	/* If the above isn't true, then we do expect some failures possibly */
 	test_str_to_u64();
 	test_str_to_u32();
 	test_str_to_llong();


More information about the dovecot-cvs mailing list