]> git.ozlabs.org Git - ccan/blobdiff - ccan/memmem/test/run.c
memmem: Trivial module to provide memmem() function
[ccan] / ccan / memmem / test / run.c
diff --git a/ccan/memmem/test/run.c b/ccan/memmem/test/run.c
new file mode 100644 (file)
index 0000000..af9aac5
--- /dev/null
@@ -0,0 +1,20 @@
+#include <ccan/array_size/array_size.h>
+#include <ccan/memmem/memmem.h>
+#include <ccan/tap/tap.h>
+
+int main(void)
+{
+       char haystack1[] = "abcd\0efgh";
+       char needle1[] = "ab";
+       char needle2[] = "d\0e";
+
+       /* This is how many tests you plan to run */
+       plan_tests(3);
+
+       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));
+
+       /* This exits depending on whether all tests passed */
+       return exit_status();
+}