1 /* $Id: t_bm.c,v 1.1 2014/06/23 10:53:20 shm Exp $ */
3 * Copyright (c) 2014 The NetBSD Foundation, Inc.
6 * This code is derived from software contributed to The NetBSD Foundation
7 * by Mateusz Kocielski.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
31 #include <sys/cdefs.h>
32 __RCSID("$Id: t_bm.c,v 1.1 2014/06/23 10:53:20 shm Exp $");
36 #include <sys/types.h>
44 atf_tc_set_md_var(tc
, "descr", "Test bm(3)");
54 const t_testcase testcases
[] = {
55 {"test", "test", NULL
, 0},
56 {"test", "ttest", NULL
, 1},
57 {"test", "tes", NULL
, -1},
58 {"test", "testtesttest", NULL
, 0},
59 {"test", "testtesttesttesttesttest", NULL
, 0},
60 {"test", "------------------------", NULL
, -1},
63 {"a", "bba", NULL
, 2},
64 {"bla", "bl", NULL
, -1},
65 {"a", "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", NULL
, -1},
66 {"test", "qfwiofjqeiwofjioqewfjeiqwjfiqewjfioqewfjioewqjfioewqjfioewqjoi",
68 {"needle", "haystack", NULL
, -1},
69 {"netbsd", "freebsd netbsd openbsd", NULL
, 8},
79 for (ts
= 0; ts
< sizeof(testcases
)/sizeof(t_testcase
); ts
++) {
80 ATF_CHECK(pattern
= bm_comp((const u_char
*)testcases
[ts
].pattern
,
81 strlen(testcases
[ts
].pattern
), (const u_char
*)testcases
[ts
].freq
));
83 ATF_REQUIRE(text
= strdup(testcases
[ts
].text
));
84 off
= bm_exec(pattern
, (u_char
*)text
, strlen(text
));
86 if (testcases
[ts
].match
== -1)
87 ATF_CHECK_EQ(off
, NULL
);
89 ATF_CHECK_EQ(testcases
[ts
].match
,
90 (off
-(u_char
*)text
));
100 ATF_TP_ADD_TC(tp
, bm
);
101 return atf_no_error();