diff options
author | David Gibson <david@gibson.dropbear.id.au> | 2014-10-22 13:56:52 +0200 |
---|---|---|
committer | Rusty Russell <rusty@rustcorp.com.au> | 2014-10-27 16:13:15 +1030 |
commit | 2ab3ac5b30c1cc58c0846e05c5943c03e7111ad8 (patch) | |
tree | a436d611951fd51411cfa2b12986db0be284fbad | |
parent | 992931f06cf25d24fe74b4c617753aef2de70426 (diff) |
mem: Correct testcases
Currently the 'mem' module testcases use test/run.c even though they don't
rely on access to the module internals. They're also missing an include
of mem.c, which has the effect that on systems with a C library memmem()
implementaiton, only that is tested, not the (re-)implementation in the
mem module itself. This corrects that by moving run.c to api.c/
Additionally, the memmem() testcases don't cover the case where the
"needle" appears multiple times in the "haystack". This patch also adds
such a test.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
-rw-r--r-- | ccan/mem/test/api.c (renamed from ccan/mem/test/run.c) | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/ccan/mem/test/run.c b/ccan/mem/test/api.c index 3efd1d81..a7cfb9a1 100644 --- a/ccan/mem/test/run.c +++ b/ccan/mem/test/api.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(); } |