1 /* $NetBSD: t_strcat.c,v 1.2 2011/07/14 05:46:04 jruoho Exp $ */
4 * Written by J.T. Conklin <jtc@acorntoolworks.com>
15 ATF_TC_HEAD(strcat_basic, tc)
17 atf_tc_set_md_var(tc, "descr", "Test strcat(3) results");
20 ATF_TC_BODY(strcat_basic, tc)
22 /* try to trick the compiler */
23 char * (*f)(char *, const char *s) = strcat;
25 unsigned int a0, a1, t0, t1;
35 const struct tab tab[] = {
37 * patterns that check for all combinations of leading and
38 * trailing unaligned characters (on a 64 bit processor)
52 { "abcdefghijk", 11 },
53 { "abcdefghijkl", 12 },
54 { "abcdefghijklm", 13 },
55 { "abcdefghijklmn", 14 },
56 { "abcdefghijklmno", 15 },
57 { "abcdefghijklmnop", 16 },
58 { "abcdefghijklmnopq", 17 },
59 { "abcdefghijklmnopqr", 18 },
60 { "abcdefghijklmnopqrs", 19 },
61 { "abcdefghijklmnopqrst", 20 },
62 { "abcdefghijklmnopqrstu", 21 },
63 { "abcdefghijklmnopqrstuv", 22 },
64 { "abcdefghijklmnopqrstuvw", 23 },
67 * patterns that check for the cases where the expression:
69 * ((word - 0x7f7f..7f) & 0x8080..80)
71 * returns non-zero even though there are no zero bytes in
75 { "" "\xff\xff\xff\xff\xff\xff\xff\xff" "abcdefgh", 16 },
76 { "a" "\xff\xff\xff\xff\xff\xff\xff\xff" "bcdefgh", 16 },
77 { "ab" "\xff\xff\xff\xff\xff\xff\xff\xff" "cdefgh", 16 },
78 { "abc" "\xff\xff\xff\xff\xff\xff\xff\xff" "defgh", 16 },
79 { "abcd" "\xff\xff\xff\xff\xff\xff\xff\xff" "efgh", 16 },
80 { "abcde" "\xff\xff\xff\xff\xff\xff\xff\xff" "fgh", 16 },
81 { "abcdef" "\xff\xff\xff\xff\xff\xff\xff\xff" "gh", 16 },
82 { "abcdefg" "\xff\xff\xff\xff\xff\xff\xff\xff" "h", 16 },
83 { "abcdefgh" "\xff\xff\xff\xff\xff\xff\xff\xff" "", 16 },
86 for (a0 = 0; a0 < sizeof(long); ++a0) {
87 for (a1 = 0; a1 < sizeof(long); ++a1) {
88 for (t0 = 0; t0 < __arraycount(tab); ++t0) {
89 for (t1 = 0; t1 < __arraycount(tab); ++t1) {
91 memcpy(&buf0[a0], tab[t0].val,
93 memcpy(&buf1[a1], tab[t1].val,
96 ret = f(&buf0[a0], &buf1[a1]);
99 * verify strcat returns address
102 if (&buf0[a0] != ret) {
103 fprintf(stderr, "a0 %d, a1 %d, "
106 atf_tc_fail("strcat did not "
107 "return its first arg");
110 /* verify string copied correctly */
111 if (memcmp(&buf0[a0] + tab[t0].len,
113 tab[t1].len + 1) != 0) {
114 fprintf(stderr, "a0 %d, a1 %d, "
117 atf_tc_fail("string not copied "
126 ATF_TC(strncat_simple);
127 ATF_TC_HEAD(strncat_simple, tc)
129 atf_tc_set_md_var(tc, "descr", "Test strncat(3) results");
132 ATF_TC_BODY(strncat_simple, tc)
134 char buf[100] = "abcdefg";
136 ATF_CHECK(strncat(buf, "xxx", 0) == buf);
137 ATF_CHECK(strcmp(buf, "abcdefg") == 0);
138 ATF_CHECK(strncat(buf, "xxx", 1) == buf);
139 ATF_CHECK(strcmp(buf, "abcdefgx") == 0);
140 ATF_CHECK(strncat(buf, "xxx", 2) == buf);
141 ATF_CHECK(strcmp(buf, "abcdefgxxx") == 0);
142 ATF_CHECK(strncat(buf, "\0", 1) == buf);
143 ATF_CHECK(strcmp(buf, "abcdefgxxx") == 0);
149 ATF_TP_ADD_TC(tp, strcat_basic);
150 ATF_TP_ADD_TC(tp, strncat_simple);
152 return atf_no_error();