1c2c66affSColin Finck /*
2c2c66affSColin Finck * Unit test suite for volume functions
3c2c66affSColin Finck *
4c2c66affSColin Finck * Copyright 2006 Stefan Leichter
5c2c66affSColin Finck *
6c2c66affSColin Finck * This library is free software; you can redistribute it and/or
7c2c66affSColin Finck * modify it under the terms of the GNU Lesser General Public
8c2c66affSColin Finck * License as published by the Free Software Foundation; either
9c2c66affSColin Finck * version 2.1 of the License, or (at your option) any later version.
10c2c66affSColin Finck *
11c2c66affSColin Finck * This library is distributed in the hope that it will be useful,
12c2c66affSColin Finck * but WITHOUT ANY WARRANTY; without even the implied warranty of
13c2c66affSColin Finck * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14c2c66affSColin Finck * Lesser General Public License for more details.
15c2c66affSColin Finck *
16c2c66affSColin Finck * You should have received a copy of the GNU Lesser General Public
17c2c66affSColin Finck * License along with this library; if not, write to the Free Software
18c2c66affSColin Finck * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19c2c66affSColin Finck */
20c2c66affSColin Finck
21*ed41a4deSAmine Khaldi #include "wine/test.h"
22*ed41a4deSAmine Khaldi #include "winbase.h"
23*ed41a4deSAmine Khaldi #include "winioctl.h"
24*ed41a4deSAmine Khaldi #include <stdio.h>
25*ed41a4deSAmine Khaldi #include "wine/ddk/ntddcdvd.h"
26c2c66affSColin Finck
27c2c66affSColin Finck #include <pshpack1.h>
28c2c66affSColin Finck struct COMPLETE_DVD_LAYER_DESCRIPTOR
29c2c66affSColin Finck {
30c2c66affSColin Finck DVD_DESCRIPTOR_HEADER Header;
31c2c66affSColin Finck DVD_LAYER_DESCRIPTOR Descriptor;
32c2c66affSColin Finck UCHAR Padding;
33c2c66affSColin Finck };
34c2c66affSColin Finck #include <poppack.h>
35c2c66affSColin Finck C_ASSERT(sizeof(struct COMPLETE_DVD_LAYER_DESCRIPTOR) == 22);
36c2c66affSColin Finck
37c2c66affSColin Finck #include <pshpack1.h>
38c2c66affSColin Finck struct COMPLETE_DVD_MANUFACTURER_DESCRIPTOR
39c2c66affSColin Finck {
40c2c66affSColin Finck DVD_DESCRIPTOR_HEADER Header;
41c2c66affSColin Finck DVD_MANUFACTURER_DESCRIPTOR Descriptor;
42c2c66affSColin Finck UCHAR Padding;
43c2c66affSColin Finck };
44c2c66affSColin Finck #include <poppack.h>
45c2c66affSColin Finck C_ASSERT(sizeof(struct COMPLETE_DVD_MANUFACTURER_DESCRIPTOR) == 2053);
46c2c66affSColin Finck
47c2c66affSColin Finck static HINSTANCE hdll;
48c2c66affSColin Finck static BOOL (WINAPI * pGetVolumeNameForVolumeMountPointA)(LPCSTR, LPSTR, DWORD);
49c2c66affSColin Finck static BOOL (WINAPI * pGetVolumeNameForVolumeMountPointW)(LPCWSTR, LPWSTR, DWORD);
50c2c66affSColin Finck static HANDLE (WINAPI *pFindFirstVolumeA)(LPSTR,DWORD);
51c2c66affSColin Finck static BOOL (WINAPI *pFindNextVolumeA)(HANDLE,LPSTR,DWORD);
52c2c66affSColin Finck static BOOL (WINAPI *pFindVolumeClose)(HANDLE);
53c2c66affSColin Finck static UINT (WINAPI *pGetLogicalDriveStringsA)(UINT,LPSTR);
54c2c66affSColin Finck static UINT (WINAPI *pGetLogicalDriveStringsW)(UINT,LPWSTR);
55c2c66affSColin Finck static BOOL (WINAPI *pGetVolumeInformationA)(LPCSTR, LPSTR, DWORD, LPDWORD, LPDWORD, LPDWORD, LPSTR, DWORD);
56c2c66affSColin Finck static BOOL (WINAPI *pGetVolumePathNameA)(LPCSTR, LPSTR, DWORD);
57c2c66affSColin Finck static BOOL (WINAPI *pGetVolumePathNameW)(LPWSTR, LPWSTR, DWORD);
58c2c66affSColin Finck static BOOL (WINAPI *pGetVolumePathNamesForVolumeNameA)(LPCSTR, LPSTR, DWORD, LPDWORD);
59c2c66affSColin Finck static BOOL (WINAPI *pGetVolumePathNamesForVolumeNameW)(LPCWSTR, LPWSTR, DWORD, LPDWORD);
60c2c66affSColin Finck
61c2c66affSColin Finck /* ############################### */
62c2c66affSColin Finck
test_query_dos_deviceA(void)63c2c66affSColin Finck static void test_query_dos_deviceA(void)
64c2c66affSColin Finck {
65c2c66affSColin Finck char drivestr[] = "a:";
66c2c66affSColin Finck char *p, *buffer, buffer2[2000];
67c2c66affSColin Finck DWORD ret, ret2, buflen=32768;
68c2c66affSColin Finck BOOL found = FALSE;
69c2c66affSColin Finck
70c2c66affSColin Finck /* callers must guess the buffer size */
71c2c66affSColin Finck SetLastError(0xdeadbeef);
72c2c66affSColin Finck ret = QueryDosDeviceA( NULL, NULL, 0 );
73c2c66affSColin Finck ok(!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER,
74c2c66affSColin Finck "QueryDosDeviceA(no buffer): returned %u, le=%u\n", ret, GetLastError());
75c2c66affSColin Finck
76c2c66affSColin Finck buffer = HeapAlloc( GetProcessHeap(), 0, buflen );
77c2c66affSColin Finck SetLastError(0xdeadbeef);
78c2c66affSColin Finck ret = QueryDosDeviceA( NULL, buffer, buflen );
79c2c66affSColin Finck ok((ret && GetLastError() != ERROR_INSUFFICIENT_BUFFER),
80c2c66affSColin Finck "QueryDosDeviceA failed to return list, last error %u\n", GetLastError());
81c2c66affSColin Finck
82c2c66affSColin Finck if (ret && GetLastError() != ERROR_INSUFFICIENT_BUFFER) {
83c2c66affSColin Finck p = buffer;
84c2c66affSColin Finck for (;;) {
85c2c66affSColin Finck if (!strlen(p)) break;
86c2c66affSColin Finck ret2 = QueryDosDeviceA( p, buffer2, sizeof(buffer2) );
87c2c66affSColin Finck ok(ret2, "QueryDosDeviceA failed to return current mapping for %s, last error %u\n", p, GetLastError());
88c2c66affSColin Finck p += strlen(p) + 1;
89c2c66affSColin Finck if (ret <= (p-buffer)) break;
90c2c66affSColin Finck }
91c2c66affSColin Finck }
92c2c66affSColin Finck
93c2c66affSColin Finck for (;drivestr[0] <= 'z'; drivestr[0]++) {
94c2c66affSColin Finck /* Older W2K fails with ERROR_INSUFFICIENT_BUFFER when buflen is > 32767 */
95c2c66affSColin Finck ret = QueryDosDeviceA( drivestr, buffer, buflen - 1);
96c2c66affSColin Finck ok(ret || GetLastError() == ERROR_FILE_NOT_FOUND,
97c2c66affSColin Finck "QueryDosDeviceA failed to return current mapping for %s, last error %u\n", drivestr, GetLastError());
98c2c66affSColin Finck if(ret) {
99c2c66affSColin Finck for (p = buffer; *p; p++) *p = toupper(*p);
100c2c66affSColin Finck if (strstr(buffer, "HARDDISK") || strstr(buffer, "RAMDISK")) found = TRUE;
101c2c66affSColin Finck }
102c2c66affSColin Finck }
103c2c66affSColin Finck ok(found, "expected at least one devicename to contain HARDDISK or RAMDISK\n");
104c2c66affSColin Finck HeapFree( GetProcessHeap(), 0, buffer );
105c2c66affSColin Finck }
106c2c66affSColin Finck
test_define_dos_deviceA(void)107c2c66affSColin Finck static void test_define_dos_deviceA(void)
108c2c66affSColin Finck {
109c2c66affSColin Finck char drivestr[3];
110c2c66affSColin Finck char buf[MAX_PATH];
111c2c66affSColin Finck DWORD ret;
112c2c66affSColin Finck
113c2c66affSColin Finck /* Find an unused drive letter */
114c2c66affSColin Finck drivestr[1] = ':';
115c2c66affSColin Finck drivestr[2] = 0;
116c2c66affSColin Finck for (drivestr[0] = 'a'; drivestr[0] <= 'z'; drivestr[0]++) {
117c2c66affSColin Finck ret = QueryDosDeviceA( drivestr, buf, sizeof(buf));
118c2c66affSColin Finck if (!ret) break;
119c2c66affSColin Finck }
120c2c66affSColin Finck if (drivestr[0] > 'z') {
121c2c66affSColin Finck skip("can't test creating a dos drive, none available\n");
122c2c66affSColin Finck return;
123c2c66affSColin Finck }
124c2c66affSColin Finck
125c2c66affSColin Finck /* Map it to point to the current directory */
126c2c66affSColin Finck ret = GetCurrentDirectoryA(sizeof(buf), buf);
127c2c66affSColin Finck ok(ret, "GetCurrentDir\n");
128c2c66affSColin Finck
129c2c66affSColin Finck ret = DefineDosDeviceA(0, drivestr, buf);
130c2c66affSColin Finck todo_wine
131c2c66affSColin Finck ok(ret, "Could not make drive %s point to %s!\n", drivestr, buf);
132c2c66affSColin Finck
133c2c66affSColin Finck if (!ret) {
134c2c66affSColin Finck skip("can't test removing fake drive\n");
135c2c66affSColin Finck } else {
136c2c66affSColin Finck ret = DefineDosDeviceA(DDD_REMOVE_DEFINITION, drivestr, NULL);
137c2c66affSColin Finck ok(ret, "Could not remove fake drive %s!\n", drivestr);
138c2c66affSColin Finck }
139c2c66affSColin Finck }
140c2c66affSColin Finck
test_FindFirstVolume(void)141c2c66affSColin Finck static void test_FindFirstVolume(void)
142c2c66affSColin Finck {
143c2c66affSColin Finck char volume[51];
144c2c66affSColin Finck HANDLE handle;
145c2c66affSColin Finck
146c2c66affSColin Finck /* not present before w2k */
147c2c66affSColin Finck if (!pFindFirstVolumeA) {
148c2c66affSColin Finck win_skip("FindFirstVolumeA not found\n");
149c2c66affSColin Finck return;
150c2c66affSColin Finck }
151c2c66affSColin Finck
152c2c66affSColin Finck handle = pFindFirstVolumeA( volume, 0 );
153c2c66affSColin Finck ok( handle == INVALID_HANDLE_VALUE, "succeeded with short buffer\n" );
154c2c66affSColin Finck ok( GetLastError() == ERROR_MORE_DATA || /* XP */
155c2c66affSColin Finck GetLastError() == ERROR_FILENAME_EXCED_RANGE, /* Vista */
156c2c66affSColin Finck "wrong error %u\n", GetLastError() );
157c2c66affSColin Finck handle = pFindFirstVolumeA( volume, 49 );
158c2c66affSColin Finck ok( handle == INVALID_HANDLE_VALUE, "succeeded with short buffer\n" );
159c2c66affSColin Finck ok( GetLastError() == ERROR_FILENAME_EXCED_RANGE, "wrong error %u\n", GetLastError() );
160c2c66affSColin Finck handle = pFindFirstVolumeA( volume, 51 );
161c2c66affSColin Finck ok( handle != INVALID_HANDLE_VALUE, "failed err %u\n", GetLastError() );
162c2c66affSColin Finck if (handle != INVALID_HANDLE_VALUE)
163c2c66affSColin Finck {
164c2c66affSColin Finck do
165c2c66affSColin Finck {
166c2c66affSColin Finck ok( strlen(volume) == 49, "bad volume name %s\n", volume );
167c2c66affSColin Finck ok( !memcmp( volume, "\\\\?\\Volume{", 11 ), "bad volume name %s\n", volume );
168c2c66affSColin Finck ok( !memcmp( volume + 47, "}\\", 2 ), "bad volume name %s\n", volume );
169c2c66affSColin Finck } while (pFindNextVolumeA( handle, volume, MAX_PATH ));
170c2c66affSColin Finck ok( GetLastError() == ERROR_NO_MORE_FILES, "wrong error %u\n", GetLastError() );
171c2c66affSColin Finck pFindVolumeClose( handle );
172c2c66affSColin Finck }
173c2c66affSColin Finck }
174c2c66affSColin Finck
test_GetVolumeNameForVolumeMountPointA(void)175c2c66affSColin Finck static void test_GetVolumeNameForVolumeMountPointA(void)
176c2c66affSColin Finck {
177c2c66affSColin Finck BOOL ret;
178c2c66affSColin Finck char volume[MAX_PATH], path[] = "c:\\";
179c2c66affSColin Finck DWORD len = sizeof(volume), reti;
180c2c66affSColin Finck char temp_path[MAX_PATH];
181c2c66affSColin Finck
182c2c66affSColin Finck /* not present before w2k */
183c2c66affSColin Finck if (!pGetVolumeNameForVolumeMountPointA) {
184c2c66affSColin Finck win_skip("GetVolumeNameForVolumeMountPointA not found\n");
185c2c66affSColin Finck return;
186c2c66affSColin Finck }
187c2c66affSColin Finck
188c2c66affSColin Finck reti = GetTempPathA(MAX_PATH, temp_path);
189c2c66affSColin Finck ok(reti != 0, "GetTempPathA error %d\n", GetLastError());
190c2c66affSColin Finck ok(reti < MAX_PATH, "temp path should fit into MAX_PATH\n");
191c2c66affSColin Finck
192c2c66affSColin Finck ret = pGetVolumeNameForVolumeMountPointA(path, volume, 0);
193c2c66affSColin Finck ok(ret == FALSE, "GetVolumeNameForVolumeMountPointA succeeded\n");
194c2c66affSColin Finck ok(GetLastError() == ERROR_FILENAME_EXCED_RANGE ||
195c2c66affSColin Finck GetLastError() == ERROR_INVALID_PARAMETER, /* Vista */
196c2c66affSColin Finck "wrong error, last=%d\n", GetLastError());
197c2c66affSColin Finck
198c2c66affSColin Finck if (0) { /* these crash on XP */
199c2c66affSColin Finck ret = pGetVolumeNameForVolumeMountPointA(path, NULL, len);
200c2c66affSColin Finck ok(ret == FALSE, "GetVolumeNameForVolumeMountPointA succeeded\n");
201c2c66affSColin Finck
202c2c66affSColin Finck ret = pGetVolumeNameForVolumeMountPointA(NULL, volume, len);
203c2c66affSColin Finck ok(ret == FALSE, "GetVolumeNameForVolumeMountPointA succeeded\n");
204c2c66affSColin Finck }
205c2c66affSColin Finck
206c2c66affSColin Finck ret = pGetVolumeNameForVolumeMountPointA(path, volume, len);
207c2c66affSColin Finck ok(ret == TRUE, "GetVolumeNameForVolumeMountPointA failed\n");
208c2c66affSColin Finck ok(!strncmp( volume, "\\\\?\\Volume{", 11),
209c2c66affSColin Finck "GetVolumeNameForVolumeMountPointA failed to return valid string <%s>\n",
210c2c66affSColin Finck volume);
211c2c66affSColin Finck
212c2c66affSColin Finck /* test with too small buffer */
213c2c66affSColin Finck ret = pGetVolumeNameForVolumeMountPointA(path, volume, 10);
214c2c66affSColin Finck ok(ret == FALSE && GetLastError() == ERROR_FILENAME_EXCED_RANGE,
215c2c66affSColin Finck "GetVolumeNameForVolumeMountPointA failed, wrong error returned, was %d, should be ERROR_FILENAME_EXCED_RANGE\n",
216c2c66affSColin Finck GetLastError());
217c2c66affSColin Finck
218c2c66affSColin Finck /* Try on an arbitrary directory */
219c2c66affSColin Finck /* On FAT filesystems it seems that GetLastError() is set to
220c2c66affSColin Finck ERROR_INVALID_FUNCTION. */
221c2c66affSColin Finck ret = pGetVolumeNameForVolumeMountPointA(temp_path, volume, len);
222c2c66affSColin Finck ok(ret == FALSE && (GetLastError() == ERROR_NOT_A_REPARSE_POINT ||
223c2c66affSColin Finck GetLastError() == ERROR_INVALID_FUNCTION),
224c2c66affSColin Finck "GetVolumeNameForVolumeMountPointA failed on %s, last=%d\n",
225c2c66affSColin Finck temp_path, GetLastError());
226c2c66affSColin Finck
227c2c66affSColin Finck /* Try on a nonexistent dos drive */
228c2c66affSColin Finck path[2] = 0;
229c2c66affSColin Finck for (;path[0] <= 'z'; path[0]++) {
230c2c66affSColin Finck ret = QueryDosDeviceA( path, volume, len);
231c2c66affSColin Finck if(!ret) break;
232c2c66affSColin Finck }
233c2c66affSColin Finck if (path[0] <= 'z')
234c2c66affSColin Finck {
235c2c66affSColin Finck path[2] = '\\';
236c2c66affSColin Finck ret = pGetVolumeNameForVolumeMountPointA(path, volume, len);
237c2c66affSColin Finck ok(ret == FALSE && GetLastError() == ERROR_FILE_NOT_FOUND,
238c2c66affSColin Finck "GetVolumeNameForVolumeMountPointA failed on %s, last=%d\n",
239c2c66affSColin Finck path, GetLastError());
240c2c66affSColin Finck
241c2c66affSColin Finck /* Try without trailing \ and on a nonexistent dos drive */
242c2c66affSColin Finck path[2] = 0;
243c2c66affSColin Finck ret = pGetVolumeNameForVolumeMountPointA(path, volume, len);
244c2c66affSColin Finck ok(ret == FALSE && GetLastError() == ERROR_INVALID_NAME,
245c2c66affSColin Finck "GetVolumeNameForVolumeMountPointA failed on %s, last=%d\n",
246c2c66affSColin Finck path, GetLastError());
247c2c66affSColin Finck }
248c2c66affSColin Finck }
249c2c66affSColin Finck
test_GetVolumeNameForVolumeMountPointW(void)250c2c66affSColin Finck static void test_GetVolumeNameForVolumeMountPointW(void)
251c2c66affSColin Finck {
252c2c66affSColin Finck BOOL ret;
253c2c66affSColin Finck WCHAR volume[MAX_PATH], path[] = {'c',':','\\',0};
254c2c66affSColin Finck DWORD len = sizeof(volume) / sizeof(WCHAR);
255c2c66affSColin Finck
256c2c66affSColin Finck /* not present before w2k */
257c2c66affSColin Finck if (!pGetVolumeNameForVolumeMountPointW) {
258c2c66affSColin Finck win_skip("GetVolumeNameForVolumeMountPointW not found\n");
259c2c66affSColin Finck return;
260c2c66affSColin Finck }
261c2c66affSColin Finck
262c2c66affSColin Finck ret = pGetVolumeNameForVolumeMountPointW(path, volume, 0);
263*ed41a4deSAmine Khaldi ok(ret == FALSE, "GetVolumeNameForVolumeMountPointW succeeded\n");
264c2c66affSColin Finck ok(GetLastError() == ERROR_FILENAME_EXCED_RANGE ||
265c2c66affSColin Finck GetLastError() == ERROR_INVALID_PARAMETER, /* Vista */
266c2c66affSColin Finck "wrong error, last=%d\n", GetLastError());
267c2c66affSColin Finck
268c2c66affSColin Finck if (0) { /* these crash on XP */
269c2c66affSColin Finck ret = pGetVolumeNameForVolumeMountPointW(path, NULL, len);
270c2c66affSColin Finck ok(ret == FALSE, "GetVolumeNameForVolumeMountPointW succeeded\n");
271c2c66affSColin Finck
272c2c66affSColin Finck ret = pGetVolumeNameForVolumeMountPointW(NULL, volume, len);
273c2c66affSColin Finck ok(ret == FALSE, "GetVolumeNameForVolumeMountPointW succeeded\n");
274c2c66affSColin Finck }
275c2c66affSColin Finck
276c2c66affSColin Finck ret = pGetVolumeNameForVolumeMountPointW(path, volume, len);
277c2c66affSColin Finck ok(ret == TRUE, "GetVolumeNameForVolumeMountPointW failed\n");
278c2c66affSColin Finck }
279c2c66affSColin Finck
test_GetLogicalDriveStringsA(void)280c2c66affSColin Finck static void test_GetLogicalDriveStringsA(void)
281c2c66affSColin Finck {
282c2c66affSColin Finck UINT size, size2;
283c2c66affSColin Finck char *buf, *ptr;
284c2c66affSColin Finck
285c2c66affSColin Finck ok( pGetLogicalDriveStringsA != NULL, "GetLogicalDriveStringsA not available\n");
286c2c66affSColin Finck if(!pGetLogicalDriveStringsA) {
287c2c66affSColin Finck return;
288c2c66affSColin Finck }
289c2c66affSColin Finck
290c2c66affSColin Finck size = pGetLogicalDriveStringsA(0, NULL);
291c2c66affSColin Finck ok(size%4 == 1, "size = %d\n", size);
292c2c66affSColin Finck
293c2c66affSColin Finck buf = HeapAlloc(GetProcessHeap(), 0, size);
294c2c66affSColin Finck
295c2c66affSColin Finck *buf = 0;
296c2c66affSColin Finck size2 = pGetLogicalDriveStringsA(2, buf);
297c2c66affSColin Finck ok(size2 == size, "size2 = %d\n", size2);
298c2c66affSColin Finck ok(!*buf, "buf changed\n");
299c2c66affSColin Finck
300c2c66affSColin Finck size2 = pGetLogicalDriveStringsA(size, buf);
301c2c66affSColin Finck ok(size2 == size-1, "size2 = %d\n", size2);
302c2c66affSColin Finck
303c2c66affSColin Finck for(ptr = buf; ptr < buf+size2; ptr += 4) {
304c2c66affSColin Finck ok(('A' <= *ptr && *ptr <= 'Z'), "device name '%c' is not uppercase\n", *ptr);
305c2c66affSColin Finck ok(ptr[1] == ':', "ptr[1] = %c, expected ':'\n", ptr[1]);
306c2c66affSColin Finck ok(ptr[2] == '\\', "ptr[2] = %c expected '\\'\n", ptr[2]);
307c2c66affSColin Finck ok(!ptr[3], "ptr[3] = %c expected nullbyte\n", ptr[3]);
308c2c66affSColin Finck }
309c2c66affSColin Finck ok(!*ptr, "buf[size2] is not nullbyte\n");
310c2c66affSColin Finck
311c2c66affSColin Finck HeapFree(GetProcessHeap(), 0, buf);
312c2c66affSColin Finck }
313c2c66affSColin Finck
test_GetLogicalDriveStringsW(void)314c2c66affSColin Finck static void test_GetLogicalDriveStringsW(void)
315c2c66affSColin Finck {
316c2c66affSColin Finck UINT size, size2;
317c2c66affSColin Finck WCHAR *buf, *ptr;
318c2c66affSColin Finck
319c2c66affSColin Finck ok( pGetLogicalDriveStringsW != NULL, "GetLogicalDriveStringsW not available\n");
320c2c66affSColin Finck if(!pGetLogicalDriveStringsW) {
321c2c66affSColin Finck return;
322c2c66affSColin Finck }
323c2c66affSColin Finck
324c2c66affSColin Finck SetLastError(0xdeadbeef);
325c2c66affSColin Finck size = pGetLogicalDriveStringsW(0, NULL);
326c2c66affSColin Finck if (size == 0 && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED) {
327c2c66affSColin Finck win_skip("GetLogicalDriveStringsW not implemented\n");
328c2c66affSColin Finck return;
329c2c66affSColin Finck }
330c2c66affSColin Finck ok(size%4 == 1, "size = %d\n", size);
331c2c66affSColin Finck
332c2c66affSColin Finck buf = HeapAlloc(GetProcessHeap(), 0, size*sizeof(WCHAR));
333c2c66affSColin Finck
334c2c66affSColin Finck *buf = 0;
335c2c66affSColin Finck size2 = pGetLogicalDriveStringsW(2, buf);
336c2c66affSColin Finck ok(size2 == size, "size2 = %d\n", size2);
337c2c66affSColin Finck ok(!*buf, "buf changed\n");
338c2c66affSColin Finck
339c2c66affSColin Finck size2 = pGetLogicalDriveStringsW(size, buf);
340c2c66affSColin Finck ok(size2 == size-1, "size2 = %d\n", size2);
341c2c66affSColin Finck
342c2c66affSColin Finck for(ptr = buf; ptr < buf+size2; ptr += 4) {
343c2c66affSColin Finck ok('A' <= *ptr && *ptr <= 'Z', "device name '%c' is not uppercase\n", *ptr);
344c2c66affSColin Finck ok(ptr[1] == ':', "ptr[1] = %c, expected ':'\n", ptr[1]);
345c2c66affSColin Finck ok(ptr[2] == '\\', "ptr[2] = %c expected '\\'\n", ptr[2]);
346c2c66affSColin Finck ok(!ptr[3], "ptr[3] = %c expected nullbyte\n", ptr[3]);
347c2c66affSColin Finck }
348c2c66affSColin Finck ok(!*ptr, "buf[size2] is not nullbyte\n");
349c2c66affSColin Finck
350c2c66affSColin Finck HeapFree(GetProcessHeap(), 0, buf);
351c2c66affSColin Finck }
352c2c66affSColin Finck
test_GetVolumeInformationA(void)353c2c66affSColin Finck static void test_GetVolumeInformationA(void)
354c2c66affSColin Finck {
355c2c66affSColin Finck BOOL ret;
356c2c66affSColin Finck UINT result;
357c2c66affSColin Finck char Root_Colon[]="C:";
358c2c66affSColin Finck char Root_Slash[]="C:\\";
359c2c66affSColin Finck char Root_UNC[]="\\\\?\\C:\\";
360c2c66affSColin Finck char volume[MAX_PATH+1];
361c2c66affSColin Finck DWORD vol_name_size=MAX_PATH+1, vol_serial_num=-1, max_comp_len=0, fs_flags=0, fs_name_len=MAX_PATH+1;
362c2c66affSColin Finck char vol_name_buf[MAX_PATH+1], fs_name_buf[MAX_PATH+1];
363c2c66affSColin Finck char windowsdir[MAX_PATH+10];
364c2c66affSColin Finck char currentdir[MAX_PATH+1];
365c2c66affSColin Finck
366c2c66affSColin Finck ok( pGetVolumeInformationA != NULL, "GetVolumeInformationA not found\n");
367c2c66affSColin Finck if(!pGetVolumeInformationA) {
368c2c66affSColin Finck return;
369c2c66affSColin Finck }
370c2c66affSColin Finck
371c2c66affSColin Finck /* get windows drive letter and update strings for testing */
372c2c66affSColin Finck result = GetWindowsDirectoryA(windowsdir, sizeof(windowsdir));
373c2c66affSColin Finck ok(result < sizeof(windowsdir), "windowsdir is abnormally long!\n");
374c2c66affSColin Finck ok(result != 0, "GetWindowsDirectory: error %d\n", GetLastError());
375c2c66affSColin Finck Root_Colon[0] = windowsdir[0];
376c2c66affSColin Finck Root_Slash[0] = windowsdir[0];
377c2c66affSColin Finck Root_UNC[4] = windowsdir[0];
378c2c66affSColin Finck
379c2c66affSColin Finck result = GetCurrentDirectoryA(MAX_PATH, currentdir);
380c2c66affSColin Finck ok(result, "GetCurrentDirectory: error %d\n", GetLastError());
381c2c66affSColin Finck /* Note that GetCurrentDir yields no trailing slash for subdirs */
382c2c66affSColin Finck
383c2c66affSColin Finck /* check for NO error on no trailing \ when current dir is root dir */
384c2c66affSColin Finck ret = SetCurrentDirectoryA(Root_Slash);
385c2c66affSColin Finck ok(ret, "SetCurrentDirectory: error %d\n", GetLastError());
386c2c66affSColin Finck ret = pGetVolumeInformationA(Root_Colon, vol_name_buf, vol_name_size, NULL,
387c2c66affSColin Finck NULL, NULL, fs_name_buf, fs_name_len);
388c2c66affSColin Finck ok(ret, "GetVolumeInformationA root failed, last error %u\n", GetLastError());
389c2c66affSColin Finck
390c2c66affSColin Finck /* check for error on no trailing \ when current dir is subdir (windows) of queried drive */
391c2c66affSColin Finck ret = SetCurrentDirectoryA(windowsdir);
392c2c66affSColin Finck ok(ret, "SetCurrentDirectory: error %d\n", GetLastError());
393c2c66affSColin Finck SetLastError(0xdeadbeef);
394c2c66affSColin Finck ret = pGetVolumeInformationA(Root_Colon, vol_name_buf, vol_name_size, NULL,
395c2c66affSColin Finck NULL, NULL, fs_name_buf, fs_name_len);
396c2c66affSColin Finck ok(!ret && (GetLastError() == ERROR_INVALID_NAME),
397c2c66affSColin Finck "GetVolumeInformationA did%s fail, last error %u\n", ret ? " not":"", GetLastError());
398c2c66affSColin Finck
399c2c66affSColin Finck /* reset current directory */
400c2c66affSColin Finck ret = SetCurrentDirectoryA(currentdir);
401c2c66affSColin Finck ok(ret, "SetCurrentDirectory: error %d\n", GetLastError());
402c2c66affSColin Finck
403c2c66affSColin Finck if (toupper(currentdir[0]) == toupper(windowsdir[0])) {
404c2c66affSColin Finck skip("Please re-run from another device than %c:\n", windowsdir[0]);
405c2c66affSColin Finck /* FIXME: Use GetLogicalDrives to find another device to avoid this skip. */
406c2c66affSColin Finck } else {
407c2c66affSColin Finck char Root_Env[]="=C:"; /* where MS maintains the per volume directory */
408c2c66affSColin Finck Root_Env[1] = windowsdir[0];
409c2c66affSColin Finck
410c2c66affSColin Finck /* C:\windows becomes the current directory on drive C: */
411c2c66affSColin Finck /* Note that paths to subdirs are stored without trailing slash, like what GetCurrentDir yields. */
412c2c66affSColin Finck ret = SetEnvironmentVariableA(Root_Env, windowsdir);
413c2c66affSColin Finck ok(ret, "SetEnvironmentVariable %s failed\n", Root_Env);
414c2c66affSColin Finck
415c2c66affSColin Finck ret = SetCurrentDirectoryA(windowsdir);
416c2c66affSColin Finck ok(ret, "SetCurrentDirectory: error %d\n", GetLastError());
417c2c66affSColin Finck ret = SetCurrentDirectoryA(currentdir);
418c2c66affSColin Finck ok(ret, "SetCurrentDirectory: error %d\n", GetLastError());
419c2c66affSColin Finck
420c2c66affSColin Finck /* windows dir is current on the root drive, call fails */
421c2c66affSColin Finck SetLastError(0xdeadbeef);
422c2c66affSColin Finck ret = pGetVolumeInformationA(Root_Colon, vol_name_buf, vol_name_size, NULL,
423c2c66affSColin Finck NULL, NULL, fs_name_buf, fs_name_len);
424c2c66affSColin Finck ok(!ret && (GetLastError() == ERROR_INVALID_NAME),
425c2c66affSColin Finck "GetVolumeInformationA did%s fail, last error %u\n", ret ? " not":"", GetLastError());
426c2c66affSColin Finck
427c2c66affSColin Finck /* Try normal drive letter with trailing \ */
428c2c66affSColin Finck ret = pGetVolumeInformationA(Root_Slash, vol_name_buf, vol_name_size, NULL,
429c2c66affSColin Finck NULL, NULL, fs_name_buf, fs_name_len);
430c2c66affSColin Finck ok(ret, "GetVolumeInformationA with \\ failed, last error %u\n", GetLastError());
431c2c66affSColin Finck
432c2c66affSColin Finck ret = SetCurrentDirectoryA(Root_Slash);
433c2c66affSColin Finck ok(ret, "SetCurrentDirectory: error %d\n", GetLastError());
434c2c66affSColin Finck ret = SetCurrentDirectoryA(currentdir);
435c2c66affSColin Finck ok(ret, "SetCurrentDirectory: error %d\n", GetLastError());
436c2c66affSColin Finck
437c2c66affSColin Finck /* windows dir is STILL CURRENT on root drive; the call fails as before, */
438c2c66affSColin Finck /* proving that SetCurrentDir did not remember the other drive's directory */
439c2c66affSColin Finck SetLastError(0xdeadbeef);
440c2c66affSColin Finck ret = pGetVolumeInformationA(Root_Colon, vol_name_buf, vol_name_size, NULL,
441c2c66affSColin Finck NULL, NULL, fs_name_buf, fs_name_len);
442c2c66affSColin Finck ok(!ret && (GetLastError() == ERROR_INVALID_NAME),
443c2c66affSColin Finck "GetVolumeInformationA did%s fail, last error %u\n", ret ? " not":"", GetLastError());
444c2c66affSColin Finck
445c2c66affSColin Finck /* Now C:\ becomes the current directory on drive C: */
446c2c66affSColin Finck ret = SetEnvironmentVariableA(Root_Env, Root_Slash); /* set =C:=C:\ */
447c2c66affSColin Finck ok(ret, "SetEnvironmentVariable %s failed\n", Root_Env);
448c2c66affSColin Finck
449c2c66affSColin Finck /* \ is current on root drive, call succeeds */
450c2c66affSColin Finck ret = pGetVolumeInformationA(Root_Colon, vol_name_buf, vol_name_size, NULL,
451c2c66affSColin Finck NULL, NULL, fs_name_buf, fs_name_len);
452c2c66affSColin Finck ok(ret, "GetVolumeInformationA failed, last error %u\n", GetLastError());
453c2c66affSColin Finck
454c2c66affSColin Finck /* again, SetCurrentDirectory on another drive does not matter */
455c2c66affSColin Finck ret = SetCurrentDirectoryA(Root_Slash);
456c2c66affSColin Finck ok(ret, "SetCurrentDirectory: error %d\n", GetLastError());
457c2c66affSColin Finck ret = SetCurrentDirectoryA(currentdir);
458c2c66affSColin Finck ok(ret, "SetCurrentDirectory: error %d\n", GetLastError());
459c2c66affSColin Finck
460c2c66affSColin Finck /* \ is current on root drive, call succeeds */
461c2c66affSColin Finck ret = pGetVolumeInformationA(Root_Colon, vol_name_buf, vol_name_size, NULL,
462c2c66affSColin Finck NULL, NULL, fs_name_buf, fs_name_len);
463c2c66affSColin Finck ok(ret, "GetVolumeInformationA failed, last error %u\n", GetLastError());
464c2c66affSColin Finck }
465c2c66affSColin Finck
466c2c66affSColin Finck /* try null root directory to return "root of the current directory" */
467c2c66affSColin Finck ret = pGetVolumeInformationA(NULL, vol_name_buf, vol_name_size, NULL,
468c2c66affSColin Finck NULL, NULL, fs_name_buf, fs_name_len);
469c2c66affSColin Finck ok(ret, "GetVolumeInformationA failed on null root dir, last error %u\n", GetLastError());
470c2c66affSColin Finck
471c2c66affSColin Finck /* Try normal drive letter with trailing \ */
472c2c66affSColin Finck ret = pGetVolumeInformationA(Root_Slash, vol_name_buf, vol_name_size,
473c2c66affSColin Finck &vol_serial_num, &max_comp_len, &fs_flags, fs_name_buf, fs_name_len);
474c2c66affSColin Finck ok(ret, "GetVolumeInformationA failed, root=%s, last error=%u\n", Root_Slash, GetLastError());
475c2c66affSColin Finck
476c2c66affSColin Finck /* try again with drive letter and the "disable parsing" prefix */
477c2c66affSColin Finck SetLastError(0xdeadbeef);
478c2c66affSColin Finck ret = pGetVolumeInformationA(Root_UNC, vol_name_buf, vol_name_size,
479c2c66affSColin Finck &vol_serial_num, &max_comp_len, &fs_flags, fs_name_buf, fs_name_len);
480c2c66affSColin Finck ok(ret, "GetVolumeInformationA did%s fail, root=%s, last error=%u\n", ret ? " not":"", Root_UNC, GetLastError());
481c2c66affSColin Finck
482c2c66affSColin Finck /* try again with device name space */
483c2c66affSColin Finck Root_UNC[2] = '.';
484c2c66affSColin Finck SetLastError(0xdeadbeef);
485c2c66affSColin Finck ret = pGetVolumeInformationA(Root_UNC, vol_name_buf, vol_name_size,
486c2c66affSColin Finck &vol_serial_num, &max_comp_len, &fs_flags, fs_name_buf, fs_name_len);
487c2c66affSColin Finck ok(ret, "GetVolumeInformationA did%s fail, root=%s, last error=%u\n", ret ? " not":"", Root_UNC, GetLastError());
488c2c66affSColin Finck
489c2c66affSColin Finck /* try again with a directory off the root - should generate error */
490c2c66affSColin Finck if (windowsdir[strlen(windowsdir)-1] != '\\') strcat(windowsdir, "\\");
491c2c66affSColin Finck SetLastError(0xdeadbeef);
492c2c66affSColin Finck ret = pGetVolumeInformationA(windowsdir, vol_name_buf, vol_name_size,
493c2c66affSColin Finck &vol_serial_num, &max_comp_len, &fs_flags, fs_name_buf, fs_name_len);
494c2c66affSColin Finck ok(!ret && (GetLastError()==ERROR_DIR_NOT_ROOT),
495c2c66affSColin Finck "GetVolumeInformationA did%s fail, root=%s, last error=%u\n", ret ? " not":"", windowsdir, GetLastError());
496c2c66affSColin Finck /* A subdir with trailing \ yields DIR_NOT_ROOT instead of INVALID_NAME */
497c2c66affSColin Finck if (windowsdir[strlen(windowsdir)-1] == '\\') windowsdir[strlen(windowsdir)-1] = 0;
498c2c66affSColin Finck SetLastError(0xdeadbeef);
499c2c66affSColin Finck ret = pGetVolumeInformationA(windowsdir, vol_name_buf, vol_name_size,
500c2c66affSColin Finck &vol_serial_num, &max_comp_len, &fs_flags, fs_name_buf, fs_name_len);
501c2c66affSColin Finck ok(!ret && (GetLastError()==ERROR_INVALID_NAME),
502c2c66affSColin Finck "GetVolumeInformationA did%s fail, root=%s, last error=%u\n", ret ? " not":"", windowsdir, GetLastError());
503c2c66affSColin Finck
504c2c66affSColin Finck if (!pGetVolumeNameForVolumeMountPointA) {
505c2c66affSColin Finck win_skip("GetVolumeNameForVolumeMountPointA not found\n");
506c2c66affSColin Finck return;
507c2c66affSColin Finck }
508c2c66affSColin Finck /* get the unique volume name for the windows drive */
509c2c66affSColin Finck ret = pGetVolumeNameForVolumeMountPointA(Root_Slash, volume, MAX_PATH);
510c2c66affSColin Finck ok(ret == TRUE, "GetVolumeNameForVolumeMountPointA failed\n");
511c2c66affSColin Finck
512c2c66affSColin Finck /* try again with unique volume name */
513c2c66affSColin Finck ret = pGetVolumeInformationA(volume, vol_name_buf, vol_name_size,
514c2c66affSColin Finck &vol_serial_num, &max_comp_len, &fs_flags, fs_name_buf, fs_name_len);
515c2c66affSColin Finck ok(ret, "GetVolumeInformationA failed, root=%s, last error=%u\n", volume, GetLastError());
516c2c66affSColin Finck }
517c2c66affSColin Finck
518c2c66affSColin Finck /* Test to check that unique volume name from windows dir mount point */
519c2c66affSColin Finck /* matches at least one of the unique volume names returned from the */
520c2c66affSColin Finck /* FindFirstVolumeA/FindNextVolumeA list. */
test_enum_vols(void)521c2c66affSColin Finck static void test_enum_vols(void)
522c2c66affSColin Finck {
523c2c66affSColin Finck DWORD ret;
524c2c66affSColin Finck HANDLE hFind = INVALID_HANDLE_VALUE;
525c2c66affSColin Finck char Volume_1[MAX_PATH] = {0};
526c2c66affSColin Finck char Volume_2[MAX_PATH] = {0};
527c2c66affSColin Finck char path[] = "c:\\";
528c2c66affSColin Finck BOOL found = FALSE;
529c2c66affSColin Finck char windowsdir[MAX_PATH];
530c2c66affSColin Finck
531c2c66affSColin Finck if (!pGetVolumeNameForVolumeMountPointA) {
532c2c66affSColin Finck win_skip("GetVolumeNameForVolumeMountPointA not found\n");
533c2c66affSColin Finck return;
534c2c66affSColin Finck }
535c2c66affSColin Finck
536c2c66affSColin Finck /*get windows drive letter and update strings for testing */
537c2c66affSColin Finck ret = GetWindowsDirectoryA( windowsdir, sizeof(windowsdir) );
538c2c66affSColin Finck ok(ret < sizeof(windowsdir), "windowsdir is abnormally long!\n");
539c2c66affSColin Finck ok(ret != 0, "GetWindowsDirectory: error %d\n", GetLastError());
540c2c66affSColin Finck path[0] = windowsdir[0];
541c2c66affSColin Finck
542c2c66affSColin Finck /* get the unique volume name for the windows drive */
543c2c66affSColin Finck ret = pGetVolumeNameForVolumeMountPointA( path, Volume_1, MAX_PATH );
544c2c66affSColin Finck ok(ret == TRUE, "GetVolumeNameForVolumeMountPointA failed\n");
545c2c66affSColin Finck ok(strlen(Volume_1) == 49, "GetVolumeNameForVolumeMountPointA returned wrong length name %s\n", Volume_1);
546c2c66affSColin Finck
547c2c66affSColin Finck /* get first unique volume name of list */
548c2c66affSColin Finck hFind = pFindFirstVolumeA( Volume_2, MAX_PATH );
549c2c66affSColin Finck ok(hFind != INVALID_HANDLE_VALUE, "FindFirstVolume failed, err=%u\n",
550c2c66affSColin Finck GetLastError());
551c2c66affSColin Finck /* ReactOS */
552c2c66affSColin Finck if (hFind != INVALID_HANDLE_VALUE) {
553c2c66affSColin Finck do
554c2c66affSColin Finck {
555c2c66affSColin Finck /* validate correct length of unique volume name */
556c2c66affSColin Finck ok(strlen(Volume_2) == 49, "Find[First/Next]Volume returned wrong length name %s\n", Volume_1);
557c2c66affSColin Finck if (memcmp(Volume_1, Volume_2, 49) == 0)
558c2c66affSColin Finck {
559c2c66affSColin Finck found = TRUE;
560c2c66affSColin Finck break;
561c2c66affSColin Finck }
562c2c66affSColin Finck } while (pFindNextVolumeA( hFind, Volume_2, MAX_PATH ));
563c2c66affSColin Finck ok(found, "volume name %s not found by Find[First/Next]Volume\n", Volume_1);
564c2c66affSColin Finck pFindVolumeClose( hFind );
565c2c66affSColin Finck }
566c2c66affSColin Finck }
567c2c66affSColin Finck
test_disk_extents(void)568c2c66affSColin Finck static void test_disk_extents(void)
569c2c66affSColin Finck {
570c2c66affSColin Finck BOOL ret;
571c2c66affSColin Finck DWORD size;
572c2c66affSColin Finck HANDLE handle;
573c2c66affSColin Finck static DWORD data[16];
574c2c66affSColin Finck
575c2c66affSColin Finck handle = CreateFileA( "\\\\.\\c:", GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0 );
576c2c66affSColin Finck if (handle == INVALID_HANDLE_VALUE)
577c2c66affSColin Finck {
578c2c66affSColin Finck win_skip("can't open c: drive %u\n", GetLastError());
579c2c66affSColin Finck return;
580c2c66affSColin Finck }
581c2c66affSColin Finck size = 0;
582c2c66affSColin Finck ret = DeviceIoControl( handle, IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS, &data,
583c2c66affSColin Finck sizeof(data), &data, sizeof(data), &size, NULL );
584c2c66affSColin Finck if (!ret && GetLastError() == ERROR_INVALID_FUNCTION)
585c2c66affSColin Finck {
586c2c66affSColin Finck win_skip("IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS not supported\n");
587c2c66affSColin Finck CloseHandle( handle );
588c2c66affSColin Finck return;
589c2c66affSColin Finck }
590c2c66affSColin Finck ok(ret, "DeviceIoControl failed %u\n", GetLastError());
591c2c66affSColin Finck ok(size == 32, "expected 32, got %u\n", size);
592c2c66affSColin Finck CloseHandle( handle );
593c2c66affSColin Finck }
594c2c66affSColin Finck
test_GetVolumePathNameA(void)595c2c66affSColin Finck static void test_GetVolumePathNameA(void)
596c2c66affSColin Finck {
597c2c66affSColin Finck char volume_path[MAX_PATH], cwd[MAX_PATH];
598c2c66affSColin Finck struct {
599c2c66affSColin Finck const char *file_name;
600c2c66affSColin Finck const char *path_name;
601c2c66affSColin Finck DWORD path_len;
602c2c66affSColin Finck DWORD error;
603c2c66affSColin Finck DWORD broken_error;
604c2c66affSColin Finck } test_paths[] = {
605c2c66affSColin Finck { /* test 0: NULL parameters, 0 output length */
606c2c66affSColin Finck NULL, NULL, 0,
607c2c66affSColin Finck ERROR_INVALID_PARAMETER, 0xdeadbeef /* winxp */
608c2c66affSColin Finck },
609c2c66affSColin Finck { /* test 1: empty input, NULL output, 0 output length */
610c2c66affSColin Finck "", NULL, 0,
611c2c66affSColin Finck ERROR_INVALID_PARAMETER, 0xdeadbeef /* winxp */
612c2c66affSColin Finck },
613c2c66affSColin Finck { /* test 2: valid input, NULL output, 0 output length */
614c2c66affSColin Finck "C:\\", NULL, 0,
615c2c66affSColin Finck ERROR_INVALID_PARAMETER, ERROR_FILENAME_EXCED_RANGE /* winxp */
616c2c66affSColin Finck },
617c2c66affSColin Finck { /* test 3: valid input, valid output, 0 output length */
618c2c66affSColin Finck "C:\\", "C:\\", 0,
619c2c66affSColin Finck ERROR_INVALID_PARAMETER, ERROR_FILENAME_EXCED_RANGE /* winxp */
620c2c66affSColin Finck },
621c2c66affSColin Finck { /* test 4: valid input, valid output, 1 output length */
622c2c66affSColin Finck "C:\\", "C:\\", 1,
623c2c66affSColin Finck ERROR_FILENAME_EXCED_RANGE, NO_ERROR
624c2c66affSColin Finck },
625c2c66affSColin Finck { /* test 5: valid input, valid output, valid output length */
626c2c66affSColin Finck "C:\\", "C:\\", sizeof(volume_path),
627c2c66affSColin Finck NO_ERROR, NO_ERROR
628c2c66affSColin Finck },
629c2c66affSColin Finck { /* test 6: lowercase input, uppercase output, valid output length */
630c2c66affSColin Finck "c:\\", "C:\\", sizeof(volume_path),
631c2c66affSColin Finck NO_ERROR, NO_ERROR
632c2c66affSColin Finck },
633c2c66affSColin Finck { /* test 7: poor quality input, valid output, valid output length */
634c2c66affSColin Finck "C::", "C:\\", sizeof(volume_path),
635c2c66affSColin Finck NO_ERROR, NO_ERROR
636c2c66affSColin Finck },
637c2c66affSColin Finck { /* test 8: really bogus input, valid output, 1 output length */
638c2c66affSColin Finck "\\\\$$$", "C:\\", 1,
639c2c66affSColin Finck ERROR_INVALID_NAME, ERROR_FILENAME_EXCED_RANGE
640c2c66affSColin Finck },
641c2c66affSColin Finck { /* test 9: a reasonable DOS path that is guaranteed to exist */
642c2c66affSColin Finck "C:\\windows\\system32", "C:\\", sizeof(volume_path),
643c2c66affSColin Finck NO_ERROR, NO_ERROR
644c2c66affSColin Finck },
645c2c66affSColin Finck { /* test 10: a reasonable DOS path that shouldn't exist */
646c2c66affSColin Finck "C:\\windows\\system32\\AnInvalidFolder", "C:\\", sizeof(volume_path),
647c2c66affSColin Finck NO_ERROR, NO_ERROR
648c2c66affSColin Finck },
649c2c66affSColin Finck { /* test 11: a reasonable NT-converted DOS path that shouldn't exist */
650c2c66affSColin Finck "\\\\?\\C:\\AnInvalidFolder", "\\\\?\\C:\\", sizeof(volume_path),
651c2c66affSColin Finck NO_ERROR, NO_ERROR
652c2c66affSColin Finck },
653c2c66affSColin Finck { /* test 12: an unreasonable NT-converted DOS path */
654c2c66affSColin Finck "\\\\?\\InvalidDrive:\\AnInvalidFolder", "\\\\?\\InvalidDrive:\\" /* win2k, winxp */,
655c2c66affSColin Finck sizeof(volume_path),
656c2c66affSColin Finck ERROR_INVALID_NAME, NO_ERROR
657c2c66affSColin Finck },
658c2c66affSColin Finck { /* test 13: an unreasonable NT volume path */
659c2c66affSColin Finck "\\\\?\\Volume{00000000-00-0000-0000-000000000000}\\AnInvalidFolder",
660c2c66affSColin Finck "\\\\?\\Volume{00000000-00-0000-0000-000000000000}\\" /* win2k, winxp */,
661c2c66affSColin Finck sizeof(volume_path),
662c2c66affSColin Finck ERROR_INVALID_NAME, NO_ERROR
663c2c66affSColin Finck },
664c2c66affSColin Finck { /* test 14: an unreasonable NT-ish path */
665c2c66affSColin Finck "\\\\ReallyBogus\\InvalidDrive:\\AnInvalidFolder",
666c2c66affSColin Finck "\\\\ReallyBogus\\InvalidDrive:\\" /* win2k, winxp */, sizeof(volume_path),
667c2c66affSColin Finck ERROR_INVALID_NAME, NO_ERROR
668c2c66affSColin Finck },
669c2c66affSColin Finck { /* test 15: poor quality input, valid output, valid (but short) output length */
670c2c66affSColin Finck "C::", "C:\\", 4,
671c2c66affSColin Finck NO_ERROR, ERROR_MORE_DATA
672c2c66affSColin Finck },
673c2c66affSColin Finck { /* test 16: unused drive letter */
674c2c66affSColin Finck "M::", "C:\\", 4,
675c2c66affSColin Finck ERROR_FILE_NOT_FOUND, ERROR_MORE_DATA
676c2c66affSColin Finck },
677c2c66affSColin Finck { /* test 17: an unreasonable DOS path */
678c2c66affSColin Finck "InvalidDrive:\\AnInvalidFolder", "%CurrentDrive%\\", sizeof(volume_path),
679c2c66affSColin Finck NO_ERROR, NO_ERROR
680c2c66affSColin Finck },
681c2c66affSColin Finck { /* test 18: a reasonable device path */
682c2c66affSColin Finck "\\??\\CdRom0", "%CurrentDrive%\\", sizeof(volume_path),
683c2c66affSColin Finck NO_ERROR, NO_ERROR
684c2c66affSColin Finck },
685c2c66affSColin Finck { /* test 19: an unreasonable device path */
686c2c66affSColin Finck "\\??\\ReallyBogus", "%CurrentDrive%\\", sizeof(volume_path),
687c2c66affSColin Finck NO_ERROR, NO_ERROR
688c2c66affSColin Finck },
689c2c66affSColin Finck { /* test 20 */
690c2c66affSColin Finck "C:", "C:", 2,
691c2c66affSColin Finck ERROR_FILENAME_EXCED_RANGE, NO_ERROR
692c2c66affSColin Finck },
693c2c66affSColin Finck { /* test 21 */
694c2c66affSColin Finck "C:", "C:", 3,
695c2c66affSColin Finck NO_ERROR, ERROR_FILENAME_EXCED_RANGE
696c2c66affSColin Finck },
697c2c66affSColin Finck { /* test 22 */
698c2c66affSColin Finck "C:\\", "C:", 2,
699c2c66affSColin Finck ERROR_FILENAME_EXCED_RANGE, NO_ERROR
700c2c66affSColin Finck },
701c2c66affSColin Finck { /* test 23 */
702c2c66affSColin Finck "C:\\", "C:", 3,
703c2c66affSColin Finck NO_ERROR, ERROR_FILENAME_EXCED_RANGE
704c2c66affSColin Finck },
705c2c66affSColin Finck { /* test 24 */
706c2c66affSColin Finck "C::", "C:", 2,
707c2c66affSColin Finck ERROR_FILENAME_EXCED_RANGE, NO_ERROR
708c2c66affSColin Finck },
709c2c66affSColin Finck { /* test 25 */
710c2c66affSColin Finck "C::", "C:", 3,
711c2c66affSColin Finck NO_ERROR, ERROR_FILENAME_EXCED_RANGE
712c2c66affSColin Finck },
713c2c66affSColin Finck { /* test 26 */
714c2c66affSColin Finck "C::", "C:\\", 4,
715c2c66affSColin Finck NO_ERROR, ERROR_MORE_DATA
716c2c66affSColin Finck },
717c2c66affSColin Finck { /* test 27 */
718c2c66affSColin Finck "C:\\windows\\system32\\AnInvalidFolder", "C:", 3,
719c2c66affSColin Finck NO_ERROR, ERROR_FILENAME_EXCED_RANGE
720c2c66affSColin Finck },
721c2c66affSColin Finck { /* test 28 */
722c2c66affSColin Finck "\\\\?\\C:\\AnInvalidFolder", "\\\\?\\C:", 3,
723c2c66affSColin Finck ERROR_FILENAME_EXCED_RANGE, NO_ERROR
724c2c66affSColin Finck },
725c2c66affSColin Finck { /* test 29 */
726c2c66affSColin Finck "\\\\?\\C:\\AnInvalidFolder", "\\\\?\\C:", 6,
727c2c66affSColin Finck ERROR_FILENAME_EXCED_RANGE, NO_ERROR
728c2c66affSColin Finck },
729c2c66affSColin Finck { /* test 30 */
730c2c66affSColin Finck "\\\\?\\C:\\AnInvalidFolder", "\\\\?\\C:", 7,
731c2c66affSColin Finck NO_ERROR, ERROR_FILENAME_EXCED_RANGE
732c2c66affSColin Finck },
733c2c66affSColin Finck { /* test 31 */
734c2c66affSColin Finck "\\\\?\\c:\\AnInvalidFolder", "\\\\?\\c:", 7,
735c2c66affSColin Finck NO_ERROR, ERROR_FILENAME_EXCED_RANGE
736c2c66affSColin Finck },
737c2c66affSColin Finck { /* test 32 */
738c2c66affSColin Finck "C:/", "C:\\", 4,
739c2c66affSColin Finck NO_ERROR, ERROR_MORE_DATA
740c2c66affSColin Finck },
741c2c66affSColin Finck { /* test 33 */
742c2c66affSColin Finck "M:/", "", 4,
743c2c66affSColin Finck ERROR_FILE_NOT_FOUND, ERROR_MORE_DATA
744c2c66affSColin Finck },
745c2c66affSColin Finck { /* test 34 */
746c2c66affSColin Finck "C:ABC:DEF:\\AnInvalidFolder", "C:\\", 4,
747c2c66affSColin Finck NO_ERROR, ERROR_MORE_DATA
748c2c66affSColin Finck },
749c2c66affSColin Finck { /* test 35 */
750c2c66affSColin Finck "?:ABC:DEF:\\AnInvalidFolder", "?:\\" /* win2k, winxp */, sizeof(volume_path),
751c2c66affSColin Finck ERROR_FILE_NOT_FOUND, NO_ERROR
752c2c66affSColin Finck },
753c2c66affSColin Finck { /* test 36 */
754c2c66affSColin Finck "relative/path", "%CurrentDrive%\\", sizeof(volume_path),
755c2c66affSColin Finck NO_ERROR, NO_ERROR
756c2c66affSColin Finck },
757c2c66affSColin Finck { /* test 37 */
758c2c66affSColin Finck "/unix-style/absolute/path", "%CurrentDrive%\\", sizeof(volume_path),
759c2c66affSColin Finck NO_ERROR, NO_ERROR
760c2c66affSColin Finck },
761c2c66affSColin Finck { /* test 38 */
762c2c66affSColin Finck "\\??\\C:\\NonExistent", "%CurrentDrive%\\", sizeof(volume_path),
763c2c66affSColin Finck NO_ERROR, NO_ERROR
764c2c66affSColin Finck },
765c2c66affSColin Finck { /* test 39 */
766c2c66affSColin Finck "\\??\\M:\\NonExistent", "%CurrentDrive%\\", sizeof(volume_path),
767c2c66affSColin Finck NO_ERROR, NO_ERROR
768c2c66affSColin Finck },
769c2c66affSColin Finck { /* test 40 */
770c2c66affSColin Finck "somefile:def", "%CurrentDrive%\\", sizeof(volume_path),
771c2c66affSColin Finck NO_ERROR, NO_ERROR
772c2c66affSColin Finck },
773c2c66affSColin Finck { /* test 41 */
774c2c66affSColin Finck "s:omefile", "S:\\" /* win2k, winxp */, sizeof(volume_path),
775c2c66affSColin Finck ERROR_FILE_NOT_FOUND, NO_ERROR
776c2c66affSColin Finck },
777c2c66affSColin Finck };
778c2c66affSColin Finck BOOL ret, success;
779c2c66affSColin Finck DWORD error;
780c2c66affSColin Finck UINT i;
781c2c66affSColin Finck
782c2c66affSColin Finck /* GetVolumePathNameA is not present before w2k */
783c2c66affSColin Finck if (!pGetVolumePathNameA)
784c2c66affSColin Finck {
785c2c66affSColin Finck win_skip("required functions not found\n");
786c2c66affSColin Finck return;
787c2c66affSColin Finck }
788c2c66affSColin Finck
789c2c66affSColin Finck /* Obtain the drive of the working directory */
790c2c66affSColin Finck ret = GetCurrentDirectoryA( sizeof(cwd), cwd );
791c2c66affSColin Finck ok( ret, "Failed to obtain the current working directory.\n" );
792c2c66affSColin Finck cwd[2] = 0;
793c2c66affSColin Finck ret = SetEnvironmentVariableA( "CurrentDrive", cwd );
794c2c66affSColin Finck ok( ret, "Failed to set an environment variable for the current working drive.\n" );
795c2c66affSColin Finck
796c2c66affSColin Finck for (i=0; i<sizeof(test_paths)/sizeof(test_paths[0]); i++)
797c2c66affSColin Finck {
798c2c66affSColin Finck BOOL broken_ret = test_paths[i].broken_error == NO_ERROR;
799c2c66affSColin Finck char *output = (test_paths[i].path_name != NULL ? volume_path : NULL);
800c2c66affSColin Finck BOOL expected_ret = test_paths[i].error == NO_ERROR;
801c2c66affSColin Finck
802c2c66affSColin Finck volume_path[0] = 0;
803c2c66affSColin Finck if (test_paths[i].path_len < sizeof(volume_path))
804c2c66affSColin Finck volume_path[ test_paths[i].path_len ] = 0x11;
805c2c66affSColin Finck
806c2c66affSColin Finck SetLastError( 0xdeadbeef );
807c2c66affSColin Finck ret = pGetVolumePathNameA( test_paths[i].file_name, output, test_paths[i].path_len );
808c2c66affSColin Finck error = GetLastError();
809c2c66affSColin Finck ok(ret == expected_ret || broken(ret == broken_ret),
810c2c66affSColin Finck "GetVolumePathName test %d %s unexpectedly.\n",
811c2c66affSColin Finck i, test_paths[i].error == NO_ERROR ? "failed" : "succeeded");
812c2c66affSColin Finck
813c2c66affSColin Finck if (ret)
814c2c66affSColin Finck {
815c2c66affSColin Finck char path_name[MAX_PATH];
816c2c66affSColin Finck
817c2c66affSColin Finck ExpandEnvironmentStringsA( test_paths[i].path_name, path_name, MAX_PATH);
818c2c66affSColin Finck /* If we succeeded then make sure the path is correct */
819c2c66affSColin Finck success = (strcmp( volume_path, path_name ) == 0)
820c2c66affSColin Finck || broken(strcasecmp( volume_path, path_name ) == 0) /* XP */;
821c2c66affSColin Finck ok(success, "GetVolumePathName test %d unexpectedly returned path %s (expected %s).\n",
822c2c66affSColin Finck i, volume_path, path_name);
823c2c66affSColin Finck }
824c2c66affSColin Finck else
825c2c66affSColin Finck {
826c2c66affSColin Finck /* On success Windows always returns ERROR_MORE_DATA, so only worry about failure */
827c2c66affSColin Finck success = (error == test_paths[i].error || broken(error == test_paths[i].broken_error));
828c2c66affSColin Finck ok(success, "GetVolumePathName test %d unexpectedly returned error 0x%x (expected 0x%x).\n",
829c2c66affSColin Finck i, error, test_paths[i].error);
830c2c66affSColin Finck }
831c2c66affSColin Finck
832c2c66affSColin Finck if (test_paths[i].path_len < sizeof(volume_path))
833c2c66affSColin Finck ok(volume_path[ test_paths[i].path_len ] == 0x11,
834c2c66affSColin Finck "GetVolumePathName test %d corrupted byte after end of buffer.\n", i);
835c2c66affSColin Finck }
836c2c66affSColin Finck }
837c2c66affSColin Finck
test_GetVolumePathNameW(void)838c2c66affSColin Finck static void test_GetVolumePathNameW(void)
839c2c66affSColin Finck {
840c2c66affSColin Finck static WCHAR drive_c1[] = {'C',':',0};
841c2c66affSColin Finck static WCHAR drive_c2[] = {'C',':','\\',0};
842c2c66affSColin Finck WCHAR volume_path[MAX_PATH];
843c2c66affSColin Finck BOOL ret;
844c2c66affSColin Finck
845c2c66affSColin Finck if (!pGetVolumePathNameW)
846c2c66affSColin Finck {
847c2c66affSColin Finck win_skip("required functions not found\n");
848c2c66affSColin Finck return;
849c2c66affSColin Finck }
850c2c66affSColin Finck
851c2c66affSColin Finck volume_path[0] = 0;
852c2c66affSColin Finck volume_path[1] = 0x11;
853c2c66affSColin Finck ret = pGetVolumePathNameW( drive_c1, volume_path, 1 );
854c2c66affSColin Finck ok(!ret, "GetVolumePathNameW test succeeded unexpectedly.\n");
855c2c66affSColin Finck ok(GetLastError() == ERROR_FILENAME_EXCED_RANGE, "GetVolumePathNameW unexpectedly returned error 0x%x (expected 0x%x).\n",
856c2c66affSColin Finck GetLastError(), ERROR_FILENAME_EXCED_RANGE);
857c2c66affSColin Finck ok(volume_path[1] == 0x11, "GetVolumePathW corrupted byte after end of buffer.\n");
858c2c66affSColin Finck
859c2c66affSColin Finck volume_path[0] = 0;
860c2c66affSColin Finck volume_path[2] = 0x11;
861c2c66affSColin Finck ret = pGetVolumePathNameW( drive_c1, volume_path, 2 );
862c2c66affSColin Finck ok(!ret, "GetVolumePathNameW test succeeded unexpectedly.\n");
863c2c66affSColin Finck ok(GetLastError() == ERROR_FILENAME_EXCED_RANGE, "GetVolumePathNameW unexpectedly returned error 0x%x (expected 0x%x).\n",
864c2c66affSColin Finck GetLastError(), ERROR_FILENAME_EXCED_RANGE);
865c2c66affSColin Finck ok(volume_path[2] == 0x11, "GetVolumePathW corrupted byte after end of buffer.\n");
866c2c66affSColin Finck
867c2c66affSColin Finck volume_path[0] = 0;
868c2c66affSColin Finck volume_path[3] = 0x11;
869c2c66affSColin Finck ret = pGetVolumePathNameW( drive_c1, volume_path, 3 );
870c2c66affSColin Finck ok(ret || broken(!ret) /* win2k */, "GetVolumePathNameW test failed unexpectedly.\n");
871c2c66affSColin Finck ok(memcmp(volume_path, drive_c1, sizeof(drive_c1)) == 0
872c2c66affSColin Finck || broken(volume_path[0] == 0) /* win2k */,
873c2c66affSColin Finck "GetVolumePathNameW unexpectedly returned wrong path.\n");
874c2c66affSColin Finck ok(volume_path[3] == 0x11, "GetVolumePathW corrupted byte after end of buffer.\n");
875c2c66affSColin Finck
876c2c66affSColin Finck volume_path[0] = 0;
877c2c66affSColin Finck volume_path[4] = 0x11;
878c2c66affSColin Finck ret = pGetVolumePathNameW( drive_c1, volume_path, 4 );
879c2c66affSColin Finck ok(ret, "GetVolumePathNameW test failed unexpectedly.\n");
880c2c66affSColin Finck ok(memcmp(volume_path, drive_c2, sizeof(drive_c2)) == 0, "GetVolumePathNameW unexpectedly returned wrong path.\n");
881c2c66affSColin Finck ok(volume_path[4] == 0x11, "GetVolumePathW corrupted byte after end of buffer.\n");
882c2c66affSColin Finck }
883c2c66affSColin Finck
test_GetVolumePathNamesForVolumeNameA(void)884c2c66affSColin Finck static void test_GetVolumePathNamesForVolumeNameA(void)
885c2c66affSColin Finck {
886c2c66affSColin Finck BOOL ret;
887c2c66affSColin Finck char volume[MAX_PATH], buffer[MAX_PATH];
888c2c66affSColin Finck DWORD len, error;
889c2c66affSColin Finck
890c2c66affSColin Finck if (!pGetVolumePathNamesForVolumeNameA || !pGetVolumeNameForVolumeMountPointA)
891c2c66affSColin Finck {
892c2c66affSColin Finck win_skip("required functions not found\n");
893c2c66affSColin Finck return;
894c2c66affSColin Finck }
895c2c66affSColin Finck
896c2c66affSColin Finck ret = pGetVolumeNameForVolumeMountPointA( "c:\\", volume, sizeof(volume) );
897c2c66affSColin Finck ok(ret, "failed to get volume name %u\n", GetLastError());
898c2c66affSColin Finck trace("c:\\ -> %s\n", volume);
899c2c66affSColin Finck
900c2c66affSColin Finck SetLastError( 0xdeadbeef );
901c2c66affSColin Finck ret = pGetVolumePathNamesForVolumeNameA( NULL, NULL, 0, NULL );
902c2c66affSColin Finck error = GetLastError();
903c2c66affSColin Finck ok(!ret, "expected failure\n");
904c2c66affSColin Finck ok(error == ERROR_INVALID_NAME, "expected ERROR_INVALID_NAME got %u\n", error);
905c2c66affSColin Finck
906c2c66affSColin Finck SetLastError( 0xdeadbeef );
907c2c66affSColin Finck ret = pGetVolumePathNamesForVolumeNameA( "", NULL, 0, NULL );
908c2c66affSColin Finck error = GetLastError();
909c2c66affSColin Finck ok(!ret, "expected failure\n");
910c2c66affSColin Finck ok(error == ERROR_INVALID_NAME, "expected ERROR_INVALID_NAME got %u\n", error);
911c2c66affSColin Finck
912c2c66affSColin Finck SetLastError( 0xdeadbeef );
913c2c66affSColin Finck ret = pGetVolumePathNamesForVolumeNameA( volume, NULL, 0, NULL );
914c2c66affSColin Finck error = GetLastError();
915c2c66affSColin Finck ok(!ret, "expected failure\n");
916c2c66affSColin Finck ok(error == ERROR_MORE_DATA, "expected ERROR_MORE_DATA got %u\n", error);
917c2c66affSColin Finck
918c2c66affSColin Finck SetLastError( 0xdeadbeef );
919c2c66affSColin Finck ret = pGetVolumePathNamesForVolumeNameA( volume, buffer, 0, NULL );
920c2c66affSColin Finck error = GetLastError();
921c2c66affSColin Finck ok(!ret, "expected failure\n");
922c2c66affSColin Finck ok(error == ERROR_MORE_DATA, "expected ERROR_MORE_DATA got %u\n", error);
923c2c66affSColin Finck
924c2c66affSColin Finck memset( buffer, 0xff, sizeof(buffer) );
925c2c66affSColin Finck ret = pGetVolumePathNamesForVolumeNameA( volume, buffer, sizeof(buffer), NULL );
926c2c66affSColin Finck ok(ret, "failed to get path names %u\n", GetLastError());
927c2c66affSColin Finck ok(!strcmp( "C:\\", buffer ), "expected \"\\C:\" got \"%s\"\n", buffer);
928c2c66affSColin Finck ok(!buffer[4], "expected double null-terminated buffer\n");
929c2c66affSColin Finck
930c2c66affSColin Finck len = 0;
931c2c66affSColin Finck SetLastError( 0xdeadbeef );
932c2c66affSColin Finck ret = pGetVolumePathNamesForVolumeNameA( NULL, NULL, 0, &len );
933c2c66affSColin Finck error = GetLastError();
934c2c66affSColin Finck ok(!ret, "expected failure\n");
935c2c66affSColin Finck ok(error == ERROR_INVALID_NAME, "expected ERROR_INVALID_NAME got %u\n", error);
936c2c66affSColin Finck
937c2c66affSColin Finck len = 0;
938c2c66affSColin Finck SetLastError( 0xdeadbeef );
939c2c66affSColin Finck ret = pGetVolumePathNamesForVolumeNameA( NULL, NULL, sizeof(buffer), &len );
940c2c66affSColin Finck error = GetLastError();
941c2c66affSColin Finck ok(!ret, "expected failure\n");
942c2c66affSColin Finck ok(error == ERROR_INVALID_NAME, "expected ERROR_INVALID_NAME got %u\n", error);
943c2c66affSColin Finck
944c2c66affSColin Finck len = 0;
945c2c66affSColin Finck SetLastError( 0xdeadbeef );
946c2c66affSColin Finck ret = pGetVolumePathNamesForVolumeNameA( NULL, buffer, sizeof(buffer), &len );
947c2c66affSColin Finck error = GetLastError();
948c2c66affSColin Finck ok(!ret, "expected failure\n");
949c2c66affSColin Finck ok(error == ERROR_INVALID_NAME, "expected ERROR_INVALID_NAME got %u\n", error);
950c2c66affSColin Finck
951c2c66affSColin Finck len = 0;
952c2c66affSColin Finck SetLastError( 0xdeadbeef );
953c2c66affSColin Finck ret = pGetVolumePathNamesForVolumeNameA( NULL, buffer, sizeof(buffer), &len );
954c2c66affSColin Finck error = GetLastError();
955c2c66affSColin Finck ok(!ret, "expected failure\n");
956c2c66affSColin Finck ok(error == ERROR_INVALID_NAME, "expected ERROR_INVALID_NAME got %u\n", error);
957c2c66affSColin Finck
958c2c66affSColin Finck len = 0;
959c2c66affSColin Finck memset( buffer, 0xff, sizeof(buffer) );
960c2c66affSColin Finck ret = pGetVolumePathNamesForVolumeNameA( volume, buffer, sizeof(buffer), &len );
961c2c66affSColin Finck ok(ret, "failed to get path names %u\n", GetLastError());
962c2c66affSColin Finck ok(len == 5 || broken(len == 2), "expected 5 got %u\n", len);
963c2c66affSColin Finck ok(!strcmp( "C:\\", buffer ), "expected \"\\C:\" got \"%s\"\n", buffer);
964c2c66affSColin Finck ok(!buffer[4], "expected double null-terminated buffer\n");
965c2c66affSColin Finck }
966c2c66affSColin Finck
test_GetVolumePathNamesForVolumeNameW(void)967c2c66affSColin Finck static void test_GetVolumePathNamesForVolumeNameW(void)
968c2c66affSColin Finck {
969c2c66affSColin Finck static const WCHAR empty[] = {0};
970c2c66affSColin Finck static const WCHAR drive_c[] = {'c',':','\\',0};
971c2c66affSColin Finck static const WCHAR volume_null[] = {'\\','\\','?','\\','V','o','l','u','m','e',
972c2c66affSColin Finck '{','0','0','0','0','0','0','0','0','-','0','0','0','0','-','0','0','0','0',
973c2c66affSColin Finck '-','0','0','0','0','-','0','0','0','0','0','0','0','0','0','0','0','0','}','\\',0};
974c2c66affSColin Finck BOOL ret;
975c2c66affSColin Finck WCHAR volume[MAX_PATH], buffer[MAX_PATH];
976c2c66affSColin Finck DWORD len, error;
977c2c66affSColin Finck
978c2c66affSColin Finck #ifdef __REACTOS__
979c2c66affSColin Finck /* due to failing all calls to GetVolumeNameForVolumeMountPointW, this
980c2c66affSColin Finck * buffer never gets initialized and could cause a buffer overflow later */
981c2c66affSColin Finck volume[0] = '$';
982c2c66affSColin Finck volume[1] = 0;
983c2c66affSColin Finck #endif /* __REACTOS__ */
984c2c66affSColin Finck
985c2c66affSColin Finck if (!pGetVolumePathNamesForVolumeNameW || !pGetVolumeNameForVolumeMountPointW)
986c2c66affSColin Finck {
987c2c66affSColin Finck win_skip("required functions not found\n");
988c2c66affSColin Finck return;
989c2c66affSColin Finck }
990c2c66affSColin Finck
991c2c66affSColin Finck ret = pGetVolumeNameForVolumeMountPointW( drive_c, volume, sizeof(volume)/sizeof(volume[0]) );
992c2c66affSColin Finck ok(ret, "failed to get volume name %u\n", GetLastError());
993c2c66affSColin Finck
994c2c66affSColin Finck SetLastError( 0xdeadbeef );
995c2c66affSColin Finck ret = pGetVolumePathNamesForVolumeNameW( empty, NULL, 0, NULL );
996c2c66affSColin Finck error = GetLastError();
997c2c66affSColin Finck ok(!ret, "expected failure\n");
998c2c66affSColin Finck ok(error == ERROR_INVALID_NAME, "expected ERROR_INVALID_NAME got %u\n", error);
999c2c66affSColin Finck
1000c2c66affSColin Finck SetLastError( 0xdeadbeef );
1001c2c66affSColin Finck ret = pGetVolumePathNamesForVolumeNameW( volume, NULL, 0, NULL );
1002c2c66affSColin Finck error = GetLastError();
1003c2c66affSColin Finck ok(!ret, "expected failure\n");
1004c2c66affSColin Finck ok(error == ERROR_MORE_DATA, "expected ERROR_MORE_DATA got %u\n", error);
1005c2c66affSColin Finck
1006c2c66affSColin Finck SetLastError( 0xdeadbeef );
1007c2c66affSColin Finck ret = pGetVolumePathNamesForVolumeNameW( volume, buffer, 0, NULL );
1008c2c66affSColin Finck error = GetLastError();
1009c2c66affSColin Finck ok(!ret, "expected failure\n");
1010c2c66affSColin Finck ok(error == ERROR_MORE_DATA, "expected ERROR_MORE_DATA got %u\n", error);
1011c2c66affSColin Finck
1012c2c66affSColin Finck if (0) { /* crash */
1013c2c66affSColin Finck ret = pGetVolumePathNamesForVolumeNameW( volume, NULL, sizeof(buffer), NULL );
1014c2c66affSColin Finck ok(ret, "failed to get path names %u\n", GetLastError());
1015c2c66affSColin Finck }
1016c2c66affSColin Finck
1017c2c66affSColin Finck ret = pGetVolumePathNamesForVolumeNameW( volume, buffer, sizeof(buffer), NULL );
1018c2c66affSColin Finck ok(ret, "failed to get path names %u\n", GetLastError());
1019c2c66affSColin Finck
1020c2c66affSColin Finck len = 0;
1021c2c66affSColin Finck memset( buffer, 0xff, sizeof(buffer) );
1022c2c66affSColin Finck ret = pGetVolumePathNamesForVolumeNameW( volume, buffer, sizeof(buffer), &len );
1023c2c66affSColin Finck ok(ret, "failed to get path names %u\n", GetLastError());
1024c2c66affSColin Finck ok(len == 5, "expected 5 got %u\n", len);
1025c2c66affSColin Finck ok(!buffer[4], "expected double null-terminated buffer\n");
1026c2c66affSColin Finck
1027c2c66affSColin Finck len = 0;
1028c2c66affSColin Finck volume[1] = '?';
1029c2c66affSColin Finck volume[lstrlenW( volume ) - 1] = 0;
1030c2c66affSColin Finck SetLastError( 0xdeadbeef );
1031c2c66affSColin Finck ret = pGetVolumePathNamesForVolumeNameW( volume, buffer, sizeof(buffer), &len );
1032c2c66affSColin Finck error = GetLastError();
1033c2c66affSColin Finck ok(!ret, "expected failure\n");
1034c2c66affSColin Finck ok(error == ERROR_INVALID_NAME, "expected ERROR_INVALID_NAME got %u\n", error);
1035c2c66affSColin Finck
1036c2c66affSColin Finck len = 0;
1037c2c66affSColin Finck volume[0] = '\\';
1038c2c66affSColin Finck volume[1] = 0;
1039c2c66affSColin Finck SetLastError( 0xdeadbeef );
1040c2c66affSColin Finck ret = pGetVolumePathNamesForVolumeNameW( volume, buffer, sizeof(buffer), &len );
1041c2c66affSColin Finck error = GetLastError();
1042c2c66affSColin Finck ok(!ret, "expected failure\n");
1043c2c66affSColin Finck todo_wine ok(error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER got %u\n", error);
1044c2c66affSColin Finck
1045c2c66affSColin Finck len = 0;
1046c2c66affSColin Finck lstrcpyW( volume, volume_null );
1047c2c66affSColin Finck SetLastError( 0xdeadbeef );
1048c2c66affSColin Finck ret = pGetVolumePathNamesForVolumeNameW( volume, buffer, sizeof(buffer), &len );
1049c2c66affSColin Finck error = GetLastError();
1050c2c66affSColin Finck ok(!ret, "expected failure\n");
1051c2c66affSColin Finck ok(error == ERROR_FILE_NOT_FOUND, "expected ERROR_FILE_NOT_FOUND got %u\n", error);
1052c2c66affSColin Finck }
1053c2c66affSColin Finck
test_dvd_read_structure(HANDLE handle)1054c2c66affSColin Finck static void test_dvd_read_structure(HANDLE handle)
1055c2c66affSColin Finck {
1056c2c66affSColin Finck int i;
1057c2c66affSColin Finck DWORD nbBytes;
1058c2c66affSColin Finck BOOL ret;
1059c2c66affSColin Finck DVD_READ_STRUCTURE dvdReadStructure;
1060c2c66affSColin Finck DVD_LAYER_DESCRIPTOR dvdLayerDescriptor;
1061c2c66affSColin Finck struct COMPLETE_DVD_LAYER_DESCRIPTOR completeDvdLayerDescriptor;
1062c2c66affSColin Finck DVD_COPYRIGHT_DESCRIPTOR dvdCopyrightDescriptor;
1063c2c66affSColin Finck struct COMPLETE_DVD_MANUFACTURER_DESCRIPTOR completeDvdManufacturerDescriptor;
1064c2c66affSColin Finck
1065c2c66affSColin Finck dvdReadStructure.BlockByteOffset.QuadPart = 0;
1066c2c66affSColin Finck dvdReadStructure.SessionId = 0;
1067c2c66affSColin Finck dvdReadStructure.LayerNumber = 0;
1068c2c66affSColin Finck
1069c2c66affSColin Finck
1070c2c66affSColin Finck /* DvdPhysicalDescriptor */
1071c2c66affSColin Finck dvdReadStructure.Format = 0;
1072c2c66affSColin Finck
1073c2c66affSColin Finck SetLastError(0xdeadbeef);
1074c2c66affSColin Finck
1075c2c66affSColin Finck /* Test whether this ioctl is supported */
1076c2c66affSColin Finck ret = DeviceIoControl(handle, IOCTL_DVD_READ_STRUCTURE, &dvdReadStructure, sizeof(DVD_READ_STRUCTURE),
1077c2c66affSColin Finck &completeDvdLayerDescriptor, sizeof(struct COMPLETE_DVD_LAYER_DESCRIPTOR), &nbBytes, NULL);
1078c2c66affSColin Finck
1079c2c66affSColin Finck if(!ret)
1080c2c66affSColin Finck {
1081c2c66affSColin Finck skip("IOCTL_DVD_READ_STRUCTURE not supported: %u\n", GetLastError());
1082c2c66affSColin Finck return;
1083c2c66affSColin Finck }
1084c2c66affSColin Finck
1085c2c66affSColin Finck /* Confirm there is always a header before the actual data */
1086c2c66affSColin Finck ok( completeDvdLayerDescriptor.Header.Length == 0x0802, "Length is 0x%04x instead of 0x0802\n", completeDvdLayerDescriptor.Header.Length);
1087c2c66affSColin Finck ok( completeDvdLayerDescriptor.Header.Reserved[0] == 0, "Reserved[0] is %x instead of 0\n", completeDvdLayerDescriptor.Header.Reserved[0]);
1088c2c66affSColin Finck ok( completeDvdLayerDescriptor.Header.Reserved[1] == 0, "Reserved[1] is %x instead of 0\n", completeDvdLayerDescriptor.Header.Reserved[1]);
1089c2c66affSColin Finck
1090c2c66affSColin Finck /* TODO: Also check completeDvdLayerDescriptor.Descriptor content (via IOCTL_SCSI_PASS_THROUGH_DIRECT ?) */
1091c2c66affSColin Finck
1092c2c66affSColin Finck /* Insufficient output buffer */
1093c2c66affSColin Finck for(i=0; i<sizeof(DVD_DESCRIPTOR_HEADER); i++)
1094c2c66affSColin Finck {
1095c2c66affSColin Finck SetLastError(0xdeadbeef);
1096c2c66affSColin Finck
1097c2c66affSColin Finck ret = DeviceIoControl(handle, IOCTL_DVD_READ_STRUCTURE, &dvdReadStructure, sizeof(DVD_READ_STRUCTURE),
1098c2c66affSColin Finck &completeDvdLayerDescriptor, i, &nbBytes, NULL);
1099c2c66affSColin Finck ok(!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER,"IOCTL_DVD_READ_STRUCTURE should fail with small buffer\n");
1100c2c66affSColin Finck }
1101c2c66affSColin Finck
1102c2c66affSColin Finck SetLastError(0xdeadbeef);
1103c2c66affSColin Finck
1104c2c66affSColin Finck /* On newer version, an output buffer of sizeof(DVD_READ_STRUCTURE) size fails.
1105c2c66affSColin Finck I think this is to force developers to realize that there is a header before the actual content */
1106c2c66affSColin Finck ret = DeviceIoControl(handle, IOCTL_DVD_READ_STRUCTURE, &dvdReadStructure, sizeof(DVD_READ_STRUCTURE),
1107c2c66affSColin Finck &dvdLayerDescriptor, sizeof(DVD_LAYER_DESCRIPTOR), &nbBytes, NULL);
1108c2c66affSColin Finck ok( (!ret && GetLastError() == ERROR_INVALID_PARAMETER) || broken(ret) /* < Win7 */,
1109c2c66affSColin Finck "IOCTL_DVD_READ_STRUCTURE should have failed\n");
1110c2c66affSColin Finck
1111c2c66affSColin Finck SetLastError(0xdeadbeef);
1112c2c66affSColin Finck
1113c2c66affSColin Finck ret = DeviceIoControl(handle, IOCTL_DVD_READ_STRUCTURE, NULL, sizeof(DVD_READ_STRUCTURE),
1114c2c66affSColin Finck &completeDvdLayerDescriptor, sizeof(struct COMPLETE_DVD_LAYER_DESCRIPTOR), &nbBytes, NULL);
1115c2c66affSColin Finck ok( (!ret && GetLastError() == ERROR_INVALID_PARAMETER),
1116c2c66affSColin Finck "IOCTL_DVD_READ_STRUCTURE should have failed\n");
1117c2c66affSColin Finck
1118c2c66affSColin Finck /* Test wrong input parameters */
1119c2c66affSColin Finck for(i=0; i<sizeof(DVD_READ_STRUCTURE); i++)
1120c2c66affSColin Finck {
1121c2c66affSColin Finck SetLastError(0xdeadbeef);
1122c2c66affSColin Finck
1123c2c66affSColin Finck ret = DeviceIoControl(handle, IOCTL_DVD_READ_STRUCTURE, &dvdReadStructure, i,
1124c2c66affSColin Finck &completeDvdLayerDescriptor, sizeof(struct COMPLETE_DVD_LAYER_DESCRIPTOR), &nbBytes, NULL);
1125c2c66affSColin Finck ok( (!ret && GetLastError() == ERROR_INVALID_PARAMETER),
1126c2c66affSColin Finck "IOCTL_DVD_READ_STRUCTURE should have failed\n");
1127c2c66affSColin Finck }
1128c2c66affSColin Finck
1129c2c66affSColin Finck
1130c2c66affSColin Finck /* DvdCopyrightDescriptor */
1131c2c66affSColin Finck dvdReadStructure.Format = 1;
1132c2c66affSColin Finck
1133c2c66affSColin Finck SetLastError(0xdeadbeef);
1134c2c66affSColin Finck
1135c2c66affSColin Finck /* Strangely, with NULL lpOutBuffer, last error is insufficient buffer, not invalid parameter as we could expect */
1136c2c66affSColin Finck ret = DeviceIoControl(handle, IOCTL_DVD_READ_STRUCTURE, &dvdReadStructure, sizeof(DVD_READ_STRUCTURE),
1137c2c66affSColin Finck NULL, sizeof(DVD_COPYRIGHT_DESCRIPTOR), &nbBytes, NULL);
1138c2c66affSColin Finck ok(!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER, "IOCTL_DVD_READ_STRUCTURE should have failed %d %u\n", ret, GetLastError());
1139c2c66affSColin Finck
1140c2c66affSColin Finck for(i=0; i<sizeof(DVD_COPYRIGHT_DESCRIPTOR); i++)
1141c2c66affSColin Finck {
1142c2c66affSColin Finck SetLastError(0xdeadbeef);
1143c2c66affSColin Finck
1144c2c66affSColin Finck ret = DeviceIoControl(handle, IOCTL_DVD_READ_STRUCTURE, &dvdReadStructure, sizeof(DVD_READ_STRUCTURE),
1145c2c66affSColin Finck &dvdCopyrightDescriptor, i, &nbBytes, NULL);
1146c2c66affSColin Finck ok(!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER, "IOCTL_DVD_READ_STRUCTURE should have failed %d %u\n", ret, GetLastError());
1147c2c66affSColin Finck }
1148c2c66affSColin Finck
1149c2c66affSColin Finck
1150c2c66affSColin Finck /* DvdManufacturerDescriptor */
1151c2c66affSColin Finck dvdReadStructure.Format = 4;
1152c2c66affSColin Finck
1153c2c66affSColin Finck SetLastError(0xdeadbeef);
1154c2c66affSColin Finck
1155c2c66affSColin Finck ret = DeviceIoControl(handle, IOCTL_DVD_READ_STRUCTURE, &dvdReadStructure, sizeof(DVD_READ_STRUCTURE),
1156c2c66affSColin Finck &completeDvdManufacturerDescriptor, sizeof(DVD_MANUFACTURER_DESCRIPTOR), &nbBytes, NULL);
1157c2c66affSColin Finck ok(ret || broken(GetLastError() == ERROR_NOT_READY),
1158c2c66affSColin Finck "IOCTL_DVD_READ_STRUCTURE (DvdManufacturerDescriptor) failed, last error = %u\n", GetLastError());
1159c2c66affSColin Finck if(!ret)
1160c2c66affSColin Finck return;
1161c2c66affSColin Finck
1162c2c66affSColin Finck /* Confirm there is always a header before the actual data */
1163c2c66affSColin Finck ok( completeDvdManufacturerDescriptor.Header.Length == 0x0802, "Length is 0x%04x instead of 0x0802\n", completeDvdManufacturerDescriptor.Header.Length);
1164c2c66affSColin Finck ok( completeDvdManufacturerDescriptor.Header.Reserved[0] == 0, "Reserved[0] is %x instead of 0\n", completeDvdManufacturerDescriptor.Header.Reserved[0]);
1165c2c66affSColin Finck ok( completeDvdManufacturerDescriptor.Header.Reserved[1] == 0, "Reserved[1] is %x instead of 0\n", completeDvdManufacturerDescriptor.Header.Reserved[1]);
1166c2c66affSColin Finck
1167c2c66affSColin Finck SetLastError(0xdeadbeef);
1168c2c66affSColin Finck
1169c2c66affSColin Finck /* Basic parameter check */
1170c2c66affSColin Finck ret = DeviceIoControl(handle, IOCTL_DVD_READ_STRUCTURE, &dvdReadStructure, sizeof(DVD_READ_STRUCTURE),
1171c2c66affSColin Finck NULL, sizeof(DVD_MANUFACTURER_DESCRIPTOR), &nbBytes, NULL);
1172c2c66affSColin Finck ok(!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER, "IOCTL_DVD_READ_STRUCTURE should have failed %d %u\n", ret, GetLastError());
1173c2c66affSColin Finck }
1174c2c66affSColin Finck
test_cdrom_ioctl(void)1175c2c66affSColin Finck static void test_cdrom_ioctl(void)
1176c2c66affSColin Finck {
1177c2c66affSColin Finck char drive_letter, drive_path[] = "A:\\", drive_full_path[] = "\\\\.\\A:";
1178c2c66affSColin Finck DWORD bitmask;
1179c2c66affSColin Finck HANDLE handle;
1180c2c66affSColin Finck
1181c2c66affSColin Finck bitmask = GetLogicalDrives();
1182c2c66affSColin Finck if(!bitmask)
1183c2c66affSColin Finck {
1184c2c66affSColin Finck trace("GetLogicalDrives failed : %u\n", GetLastError());
1185c2c66affSColin Finck return;
1186c2c66affSColin Finck }
1187c2c66affSColin Finck
1188c2c66affSColin Finck for(drive_letter='A'; drive_letter<='Z'; drive_letter++)
1189c2c66affSColin Finck {
1190c2c66affSColin Finck if(!(bitmask & (1 << (drive_letter-'A') )))
1191c2c66affSColin Finck continue;
1192c2c66affSColin Finck
1193c2c66affSColin Finck drive_path[0] = drive_letter;
1194c2c66affSColin Finck if(GetDriveTypeA(drive_path) != DRIVE_CDROM)
1195c2c66affSColin Finck {
1196c2c66affSColin Finck trace("Skipping %c:, not a CDROM drive.\n", drive_letter);
1197c2c66affSColin Finck continue;
1198c2c66affSColin Finck }
1199c2c66affSColin Finck
1200c2c66affSColin Finck trace("Testing with %c:\n", drive_letter);
1201c2c66affSColin Finck
1202c2c66affSColin Finck drive_full_path[4] = drive_letter;
1203c2c66affSColin Finck handle = CreateFileA(drive_full_path, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0);
1204c2c66affSColin Finck if(handle == INVALID_HANDLE_VALUE)
1205c2c66affSColin Finck {
1206c2c66affSColin Finck trace("Failed to open the device : %u\n", GetLastError());
1207c2c66affSColin Finck continue;
1208c2c66affSColin Finck }
1209c2c66affSColin Finck
1210c2c66affSColin Finck /* Add your tests here */
1211c2c66affSColin Finck test_dvd_read_structure(handle);
1212c2c66affSColin Finck
1213c2c66affSColin Finck CloseHandle(handle);
1214c2c66affSColin Finck }
1215c2c66affSColin Finck
1216c2c66affSColin Finck }
1217c2c66affSColin Finck
START_TEST(volume)1218c2c66affSColin Finck START_TEST(volume)
1219c2c66affSColin Finck {
1220c2c66affSColin Finck hdll = GetModuleHandleA("kernel32.dll");
1221c2c66affSColin Finck pGetVolumeNameForVolumeMountPointA = (void *) GetProcAddress(hdll, "GetVolumeNameForVolumeMountPointA");
1222c2c66affSColin Finck pGetVolumeNameForVolumeMountPointW = (void *) GetProcAddress(hdll, "GetVolumeNameForVolumeMountPointW");
1223c2c66affSColin Finck pFindFirstVolumeA = (void *) GetProcAddress(hdll, "FindFirstVolumeA");
1224c2c66affSColin Finck pFindNextVolumeA = (void *) GetProcAddress(hdll, "FindNextVolumeA");
1225c2c66affSColin Finck pFindVolumeClose = (void *) GetProcAddress(hdll, "FindVolumeClose");
1226c2c66affSColin Finck pGetLogicalDriveStringsA = (void *) GetProcAddress(hdll, "GetLogicalDriveStringsA");
1227c2c66affSColin Finck pGetLogicalDriveStringsW = (void *) GetProcAddress(hdll, "GetLogicalDriveStringsW");
1228c2c66affSColin Finck pGetVolumeInformationA = (void *) GetProcAddress(hdll, "GetVolumeInformationA");
1229c2c66affSColin Finck pGetVolumePathNameA = (void *) GetProcAddress(hdll, "GetVolumePathNameA");
1230c2c66affSColin Finck pGetVolumePathNameW = (void *) GetProcAddress(hdll, "GetVolumePathNameW");
1231c2c66affSColin Finck pGetVolumePathNamesForVolumeNameA = (void *) GetProcAddress(hdll, "GetVolumePathNamesForVolumeNameA");
1232c2c66affSColin Finck pGetVolumePathNamesForVolumeNameW = (void *) GetProcAddress(hdll, "GetVolumePathNamesForVolumeNameW");
1233c2c66affSColin Finck
1234c2c66affSColin Finck test_query_dos_deviceA();
1235c2c66affSColin Finck test_define_dos_deviceA();
1236c2c66affSColin Finck test_FindFirstVolume();
1237c2c66affSColin Finck test_GetVolumePathNameA();
1238c2c66affSColin Finck test_GetVolumePathNameW();
1239c2c66affSColin Finck test_GetVolumeNameForVolumeMountPointA();
1240c2c66affSColin Finck test_GetVolumeNameForVolumeMountPointW();
1241c2c66affSColin Finck test_GetLogicalDriveStringsA();
1242c2c66affSColin Finck test_GetLogicalDriveStringsW();
1243c2c66affSColin Finck test_GetVolumeInformationA();
1244c2c66affSColin Finck test_enum_vols();
1245c2c66affSColin Finck test_disk_extents();
1246c2c66affSColin Finck test_GetVolumePathNamesForVolumeNameA();
1247c2c66affSColin Finck test_GetVolumePathNamesForVolumeNameW();
1248c2c66affSColin Finck test_cdrom_ioctl();
1249c2c66affSColin Finck }
1250