kernel32/tests: Check what happens if QueryDosDeviceA() is given an insufficient...
[wine/multimedia.git] / dlls / kernel32 / tests / volume.c
blob2755af5a106f871d4558c3e584bd8418dd46b6dd
1 /*
2 * Unit test suite for volume functions
4 * Copyright 2006 Stefan Leichter
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.
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.
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
21 #include "wine/test.h"
22 #include "winbase.h"
23 #include "winioctl.h"
24 #include <stdio.h>
26 static HINSTANCE hdll;
27 static BOOL (WINAPI * pGetVolumeNameForVolumeMountPointA)(LPCSTR, LPSTR, DWORD);
28 static BOOL (WINAPI * pGetVolumeNameForVolumeMountPointW)(LPCWSTR, LPWSTR, DWORD);
29 static HANDLE (WINAPI *pFindFirstVolumeA)(LPSTR,DWORD);
30 static BOOL (WINAPI *pFindNextVolumeA)(HANDLE,LPSTR,DWORD);
31 static BOOL (WINAPI *pFindVolumeClose)(HANDLE);
32 static UINT (WINAPI *pGetLogicalDriveStringsA)(UINT,LPSTR);
33 static UINT (WINAPI *pGetLogicalDriveStringsW)(UINT,LPWSTR);
34 static BOOL (WINAPI *pGetVolumeInformationA)(LPCSTR, LPSTR, DWORD, LPDWORD, LPDWORD, LPDWORD, LPSTR, DWORD);
35 static BOOL (WINAPI *pGetVolumePathNamesForVolumeNameA)(LPCSTR, LPSTR, DWORD, LPDWORD);
36 static BOOL (WINAPI *pGetVolumePathNamesForVolumeNameW)(LPCWSTR, LPWSTR, DWORD, LPDWORD);
38 /* ############################### */
40 static void test_query_dos_deviceA(void)
42 char drivestr[] = "a:";
43 char *p, *buffer, buffer2[2000];
44 DWORD ret, ret2, buflen=32768;
45 BOOL found = FALSE;
47 /* callers must guess the buffer size */
48 SetLastError(0xdeadbeef);
49 ret = QueryDosDeviceA( NULL, NULL, 0 );
50 ok(!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER,
51 "QueryDosDeviceA(no buffer): returned %u, le=%u\n", ret, GetLastError());
53 buffer = HeapAlloc( GetProcessHeap(), 0, buflen );
54 SetLastError(0xdeadbeef);
55 ret = QueryDosDeviceA( NULL, buffer, buflen );
56 ok((ret && GetLastError() != ERROR_INSUFFICIENT_BUFFER),
57 "QueryDosDeviceA failed to return list, last error %u\n", GetLastError());
59 if (ret && GetLastError() != ERROR_INSUFFICIENT_BUFFER) {
60 p = buffer;
61 for (;;) {
62 if (!strlen(p)) break;
63 ret2 = QueryDosDeviceA( p, buffer2, sizeof(buffer2) );
64 ok(ret2, "QueryDosDeviceA failed to return current mapping for %s, last error %u\n", p, GetLastError());
65 p += strlen(p) + 1;
66 if (ret <= (p-buffer)) break;
70 for (;drivestr[0] <= 'z'; drivestr[0]++) {
71 /* Older W2K fails with ERROR_INSUFFICIENT_BUFFER when buflen is > 32767 */
72 ret = QueryDosDeviceA( drivestr, buffer, buflen - 1);
73 ok(ret || GetLastError() == ERROR_FILE_NOT_FOUND,
74 "QueryDosDeviceA failed to return current mapping for %s, last error %u\n", drivestr, GetLastError());
75 if(ret) {
76 for (p = buffer; *p; p++) *p = toupper(*p);
77 if (strstr(buffer, "HARDDISK") || strstr(buffer, "RAMDISK")) found = TRUE;
80 ok(found, "expected at least one devicename to contain HARDDISK or RAMDISK\n");
81 HeapFree( GetProcessHeap(), 0, buffer );
84 static void test_define_dos_deviceA(void)
86 char drivestr[3];
87 char buf[MAX_PATH];
88 DWORD ret;
90 /* Find an unused drive letter */
91 drivestr[1] = ':';
92 drivestr[2] = 0;
93 for (drivestr[0] = 'a'; drivestr[0] <= 'z'; drivestr[0]++) {
94 ret = QueryDosDeviceA( drivestr, buf, sizeof(buf));
95 if (!ret) break;
97 if (drivestr[0] > 'z') {
98 skip("can't test creating a dos drive, none available\n");
99 return;
102 /* Map it to point to the current directory */
103 ret = GetCurrentDirectory(sizeof(buf), buf);
104 ok(ret, "GetCurrentDir\n");
106 ret = DefineDosDeviceA(0, drivestr, buf);
107 todo_wine
108 ok(ret, "Could not make drive %s point to %s!\n", drivestr, buf);
110 if (!ret) {
111 skip("can't test removing fake drive\n");
112 } else {
113 ret = DefineDosDeviceA(DDD_REMOVE_DEFINITION, drivestr, NULL);
114 ok(ret, "Could not remove fake drive %s!\n", drivestr);
118 static void test_FindFirstVolume(void)
120 char volume[51];
121 HANDLE handle;
123 /* not present before w2k */
124 if (!pFindFirstVolumeA) {
125 win_skip("FindFirstVolumeA not found\n");
126 return;
129 handle = pFindFirstVolumeA( volume, 0 );
130 ok( handle == INVALID_HANDLE_VALUE, "succeeded with short buffer\n" );
131 ok( GetLastError() == ERROR_MORE_DATA || /* XP */
132 GetLastError() == ERROR_FILENAME_EXCED_RANGE, /* Vista */
133 "wrong error %u\n", GetLastError() );
134 handle = pFindFirstVolumeA( volume, 49 );
135 ok( handle == INVALID_HANDLE_VALUE, "succeeded with short buffer\n" );
136 ok( GetLastError() == ERROR_FILENAME_EXCED_RANGE, "wrong error %u\n", GetLastError() );
137 handle = pFindFirstVolumeA( volume, 51 );
138 ok( handle != INVALID_HANDLE_VALUE, "failed err %u\n", GetLastError() );
139 if (handle != INVALID_HANDLE_VALUE)
143 ok( strlen(volume) == 49, "bad volume name %s\n", volume );
144 ok( !memcmp( volume, "\\\\?\\Volume{", 11 ), "bad volume name %s\n", volume );
145 ok( !memcmp( volume + 47, "}\\", 2 ), "bad volume name %s\n", volume );
146 } while (pFindNextVolumeA( handle, volume, MAX_PATH ));
147 ok( GetLastError() == ERROR_NO_MORE_FILES, "wrong error %u\n", GetLastError() );
148 pFindVolumeClose( handle );
152 static void test_GetVolumeNameForVolumeMountPointA(void)
154 BOOL ret;
155 char volume[MAX_PATH], path[] = "c:\\";
156 DWORD len = sizeof(volume), reti;
157 char temp_path[MAX_PATH];
159 /* not present before w2k */
160 if (!pGetVolumeNameForVolumeMountPointA) {
161 win_skip("GetVolumeNameForVolumeMountPointA not found\n");
162 return;
165 reti = GetTempPathA(MAX_PATH, temp_path);
166 ok(reti != 0, "GetTempPathA error %d\n", GetLastError());
167 ok(reti < MAX_PATH, "temp path should fit into MAX_PATH\n");
169 ret = pGetVolumeNameForVolumeMountPointA(path, volume, 0);
170 ok(ret == FALSE, "GetVolumeNameForVolumeMountPointA succeeded\n");
171 ok(GetLastError() == ERROR_FILENAME_EXCED_RANGE ||
172 GetLastError() == ERROR_INVALID_PARAMETER, /* Vista */
173 "wrong error, last=%d\n", GetLastError());
175 if (0) { /* these crash on XP */
176 ret = pGetVolumeNameForVolumeMountPointA(path, NULL, len);
177 ok(ret == FALSE, "GetVolumeNameForVolumeMountPointA succeeded\n");
179 ret = pGetVolumeNameForVolumeMountPointA(NULL, volume, len);
180 ok(ret == FALSE, "GetVolumeNameForVolumeMountPointA succeeded\n");
183 ret = pGetVolumeNameForVolumeMountPointA(path, volume, len);
184 ok(ret == TRUE, "GetVolumeNameForVolumeMountPointA failed\n");
185 ok(!strncmp( volume, "\\\\?\\Volume{", 11),
186 "GetVolumeNameForVolumeMountPointA failed to return valid string <%s>\n",
187 volume);
189 /* test with too small buffer */
190 ret = pGetVolumeNameForVolumeMountPointA(path, volume, 10);
191 ok(ret == FALSE && GetLastError() == ERROR_FILENAME_EXCED_RANGE,
192 "GetVolumeNameForVolumeMountPointA failed, wrong error returned, was %d, should be ERROR_FILENAME_EXCED_RANGE\n",
193 GetLastError());
195 /* Try on a arbitrary directory */
196 /* On FAT filesystems it seems that GetLastError() is set to
197 ERROR_INVALID_FUNCTION. */
198 ret = pGetVolumeNameForVolumeMountPointA(temp_path, volume, len);
199 ok(ret == FALSE && (GetLastError() == ERROR_NOT_A_REPARSE_POINT ||
200 GetLastError() == ERROR_INVALID_FUNCTION),
201 "GetVolumeNameForVolumeMountPointA failed on %s, last=%d\n",
202 temp_path, GetLastError());
204 /* Try on a nonexistent dos drive */
205 path[2] = 0;
206 for (;path[0] <= 'z'; path[0]++) {
207 ret = QueryDosDeviceA( path, volume, len);
208 if(!ret) break;
210 if (path[0] <= 'z')
212 path[2] = '\\';
213 ret = pGetVolumeNameForVolumeMountPointA(path, volume, len);
214 ok(ret == FALSE && GetLastError() == ERROR_FILE_NOT_FOUND,
215 "GetVolumeNameForVolumeMountPointA failed on %s, last=%d\n",
216 path, GetLastError());
218 /* Try without trailing \ and on a nonexistent dos drive */
219 path[2] = 0;
220 ret = pGetVolumeNameForVolumeMountPointA(path, volume, len);
221 ok(ret == FALSE && GetLastError() == ERROR_INVALID_NAME,
222 "GetVolumeNameForVolumeMountPointA failed on %s, last=%d\n",
223 path, GetLastError());
227 static void test_GetVolumeNameForVolumeMountPointW(void)
229 BOOL ret;
230 WCHAR volume[MAX_PATH], path[] = {'c',':','\\',0};
231 DWORD len = sizeof(volume) / sizeof(WCHAR);
233 /* not present before w2k */
234 if (!pGetVolumeNameForVolumeMountPointW) {
235 win_skip("GetVolumeNameForVolumeMountPointW not found\n");
236 return;
239 ret = pGetVolumeNameForVolumeMountPointW(path, volume, 0);
240 ok(ret == FALSE, "GetVolumeNameForVolumeMountPointA succeeded\n");
241 ok(GetLastError() == ERROR_FILENAME_EXCED_RANGE ||
242 GetLastError() == ERROR_INVALID_PARAMETER, /* Vista */
243 "wrong error, last=%d\n", GetLastError());
245 if (0) { /* these crash on XP */
246 ret = pGetVolumeNameForVolumeMountPointW(path, NULL, len);
247 ok(ret == FALSE, "GetVolumeNameForVolumeMountPointW succeeded\n");
249 ret = pGetVolumeNameForVolumeMountPointW(NULL, volume, len);
250 ok(ret == FALSE, "GetVolumeNameForVolumeMountPointW succeeded\n");
253 ret = pGetVolumeNameForVolumeMountPointW(path, volume, len);
254 ok(ret == TRUE, "GetVolumeNameForVolumeMountPointW failed\n");
257 static void test_GetLogicalDriveStringsA(void)
259 UINT size, size2;
260 char *buf, *ptr;
262 ok( pGetLogicalDriveStringsA != NULL, "GetLogicalDriveStringsA not available\n");
263 if(!pGetLogicalDriveStringsA) {
264 return;
267 size = pGetLogicalDriveStringsA(0, NULL);
268 ok(size%4 == 1, "size = %d\n", size);
270 buf = HeapAlloc(GetProcessHeap(), 0, size);
272 *buf = 0;
273 size2 = pGetLogicalDriveStringsA(2, buf);
274 ok(size2 == size, "size2 = %d\n", size2);
275 ok(!*buf, "buf changed\n");
277 size2 = pGetLogicalDriveStringsA(size, buf);
278 ok(size2 == size-1, "size2 = %d\n", size2);
280 for(ptr = buf; ptr < buf+size2; ptr += 4) {
281 ok(('A' <= *ptr && *ptr <= 'Z'), "device name '%c' is not uppercase\n", *ptr);
282 ok(ptr[1] == ':', "ptr[1] = %c, expected ':'\n", ptr[1]);
283 ok(ptr[2] == '\\', "ptr[2] = %c expected '\\'\n", ptr[2]);
284 ok(!ptr[3], "ptr[3] = %c expected nullbyte\n", ptr[3]);
286 ok(!*ptr, "buf[size2] is not nullbyte\n");
288 HeapFree(GetProcessHeap(), 0, buf);
291 static void test_GetLogicalDriveStringsW(void)
293 UINT size, size2;
294 WCHAR *buf, *ptr;
296 ok( pGetLogicalDriveStringsW != NULL, "GetLogicalDriveStringsW not available\n");
297 if(!pGetLogicalDriveStringsW) {
298 return;
301 SetLastError(0xdeadbeef);
302 size = pGetLogicalDriveStringsW(0, NULL);
303 if (size == 0 && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED) {
304 win_skip("GetLogicalDriveStringsW not implemented\n");
305 return;
307 ok(size%4 == 1, "size = %d\n", size);
309 buf = HeapAlloc(GetProcessHeap(), 0, size*sizeof(WCHAR));
311 *buf = 0;
312 size2 = pGetLogicalDriveStringsW(2, buf);
313 ok(size2 == size, "size2 = %d\n", size2);
314 ok(!*buf, "buf changed\n");
316 size2 = pGetLogicalDriveStringsW(size, buf);
317 ok(size2 == size-1, "size2 = %d\n", size2);
319 for(ptr = buf; ptr < buf+size2; ptr += 4) {
320 ok('A' <= *ptr && *ptr <= 'Z', "device name '%c' is not uppercase\n", *ptr);
321 ok(ptr[1] == ':', "ptr[1] = %c, expected ':'\n", ptr[1]);
322 ok(ptr[2] == '\\', "ptr[2] = %c expected '\\'\n", ptr[2]);
323 ok(!ptr[3], "ptr[3] = %c expected nullbyte\n", ptr[3]);
325 ok(!*ptr, "buf[size2] is not nullbyte\n");
327 HeapFree(GetProcessHeap(), 0, buf);
330 static void test_GetVolumeInformationA(void)
332 BOOL ret;
333 UINT result;
334 char Root_Colon[]="C:";
335 char Root_Slash[]="C:\\";
336 char Root_UNC[]="\\\\?\\C:\\";
337 char volume[MAX_PATH+1];
338 DWORD vol_name_size=MAX_PATH+1, vol_serial_num=-1, max_comp_len=0, fs_flags=0, fs_name_len=MAX_PATH+1;
339 char vol_name_buf[MAX_PATH+1], fs_name_buf[MAX_PATH+1];
340 char windowsdir[MAX_PATH+10];
341 char currentdir[MAX_PATH+1];
343 ok( pGetVolumeInformationA != NULL, "GetVolumeInformationA not found\n");
344 if(!pGetVolumeInformationA) {
345 return;
348 /* get windows drive letter and update strings for testing */
349 result = GetWindowsDirectory(windowsdir, sizeof(windowsdir));
350 ok(result < sizeof(windowsdir), "windowsdir is abnormally long!\n");
351 ok(result != 0, "GetWindowsDirectory: error %d\n", GetLastError());
352 Root_Colon[0] = windowsdir[0];
353 Root_Slash[0] = windowsdir[0];
354 Root_UNC[4] = windowsdir[0];
356 result = GetCurrentDirectory(MAX_PATH, currentdir);
357 ok(result, "GetCurrentDirectory: error %d\n", GetLastError());
358 /* Note that GetCurrentDir yields no trailing slash for subdirs */
360 /* check for NO error on no trailing \ when current dir is root dir */
361 ret = SetCurrentDirectory(Root_Slash);
362 ok(ret, "SetCurrentDirectory: error %d\n", GetLastError());
363 ret = pGetVolumeInformationA(Root_Colon, vol_name_buf, vol_name_size, NULL,
364 NULL, NULL, fs_name_buf, fs_name_len);
365 ok(ret, "GetVolumeInformationA root failed, last error %u\n", GetLastError());
367 /* check for error on no trailing \ when current dir is subdir (windows) of queried drive */
368 ret = SetCurrentDirectory(windowsdir);
369 ok(ret, "SetCurrentDirectory: error %d\n", GetLastError());
370 SetLastError(0xdeadbeef);
371 ret = pGetVolumeInformationA(Root_Colon, vol_name_buf, vol_name_size, NULL,
372 NULL, NULL, fs_name_buf, fs_name_len);
373 ok(!ret && (GetLastError() == ERROR_INVALID_NAME),
374 "GetVolumeInformationA did%s fail, last error %u\n", ret ? " not":"", GetLastError());
376 /* reset current directory */
377 ret = SetCurrentDirectory(currentdir);
378 ok(ret, "SetCurrentDirectory: error %d\n", GetLastError());
380 if (toupper(currentdir[0]) == toupper(windowsdir[0])) {
381 skip("Please re-run from another device than %c:\n", windowsdir[0]);
382 /* FIXME: Use GetLogicalDrives to find another device to avoid this skip. */
383 } else {
384 char Root_Env[]="=C:"; /* where MS maintains the per volume directory */
385 Root_Env[1] = windowsdir[0];
387 /* C:\windows becomes the current directory on drive C: */
388 /* Note that paths to subdirs are stored without trailing slash, like what GetCurrentDir yields. */
389 ret = SetEnvironmentVariable(Root_Env, windowsdir);
390 ok(ret, "SetEnvironmentVariable %s failed\n", Root_Env);
392 ret = SetCurrentDirectory(windowsdir);
393 ok(ret, "SetCurrentDirectory: error %d\n", GetLastError());
394 ret = SetCurrentDirectory(currentdir);
395 ok(ret, "SetCurrentDirectory: error %d\n", GetLastError());
397 /* windows dir is current on the root drive, call fails */
398 SetLastError(0xdeadbeef);
399 ret = pGetVolumeInformationA(Root_Colon, vol_name_buf, vol_name_size, NULL,
400 NULL, NULL, fs_name_buf, fs_name_len);
401 ok(!ret && (GetLastError() == ERROR_INVALID_NAME),
402 "GetVolumeInformationA did%s fail, last error %u\n", ret ? " not":"", GetLastError());
404 /* Try normal drive letter with trailing \ */
405 ret = pGetVolumeInformationA(Root_Slash, vol_name_buf, vol_name_size, NULL,
406 NULL, NULL, fs_name_buf, fs_name_len);
407 ok(ret, "GetVolumeInformationA with \\ failed, last error %u\n", GetLastError());
409 ret = SetCurrentDirectory(Root_Slash);
410 ok(ret, "SetCurrentDirectory: error %d\n", GetLastError());
411 ret = SetCurrentDirectory(currentdir);
412 ok(ret, "SetCurrentDirectory: error %d\n", GetLastError());
414 /* windows dir is STILL CURRENT on root drive; the call fails as before, */
415 /* proving that SetCurrentDir did not remember the other drive's directory */
416 SetLastError(0xdeadbeef);
417 ret = pGetVolumeInformationA(Root_Colon, vol_name_buf, vol_name_size, NULL,
418 NULL, NULL, fs_name_buf, fs_name_len);
419 ok(!ret && (GetLastError() == ERROR_INVALID_NAME),
420 "GetVolumeInformationA did%s fail, last error %u\n", ret ? " not":"", GetLastError());
422 /* Now C:\ becomes the current directory on drive C: */
423 ret = SetEnvironmentVariable(Root_Env, Root_Slash); /* set =C:=C:\ */
424 ok(ret, "SetEnvironmentVariable %s failed\n", Root_Env);
426 /* \ is current on root drive, call succeeds */
427 ret = pGetVolumeInformationA(Root_Colon, vol_name_buf, vol_name_size, NULL,
428 NULL, NULL, fs_name_buf, fs_name_len);
429 ok(ret, "GetVolumeInformationA failed, last error %u\n", GetLastError());
431 /* again, SetCurrentDirectory on another drive does not matter */
432 ret = SetCurrentDirectory(Root_Slash);
433 ok(ret, "SetCurrentDirectory: error %d\n", GetLastError());
434 ret = SetCurrentDirectory(currentdir);
435 ok(ret, "SetCurrentDirectory: error %d\n", GetLastError());
437 /* \ is current on root drive, call succeeds */
438 ret = pGetVolumeInformationA(Root_Colon, vol_name_buf, vol_name_size, NULL,
439 NULL, NULL, fs_name_buf, fs_name_len);
440 ok(ret, "GetVolumeInformationA failed, last error %u\n", GetLastError());
443 /* try null root directory to return "root of the current directory" */
444 ret = pGetVolumeInformationA(NULL, vol_name_buf, vol_name_size, NULL,
445 NULL, NULL, fs_name_buf, fs_name_len);
446 ok(ret, "GetVolumeInformationA failed on null root dir, last error %u\n", GetLastError());
448 /* Try normal drive letter with trailing \ */
449 ret = pGetVolumeInformationA(Root_Slash, vol_name_buf, vol_name_size,
450 &vol_serial_num, &max_comp_len, &fs_flags, fs_name_buf, fs_name_len);
451 ok(ret, "GetVolumeInformationA failed, root=%s, last error=%u\n", Root_Slash, GetLastError());
453 /* try again with drive letter and the "disable parsing" prefix */
454 SetLastError(0xdeadbeef);
455 ret = pGetVolumeInformationA(Root_UNC, vol_name_buf, vol_name_size,
456 &vol_serial_num, &max_comp_len, &fs_flags, fs_name_buf, fs_name_len);
457 ok(ret, "GetVolumeInformationA did%s fail, root=%s, last error=%u\n", ret ? " not":"", Root_UNC, GetLastError());
459 /* try again with device name space */
460 Root_UNC[2] = '.';
461 SetLastError(0xdeadbeef);
462 ret = pGetVolumeInformationA(Root_UNC, vol_name_buf, vol_name_size,
463 &vol_serial_num, &max_comp_len, &fs_flags, fs_name_buf, fs_name_len);
464 ok(ret, "GetVolumeInformationA did%s fail, root=%s, last error=%u\n", ret ? " not":"", Root_UNC, GetLastError());
466 /* try again with a directory off the root - should generate error */
467 if (windowsdir[strlen(windowsdir)-1] != '\\') strcat(windowsdir, "\\");
468 SetLastError(0xdeadbeef);
469 ret = pGetVolumeInformationA(windowsdir, vol_name_buf, vol_name_size,
470 &vol_serial_num, &max_comp_len, &fs_flags, fs_name_buf, fs_name_len);
471 ok(!ret && (GetLastError()==ERROR_DIR_NOT_ROOT),
472 "GetVolumeInformationA did%s fail, root=%s, last error=%u\n", ret ? " not":"", windowsdir, GetLastError());
473 /* A subdir with trailing \ yields DIR_NOT_ROOT instead of INVALID_NAME */
474 if (windowsdir[strlen(windowsdir)-1] == '\\') windowsdir[strlen(windowsdir)-1] = 0;
475 SetLastError(0xdeadbeef);
476 ret = pGetVolumeInformationA(windowsdir, vol_name_buf, vol_name_size,
477 &vol_serial_num, &max_comp_len, &fs_flags, fs_name_buf, fs_name_len);
478 ok(!ret && (GetLastError()==ERROR_INVALID_NAME),
479 "GetVolumeInformationA did%s fail, root=%s, last error=%u\n", ret ? " not":"", windowsdir, GetLastError());
481 if (!pGetVolumeNameForVolumeMountPointA) {
482 win_skip("GetVolumeNameForVolumeMountPointA not found\n");
483 return;
485 /* get the unique volume name for the windows drive */
486 ret = pGetVolumeNameForVolumeMountPointA(Root_Slash, volume, MAX_PATH);
487 ok(ret == TRUE, "GetVolumeNameForVolumeMountPointA failed\n");
489 /* try again with unique volume name */
490 ret = pGetVolumeInformationA(volume, vol_name_buf, vol_name_size,
491 &vol_serial_num, &max_comp_len, &fs_flags, fs_name_buf, fs_name_len);
492 ok(ret, "GetVolumeInformationA failed, root=%s, last error=%u\n", volume, GetLastError());
495 /* Test to check that unique volume name from windows dir mount point */
496 /* matches at least one of the unique volume names returned from the */
497 /* FindFirstVolumeA/FindNextVolumeA list. */
498 static void test_enum_vols(void)
500 DWORD ret;
501 HANDLE hFind = INVALID_HANDLE_VALUE;
502 char Volume_1[MAX_PATH] = {0};
503 char Volume_2[MAX_PATH] = {0};
504 char path[] = "c:\\";
505 BOOL found = FALSE;
506 char windowsdir[MAX_PATH];
508 if (!pGetVolumeNameForVolumeMountPointA) {
509 win_skip("GetVolumeNameForVolumeMountPointA not found\n");
510 return;
513 /*get windows drive letter and update strings for testing */
514 ret = GetWindowsDirectory( windowsdir, sizeof(windowsdir) );
515 ok(ret < sizeof(windowsdir), "windowsdir is abnormally long!\n");
516 ok(ret != 0, "GetWindowsDirecory: error %d\n", GetLastError());
517 path[0] = windowsdir[0];
519 /* get the unique volume name for the windows drive */
520 ret = pGetVolumeNameForVolumeMountPointA( path, Volume_1, MAX_PATH );
521 ok(ret == TRUE, "GetVolumeNameForVolumeMountPointA failed\n");
522 ok(strlen(Volume_1) == 49, "GetVolumeNameForVolumeMountPointA returned wrong length name %s\n", Volume_1);
524 /* get first unique volume name of list */
525 hFind = pFindFirstVolumeA( Volume_2, MAX_PATH );
526 ok(hFind != INVALID_HANDLE_VALUE, "FindFirstVolume failed, err=%u\n",
527 GetLastError());
531 /* validate correct length of unique volume name */
532 ok(strlen(Volume_2) == 49, "Find[First/Next]Volume returned wrong length name %s\n", Volume_1);
533 if (memcmp(Volume_1, Volume_2, 49) == 0)
535 found = TRUE;
536 break;
538 } while (pFindNextVolumeA( hFind, Volume_2, MAX_PATH ));
539 ok(found, "volume name %s not found by Find[First/Next]Volume\n", Volume_1);
540 pFindVolumeClose( hFind );
543 static void test_disk_extents(void)
545 BOOL ret;
546 DWORD size;
547 HANDLE handle;
548 static DWORD data[16];
550 handle = CreateFileA( "\\\\.\\c:", GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0 );
551 if (handle == INVALID_HANDLE_VALUE)
553 win_skip("can't open c: drive %u\n", GetLastError());
554 return;
556 size = 0;
557 ret = DeviceIoControl( handle, IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS, &data,
558 sizeof(data), &data, sizeof(data), &size, NULL );
559 if (!ret && GetLastError() == ERROR_INVALID_FUNCTION)
561 win_skip("IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS not supported\n");
562 CloseHandle( handle );
563 return;
565 ok(ret, "DeviceIoControl failed %u\n", GetLastError());
566 ok(size == 32, "expected 32, got %u\n", size);
567 CloseHandle( handle );
570 static void test_GetVolumePathNamesForVolumeNameA(void)
572 BOOL ret;
573 char volume[MAX_PATH], buffer[MAX_PATH];
574 DWORD len, error;
576 if (!pGetVolumePathNamesForVolumeNameA || !pGetVolumeNameForVolumeMountPointA)
578 win_skip("required functions not found\n");
579 return;
582 ret = pGetVolumeNameForVolumeMountPointA( "c:\\", volume, sizeof(volume) );
583 ok(ret, "failed to get volume name %u\n", GetLastError());
584 trace("c:\\ -> %s\n", volume);
586 SetLastError( 0xdeadbeef );
587 ret = pGetVolumePathNamesForVolumeNameA( NULL, NULL, 0, NULL );
588 error = GetLastError();
589 ok(!ret, "expected failure\n");
590 ok(error == ERROR_INVALID_NAME, "expected ERROR_INVALID_NAME got %u\n", error);
592 SetLastError( 0xdeadbeef );
593 ret = pGetVolumePathNamesForVolumeNameA( "", NULL, 0, NULL );
594 error = GetLastError();
595 ok(!ret, "expected failure\n");
596 ok(error == ERROR_INVALID_NAME, "expected ERROR_INVALID_NAME got %u\n", error);
598 SetLastError( 0xdeadbeef );
599 ret = pGetVolumePathNamesForVolumeNameA( volume, NULL, 0, NULL );
600 error = GetLastError();
601 ok(!ret, "expected failure\n");
602 ok(error == ERROR_MORE_DATA, "expected ERROR_MORE_DATA got %u\n", error);
604 SetLastError( 0xdeadbeef );
605 ret = pGetVolumePathNamesForVolumeNameA( volume, buffer, 0, NULL );
606 error = GetLastError();
607 ok(!ret, "expected failure\n");
608 ok(error == ERROR_MORE_DATA, "expected ERROR_MORE_DATA got %u\n", error);
610 memset( buffer, 0xff, sizeof(buffer) );
611 ret = pGetVolumePathNamesForVolumeNameA( volume, buffer, sizeof(buffer), NULL );
612 ok(ret, "failed to get path names %u\n", GetLastError());
613 ok(!strcmp( "C:\\", buffer ), "expected \"\\C:\" got \"%s\"\n", buffer);
614 ok(!buffer[4], "expected double null-terminated buffer\n");
616 len = 0;
617 SetLastError( 0xdeadbeef );
618 ret = pGetVolumePathNamesForVolumeNameA( NULL, NULL, 0, &len );
619 error = GetLastError();
620 ok(!ret, "expected failure\n");
621 ok(error == ERROR_INVALID_NAME, "expected ERROR_INVALID_NAME got %u\n", error);
623 len = 0;
624 SetLastError( 0xdeadbeef );
625 ret = pGetVolumePathNamesForVolumeNameA( NULL, NULL, sizeof(buffer), &len );
626 error = GetLastError();
627 ok(!ret, "expected failure\n");
628 ok(error == ERROR_INVALID_NAME, "expected ERROR_INVALID_NAME got %u\n", error);
630 len = 0;
631 SetLastError( 0xdeadbeef );
632 ret = pGetVolumePathNamesForVolumeNameA( NULL, buffer, sizeof(buffer), &len );
633 error = GetLastError();
634 ok(!ret, "expected failure\n");
635 ok(error == ERROR_INVALID_NAME, "expected ERROR_INVALID_NAME got %u\n", error);
637 len = 0;
638 SetLastError( 0xdeadbeef );
639 ret = pGetVolumePathNamesForVolumeNameA( NULL, buffer, sizeof(buffer), &len );
640 error = GetLastError();
641 ok(!ret, "expected failure\n");
642 ok(error == ERROR_INVALID_NAME, "expected ERROR_INVALID_NAME got %u\n", error);
644 len = 0;
645 memset( buffer, 0xff, sizeof(buffer) );
646 ret = pGetVolumePathNamesForVolumeNameA( volume, buffer, sizeof(buffer), &len );
647 ok(ret, "failed to get path names %u\n", GetLastError());
648 ok(len == 5 || broken(len == 2), "expected 5 got %u\n", len);
649 ok(!strcmp( "C:\\", buffer ), "expected \"\\C:\" got \"%s\"\n", buffer);
650 ok(!buffer[4], "expected double null-terminated buffer\n");
653 static void test_GetVolumePathNamesForVolumeNameW(void)
655 static const WCHAR empty[] = {0};
656 static const WCHAR drive_c[] = {'c',':','\\',0};
657 static const WCHAR volume_null[] = {'\\','\\','?','\\','V','o','l','u','m','e',
658 '{','0','0','0','0','0','0','0','0','-','0','0','0','0','-','0','0','0','0',
659 '-','0','0','0','0','-','0','0','0','0','0','0','0','0','0','0','0','0','}','\\',0};
660 BOOL ret;
661 WCHAR volume[MAX_PATH], buffer[MAX_PATH];
662 DWORD len, error;
664 if (!pGetVolumePathNamesForVolumeNameW || !pGetVolumeNameForVolumeMountPointW)
666 win_skip("required functions not found\n");
667 return;
670 ret = pGetVolumeNameForVolumeMountPointW( drive_c, volume, sizeof(volume)/sizeof(volume[0]) );
671 ok(ret, "failed to get volume name %u\n", GetLastError());
673 SetLastError( 0xdeadbeef );
674 ret = pGetVolumePathNamesForVolumeNameW( empty, NULL, 0, NULL );
675 error = GetLastError();
676 ok(!ret, "expected failure\n");
677 ok(error == ERROR_INVALID_NAME, "expected ERROR_INVALID_NAME got %u\n", error);
679 SetLastError( 0xdeadbeef );
680 ret = pGetVolumePathNamesForVolumeNameW( volume, NULL, 0, NULL );
681 error = GetLastError();
682 ok(!ret, "expected failure\n");
683 ok(error == ERROR_MORE_DATA, "expected ERROR_MORE_DATA got %u\n", error);
685 SetLastError( 0xdeadbeef );
686 ret = pGetVolumePathNamesForVolumeNameW( volume, buffer, 0, NULL );
687 error = GetLastError();
688 ok(!ret, "expected failure\n");
689 ok(error == ERROR_MORE_DATA, "expected ERROR_MORE_DATA got %u\n", error);
691 if (0) { /* crash */
692 ret = pGetVolumePathNamesForVolumeNameW( volume, NULL, sizeof(buffer), NULL );
693 ok(ret, "failed to get path names %u\n", GetLastError());
696 ret = pGetVolumePathNamesForVolumeNameW( volume, buffer, sizeof(buffer), NULL );
697 ok(ret, "failed to get path names %u\n", GetLastError());
699 len = 0;
700 memset( buffer, 0xff, sizeof(buffer) );
701 ret = pGetVolumePathNamesForVolumeNameW( volume, buffer, sizeof(buffer), &len );
702 ok(ret, "failed to get path names %u\n", GetLastError());
703 ok(len == 5, "expected 5 got %u\n", len);
704 ok(!buffer[4], "expected double null-terminated buffer\n");
706 len = 0;
707 volume[1] = '?';
708 volume[lstrlenW( volume ) - 1] = 0;
709 SetLastError( 0xdeadbeef );
710 ret = pGetVolumePathNamesForVolumeNameW( volume, buffer, sizeof(buffer), &len );
711 error = GetLastError();
712 ok(!ret, "expected failure\n");
713 ok(error == ERROR_INVALID_NAME, "expected ERROR_INVALID_NAME got %u\n", error);
715 len = 0;
716 volume[0] = '\\';
717 volume[1] = 0;
718 SetLastError( 0xdeadbeef );
719 ret = pGetVolumePathNamesForVolumeNameW( volume, buffer, sizeof(buffer), &len );
720 error = GetLastError();
721 ok(!ret, "expected failure\n");
722 todo_wine ok(error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER got %u\n", error);
724 len = 0;
725 lstrcpyW( volume, volume_null );
726 SetLastError( 0xdeadbeef );
727 ret = pGetVolumePathNamesForVolumeNameW( volume, buffer, sizeof(buffer), &len );
728 error = GetLastError();
729 ok(!ret, "expected failure\n");
730 ok(error == ERROR_FILE_NOT_FOUND, "expected ERROR_FILE_NOT_FOUND got %u\n", error);
733 START_TEST(volume)
735 hdll = GetModuleHandleA("kernel32.dll");
736 pGetVolumeNameForVolumeMountPointA = (void *) GetProcAddress(hdll, "GetVolumeNameForVolumeMountPointA");
737 pGetVolumeNameForVolumeMountPointW = (void *) GetProcAddress(hdll, "GetVolumeNameForVolumeMountPointW");
738 pFindFirstVolumeA = (void *) GetProcAddress(hdll, "FindFirstVolumeA");
739 pFindNextVolumeA = (void *) GetProcAddress(hdll, "FindNextVolumeA");
740 pFindVolumeClose = (void *) GetProcAddress(hdll, "FindVolumeClose");
741 pGetLogicalDriveStringsA = (void *) GetProcAddress(hdll, "GetLogicalDriveStringsA");
742 pGetLogicalDriveStringsW = (void *) GetProcAddress(hdll, "GetLogicalDriveStringsW");
743 pGetVolumeInformationA = (void *) GetProcAddress(hdll, "GetVolumeInformationA");
744 pGetVolumePathNamesForVolumeNameA = (void *) GetProcAddress(hdll, "GetVolumePathNamesForVolumeNameA");
745 pGetVolumePathNamesForVolumeNameW = (void *) GetProcAddress(hdll, "GetVolumePathNamesForVolumeNameW");
747 test_query_dos_deviceA();
748 test_define_dos_deviceA();
749 test_FindFirstVolume();
750 test_GetVolumeNameForVolumeMountPointA();
751 test_GetVolumeNameForVolumeMountPointW();
752 test_GetLogicalDriveStringsA();
753 test_GetLogicalDriveStringsW();
754 test_GetVolumeInformationA();
755 test_enum_vols();
756 test_disk_extents();
757 test_GetVolumePathNamesForVolumeNameA();
758 test_GetVolumePathNamesForVolumeNameW();