Update tag value for tizen 2.0 build
[external/curl.git] / tests / libtest / lib577.c
1 /*****************************************************************************
2  *                                  _   _ ____  _
3  *  Project                     ___| | | |  _ \| |
4  *                             / __| | | | |_) | |
5  *                            | (__| |_| |  _ <| |___
6  *                             \___|\___/|_| \_\_____|
7  *
8  */
9
10 #include "test.h"
11
12 /*
13  * This hacky test bypasses the library external API,
14  * using internal only libcurl functions. So don't be
15  * surprised if we cannot run it when the library has
16  * been built with hidden symbols, exporting only the
17  * ones in the public API.
18  */
19
20 #if defined(CURL_HIDDEN_SYMBOLS)
21 #  define SKIP_TEST 1
22 #elif defined(WIN32) && !defined(CURL_STATICLIB)
23 #  define SKIP_TEST 1
24 #else
25 #  undef  SKIP_TEST
26 #endif
27
28
29 #if !defined(SKIP_TEST)
30
31 #include "memdebug.h"
32
33 #include "curl_fnmatch.h"
34
35 #define MATCH   CURL_FNMATCH_MATCH
36 #define NOMATCH CURL_FNMATCH_NOMATCH
37 #define RE_ERR  CURL_FNMATCH_FAIL
38
39 #define MAX_PATTERN_L 100
40 #define MAX_STRING_L  100
41
42 struct testcase {
43   char pattern[MAX_PATTERN_L];
44   char string[MAX_STRING_L];
45   int  result;
46 };
47
48 static const struct testcase tests[] = {
49   /* brackets syntax */
50   { "\\[",                      "[",                      MATCH },
51   { "[",                        "[",                      RE_ERR },
52   { "[]",                       "[]",                     RE_ERR },
53   { "[][]",                     "[",                      MATCH },
54   { "[][]",                     "]",                      MATCH },
55   { "[[]",                      "[",                      MATCH },
56   { "[[[]",                     "[",                      MATCH },
57   { "[[[[]",                    "[",                      MATCH },
58   { "[[[[]",                    "[",                      MATCH },
59
60   { "[][[]",                    "]",                      MATCH },
61   { "[][[[]",                   "[",                      MATCH },
62   { "[[]",                      "]",                      NOMATCH },
63
64   { "[a-z]",                    "a",                      MATCH },
65   { "[a-z]",                    "A",                      NOMATCH },
66   { "?[a-z]",                   "?Z",                     NOMATCH },
67   { "[A-Z]",                    "C",                      MATCH },
68   { "[A-Z]",                    "c",                      NOMATCH },
69   { "[0-9]",                    "7",                      MATCH },
70   { "[7-8]",                    "7",                      MATCH },
71   { "[7-]",                     "7",                      MATCH },
72   { "[7-]",                     "-",                      MATCH },
73   { "[7-]",                     "[",                      NOMATCH },
74   { "[a-bA-F]",                 "F",                      MATCH },
75   { "[a-bA-B9]",                "9",                      MATCH },
76   { "[a-bA-B98]",               "8",                      MATCH },
77   { "[a-bA-B98]",               "C",                      NOMATCH },
78   { "[a-bA-Z9]",                "F",                      MATCH },
79   { "[a-bA-Z9]ero*",            "Zero chance.",           MATCH },
80   { "S[a-][x]opho*",            "Saxophone",              MATCH },
81   { "S[a-][x]opho*",            "SaXophone",              NOMATCH },
82   { "S[a-][x]*.txt",            "S-x.txt",                MATCH },
83   { "[\\a-\\b]",                "a",                      MATCH },
84   { "[\\a-\\b]",                "b",                      MATCH },
85   { "[?*[][?*[][?*[]",          "?*[",                    MATCH },
86   { "[][?*-]",                  "]",                      MATCH },
87   { "[][?*-]",                  "[",                      MATCH },
88   { "[][?*-]",                  "?",                      MATCH },
89   { "[][?*-]",                  "*",                      MATCH },
90   { "[][?*-]",                  "-",                      MATCH },
91   { "[]?*-]",                   "-",                      MATCH },
92   { "?/b/c",                    "a/b/c",                  MATCH },
93   { "^_{}~",                    "^_{}~",                  MATCH },
94   { "!#%+,-./01234567889",      "!#%+,-./01234567889",    MATCH },
95   { "PQRSTUVWXYZ]abcdefg",      "PQRSTUVWXYZ]abcdefg",    MATCH },
96   { ":;=@ABCDEFGHIJKLMNO",      ":;=@ABCDEFGHIJKLMNO",    MATCH },
97
98   /* negate */
99   { "[!a]",                     "b",                      MATCH },
100   { "[!a]",                     "a",                      NOMATCH },
101   { "[^a]",                     "b",                      MATCH },
102   { "[^a]",                     "a",                      NOMATCH },
103   { "[^a-z0-9A-Z]",             "a",                      NOMATCH },
104   { "[^a-z0-9A-Z]",             "-",                      MATCH },
105   { "curl[!a-z]lib",            "curl lib",               MATCH },
106   { "curl[! ]lib",              "curl lib",               NOMATCH },
107   { "[! ][ ]",                  "  ",                     NOMATCH },
108   { "[! ][ ]",                  "a ",                     MATCH },
109   { "*[^a].t?t",                "a.txt",                  NOMATCH },
110   { "*[^a].t?t",                "ba.txt",                 NOMATCH },
111   { "*[^a].t?t",                "ab.txt",                 MATCH },
112   { "[!?*[]",                   "?",                      NOMATCH },
113   { "[!!]",                     "!",                      NOMATCH },
114   { "[!!]",                     "x",                      MATCH },
115
116   { "[[:alpha:]]",              "a",                      MATCH },
117   { "[[:alpha:]]",              "9",                      NOMATCH },
118   { "[[:alnum:]]",              "a",                      MATCH },
119   { "[[:alnum:]]",              "[",                      NOMATCH },
120   { "[[:alnum:]]",              "]",                      NOMATCH },
121   { "[[:alnum:]]",              "9",                      MATCH },
122   { "[[:digit:]]",              "9",                      MATCH },
123   { "[[:xdigit:]]",             "9",                      MATCH },
124   { "[[:xdigit:]]",             "F",                      MATCH },
125   { "[[:xdigit:]]",             "G",                      NOMATCH },
126   { "[[:upper:]]",              "U",                      MATCH },
127   { "[[:upper:]]",              "u",                      NOMATCH },
128   { "[[:lower:]]",              "l",                      MATCH },
129   { "[[:lower:]]",              "L",                      NOMATCH },
130   { "[[:print:]]",              "L",                      MATCH },
131   { "[[:print:]]",              {'\10'},                  NOMATCH },
132   { "[[:print:]]",              {'\10'},                  NOMATCH },
133   { "[[:space:]]",              " ",                      MATCH },
134   { "[[:space:]]",              "x",                      NOMATCH },
135   { "[[:graph:]]",              " ",                      NOMATCH },
136   { "[[:graph:]]",              "x",                      MATCH },
137   { "[[:blank:]]",              {'\t'},                   MATCH },
138   { "[[:blank:]]",              {' '},                    MATCH },
139   { "[[:blank:]]",              {'\r'},                   NOMATCH },
140   { "[^[:blank:]]",             {'\t'},                   NOMATCH },
141   { "[^[:print:]]",             {'\10'},                  MATCH },
142   { "[[:lower:]][[:lower:]]",   "ll",                     MATCH },
143
144   { "Curl[[:blank:]];-)",       "Curl ;-)",               MATCH },
145   { "*[[:blank:]]*",            " ",                      MATCH },
146   { "*[[:blank:]]*",            "",                       NOMATCH },
147   { "*[[:blank:]]*",            "hi, im_Pavel",           MATCH },
148
149   /* common using */
150   { "filename.dat",             "filename.dat",           MATCH },
151   { "*curl*",                   "lets use curl!!",        MATCH },
152   { "filename.txt",             "filename.dat",           NOMATCH },
153   { "*.txt",                    "text.txt",               MATCH },
154   { "*.txt",                    "a.txt",                  MATCH },
155   { "*.txt",                    ".txt",                   MATCH },
156   { "*.txt",                    "txt",                    NOMATCH },
157   { "??.txt",                   "99.txt",                 MATCH },
158   { "??.txt",                   "a99.txt",                NOMATCH },
159   { "?.???",                    "a.txt",                  MATCH },
160   { "*.???",                    "somefile.dat",           MATCH },
161   { "*.???",                    "photo.jpeg",             NOMATCH },
162   { ".*",                       ".htaccess",              MATCH },
163   { ".*",                       ".",                      MATCH },
164   { ".*",                       "..",                     MATCH },
165
166   /* many stars => one star */
167   { "**.txt",                   "text.txt",               MATCH },
168   { "***.txt",                  "t.txt",                  MATCH },
169   { "****.txt",                 ".txt",                   MATCH },
170
171   /* empty string or pattern */
172   { "",                         "",                       MATCH } ,
173   { "",                         "hello",                  NOMATCH },
174   { "file",                     "",                       NOMATCH  },
175   { "?",                        "",                       NOMATCH },
176   { "*",                        "",                       MATCH },
177   { "x",                        "",                       NOMATCH },
178
179   /* backslash */
180   { "\\",                       "\\",                     RE_ERR },
181   { "\\\\",                     "\\",                     MATCH },
182   { "\\\\",                     "\\\\",                   NOMATCH },
183   { "\\?",                      "?",                      MATCH },
184   { "\\*",                      "*",                      MATCH },
185   { "?.txt",                    "?.txt",                  MATCH },
186   { "*.txt",                    "*.txt",                  MATCH },
187   { "\\?.txt",                  "?.txt",                  MATCH },
188   { "\\*.txt",                  "*.txt",                  MATCH },
189   { "\\?.txt",                  "x.txt",                  NOMATCH },
190   { "\\*.txt",                  "x.txt",                  NOMATCH },
191   { "\\*\\\\.txt",              "*\\.txt",                MATCH },
192   { "*\\**\\?*\\\\*",           "cc*cc?cc\\cc*cc",        MATCH },
193   { "*\\**\\?*\\\\*",           "cc*cc?cccc",             NOMATCH },
194   { "*\\**\\?*\\\\*",           "cc*cc?cc\\cc*cc",        MATCH },
195   { "*\\?*\\**",                "cc?c*c",                 MATCH },
196   { "*\\?*\\**curl*",           "cc?c*curl",              MATCH },
197   { "*\\?*\\**",                "cc?cc",                  NOMATCH },
198   { "\\\"\\$\\&\\'\\(\\)",      "\"$&'()",                MATCH },
199   { "\\*\\?\\[\\\\\\`\\|",      "*?[\\`|",                MATCH },
200   { "[\\a\\b]c",                "ac",                     MATCH },
201   { "[\\a\\b]c",                "bc",                     MATCH },
202   { "[\\a\\b]d",                "bc",                     NOMATCH },
203   { "[a-bA-B\\?]",              "?",                      MATCH },
204   { "cu[a-ab-b\\r]l",           "curl",                   MATCH },
205   { "[\\a-z]",                  "c",                      MATCH },
206
207   { "?*?*?.*?*",                "abc.c",                  MATCH },
208   { "?*?*?.*?*",                "abcc",                   NOMATCH },
209   { "?*?*?.*?*",                "abc.",                   NOMATCH },
210   { "?*?*?.*?*",                "abc.c++",                MATCH },
211   { "?*?*?.*?*",                "abcdef.c++",             MATCH },
212   { "?*?*?.?",                  "abcdef.c",               MATCH },
213   { "?*?*?.?",                  "abcdef.cd",              NOMATCH },
214
215   { "Lindmätarv",               "Lindmätarv",             MATCH },
216
217   { "",                         "",                       MATCH }
218 };
219
220
221 int test(char *URL)
222 {
223   int testnum = sizeof(tests) / sizeof(struct testcase);
224   int i, rc;
225   (void)URL; /* not used */
226
227   if(!strcmp(URL, "check")) {
228     /* test harness script verifying if this test can run */
229     return 0; /* sure, run this! */
230   }
231
232   printf("===========================\n");
233   for(i = 0; i < testnum; i++) {
234     rc = Curl_fnmatch(NULL, tests[i].pattern, tests[i].string);
235     if(rc != tests[i].result) {
236       printf("Curl_fnmatch(\"%s\", \"%s\") should return %d (returns %d)\n",
237              tests[i].pattern, tests[i].string, tests[i].result, rc);
238     }
239   }
240   printf("===========================\n");
241   return 0;
242 }
243
244 #else /* !defined(SKIP_TEST) */
245
246
247 int test(char *URL)
248 {
249   (void)URL;
250   fprintf(stdout, "libcurl built with hidden symbols");
251   return 1; /* skip test */
252 }
253
254
255 #endif /* !defined(SKIP_TEST) */