summaryrefslogtreecommitdiff
path: root/tests/lib/libc/string
diff options
context:
space:
mode:
authorjoerg <joerg@NetBSD.org>2011-11-21 23:50:44 +0000
committerjoerg <joerg@NetBSD.org>2011-11-21 23:50:44 +0000
commitcf5b206fe31d956c20cd5d331a7352f202f2d265 (patch)
tree75fe92e8649cd372f3fd746580e2bac9d6c8bb61 /tests/lib/libc/string
parentb5df9b6700fd304520105359d6fc03632f56931d (diff)
Add test cases for strcspn, strpbrk, strspn, wcscspn, wcspbrk and
wcsspn.
Diffstat (limited to 'tests/lib/libc/string')
-rw-r--r--tests/lib/libc/string/Makefile5
-rw-r--r--tests/lib/libc/string/t_strcspn.c58
-rw-r--r--tests/lib/libc/string/t_strpbrk.c62
-rw-r--r--tests/lib/libc/string/t_strspn.c60
4 files changed, 184 insertions, 1 deletions
diff --git a/tests/lib/libc/string/Makefile b/tests/lib/libc/string/Makefile
index ba4b2700543..9bd1959488d 100644
--- a/tests/lib/libc/string/Makefile
+++ b/tests/lib/libc/string/Makefile
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.7 2011/07/07 08:59:33 jruoho Exp $
+# $NetBSD: Makefile,v 1.8 2011/11/21 23:50:45 joerg Exp $
.include <bsd.own.mk>
@@ -13,10 +13,13 @@ TESTS_C+= t_strcat
TESTS_C+= t_strchr
TESTS_C+= t_strcmp
TESTS_C+= t_strcpy
+TESTS_C+= t_strcspn
TESTS_C+= t_strerror
TESTS_C+= t_stresep
TESTS_C+= t_strlen
+TESTS_C+= t_strpbrk
TESTS_C+= t_strrchr
+TESTS_C+= t_strspn
TESTS_C+= t_swab
WARNS= 4
diff --git a/tests/lib/libc/string/t_strcspn.c b/tests/lib/libc/string/t_strcspn.c
new file mode 100644
index 00000000000..d38cdb43939
--- /dev/null
+++ b/tests/lib/libc/string/t_strcspn.c
@@ -0,0 +1,58 @@
+/* $NetBSD: t_strcspn.c,v 1.1 2011/11/21 23:50:45 joerg Exp $ */
+
+/*-
+ * Copyright (c) 2011 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Joerg Sonnenberger.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__RCSID("$NetBSD: t_strcspn.c,v 1.1 2011/11/21 23:50:45 joerg Exp $");
+
+#include <atf-c.h>
+#include <string.h>
+
+ATF_TC(strcspn);
+ATF_TC_HEAD(strcspn, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Test strcspn(3)");
+}
+
+ATF_TC_BODY(strcspn, tc)
+{
+ ATF_CHECK_EQ(strcspn("abcdefghijklmnop", ""), 16);
+ ATF_CHECK_EQ(strcspn("abcdefghijklmnop", "a"), 0);
+ ATF_CHECK_EQ(strcspn("abcdefghijklmnop", "b"), 1);
+ ATF_CHECK_EQ(strcspn("abcdefghijklmnop", "cd"), 2);
+ ATF_CHECK_EQ(strcspn("abcdefghijklmnop", "qrstuvwxyz"), 16);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, strcspn);
+ return atf_no_error();
+}
diff --git a/tests/lib/libc/string/t_strpbrk.c b/tests/lib/libc/string/t_strpbrk.c
new file mode 100644
index 00000000000..d0f2d9b5d0b
--- /dev/null
+++ b/tests/lib/libc/string/t_strpbrk.c
@@ -0,0 +1,62 @@
+/* $NetBSD: t_strpbrk.c,v 1.1 2011/11/21 23:50:45 joerg Exp $ */
+
+/*-
+ * Copyright (c) 2011 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Joerg Sonnenberger.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__RCSID("$NetBSD: t_strpbrk.c,v 1.1 2011/11/21 23:50:45 joerg Exp $");
+
+#include <atf-c.h>
+#include <string.h>
+
+ATF_TC(strpbrk);
+ATF_TC_HEAD(strpbrk, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Test strpbrk(3)");
+}
+
+ATF_TC_BODY(strpbrk, tc)
+{
+ static const char s[] = "abcdefghijklmnop";
+
+ ATF_CHECK_EQ(strpbrk(s, ""), NULL);
+ ATF_CHECK_EQ(strpbrk(s, "qrst"), NULL);
+ ATF_CHECK_EQ(strpbrk(s, "a"), s);
+ ATF_CHECK_EQ(strpbrk(s, "b"), s + 1);
+ ATF_CHECK_EQ(strpbrk(s, "ab"), s);
+ ATF_CHECK_EQ(strpbrk(s, "cdef"), s + 2);
+ ATF_CHECK_EQ(strpbrk(s, "fedc"), s + 2);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, strpbrk);
+ return atf_no_error();
+}
diff --git a/tests/lib/libc/string/t_strspn.c b/tests/lib/libc/string/t_strspn.c
new file mode 100644
index 00000000000..6782181b079
--- /dev/null
+++ b/tests/lib/libc/string/t_strspn.c
@@ -0,0 +1,60 @@
+/* $NetBSD: t_strspn.c,v 1.1 2011/11/21 23:50:45 joerg Exp $ */
+
+/*-
+ * Copyright (c) 2011 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Joerg Sonnenberger.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__RCSID("$NetBSD: t_strspn.c,v 1.1 2011/11/21 23:50:45 joerg Exp $");
+
+#include <atf-c.h>
+#include <string.h>
+
+ATF_TC(strspn);
+ATF_TC_HEAD(strspn, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Test strspn(3)");
+}
+
+ATF_TC_BODY(strspn, tc)
+{
+ ATF_CHECK_EQ(strspn("abcdefghijklmnop", ""), 0);
+ ATF_CHECK_EQ(strspn("abcdefghijklmnop", "a"), 1);
+ ATF_CHECK_EQ(strspn("abcdefghijklmnop", "b"), 0);
+ ATF_CHECK_EQ(strspn("abcdefghijklmnop", "ab"), 2);
+ ATF_CHECK_EQ(strspn("abcdefghijklmnop", "abc"), 3);
+ ATF_CHECK_EQ(strspn("abcdefghijklmnop", "abce"), 3);
+ ATF_CHECK_EQ(strspn("abcdefghijklmnop", "abcdefghijklmnop"), 16);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, strspn);
+ return atf_no_error();
+}