summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--regress/unittests/Makefile4
-rw-r--r--regress/unittests/match/Makefile12
-rw-r--r--regress/unittests/match/tests.c84
3 files changed, 98 insertions, 2 deletions
diff --git a/regress/unittests/Makefile b/regress/unittests/Makefile
index 0a95d4b20..e70b16644 100644
--- a/regress/unittests/Makefile
+++ b/regress/unittests/Makefile
@@ -1,5 +1,5 @@
1# $OpenBSD: Makefile,v 1.6 2016/05/26 19:14:25 schwarze Exp $ 1# $OpenBSD: Makefile,v 1.7 2016/08/19 06:44:13 djm Exp $
2REGRESS_FAIL_EARLY= yes 2REGRESS_FAIL_EARLY= yes
3SUBDIR= test_helper sshbuf sshkey bitmap kex hostkeys utf8 3SUBDIR= test_helper sshbuf sshkey bitmap kex hostkeys utf8 match
4 4
5.include <bsd.subdir.mk> 5.include <bsd.subdir.mk>
diff --git a/regress/unittests/match/Makefile b/regress/unittests/match/Makefile
new file mode 100644
index 000000000..dc802f58d
--- /dev/null
+++ b/regress/unittests/match/Makefile
@@ -0,0 +1,12 @@
1# $OpenBSD: Makefile,v 1.1 2016/08/19 06:44:13 djm Exp $
2
3TEST_ENV= "MALLOC_OPTIONS=AFGJPRX"
4
5PROG=test_match
6SRCS=tests.c
7REGRESS_TARGETS=run-regress-${PROG}
8
9run-regress-${PROG}: ${PROG}
10 env ${TEST_ENV} ./${PROG}
11
12.include <bsd.regress.mk>
diff --git a/regress/unittests/match/tests.c b/regress/unittests/match/tests.c
new file mode 100644
index 000000000..aaca546bf
--- /dev/null
+++ b/regress/unittests/match/tests.c
@@ -0,0 +1,84 @@
1/* $OpenBSD: tests.c,v 1.1 2016/08/19 06:44:13 djm Exp $ */
2/*
3 * Regress test for matching functions
4 *
5 * Placed in the public domain
6 */
7
8#include <sys/types.h>
9#include <sys/param.h>
10#include <stdio.h>
11#include <stdint.h>
12#include <stdlib.h>
13#include <string.h>
14
15#include "test_helper.h"
16
17#include "match.h"
18
19void
20tests(void)
21{
22 TEST_START("match_pattern");
23 ASSERT_INT_EQ(match_pattern("", ""), 1);
24 ASSERT_INT_EQ(match_pattern("", "aaa"), 0);
25 ASSERT_INT_EQ(match_pattern("aaa", ""), 0);
26 ASSERT_INT_EQ(match_pattern("aaa", "aaaa"), 0);
27 ASSERT_INT_EQ(match_pattern("aaaa", "aaa"), 0);
28 TEST_DONE();
29
30 TEST_START("match_pattern wildcard");
31 ASSERT_INT_EQ(match_pattern("", "*"), 1);
32 ASSERT_INT_EQ(match_pattern("a", "?"), 1);
33 ASSERT_INT_EQ(match_pattern("aa", "a?"), 1);
34 ASSERT_INT_EQ(match_pattern("a", "*"), 1);
35 ASSERT_INT_EQ(match_pattern("aa", "a*"), 1);
36 ASSERT_INT_EQ(match_pattern("aa", "?*"), 1);
37 ASSERT_INT_EQ(match_pattern("aa", "**"), 1);
38 ASSERT_INT_EQ(match_pattern("aa", "?a"), 1);
39 ASSERT_INT_EQ(match_pattern("aa", "*a"), 1);
40 ASSERT_INT_EQ(match_pattern("ba", "a?"), 0);
41 ASSERT_INT_EQ(match_pattern("ba", "a*"), 0);
42 ASSERT_INT_EQ(match_pattern("ab", "?a"), 0);
43 ASSERT_INT_EQ(match_pattern("ab", "*a"), 0);
44 TEST_DONE();
45
46 TEST_START("match_pattern_list");
47 ASSERT_INT_EQ(match_pattern_list("", "", 0), 0); /* no patterns */
48 ASSERT_INT_EQ(match_pattern_list("", "*", 0), 1);
49 ASSERT_INT_EQ(match_pattern_list("", "!*", 0), -1);
50 ASSERT_INT_EQ(match_pattern_list("", "!a,*", 0), 1);
51 ASSERT_INT_EQ(match_pattern_list("", "*,!a", 0), 1);
52 ASSERT_INT_EQ(match_pattern_list("", "a,!*", 0), -1);
53 ASSERT_INT_EQ(match_pattern_list("", "!*,a", 0), -1);
54 ASSERT_INT_EQ(match_pattern_list("a", "", 0), 0);
55 ASSERT_INT_EQ(match_pattern_list("a", "*", 0), 1);
56 ASSERT_INT_EQ(match_pattern_list("a", "!*", 0), -1);
57 ASSERT_INT_EQ(match_pattern_list("a", "!a,*", 0), -1);
58 ASSERT_INT_EQ(match_pattern_list("b", "!a,*", 0), 1);
59 ASSERT_INT_EQ(match_pattern_list("a", "*,!a", 0), -1);
60 ASSERT_INT_EQ(match_pattern_list("b", "*,!a", 0), 1);
61 ASSERT_INT_EQ(match_pattern_list("a", "a,!*", 0), -1);
62 ASSERT_INT_EQ(match_pattern_list("b", "a,!*", 0), -1);
63 ASSERT_INT_EQ(match_pattern_list("a", "!*,a", 0), -1);
64 ASSERT_INT_EQ(match_pattern_list("b", "!*,a", 0), -1);
65 TEST_DONE();
66
67 TEST_START("match_pattern_list lowercase");
68 ASSERT_INT_EQ(match_pattern_list("abc", "ABC", 0), 0);
69 ASSERT_INT_EQ(match_pattern_list("ABC", "abc", 0), 0);
70 ASSERT_INT_EQ(match_pattern_list("abc", "ABC", 1), 1);
71 ASSERT_INT_EQ(match_pattern_list("ABC", "abc", 1), 0);
72 TEST_DONE();
73
74/*
75 * XXX TODO
76 * int match_host_and_ip(const char *, const char *, const char *);
77 * int match_user(const char *, const char *, const char *, const char *);
78 * char *match_list(const char *, const char *, u_int *);
79 * int addr_match_list(const char *, const char *);
80 * int addr_match_cidr_list(const char *, const char *);
81 */
82
83}
84