aboutsummaryrefslogtreecommitdiffstats
path: root/memmem.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2018-08-12 21:35:12 +0200
committerMattias Andrée <maandree@kth.se>2018-08-12 21:35:12 +0200
commit93b8428b5812191177c790ea9ffb9158d5a296b4 (patch)
tree8e43220208a7e3b4780a49b8278e731f3b5fcbbf /memmem.c
parentAdd DONT_DEFINE_CLOCK_MONOTONIC_RAW (diff)
downloadlibsimple-93b8428b5812191177c790ea9ffb9158d5a296b4.tar.gz
libsimple-93b8428b5812191177c790ea9ffb9158d5a296b4.tar.bz2
libsimple-93b8428b5812191177c790ea9ffb9158d5a296b4.tar.xz
Add tests
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'memmem.c')
-rw-r--r--memmem.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/memmem.c b/memmem.c
index c7e331a..0046e19 100644
--- a/memmem.c
+++ b/memmem.c
@@ -21,3 +21,34 @@ libsimple_memmem(const void *hay_, size_t hayn, const void *sub_, size_t subn)
return NULL;
}
+
+
+#ifdef TEST
+#include <assert.h>
+
+int
+main(void)
+{
+ assert(!strcmp(libsimple_memmem("test", 4, "test", 4), "test"));
+ assert(!strcmp(libsimple_memmem("", 0, "", 0), ""));
+ assert(!strcmp(libsimple_memmem("test", 4, "", 0), "test"));
+ assert(!libsimple_memmem("", 0, "test", 4));
+ assert(!libsimple_memmem("t", 1, "test", 4));
+ assert(!strcmp(libsimple_memmem("test", 4, "t", 1), "test"));
+ assert(!strcmp(libsimple_memmem("test", 4, "e", 1), "est"));
+ assert(!strcmp(libsimple_memmem("test", 4, "s", 1), "st"));
+ assert(!libsimple_memmem("test", 4, "x", 1));
+ assert(!strcmp(libsimple_memmem("test", 4, "te", 2), "test"));
+ assert(!strcmp(libsimple_memmem("test", 4, "es", 2), "est"));
+ assert(!strcmp(libsimple_memmem("test", 4, "st", 2), "st"));
+ assert(!strcmp(libsimple_memmem("test", 5, "t", 2), "t"));
+ assert(!libsimple_memmem("test", 4, "xx", 2));
+ assert(!strcmp(libsimple_memmem("abc", 3, "c", 1), "c"));
+ assert(!strcmp(libsimple_memmem("abc", 3, "bc", 2), "bc"));
+ assert(!strcmp(libsimple_memmem("abc", 3, "abc", 3), "abc"));
+ assert(!libsimple_memmem("abc", 3, "abc", 4));
+ assert(!strcmp(libsimple_memmem("abcabc", 6, "bc", 2), "bcabc"));
+ return 0;
+}
+
+#endif