add test for strftime
[libc-test.git] / src / functional / string_memmem.c
blob608eadf0764123160f3ef30f1309d814fe05a00e
1 #ifndef _GNU_SOURCE
2 #define _GNU_SOURCE 1
3 #endif
4 #include <string.h>
5 #include "test.h"
7 #define N(s, tail, sub) { \
8 char *p = s tail; \
9 char *q = memmem(p, strlen(s), sub, strlen(sub)); \
10 if (q) \
11 t_error("memmem("#s" "#tail", %d, "#sub", %d) returned str+%d, wanted 0\n",\
12 strlen(s), strlen(sub), q-p); \
15 #define T(s, sub, n) { \
16 char *p = s; \
17 char *q = memmem(p, strlen(p), sub, strlen(sub)); \
18 if (q == 0) \
19 t_error("memmem(%s,%s) returned 0, wanted str+%d\n", #s, #sub, n); \
20 else if (q - p != n) \
21 t_error("memmem(%s,%s) returned str+%d, wanted str+%d\n", #s, #sub, q-p, n); \
24 int main(void)
26 N("","a", "a")
27 N("a","a", "aa")
28 N("a","b", "b")
29 N("aa","b", "ab")
30 N("aa","a", "aaa")
31 N("aba","b", "bab")
32 N("abba","b", "bab")
33 N("abba","ba", "aba")
34 N("abc abc","d", "abcd")
35 N("0-1-2-3-4-5-6-7-8-9","", "-3-4-56-7-8-")
36 N("0-1-2-3-4-5-6-7-8-9","", "-3-4-5+6-7-8-")
37 N("_ _ _\xff_ _ _","\x7f_", "_\x7f_")
38 N("_ _ _\x7f_ _ _","\xff_", "_\xff_")
40 T("", "", 0)
41 T("abcd", "", 0)
42 T("abcd", "a", 0)
43 T("abcd", "b", 1)
44 T("abcd", "c", 2)
45 T("abcd", "d", 3)
46 T("abcd", "ab", 0)
47 T("abcd", "bc", 1)
48 T("abcd", "cd", 2)
49 T("ababa", "baba", 1)
50 T("ababab", "babab", 1)
51 T("abababa", "bababa", 1)
52 T("abababab", "bababab", 1)
53 T("ababababa", "babababa", 1)
54 T("abbababab", "bababa", 2)
55 T("abbababab", "ababab", 3)
56 T("abacabcabcab", "abcabcab", 4)
57 T("nanabanabanana", "aba", 3)
58 T("nanabanabanana", "ban", 4)
59 T("nanabanabanana", "anab", 1)
60 T("nanabanabanana", "banana", 8)
61 T("_ _\xff_ _", "_\xff_", 2)
63 return t_status;