Return-Path: X-Original-To: apmail-apr-commits-archive@www.apache.org Delivered-To: apmail-apr-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 86B2949E5 for ; Tue, 17 May 2011 19:59:22 +0000 (UTC) Received: (qmail 11030 invoked by uid 500); 17 May 2011 19:59:22 -0000 Delivered-To: apmail-apr-commits-archive@apr.apache.org Received: (qmail 10989 invoked by uid 500); 17 May 2011 19:59:22 -0000 Mailing-List: contact commits-help@apr.apache.org; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: Reply-To: dev@apr.apache.org List-Id: Delivered-To: mailing list commits@apr.apache.org Received: (qmail 10982 invoked by uid 99); 17 May 2011 19:59:22 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 17 May 2011 19:59:22 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 17 May 2011 19:59:21 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 2222D23889B2; Tue, 17 May 2011 19:59:01 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1104504 - /apr/apr/branches/1.5.x/test/testfnmatch.c Date: Tue, 17 May 2011 19:59:01 -0000 To: commits@apr.apache.org From: wrowe@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110517195901.2222D23889B2@eris.apache.org> Author: wrowe Date: Tue May 17 19:59:00 2011 New Revision: 1104504 URL: http://svn.apache.org/viewvc?rev=1104504&view=rev Log: Sync fnmatch pattern tests to apr-2.0 trunk at r1104503. Modified: apr/apr/branches/1.5.x/test/testfnmatch.c Modified: apr/apr/branches/1.5.x/test/testfnmatch.c URL: http://svn.apache.org/viewvc/apr/apr/branches/1.5.x/test/testfnmatch.c?rev=1104504&r1=1104503&r2=1104504&view=diff ============================================================================== --- apr/apr/branches/1.5.x/test/testfnmatch.c (original) +++ apr/apr/branches/1.5.x/test/testfnmatch.c Tue May 17 19:59:00 2011 @@ -25,6 +25,173 @@ #define NUM_FILES (5) +#define APR_FNM_BITS 15 +#define APR_FNM_FAILBIT 256 + +#define FAILS_IF(X) 0, X +#define SUCCEEDS_IF(X) X, 256 +#define SUCCEEDS 0, 256 +#define FAILS 256, 0 + +static struct pattern_s { + const char *pattern; + const char *string; + int require_flags; + int fail_flags; +} patterns[] = { + +/* Pattern, String to Test, Flags to Match */ + {"", "test", FAILS}, + {"", "*", FAILS}, + {"test", "*", FAILS}, + {"test", "test", SUCCEEDS}, + + /* Remember C '\\' is a single backslash in pattern */ + {"te\\st", "test", FAILS_IF(APR_FNM_NOESCAPE)}, + {"te\\\\st", "te\\st", FAILS_IF(APR_FNM_NOESCAPE)}, + {"te\\*t", "te*t", FAILS_IF(APR_FNM_NOESCAPE)}, + {"te\\*t", "test", FAILS}, + {"te\\?t", "te?t", FAILS_IF(APR_FNM_NOESCAPE)}, + {"te\\?t", "test", FAILS}, + + {"tesT", "test", SUCCEEDS_IF(APR_FNM_CASE_BLIND)}, + {"test", "Test", SUCCEEDS_IF(APR_FNM_CASE_BLIND)}, + {"tEst", "teSt", SUCCEEDS_IF(APR_FNM_CASE_BLIND)}, + + {"?est", "test", SUCCEEDS}, + {"te?t", "test", SUCCEEDS}, + {"tes?", "test", SUCCEEDS}, + {"test?", "test", FAILS}, + + {"*", "", SUCCEEDS}, + {"*", "test", SUCCEEDS}, + {"*test", "test", SUCCEEDS}, + {"*est", "test", SUCCEEDS}, + {"*st", "test", SUCCEEDS}, + {"t*t", "test", SUCCEEDS}, + {"te*t", "test", SUCCEEDS}, + {"te*st", "test", SUCCEEDS}, + {"te*", "test", SUCCEEDS}, + {"tes*", "test", SUCCEEDS}, + {"test*", "test", SUCCEEDS}, + + {"test*?*[a-z]*", "testgoop", SUCCEEDS}, + {"te[^x]t", "test", SUCCEEDS}, + {"te[^abc]t", "test", SUCCEEDS}, + {"te[^x]t", "test", SUCCEEDS}, + {"te[!x]t", "test", SUCCEEDS}, + {"te[^x]t", "text", FAILS}, + {"te[^\\x]t", "text", FAILS}, + {"te[^x\\", "text", FAILS}, + {"te[/]t", "text", FAILS}, + {"te[S]t", "test", SUCCEEDS_IF(APR_FNM_CASE_BLIND)}, + {"te[r-t]t", "test", SUCCEEDS}, + {"te[r-t]t", "teSt", SUCCEEDS_IF(APR_FNM_CASE_BLIND)}, + {"te[r-T]t", "test", SUCCEEDS_IF(APR_FNM_CASE_BLIND)}, + {"te[R-T]t", "test", SUCCEEDS_IF(APR_FNM_CASE_BLIND)}, + {"te[r-Tz]t", "tezt", SUCCEEDS}, + {"te[R-T]t", "tent", FAILS}, + {"\\/test", "/test", FAILS_IF(APR_FNM_NOESCAPE)}, + {"tes[]t]", "test", SUCCEEDS}, + {"tes[t-]", "test", SUCCEEDS}, + {"tes[t-]]", "test]", SUCCEEDS}, + {"tes[t-]]", "test", FAILS}, + {"tes[u-]", "test", FAILS}, + {"tes[t-]", "tes[t-]", FAILS}, + {"test[/-/]", "test[/-/]", SUCCEEDS_IF(APR_FNM_PATHNAME)}, + {"test[\\/-/]", "test[/-/]", APR_FNM_PATHNAME, APR_FNM_NOESCAPE}, + {"test[/-\\/]", "test[/-/]", APR_FNM_PATHNAME, APR_FNM_NOESCAPE}, + {"test[/-/]", "test/", FAILS_IF(APR_FNM_PATHNAME)}, + {"test[\\/-/]", "test/", FAILS_IF(APR_FNM_PATHNAME)}, + {"test[/-\\/]", "test/", FAILS_IF(APR_FNM_PATHNAME)}, + + {"test/this", "test/", FAILS}, + {"test/", "test/this", FAILS}, + {"test*/this", "test/this", SUCCEEDS}, + {"test/*this", "test/this", SUCCEEDS}, + + {".*", ".this", SUCCEEDS}, + {"*", ".this", FAILS_IF(APR_FNM_PERIOD)}, + {"?this", ".this", FAILS_IF(APR_FNM_PERIOD)}, + {"[.]this", ".this", FAILS_IF(APR_FNM_PERIOD)}, + + {"test/this", "test/this", SUCCEEDS}, + {"test?this", "test/this", FAILS_IF(APR_FNM_PATHNAME)}, + {"test*this", "test/this", FAILS_IF(APR_FNM_PATHNAME)}, + {"test[/]this", "test/this", FAILS_IF(APR_FNM_PATHNAME)}, + + {"test/.*", "test/.this", SUCCEEDS}, + {"test/*", "test/.this", FAILS_IF(APR_FNM_PERIOD | APR_FNM_PATHNAME)}, + {"test/?this", "test/.this", FAILS_IF(APR_FNM_PERIOD | APR_FNM_PATHNAME)}, + {"test/[.]this", "test/.this", FAILS_IF(APR_FNM_PERIOD | APR_FNM_PATHNAME)}, + + {NULL, NULL, 0} +}; + + + +static void test_fnmatch(abts_case *tc, void *data) +{ + struct pattern_s *test = patterns; + char buf[80]; + int i = APR_FNM_BITS + 1; + int res; + + for (test = patterns; test->pattern; ++test) + { + for (i = 0; i <= APR_FNM_BITS; ++i) + { + res = apr_fnmatch(test->pattern, test->string, i); + if (((i & test->require_flags) != test->require_flags) + || ((i & test->fail_flags) == test->fail_flags)) { + if (res != APR_FNM_NOMATCH) + break; + } + else { + if (res != 0) + break; + } + } + if (i <= APR_FNM_BITS) + break; + } + + if (i <= APR_FNM_BITS) { + sprintf(buf, "apr_fnmatch(\"%s\", \"%s\", %d) returns %d\n", + test->pattern, test->string, i, res); + abts_fail(tc, buf, __LINE__); + } +} + +static void test_fnmatch_test(abts_case *tc, void *data) +{ + static const struct test { + const char *pattern; + int result; + } ft_tests[] = { + { "a*b", 1 }, + { "a?", 1 }, + { "a\\b?", 1 }, + { "a[b-c]", 1 }, + { "a", 0 }, + { "a\\", 0 }, + { NULL, 0 } + }; + const struct test *t; + + for (t = ft_tests; t->pattern != NULL; t++) { + int res = apr_fnmatch_test(t->pattern); + + if (res != t->result) { + char buf[128]; + + sprintf(buf, "apr_fnmatch_test(\"%s\") = %d, expected %d\n", + t->pattern, res, t->result); + abts_fail(tc, buf, __LINE__); + } + } +} + static void test_glob(abts_case *tc, void *data) { int i; @@ -68,6 +235,8 @@ abts_suite *testfnmatch(abts_suite *suit { suite = ADD_SUITE(suite) + abts_run_test(suite, test_fnmatch, NULL); + abts_run_test(suite, test_fnmatch_test, NULL); abts_run_test(suite, test_glob, NULL); abts_run_test(suite, test_glob_currdir, NULL);