d3dx9: Implement ID3DXBaseEffect::GetAnnotation().
[wine/multimedia.git] / dlls / kernel32 / tests / volume.c
blobfb920f3bc570edb0ccf77f317fa0d075588d0fa0
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 buffer = HeapAlloc( GetProcessHeap(), 0, buflen );
48 SetLastError(0xdeadbeef);
49 ret = QueryDosDeviceA( NULL, buffer, buflen );
50 ok((ret && GetLastError() != ERROR_INSUFFICIENT_BUFFER),
51 "QueryDosDeviceA failed to return list, last error %u\n", GetLastError());
53 if (ret && GetLastError() != ERROR_INSUFFICIENT_BUFFER) {
54 p = buffer;
55 for (;;) {
56 if (!strlen(p)) break;
57 ret2 = QueryDosDeviceA( p, buffer2, sizeof(buffer2) );
58 ok(ret2, "QueryDosDeviceA failed to return current mapping for %s, last error %u\n", p, GetLastError());
59 p += strlen(p) + 1;
60 if (ret <= (p-buffer)) break;
64 for (;drivestr[0] <= 'z'; drivestr[0]++) {
65 /* Older W2K fails with ERROR_INSUFFICIENT_BUFFER when buflen is > 32767 */
66 ret = QueryDosDeviceA( drivestr, buffer, buflen - 1);
67 ok(ret || GetLastError() == ERROR_FILE_NOT_FOUND,
68 "QueryDosDeviceA failed to return current mapping for %s, last error %u\n", drivestr, GetLastError());
69 if(ret) {
70 for (p = buffer; *p; p++) *p = toupper(*p);
71 if (strstr(buffer, "HARDDISK") || strstr(buffer, "RAMDISK")) found = TRUE;
74 ok(found, "expected at least one devicename to contain HARDDISK or RAMDISK\n");
75 HeapFree( GetProcessHeap(), 0, buffer );
78 static void test_FindFirstVolume(void)
80 char volume[51];
81 HANDLE handle;
83 /* not present before w2k */
84 if (!pFindFirstVolumeA) {
85 win_skip("FindFirstVolumeA not found\n");
86 return;
89 handle = pFindFirstVolumeA( volume, 0 );
90 ok( handle == INVALID_HANDLE_VALUE, "succeeded with short buffer\n" );
91 ok( GetLastError() == ERROR_MORE_DATA || /* XP */
92 GetLastError() == ERROR_FILENAME_EXCED_RANGE, /* Vista */
93 "wrong error %u\n", GetLastError() );
94 handle = pFindFirstVolumeA( volume, 49 );
95 ok( handle == INVALID_HANDLE_VALUE, "succeeded with short buffer\n" );
96 ok( GetLastError() == ERROR_FILENAME_EXCED_RANGE, "wrong error %u\n", GetLastError() );
97 handle = pFindFirstVolumeA( volume, 51 );
98 ok( handle != INVALID_HANDLE_VALUE, "failed err %u\n", GetLastError() );
99 if (handle != INVALID_HANDLE_VALUE)
103 ok( strlen(volume) == 49, "bad volume name %s\n", volume );
104 ok( !memcmp( volume, "\\\\?\\Volume{", 11 ), "bad volume name %s\n", volume );
105 ok( !memcmp( volume + 47, "}\\", 2 ), "bad volume name %s\n", volume );
106 } while (pFindNextVolumeA( handle, volume, MAX_PATH ));
107 ok( GetLastError() == ERROR_NO_MORE_FILES, "wrong error %u\n", GetLastError() );
108 pFindVolumeClose( handle );
112 static void test_GetVolumeNameForVolumeMountPointA(void)
114 BOOL ret;
115 char volume[MAX_PATH], path[] = "c:\\";
116 DWORD len = sizeof(volume), reti;
117 char temp_path[MAX_PATH];
119 /* not present before w2k */
120 if (!pGetVolumeNameForVolumeMountPointA) {
121 win_skip("GetVolumeNameForVolumeMountPointA not found\n");
122 return;
125 reti = GetTempPathA(MAX_PATH, temp_path);
126 ok(reti != 0, "GetTempPathA error %d\n", GetLastError());
127 ok(reti < MAX_PATH, "temp path should fit into MAX_PATH\n");
129 ret = pGetVolumeNameForVolumeMountPointA(path, volume, 0);
130 ok(ret == FALSE, "GetVolumeNameForVolumeMountPointA succeeded\n");
131 ok(GetLastError() == ERROR_FILENAME_EXCED_RANGE ||
132 GetLastError() == ERROR_INVALID_PARAMETER, /* Vista */
133 "wrong error, last=%d\n", GetLastError());
135 if (0) { /* these crash on XP */
136 ret = pGetVolumeNameForVolumeMountPointA(path, NULL, len);
137 ok(ret == FALSE, "GetVolumeNameForVolumeMountPointA succeeded\n");
139 ret = pGetVolumeNameForVolumeMountPointA(NULL, volume, len);
140 ok(ret == FALSE, "GetVolumeNameForVolumeMountPointA succeeded\n");
143 ret = pGetVolumeNameForVolumeMountPointA(path, volume, len);
144 ok(ret == TRUE, "GetVolumeNameForVolumeMountPointA failed\n");
145 ok(!strncmp( volume, "\\\\?\\Volume{", 11),
146 "GetVolumeNameForVolumeMountPointA failed to return valid string <%s>\n",
147 volume);
149 /* test with too small buffer */
150 ret = pGetVolumeNameForVolumeMountPointA(path, volume, 10);
151 ok(ret == FALSE && GetLastError() == ERROR_FILENAME_EXCED_RANGE,
152 "GetVolumeNameForVolumeMountPointA failed, wrong error returned, was %d, should be ERROR_FILENAME_EXCED_RANGE\n",
153 GetLastError());
155 /* Try on a arbitrary directory */
156 /* On FAT filesystems it seems that GetLastError() is set to
157 ERROR_INVALID_FUNCTION. */
158 ret = pGetVolumeNameForVolumeMountPointA(temp_path, volume, len);
159 ok(ret == FALSE && (GetLastError() == ERROR_NOT_A_REPARSE_POINT ||
160 GetLastError() == ERROR_INVALID_FUNCTION),
161 "GetVolumeNameForVolumeMountPointA failed on %s, last=%d\n",
162 temp_path, GetLastError());
164 /* Try on a nonexistent dos drive */
165 path[2] = 0;
166 for (;path[0] <= 'z'; path[0]++) {
167 ret = QueryDosDeviceA( path, volume, len);
168 if(!ret) break;
170 if (path[0] <= 'z')
172 path[2] = '\\';
173 ret = pGetVolumeNameForVolumeMountPointA(path, volume, len);
174 ok(ret == FALSE && GetLastError() == ERROR_FILE_NOT_FOUND,
175 "GetVolumeNameForVolumeMountPointA failed on %s, last=%d\n",
176 path, GetLastError());
178 /* Try without trailing \ and on a nonexistent dos drive */
179 path[2] = 0;
180 ret = pGetVolumeNameForVolumeMountPointA(path, volume, len);
181 ok(ret == FALSE && GetLastError() == ERROR_INVALID_NAME,
182 "GetVolumeNameForVolumeMountPointA failed on %s, last=%d\n",
183 path, GetLastError());
187 static void test_GetVolumeNameForVolumeMountPointW(void)
189 BOOL ret;
190 WCHAR volume[MAX_PATH], path[] = {'c',':','\\',0};
191 DWORD len = sizeof(volume) / sizeof(WCHAR);
193 /* not present before w2k */
194 if (!pGetVolumeNameForVolumeMountPointW) {
195 win_skip("GetVolumeNameForVolumeMountPointW not found\n");
196 return;
199 ret = pGetVolumeNameForVolumeMountPointW(path, volume, 0);
200 ok(ret == FALSE, "GetVolumeNameForVolumeMountPointA succeeded\n");
201 ok(GetLastError() == ERROR_FILENAME_EXCED_RANGE ||
202 GetLastError() == ERROR_INVALID_PARAMETER, /* Vista */
203 "wrong error, last=%d\n", GetLastError());
205 if (0) { /* these crash on XP */
206 ret = pGetVolumeNameForVolumeMountPointW(path, NULL, len);
207 ok(ret == FALSE, "GetVolumeNameForVolumeMountPointW succeeded\n");
209 ret = pGetVolumeNameForVolumeMountPointW(NULL, volume, len);
210 ok(ret == FALSE, "GetVolumeNameForVolumeMountPointW succeeded\n");
213 ret = pGetVolumeNameForVolumeMountPointW(path, volume, len);
214 ok(ret == TRUE, "GetVolumeNameForVolumeMountPointW failed\n");
217 static void test_GetLogicalDriveStringsA(void)
219 UINT size, size2;
220 char *buf, *ptr;
222 ok( pGetLogicalDriveStringsA != NULL, "GetLogicalDriveStringsA not available\n");
223 if(!pGetLogicalDriveStringsA) {
224 return;
227 size = pGetLogicalDriveStringsA(0, NULL);
228 ok(size%4 == 1, "size = %d\n", size);
230 buf = HeapAlloc(GetProcessHeap(), 0, size);
232 *buf = 0;
233 size2 = pGetLogicalDriveStringsA(2, buf);
234 ok(size2 == size, "size2 = %d\n", size2);
235 ok(!*buf, "buf changed\n");
237 size2 = pGetLogicalDriveStringsA(size, buf);
238 ok(size2 == size-1, "size2 = %d\n", size2);
240 for(ptr = buf; ptr < buf+size2; ptr += 4) {
241 ok(('A' <= *ptr && *ptr <= 'Z'), "device name '%c' is not uppercase\n", *ptr);
242 ok(ptr[1] == ':', "ptr[1] = %c, expected ':'\n", ptr[1]);
243 ok(ptr[2] == '\\', "ptr[2] = %c expected '\\'\n", ptr[2]);
244 ok(!ptr[3], "ptr[3] = %c expected nullbyte\n", ptr[3]);
246 ok(!*ptr, "buf[size2] is not nullbyte\n");
248 HeapFree(GetProcessHeap(), 0, buf);
251 static void test_GetLogicalDriveStringsW(void)
253 UINT size, size2;
254 WCHAR *buf, *ptr;
256 ok( pGetLogicalDriveStringsW != NULL, "GetLogicalDriveStringsW not available\n");
257 if(!pGetLogicalDriveStringsW) {
258 return;
261 SetLastError(0xdeadbeef);
262 size = pGetLogicalDriveStringsW(0, NULL);
263 if (size == 0 && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED) {
264 win_skip("GetLogicalDriveStringsW not implemented\n");
265 return;
267 ok(size%4 == 1, "size = %d\n", size);
269 buf = HeapAlloc(GetProcessHeap(), 0, size*sizeof(WCHAR));
271 *buf = 0;
272 size2 = pGetLogicalDriveStringsW(2, buf);
273 ok(size2 == size, "size2 = %d\n", size2);
274 ok(!*buf, "buf changed\n");
276 size2 = pGetLogicalDriveStringsW(size, buf);
277 ok(size2 == size-1, "size2 = %d\n", size2);
279 for(ptr = buf; ptr < buf+size2; ptr += 4) {
280 ok('A' <= *ptr && *ptr <= 'Z', "device name '%c' is not uppercase\n", *ptr);
281 ok(ptr[1] == ':', "ptr[1] = %c, expected ':'\n", ptr[1]);
282 ok(ptr[2] == '\\', "ptr[2] = %c expected '\\'\n", ptr[2]);
283 ok(!ptr[3], "ptr[3] = %c expected nullbyte\n", ptr[3]);
285 ok(!*ptr, "buf[size2] is not nullbyte\n");
287 HeapFree(GetProcessHeap(), 0, buf);
290 static void test_GetVolumeInformationA(void)
292 BOOL ret;
293 UINT result;
294 char Root_Colon[]="C:";
295 char Root_Slash[]="C:\\";
296 char Root_UNC[]="\\\\?\\C:\\";
297 char volume[MAX_PATH+1];
298 DWORD vol_name_size=MAX_PATH+1, vol_serial_num=-1, max_comp_len=0, fs_flags=0, fs_name_len=MAX_PATH+1;
299 char vol_name_buf[MAX_PATH+1], fs_name_buf[MAX_PATH+1];
300 char windowsdir[MAX_PATH+10];
301 char currentdir[MAX_PATH+1];
303 ok( pGetVolumeInformationA != NULL, "GetVolumeInformationA not found\n");
304 if(!pGetVolumeInformationA) {
305 return;
308 /* get windows drive letter and update strings for testing */
309 result = GetWindowsDirectory(windowsdir, sizeof(windowsdir));
310 ok(result < sizeof(windowsdir), "windowsdir is abnormally long!\n");
311 ok(result != 0, "GetWindowsDirectory: error %d\n", GetLastError());
312 Root_Colon[0] = windowsdir[0];
313 Root_Slash[0] = windowsdir[0];
314 Root_UNC[4] = windowsdir[0];
316 result = GetCurrentDirectory(MAX_PATH, currentdir);
317 ok(result, "GetCurrentDirectory: error %d\n", GetLastError());
318 /* Note that GetCurrentDir yields no trailing slash for subdirs */
320 /* check for NO error on no trailing \ when current dir is root dir */
321 ret = SetCurrentDirectory(Root_Slash);
322 ok(ret, "SetCurrentDirectory: error %d\n", GetLastError());
323 ret = pGetVolumeInformationA(Root_Colon, vol_name_buf, vol_name_size, NULL,
324 NULL, NULL, fs_name_buf, fs_name_len);
325 ok(ret, "GetVolumeInformationA root failed, last error %u\n", GetLastError());
327 /* check for error on no trailing \ when current dir is subdir (windows) of queried drive */
328 ret = SetCurrentDirectory(windowsdir);
329 ok(ret, "SetCurrentDirectory: error %d\n", GetLastError());
330 SetLastError(0xdeadbeef);
331 ret = pGetVolumeInformationA(Root_Colon, vol_name_buf, vol_name_size, NULL,
332 NULL, NULL, fs_name_buf, fs_name_len);
333 ok(!ret && (GetLastError() == ERROR_INVALID_NAME),
334 "GetVolumeInformationA did%s fail, last error %u\n", ret ? " not":"", GetLastError());
336 /* reset current directory */
337 ret = SetCurrentDirectory(currentdir);
338 ok(ret, "SetCurrentDirectory: error %d\n", GetLastError());
340 if (toupper(currentdir[0]) == toupper(windowsdir[0])) {
341 skip("Please re-run from another device than %c:\n", windowsdir[0]);
342 /* FIXME: Use GetLogicalDrives to find another device to avoid this skip. */
343 } else {
344 char Root_Env[]="=C:"; /* where MS maintains the per volume directory */
345 Root_Env[1] = windowsdir[0];
347 /* C:\windows becomes the current directory on drive C: */
348 /* Note that paths to subdirs are stored without trailing slash, like what GetCurrentDir yields. */
349 ret = SetEnvironmentVariable(Root_Env, windowsdir);
350 ok(ret, "SetEnvironmentVariable %s failed\n", Root_Env);
352 ret = SetCurrentDirectory(windowsdir);
353 ok(ret, "SetCurrentDirectory: error %d\n", GetLastError());
354 ret = SetCurrentDirectory(currentdir);
355 ok(ret, "SetCurrentDirectory: error %d\n", GetLastError());
357 /* windows dir is current on the root drive, call fails */
358 SetLastError(0xdeadbeef);
359 ret = pGetVolumeInformationA(Root_Colon, vol_name_buf, vol_name_size, NULL,
360 NULL, NULL, fs_name_buf, fs_name_len);
361 ok(!ret && (GetLastError() == ERROR_INVALID_NAME),
362 "GetVolumeInformationA did%s fail, last error %u\n", ret ? " not":"", GetLastError());
364 /* Try normal drive letter with trailing \ */
365 ret = pGetVolumeInformationA(Root_Slash, vol_name_buf, vol_name_size, NULL,
366 NULL, NULL, fs_name_buf, fs_name_len);
367 ok(ret, "GetVolumeInformationA with \\ failed, last error %u\n", GetLastError());
369 ret = SetCurrentDirectory(Root_Slash);
370 ok(ret, "SetCurrentDirectory: error %d\n", GetLastError());
371 ret = SetCurrentDirectory(currentdir);
372 ok(ret, "SetCurrentDirectory: error %d\n", GetLastError());
374 /* windows dir is STILL CURRENT on root drive; the call fails as before, */
375 /* proving that SetCurrentDir did not remember the other drive's directory */
376 SetLastError(0xdeadbeef);
377 ret = pGetVolumeInformationA(Root_Colon, vol_name_buf, vol_name_size, NULL,
378 NULL, NULL, fs_name_buf, fs_name_len);
379 ok(!ret && (GetLastError() == ERROR_INVALID_NAME),
380 "GetVolumeInformationA did%s fail, last error %u\n", ret ? " not":"", GetLastError());
382 /* Now C:\ becomes the current directory on drive C: */
383 ret = SetEnvironmentVariable(Root_Env, Root_Slash); /* set =C:=C:\ */
384 ok(ret, "SetEnvironmentVariable %s failed\n", Root_Env);
386 /* \ is current on root drive, call succeeds */
387 ret = pGetVolumeInformationA(Root_Colon, vol_name_buf, vol_name_size, NULL,
388 NULL, NULL, fs_name_buf, fs_name_len);
389 ok(ret, "GetVolumeInformationA failed, last error %u\n", GetLastError());
391 /* again, SetCurrentDirectory on another drive does not matter */
392 ret = SetCurrentDirectory(Root_Slash);
393 ok(ret, "SetCurrentDirectory: error %d\n", GetLastError());
394 ret = SetCurrentDirectory(currentdir);
395 ok(ret, "SetCurrentDirectory: error %d\n", GetLastError());
397 /* \ is current on root drive, call succeeds */
398 ret = pGetVolumeInformationA(Root_Colon, vol_name_buf, vol_name_size, NULL,
399 NULL, NULL, fs_name_buf, fs_name_len);
400 ok(ret, "GetVolumeInformationA failed, last error %u\n", GetLastError());
403 /* try null root directory to return "root of the current directory" */
404 ret = pGetVolumeInformationA(NULL, vol_name_buf, vol_name_size, NULL,
405 NULL, NULL, fs_name_buf, fs_name_len);
406 ok(ret, "GetVolumeInformationA failed on null root dir, last error %u\n", GetLastError());
408 /* Try normal drive letter with trailing \ */
409 ret = pGetVolumeInformationA(Root_Slash, vol_name_buf, vol_name_size,
410 &vol_serial_num, &max_comp_len, &fs_flags, fs_name_buf, fs_name_len);
411 ok(ret, "GetVolumeInformationA failed, root=%s, last error=%u\n", Root_Slash, GetLastError());
413 /* try again with drive letter and the "disable parsing" prefix */
414 SetLastError(0xdeadbeef);
415 ret = pGetVolumeInformationA(Root_UNC, vol_name_buf, vol_name_size,
416 &vol_serial_num, &max_comp_len, &fs_flags, fs_name_buf, fs_name_len);
417 ok(ret, "GetVolumeInformationA did%s fail, root=%s, last error=%u\n", ret ? " not":"", Root_UNC, GetLastError());
419 /* try again with device name space */
420 Root_UNC[2] = '.';
421 SetLastError(0xdeadbeef);
422 ret = pGetVolumeInformationA(Root_UNC, vol_name_buf, vol_name_size,
423 &vol_serial_num, &max_comp_len, &fs_flags, fs_name_buf, fs_name_len);
424 ok(ret, "GetVolumeInformationA did%s fail, root=%s, last error=%u\n", ret ? " not":"", Root_UNC, GetLastError());
426 /* try again with a directory off the root - should generate error */
427 if (windowsdir[strlen(windowsdir)-1] != '\\') strcat(windowsdir, "\\");
428 SetLastError(0xdeadbeef);
429 ret = pGetVolumeInformationA(windowsdir, vol_name_buf, vol_name_size,
430 &vol_serial_num, &max_comp_len, &fs_flags, fs_name_buf, fs_name_len);
431 ok(!ret && (GetLastError()==ERROR_DIR_NOT_ROOT),
432 "GetVolumeInformationA did%s fail, root=%s, last error=%u\n", ret ? " not":"", windowsdir, GetLastError());
433 /* A subdir with trailing \ yields DIR_NOT_ROOT instead of INVALID_NAME */
434 if (windowsdir[strlen(windowsdir)-1] == '\\') windowsdir[strlen(windowsdir)-1] = 0;
435 SetLastError(0xdeadbeef);
436 ret = pGetVolumeInformationA(windowsdir, vol_name_buf, vol_name_size,
437 &vol_serial_num, &max_comp_len, &fs_flags, fs_name_buf, fs_name_len);
438 ok(!ret && (GetLastError()==ERROR_INVALID_NAME),
439 "GetVolumeInformationA did%s fail, root=%s, last error=%u\n", ret ? " not":"", windowsdir, GetLastError());
441 if (!pGetVolumeNameForVolumeMountPointA) {
442 win_skip("GetVolumeNameForVolumeMountPointA not found\n");
443 return;
445 /* get the unique volume name for the windows drive */
446 ret = pGetVolumeNameForVolumeMountPointA(Root_Slash, volume, MAX_PATH);
447 ok(ret == TRUE, "GetVolumeNameForVolumeMountPointA failed\n");
449 /* try again with unique volume name */
450 ret = pGetVolumeInformationA(volume, vol_name_buf, vol_name_size,
451 &vol_serial_num, &max_comp_len, &fs_flags, fs_name_buf, fs_name_len);
452 ok(ret, "GetVolumeInformationA failed, root=%s, last error=%u\n", volume, GetLastError());
455 /* Test to check that unique volume name from windows dir mount point */
456 /* matches at least one of the unique volume names returned from the */
457 /* FindFirstVolumeA/FindNextVolumeA list. */
458 static void test_enum_vols(void)
460 DWORD ret;
461 HANDLE hFind = INVALID_HANDLE_VALUE;
462 char Volume_1[MAX_PATH] = {0};
463 char Volume_2[MAX_PATH] = {0};
464 char path[] = "c:\\";
465 BOOL found = FALSE;
466 char windowsdir[MAX_PATH];
468 if (!pGetVolumeNameForVolumeMountPointA) {
469 win_skip("GetVolumeNameForVolumeMountPointA not found\n");
470 return;
473 /*get windows drive letter and update strings for testing */
474 ret = GetWindowsDirectory( windowsdir, sizeof(windowsdir) );
475 ok(ret < sizeof(windowsdir), "windowsdir is abnormally long!\n");
476 ok(ret != 0, "GetWindowsDirecory: error %d\n", GetLastError());
477 path[0] = windowsdir[0];
479 /* get the unique volume name for the windows drive */
480 ret = pGetVolumeNameForVolumeMountPointA( path, Volume_1, MAX_PATH );
481 ok(ret == TRUE, "GetVolumeNameForVolumeMountPointA failed\n");
482 ok(strlen(Volume_1) == 49, "GetVolumeNameForVolumeMountPointA returned wrong length name %s\n", Volume_1);
484 /* get first unique volume name of list */
485 hFind = pFindFirstVolumeA( Volume_2, MAX_PATH );
486 ok(hFind != INVALID_HANDLE_VALUE, "FindFirstVolume failed, err=%u\n",
487 GetLastError());
491 /* validate correct length of unique volume name */
492 ok(strlen(Volume_2) == 49, "Find[First/Next]Volume returned wrong length name %s\n", Volume_1);
493 if (memcmp(Volume_1, Volume_2, 49) == 0)
495 found = TRUE;
496 break;
498 } while (pFindNextVolumeA( hFind, Volume_2, MAX_PATH ));
499 ok(found, "volume name %s not found by Find[First/Next]Volume\n", Volume_1);
500 pFindVolumeClose( hFind );
503 static void test_disk_extents(void)
505 BOOL ret;
506 DWORD size;
507 HANDLE handle;
508 static DWORD data[16];
510 handle = CreateFileA( "\\\\.\\c:", GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0 );
511 if (handle == INVALID_HANDLE_VALUE)
513 win_skip("can't open c: drive %u\n", GetLastError());
514 return;
516 size = 0;
517 ret = DeviceIoControl( handle, IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS, &data,
518 sizeof(data), &data, sizeof(data), &size, NULL );
519 if (!ret && GetLastError() == ERROR_INVALID_FUNCTION)
521 win_skip("IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS not supported\n");
522 CloseHandle( handle );
523 return;
525 ok(ret, "DeviceIoControl failed %u\n", GetLastError());
526 ok(size == 32, "expected 32, got %u\n", size);
527 CloseHandle( handle );
530 static void test_GetVolumePathNamesForVolumeNameA(void)
532 BOOL ret;
533 char volume[MAX_PATH], buffer[MAX_PATH];
534 DWORD len, error;
536 if (!pGetVolumePathNamesForVolumeNameA || !pGetVolumeNameForVolumeMountPointA)
538 win_skip("required functions not found\n");
539 return;
542 ret = pGetVolumeNameForVolumeMountPointA( "c:\\", volume, sizeof(volume) );
543 ok(ret, "failed to get volume name %u\n", GetLastError());
544 trace("c:\\ -> %s\n", volume);
546 SetLastError( 0xdeadbeef );
547 ret = pGetVolumePathNamesForVolumeNameA( NULL, NULL, 0, NULL );
548 error = GetLastError();
549 ok(!ret, "expected failure\n");
550 ok(error == ERROR_INVALID_NAME, "expected ERROR_INVALID_NAME got %u\n", error);
552 SetLastError( 0xdeadbeef );
553 ret = pGetVolumePathNamesForVolumeNameA( "", NULL, 0, NULL );
554 error = GetLastError();
555 ok(!ret, "expected failure\n");
556 ok(error == ERROR_INVALID_NAME, "expected ERROR_INVALID_NAME got %u\n", error);
558 SetLastError( 0xdeadbeef );
559 ret = pGetVolumePathNamesForVolumeNameA( volume, NULL, 0, NULL );
560 error = GetLastError();
561 ok(!ret, "expected failure\n");
562 ok(error == ERROR_MORE_DATA, "expected ERROR_MORE_DATA got %u\n", error);
564 SetLastError( 0xdeadbeef );
565 ret = pGetVolumePathNamesForVolumeNameA( volume, buffer, 0, NULL );
566 error = GetLastError();
567 ok(!ret, "expected failure\n");
568 ok(error == ERROR_MORE_DATA, "expected ERROR_MORE_DATA got %u\n", error);
570 memset( buffer, 0xff, sizeof(buffer) );
571 ret = pGetVolumePathNamesForVolumeNameA( volume, buffer, sizeof(buffer), NULL );
572 ok(ret, "failed to get path names %u\n", GetLastError());
573 ok(!strcmp( "C:\\", buffer ), "expected \"\\C:\" got \"%s\"\n", buffer);
574 ok(!buffer[4], "expected double null-terminated buffer\n");
576 len = 0;
577 SetLastError( 0xdeadbeef );
578 ret = pGetVolumePathNamesForVolumeNameA( NULL, NULL, 0, &len );
579 error = GetLastError();
580 ok(!ret, "expected failure\n");
581 ok(error == ERROR_INVALID_NAME, "expected ERROR_INVALID_NAME got %u\n", error);
583 len = 0;
584 SetLastError( 0xdeadbeef );
585 ret = pGetVolumePathNamesForVolumeNameA( NULL, NULL, sizeof(buffer), &len );
586 error = GetLastError();
587 ok(!ret, "expected failure\n");
588 ok(error == ERROR_INVALID_NAME, "expected ERROR_INVALID_NAME got %u\n", error);
590 len = 0;
591 SetLastError( 0xdeadbeef );
592 ret = pGetVolumePathNamesForVolumeNameA( NULL, buffer, sizeof(buffer), &len );
593 error = GetLastError();
594 ok(!ret, "expected failure\n");
595 ok(error == ERROR_INVALID_NAME, "expected ERROR_INVALID_NAME got %u\n", error);
597 len = 0;
598 SetLastError( 0xdeadbeef );
599 ret = pGetVolumePathNamesForVolumeNameA( NULL, buffer, sizeof(buffer), &len );
600 error = GetLastError();
601 ok(!ret, "expected failure\n");
602 ok(error == ERROR_INVALID_NAME, "expected ERROR_INVALID_NAME got %u\n", error);
604 len = 0;
605 memset( buffer, 0xff, sizeof(buffer) );
606 ret = pGetVolumePathNamesForVolumeNameA( volume, buffer, sizeof(buffer), &len );
607 ok(ret, "failed to get path names %u\n", GetLastError());
608 ok(len == 5 || broken(len == 2), "expected 5 got %u\n", len);
609 ok(!strcmp( "C:\\", buffer ), "expected \"\\C:\" got \"%s\"\n", buffer);
610 ok(!buffer[4], "expected double null-terminated buffer\n");
613 static void test_GetVolumePathNamesForVolumeNameW(void)
615 static const WCHAR empty[] = {0};
616 static const WCHAR drive_c[] = {'c',':','\\',0};
617 static const WCHAR volume_null[] = {'\\','\\','?','\\','V','o','l','u','m','e',
618 '{','0','0','0','0','0','0','0','0','-','0','0','0','0','-','0','0','0','0',
619 '-','0','0','0','0','-','0','0','0','0','0','0','0','0','0','0','0','0','}','\\',0};
620 BOOL ret;
621 WCHAR volume[MAX_PATH], buffer[MAX_PATH];
622 DWORD len, error;
624 if (!pGetVolumePathNamesForVolumeNameW || !pGetVolumeNameForVolumeMountPointW)
626 win_skip("required functions not found\n");
627 return;
630 ret = pGetVolumeNameForVolumeMountPointW( drive_c, volume, sizeof(volume)/sizeof(volume[0]) );
631 ok(ret, "failed to get volume name %u\n", GetLastError());
633 SetLastError( 0xdeadbeef );
634 ret = pGetVolumePathNamesForVolumeNameW( empty, NULL, 0, NULL );
635 error = GetLastError();
636 ok(!ret, "expected failure\n");
637 ok(error == ERROR_INVALID_NAME, "expected ERROR_INVALID_NAME got %u\n", error);
639 SetLastError( 0xdeadbeef );
640 ret = pGetVolumePathNamesForVolumeNameW( volume, NULL, 0, NULL );
641 error = GetLastError();
642 ok(!ret, "expected failure\n");
643 ok(error == ERROR_MORE_DATA, "expected ERROR_MORE_DATA got %u\n", error);
645 SetLastError( 0xdeadbeef );
646 ret = pGetVolumePathNamesForVolumeNameW( volume, buffer, 0, NULL );
647 error = GetLastError();
648 ok(!ret, "expected failure\n");
649 ok(error == ERROR_MORE_DATA, "expected ERROR_MORE_DATA got %u\n", error);
651 if (0) { /* crash */
652 ret = pGetVolumePathNamesForVolumeNameW( volume, NULL, sizeof(buffer), NULL );
653 ok(ret, "failed to get path names %u\n", GetLastError());
656 ret = pGetVolumePathNamesForVolumeNameW( volume, buffer, sizeof(buffer), NULL );
657 ok(ret, "failed to get path names %u\n", GetLastError());
659 len = 0;
660 memset( buffer, 0xff, sizeof(buffer) );
661 ret = pGetVolumePathNamesForVolumeNameW( volume, buffer, sizeof(buffer), &len );
662 ok(ret, "failed to get path names %u\n", GetLastError());
663 ok(len == 5, "expected 5 got %u\n", len);
664 ok(!buffer[4], "expected double null-terminated buffer\n");
666 len = 0;
667 volume[1] = '?';
668 volume[lstrlenW( volume ) - 1] = 0;
669 SetLastError( 0xdeadbeef );
670 ret = pGetVolumePathNamesForVolumeNameW( volume, buffer, sizeof(buffer), &len );
671 error = GetLastError();
672 ok(!ret, "expected failure\n");
673 ok(error == ERROR_INVALID_NAME, "expected ERROR_INVALID_NAME got %u\n", error);
675 len = 0;
676 volume[0] = '\\';
677 volume[1] = 0;
678 SetLastError( 0xdeadbeef );
679 ret = pGetVolumePathNamesForVolumeNameW( volume, buffer, sizeof(buffer), &len );
680 error = GetLastError();
681 ok(!ret, "expected failure\n");
682 todo_wine ok(error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER got %u\n", error);
684 len = 0;
685 lstrcpyW( volume, volume_null );
686 SetLastError( 0xdeadbeef );
687 ret = pGetVolumePathNamesForVolumeNameW( volume, buffer, sizeof(buffer), &len );
688 error = GetLastError();
689 ok(!ret, "expected failure\n");
690 ok(error == ERROR_FILE_NOT_FOUND, "expected ERROR_FILE_NOT_FOUND got %u\n", error);
693 START_TEST(volume)
695 hdll = GetModuleHandleA("kernel32.dll");
696 pGetVolumeNameForVolumeMountPointA = (void *) GetProcAddress(hdll, "GetVolumeNameForVolumeMountPointA");
697 pGetVolumeNameForVolumeMountPointW = (void *) GetProcAddress(hdll, "GetVolumeNameForVolumeMountPointW");
698 pFindFirstVolumeA = (void *) GetProcAddress(hdll, "FindFirstVolumeA");
699 pFindNextVolumeA = (void *) GetProcAddress(hdll, "FindNextVolumeA");
700 pFindVolumeClose = (void *) GetProcAddress(hdll, "FindVolumeClose");
701 pGetLogicalDriveStringsA = (void *) GetProcAddress(hdll, "GetLogicalDriveStringsA");
702 pGetLogicalDriveStringsW = (void *) GetProcAddress(hdll, "GetLogicalDriveStringsW");
703 pGetVolumeInformationA = (void *) GetProcAddress(hdll, "GetVolumeInformationA");
704 pGetVolumePathNamesForVolumeNameA = (void *) GetProcAddress(hdll, "GetVolumePathNamesForVolumeNameA");
705 pGetVolumePathNamesForVolumeNameW = (void *) GetProcAddress(hdll, "GetVolumePathNamesForVolumeNameW");
707 test_query_dos_deviceA();
708 test_FindFirstVolume();
709 test_GetVolumeNameForVolumeMountPointA();
710 test_GetVolumeNameForVolumeMountPointW();
711 test_GetLogicalDriveStringsA();
712 test_GetLogicalDriveStringsW();
713 test_GetVolumeInformationA();
714 test_enum_vols();
715 test_disk_extents();
716 test_GetVolumePathNamesForVolumeNameA();
717 test_GetVolumePathNamesForVolumeNameW();