dovecot-2.2: lib: Added unit tests for wildcard_match()

dovecot at dovecot.org dovecot at dovecot.org
Tue Aug 19 21:54:19 UTC 2014


details:   http://hg.dovecot.org/dovecot-2.2/rev/d1d4beff99f7
changeset: 17727:d1d4beff99f7
user:      Timo Sirainen <tss at iki.fi>
date:      Tue Aug 19 23:53:18 2014 +0200
description:
lib: Added unit tests for wildcard_match()

diffstat:

 src/lib/Makefile.am           |   3 +-
 src/lib/test-lib.c            |   1 +
 src/lib/test-lib.h            |   1 +
 src/lib/test-wildcard-match.c |  44 +++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 48 insertions(+), 1 deletions(-)

diffs (82 lines):

diff -r 2ca346d91310 -r d1d4beff99f7 src/lib/Makefile.am
--- a/src/lib/Makefile.am	Tue Aug 19 23:51:14 2014 +0200
+++ b/src/lib/Makefile.am	Tue Aug 19 23:53:18 2014 +0200
@@ -313,7 +313,8 @@
 	test-time-util.c \
 	test-unichar.c \
 	test-utc-mktime.c \
-	test-var-expand.c
+	test-var-expand.c \
+	test-wildcard-match.c
 
 test_headers = \
 	test-lib.h
diff -r 2ca346d91310 -r d1d4beff99f7 src/lib/test-lib.c
--- a/src/lib/test-lib.c	Tue Aug 19 23:51:14 2014 +0200
+++ b/src/lib/test-lib.c	Tue Aug 19 23:53:18 2014 +0200
@@ -45,6 +45,7 @@
 		test_unichar,
 		test_utc_mktime,
 		test_var_expand,
+		test_wildcard_match,
 		NULL
 	};
 	static enum fatal_test_state (*fatal_functions[])(int) = {
diff -r 2ca346d91310 -r d1d4beff99f7 src/lib/test-lib.h
--- a/src/lib/test-lib.h	Tue Aug 19 23:51:14 2014 +0200
+++ b/src/lib/test-lib.h	Tue Aug 19 23:53:18 2014 +0200
@@ -47,5 +47,6 @@
 void test_unichar(void);
 void test_utc_mktime(void);
 void test_var_expand(void);
+void test_wildcard_match(void);
 
 #endif
diff -r 2ca346d91310 -r d1d4beff99f7 src/lib/test-wildcard-match.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/lib/test-wildcard-match.c	Tue Aug 19 23:53:18 2014 +0200
@@ -0,0 +1,44 @@
+/* Copyright (c) 2014 Dovecot authors, see the included COPYING file */
+
+#include "test-lib.h"
+#include "wildcard-match.h"
+
+static struct {
+	const char *data;
+	const char *mask;
+	bool result;
+} tests[] = {
+	{ "foo", "*", TRUE },
+	{ "foo", "*foo*", TRUE },
+	{ "foo", "foo", TRUE },
+	{ "foo", "f*o*o", TRUE },
+	{ "foo", "f??", TRUE },
+	{ "foo", "f?o", TRUE },
+	{ "foo", "*??", TRUE },
+	{ "foo", "???", TRUE },
+	{ "foo", "f??*", TRUE },
+	{ "foo", "???*", TRUE },
+
+	{ "foo", "", FALSE },
+	{ "foo", "f", FALSE },
+	{ "foo", "fo", FALSE },
+	{ "foo", "fooo", FALSE },
+	{ "foo", "????", FALSE },
+	{ "foo", "f*o*o*o", FALSE },
+	{ "foo", "f???*", FALSE },
+
+	{ "", "*", TRUE },
+	{ "", "", TRUE },
+	{ "", "?", FALSE }
+};
+
+void test_wildcard_match(void)
+{
+	unsigned int i;
+
+	test_begin("wildcard_match()");
+	for (i = 0; i < N_ELEMENTS(tests); i++) {
+		test_assert_idx(wildcard_match(tests[i].data, tests[i].mask) == tests[i].result, i);
+	}
+	test_end();
+}


More information about the dovecot-cvs mailing list