fusion: CompareAssemblyIdentity() and GetAssemblyIdentityFromFile() are unused stubs...
[wine] / dlls / kernel32 / tests / volume.c
1 /*
2  * Unit test suite
3  *
4  * Copyright 2006 Stefan Leichter
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20
21 #include "wine/test.h"
22 #include "winbase.h"
23 #include <stdio.h>
24
25 static HINSTANCE hdll;
26 static BOOL (WINAPI * pGetVolumeNameForVolumeMountPointA)(LPCSTR, LPSTR, DWORD);
27 static BOOL (WINAPI * pGetVolumeNameForVolumeMountPointW)(LPCWSTR, LPWSTR, DWORD);
28 static HANDLE (WINAPI *pFindFirstVolumeA)(LPSTR,DWORD);
29 static BOOL (WINAPI *pFindNextVolumeA)(HANDLE,LPSTR,DWORD);
30 static BOOL (WINAPI *pFindVolumeClose)(HANDLE);
31 static UINT (WINAPI *pGetLogicalDriveStringsA)(UINT,LPSTR);
32 static UINT (WINAPI *pGetLogicalDriveStringsW)(UINT,LPWSTR);
33 static BOOL (WINAPI *pGetVolumeInformationA)(LPCSTR, LPSTR, DWORD, LPDWORD, LPDWORD, LPDWORD, LPSTR, DWORD);
34
35 /* ############################### */
36
37 static void test_query_dos_deviceA(void)
38 {
39     char drivestr[] = "a:";
40     char *p, *buffer, buffer2[2000];
41     DWORD ret, ret2, buflen=32768;
42     BOOL found = FALSE;
43
44     if (!pFindFirstVolumeA) {
45         win_skip("On win9x, HARDDISK and RAMDISK not present\n");
46         return;
47     }
48
49     buffer = HeapAlloc( GetProcessHeap(), 0, buflen );
50     ret = QueryDosDeviceA( NULL, buffer, buflen );
51     ok(ret && GetLastError() != ERROR_INSUFFICIENT_BUFFER,
52         "QueryDosDevice buffer too small\n");
53     if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
54         HeapFree( GetProcessHeap(), 0, buffer );
55         return;
56     }
57     ok(ret, "QueryDosDeviceA failed to return list, last error %u\n", GetLastError());
58     if (ret) {
59         p = buffer;
60         for (;;) {
61             if (!strlen(p)) break;
62             ret2 = QueryDosDeviceA( p, buffer2, sizeof(buffer2) );
63             ok(ret2, "QueryDosDeviceA failed to return current mapping for %s, last error %u\n", p, GetLastError());
64             p += strlen(p) + 1;
65             if (ret <= (p-buffer)) break;
66         }
67     }
68
69     for (;drivestr[0] <= 'z'; drivestr[0]++) {
70         ret = QueryDosDeviceA( drivestr, buffer, buflen);
71         if(ret) {
72             for (p = buffer; *p; p++) *p = toupper(*p);
73             if (strstr(buffer, "HARDDISK") || strstr(buffer, "RAMDISK")) found = TRUE;
74         }
75     }
76     ok(found, "expected at least one devicename to contain HARDDISK or RAMDISK\n");
77     HeapFree( GetProcessHeap(), 0, buffer );
78 }
79
80 static void test_FindFirstVolume(void)
81 {
82     char volume[51];
83     HANDLE handle;
84
85     if (!pFindFirstVolumeA) {
86         skip("FindFirstVolumeA not found\n");
87         return;
88     }
89
90     handle = pFindFirstVolumeA( volume, 0 );
91     ok( handle == INVALID_HANDLE_VALUE, "succeeded with short buffer\n" );
92     ok( GetLastError() == ERROR_MORE_DATA ||  /* XP */
93         GetLastError() == ERROR_FILENAME_EXCED_RANGE,  /* Vista */
94         "wrong error %u\n", GetLastError() );
95     handle = pFindFirstVolumeA( volume, 49 );
96     ok( handle == INVALID_HANDLE_VALUE, "succeeded with short buffer\n" );
97     ok( GetLastError() == ERROR_FILENAME_EXCED_RANGE, "wrong error %u\n", GetLastError() );
98     handle = pFindFirstVolumeA( volume, 51 );
99     ok( handle != INVALID_HANDLE_VALUE, "failed err %u\n", GetLastError() );
100     if (handle != INVALID_HANDLE_VALUE)
101     {
102         do
103         {
104             ok( strlen(volume) == 49, "bad volume name %s\n", volume );
105             ok( !memcmp( volume, "\\\\?\\Volume{", 11 ), "bad volume name %s\n", volume );
106             ok( !memcmp( volume + 47, "}\\", 2 ), "bad volume name %s\n", volume );
107         } while (pFindNextVolumeA( handle, volume, MAX_PATH ));
108         ok( GetLastError() == ERROR_NO_MORE_FILES, "wrong error %u\n", GetLastError() );
109         pFindVolumeClose( handle );
110     }
111 }
112
113 static void test_GetVolumeNameForVolumeMountPointA(void)
114 {
115     BOOL ret;
116     char volume[MAX_PATH], path[] = "c:\\";
117     DWORD len = sizeof(volume), reti;
118     char temp_path[MAX_PATH];
119
120     /* not present before w2k */
121     if (!pGetVolumeNameForVolumeMountPointA) {
122         skip("GetVolumeNameForVolumeMountPointA not found\n");
123         return;
124     }
125
126     reti = GetTempPathA(MAX_PATH, temp_path);
127     ok(reti != 0, "GetTempPathA error %d\n", GetLastError());
128     ok(reti < MAX_PATH, "temp path should fit into MAX_PATH\n");
129
130     ret = pGetVolumeNameForVolumeMountPointA(path, volume, 0);
131     ok(ret == FALSE, "GetVolumeNameForVolumeMountPointA succeeded\n");
132
133     if (0) { /* these crash on XP */
134     ret = pGetVolumeNameForVolumeMountPointA(path, NULL, len);
135     ok(ret == FALSE, "GetVolumeNameForVolumeMountPointA succeeded\n");
136
137     ret = pGetVolumeNameForVolumeMountPointA(NULL, volume, len);
138     ok(ret == FALSE, "GetVolumeNameForVolumeMountPointA succeeded\n");
139     }
140
141     ret = pGetVolumeNameForVolumeMountPointA(path, volume, len);
142     ok(ret == TRUE, "GetVolumeNameForVolumeMountPointA failed\n");
143     ok(!strncmp( volume, "\\\\?\\Volume{", 11),
144         "GetVolumeNameForVolumeMountPointA failed to return valid string <%s>\n",
145         volume);
146
147     /* test with too small buffer */
148     ret = pGetVolumeNameForVolumeMountPointA(path, volume, 10);
149 todo_wine
150     ok(ret == FALSE && GetLastError() == ERROR_FILENAME_EXCED_RANGE,
151             "GetVolumeNameForVolumeMountPointA failed, wrong error returned, was %d, should be ERROR_FILENAME_EXCED_RANGE\n",
152              GetLastError());
153
154     /* Try on a arbitrary directory */
155     ret = pGetVolumeNameForVolumeMountPointA(temp_path, volume, len);
156 todo_wine
157     ok(ret == FALSE && GetLastError() == ERROR_NOT_A_REPARSE_POINT,
158         "GetVolumeNameForVolumeMountPointA failed on %s, last=%d\n",
159         temp_path, GetLastError());
160
161     /* Try on a non-existent dos drive */
162     path[2] = 0;
163     for (;path[0] <= 'z'; path[0]++) {
164         ret = QueryDosDeviceA( path, volume, len);
165         if(!ret) break;
166     }
167     if (path[0] <= 'z')
168     {
169         path[2] = '\\';
170         ret = pGetVolumeNameForVolumeMountPointA(path, volume, len);
171 todo_wine
172         ok(ret == FALSE && GetLastError() == ERROR_FILE_NOT_FOUND,
173             "GetVolumeNameForVolumeMountPointA failed on %s, last=%d\n",
174             path, GetLastError());
175
176         /* Try without trailing \ and on a non-existent dos drive  */
177         path[2] = 0;
178         ret = pGetVolumeNameForVolumeMountPointA(path, volume, len);
179 todo_wine
180         ok(ret == FALSE && GetLastError() == ERROR_INVALID_NAME,
181             "GetVolumeNameForVolumeMountPointA failed on %s, last=%d\n",
182             path, GetLastError());
183     }
184 }
185
186 static void test_GetVolumeNameForVolumeMountPointW(void)
187 {
188     BOOL ret;
189     WCHAR volume[MAX_PATH], path[] = {'c',':','\\',0};
190     DWORD len = sizeof(volume) / sizeof(WCHAR);
191
192     /* not present before w2k */
193     if (!pGetVolumeNameForVolumeMountPointW) {
194         skip("GetVolumeNameForVolumeMountPointW not found\n");
195         return;
196     }
197
198     ret = pGetVolumeNameForVolumeMountPointW(path, volume, 0);
199     ok(ret == FALSE, "GetVolumeNameForVolumeMountPointA succeeded\n");
200
201     if (0) { /* these crash on XP */
202     ret = pGetVolumeNameForVolumeMountPointW(path, NULL, len);
203     ok(ret == FALSE, "GetVolumeNameForVolumeMountPointW succeeded\n");
204
205     ret = pGetVolumeNameForVolumeMountPointW(NULL, volume, len);
206     ok(ret == FALSE, "GetVolumeNameForVolumeMountPointW succeeded\n");
207     }
208
209     ret = pGetVolumeNameForVolumeMountPointW(path, volume, len);
210     ok(ret == TRUE, "GetVolumeNameForVolumeMountPointW failed\n");
211 }
212
213 static void test_GetLogicalDriveStringsA(void)
214 {
215     UINT size, size2;
216     char *buf, *ptr;
217
218     if(!pGetLogicalDriveStringsA) {
219         win_skip("GetLogicalDriveStringsA not available\n");
220         return;
221     }
222
223     size = pGetLogicalDriveStringsA(0, NULL);
224     ok(size%4 == 1, "size = %d\n", size);
225
226     buf = HeapAlloc(GetProcessHeap(), 0, size);
227
228     *buf = 0;
229     size2 = pGetLogicalDriveStringsA(2, buf);
230     ok(size2 == size, "size2 = %d\n", size2);
231     ok(!*buf, "buf changed\n");
232
233     size2 = pGetLogicalDriveStringsA(size, buf);
234     ok(size2 == size-1, "size2 = %d\n", size2);
235
236     for(ptr = buf; ptr < buf+size2; ptr += 4) {
237         ok(('A' <= *ptr && *ptr <= 'Z') ||
238            (broken('a' <= *ptr && *ptr <= 'z')), /* Win9x and WinMe */
239            "device name '%c' is not uppercase\n", *ptr);
240         ok(ptr[1] == ':', "ptr[1] = %c, expected ':'\n", ptr[1]);
241         ok(ptr[2] == '\\', "ptr[2] = %c expected '\\'\n", ptr[2]);
242         ok(!ptr[3], "ptr[3] = %c expected nullbyte\n", ptr[3]);
243     }
244     ok(!*ptr, "buf[size2] is not nullbyte\n");
245
246     HeapFree(GetProcessHeap(), 0, buf);
247 }
248
249 static void test_GetLogicalDriveStringsW(void)
250 {
251     UINT size, size2;
252     WCHAR *buf, *ptr;
253
254     if(!pGetLogicalDriveStringsW) {
255         win_skip("GetLogicalDriveStringsW not available\n");
256         return;
257     }
258
259     SetLastError(0xdeadbeef);
260     size = pGetLogicalDriveStringsW(0, NULL);
261     if (size == 0 && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED) {
262         win_skip("GetLogicalDriveStringsW not implemented\n");
263         return;
264     }
265     ok(size%4 == 1, "size = %d\n", size);
266
267     buf = HeapAlloc(GetProcessHeap(), 0, size*sizeof(WCHAR));
268
269     *buf = 0;
270     size2 = pGetLogicalDriveStringsW(2, buf);
271     ok(size2 == size, "size2 = %d\n", size2);
272     ok(!*buf, "buf changed\n");
273
274     size2 = pGetLogicalDriveStringsW(size, buf);
275     ok(size2 == size-1, "size2 = %d\n", size2);
276
277     for(ptr = buf; ptr < buf+size2; ptr += 4) {
278         ok('A' <= *ptr && *ptr <= 'Z', "device name '%c' is not uppercase\n", *ptr);
279         ok(ptr[1] == ':', "ptr[1] = %c, expected ':'\n", ptr[1]);
280         ok(ptr[2] == '\\', "ptr[2] = %c expected '\\'\n", ptr[2]);
281         ok(!ptr[3], "ptr[3] = %c expected nullbyte\n", ptr[3]);
282     }
283     ok(!*ptr, "buf[size2] is not nullbyte\n");
284
285     HeapFree(GetProcessHeap(), 0, buf);
286 }
287
288 static void test_GetVolumeInformationA(void)
289 {
290     BOOL ret;
291     UINT result;
292     char Root_Dir0[]="C:";
293     char Root_Dir1[]="C:\\";
294     char Root_Dir2[]="\\\\?\\C:\\";
295     char volume[MAX_PATH+1];
296     DWORD vol_name_size=MAX_PATH+1, vol_serial_num=-1, max_comp_len=0, fs_flags=0, fs_name_len=MAX_PATH+1;
297     char vol_name_buf[MAX_PATH+1], fs_name_buf[MAX_PATH+1];
298     char windowsdir[MAX_PATH+10];
299
300     if (!pGetVolumeInformationA) {
301         win_skip("GetVolumeInformationA not found\n");
302         return;
303     }
304     if (!pGetVolumeNameForVolumeMountPointA) {
305         win_skip("GetVolumeNameForVolumeMountPointA not found\n");
306         return;
307     }
308
309     /* get windows drive letter and update strings for testing */
310     result = GetWindowsDirectory(windowsdir, sizeof(windowsdir));
311     ok(result < sizeof(windowsdir), "windowsdir is abnormally long!\n");
312     ok(result != 0, "GetWindowsDirectory: error %d\n", GetLastError());
313     Root_Dir0[0] = windowsdir[0];
314     Root_Dir1[0] = windowsdir[0];
315     Root_Dir2[4] = windowsdir[0];
316
317     /* get the unique volume name for the windows drive  */
318     ret = pGetVolumeNameForVolumeMountPointA(Root_Dir1, volume, MAX_PATH);
319     ok(ret == TRUE, "GetVolumeNameForVolumeMountPointA failed\n");
320
321     /*  ****  now start the tests       ****  */
322     /* check for error on no trailing \   */
323     ret = pGetVolumeInformationA(Root_Dir0, vol_name_buf, vol_name_size, NULL,
324             NULL, NULL, fs_name_buf, fs_name_len);
325     ok(!ret && GetLastError() == ERROR_INVALID_NAME,
326         "GetVolumeInformationA w/o '\\' did not fail, last error %u\n", GetLastError());
327
328     /* try null root directory to return "root of the current directory"  */
329     ret = pGetVolumeInformationA(NULL, vol_name_buf, vol_name_size, NULL,
330             NULL, NULL, fs_name_buf, fs_name_len);
331     ok(ret, "GetVolumeInformationA failed on null root dir, last error %u\n", GetLastError());
332
333     /* Try normal drive letter with trailing \  */
334     ret = pGetVolumeInformationA(Root_Dir1, vol_name_buf, vol_name_size,
335             &vol_serial_num, &max_comp_len, &fs_flags, fs_name_buf, fs_name_len);
336     ok(ret, "GetVolumeInformationA failed, root=%s, last error=%u\n", Root_Dir1, GetLastError());
337
338     /* try again with dirve letter and the "disable parsing" prefix */
339     ret = pGetVolumeInformationA(Root_Dir2, vol_name_buf, vol_name_size,
340             &vol_serial_num, &max_comp_len, &fs_flags, fs_name_buf, fs_name_len);
341     todo_wine ok(ret, "GetVolumeInformationA failed, root=%s, last error=%u\n", Root_Dir2, GetLastError());
342
343     /* try again with unique voluem name */
344     ret = pGetVolumeInformationA(volume, vol_name_buf, vol_name_size,
345             &vol_serial_num, &max_comp_len, &fs_flags, fs_name_buf, fs_name_len);
346     todo_wine ok(ret, "GetVolumeInformationA failed, root=%s, last error=%u\n", volume, GetLastError());
347
348     /* try again with device name space  */
349     Root_Dir2[2] = '.';
350     ret = pGetVolumeInformationA(Root_Dir2, vol_name_buf, vol_name_size,
351             &vol_serial_num, &max_comp_len, &fs_flags, fs_name_buf, fs_name_len);
352     todo_wine ok(ret, "GetVolumeInformationA failed, root=%s, last error=%u\n", Root_Dir2, GetLastError());
353
354     /* try again with a directory off the root - should generate error  */
355     if (windowsdir[strlen(windowsdir)-1] != '\\') strcat(windowsdir, "\\");
356     ret = pGetVolumeInformationA(windowsdir, vol_name_buf, vol_name_size,
357             &vol_serial_num, &max_comp_len, &fs_flags, fs_name_buf, fs_name_len);
358     todo_wine ok(!ret && GetLastError()==ERROR_DIR_NOT_ROOT,
359           "GetVolumeInformationA failed, root=%s, last error=%u\n", windowsdir, GetLastError());
360 }
361
362 /* Test to check that unique volume name from windows dir mount point  */
363 /* matches at least one of the unique volume names returned from the   */
364 /* FindFirstVolumeA/FindNextVolumeA list.                              */
365 static void test_enum_vols(void)
366 {
367     DWORD   ret;
368     HANDLE  hFind = INVALID_HANDLE_VALUE;
369     char    Volume_1[MAX_PATH] = {0};
370     char    Volume_2[MAX_PATH] = {0};
371     char    path[] = "c:\\";
372     BOOL    found = FALSE;
373     char    windowsdir[MAX_PATH];
374
375     if (!pGetVolumeNameForVolumeMountPointA) {
376         win_skip("GetVolumeNameForVolumeMountPointA not found\n");
377         return;
378     }
379
380     /*get windows drive letter and update strings for testing  */
381     ret = GetWindowsDirectory( windowsdir, sizeof(windowsdir) );
382     ok(ret < sizeof(windowsdir), "windowsdir is abnormally long!\n");
383     ok(ret != 0, "GetWindowsDirecory: error %d\n", GetLastError());
384     path[0] = windowsdir[0];
385
386     /* get the unique volume name for the windows drive  */
387     ret = pGetVolumeNameForVolumeMountPointA( path, Volume_1, MAX_PATH );
388     ok(ret == TRUE, "GetVolumeNameForVolumeMountPointA failed\n");
389 todo_wine
390     ok(strlen(Volume_1) == 49, "GetVolumeNameForVolumeMountPointA returned wrong length name %s\n", Volume_1);
391
392     /* get first unique volume name of list  */
393     hFind = pFindFirstVolumeA( Volume_2, MAX_PATH );
394     ok(hFind != INVALID_HANDLE_VALUE, "FindFirstVolume failed, err=%u\n",
395                 GetLastError());
396
397     do
398     {
399         /* validate correct length of unique volume name  */
400         ok(strlen(Volume_2) == 49, "Find[First/Next]Volume returned wrong length name %s\n", Volume_1);
401         if (memcmp(Volume_1, Volume_2, 49) == 0)
402         {
403             found = TRUE;
404             break;
405         }
406     } while (pFindNextVolumeA( hFind, Volume_2, MAX_PATH ));
407 todo_wine
408     ok(found, "volume name %s not found by Find[First/Next]Volume\n", Volume_1);
409     pFindVolumeClose( hFind );
410 }
411
412 START_TEST(volume)
413 {
414     hdll = GetModuleHandleA("kernel32.dll");
415     pGetVolumeNameForVolumeMountPointA = (void *) GetProcAddress(hdll, "GetVolumeNameForVolumeMountPointA");
416     pGetVolumeNameForVolumeMountPointW = (void *) GetProcAddress(hdll, "GetVolumeNameForVolumeMountPointW");
417     pFindFirstVolumeA = (void *) GetProcAddress(hdll, "FindFirstVolumeA");
418     pFindNextVolumeA = (void *) GetProcAddress(hdll, "FindNextVolumeA");
419     pFindVolumeClose = (void *) GetProcAddress(hdll, "FindVolumeClose");
420     pGetLogicalDriveStringsA = (void *) GetProcAddress(hdll, "GetLogicalDriveStringsA");
421     pGetLogicalDriveStringsW = (void *) GetProcAddress(hdll, "GetLogicalDriveStringsW");
422     pGetVolumeInformationA = (void *) GetProcAddress(hdll, "GetVolumeInformationA");
423
424     test_query_dos_deviceA();
425     test_FindFirstVolume();
426     test_GetVolumeNameForVolumeMountPointA();
427     test_GetVolumeNameForVolumeMountPointW();
428     test_GetLogicalDriveStringsA();
429     test_GetLogicalDriveStringsW();
430     test_GetVolumeInformationA();
431     test_enum_vols();
432 }