summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorwrowe <wrowe@13f79535-47bb-0310-9956-ffa450edef68>2011-05-02 17:02:32 +0000
committerwrowe <wrowe@13f79535-47bb-0310-9956-ffa450edef68>2011-05-02 17:02:32 +0000
commit7a4743c9d5406dc6941f14d409c759c3f20bd765 (patch)
treea8a82273d5330df368a5d01e7467c370ca5faec9 /test
parentb14cea73276be29145c7a5e9f786be7eb6a1ff0f (diff)
downloadlibapr-7a4743c9d5406dc6941f14d409c759c3f20bd765.tar.gz
Some fnmatch patterns, more needed
git-svn-id: http://svn.apache.org/repos/asf/apr/apr/branches/1.4.x@1098664 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'test')
-rw-r--r--test/testfnmatch.c54
1 files changed, 54 insertions, 0 deletions
diff --git a/test/testfnmatch.c b/test/testfnmatch.c
index 379619887..82e817146 100644
--- a/test/testfnmatch.c
+++ b/test/testfnmatch.c
@@ -25,6 +25,59 @@
#define NUM_FILES (5)
+#define APR_FNM_ANY 0
+#define APR_FNM_NONE 128
+
+/* A string is expected to match pattern only if a success_flags bit is true,
+ * and is expected to fail for all other cases (so APR_FNM_NONE is bit never tested).
+ */
+static struct pattern_s {
+ const char *pattern;
+ const char *string;
+ int success_flags;
+} patterns[] = {
+
+ {"test", "test", APR_FNM_ANY},
+ {"test/this", "test/this", APR_FNM_ANY},
+ {"teST", "TEst", APR_FNM_CASE_BLIND},
+ {"*", "", APR_FNM_ANY},
+ {"*", "test", APR_FNM_ANY},
+ {".*", ".test", APR_FNM_PERIOD},
+ {"*", ".test", APR_FNM_NONE},
+ {"", "test", APR_FNM_NONE},
+ {"", "*", APR_FNM_NONE},
+ {"test", "*", APR_FNM_NONE},
+ {"test/this", "test/", APR_FNM_NONE},
+ {"test/", "test/this", APR_FNM_NONE},
+
+ {NULL, NULL, 0}
+};
+
+#define APR_FNM_MAX 15 /* all bits */
+
+static void test_fnmatch(abts_case *tc, void *data)
+{
+ struct pattern_s *test = patterns;
+ int i;
+ int res;
+
+ for (test = patterns; test->pattern; ++test)
+ for (i = 0; i <= APR_FNM_MAX; ++i)
+ {
+ res = apr_fnmatch(test->pattern, test->string, i);
+ if ((i & test->success_flags) == test->success_flags) {
+ if (res == APR_FNM_NOMATCH)
+ break;
+ }
+ else {
+ if (res != APR_FNM_NOMATCH)
+ break;
+ }
+ }
+
+ ABTS_INT_EQUAL(tc, APR_FNM_MAX + 1, i);
+}
+
static void test_glob(abts_case *tc, void *data)
{
int i;
@@ -68,6 +121,7 @@ abts_suite *testfnmatch(abts_suite *suite)
{
suite = ADD_SUITE(suite)
+ abts_run_test(suite, test_fnmatch, NULL);
abts_run_test(suite, test_glob, NULL);
abts_run_test(suite, test_glob_currdir, NULL);