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;
44 if (!pFindFirstVolumeA) {
45 win_skip("On win9x, HARDDISK and RAMDISK not present\n");
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 );
57 ok(ret, "QueryDosDeviceA failed to return list, last error %u\n", GetLastError());
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());
65 if (ret <= (p-buffer)) break;
69 for (;drivestr[0] <= 'z'; drivestr[0]++) {
70 /* Older W2K fails with ERROR_INSUFFICIENT_BUFFER when buflen is > 32767 */
71 ret = QueryDosDeviceA( drivestr, buffer, buflen - 1);
73 for (p = buffer; *p; p++) *p = toupper(*p);
74 if (strstr(buffer, "HARDDISK") || strstr(buffer, "RAMDISK")) found = TRUE;
77 ok(found, "expected at least one devicename to contain HARDDISK or RAMDISK\n");
78 HeapFree( GetProcessHeap(), 0, buffer );
81 static void test_FindFirstVolume(void)
86 if (!pFindFirstVolumeA) {
87 skip("FindFirstVolumeA not found\n");
91 handle = pFindFirstVolumeA( volume, 0 );
92 ok( handle == INVALID_HANDLE_VALUE, "succeeded with short buffer\n" );
93 ok( GetLastError() == ERROR_MORE_DATA || /* XP */
94 GetLastError() == ERROR_FILENAME_EXCED_RANGE, /* Vista */
95 "wrong error %u\n", GetLastError() );
96 handle = pFindFirstVolumeA( volume, 49 );
97 ok( handle == INVALID_HANDLE_VALUE, "succeeded with short buffer\n" );
98 ok( GetLastError() == ERROR_FILENAME_EXCED_RANGE, "wrong error %u\n", GetLastError() );
99 handle = pFindFirstVolumeA( volume, 51 );
100 ok( handle != INVALID_HANDLE_VALUE, "failed err %u\n", GetLastError() );
101 if (handle != INVALID_HANDLE_VALUE)
105 ok( strlen(volume) == 49, "bad volume name %s\n", volume );
106 ok( !memcmp( volume, "\\\\?\\Volume{", 11 ), "bad volume name %s\n", volume );
107 ok( !memcmp( volume + 47, "}\\", 2 ), "bad volume name %s\n", volume );
108 } while (pFindNextVolumeA( handle, volume, MAX_PATH ));
109 ok( GetLastError() == ERROR_NO_MORE_FILES, "wrong error %u\n", GetLastError() );
110 pFindVolumeClose( handle );
114 static void test_GetVolumeNameForVolumeMountPointA(void)
117 char volume[MAX_PATH], path[] = "c:\\";
118 DWORD len = sizeof(volume), reti;
119 char temp_path[MAX_PATH];
121 /* not present before w2k */
122 if (!pGetVolumeNameForVolumeMountPointA) {
123 skip("GetVolumeNameForVolumeMountPointA not found\n");
127 reti = GetTempPathA(MAX_PATH, temp_path);
128 ok(reti != 0, "GetTempPathA error %d\n", GetLastError());
129 ok(reti < MAX_PATH, "temp path should fit into MAX_PATH\n");
131 ret = pGetVolumeNameForVolumeMountPointA(path, volume, 0);
132 ok(ret == FALSE, "GetVolumeNameForVolumeMountPointA succeeded\n");
134 if (0) { /* these crash on XP */
135 ret = pGetVolumeNameForVolumeMountPointA(path, NULL, len);
136 ok(ret == FALSE, "GetVolumeNameForVolumeMountPointA succeeded\n");
138 ret = pGetVolumeNameForVolumeMountPointA(NULL, volume, len);
139 ok(ret == FALSE, "GetVolumeNameForVolumeMountPointA succeeded\n");
142 ret = pGetVolumeNameForVolumeMountPointA(path, volume, len);
143 ok(ret == TRUE, "GetVolumeNameForVolumeMountPointA failed\n");
144 ok(!strncmp( volume, "\\\\?\\Volume{", 11),
145 "GetVolumeNameForVolumeMountPointA failed to return valid string <%s>\n",
148 /* test with too small buffer */
149 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 ret = pGetVolumeNameForVolumeMountPointA(temp_path, volume, len);
158 ok(ret == FALSE && GetLastError() == ERROR_NOT_A_REPARSE_POINT,
159 "GetVolumeNameForVolumeMountPointA failed on %s, last=%d\n",
160 temp_path, GetLastError());
162 /* Try on a non-existent dos drive */
164 for (;path[0] <= 'z'; path[0]++) {
165 ret = QueryDosDeviceA( path, volume, len);
171 ret = pGetVolumeNameForVolumeMountPointA(path, volume, len);
173 ok(ret == FALSE && GetLastError() == ERROR_FILE_NOT_FOUND,
174 "GetVolumeNameForVolumeMountPointA failed on %s, last=%d\n",
175 path, GetLastError());
177 /* Try without trailing \ and on a non-existent dos drive */
179 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 skip("GetVolumeNameForVolumeMountPointW not found\n");
199 ret = pGetVolumeNameForVolumeMountPointW(path, volume, 0);
200 ok(ret == FALSE, "GetVolumeNameForVolumeMountPointA succeeded\n");
202 if (0) { /* these crash on XP */
203 ret = pGetVolumeNameForVolumeMountPointW(path, NULL, len);
204 ok(ret == FALSE, "GetVolumeNameForVolumeMountPointW succeeded\n");
206 ret = pGetVolumeNameForVolumeMountPointW(NULL, volume, len);
207 ok(ret == FALSE, "GetVolumeNameForVolumeMountPointW succeeded\n");
210 ret = pGetVolumeNameForVolumeMountPointW(path, volume, len);
211 ok(ret == TRUE, "GetVolumeNameForVolumeMountPointW failed\n");
214 static void test_GetLogicalDriveStringsA(void)
219 if(!pGetLogicalDriveStringsA) {
220 win_skip("GetLogicalDriveStringsA not available\n");
224 size = pGetLogicalDriveStringsA(0, NULL);
225 ok(size%4 == 1, "size = %d\n", size);
227 buf = HeapAlloc(GetProcessHeap(), 0, size);
230 size2 = pGetLogicalDriveStringsA(2, buf);
231 ok(size2 == size, "size2 = %d\n", size2);
232 ok(!*buf, "buf changed\n");
234 size2 = pGetLogicalDriveStringsA(size, buf);
235 ok(size2 == size-1, "size2 = %d\n", size2);
237 for(ptr = buf; ptr < buf+size2; ptr += 4) {
238 ok(('A' <= *ptr && *ptr <= 'Z') ||
239 (broken('a' <= *ptr && *ptr <= 'z')), /* Win9x and WinMe */
240 "device name '%c' is not uppercase\n", *ptr);
241 ok(ptr[1] == ':', "ptr[1] = %c, expected ':'\n", ptr[1]);
242 ok(ptr[2] == '\\', "ptr[2] = %c expected '\\'\n", ptr[2]);
243 ok(!ptr[3], "ptr[3] = %c expected nullbyte\n", ptr[3]);
245 ok(!*ptr, "buf[size2] is not nullbyte\n");
247 HeapFree(GetProcessHeap(), 0, buf);
250 static void test_GetLogicalDriveStringsW(void)
255 if(!pGetLogicalDriveStringsW) {
256 win_skip("GetLogicalDriveStringsW not available\n");
260 SetLastError(0xdeadbeef);
261 size = pGetLogicalDriveStringsW(0, NULL);
262 if (size == 0 && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED) {
263 win_skip("GetLogicalDriveStringsW not implemented\n");
266 ok(size%4 == 1, "size = %d\n", size);
268 buf = HeapAlloc(GetProcessHeap(), 0, size*sizeof(WCHAR));
271 size2 = pGetLogicalDriveStringsW(2, buf);
272 ok(size2 == size, "size2 = %d\n", size2);
273 ok(!*buf, "buf changed\n");
275 size2 = pGetLogicalDriveStringsW(size, buf);
276 ok(size2 == size-1, "size2 = %d\n", size2);
278 for(ptr = buf; ptr < buf+size2; ptr += 4) {
279 ok('A' <= *ptr && *ptr <= 'Z', "device name '%c' is not uppercase\n", *ptr);
280 ok(ptr[1] == ':', "ptr[1] = %c, expected ':'\n", ptr[1]);
281 ok(ptr[2] == '\\', "ptr[2] = %c expected '\\'\n", ptr[2]);
282 ok(!ptr[3], "ptr[3] = %c expected nullbyte\n", ptr[3]);
284 ok(!*ptr, "buf[size2] is not nullbyte\n");
286 HeapFree(GetProcessHeap(), 0, buf);
289 static void test_GetVolumeInformationA(void)
293 char Root_Dir0[]="C:";
294 char Root_Dir1[]="C:\\";
295 char Root_Dir2[]="\\\\?\\C:\\";
296 char volume[MAX_PATH+1];
297 DWORD vol_name_size=MAX_PATH+1, vol_serial_num=-1, max_comp_len=0, fs_flags=0, fs_name_len=MAX_PATH+1;
298 char vol_name_buf[MAX_PATH+1], fs_name_buf[MAX_PATH+1];
299 char windowsdir[MAX_PATH+10];
301 if (!pGetVolumeInformationA) {
302 win_skip("GetVolumeInformationA not found\n");
305 if (!pGetVolumeNameForVolumeMountPointA) {
306 win_skip("GetVolumeNameForVolumeMountPointA not found\n");
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 /* get the unique volume name for the windows drive */
319 ret = pGetVolumeNameForVolumeMountPointA(Root_Dir1, volume, MAX_PATH);
320 ok(ret == TRUE, "GetVolumeNameForVolumeMountPointA failed\n");
322 /* **** now start the tests **** */
323 /* check for error on no trailing \ */
324 ret = pGetVolumeInformationA(Root_Dir0, vol_name_buf, vol_name_size, NULL,
325 NULL, NULL, fs_name_buf, fs_name_len);
326 ok(!ret && GetLastError() == ERROR_INVALID_NAME,
327 "GetVolumeInformationA w/o '\\' did not fail, last error %u\n", GetLastError());
329 /* try null root directory to return "root of the current directory" */
330 ret = pGetVolumeInformationA(NULL, vol_name_buf, vol_name_size, NULL,
331 NULL, NULL, fs_name_buf, fs_name_len);
332 ok(ret, "GetVolumeInformationA failed on null root dir, last error %u\n", GetLastError());
334 /* Try normal drive letter with trailing \ */
335 ret = pGetVolumeInformationA(Root_Dir1, vol_name_buf, vol_name_size,
336 &vol_serial_num, &max_comp_len, &fs_flags, fs_name_buf, fs_name_len);
337 ok(ret, "GetVolumeInformationA failed, root=%s, last error=%u\n", Root_Dir1, GetLastError());
339 /* try again with dirve letter and the "disable parsing" prefix */
340 ret = pGetVolumeInformationA(Root_Dir2, vol_name_buf, vol_name_size,
341 &vol_serial_num, &max_comp_len, &fs_flags, fs_name_buf, fs_name_len);
342 todo_wine ok(ret, "GetVolumeInformationA failed, root=%s, last error=%u\n", Root_Dir2, GetLastError());
344 /* try again with unique voluem name */
345 ret = pGetVolumeInformationA(volume, vol_name_buf, vol_name_size,
346 &vol_serial_num, &max_comp_len, &fs_flags, fs_name_buf, fs_name_len);
347 todo_wine ok(ret, "GetVolumeInformationA failed, root=%s, last error=%u\n", volume, GetLastError());
349 /* try again with device name space */
351 ret = pGetVolumeInformationA(Root_Dir2, vol_name_buf, vol_name_size,
352 &vol_serial_num, &max_comp_len, &fs_flags, fs_name_buf, fs_name_len);
353 todo_wine ok(ret, "GetVolumeInformationA failed, root=%s, last error=%u\n", Root_Dir2, GetLastError());
355 /* try again with a directory off the root - should generate error */
356 if (windowsdir[strlen(windowsdir)-1] != '\\') strcat(windowsdir, "\\");
357 ret = pGetVolumeInformationA(windowsdir, vol_name_buf, vol_name_size,
358 &vol_serial_num, &max_comp_len, &fs_flags, fs_name_buf, fs_name_len);
359 todo_wine ok(!ret && GetLastError()==ERROR_DIR_NOT_ROOT,
360 "GetVolumeInformationA failed, root=%s, last error=%u\n", windowsdir, GetLastError());
363 /* Test to check that unique volume name from windows dir mount point */
364 /* matches at least one of the unique volume names returned from the */
365 /* FindFirstVolumeA/FindNextVolumeA list. */
366 static void test_enum_vols(void)
369 HANDLE hFind = INVALID_HANDLE_VALUE;
370 char Volume_1[MAX_PATH] = {0};
371 char Volume_2[MAX_PATH] = {0};
372 char path[] = "c:\\";
374 char windowsdir[MAX_PATH];
376 if (!pGetVolumeNameForVolumeMountPointA) {
377 win_skip("GetVolumeNameForVolumeMountPointA not found\n");
381 /*get windows drive letter and update strings for testing */
382 ret = GetWindowsDirectory( windowsdir, sizeof(windowsdir) );
383 ok(ret < sizeof(windowsdir), "windowsdir is abnormally long!\n");
384 ok(ret != 0, "GetWindowsDirecory: error %d\n", GetLastError());
385 path[0] = windowsdir[0];
387 /* get the unique volume name for the windows drive */
388 ret = pGetVolumeNameForVolumeMountPointA( path, Volume_1, MAX_PATH );
389 ok(ret == TRUE, "GetVolumeNameForVolumeMountPointA failed\n");
391 ok(strlen(Volume_1) == 49, "GetVolumeNameForVolumeMountPointA returned wrong length name %s\n", Volume_1);
393 /* get first unique volume name of list */
394 hFind = pFindFirstVolumeA( Volume_2, MAX_PATH );
395 ok(hFind != INVALID_HANDLE_VALUE, "FindFirstVolume failed, err=%u\n",
400 /* validate correct length of unique volume name */
401 ok(strlen(Volume_2) == 49, "Find[First/Next]Volume returned wrong length name %s\n", Volume_1);
402 if (memcmp(Volume_1, Volume_2, 49) == 0)
407 } while (pFindNextVolumeA( hFind, Volume_2, MAX_PATH ));
409 ok(found, "volume name %s not found by Find[First/Next]Volume\n", Volume_1);
410 pFindVolumeClose( hFind );
415 hdll = GetModuleHandleA("kernel32.dll");
416 pGetVolumeNameForVolumeMountPointA = (void *) GetProcAddress(hdll, "GetVolumeNameForVolumeMountPointA");
417 pGetVolumeNameForVolumeMountPointW = (void *) GetProcAddress(hdll, "GetVolumeNameForVolumeMountPointW");
418 pFindFirstVolumeA = (void *) GetProcAddress(hdll, "FindFirstVolumeA");
419 pFindNextVolumeA = (void *) GetProcAddress(hdll, "FindNextVolumeA");
420 pFindVolumeClose = (void *) GetProcAddress(hdll, "FindVolumeClose");
421 pGetLogicalDriveStringsA = (void *) GetProcAddress(hdll, "GetLogicalDriveStringsA");
422 pGetLogicalDriveStringsW = (void *) GetProcAddress(hdll, "GetLogicalDriveStringsW");
423 pGetVolumeInformationA = (void *) GetProcAddress(hdll, "GetVolumeInformationA");
425 test_query_dos_deviceA();
426 test_FindFirstVolume();
427 test_GetVolumeNameForVolumeMountPointA();
428 test_GetVolumeNameForVolumeMountPointW();
429 test_GetLogicalDriveStringsA();
430 test_GetLogicalDriveStringsW();
431 test_GetVolumeInformationA();