Add few simple test cases.

This commit is contained in:
jruoho 2011-07-14 05:46:04 +00:00
parent b8272261e5
commit 5fb118d0d5
3 changed files with 115 additions and 4 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: t_memchr.c,v 1.1 2011/07/07 08:59:32 jruoho Exp $ */
/* $NetBSD: t_memchr.c,v 1.2 2011/07/14 05:46:04 jruoho Exp $ */
/*
* Written by J.T. Conklin <jtc@acorntoolworks.com>
@ -14,7 +14,7 @@
ATF_TC(memchr_basic);
ATF_TC_HEAD(memchr_basic, tc)
{
atf_tc_set_md_var(tc, "descr", "Test memchr(3) results");
atf_tc_set_md_var(tc, "descr", "Test memchr(3) results, #1");
}
ATF_TC_BODY(memchr_basic, tc)
@ -128,10 +128,73 @@ ATF_TC_BODY(memchr_basic, tc)
}
}
ATF_TC(memchr_simple);
ATF_TC_HEAD(memchr_simple, tc)
{
atf_tc_set_md_var(tc, "descr", "Test memchr(3) results, #2");
}
ATF_TC_BODY(memchr_simple, tc)
{
char buf[] = "abcdefg";
short i = 7;
ATF_CHECK(memchr(buf, 'a', 0) == NULL);
ATF_CHECK(memchr(buf, 'g', 0) == NULL);
ATF_CHECK(memchr(buf, 'x', 7) == NULL);
ATF_CHECK(memchr("\0", 'x', 0) == NULL);
ATF_CHECK(memchr("\0", 'x', 1) == NULL);
while (i <= 14) {
ATF_CHECK(memchr(buf, 'a', i) == buf + 0);
ATF_CHECK(memchr(buf, 'b', i) == buf + 1);
ATF_CHECK(memchr(buf, 'c', i) == buf + 2);
ATF_CHECK(memchr(buf, 'd', i) == buf + 3);
ATF_CHECK(memchr(buf, 'e', i) == buf + 4);
ATF_CHECK(memchr(buf, 'f', i) == buf + 5);
ATF_CHECK(memchr(buf, 'g', i) == buf + 6);
i *= 2;
}
}
ATF_TC(memrchr_simple);
ATF_TC_HEAD(memrchr_simple, tc)
{
atf_tc_set_md_var(tc, "descr", "Test memrchr(3) results");
}
ATF_TC_BODY(memrchr_simple, tc)
{
char buf[] = "abcdabcd";
short i = 8;
ATF_CHECK(memrchr(buf, 'a', 0) == NULL);
ATF_CHECK(memrchr(buf, 'g', 0) == NULL);
ATF_CHECK(memrchr(buf, 'x', 8) == NULL);
ATF_CHECK(memrchr("\0", 'x', 0) == NULL);
ATF_CHECK(memrchr("\0", 'x', 1) == NULL);
while (i <= 16) {
ATF_CHECK(memrchr(buf, 'a', i) == buf + 4);
ATF_CHECK(memrchr(buf, 'b', i) == buf + 5);
ATF_CHECK(memrchr(buf, 'c', i) == buf + 6);
ATF_CHECK(memrchr(buf, 'd', i) == buf + 7);
i *= 2;
}
}
ATF_TP_ADD_TCS(tp)
{
ATF_TP_ADD_TC(tp, memchr_basic);
ATF_TP_ADD_TC(tp, memchr_simple);
ATF_TP_ADD_TC(tp, memrchr_simple);
return atf_no_error();
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: t_memcpy.c,v 1.3 2011/07/07 08:27:36 jruoho Exp $ */
/* $NetBSD: t_memcpy.c,v 1.4 2011/07/14 05:46:04 jruoho Exp $ */
/*-
* Copyright (c) 2010 The NetBSD Foundation, Inc.
@ -99,10 +99,37 @@ ATF_TC_BODY(memcpy_basic, tc)
ATF_REQUIRE_EQ(strcmp(result, goodResult), 0);
}
ATF_TC(memccpy_simple);
ATF_TC_HEAD(memccpy_simple, tc)
{
atf_tc_set_md_var(tc, "descr", "Test memccpy(3) results");
}
ATF_TC_BODY(memccpy_simple, tc)
{
char buf[100];
char c = ' ';
(void)memset(buf, c, sizeof(buf));
ATF_CHECK(memccpy(buf, "foo bar", c, sizeof(buf)) != NULL);
ATF_CHECK(buf[4] == c);
ATF_CHECK(memccpy(buf, "foo bar", '\0', sizeof(buf) - 1) != NULL);
ATF_CHECK(buf[8] == c);
ATF_CHECK(memccpy(buf, "foo bar", 'x', 7) == NULL);
ATF_CHECK(strncmp(buf, "foo bar", 7) == 0);
ATF_CHECK(memccpy(buf, "xxxxxxx", 'r', 7) == NULL);
ATF_CHECK(strncmp(buf, "xxxxxxx", 7) == 0);
}
ATF_TP_ADD_TCS(tp)
{
ATF_TP_ADD_TC(tp, memcpy_basic);
ATF_TP_ADD_TC(tp, memccpy_simple);
return atf_no_error();
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: t_strcat.c,v 1.1 2011/07/07 08:59:32 jruoho Exp $ */
/* $NetBSD: t_strcat.c,v 1.2 2011/07/14 05:46:04 jruoho Exp $ */
/*
* Written by J.T. Conklin <jtc@acorntoolworks.com>
@ -123,10 +123,31 @@ ATF_TC_BODY(strcat_basic, tc)
}
}
ATF_TC(strncat_simple);
ATF_TC_HEAD(strncat_simple, tc)
{
atf_tc_set_md_var(tc, "descr", "Test strncat(3) results");
}
ATF_TC_BODY(strncat_simple, tc)
{
char buf[100] = "abcdefg";
ATF_CHECK(strncat(buf, "xxx", 0) == buf);
ATF_CHECK(strcmp(buf, "abcdefg") == 0);
ATF_CHECK(strncat(buf, "xxx", 1) == buf);
ATF_CHECK(strcmp(buf, "abcdefgx") == 0);
ATF_CHECK(strncat(buf, "xxx", 2) == buf);
ATF_CHECK(strcmp(buf, "abcdefgxxx") == 0);
ATF_CHECK(strncat(buf, "\0", 1) == buf);
ATF_CHECK(strcmp(buf, "abcdefgxxx") == 0);
}
ATF_TP_ADD_TCS(tp)
{
ATF_TP_ADD_TC(tp, strcat_basic);
ATF_TP_ADD_TC(tp, strncat_simple);
return atf_no_error();
}