1 /* $NetBSD: t_strchr.c,v 1.1 2011/07/07 08:59:33 jruoho Exp $ */
4 * Written by J.T. Conklin <jtc@acorntoolworks.com>
15 static char *slow_strchr(char *, int);
16 static void verify_strchr(char *, int, unsigned int, unsigned int);
18 char * (*volatile strchr_fn)(const char *, int);
21 slow_strchr(char *buf, int ch)
27 for (; c != 0; buf++) {
36 verify_strchr(char *buf, int ch, unsigned int t, unsigned int a)
38 const char *off, *ok_off;
40 off = strchr_fn(buf, ch);
41 ok_off = slow_strchr(buf, ch);
45 fprintf(stderr, "test_strchr(\"%s\", %#x) gave %zd not %zd (test %d, "
47 buf, ch, off ? off - buf : -1, ok_off ? ok_off - buf : -1, t, a);
49 atf_tc_fail("Check stderr for details");
53 ATF_TC_HEAD(strchr_basic, tc)
56 atf_tc_set_md_var(tc, "descr", "Test strchr(3) results");
59 ATF_TC_BODY(strchr_basic, tc)
245 "abcdefgh/abcdefgh/",
249 strchr_fn = dlsym(dlopen(0, RTLD_LAZY), "test_strchr");
253 for (a = 3; a < 3 + sizeof(long); ++a) {
254 /* Put char and a \0 before the buffer */
258 for (t = 0; t < (sizeof(tab) / sizeof(tab[0])); ++t) {
259 int len = strlen(tab[t]) + 1;
260 memcpy(&buf[a], tab[t], len);
262 /* Put the char we are looking for after the \0 */
265 /* Check search for NUL at end of string */
266 verify_strchr(buf + a, 0, t, a);
268 /* Then for the '/' in the strings */
269 verify_strchr(buf + a, '/', t, a);
271 /* check zero extension of char arg */
272 verify_strchr(buf + a, 0xffffff00 | '/', t, a);
274 /* Replace all the '/' with 0xff */
275 while ((off = slow_strchr(buf + a, '/')) != NULL)
280 /* Check we can search for 0xff as well as '/' */
281 verify_strchr(buf + a, 0xff, t, a);
289 ATF_TP_ADD_TC(tp, strchr_basic);
291 return atf_no_error();