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"
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
);
35 /* ############################### */
37 static void test_query_dos_deviceA(void)
39 char drivestr
[] = "a:";
40 char *p
, *buffer
, buffer2
[2000];
41 DWORD ret
, ret2
, buflen
=32768;
42 BOOL iswin9x
, found
= FALSE
;
44 buffer
= HeapAlloc( GetProcessHeap(), 0, buflen
);
45 SetLastError(0xdeadbeef);
46 ret
= QueryDosDeviceA( NULL
, buffer
, buflen
);
47 iswin9x
= !ret
&& (GetLastError() == ERROR_INVALID_PARAMETER
/* win98 */
48 || GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
/* win95*/);
49 ok((ret
&& GetLastError() != ERROR_INSUFFICIENT_BUFFER
) || broken(iswin9x
),
50 "QueryDosDeviceA failed to return list, last error %u\n", GetLastError());
52 if (ret
&& GetLastError() != ERROR_INSUFFICIENT_BUFFER
) {
55 if (!strlen(p
)) break;
56 ret2
= QueryDosDeviceA( p
, buffer2
, sizeof(buffer2
) );
57 ok(ret2
, "QueryDosDeviceA failed to return current mapping for %s, last error %u\n", p
, GetLastError());
59 if (ret
<= (p
-buffer
)) break;
63 for (;drivestr
[0] <= 'z'; drivestr
[0]++) {
64 /* Older W2K fails with ERROR_INSUFFICIENT_BUFFER when buflen is > 32767 */
65 ret
= QueryDosDeviceA( drivestr
, buffer
, buflen
- 1);
66 /* fails for all drives in win9x */
67 ok(ret
|| GetLastError() == ERROR_FILE_NOT_FOUND
|| broken(!ret
&& iswin9x
),
68 "QueryDosDeviceA failed to return current mapping for %s, last error %u\n", drivestr
, GetLastError());
70 for (p
= buffer
; *p
; p
++) *p
= toupper(*p
);
71 if (strstr(buffer
, "HARDDISK") || strstr(buffer
, "RAMDISK")) found
= TRUE
;
74 ok(found
^ iswin9x
, "expected at least one devicename to contain HARDDISK or RAMDISK except on win9x\n");
75 HeapFree( GetProcessHeap(), 0, buffer
);
78 static void test_FindFirstVolume(void)
83 /* not present before w2k */
84 if (!pFindFirstVolumeA
) {
85 win_skip("FindFirstVolumeA not found\n");
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)
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");
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",
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",
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 */
166 for (;path
[0] <= 'z'; path
[0]++) {
167 ret
= QueryDosDeviceA( path
, volume
, len
);
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 */
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)
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");
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)
222 ok( pGetLogicalDriveStringsA
!= NULL
, "GetLogicalDriveStringsA not available\n");
223 if(!pGetLogicalDriveStringsA
) {
227 size
= pGetLogicalDriveStringsA(0, NULL
);
228 ok(size
%4 == 1, "size = %d\n", size
);
230 buf
= HeapAlloc(GetProcessHeap(), 0, size
);
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') ||
242 (broken('a' <= *ptr
&& *ptr
<= 'z')), /* Win9x and WinMe */
243 "device name '%c' is not uppercase\n", *ptr
);
244 ok(ptr
[1] == ':', "ptr[1] = %c, expected ':'\n", ptr
[1]);
245 ok(ptr
[2] == '\\', "ptr[2] = %c expected '\\'\n", ptr
[2]);
246 ok(!ptr
[3], "ptr[3] = %c expected nullbyte\n", ptr
[3]);
248 ok(!*ptr
, "buf[size2] is not nullbyte\n");
250 HeapFree(GetProcessHeap(), 0, buf
);
253 static void test_GetLogicalDriveStringsW(void)
258 ok( pGetLogicalDriveStringsW
!= NULL
, "GetLogicalDriveStringsW not available\n");
259 if(!pGetLogicalDriveStringsW
) {
263 SetLastError(0xdeadbeef);
264 size
= pGetLogicalDriveStringsW(0, NULL
);
265 if (size
== 0 && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
) {
266 win_skip("GetLogicalDriveStringsW not implemented\n");
269 ok(size
%4 == 1, "size = %d\n", size
);
271 buf
= HeapAlloc(GetProcessHeap(), 0, size
*sizeof(WCHAR
));
274 size2
= pGetLogicalDriveStringsW(2, buf
);
275 ok(size2
== size
, "size2 = %d\n", size2
);
276 ok(!*buf
, "buf changed\n");
278 size2
= pGetLogicalDriveStringsW(size
, buf
);
279 ok(size2
== size
-1, "size2 = %d\n", size2
);
281 for(ptr
= buf
; ptr
< buf
+size2
; ptr
+= 4) {
282 ok('A' <= *ptr
&& *ptr
<= 'Z', "device name '%c' is not uppercase\n", *ptr
);
283 ok(ptr
[1] == ':', "ptr[1] = %c, expected ':'\n", ptr
[1]);
284 ok(ptr
[2] == '\\', "ptr[2] = %c expected '\\'\n", ptr
[2]);
285 ok(!ptr
[3], "ptr[3] = %c expected nullbyte\n", ptr
[3]);
287 ok(!*ptr
, "buf[size2] is not nullbyte\n");
289 HeapFree(GetProcessHeap(), 0, buf
);
292 static void test_GetVolumeInformationA(void)
296 char Root_Dir0
[]="C:";
297 char Root_Dir1
[]="C:\\";
298 char Root_Dir2
[]="\\\\?\\C:\\";
299 char volume
[MAX_PATH
+1];
300 DWORD vol_name_size
=MAX_PATH
+1, vol_serial_num
=-1, max_comp_len
=0, fs_flags
=0, fs_name_len
=MAX_PATH
+1;
301 char vol_name_buf
[MAX_PATH
+1], fs_name_buf
[MAX_PATH
+1];
302 char windowsdir
[MAX_PATH
+10];
303 char currentdir
[MAX_PATH
+1];
305 ok( pGetVolumeInformationA
!= NULL
, "GetVolumeInformationA not found\n");
306 if(!pGetVolumeInformationA
) {
310 /* get windows drive letter and update strings for testing */
311 result
= GetWindowsDirectory(windowsdir
, sizeof(windowsdir
));
312 ok(result
< sizeof(windowsdir
), "windowsdir is abnormally long!\n");
313 ok(result
!= 0, "GetWindowsDirectory: error %d\n", GetLastError());
314 Root_Dir0
[0] = windowsdir
[0];
315 Root_Dir1
[0] = windowsdir
[0];
316 Root_Dir2
[4] = windowsdir
[0];
318 result
= GetCurrentDirectory(MAX_PATH
, currentdir
);
319 ok(result
, "GetCurrentDirectory: error %d\n", GetLastError());
321 /* **** now start the tests **** */
322 /* check for error on no trailing \ */
325 SetLastError(0xdeadbeef);
326 ret
= pGetVolumeInformationA(Root_Dir0
, vol_name_buf
, vol_name_size
, NULL
,
327 NULL
, NULL
, fs_name_buf
, fs_name_len
);
328 ok(!ret
&& (GetLastError() == ERROR_INVALID_NAME
||
329 broken(GetLastError() == ERROR_BAD_PATHNAME
/* win9x */)),
330 "GetVolumeInformationA w/o '\\' did%s fail, last error %u\n", ret
? " not":"", GetLastError());
333 skip("Running on a root directory\n");
335 /* check for NO error on no trailing \ when current dir is root dir */
336 ret
= SetCurrentDirectory(Root_Dir1
);
337 ok(ret
, "SetCurrentDirectory: error %d\n", GetLastError());
338 ret
= pGetVolumeInformationA(Root_Dir0
, vol_name_buf
, vol_name_size
, NULL
,
339 NULL
, NULL
, fs_name_buf
, fs_name_len
);
341 ok(ret
, "GetVolumeInformationA failed, last error %u\n", GetLastError());
343 /* check for error on no trailing \ when current dir is windows dir */
344 ret
= SetCurrentDirectory(windowsdir
);
345 ok(ret
, "SetCurrentDirectory: error %d\n", GetLastError());
346 SetLastError(0xdeadbeef);
347 ret
= pGetVolumeInformationA(Root_Dir0
, vol_name_buf
, vol_name_size
, NULL
,
348 NULL
, NULL
, fs_name_buf
, fs_name_len
);
349 ok(!ret
&& (GetLastError() == ERROR_INVALID_NAME
||
350 broken(GetLastError() == ERROR_BAD_PATHNAME
/* win9x */)),
351 "GetVolumeInformationA did%s fail, last error %u\n", ret
? " not":"", GetLastError());
353 /* reset current directory */
354 ret
= SetCurrentDirectory(currentdir
);
355 ok(ret
, "SetCurrentDirectory: error %d\n", GetLastError());
357 /* try null root directory to return "root of the current directory" */
358 ret
= pGetVolumeInformationA(NULL
, vol_name_buf
, vol_name_size
, NULL
,
359 NULL
, NULL
, fs_name_buf
, fs_name_len
);
360 ok(ret
, "GetVolumeInformationA failed on null root dir, last error %u\n", GetLastError());
362 /* Try normal drive letter with trailing \ */
363 ret
= pGetVolumeInformationA(Root_Dir1
, vol_name_buf
, vol_name_size
,
364 &vol_serial_num
, &max_comp_len
, &fs_flags
, fs_name_buf
, fs_name_len
);
365 ok(ret
, "GetVolumeInformationA failed, root=%s, last error=%u\n", Root_Dir1
, GetLastError());
367 /* try again with drive letter and the "disable parsing" prefix */
368 SetLastError(0xdeadbeef);
369 ret
= pGetVolumeInformationA(Root_Dir2
, vol_name_buf
, vol_name_size
,
370 &vol_serial_num
, &max_comp_len
, &fs_flags
, fs_name_buf
, fs_name_len
);
371 todo_wine
ok(ret
|| broken(!ret
/* win9x */ && GetLastError()==ERROR_BAD_NETPATH
),
372 "GetVolumeInformationA did%s fail, root=%s, last error=%u\n", ret
? " not":"", Root_Dir2
, GetLastError());
374 /* try again with device name space */
376 SetLastError(0xdeadbeef);
377 ret
= pGetVolumeInformationA(Root_Dir2
, vol_name_buf
, vol_name_size
,
378 &vol_serial_num
, &max_comp_len
, &fs_flags
, fs_name_buf
, fs_name_len
);
379 todo_wine
ok(ret
|| broken(!ret
/* win9x */ && GetLastError()==ERROR_BAD_NETPATH
),
380 "GetVolumeInformationA did%s fail, root=%s, last error=%u\n", ret
? " not":"", Root_Dir2
, GetLastError());
382 /* try again with a directory off the root - should generate error */
383 if (windowsdir
[strlen(windowsdir
)-1] != '\\') strcat(windowsdir
, "\\");
384 SetLastError(0xdeadbeef);
385 ret
= pGetVolumeInformationA(windowsdir
, vol_name_buf
, vol_name_size
,
386 &vol_serial_num
, &max_comp_len
, &fs_flags
, fs_name_buf
, fs_name_len
);
387 todo_wine
ok(!ret
&& (GetLastError()==ERROR_DIR_NOT_ROOT
||
388 /* win9x */ broken(GetLastError()==ERROR_BAD_PATHNAME
)),
389 "GetVolumeInformationA did%s fail, root=%s, last error=%u\n", ret
? " not":"", windowsdir
, GetLastError());
391 if (!pGetVolumeNameForVolumeMountPointA
) {
392 win_skip("GetVolumeNameForVolumeMountPointA not found\n");
395 /* get the unique volume name for the windows drive */
396 ret
= pGetVolumeNameForVolumeMountPointA(Root_Dir1
, volume
, MAX_PATH
);
397 ok(ret
== TRUE
, "GetVolumeNameForVolumeMountPointA failed\n");
399 /* try again with unique volume name */
400 ret
= pGetVolumeInformationA(volume
, vol_name_buf
, vol_name_size
,
401 &vol_serial_num
, &max_comp_len
, &fs_flags
, fs_name_buf
, fs_name_len
);
402 todo_wine
ok(ret
, "GetVolumeInformationA failed, root=%s, last error=%u\n", volume
, GetLastError());
405 /* Test to check that unique volume name from windows dir mount point */
406 /* matches at least one of the unique volume names returned from the */
407 /* FindFirstVolumeA/FindNextVolumeA list. */
408 static void test_enum_vols(void)
411 HANDLE hFind
= INVALID_HANDLE_VALUE
;
412 char Volume_1
[MAX_PATH
] = {0};
413 char Volume_2
[MAX_PATH
] = {0};
414 char path
[] = "c:\\";
416 char windowsdir
[MAX_PATH
];
418 if (!pGetVolumeNameForVolumeMountPointA
) {
419 win_skip("GetVolumeNameForVolumeMountPointA not found\n");
423 /*get windows drive letter and update strings for testing */
424 ret
= GetWindowsDirectory( windowsdir
, sizeof(windowsdir
) );
425 ok(ret
< sizeof(windowsdir
), "windowsdir is abnormally long!\n");
426 ok(ret
!= 0, "GetWindowsDirecory: error %d\n", GetLastError());
427 path
[0] = windowsdir
[0];
429 /* get the unique volume name for the windows drive */
430 ret
= pGetVolumeNameForVolumeMountPointA( path
, Volume_1
, MAX_PATH
);
431 ok(ret
== TRUE
, "GetVolumeNameForVolumeMountPointA failed\n");
432 ok(strlen(Volume_1
) == 49, "GetVolumeNameForVolumeMountPointA returned wrong length name %s\n", Volume_1
);
434 /* get first unique volume name of list */
435 hFind
= pFindFirstVolumeA( Volume_2
, MAX_PATH
);
436 ok(hFind
!= INVALID_HANDLE_VALUE
, "FindFirstVolume failed, err=%u\n",
441 /* validate correct length of unique volume name */
442 ok(strlen(Volume_2
) == 49, "Find[First/Next]Volume returned wrong length name %s\n", Volume_1
);
443 if (memcmp(Volume_1
, Volume_2
, 49) == 0)
448 } while (pFindNextVolumeA( hFind
, Volume_2
, MAX_PATH
));
449 ok(found
, "volume name %s not found by Find[First/Next]Volume\n", Volume_1
);
450 pFindVolumeClose( hFind
);
455 hdll
= GetModuleHandleA("kernel32.dll");
456 pGetVolumeNameForVolumeMountPointA
= (void *) GetProcAddress(hdll
, "GetVolumeNameForVolumeMountPointA");
457 pGetVolumeNameForVolumeMountPointW
= (void *) GetProcAddress(hdll
, "GetVolumeNameForVolumeMountPointW");
458 pFindFirstVolumeA
= (void *) GetProcAddress(hdll
, "FindFirstVolumeA");
459 pFindNextVolumeA
= (void *) GetProcAddress(hdll
, "FindNextVolumeA");
460 pFindVolumeClose
= (void *) GetProcAddress(hdll
, "FindVolumeClose");
461 pGetLogicalDriveStringsA
= (void *) GetProcAddress(hdll
, "GetLogicalDriveStringsA");
462 pGetLogicalDriveStringsW
= (void *) GetProcAddress(hdll
, "GetLogicalDriveStringsW");
463 pGetVolumeInformationA
= (void *) GetProcAddress(hdll
, "GetVolumeInformationA");
465 test_query_dos_deviceA();
466 test_FindFirstVolume();
467 test_GetVolumeNameForVolumeMountPointA();
468 test_GetVolumeNameForVolumeMountPointW();
469 test_GetLogicalDriveStringsA();
470 test_GetLogicalDriveStringsW();
471 test_GetVolumeInformationA();