Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src Add bm(3) tests



details:   https://anonhg.NetBSD.org/src/rev/a3155ecb9d08
branches:  trunk
changeset: 330114:a3155ecb9d08
user:      shm <shm%NetBSD.org@localhost>
date:      Mon Jun 23 10:53:20 2014 +0000

description:
Add bm(3) tests

diffstat:

 distrib/sets/lists/debug/mi    |    3 +-
 distrib/sets/lists/tests/mi    |    3 +-
 tests/lib/libc/string/Makefile |    3 +-
 tests/lib/libc/string/t_bm.c   |  102 +++++++++++++++++++++++++++++++++++++++++
 4 files changed, 108 insertions(+), 3 deletions(-)

diffs (155 lines):

diff -r dc68bb65eb86 -r a3155ecb9d08 distrib/sets/lists/debug/mi
--- a/distrib/sets/lists/debug/mi       Mon Jun 23 10:43:25 2014 +0000
+++ b/distrib/sets/lists/debug/mi       Mon Jun 23 10:53:20 2014 +0000
@@ -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
diff -r dc68bb65eb86 -r a3155ecb9d08 distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi       Mon Jun 23 10:43:25 2014 +0000
+++ b/distrib/sets/lists/tests/mi       Mon Jun 23 10:53:20 2014 +0000
@@ -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
diff -r dc68bb65eb86 -r a3155ecb9d08 tests/lib/libc/string/Makefile
--- a/tests/lib/libc/string/Makefile    Mon Jun 23 10:43:25 2014 +0000
+++ b/tests/lib/libc/string/Makefile    Mon Jun 23 10:53:20 2014 +0000
@@ -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
diff -r dc68bb65eb86 -r a3155ecb9d08 tests/lib/libc/string/t_bm.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/lib/libc/string/t_bm.c      Mon Jun 23 10:53:20 2014 +0000
@@ -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();
+}



Home | Main Index | Thread Index | Old Index