Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/tests/lib/libc/string Add few simple test cases.
details: https://anonhg.NetBSD.org/src/rev/6ccddc48d670
branches: trunk
changeset: 767272:6ccddc48d670
user: jruoho <jruoho%NetBSD.org@localhost>
date: Thu Jul 14 05:46:04 2011 +0000
description:
Add few simple test cases.
diffstat:
tests/lib/libc/string/t_memchr.c | 67 ++++++++++++++++++++++++++++++++++++++-
tests/lib/libc/string/t_memcpy.c | 29 ++++++++++++++++-
tests/lib/libc/string/t_strcat.c | 23 +++++++++++++-
3 files changed, 115 insertions(+), 4 deletions(-)
diffs (180 lines):
diff -r 6d3d12d6c4b4 -r 6ccddc48d670 tests/lib/libc/string/t_memchr.c
--- a/tests/lib/libc/string/t_memchr.c Thu Jul 14 05:31:16 2011 +0000
+++ b/tests/lib/libc/string/t_memchr.c Thu Jul 14 05:46:04 2011 +0000
@@ -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@localhost>
@@ -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(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();
}
diff -r 6d3d12d6c4b4 -r 6ccddc48d670 tests/lib/libc/string/t_memcpy.c
--- a/tests/lib/libc/string/t_memcpy.c Thu Jul 14 05:31:16 2011 +0000
+++ b/tests/lib/libc/string/t_memcpy.c Thu Jul 14 05:46:04 2011 +0000
@@ -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_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();
}
diff -r 6d3d12d6c4b4 -r 6ccddc48d670 tests/lib/libc/string/t_strcat.c
--- a/tests/lib/libc/string/t_strcat.c Thu Jul 14 05:31:16 2011 +0000
+++ b/tests/lib/libc/string/t_strcat.c Thu Jul 14 05:46:04 2011 +0000
@@ -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@localhost>
@@ -123,10 +123,31 @@
}
}
+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();
}
Home |
Main Index |
Thread Index |
Old Index