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