2
* Copyright (c) 2009 Michihiro NAKAJIMA
5
* Redistribution and use in source and binary forms, with or without
6
* modification, are permitted provided that the following conditions
8
* 1. Redistributions of source code must retain the above copyright
9
* notice, this list of conditions and the following disclaimer.
10
* 2. Redistributions in binary form must reproduce the above copyright
11
* notice, this list of conditions and the following disclaimer in the
12
* documentation and/or other materials provided with the distribution.
14
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
15
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17
* IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
18
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
#if defined(_WIN32) && !defined(__CYGWIN__)
31
mkfile(const char *name)
35
f = fopen(name, "wb");
37
assertEqualInt(5, fwrite("01234", 1, 5, f));
42
mkfullpath(char **path1, char **path2, const char *tpath, int type)
44
char *fp1 = NULL, *fp2 = NULL, *p1 = NULL, *p2 = NULL;
48
* Get full path name of "tpath"
50
l = GetFullPathNameA(tpath, 0, NULL, NULL);
56
l = GetFullPathNameA(tpath, l, fp1, NULL);
57
if ((type & 0x01) == 0) {
58
for (p1 = fp1; *p1 != '\0'; p1++)
64
case 0: /* start with "/" */
65
case 1: /* start with "\" */
67
memmove(fp1, fp1 + 2, l - 2);
71
case 2: /* start with "c:/" */
72
case 3: /* start with "c:\" */
75
case 4: /* start with "//./c:/" */
76
case 5: /* start with "\\.\c:\" */
77
case 6: /* start with "//?/c:/" */
78
case 7: /* start with "\\?\c:\" */
79
p1 = malloc(l + 4 + 1);
82
memcpy(p1, "\\\\.\\", 4);
84
memcpy(p1, "//./", 4);
85
if (type == 6 || type == 7)
87
memcpy(p1 + 4, fp1, l);
96
* Strip leading drive names and converting "\" to "\\"
115
static const char *list1[] = {"aaa/", "aaa/file1", "aaa/xxa/", "aaa/xxb/",
116
"aaa/zzc/", "aaa/zzc/file1", "aaa/xxb/file1", "aaa/xxa/file1",
117
"aab/", "aac/", "abb/", "abc/", "abd/", NULL};
118
static const char *list2[] = {"bbb/", "bbb/file1", "bbb/xxa/", "bbb/xxb/",
119
"bbb/zzc/", "bbb/zzc/file1", "bbb/xxb/file1", "bbb/xxa/file1", "bbc/",
120
"bbd/", "bcc/", "bcd/", "bce/", NULL};
121
static const char *list3[] = {"aac/", "abc/", "bbc/", "bcc/", "ccc/", NULL};
122
static const char *list4[] = {"fff/abca", "fff/acca", NULL};
123
static const char *list5[] = {"aaa/file1", "aaa/xxa/", "aaa/xxa/file1",
124
"aaa/xxb/", "aaa/xxb/file1", "aaa/zzc/", "aaa/zzc/file1", NULL};
125
static const char *list6[] = {"fff/abca", "fff/acca", "aaa/xxa/",
126
"aaa/xxa/file1", "aaa/xxb/", "aaa/xxb/file1", NULL};
127
#endif /* _WIN32 && !__CYGWIN__ */
129
DEFINE_TEST(test_windows)
131
#if defined(_WIN32) && !defined(__CYGWIN__)
136
* Create directories and files.
138
assertMakeDir("tmp", 0775);
141
assertMakeDir("aaa", 0775);
142
assertMakeDir("aaa/xxa", 0775);
143
assertMakeDir("aaa/xxb", 0775);
144
assertMakeDir("aaa/zzc", 0775);
146
mkfile("aaa/xxa/file1");
147
mkfile("aaa/xxb/file1");
148
mkfile("aaa/zzc/file1");
149
assertMakeDir("aab", 0775);
150
assertMakeDir("aac", 0775);
151
assertMakeDir("abb", 0775);
152
assertMakeDir("abc", 0775);
153
assertMakeDir("abd", 0775);
154
assertMakeDir("bbb", 0775);
155
assertMakeDir("bbb/xxa", 0775);
156
assertMakeDir("bbb/xxb", 0775);
157
assertMakeDir("bbb/zzc", 0775);
159
mkfile("bbb/xxa/file1");
160
mkfile("bbb/xxb/file1");
161
mkfile("bbb/zzc/file1");
162
assertMakeDir("bbc", 0775);
163
assertMakeDir("bbd", 0775);
164
assertMakeDir("bcc", 0775);
165
assertMakeDir("bcd", 0775);
166
assertEqualInt(0, _mkdir("bce"));
167
assertEqualInt(0, _mkdir("ccc"));
168
assertEqualInt(0, _mkdir("fff"));
176
* Test1: Command line pattern matching.
179
systemf("%s -cf ../archive1.tar a*", testprog));
181
systemf("%s -tf ../archive1.tar > ../list1", testprog));
182
assertFileContainsLinesAnyOrder("../list1", list1);
185
systemf("%s -cf ../archive2.tar b*", testprog));
187
systemf("%s -tf ../archive2.tar > ../list2", testprog));
188
assertFileContainsLinesAnyOrder("../list2", list2);
191
systemf("%s -cf ../archive3.tar ??c", testprog));
193
systemf("%s -tf ../archive3.tar > ../list3", testprog));
194
assertFileContainsLinesAnyOrder("../list3", list3);
197
systemf("%s -cf ../archive3b.tar *c", testprog));
199
systemf("%s -tf ../archive3b.tar > ../list3b", testprog));
200
assertFileContainsLinesAnyOrder("../list3b", list3);
203
systemf("%s -cf ../archive4.tar fff/a?ca", testprog));
205
systemf("%s -tf ../archive4.tar > ../list4", testprog));
206
assertFileContainsLinesAnyOrder("../list4", list4);
209
systemf("%s -cf ../archive5.tar aaa\\*", testprog));
211
systemf("%s -tf ../archive5.tar > ../list5", testprog));
212
assertFileContainsLinesAnyOrder("../list5", list5);
215
systemf("%s -cf ../archive6.tar fff\\a?ca aaa\\xx*", testprog));
217
systemf("%s -tf ../archive6.tar > ../list6", testprog));
218
assertFileContainsLinesAnyOrder("../list6", list6);
221
* Test2: Archive the file start with drive letters.
223
/* Test2a: start with "/" */
224
mkfullpath(&fp1, &fp2, "aaa/file1", 0);
226
systemf("%s -cf ../archive10.tar %s > ../out10 2> ../err10",
229
systemf("%s -tf ../archive10.tar > ../list10", testprog));
230
/* Check drive letters have been stripped. */
231
assertFileContents(fp2, strlen(fp2), "../list10");
235
/* Test2b: start with "\" */
236
mkfullpath(&fp1, &fp2, "aaa/file1", 1);
238
systemf("%s -cf ../archive11.tar %s > ../out11 2> ../err11",
241
systemf("%s -tf ../archive11.tar > ../list11", testprog));
242
/* Check drive letters have been stripped. */
243
assertFileContents(fp2, strlen(fp2), "../list11");
247
/* Test2c: start with "c:/" */
248
mkfullpath(&fp1, &fp2, "aaa/file1", 2);
250
systemf("%s -cf ../archive12.tar %s > ../out12 2> ../err12",
253
systemf("%s -tf ../archive12.tar > ../list12", testprog));
254
/* Check drive letters have been stripped. */
255
assertFileContents(fp2, strlen(fp2), "../list12");
259
/* Test2d: start with "c:\" */
260
mkfullpath(&fp1, &fp2, "aaa/file1", 3);
262
systemf("%s -cf ../archive13.tar %s > ../out13 2> ../err13",
265
systemf("%s -tf ../archive13.tar > ../list13", testprog));
266
/* Check drive letters have been stripped. */
267
assertFileContents(fp2, strlen(fp2), "../list13");
271
/* Test2e: start with "//./c:/" */
272
mkfullpath(&fp1, &fp2, "aaa/file1", 4);
274
systemf("%s -cf ../archive14.tar %s > ../out14 2> ../err14",
277
systemf("%s -tf ../archive14.tar > ../list14", testprog));
278
/* Check drive letters have been stripped. */
279
assertFileContents(fp2, strlen(fp2), "../list14");
283
/* Test2f: start with "\\.\c:\" */
284
mkfullpath(&fp1, &fp2, "aaa/file1", 5);
286
systemf("%s -cf ../archive15.tar %s > ../out15 2> ../err15",
289
systemf("%s -tf ../archive15.tar > ../list15", testprog));
290
/* Check drive letters have been stripped. */
291
assertFileContents(fp2, strlen(fp2), "../list15");
295
/* Test2g: start with "//?/c:/" */
296
mkfullpath(&fp1, &fp2, "aaa/file1", 6);
297
failure("fp1=%s, fp2=%s", fp1, fp2);
299
systemf("%s -cf ../archive16.tar %s > ../out16 2> ../err16",
302
systemf("%s -tf ../archive16.tar > ../list16", testprog));
303
/* Check drive letters have been stripped. */
304
assertFileContents(fp2, strlen(fp2), "../list16");
308
/* Test2h: start with "\\?\c:\" */
309
mkfullpath(&fp1, &fp2, "aaa/file1", 7);
310
failure("fp1=%s, fp2=%s", fp1, fp2);
312
systemf("%s -cf ../archive17.tar %s > ../out17 2> ../err17",
315
systemf("%s -tf ../archive17.tar > ../list17", testprog));
316
/* Check drive letters have been stripped. */
317
assertFileContents(fp2, strlen(fp2), "../list17");
321
skipping("Windows specific test");
322
#endif /* _WIN32 && !__CYGWIN__ */