2011-03-10 18:48:02 +08:00
|
|
|
/***************************************************************************
|
2010-05-12 21:33:22 +08:00
|
|
|
* _ _ ____ _
|
|
|
|
* Project ___| | | | _ \| |
|
|
|
|
* / __| | | | |_) | |
|
|
|
|
* | (__| |_| | _ <| |___
|
|
|
|
* \___|\___/|_| \_\_____|
|
|
|
|
*
|
2011-03-10 18:48:02 +08:00
|
|
|
* Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
|
|
|
|
*
|
|
|
|
* This software is licensed as described in the file COPYING, which
|
|
|
|
* you should have received as part of this distribution. The terms
|
|
|
|
* are also available at http://curl.haxx.se/docs/copyright.html.
|
|
|
|
*
|
|
|
|
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
|
|
|
* copies of the Software, and permit persons to whom the Software is
|
|
|
|
* furnished to do so, under the terms of the COPYING file.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
***************************************************************************/
|
2011-03-05 07:56:40 +08:00
|
|
|
#include "curlcheck.h"
|
2010-05-12 21:33:22 +08:00
|
|
|
|
2011-05-21 19:22:11 +08:00
|
|
|
#include "curl_fnmatch.h"
|
|
|
|
|
2010-05-12 21:33:22 +08:00
|
|
|
#define MATCH CURL_FNMATCH_MATCH
|
|
|
|
#define NOMATCH CURL_FNMATCH_NOMATCH
|
2010-05-28 06:50:11 +08:00
|
|
|
#define RE_ERR CURL_FNMATCH_FAIL
|
2010-05-12 21:33:22 +08:00
|
|
|
|
|
|
|
#define MAX_PATTERN_L 100
|
|
|
|
#define MAX_STRING_L 100
|
|
|
|
|
|
|
|
struct testcase {
|
|
|
|
char pattern[MAX_PATTERN_L];
|
|
|
|
char string[MAX_STRING_L];
|
|
|
|
int result;
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct testcase tests[] = {
|
|
|
|
/* brackets syntax */
|
|
|
|
{ "\\[", "[", MATCH },
|
2010-05-28 06:50:11 +08:00
|
|
|
{ "[", "[", RE_ERR },
|
|
|
|
{ "[]", "[]", RE_ERR },
|
2010-05-12 21:33:22 +08:00
|
|
|
{ "[][]", "[", MATCH },
|
|
|
|
{ "[][]", "]", MATCH },
|
|
|
|
{ "[[]", "[", MATCH },
|
|
|
|
{ "[[[]", "[", MATCH },
|
|
|
|
{ "[[[[]", "[", MATCH },
|
|
|
|
{ "[[[[]", "[", MATCH },
|
|
|
|
|
|
|
|
{ "[][[]", "]", MATCH },
|
|
|
|
{ "[][[[]", "[", MATCH },
|
|
|
|
{ "[[]", "]", NOMATCH },
|
|
|
|
|
|
|
|
{ "[a-z]", "a", MATCH },
|
|
|
|
{ "[a-z]", "A", NOMATCH },
|
|
|
|
{ "?[a-z]", "?Z", NOMATCH },
|
|
|
|
{ "[A-Z]", "C", MATCH },
|
|
|
|
{ "[A-Z]", "c", NOMATCH },
|
|
|
|
{ "[0-9]", "7", MATCH },
|
|
|
|
{ "[7-8]", "7", MATCH },
|
|
|
|
{ "[7-]", "7", MATCH },
|
|
|
|
{ "[7-]", "-", MATCH },
|
|
|
|
{ "[7-]", "[", NOMATCH },
|
|
|
|
{ "[a-bA-F]", "F", MATCH },
|
|
|
|
{ "[a-bA-B9]", "9", MATCH },
|
|
|
|
{ "[a-bA-B98]", "8", MATCH },
|
|
|
|
{ "[a-bA-B98]", "C", NOMATCH },
|
|
|
|
{ "[a-bA-Z9]", "F", MATCH },
|
|
|
|
{ "[a-bA-Z9]ero*", "Zero chance.", MATCH },
|
|
|
|
{ "S[a-][x]opho*", "Saxophone", MATCH },
|
|
|
|
{ "S[a-][x]opho*", "SaXophone", NOMATCH },
|
|
|
|
{ "S[a-][x]*.txt", "S-x.txt", MATCH },
|
|
|
|
{ "[\\a-\\b]", "a", MATCH },
|
|
|
|
{ "[\\a-\\b]", "b", MATCH },
|
|
|
|
{ "[?*[][?*[][?*[]", "?*[", MATCH },
|
|
|
|
{ "[][?*-]", "]", MATCH },
|
|
|
|
{ "[][?*-]", "[", MATCH },
|
|
|
|
{ "[][?*-]", "?", MATCH },
|
|
|
|
{ "[][?*-]", "*", MATCH },
|
|
|
|
{ "[][?*-]", "-", MATCH },
|
|
|
|
{ "[]?*-]", "-", MATCH },
|
|
|
|
{ "?/b/c", "a/b/c", MATCH },
|
|
|
|
{ "^_{}~", "^_{}~", MATCH },
|
|
|
|
{ "!#%+,-./01234567889", "!#%+,-./01234567889", MATCH },
|
|
|
|
{ "PQRSTUVWXYZ]abcdefg", "PQRSTUVWXYZ]abcdefg", MATCH },
|
|
|
|
{ ":;=@ABCDEFGHIJKLMNO", ":;=@ABCDEFGHIJKLMNO", MATCH },
|
|
|
|
|
|
|
|
/* negate */
|
|
|
|
{ "[!a]", "b", MATCH },
|
|
|
|
{ "[!a]", "a", NOMATCH },
|
|
|
|
{ "[^a]", "b", MATCH },
|
|
|
|
{ "[^a]", "a", NOMATCH },
|
|
|
|
{ "[^a-z0-9A-Z]", "a", NOMATCH },
|
|
|
|
{ "[^a-z0-9A-Z]", "-", MATCH },
|
|
|
|
{ "curl[!a-z]lib", "curl lib", MATCH },
|
|
|
|
{ "curl[! ]lib", "curl lib", NOMATCH },
|
|
|
|
{ "[! ][ ]", " ", NOMATCH },
|
|
|
|
{ "[! ][ ]", "a ", MATCH },
|
|
|
|
{ "*[^a].t?t", "a.txt", NOMATCH },
|
|
|
|
{ "*[^a].t?t", "ba.txt", NOMATCH },
|
|
|
|
{ "*[^a].t?t", "ab.txt", MATCH },
|
|
|
|
{ "[!?*[]", "?", NOMATCH },
|
|
|
|
{ "[!!]", "!", NOMATCH },
|
|
|
|
{ "[!!]", "x", MATCH },
|
|
|
|
|
|
|
|
{ "[[:alpha:]]", "a", MATCH },
|
|
|
|
{ "[[:alpha:]]", "9", NOMATCH },
|
|
|
|
{ "[[:alnum:]]", "a", MATCH },
|
|
|
|
{ "[[:alnum:]]", "[", NOMATCH },
|
|
|
|
{ "[[:alnum:]]", "]", NOMATCH },
|
|
|
|
{ "[[:alnum:]]", "9", MATCH },
|
|
|
|
{ "[[:digit:]]", "9", MATCH },
|
|
|
|
{ "[[:xdigit:]]", "9", MATCH },
|
|
|
|
{ "[[:xdigit:]]", "F", MATCH },
|
|
|
|
{ "[[:xdigit:]]", "G", NOMATCH },
|
|
|
|
{ "[[:upper:]]", "U", MATCH },
|
|
|
|
{ "[[:upper:]]", "u", NOMATCH },
|
|
|
|
{ "[[:lower:]]", "l", MATCH },
|
|
|
|
{ "[[:lower:]]", "L", NOMATCH },
|
|
|
|
{ "[[:print:]]", "L", MATCH },
|
|
|
|
{ "[[:print:]]", {'\10'}, NOMATCH },
|
|
|
|
{ "[[:print:]]", {'\10'}, NOMATCH },
|
|
|
|
{ "[[:space:]]", " ", MATCH },
|
|
|
|
{ "[[:space:]]", "x", NOMATCH },
|
|
|
|
{ "[[:graph:]]", " ", NOMATCH },
|
|
|
|
{ "[[:graph:]]", "x", MATCH },
|
|
|
|
{ "[[:blank:]]", {'\t'}, MATCH },
|
|
|
|
{ "[[:blank:]]", {' '}, MATCH },
|
|
|
|
{ "[[:blank:]]", {'\r'}, NOMATCH },
|
|
|
|
{ "[^[:blank:]]", {'\t'}, NOMATCH },
|
|
|
|
{ "[^[:print:]]", {'\10'}, MATCH },
|
|
|
|
{ "[[:lower:]][[:lower:]]", "ll", MATCH },
|
|
|
|
|
|
|
|
{ "Curl[[:blank:]];-)", "Curl ;-)", MATCH },
|
|
|
|
{ "*[[:blank:]]*", " ", MATCH },
|
|
|
|
{ "*[[:blank:]]*", "", NOMATCH },
|
|
|
|
{ "*[[:blank:]]*", "hi, im_Pavel", MATCH },
|
|
|
|
|
|
|
|
/* common using */
|
|
|
|
{ "filename.dat", "filename.dat", MATCH },
|
|
|
|
{ "*curl*", "lets use curl!!", MATCH },
|
|
|
|
{ "filename.txt", "filename.dat", NOMATCH },
|
|
|
|
{ "*.txt", "text.txt", MATCH },
|
|
|
|
{ "*.txt", "a.txt", MATCH },
|
|
|
|
{ "*.txt", ".txt", MATCH },
|
|
|
|
{ "*.txt", "txt", NOMATCH },
|
|
|
|
{ "??.txt", "99.txt", MATCH },
|
|
|
|
{ "??.txt", "a99.txt", NOMATCH },
|
|
|
|
{ "?.???", "a.txt", MATCH },
|
|
|
|
{ "*.???", "somefile.dat", MATCH },
|
|
|
|
{ "*.???", "photo.jpeg", NOMATCH },
|
|
|
|
{ ".*", ".htaccess", MATCH },
|
|
|
|
{ ".*", ".", MATCH },
|
|
|
|
{ ".*", "..", MATCH },
|
|
|
|
|
|
|
|
/* many stars => one star */
|
|
|
|
{ "**.txt", "text.txt", MATCH },
|
|
|
|
{ "***.txt", "t.txt", MATCH },
|
|
|
|
{ "****.txt", ".txt", MATCH },
|
|
|
|
|
|
|
|
/* empty string or pattern */
|
|
|
|
{ "", "", MATCH } ,
|
|
|
|
{ "", "hello", NOMATCH },
|
|
|
|
{ "file", "", NOMATCH },
|
|
|
|
{ "?", "", NOMATCH },
|
|
|
|
{ "*", "", MATCH },
|
|
|
|
{ "x", "", NOMATCH },
|
|
|
|
|
|
|
|
/* backslash */
|
2010-05-28 06:50:11 +08:00
|
|
|
{ "\\", "\\", RE_ERR },
|
2010-05-12 21:33:22 +08:00
|
|
|
{ "\\\\", "\\", MATCH },
|
|
|
|
{ "\\\\", "\\\\", NOMATCH },
|
|
|
|
{ "\\?", "?", MATCH },
|
|
|
|
{ "\\*", "*", MATCH },
|
|
|
|
{ "?.txt", "?.txt", MATCH },
|
|
|
|
{ "*.txt", "*.txt", MATCH },
|
|
|
|
{ "\\?.txt", "?.txt", MATCH },
|
|
|
|
{ "\\*.txt", "*.txt", MATCH },
|
|
|
|
{ "\\?.txt", "x.txt", NOMATCH },
|
|
|
|
{ "\\*.txt", "x.txt", NOMATCH },
|
|
|
|
{ "\\*\\\\.txt", "*\\.txt", MATCH },
|
|
|
|
{ "*\\**\\?*\\\\*", "cc*cc?cc\\cc*cc", MATCH },
|
|
|
|
{ "*\\**\\?*\\\\*", "cc*cc?cccc", NOMATCH },
|
|
|
|
{ "*\\**\\?*\\\\*", "cc*cc?cc\\cc*cc", MATCH },
|
|
|
|
{ "*\\?*\\**", "cc?c*c", MATCH },
|
|
|
|
{ "*\\?*\\**curl*", "cc?c*curl", MATCH },
|
|
|
|
{ "*\\?*\\**", "cc?cc", NOMATCH },
|
|
|
|
{ "\\\"\\$\\&\\'\\(\\)", "\"$&'()", MATCH },
|
|
|
|
{ "\\*\\?\\[\\\\\\`\\|", "*?[\\`|", MATCH },
|
|
|
|
{ "[\\a\\b]c", "ac", MATCH },
|
|
|
|
{ "[\\a\\b]c", "bc", MATCH },
|
|
|
|
{ "[\\a\\b]d", "bc", NOMATCH },
|
|
|
|
{ "[a-bA-B\\?]", "?", MATCH },
|
|
|
|
{ "cu[a-ab-b\\r]l", "curl", MATCH },
|
|
|
|
{ "[\\a-z]", "c", MATCH },
|
|
|
|
|
|
|
|
{ "?*?*?.*?*", "abc.c", MATCH },
|
|
|
|
{ "?*?*?.*?*", "abcc", NOMATCH },
|
|
|
|
{ "?*?*?.*?*", "abc.", NOMATCH },
|
|
|
|
{ "?*?*?.*?*", "abc.c++", MATCH },
|
|
|
|
{ "?*?*?.*?*", "abcdef.c++", MATCH },
|
|
|
|
{ "?*?*?.?", "abcdef.c", MATCH },
|
|
|
|
{ "?*?*?.?", "abcdef.cd", NOMATCH },
|
|
|
|
|
|
|
|
{ "Lindmätarv", "Lindmätarv", MATCH },
|
|
|
|
|
|
|
|
{ "", "", MATCH }
|
|
|
|
};
|
|
|
|
|
2011-03-05 07:56:40 +08:00
|
|
|
static CURLcode unit_setup( void )
|
|
|
|
{
|
|
|
|
return CURLE_OK;
|
|
|
|
}
|
2010-05-12 21:33:22 +08:00
|
|
|
|
2011-03-05 07:56:40 +08:00
|
|
|
static void unit_stop( void )
|
2010-05-12 21:33:22 +08:00
|
|
|
{
|
2011-03-05 07:56:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
UNITTEST_START
|
|
|
|
|
2010-05-12 21:33:22 +08:00
|
|
|
int testnum = sizeof(tests) / sizeof(struct testcase);
|
|
|
|
int i, rc;
|
2010-05-15 05:42:58 +08:00
|
|
|
|
2010-05-12 21:33:22 +08:00
|
|
|
for(i = 0; i < testnum; i++) {
|
2010-05-16 08:49:08 +08:00
|
|
|
rc = Curl_fnmatch(NULL, tests[i].pattern, tests[i].string);
|
2010-05-12 21:33:22 +08:00
|
|
|
if(rc != tests[i].result) {
|
|
|
|
printf("Curl_fnmatch(\"%s\", \"%s\") should return %d (returns %d)\n",
|
|
|
|
tests[i].pattern, tests[i].string, tests[i].result, rc);
|
2011-03-05 07:56:40 +08:00
|
|
|
fail("pattern mismatch");
|
2010-05-12 21:33:22 +08:00
|
|
|
}
|
|
|
|
}
|
2010-05-15 05:42:58 +08:00
|
|
|
|
2011-03-05 07:56:40 +08:00
|
|
|
UNITTEST_STOP
|