You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by wr...@apache.org on 2011/05/02 19:02:33 UTC
svn commit: r1098664 - /apr/apr/branches/1.4.x/test/testfnmatch.c
Author: wrowe
Date: Mon May 2 17:02:32 2011
New Revision: 1098664
URL: http://svn.apache.org/viewvc?rev=1098664&view=rev
Log:
Some fnmatch patterns, more needed
Modified:
apr/apr/branches/1.4.x/test/testfnmatch.c
Modified: apr/apr/branches/1.4.x/test/testfnmatch.c
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.4.x/test/testfnmatch.c?rev=1098664&r1=1098663&r2=1098664&view=diff
==============================================================================
--- apr/apr/branches/1.4.x/test/testfnmatch.c (original)
+++ apr/apr/branches/1.4.x/test/testfnmatch.c Mon May 2 17:02:32 2011
@@ -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 *suit
{
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);