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 Few basic checks, including a case for...



details:   https://anonhg.NetBSD.org/src/rev/50b608c480e1
branches:  trunk
changeset: 767043:50b608c480e1
user:      jruoho <jruoho%NetBSD.org@localhost>
date:      Thu Jul 07 09:31:27 2011 +0000

description:
Few basic checks, including a case for strnlen(3).

diffstat:

 tests/lib/libc/string/t_strcmp.c |  34 ++++++++++++++++++++++++++++++++--
 tests/lib/libc/string/t_strlen.c |  25 ++++++++++++++++++++++++-
 2 files changed, 56 insertions(+), 3 deletions(-)

diffs (103 lines):

diff -r fca17ee8fd07 -r 50b608c480e1 tests/lib/libc/string/t_strcmp.c
--- a/tests/lib/libc/string/t_strcmp.c  Thu Jul 07 09:16:06 2011 +0000
+++ b/tests/lib/libc/string/t_strcmp.c  Thu Jul 07 09:31:27 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: t_strcmp.c,v 1.1 2011/07/07 08:59:33 jruoho Exp $ */
+/* $NetBSD: t_strcmp.c,v 1.2 2011/07/07 09:31:27 jruoho Exp $ */
 
 /*
  * Written by J.T. Conklin <jtc%acorntoolworks.com@localhost>
@@ -14,7 +14,7 @@
 ATF_TC(strcmp_basic);
 ATF_TC_HEAD(strcmp_basic, tc)
 {
-        atf_tc_set_md_var(tc, "descr", "Test strcmp(3) results");
+        atf_tc_set_md_var(tc, "descr", "Test strcmp(3) results, #1");
 }
 
 ATF_TC_BODY(strcmp_basic, tc)
@@ -97,10 +97,40 @@
        }
 }
 
+ATF_TC(strcmp_simple);
+ATF_TC_HEAD(strcmp_simple, tc)
+{
+        atf_tc_set_md_var(tc, "descr", "Test strcmp(3) results, #2");
+}
+
+ATF_TC_BODY(strcmp_simple, tc)
+{
+       char buf1[10] = "xxx";
+       char buf2[10] = "xxy";
+
+       ATF_REQUIRE(strcmp(buf1, buf1) == 0);
+       ATF_REQUIRE(strcmp(buf2, buf2) == 0);
+
+       ATF_REQUIRE(strcmp("xöx", "xox") > 0);
+       ATF_REQUIRE(strcmp("xxx", "xxxyyy") < 0);
+       ATF_REQUIRE(strcmp("xxxyyy", "xxx") > 0);
+
+       ATF_REQUIRE(strcmp(buf1 + 0, buf2 + 0) < 0);
+       ATF_REQUIRE(strcmp(buf1 + 1, buf2 + 1) < 0);
+       ATF_REQUIRE(strcmp(buf1 + 2, buf2 + 2) < 0);
+       ATF_REQUIRE(strcmp(buf1 + 3, buf2 + 3) == 0);
+
+       ATF_REQUIRE(strcmp(buf2 + 0, buf1 + 0) > 0);
+       ATF_REQUIRE(strcmp(buf2 + 1, buf1 + 1) > 0);
+       ATF_REQUIRE(strcmp(buf2 + 2, buf1 + 2) > 0);
+       ATF_REQUIRE(strcmp(buf2 + 3, buf1 + 3) == 0);
+}
+
 ATF_TP_ADD_TCS(tp)
 {
 
        ATF_TP_ADD_TC(tp, strcmp_basic);
+       ATF_TP_ADD_TC(tp, strcmp_simple);
 
        return atf_no_error();
 }
diff -r fca17ee8fd07 -r 50b608c480e1 tests/lib/libc/string/t_strlen.c
--- a/tests/lib/libc/string/t_strlen.c  Thu Jul 07 09:16:06 2011 +0000
+++ b/tests/lib/libc/string/t_strlen.c  Thu Jul 07 09:31:27 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: t_strlen.c,v 1.2 2011/07/07 09:16:06 jruoho Exp $ */
+/* $NetBSD: t_strlen.c,v 1.3 2011/07/07 09:31:27 jruoho Exp $ */
 
 /*
  * Written by J.T. Conklin <jtc%acorntoolworks.com@localhost>
@@ -166,11 +166,34 @@
        }
 }
 
+ATF_TC(strnlen_basic);
+ATF_TC_HEAD(strnlen_basic, tc)
+{
+        atf_tc_set_md_var(tc, "descr", "A naive test of strnlen(3)");
+}
+
+ATF_TC_BODY(strnlen_basic, tc)
+{
+       char buf[1];
+
+       buf[0] = '\0';
+
+       ATF_REQUIRE(strnlen(buf, 000) == 0);
+       ATF_REQUIRE(strnlen(buf, 111) == 0);
+
+       ATF_REQUIRE(strnlen("xxx", 0) == 0);
+       ATF_REQUIRE(strnlen("xxx", 1) == 1);
+       ATF_REQUIRE(strnlen("xxx", 2) == 2);
+       ATF_REQUIRE(strnlen("xxx", 3) == 3);
+       ATF_REQUIRE(strnlen("xxx", 9) == 3);
+}
+
 ATF_TP_ADD_TCS(tp)
 {
 
        ATF_TP_ADD_TC(tp, strlen_basic);
        ATF_TP_ADD_TC(tp, strlen_huge);
+       ATF_TP_ADD_TC(tp, strnlen_basic);
 
        return atf_no_error();
 }



Home | Main Index | Thread Index | Old Index