2 * Unit test suite for drive functions.
4 * Copyright 2002 Dmitry Timoshkov
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
23 #include "wine/test.h"
28 static DWORD (WINAPI
*pGetDiskFreeSpaceExA
)(LPCSTR
, PULARGE_INTEGER
, PULARGE_INTEGER
, PULARGE_INTEGER
);
30 static void test_GetDriveTypeA(void)
32 char drive
[] = "?:\\";
36 logical_drives
= GetLogicalDrives();
37 ok(logical_drives
!= 0, "GetLogicalDrives error %d\n", GetLastError());
39 for (drive
[0] = 'A'; drive
[0] <= 'Z'; drive
[0]++)
41 type
= GetDriveTypeA(drive
);
42 ok(type
> DRIVE_UNKNOWN
&& type
<= DRIVE_RAMDISK
,
43 "not a valid drive %c: type %u\n", drive
[0], type
);
45 if (!(logical_drives
& 1))
46 ok(type
== DRIVE_NO_ROOT_DIR
,
47 "GetDriveTypeA should return DRIVE_NO_ROOT_DIR for inexistent drive %c: but not %u\n",
54 static void test_GetDriveTypeW(void)
56 WCHAR drive
[] = {'?',':','\\',0};
60 logical_drives
= GetLogicalDrives();
61 ok(logical_drives
!= 0, "GetLogicalDrives error %d\n", GetLastError());
63 for (drive
[0] = 'A'; drive
[0] <= 'Z'; drive
[0]++)
65 type
= GetDriveTypeW(drive
);
66 if (type
== DRIVE_UNKNOWN
&& GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
68 win_skip("GetDriveTypeW is not available on Win9x\n");
71 ok(type
> DRIVE_UNKNOWN
&& type
<= DRIVE_RAMDISK
,
72 "not a valid drive %c: type %u\n", drive
[0], type
);
74 if (!(logical_drives
& 1))
75 ok(type
== DRIVE_NO_ROOT_DIR
,
76 "GetDriveTypeW should return DRIVE_NO_ROOT_DIR for inexistent drive %c: but not %u\n",
83 static void test_GetDiskFreeSpaceA(void)
86 DWORD sectors_per_cluster
, bytes_per_sector
, free_clusters
, total_clusters
;
87 char drive
[] = "?:\\";
90 ret
= GetDiskFreeSpaceA(NULL
, §ors_per_cluster
, &bytes_per_sector
, &free_clusters
, &total_clusters
);
91 ok(ret
, "GetDiskFreeSpaceA error %d\n", GetLastError());
93 ret
= GetDiskFreeSpaceA("", §ors_per_cluster
, &bytes_per_sector
, &free_clusters
, &total_clusters
);
94 ok(!ret
&& (GetLastError() == ERROR_PATH_NOT_FOUND
|| GetLastError() == ERROR_INVALID_NAME
),
95 "GetDiskFreeSpaceA(\"\"): ret=%d GetLastError=%d\n",
98 ret
= GetDiskFreeSpaceA("\\", §ors_per_cluster
, &bytes_per_sector
, &free_clusters
, &total_clusters
);
99 ok(ret
, "GetDiskFreeSpaceA error %d\n", GetLastError());
101 ret
= GetDiskFreeSpaceA("/", §ors_per_cluster
, &bytes_per_sector
, &free_clusters
, &total_clusters
);
102 ok(ret
, "GetDiskFreeSpaceA error %d\n", GetLastError());
104 logical_drives
= GetLogicalDrives();
105 ok(logical_drives
!= 0, "GetLogicalDrives error %d\n", GetLastError());
107 for (drive
[0] = 'A'; drive
[0] <= 'Z'; drive
[0]++)
109 UINT drivetype
= GetDriveTypeA(drive
);
110 /* Skip floppy drives because NT pops up a MessageBox if no
113 if (drivetype
!= DRIVE_REMOVABLE
&& drivetype
!= DRIVE_NO_ROOT_DIR
)
115 ret
= GetDiskFreeSpaceA(drive
, §ors_per_cluster
, &bytes_per_sector
, &free_clusters
, &total_clusters
);
116 if (!(logical_drives
& 1))
117 ok(!ret
&& (GetLastError() == ERROR_PATH_NOT_FOUND
|| GetLastError() == ERROR_INVALID_DRIVE
),
118 "GetDiskFreeSpaceA(%s): ret=%d GetLastError=%d\n",
119 drive
, ret
, GetLastError());
123 GetLastError() == ERROR_NOT_READY
||
124 GetLastError() == ERROR_INVALID_FUNCTION
||
125 GetLastError() == ERROR_INVALID_DRIVE
||
126 GetLastError() == ERROR_PATH_NOT_FOUND
||
127 GetLastError() == ERROR_REQUEST_ABORTED
||
128 GetLastError() == ERROR_NETNAME_DELETED
||
129 GetLastError() == ERROR_UNRECOGNIZED_VOLUME
,
130 "GetDiskFreeSpaceA(%s): ret=%d GetLastError=%d\n",
131 drive
, ret
, GetLastError());
132 if( GetVersion() & 0x80000000)
133 /* win3.0 thru winME */
134 ok( total_clusters
<= 65535,
135 "total clusters is %d > 65535\n", total_clusters
);
136 else if (pGetDiskFreeSpaceExA
) {
137 /* NT, 2k, XP : GetDiskFreeSpace should be accurate */
138 ULARGE_INTEGER totEx
, tot
, d
;
140 tot
.QuadPart
= sectors_per_cluster
;
141 tot
.QuadPart
= (tot
.QuadPart
* bytes_per_sector
) * total_clusters
;
142 ret
= pGetDiskFreeSpaceExA( drive
, &d
, &totEx
, NULL
);
144 GetLastError() == ERROR_NOT_READY
||
145 GetLastError() == ERROR_INVALID_FUNCTION
||
146 GetLastError() == ERROR_PATH_NOT_FOUND
||
147 GetLastError() == ERROR_REQUEST_ABORTED
||
148 GetLastError() == ERROR_NETNAME_DELETED
||
149 GetLastError() == ERROR_UNRECOGNIZED_VOLUME
,
150 "GetDiskFreeSpaceExA( %s ) failed. GetLastError=%d\n", drive
, GetLastError());
151 ok( bytes_per_sector
== 0 || /* empty cd rom drive */
152 totEx
.QuadPart
<= tot
.QuadPart
,
153 "GetDiskFreeSpaceA should report at least as much bytes on disk %s as GetDiskFreeSpaceExA\n", drive
);
157 logical_drives
>>= 1;
161 static void test_GetDiskFreeSpaceW(void)
164 DWORD sectors_per_cluster
, bytes_per_sector
, free_clusters
, total_clusters
;
165 WCHAR drive
[] = {'?',':','\\',0};
166 DWORD logical_drives
;
167 static const WCHAR empty_pathW
[] = { 0 };
168 static const WCHAR root_pathW
[] = { '\\', 0 };
169 static const WCHAR unix_style_root_pathW
[] = { '/', 0 };
171 ret
= GetDiskFreeSpaceW(NULL
, §ors_per_cluster
, &bytes_per_sector
, &free_clusters
, &total_clusters
);
172 if (ret
== 0 && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
174 win_skip("GetDiskFreeSpaceW is not available\n");
177 ok(ret
, "GetDiskFreeSpaceW error %d\n", GetLastError());
179 ret
= GetDiskFreeSpaceW(empty_pathW
, §ors_per_cluster
, &bytes_per_sector
, &free_clusters
, &total_clusters
);
180 ok(!ret
&& GetLastError() == ERROR_PATH_NOT_FOUND
,
181 "GetDiskFreeSpaceW(\"\"): ret=%d GetLastError=%d\n",
182 ret
, GetLastError());
184 ret
= GetDiskFreeSpaceW(root_pathW
, §ors_per_cluster
, &bytes_per_sector
, &free_clusters
, &total_clusters
);
185 ok(ret
, "GetDiskFreeSpaceW(\"\") error %d\n", GetLastError());
187 ret
= GetDiskFreeSpaceW(unix_style_root_pathW
, §ors_per_cluster
, &bytes_per_sector
, &free_clusters
, &total_clusters
);
188 ok(ret
, "GetDiskFreeSpaceW error %d\n", GetLastError());
190 logical_drives
= GetLogicalDrives();
191 ok(logical_drives
!= 0, "GetLogicalDrives error %d\n", GetLastError());
193 for (drive
[0] = 'A'; drive
[0] <= 'Z'; drive
[0]++)
195 UINT drivetype
= GetDriveTypeW(drive
);
196 /* Skip floppy drives because NT4 pops up a MessageBox if no floppy is present */
197 if (drivetype
!= DRIVE_REMOVABLE
&& drivetype
!= DRIVE_NO_ROOT_DIR
)
199 ret
= GetDiskFreeSpaceW(drive
, §ors_per_cluster
, &bytes_per_sector
, &free_clusters
, &total_clusters
);
200 if (!(logical_drives
& 1))
201 ok(!ret
&& GetLastError() == ERROR_PATH_NOT_FOUND
,
202 "GetDiskFreeSpaceW(%c): ret=%d GetLastError=%d\n",
203 drive
[0], ret
, GetLastError());
206 GetLastError() == ERROR_NOT_READY
||
207 GetLastError() == ERROR_INVALID_FUNCTION
||
208 GetLastError() == ERROR_PATH_NOT_FOUND
||
209 GetLastError() == ERROR_REQUEST_ABORTED
||
210 GetLastError() == ERROR_UNRECOGNIZED_VOLUME
,
211 "GetDiskFreeSpaceW(%c): ret=%d GetLastError=%d\n",
212 drive
[0], ret
, GetLastError());
214 logical_drives
>>= 1;
220 HANDLE hkernel32
= GetModuleHandleA("kernel32");
221 pGetDiskFreeSpaceExA
= (void *) GetProcAddress(hkernel32
, "GetDiskFreeSpaceExA");
223 test_GetDriveTypeA();
224 test_GetDriveTypeW();
226 test_GetDiskFreeSpaceA();
227 test_GetDiskFreeSpaceW();