1 #define COMMON_TEST_C
2 #include <stddef.h>
3 #include "tests_common.h"
4 #include "../../src/common.c"
5
6 static void
common_memmem_tests(void)7 common_memmem_tests (void)
8 {
9 static char *hay = (char*)"0123456789";
10 char *needle = (char*)"01";
11 void *p;
12
13 // positive
14 if (my_memmem (hay, 10, needle, 2) != hay)
15 fail ("memmem %s not at 0", needle);
16 needle = (char*)"1234567890";
17 if (my_memmem (hay, 10, needle, 9) != &hay[1])
18 fail ("memmem %s not at 0", needle);
19 needle = (char*)"789";
20 if ((p = my_memmem (hay, 10, needle, 3)) != &hay[7])
21 fail ("memmem %s not at 7 but at %p of %p", needle, p, hay);
22
23 // not found
24 needle = (char*)"012344567890";
25 if (my_memmem (hay, 10, needle, 11))
26 fail ("memmem %s found", needle);
27 needle = (char*)"1234456780";
28 if (my_memmem (hay, 10, needle, 9))
29 fail ("memmem %s found", needle);
30 needle = (char*)"7890";
31 if (my_memmem (hay, 10, needle, 4))
32 fail ("memmem %s found", needle);
33 else
34 ok("memmem");
35 }
36
37 int
main(int argc,char const * argv[])38 main (int argc, char const *argv[])
39 {
40 loglevel = is_make_silent() ? 0 : 2;
41 common_memmem_tests ();
42 return failed;
43 }
44