1 /* $NetBSD: t_strcmp.c,v 1.4 2012/03/25 08:17:54 joerg Exp $ */
4 * Written by J.T. Conklin <jtc@acorntoolworks.com>
15 ATF_TC_HEAD(strcmp_basic
, tc
)
17 atf_tc_set_md_var(tc
, "descr", "Test strcmp(3) results, #1");
20 ATF_TC_BODY(strcmp_basic
, tc
)
22 /* try to trick the compiler */
23 int (*f
)(const char *, const char *s
) = strcmp
;
25 unsigned int a0
, a1
, t
;
36 const struct tab tab
[] = {
57 { "aaaa", "aaaa", 0 },
58 { "aaaa", "aaab", -1 },
59 { "aaab", "aaaa", +1 },
60 { "aaa", "aaaa", -1 },
61 { "aaaa", "aaa", +1 },
63 { "aaaaa", "aaaaa", 0 },
64 { "aaaaa", "aaaab", -1 },
65 { "aaaab", "aaaaa", +1 },
66 { "aaaa", "aaaaa", -1 },
67 { "aaaaa", "aaaa", +1 },
69 { "aaaaaa", "aaaaaa", 0 },
70 { "aaaaaa", "aaaaab", -1 },
71 { "aaaaab", "aaaaaa", +1 },
72 { "aaaaa", "aaaaaa", -1 },
73 { "aaaaaa", "aaaaa", +1 },
76 for (a0
= 0; a0
< sizeof(long); ++a0
) {
77 for (a1
= 0; a1
< sizeof(long); ++a1
) {
78 for (t
= 0; t
< __arraycount(tab
); ++t
) {
79 memcpy(&buf0
[a0
], tab
[t
].val0
,
80 strlen(tab
[t
].val0
) + 1);
81 memcpy(&buf1
[a1
], tab
[t
].val1
,
82 strlen(tab
[t
].val1
) + 1);
84 ret
= f(&buf0
[a0
], &buf1
[a1
]);
86 if ((ret
== 0 && tab
[t
].ret
!= 0) ||
87 (ret
< 0 && tab
[t
].ret
>= 0) ||
88 (ret
> 0 && tab
[t
].ret
<= 0)) {
89 fprintf(stderr
, "a0 %d, a1 %d, t %d\n",
91 fprintf(stderr
, "\"%s\" \"%s\" %d\n",
92 &buf0
[a0
], &buf1
[a1
], ret
);
93 atf_tc_fail("Check stderr for details");
100 ATF_TC(strcmp_simple
);
101 ATF_TC_HEAD(strcmp_simple
, tc
)
103 atf_tc_set_md_var(tc
, "descr", "Test strcmp(3) results, #2");
106 ATF_TC_BODY(strcmp_simple
, tc
)
108 char buf1
[10] = "xxx";
109 char buf2
[10] = "xxy";
111 ATF_CHECK(strcmp(buf1
, buf1
) == 0);
112 ATF_CHECK(strcmp(buf2
, buf2
) == 0);
114 ATF_CHECK(strcmp("x\xf6x", "xox") > 0);
115 ATF_CHECK(strcmp("xxx", "xxxyyy") < 0);
116 ATF_CHECK(strcmp("xxxyyy", "xxx") > 0);
118 ATF_CHECK(strcmp(buf1
+ 0, buf2
+ 0) < 0);
119 ATF_CHECK(strcmp(buf1
+ 1, buf2
+ 1) < 0);
120 ATF_CHECK(strcmp(buf1
+ 2, buf2
+ 2) < 0);
121 ATF_CHECK(strcmp(buf1
+ 3, buf2
+ 3) == 0);
123 ATF_CHECK(strcmp(buf2
+ 0, buf1
+ 0) > 0);
124 ATF_CHECK(strcmp(buf2
+ 1, buf1
+ 1) > 0);
125 ATF_CHECK(strcmp(buf2
+ 2, buf1
+ 2) > 0);
126 ATF_CHECK(strcmp(buf2
+ 3, buf1
+ 3) == 0);
132 ATF_TP_ADD_TC(tp
, strcmp_basic
);
133 ATF_TP_ADD_TC(tp
, strcmp_simple
);
135 return atf_no_error();