unit1307.c
Go to the documentation of this file.
00001 /***************************************************************************
00002  *                                  _   _ ____  _
00003  *  Project                     ___| | | |  _ \| |
00004  *                             / __| | | | |_) | |
00005  *                            | (__| |_| |  _ <| |___
00006  *                             \___|\___/|_| \_\_____|
00007  *
00008  * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
00009  *
00010  * This software is licensed as described in the file COPYING, which
00011  * you should have received as part of this distribution. The terms
00012  * are also available at https://curl.haxx.se/docs/copyright.html.
00013  *
00014  * You may opt to use, copy, modify, merge, publish, distribute and/or sell
00015  * copies of the Software, and permit persons to whom the Software is
00016  * furnished to do so, under the terms of the COPYING file.
00017  *
00018  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
00019  * KIND, either express or implied.
00020  *
00021  ***************************************************************************/
00022 #include "curlcheck.h"
00023 
00024 #include "curl_fnmatch.h"
00025 
00026 #define MATCH   CURL_FNMATCH_MATCH
00027 #define NOMATCH CURL_FNMATCH_NOMATCH
00028 #define RE_ERR  CURL_FNMATCH_FAIL
00029 
00030 #define MAX_PATTERN_L 100
00031 #define MAX_STRING_L  100
00032 
00033 struct testcase {
00034   char pattern[MAX_PATTERN_L];
00035   char string[MAX_STRING_L];
00036   int  result;
00037 };
00038 
00039 static const struct testcase tests[] = {
00040   /* brackets syntax */
00041   { "\\[",                      "[",                      MATCH },
00042   { "[",                        "[",                      RE_ERR },
00043   { "[]",                       "[]",                     RE_ERR },
00044   { "[][]",                     "[",                      MATCH },
00045   { "[][]",                     "]",                      MATCH },
00046   { "[[]",                      "[",                      MATCH },
00047   { "[[[]",                     "[",                      MATCH },
00048   { "[[[[]",                    "[",                      MATCH },
00049   { "[[[[]",                    "[",                      MATCH },
00050 
00051   { "[][[]",                    "]",                      MATCH },
00052   { "[][[[]",                   "[",                      MATCH },
00053   { "[[]",                      "]",                      NOMATCH },
00054 
00055   { "[a-z]",                    "a",                      MATCH },
00056   { "[a-z]",                    "A",                      NOMATCH },
00057   { "?[a-z]",                   "?Z",                     NOMATCH },
00058   { "[A-Z]",                    "C",                      MATCH },
00059   { "[A-Z]",                    "c",                      NOMATCH },
00060   { "[0-9]",                    "7",                      MATCH },
00061   { "[7-8]",                    "7",                      MATCH },
00062   { "[7-]",                     "7",                      MATCH },
00063   { "[7-]",                     "-",                      MATCH },
00064   { "[7-]",                     "[",                      NOMATCH },
00065   { "[a-bA-F]",                 "F",                      MATCH },
00066   { "[a-bA-B9]",                "9",                      MATCH },
00067   { "[a-bA-B98]",               "8",                      MATCH },
00068   { "[a-bA-B98]",               "C",                      NOMATCH },
00069   { "[a-bA-Z9]",                "F",                      MATCH },
00070   { "[a-bA-Z9]ero*",            "Zero chance.",           MATCH },
00071   { "S[a-][x]opho*",            "Saxophone",              MATCH },
00072   { "S[a-][x]opho*",            "SaXophone",              NOMATCH },
00073   { "S[a-][x]*.txt",            "S-x.txt",                MATCH },
00074   { "[\\a-\\b]",                "a",                      MATCH },
00075   { "[\\a-\\b]",                "b",                      MATCH },
00076   { "[?*[][?*[][?*[]",          "?*[",                    MATCH },
00077   { "[][?*-]",                  "]",                      MATCH },
00078   { "[][?*-]",                  "[",                      MATCH },
00079   { "[][?*-]",                  "?",                      MATCH },
00080   { "[][?*-]",                  "*",                      MATCH },
00081   { "[][?*-]",                  "-",                      MATCH },
00082   { "[]?*-]",                   "-",                      MATCH },
00083   { "?/b/c",                    "a/b/c",                  MATCH },
00084   { "^_{}~",                    "^_{}~",                  MATCH },
00085   { "!#%+,-./01234567889",      "!#%+,-./01234567889",    MATCH },
00086   { "PQRSTUVWXYZ]abcdefg",      "PQRSTUVWXYZ]abcdefg",    MATCH },
00087   { ":;=@ABCDEFGHIJKLMNO",      ":;=@ABCDEFGHIJKLMNO",    MATCH },
00088 
00089   /* negate */
00090   { "[!a]",                     "b",                      MATCH },
00091   { "[!a]",                     "a",                      NOMATCH },
00092   { "[^a]",                     "b",                      MATCH },
00093   { "[^a]",                     "a",                      NOMATCH },
00094   { "[^a-z0-9A-Z]",             "a",                      NOMATCH },
00095   { "[^a-z0-9A-Z]",             "-",                      MATCH },
00096   { "curl[!a-z]lib",            "curl lib",               MATCH },
00097   { "curl[! ]lib",              "curl lib",               NOMATCH },
00098   { "[! ][ ]",                  "  ",                     NOMATCH },
00099   { "[! ][ ]",                  "a ",                     MATCH },
00100   { "*[^a].t?t",                "a.txt",                  NOMATCH },
00101   { "*[^a].t?t",                "ba.txt",                 NOMATCH },
00102   { "*[^a].t?t",                "ab.txt",                 MATCH },
00103   { "[!?*[]",                   "?",                      NOMATCH },
00104   { "[!!]",                     "!",                      NOMATCH },
00105   { "[!!]",                     "x",                      MATCH },
00106 
00107   { "[[:alpha:]]",              "a",                      MATCH },
00108   { "[[:alpha:]]",              "9",                      NOMATCH },
00109   { "[[:alnum:]]",              "a",                      MATCH },
00110   { "[[:alnum:]]",              "[",                      NOMATCH },
00111   { "[[:alnum:]]",              "]",                      NOMATCH },
00112   { "[[:alnum:]]",              "9",                      MATCH },
00113   { "[[:digit:]]",              "9",                      MATCH },
00114   { "[[:xdigit:]]",             "9",                      MATCH },
00115   { "[[:xdigit:]]",             "F",                      MATCH },
00116   { "[[:xdigit:]]",             "G",                      NOMATCH },
00117   { "[[:upper:]]",              "U",                      MATCH },
00118   { "[[:upper:]]",              "u",                      NOMATCH },
00119   { "[[:lower:]]",              "l",                      MATCH },
00120   { "[[:lower:]]",              "L",                      NOMATCH },
00121   { "[[:print:]]",              "L",                      MATCH },
00122   { "[[:print:]]",              {'\10'},                  NOMATCH },
00123   { "[[:print:]]",              {'\10'},                  NOMATCH },
00124   { "[[:space:]]",              " ",                      MATCH },
00125   { "[[:space:]]",              "x",                      NOMATCH },
00126   { "[[:graph:]]",              " ",                      NOMATCH },
00127   { "[[:graph:]]",              "x",                      MATCH },
00128   { "[[:blank:]]",              {'\t'},                   MATCH },
00129   { "[[:blank:]]",              {' '},                    MATCH },
00130   { "[[:blank:]]",              {'\r'},                   NOMATCH },
00131   { "[^[:blank:]]",             {'\t'},                   NOMATCH },
00132   { "[^[:print:]]",             {'\10'},                  MATCH },
00133   { "[[:lower:]][[:lower:]]",   "ll",                     MATCH },
00134 
00135   { "Curl[[:blank:]];-)",       "Curl ;-)",               MATCH },
00136   { "*[[:blank:]]*",            " ",                      MATCH },
00137   { "*[[:blank:]]*",            "",                       NOMATCH },
00138   { "*[[:blank:]]*",            "hi, im_Pavel",           MATCH },
00139 
00140   /* common using */
00141   { "filename.dat",             "filename.dat",           MATCH },
00142   { "*curl*",                   "lets use curl!!",        MATCH },
00143   { "filename.txt",             "filename.dat",           NOMATCH },
00144   { "*.txt",                    "text.txt",               MATCH },
00145   { "*.txt",                    "a.txt",                  MATCH },
00146   { "*.txt",                    ".txt",                   MATCH },
00147   { "*.txt",                    "txt",                    NOMATCH },
00148   { "??.txt",                   "99.txt",                 MATCH },
00149   { "??.txt",                   "a99.txt",                NOMATCH },
00150   { "?.???",                    "a.txt",                  MATCH },
00151   { "*.???",                    "somefile.dat",           MATCH },
00152   { "*.???",                    "photo.jpeg",             NOMATCH },
00153   { ".*",                       ".htaccess",              MATCH },
00154   { ".*",                       ".",                      MATCH },
00155   { ".*",                       "..",                     MATCH },
00156 
00157   /* many stars => one star */
00158   { "**.txt",                   "text.txt",               MATCH },
00159   { "***.txt",                  "t.txt",                  MATCH },
00160   { "****.txt",                 ".txt",                   MATCH },
00161 
00162   /* empty string or pattern */
00163   { "",                         "",                       MATCH },
00164   { "",                         "hello",                  NOMATCH },
00165   { "file",                     "",                       NOMATCH  },
00166   { "?",                        "",                       NOMATCH },
00167   { "*",                        "",                       MATCH },
00168   { "x",                        "",                       NOMATCH },
00169 
00170   /* backslash */
00171   { "\\",                       "\\",                     RE_ERR },
00172   { "\\\\",                     "\\",                     MATCH },
00173   { "\\\\",                     "\\\\",                   NOMATCH },
00174   { "\\?",                      "?",                      MATCH },
00175   { "\\*",                      "*",                      MATCH },
00176   { "?.txt",                    "?.txt",                  MATCH },
00177   { "*.txt",                    "*.txt",                  MATCH },
00178   { "\\?.txt",                  "?.txt",                  MATCH },
00179   { "\\*.txt",                  "*.txt",                  MATCH },
00180   { "\\?.txt",                  "x.txt",                  NOMATCH },
00181   { "\\*.txt",                  "x.txt",                  NOMATCH },
00182   { "\\*\\\\.txt",              "*\\.txt",                MATCH },
00183   { "*\\**\\?*\\\\*",           "cc*cc?cc\\cc*cc",        MATCH },
00184   { "*\\**\\?*\\\\*",           "cc*cc?cccc",             NOMATCH },
00185   { "*\\**\\?*\\\\*",           "cc*cc?cc\\cc*cc",        MATCH },
00186   { "*\\?*\\**",                "cc?c*c",                 MATCH },
00187   { "*\\?*\\**curl*",           "cc?c*curl",              MATCH },
00188   { "*\\?*\\**",                "cc?cc",                  NOMATCH },
00189   { "\\\"\\$\\&\\'\\(\\)",      "\"$&'()",                MATCH },
00190   { "\\*\\?\\[\\\\\\`\\|",      "*?[\\`|",                MATCH },
00191   { "[\\a\\b]c",                "ac",                     MATCH },
00192   { "[\\a\\b]c",                "bc",                     MATCH },
00193   { "[\\a\\b]d",                "bc",                     NOMATCH },
00194   { "[a-bA-B\\?]",              "?",                      MATCH },
00195   { "cu[a-ab-b\\r]l",           "curl",                   MATCH },
00196   { "[\\a-z]",                  "c",                      MATCH },
00197 
00198   { "?*?*?.*?*",                "abc.c",                  MATCH },
00199   { "?*?*?.*?*",                "abcc",                   NOMATCH },
00200   { "?*?*?.*?*",                "abc.",                   NOMATCH },
00201   { "?*?*?.*?*",                "abc.c++",                MATCH },
00202   { "?*?*?.*?*",                "abcdef.c++",             MATCH },
00203   { "?*?*?.?",                  "abcdef.c",               MATCH },
00204   { "?*?*?.?",                  "abcdef.cd",              NOMATCH },
00205 
00206   { "Lindmätarv",               "Lindmätarv",             MATCH },
00207 
00208   { "",                         "",                       MATCH }
00209 };
00210 
00211 static CURLcode unit_setup(void)
00212 {
00213   return CURLE_OK;
00214 }
00215 
00216 static void unit_stop(void)
00217 {
00218 }
00219 
00220 UNITTEST_START
00221 
00222   int testnum = sizeof(tests) / sizeof(struct testcase);
00223   int i, rc;
00224 
00225   for(i = 0; i < testnum; i++) {
00226     rc = Curl_fnmatch(NULL, tests[i].pattern, tests[i].string);
00227     if(rc != tests[i].result) {
00228       printf("Curl_fnmatch(\"%s\", \"%s\") should return %d (returns %d)\n",
00229              tests[i].pattern, tests[i].string, tests[i].result, rc);
00230       fail("pattern mismatch");
00231     }
00232   }
00233 
00234 UNITTEST_STOP


rc_visard_driver
Author(s): Heiko Hirschmueller , Christian Emmerich , Felix Ruess
autogenerated on Thu Jun 6 2019 20:43:07