|
nsz |
62a26a |
#ifndef _GNU_SOURCE
|
|
nsz |
62a26a |
#define _GNU_SOURCE 1
|
|
nsz |
62a26a |
#endif
|
|
nsz |
62a26a |
#include <string.h>
|
|
nsz |
62a26a |
#include "test.h"
|
|
nsz |
62a26a |
|
|
Szabolcs Nagy |
13492a |
#define N(s, tail, sub) { \
|
|
Szabolcs Nagy |
13492a |
char *p = s tail; \
|
|
Szabolcs Nagy |
13492a |
char *q = memmem(p, strlen(s), sub, strlen(sub)); \
|
|
nsz |
62a26a |
if (q) \
|
|
Szabolcs Nagy |
13492a |
t_error("memmem("#s" "#tail", %d, "#sub", %d) returned str+%d, wanted 0\n",\
|
|
Szabolcs Nagy |
13492a |
strlen(s), strlen(sub), q-p); \
|
|
nsz |
62a26a |
}
|
|
nsz |
62a26a |
|
|
nsz |
62a26a |
#define T(s, sub, n) { \
|
|
nsz |
62a26a |
char *p = s; \
|
|
nsz |
62a26a |
char *q = memmem(p, strlen(p), sub, strlen(sub)); \
|
|
nsz |
62a26a |
if (q == 0) \
|
|
Szabolcs Nagy |
cfa23c |
t_error("memmem(%s,%s) returned 0, wanted str+%d\n", #s, #sub, n); \
|
|
nsz |
62a26a |
else if (q - p != n) \
|
|
Szabolcs Nagy |
cfa23c |
t_error("memmem(%s,%s) returned str+%d, wanted str+%d\n", #s, #sub, q-p, n); \
|
|
nsz |
62a26a |
}
|
|
nsz |
62a26a |
|
|
nsz |
62a26a |
int main(void)
|
|
nsz |
62a26a |
{
|
|
Szabolcs Nagy |
13492a |
N("","a", "a")
|
|
Szabolcs Nagy |
13492a |
N("a","a", "aa")
|
|
Szabolcs Nagy |
13492a |
N("a","b", "b")
|
|
Szabolcs Nagy |
13492a |
N("aa","b", "ab")
|
|
Szabolcs Nagy |
13492a |
N("aa","a", "aaa")
|
|
Szabolcs Nagy |
13492a |
N("aba","b", "bab")
|
|
Szabolcs Nagy |
13492a |
N("abba","b", "bab")
|
|
Szabolcs Nagy |
13492a |
N("abba","ba", "aba")
|
|
Szabolcs Nagy |
13492a |
N("abc abc","d", "abcd")
|
|
Szabolcs Nagy |
13492a |
N("0-1-2-3-4-5-6-7-8-9","", "-3-4-56-7-8-")
|
|
Szabolcs Nagy |
13492a |
N("0-1-2-3-4-5-6-7-8-9","", "-3-4-5+6-7-8-")
|
|
Szabolcs Nagy |
13492a |
N("_ _ _\xff_ _ _","\x7f_", "_\x7f_")
|
|
Szabolcs Nagy |
13492a |
N("_ _ _\x7f_ _ _","\xff_", "_\xff_")
|
|
nsz |
62a26a |
|
|
nsz |
62a26a |
T("", "", 0)
|
|
nsz |
62a26a |
T("abcd", "", 0)
|
|
nsz |
62a26a |
T("abcd", "a", 0)
|
|
nsz |
62a26a |
T("abcd", "b", 1)
|
|
nsz |
62a26a |
T("abcd", "c", 2)
|
|
nsz |
62a26a |
T("abcd", "d", 3)
|
|
nsz |
62a26a |
T("abcd", "ab", 0)
|
|
nsz |
62a26a |
T("abcd", "bc", 1)
|
|
nsz |
62a26a |
T("abcd", "cd", 2)
|
|
nsz |
62a26a |
T("ababa", "baba", 1)
|
|
nsz |
62a26a |
T("ababab", "babab", 1)
|
|
nsz |
62a26a |
T("abababa", "bababa", 1)
|
|
nsz |
62a26a |
T("abababab", "bababab", 1)
|
|
nsz |
62a26a |
T("ababababa", "babababa", 1)
|
|
Szabolcs Nagy |
9679fb |
T("abbababab", "bababa", 2)
|
|
Szabolcs Nagy |
9679fb |
T("abbababab", "ababab", 3)
|
|
Szabolcs Nagy |
9679fb |
T("abacabcabcab", "abcabcab", 4)
|
|
nsz |
62a26a |
T("nanabanabanana", "aba", 3)
|
|
nsz |
62a26a |
T("nanabanabanana", "ban", 4)
|
|
nsz |
62a26a |
T("nanabanabanana", "anab", 1)
|
|
nsz |
62a26a |
T("nanabanabanana", "banana", 8)
|
|
nsz |
62a26a |
T("_ _\xff_ _", "_\xff_", 2)
|
|
nsz |
62a26a |
|
|
Szabolcs Nagy |
cfa23c |
return t_status;
|
|
nsz |
62a26a |
}
|