[ccan] [PATCH 2/3] memfuncs: Test case of repeated substrings

David Gibson david at gibson.dropbear.id.au
Sun Oct 19 23:07:45 AEDT 2014


Currently the testcases for memmem() don't cover the case where the
"needle" appears multiple times in the "haystack".  This patch adds such
a test.

Signed-off-by: David Gibson <david at gibson.dropbear.id.au>
---
 ccan/memfuncs/test/run.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/ccan/memfuncs/test/run.c b/ccan/memfuncs/test/run.c
index 45b03eb..0e2e903 100644
--- a/ccan/memfuncs/test/run.c
+++ b/ccan/memfuncs/test/run.c
@@ -5,16 +5,21 @@
 int main(void)
 {
 	char haystack1[] = "abcd\0efgh";
+	char haystack2[] = "ab\0ab\0ab\0ab";
 	char needle1[] = "ab";
 	char needle2[] = "d\0e";
 
 	/* This is how many tests you plan to run */
-	plan_tests(3);
+	plan_tests(5);
 
 	ok1(memmem(haystack1, sizeof(haystack1), needle1, 2) == haystack1);
 	ok1(memmem(haystack1, sizeof(haystack1), needle1, 3) == NULL);
 	ok1(memmem(haystack1, sizeof(haystack1), needle2, 3) == (haystack1 + 3));
 
+	ok1(memmem(haystack2, sizeof(haystack2), needle1, sizeof(needle1))
+	    == haystack2);
+	ok1(memmem(haystack2, sizeof(haystack2), needle2, 3) == NULL);
+
 	/* This exits depending on whether all tests passed */
 	return exit_status();
 }
-- 
1.9.3



More information about the ccan mailing list