[IPHLPAPI_APITEST]
[reactos.git] / rostests / apitests / kernel32 / FindFiles.c
1 /*
2 * PROJECT: ReactOS api tests
3 * LICENSE: GPLv2+ - See COPYING in the top level directory
4 * PURPOSE: Tests for the Find*File*A/W APIs.
5 * PROGRAMMER: Hermès BÉLUSCA - MAÏTO
6 */
7
8 #include <apitest.h>
9
10 #include <windows.h>
11
12 /*
13 * NOTE: This test supposes the following requirements:
14 * - There is a disk attached to the letter "C:"
15 * - There is a Windows-like system installed in "C:\<installation_directory>"
16 * which contains a sub-directory "system32"
17 * - There is no sub-directory called "foobar" in "C:\".
18 *
19 * If one of these requirements is not fulfilled, one or more tests may fail.
20 */
21
22 static CHAR OSDirA[MAX_PATH]; // OS directory
23 static WCHAR OSDirW[MAX_PATH];
24 static CHAR baseA[MAX_PATH]; // Current directory
25 static WCHAR baseW[MAX_PATH];
26 static CHAR selfnameA[MAX_PATH]; // Path to this executable
27 static WCHAR selfnameW[MAX_PATH];
28 static LPSTR exenameA; // Executable's name
29 static LPWSTR exenameW;
30 static INT myARGC;
31 static LPSTR* myARGV;
32
33
34 /*
35 * Fixes definition of Wine's ok_err
36 */
37 #ifdef ok_err
38 #undef ok_err
39 #endif
40
41 #define ok_err(error) \
42 ok(GetLastError() == (error), "Wrong last error. Expected %lu, got %lu\n", (DWORD)(error), GetLastError())
43
44
45 /*
46 * Types of tests. Define them as macros so that calling them
47 * into the code reports the actual line where they were called.
48 */
49 #define testType1_A(lpFileName, dwInitialError, hExpectedHandleValue, dwExpectedError, bExpectedNullFilename) \
50 do { \
51 ZeroMemory(&fd, sizeof(fd)); \
52 SetLastError((dwInitialError)); \
53 h = FindFirstFileA((lpFileName), &fd); \
54 ok(h == (hExpectedHandleValue), "FindFirstFileA returned 0x%p, expected 0x%p\n", h, (hExpectedHandleValue)); \
55 ok_err(dwExpectedError); \
56 if (bExpectedNullFilename) \
57 ok(fd.cFileName[0] == 0, "fd.cFileName != \"\"\n"); \
58 else \
59 ok(fd.cFileName[0] != 0, "fd.cFileName == \"\"\n"); \
60 FindClose(h); \
61 } while (0)
62
63 #define testType1_W(lpFileName, dwInitialError, hExpectedHandleValue, dwExpectedError, bExpectedNullFilename) \
64 do { \
65 ZeroMemory(&fd, sizeof(fd)); \
66 SetLastError((dwInitialError)); \
67 h = FindFirstFileW((lpFileName), &fd); \
68 ok(h == (hExpectedHandleValue), "FindFirstFileW returned 0x%p, expected 0x%p\n", h, (hExpectedHandleValue)); \
69 ok_err(dwExpectedError); \
70 if (bExpectedNullFilename) \
71 ok(fd.cFileName[0] == 0, "fd.cFileName != \"\"\n"); \
72 else \
73 ok(fd.cFileName[0] != 0, "fd.cFileName == \"\"\n"); \
74 FindClose(h); \
75 } while (0)
76
77 #define testType2_A(lpFileName, dwInitialError, hUnexpectedHandleValue, dwExpectedError) \
78 do { \
79 ZeroMemory(&fd, sizeof(fd)); \
80 SetLastError((dwInitialError)); \
81 h = FindFirstFileA((lpFileName), &fd); \
82 ok(h != (hUnexpectedHandleValue), "FindFirstFileA returned 0x%p\n", h); \
83 ok_err(dwExpectedError); \
84 ok(fd.cFileName[0] != 0, "fd.cFileName == \"\"\n"); \
85 FindClose(h); \
86 } while (0)
87
88 #define testType2_W(lpFileName, dwInitialError, hUnexpectedHandleValue, dwExpectedError) \
89 do { \
90 ZeroMemory(&fd, sizeof(fd)); \
91 SetLastError((dwInitialError)); \
92 h = FindFirstFileW((lpFileName), &fd); \
93 ok(h != (hUnexpectedHandleValue), "FindFirstFileW returned 0x%p\n", h); \
94 ok_err(dwExpectedError); \
95 ok(fd.cFileName[0] != 0, "fd.cFileName == \"\"\n"); \
96 FindClose(h); \
97 } while (0)
98
99
100 static void Test_FindFirstFileA(void)
101 {
102 CHAR CurrentDirectory[MAX_PATH];
103 CHAR Buffer[MAX_PATH];
104 WIN32_FIND_DATAA fd;
105 HANDLE h;
106
107 /* Save the current directory */
108 GetCurrentDirectoryA(sizeof(CurrentDirectory) / sizeof(CHAR), CurrentDirectory);
109
110 /*** Tests for the root directory - root directory ***/
111 /* Modify the current directory */
112 SetCurrentDirectoryA("C:\\");
113
114 testType1_A("C:", 0xdeadbeef, INVALID_HANDLE_VALUE, ERROR_FILE_NOT_FOUND, TRUE);
115
116 testType1_A("C:\\", 0xdeadbeef, INVALID_HANDLE_VALUE, ERROR_FILE_NOT_FOUND, TRUE);
117 testType1_A("C:\\\\", 0xdeadbeef, INVALID_HANDLE_VALUE, ERROR_FILE_NOT_FOUND, TRUE);
118 testType2_A("C:\\*", 0xdeadbeef, INVALID_HANDLE_VALUE, 0xdeadbeef);
119
120 testType1_A("\\", 0xdeadbeef, INVALID_HANDLE_VALUE, ERROR_FILE_NOT_FOUND, TRUE);
121 testType1_A("\\\\", 0xdeadbeef, INVALID_HANDLE_VALUE, ERROR_INVALID_NAME, TRUE);
122 testType2_A("\\*", 0xdeadbeef, INVALID_HANDLE_VALUE, 0xdeadbeef);
123
124 /* Restore the old current directory */
125 SetCurrentDirectoryA(CurrentDirectory);
126 /*****************************************************/
127
128 /*** Tests for the root directory - long directory ***/
129 /* Modify the current directory */
130 SetCurrentDirectoryA(OSDirA); /* We expect here that OSDir is of the form: C:\OSDir */
131
132 testType2_A("C:", 0xdeadbeef, INVALID_HANDLE_VALUE, 0xdeadbeef);
133
134 testType1_A("C:\\", 0xdeadbeef, INVALID_HANDLE_VALUE, ERROR_FILE_NOT_FOUND, TRUE);
135 testType1_A("C:\\\\", 0xdeadbeef, INVALID_HANDLE_VALUE, ERROR_FILE_NOT_FOUND, TRUE);
136 testType2_A("C:\\*", 0xdeadbeef, INVALID_HANDLE_VALUE, 0xdeadbeef);
137
138 testType1_A("\\", 0xdeadbeef, INVALID_HANDLE_VALUE, ERROR_FILE_NOT_FOUND, TRUE);
139 testType1_A("\\\\", 0xdeadbeef, INVALID_HANDLE_VALUE, ERROR_INVALID_NAME, TRUE);
140 testType2_A("\\*", 0xdeadbeef, INVALID_HANDLE_VALUE, 0xdeadbeef);
141
142 /* Restore the old current directory */
143 SetCurrentDirectoryA(CurrentDirectory);
144 /*****************************************************/
145
146 /*** Relative paths ***/
147 /*
148 * NOTE: This test does not give the same results if you launch the app
149 * from a root drive or from a long-form directory (of the form C:\dir).
150 */
151 // testType2_A("..", 0xdeadbeef, INVALID_HANDLE_VALUE, 0xdeadbeef);
152 // testType1_A("..", 0xdeadbeef, INVALID_HANDLE_VALUE, ERROR_FILE_NOT_FOUND, TRUE);
153 /**********************/
154
155 /*** Relative paths - root directory ***/
156 /* Modify the current directory */
157 SetCurrentDirectoryA("C:\\");
158
159 testType1_A(".", 0xdeadbeef, INVALID_HANDLE_VALUE, ERROR_FILE_NOT_FOUND, TRUE);
160 testType1_A(".\\", 0xdeadbeef, INVALID_HANDLE_VALUE, ERROR_FILE_NOT_FOUND, TRUE);
161 testType1_A(".\\\\", 0xdeadbeef, INVALID_HANDLE_VALUE, ERROR_FILE_NOT_FOUND, TRUE);
162 testType2_A(".\\*", 0xdeadbeef, INVALID_HANDLE_VALUE, 0xdeadbeef);
163
164 testType1_A("..", 0xdeadbeef, INVALID_HANDLE_VALUE, ERROR_FILE_NOT_FOUND, TRUE);
165 testType1_A("..\\", 0xdeadbeef, INVALID_HANDLE_VALUE, ERROR_FILE_NOT_FOUND, TRUE);
166 testType1_A("..\\\\", 0xdeadbeef, INVALID_HANDLE_VALUE, ERROR_FILE_NOT_FOUND, TRUE);
167 testType2_A("..\\*", 0xdeadbeef, INVALID_HANDLE_VALUE, 0xdeadbeef);
168
169 /* Restore the old current directory */
170 SetCurrentDirectoryA(CurrentDirectory);
171 /***************************************/
172
173 /*** Relative paths - long directory ***/
174 /* Modify the current directory */
175 SetCurrentDirectoryA(OSDirA); /* We expect here that OSDir is of the form: C:\OSDir */
176
177 testType2_A(".", 0xdeadbeef, INVALID_HANDLE_VALUE, 0xdeadbeef);
178
179 testType1_A(".\\", 0xdeadbeef, INVALID_HANDLE_VALUE, ERROR_FILE_NOT_FOUND, TRUE);
180 testType1_A(".\\\\", 0xdeadbeef, INVALID_HANDLE_VALUE, ERROR_FILE_NOT_FOUND, TRUE);
181 testType2_A(".\\*", 0xdeadbeef, INVALID_HANDLE_VALUE, 0xdeadbeef);
182
183 testType1_A("..", 0xdeadbeef, INVALID_HANDLE_VALUE, ERROR_FILE_NOT_FOUND, TRUE);
184
185 testType1_A("..\\", 0xdeadbeef, INVALID_HANDLE_VALUE, ERROR_FILE_NOT_FOUND, TRUE);
186 testType1_A("..\\\\", 0xdeadbeef, INVALID_HANDLE_VALUE, ERROR_FILE_NOT_FOUND, TRUE);
187 testType2_A("..\\*", 0xdeadbeef, INVALID_HANDLE_VALUE, 0xdeadbeef);
188
189 /* Restore the old current directory */
190 SetCurrentDirectoryA(CurrentDirectory);
191 /****************************************/
192
193 /*** Unexisting path ***/
194 testType1_A("C:\\foobar", 0xdeadbeef, INVALID_HANDLE_VALUE, ERROR_FILE_NOT_FOUND, TRUE);
195 testType1_A("C:\\foobar\\", 0xdeadbeef, INVALID_HANDLE_VALUE, ERROR_PATH_NOT_FOUND, TRUE);
196 testType1_A("C:\\foobar\\\\", 0xdeadbeef, INVALID_HANDLE_VALUE, ERROR_PATH_NOT_FOUND, TRUE);
197 testType1_A("C:\\foobar\\*", 0xdeadbeef, INVALID_HANDLE_VALUE, ERROR_PATH_NOT_FOUND, TRUE);
198 testType1_A("C:\\foobar\\system32\\..\\*", 0xdeadbeef, INVALID_HANDLE_VALUE, ERROR_PATH_NOT_FOUND, TRUE);
199
200 /* Possibly a DOS device */
201 testType1_A("C:\\foobar\\nul", 0xdeadbeef, INVALID_HANDLE_VALUE, ERROR_PATH_NOT_FOUND, TRUE);
202 testType1_A("C:\\foobar\\nul\\", 0xdeadbeef, INVALID_HANDLE_VALUE, ERROR_PATH_NOT_FOUND, TRUE);
203 testType1_A("C:\\foobar\\nul\\\\", 0xdeadbeef, INVALID_HANDLE_VALUE, ERROR_PATH_NOT_FOUND, TRUE);
204 testType1_A("C:\\foobar\\nul\\*", 0xdeadbeef, INVALID_HANDLE_VALUE, ERROR_PATH_NOT_FOUND, TRUE);
205
206 testType1_A("C:\\foobar\\toto", 0xdeadbeef, INVALID_HANDLE_VALUE, ERROR_PATH_NOT_FOUND, TRUE);
207 testType1_A("C:\\foobar\\toto\\", 0xdeadbeef, INVALID_HANDLE_VALUE, ERROR_PATH_NOT_FOUND, TRUE);
208 testType1_A("C:\\foobar\\toto\\\\", 0xdeadbeef, INVALID_HANDLE_VALUE, ERROR_PATH_NOT_FOUND, TRUE);
209 testType1_A("C:\\foobar\\toto\\*", 0xdeadbeef, INVALID_HANDLE_VALUE, ERROR_PATH_NOT_FOUND, TRUE);
210
211 strcpy(Buffer, "C:\\foobar\\");
212 strcat(Buffer, exenameA);
213 testType1_A(Buffer, 0xdeadbeef, INVALID_HANDLE_VALUE, ERROR_PATH_NOT_FOUND, TRUE);
214
215 strcpy(Buffer, "C:\\foobar\\.\\");
216 strcat(Buffer, exenameA);
217 testType1_A(Buffer, 0xdeadbeef, INVALID_HANDLE_VALUE, ERROR_PATH_NOT_FOUND, TRUE);
218 /***********************/
219
220 /*** Existing path ***/
221 strcpy(Buffer, OSDirA);
222 testType2_A(Buffer, 0xdeadbeef, INVALID_HANDLE_VALUE, 0xdeadbeef);
223
224 strcpy(Buffer, OSDirA);
225 strcat(Buffer, "\\");
226 testType1_A(Buffer, 0xdeadbeef, INVALID_HANDLE_VALUE, ERROR_FILE_NOT_FOUND, TRUE);
227
228 strcpy(Buffer, OSDirA);
229 strcat(Buffer, "\\\\");
230 testType1_A(Buffer, 0xdeadbeef, INVALID_HANDLE_VALUE, ERROR_FILE_NOT_FOUND, TRUE);
231
232 strcpy(Buffer, OSDirA);
233 strcat(Buffer, "\\*");
234 testType2_A(Buffer, 0xdeadbeef, INVALID_HANDLE_VALUE, 0xdeadbeef);
235
236 strcpy(Buffer, OSDirA);
237 strcat(Buffer, "\\.\\*");
238 testType2_A(Buffer, 0xdeadbeef, INVALID_HANDLE_VALUE, 0xdeadbeef);
239
240 strcpy(Buffer, OSDirA);
241 strcat(Buffer, "\\system32\\..\\*");
242 testType2_A(Buffer, 0xdeadbeef, INVALID_HANDLE_VALUE, 0xdeadbeef);
243
244 /* Possibly a DOS device */
245 strcpy(Buffer, OSDirA);
246 strcat(Buffer, "\\nul");
247 testType1_A(Buffer, 0xdeadbeef, (HANDLE)0x00000001, 0xdeadbeef, FALSE);
248
249 strcpy(Buffer, OSDirA);
250 strcat(Buffer, "\\nul\\");
251 testType1_A(Buffer, 0xdeadbeef, INVALID_HANDLE_VALUE, ERROR_PATH_NOT_FOUND, TRUE);
252
253 strcpy(Buffer, OSDirA);
254 strcat(Buffer, "\\nul\\\\");
255 testType1_A(Buffer, 0xdeadbeef, INVALID_HANDLE_VALUE, ERROR_PATH_NOT_FOUND, TRUE);
256
257 strcpy(Buffer, OSDirA);
258 strcat(Buffer, "\\nul\\*");
259 testType1_A(Buffer, 0xdeadbeef, INVALID_HANDLE_VALUE, ERROR_PATH_NOT_FOUND, TRUE);
260
261 strcpy(Buffer, OSDirA);
262 strcat(Buffer, "\\toto");
263 testType1_A(Buffer, 0xdeadbeef, INVALID_HANDLE_VALUE, ERROR_FILE_NOT_FOUND, TRUE);
264
265 strcpy(Buffer, OSDirA);
266 strcat(Buffer, "\\toto\\");
267 testType1_A(Buffer, 0xdeadbeef, INVALID_HANDLE_VALUE, ERROR_PATH_NOT_FOUND, TRUE);
268
269 strcpy(Buffer, OSDirA);
270 strcat(Buffer, "\\toto\\\\");
271 testType1_A(Buffer, 0xdeadbeef, INVALID_HANDLE_VALUE, ERROR_PATH_NOT_FOUND, TRUE);
272
273 strcpy(Buffer, OSDirA);
274 strcat(Buffer, "\\toto\\*");
275 testType1_A(Buffer, 0xdeadbeef, INVALID_HANDLE_VALUE, ERROR_PATH_NOT_FOUND, TRUE);
276
277 // strcpy(Buffer, baseA);
278 // strcat(Buffer, "\\");
279 // strcat(Buffer, exenameA);
280 // testType2_A(Buffer, 0xdeadbeef, INVALID_HANDLE_VALUE, 0xdeadbeef);
281
282 // strcpy(Buffer, baseA);
283 // strcat(Buffer, "\\.\\");
284 // strcat(Buffer, exenameA);
285 // testType2_A(Buffer, 0xdeadbeef, INVALID_HANDLE_VALUE, 0xdeadbeef);
286 /*********************/
287
288 return;
289 }
290
291 static void Test_FindFirstFileW(void)
292 {
293 WCHAR CurrentDirectory[MAX_PATH];
294 WCHAR Buffer[MAX_PATH];
295 WIN32_FIND_DATAW fd;
296 HANDLE h;
297
298 /* Save the current directory */
299 GetCurrentDirectoryW(sizeof(CurrentDirectory) / sizeof(WCHAR), CurrentDirectory);
300
301 /*** Tests for the root directory - root directory ***/
302 /* Modify the current directory */
303 SetCurrentDirectoryW(L"C:\\");
304
305 testType1_W(L"C:", 0xdeadbeef, INVALID_HANDLE_VALUE, ERROR_FILE_NOT_FOUND, TRUE);
306
307 testType1_W(L"C:\\", 0xdeadbeef, INVALID_HANDLE_VALUE, ERROR_FILE_NOT_FOUND, TRUE);
308 testType1_W(L"C:\\\\", 0xdeadbeef, INVALID_HANDLE_VALUE, ERROR_FILE_NOT_FOUND, TRUE);
309 testType2_W(L"C:\\*", 0xdeadbeef, INVALID_HANDLE_VALUE, 0xdeadbeef);
310
311 testType1_W(L"\\", 0xdeadbeef, INVALID_HANDLE_VALUE, ERROR_FILE_NOT_FOUND, TRUE);
312 testType1_W(L"\\\\", 0xdeadbeef, INVALID_HANDLE_VALUE, ERROR_INVALID_NAME, TRUE);
313 testType2_W(L"\\*", 0xdeadbeef, INVALID_HANDLE_VALUE, 0xdeadbeef);
314
315 /* Restore the old current directory */
316 SetCurrentDirectoryW(CurrentDirectory);
317 /*****************************************************/
318
319 /*** Tests for the root directory - long directory ***/
320 /* Modify the current directory */
321 SetCurrentDirectoryW(OSDirW); /* We expect here that OSDir is of the form: C:\OSDir */
322
323 testType2_W(L"C:", 0xdeadbeef, INVALID_HANDLE_VALUE, 0xdeadbeef);
324
325 testType1_W(L"C:\\", 0xdeadbeef, INVALID_HANDLE_VALUE, ERROR_FILE_NOT_FOUND, TRUE);
326 testType1_W(L"C:\\\\", 0xdeadbeef, INVALID_HANDLE_VALUE, ERROR_FILE_NOT_FOUND, TRUE);
327 testType2_W(L"C:\\*", 0xdeadbeef, INVALID_HANDLE_VALUE, 0xdeadbeef);
328
329 testType1_W(L"\\", 0xdeadbeef, INVALID_HANDLE_VALUE, ERROR_FILE_NOT_FOUND, TRUE);
330 testType1_W(L"\\\\", 0xdeadbeef, INVALID_HANDLE_VALUE, ERROR_INVALID_NAME, TRUE);
331 testType2_W(L"\\*", 0xdeadbeef, INVALID_HANDLE_VALUE, 0xdeadbeef);
332
333 /* Restore the old current directory */
334 SetCurrentDirectoryW(CurrentDirectory);
335 /*****************************************************/
336
337 /*** Relative paths ***/
338 /*
339 * NOTE: This test does not give the same results if you launch the app
340 * from a root drive or from a long-form directory (of the form C:\dir).
341 */
342 // testType2_W(L"..", 0xdeadbeef, INVALID_HANDLE_VALUE, 0xdeadbeef);
343 // testType1_W(L"..", 0xdeadbeef, INVALID_HANDLE_VALUE, ERROR_FILE_NOT_FOUND, TRUE);
344 /**********************/
345
346 /*** Relative paths - root directory ***/
347 /* Modify the current directory */
348 SetCurrentDirectoryW(L"C:\\");
349
350 testType1_W(L".", 0xdeadbeef, INVALID_HANDLE_VALUE, ERROR_FILE_NOT_FOUND, TRUE);
351 testType1_W(L".\\", 0xdeadbeef, INVALID_HANDLE_VALUE, ERROR_FILE_NOT_FOUND, TRUE);
352 testType1_W(L".\\\\", 0xdeadbeef, INVALID_HANDLE_VALUE, ERROR_FILE_NOT_FOUND, TRUE);
353 testType2_W(L".\\*", 0xdeadbeef, INVALID_HANDLE_VALUE, 0xdeadbeef);
354
355 testType1_W(L"..", 0xdeadbeef, INVALID_HANDLE_VALUE, ERROR_FILE_NOT_FOUND, TRUE);
356 testType1_W(L"..\\", 0xdeadbeef, INVALID_HANDLE_VALUE, ERROR_FILE_NOT_FOUND, TRUE);
357 testType1_W(L"..\\\\", 0xdeadbeef, INVALID_HANDLE_VALUE, ERROR_FILE_NOT_FOUND, TRUE);
358 testType2_W(L"..\\*", 0xdeadbeef, INVALID_HANDLE_VALUE, 0xdeadbeef);
359
360 /* Restore the old current directory */
361 SetCurrentDirectoryW(CurrentDirectory);
362 /***************************************/
363
364 /*** Relative paths - long directory ***/
365 /* Modify the current directory */
366 SetCurrentDirectoryW(OSDirW); /* We expect here that OSDir is of the form: C:\OSDir */
367
368 testType2_W(L".", 0xdeadbeef, INVALID_HANDLE_VALUE, 0xdeadbeef);
369
370 testType1_W(L".\\", 0xdeadbeef, INVALID_HANDLE_VALUE, ERROR_FILE_NOT_FOUND, TRUE);
371 testType1_W(L".\\\\", 0xdeadbeef, INVALID_HANDLE_VALUE, ERROR_FILE_NOT_FOUND, TRUE);
372 testType2_W(L".\\*", 0xdeadbeef, INVALID_HANDLE_VALUE, 0xdeadbeef);
373
374 testType1_W(L"..", 0xdeadbeef, INVALID_HANDLE_VALUE, ERROR_FILE_NOT_FOUND, TRUE);
375
376 testType1_W(L"..\\", 0xdeadbeef, INVALID_HANDLE_VALUE, ERROR_FILE_NOT_FOUND, TRUE);
377 testType1_W(L"..\\\\", 0xdeadbeef, INVALID_HANDLE_VALUE, ERROR_FILE_NOT_FOUND, TRUE);
378 testType2_W(L"..\\*", 0xdeadbeef, INVALID_HANDLE_VALUE, 0xdeadbeef);
379
380 /* Restore the old current directory */
381 SetCurrentDirectoryW(CurrentDirectory);
382 /****************************************/
383
384 /*** Unexisting path ***/
385 testType1_W(L"C:\\foobar", 0xdeadbeef, INVALID_HANDLE_VALUE, ERROR_FILE_NOT_FOUND, TRUE);
386 testType1_W(L"C:\\foobar\\", 0xdeadbeef, INVALID_HANDLE_VALUE, ERROR_PATH_NOT_FOUND, TRUE);
387 testType1_W(L"C:\\foobar\\\\", 0xdeadbeef, INVALID_HANDLE_VALUE, ERROR_PATH_NOT_FOUND, TRUE);
388 testType1_W(L"C:\\foobar\\*", 0xdeadbeef, INVALID_HANDLE_VALUE, ERROR_PATH_NOT_FOUND, TRUE);
389 testType1_W(L"C:\\foobar\\system32\\..\\*", 0xdeadbeef, INVALID_HANDLE_VALUE, ERROR_PATH_NOT_FOUND, TRUE);
390
391 /* Possibly a DOS device */
392 testType1_W(L"C:\\foobar\\nul", 0xdeadbeef, INVALID_HANDLE_VALUE, ERROR_PATH_NOT_FOUND, TRUE);
393 testType1_W(L"C:\\foobar\\nul\\", 0xdeadbeef, INVALID_HANDLE_VALUE, ERROR_PATH_NOT_FOUND, TRUE);
394 testType1_W(L"C:\\foobar\\nul\\\\", 0xdeadbeef, INVALID_HANDLE_VALUE, ERROR_PATH_NOT_FOUND, TRUE);
395 testType1_W(L"C:\\foobar\\nul\\*", 0xdeadbeef, INVALID_HANDLE_VALUE, ERROR_PATH_NOT_FOUND, TRUE);
396
397 testType1_W(L"C:\\foobar\\toto", 0xdeadbeef, INVALID_HANDLE_VALUE, ERROR_PATH_NOT_FOUND, TRUE);
398 testType1_W(L"C:\\foobar\\toto\\", 0xdeadbeef, INVALID_HANDLE_VALUE, ERROR_PATH_NOT_FOUND, TRUE);
399 testType1_W(L"C:\\foobar\\toto\\\\", 0xdeadbeef, INVALID_HANDLE_VALUE, ERROR_PATH_NOT_FOUND, TRUE);
400 testType1_W(L"C:\\foobar\\toto\\*", 0xdeadbeef, INVALID_HANDLE_VALUE, ERROR_PATH_NOT_FOUND, TRUE);
401
402 wcscpy(Buffer, L"C:\\foobar\\");
403 wcscat(Buffer, exenameW);
404 testType1_W(Buffer, 0xdeadbeef, INVALID_HANDLE_VALUE, ERROR_PATH_NOT_FOUND, TRUE);
405
406 wcscpy(Buffer, L"C:\\foobar\\.\\");
407 wcscat(Buffer, exenameW);
408 testType1_W(Buffer, 0xdeadbeef, INVALID_HANDLE_VALUE, ERROR_PATH_NOT_FOUND, TRUE);
409 /***********************/
410
411 /*** Existing path ***/
412 wcscpy(Buffer, OSDirW);
413 testType2_W(Buffer, 0xdeadbeef, INVALID_HANDLE_VALUE, 0xdeadbeef);
414
415 wcscpy(Buffer, OSDirW);
416 wcscat(Buffer, L"\\");
417 testType1_W(Buffer, 0xdeadbeef, INVALID_HANDLE_VALUE, ERROR_FILE_NOT_FOUND, TRUE);
418
419 wcscpy(Buffer, OSDirW);
420 wcscat(Buffer, L"\\\\");
421 testType1_W(Buffer, 0xdeadbeef, INVALID_HANDLE_VALUE, ERROR_FILE_NOT_FOUND, TRUE);
422
423 wcscpy(Buffer, OSDirW);
424 wcscat(Buffer, L"\\*");
425 testType2_W(Buffer, 0xdeadbeef, INVALID_HANDLE_VALUE, 0xdeadbeef);
426
427 wcscpy(Buffer, OSDirW);
428 wcscat(Buffer, L"\\.\\*");
429 testType2_W(Buffer, 0xdeadbeef, INVALID_HANDLE_VALUE, 0xdeadbeef);
430
431 wcscpy(Buffer, OSDirW);
432 wcscat(Buffer, L"\\system32\\..\\*");
433 testType2_W(Buffer, 0xdeadbeef, INVALID_HANDLE_VALUE, 0xdeadbeef);
434
435 /* Possibly a DOS device */
436 wcscpy(Buffer, OSDirW);
437 wcscat(Buffer, L"\\nul");
438 testType1_W(Buffer, 0xdeadbeef, (HANDLE)0x00000001, 0xdeadbeef, FALSE);
439
440 wcscpy(Buffer, OSDirW);
441 wcscat(Buffer, L"\\nul\\");
442 testType1_W(Buffer, 0xdeadbeef, INVALID_HANDLE_VALUE, ERROR_PATH_NOT_FOUND, TRUE);
443
444 wcscpy(Buffer, OSDirW);
445 wcscat(Buffer, L"\\nul\\\\");
446 testType1_W(Buffer, 0xdeadbeef, INVALID_HANDLE_VALUE, ERROR_PATH_NOT_FOUND, TRUE);
447
448 wcscpy(Buffer, OSDirW);
449 wcscat(Buffer, L"\\nul\\*");
450 testType1_W(Buffer, 0xdeadbeef, INVALID_HANDLE_VALUE, ERROR_PATH_NOT_FOUND, TRUE);
451
452 wcscpy(Buffer, OSDirW);
453 wcscat(Buffer, L"\\toto");
454 testType1_W(Buffer, 0xdeadbeef, INVALID_HANDLE_VALUE, ERROR_FILE_NOT_FOUND, TRUE);
455
456 wcscpy(Buffer, OSDirW);
457 wcscat(Buffer, L"\\toto\\");
458 testType1_W(Buffer, 0xdeadbeef, INVALID_HANDLE_VALUE, ERROR_PATH_NOT_FOUND, TRUE);
459
460 wcscpy(Buffer, OSDirW);
461 wcscat(Buffer, L"\\toto\\\\");
462 testType1_W(Buffer, 0xdeadbeef, INVALID_HANDLE_VALUE, ERROR_PATH_NOT_FOUND, TRUE);
463
464 wcscpy(Buffer, OSDirW);
465 wcscat(Buffer, L"\\toto\\*");
466 testType1_W(Buffer, 0xdeadbeef, INVALID_HANDLE_VALUE, ERROR_PATH_NOT_FOUND, TRUE);
467
468 // wcscpy(Buffer, baseW);
469 // wcscat(Buffer, L"\\");
470 // wcscat(Buffer, exenameW);
471 // testType2_W(Buffer, 0xdeadbeef, INVALID_HANDLE_VALUE, 0xdeadbeef);
472
473 // wcscpy(Buffer, baseW);
474 // wcscat(Buffer, L"\\.\\");
475 // wcscat(Buffer, exenameW);
476 // testType2_W(Buffer, 0xdeadbeef, INVALID_HANDLE_VALUE, 0xdeadbeef);
477 /*********************/
478
479 return;
480 }
481
482
483 static int init(void)
484 {
485 LPSTR p;
486 size_t i;
487
488 myARGC = winetest_get_mainargs(&myARGV);
489 if (!GetCurrentDirectoryA(sizeof(baseA)/sizeof(baseA[0]), baseA)) return 0;
490 strcpy(selfnameA, myARGV[0]);
491
492 /* Strip the path of selfname */
493 if ((p = strrchr(selfnameA, '\\')) != NULL)
494 exenameA = p + 1;
495 else
496 exenameA = selfnameA;
497
498 if ((p = strrchr(exenameA, '/')) != NULL)
499 exenameA = p + 1;
500
501 if (!GetWindowsDirectoryA(OSDirA, sizeof(OSDirA)/sizeof(OSDirA[0]))) return 0;
502
503 /* Quick-and-dirty conversion ANSI --> UNICODE without the Win32 APIs */
504 for (i = 0 ; i <= strlen(baseA) ; ++i)
505 {
506 baseW[i] = (WCHAR)baseA[i];
507 }
508 for (i = 0 ; i <= strlen(selfnameA) ; ++i)
509 {
510 selfnameW[i] = (WCHAR)selfnameA[i];
511 }
512 exenameW = selfnameW + (exenameA - selfnameA);
513 for (i = 0 ; i <= strlen(OSDirA) ; ++i)
514 {
515 OSDirW[i] = (WCHAR)OSDirA[i];
516 }
517
518 return 1;
519 }
520
521 START_TEST(FindFiles)
522 {
523 int b = init();
524 ok(b, "Basic init of FindFiles test\n");
525 if (!b) return;
526
527 Test_FindFirstFileA();
528 Test_FindFirstFileW();
529 }