Blame src/functional/string_strcspn.c

nsz 49b23c
#include <stddef.h>
nsz 49b23c
#include <string.h>
nsz 49b23c
#include "test.h"
nsz 49b23c
nsz 49b23c
#define T(s, c, n) { \
nsz 49b23c
	char *p = s; \
nsz 49b23c
	char *q = c; \
nsz 49b23c
	size_t r = strcspn(p, q); \
nsz 49b23c
	if (r != n) \
nsz 49b23c
		error("strcspn(%s,%s) returned %lu, wanted %lu\n", #s, #c, (unsigned long)r, (unsigned long)(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
	T("", "", 0)
nsz 49b23c
	T("a", "", 1)
nsz 49b23c
	T("", "a", 0)
nsz 49b23c
	T("abc", "cde", 2)
nsz 90956e
	T("abc", "ccc", 2)
nsz 49b23c
	T("abc", a, 0)
nsz 49b23c
	T("\xff\x80 abc", a, 2)
nsz 49b23c
	T(s, "\xff", 254)
nsz 49b23c
nsz 49b23c
	return test_status;
nsz 49b23c
}