Blame src/functional/string_strchr.c
|
nsz |
49b23c |
#include <string.h>
|
|
nsz |
49b23c |
#include "test.h"
|
|
nsz |
49b23c |
|
|
nsz |
49b23c |
#define N(s, c) { \
|
|
nsz |
49b23c |
char *p = s; \
|
|
nsz |
49b23c |
char *q = strchr(p, c); \
|
|
nsz |
49b23c |
if (q) \
|
|
nsz |
49b23c |
error("strchr(%s,%s) returned str+%d, wanted 0\n", #s, #c, q-p); \
|
|
nsz |
49b23c |
}
|
|
nsz |
49b23c |
|
|
nsz |
49b23c |
#define T(s, c, n) { \
|
|
nsz |
49b23c |
char *p = s; \
|
|
nsz |
49b23c |
char *q = strchr(p, c); \
|
|
nsz |
49b23c |
if (q == 0) \
|
|
nsz |
49b23c |
error("strchr(%s,%s) returned 0, wanted str+%d\n", #s, #c, n); \
|
|
nsz |
49b23c |
else if (q - p != n) \
|
|
nsz |
49b23c |
error("strchr(%s,%s) returned str+%d, wanted str+%d\n", #s, #c, q-p, n); \
|
|
nsz |
49b23c |
}
|
|
nsz |
49b23c |
|
|
nsz |
49b23c |
int main(void)
|
|
nsz |
49b23c |
{
|
|
nsz |
49b23c |
int i;
|
|
nsz |
49b23c |
char a[128];
|
|
nsz |
49b23c |
char s[256];
|
|
nsz |
49b23c |
|
|
nsz |
49b23c |
for (i = 0; i < 128; i++)
|
|
nsz |
49b23c |
a[i] = (i+1) & 127;
|
|
nsz |
49b23c |
for (i = 0; i < 256; i++)
|
|
nsz |
49b23c |
*((unsigned char*)s+i) = i+1;
|
|
nsz |
49b23c |
|
|
nsz |
49b23c |
N("", 'a')
|
|
nsz |
49b23c |
N("a", 'b')
|
|
nsz |
49b23c |
N("abc abc", 'x')
|
|
nsz |
49b23c |
N(a, 128)
|
|
nsz |
49b23c |
N(a, 255)
|
|
nsz |
49b23c |
|
|
nsz |
49b23c |
T("", 0, 0)
|
|
nsz |
49b23c |
T("a", 'a', 0)
|
|
nsz |
49b23c |
T("a", 'a'+256, 0)
|
|
nsz |
49b23c |
T("a", 0, 1)
|
|
nsz |
90956e |
T("ab", 'b', 1)
|
|
nsz |
90956e |
T("aab", 'b', 2)
|
|
nsz |
90956e |
T("aaab", 'b', 3)
|
|
nsz |
90956e |
T("aaaab", 'b', 4)
|
|
nsz |
90956e |
T("aaaaab", 'b', 5)
|
|
nsz |
90956e |
T("aaaaaab", 'b', 6)
|
|
nsz |
49b23c |
T("abc abc", 'c', 2)
|
|
nsz |
49b23c |
T(s, 1, 0)
|
|
nsz |
49b23c |
T(s, 2, 1)
|
|
nsz |
49b23c |
T(s, 10, 9)
|
|
nsz |
49b23c |
T(s, 11, 10)
|
|
nsz |
49b23c |
T(s, 127, 126)
|
|
nsz |
49b23c |
T(s, 128, 127)
|
|
nsz |
49b23c |
T(s, 255, 254)
|
|
nsz |
49b23c |
T(s, 0, 255)
|
|
nsz |
49b23c |
|
|
nsz |
49b23c |
return test_status;
|
|
nsz |
49b23c |
}
|