Module Name:    src
Committed By:   shm
Date:           Mon Jun 23 10:53:20 UTC 2014

Modified Files:
        src/distrib/sets/lists/debug: mi
        src/distrib/sets/lists/tests: mi
        src/tests/lib/libc/string: Makefile
Added Files:
        src/tests/lib/libc/string: t_bm.c

Log Message:
Add bm(3) tests


To generate a diff of this commit:
cvs rdiff -u -r1.61 -r1.62 src/distrib/sets/lists/debug/mi
cvs rdiff -u -r1.572 -r1.573 src/distrib/sets/lists/tests/mi
cvs rdiff -u -r1.8 -r1.9 src/tests/lib/libc/string/Makefile
cvs rdiff -u -r0 -r1.1 src/tests/lib/libc/string/t_bm.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/distrib/sets/lists/debug/mi
diff -u src/distrib/sets/lists/debug/mi:1.61 src/distrib/sets/lists/debug/mi:1.62
--- src/distrib/sets/lists/debug/mi:1.61	Mon Jun 16 12:54:42 2014
+++ src/distrib/sets/lists/debug/mi	Mon Jun 23 10:53:20 2014
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.61 2014/06/16 12:54:42 joerg Exp $
+# $NetBSD: mi,v 1.62 2014/06/23 10:53:20 shm Exp $
 
 ./etc/mtree/set.debug                           comp-sys-root
 ./usr/lib/i18n/libBIG5_g.a			comp-c-debuglib		debuglib
@@ -1921,6 +1921,7 @@
 ./usr/libdata/debug/usr/tests/lib/libc/stdlib/t_strtol.debug		tests-lib-debug		debug,atf
 ./usr/libdata/debug/usr/tests/lib/libc/stdlib/t_strtox.debug		tests-obsolete		obsolete
 ./usr/libdata/debug/usr/tests/lib/libc/stdlib/t_system.debug		tests-lib-debug		debug,atf
+./usr/libdata/debug/usr/tests/lib/libc/string/t_bm.debug		tests-lib-debug		debug,atf
 ./usr/libdata/debug/usr/tests/lib/libc/string/t_memchr.debug		tests-lib-debug		debug,atf
 ./usr/libdata/debug/usr/tests/lib/libc/string/t_memcpy.debug		tests-lib-debug		debug,atf
 ./usr/libdata/debug/usr/tests/lib/libc/string/t_memmem.debug		tests-lib-debug		debug,atf

Index: src/distrib/sets/lists/tests/mi
diff -u src/distrib/sets/lists/tests/mi:1.572 src/distrib/sets/lists/tests/mi:1.573
--- src/distrib/sets/lists/tests/mi:1.572	Mon Jun 16 12:54:43 2014
+++ src/distrib/sets/lists/tests/mi	Mon Jun 23 10:53:20 2014
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.572 2014/06/16 12:54:43 joerg Exp $
+# $NetBSD: mi,v 1.573 2014/06/23 10:53:20 shm Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -2580,6 +2580,7 @@
 ./usr/tests/lib/libc/string			tests-lib-tests
 ./usr/tests/lib/libc/string/Atffile		tests-lib-tests		atf
 ./usr/tests/lib/libc/string/Kyuafile		tests-lib-tests		atf,kyua
+./usr/tests/lib/libc/string/t_bm		tests-lib-tests		atf
 ./usr/tests/lib/libc/string/t_memchr		tests-lib-tests		atf
 ./usr/tests/lib/libc/string/t_memcpy		tests-lib-tests		atf
 ./usr/tests/lib/libc/string/t_memmem		tests-lib-tests		atf

Index: src/tests/lib/libc/string/Makefile
diff -u src/tests/lib/libc/string/Makefile:1.8 src/tests/lib/libc/string/Makefile:1.9
--- src/tests/lib/libc/string/Makefile:1.8	Mon Nov 21 23:50:45 2011
+++ src/tests/lib/libc/string/Makefile	Mon Jun 23 10:53:20 2014
@@ -1,9 +1,10 @@
-# $NetBSD: Makefile,v 1.8 2011/11/21 23:50:45 joerg Exp $
+# $NetBSD: Makefile,v 1.9 2014/06/23 10:53:20 shm Exp $
 
 .include <bsd.own.mk>
 
 TESTSDIR=	${TESTSBASE}/lib/libc/string
 
+TESTS_C+=	t_bm
 TESTS_C+=	t_memchr
 TESTS_C+=	t_memcpy
 TESTS_C+=	t_memmem

Added files:

Index: src/tests/lib/libc/string/t_bm.c
diff -u /dev/null src/tests/lib/libc/string/t_bm.c:1.1
--- /dev/null	Mon Jun 23 10:53:21 2014
+++ src/tests/lib/libc/string/t_bm.c	Mon Jun 23 10:53:20 2014
@@ -0,0 +1,102 @@
+/* $Id: t_bm.c,v 1.1 2014/06/23 10:53:20 shm Exp $ */
+/*-
+ * Copyright (c) 2014 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Mateusz Kocielski.
+ *
+ * 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("$Id: t_bm.c,v 1.1 2014/06/23 10:53:20 shm Exp $");
+
+#include <atf-c.h>
+#include <stdio.h>
+#include <sys/types.h>
+#include <bm.h>
+#include <string.h>
+#include <stdlib.h>
+
+ATF_TC(bm);
+ATF_TC_HEAD(bm, tc)
+{
+	atf_tc_set_md_var(tc, "descr", "Test bm(3)");
+}
+
+typedef struct {
+	const char *pattern;
+	const char *text;
+	const char *freq;
+	ssize_t match;
+} t_testcase;
+
+const t_testcase testcases[] = {
+	{"test", "test", NULL, 0},
+	{"test", "ttest", NULL, 1},
+	{"test", "tes", NULL, -1},
+	{"test", "testtesttest", NULL, 0},
+	{"test", "testtesttesttesttesttest", NULL, 0},
+	{"test", "------------------------", NULL, -1},
+	{"a", "a", NULL, 0},
+	{"a", "ba", NULL, 1},
+	{"a", "bba", NULL, 2},
+	{"bla", "bl", NULL, -1},
+	{"a", "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", NULL, -1},
+	{"test", "qfwiofjqeiwofjioqewfjeiqwjfiqewjfioqewfjioewqjfioewqjfioewqjoi",
+	  NULL, -1},
+	{"needle", "haystack", NULL, -1},
+	{"netbsd", "freebsd netbsd openbsd", NULL, 8},
+};
+
+ATF_TC_BODY(bm, tc)
+{
+	size_t ts;
+	u_char *off;
+	char *text;
+	bm_pat *pattern;
+	
+	for (ts = 0; ts < sizeof(testcases)/sizeof(t_testcase); ts++) {
+		ATF_CHECK(pattern = bm_comp((const u_char *)testcases[ts].pattern,
+		  strlen(testcases[ts].pattern), (const u_char *)testcases[ts].freq));
+
+		ATF_REQUIRE(text = strdup(testcases[ts].text));
+		off = bm_exec(pattern, (u_char *)text, strlen(text));
+
+		if (testcases[ts].match == -1)
+			ATF_CHECK_EQ(off, NULL);
+		else
+			ATF_CHECK_EQ(testcases[ts].match,
+			  (off-(u_char *)text));
+
+		bm_free(pattern);
+		free(text);
+	}
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+	ATF_TP_ADD_TC(tp, bm);
+	return atf_no_error();
+}

Reply via email to