rename
[libc-test] / src / functional / string_strcspn.c
diff --git a/src/functional/string_strcspn.c b/src/functional/string_strcspn.c
new file mode 100644 (file)
index 0000000..87fcd10
--- /dev/null
@@ -0,0 +1,34 @@
+#include <stddef.h>
+#include <string.h>
+#include "test.h"
+
+#define T(s, c, n) { \
+       char *p = s; \
+       char *q = c; \
+       size_t r = strcspn(p, q); \
+       if (r != n) \
+               error("strcspn(%s,%s) returned %lu, wanted %lu\n", #s, #c, (unsigned long)r, (unsigned long)(n)); \
+}
+
+int main(void)
+{
+       int i;
+       char a[128];
+       char s[256];
+
+       for (i = 0; i < 128; i++)
+               a[i] = (i+1) & 127;
+       for (i = 0; i < 256; i++)
+               *((unsigned char*)s+i) = i+1;
+
+       T("", "", 0)
+       T("a", "", 1)
+       T("", "a", 0)
+       T("abc", "cde", 2)
+       T("abc", "ccc", 2)
+       T("abc", a, 0)
+       T("\xff\x80 abc", a, 2)
+       T(s, "\xff", 254)
+
+       return test_status;
+}