mfplat: Read queue subscriber within the critical section.
[wine/zf.git] / dlls / kernel32 / tests / drive.c
blob98dc454f3403bdf2fb128eeaa28b712027db2f10
1 /*
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
21 #include <stdarg.h>
23 #include "wine/test.h"
24 #include "windef.h"
25 #include "winbase.h"
26 #include "winerror.h"
28 static DWORD (WINAPI *pGetDiskFreeSpaceExA)(LPCSTR, PULARGE_INTEGER, PULARGE_INTEGER, PULARGE_INTEGER);
30 static void test_GetDriveTypeA(void)
32 char drive[] = "?:\\";
33 char existing_drive_letter = 0;
34 DWORD logical_drives;
35 UINT type;
37 logical_drives = GetLogicalDrives();
38 ok(logical_drives != 0, "GetLogicalDrives error %d\n", GetLastError());
40 for (drive[0] = 'A'; drive[0] <= 'Z'; drive[0]++)
42 type = GetDriveTypeA(drive);
43 ok(type > DRIVE_UNKNOWN && type <= DRIVE_RAMDISK,
44 "not a valid drive %c: type %u\n", drive[0], type);
46 if (!(logical_drives & 1))
47 ok(type == DRIVE_NO_ROOT_DIR,
48 "GetDriveTypeA should return DRIVE_NO_ROOT_DIR for inexistent drive %c: but not %u\n",
49 drive[0], type);
50 else if (type != DRIVE_NO_ROOT_DIR)
51 existing_drive_letter = drive[0];
53 logical_drives >>= 1;
56 if (!existing_drive_letter) {
57 skip("No drives found, skipping drive spec format tests.\n");
58 return;
61 drive[0] = existing_drive_letter;
62 drive[2] = 0; /* C: */
63 type = GetDriveTypeA(drive);
64 ok(type > DRIVE_NO_ROOT_DIR && type <= DRIVE_RAMDISK, "got %u for drive spec '%s'\n", type, drive);
66 drive[1] = '?'; /* C? */
67 type = GetDriveTypeA(drive);
68 ok(type == DRIVE_NO_ROOT_DIR, "got %u for drive spec '%s'\n", type, drive);
70 drive[1] = 0; /* C */
71 type = GetDriveTypeA(drive);
72 ok(type == DRIVE_NO_ROOT_DIR, "got %u for drive spec '%s'\n", type, drive);
74 drive[0] = '?'; /* the string "?" */
75 type = GetDriveTypeA(drive);
76 ok(type == DRIVE_NO_ROOT_DIR, "got %u for drive spec '%s'\n", type, drive);
78 drive[0] = 0; /* the empty string */
79 type = GetDriveTypeA(drive);
80 ok(type == DRIVE_NO_ROOT_DIR, "got %u for drive spec '%s'\n", type, drive);
83 static void test_GetDriveTypeW(void)
85 WCHAR drive[] = {'?',':','\\',0};
86 WCHAR existing_drive_letter = 0;
87 DWORD logical_drives;
88 UINT type;
90 logical_drives = GetLogicalDrives();
91 ok(logical_drives != 0, "GetLogicalDrives error %d\n", GetLastError());
93 for (drive[0] = 'A'; drive[0] <= 'Z'; drive[0]++)
95 type = GetDriveTypeW(drive);
96 ok(type > DRIVE_UNKNOWN && type <= DRIVE_RAMDISK,
97 "not a valid drive %c: type %u\n", drive[0], type);
99 if (!(logical_drives & 1))
100 ok(type == DRIVE_NO_ROOT_DIR,
101 "GetDriveTypeW should return DRIVE_NO_ROOT_DIR for inexistent drive %c: but not %u\n",
102 drive[0], type);
103 else if (type != DRIVE_NO_ROOT_DIR)
104 existing_drive_letter = drive[0];
106 logical_drives >>= 1;
109 if (!existing_drive_letter) {
110 skip("No drives found, skipping drive spec format tests.\n");
111 return;
114 drive[0] = existing_drive_letter;
115 drive[2] = 0; /* C: */
116 type = GetDriveTypeW(drive);
117 ok(type > DRIVE_NO_ROOT_DIR && type <= DRIVE_RAMDISK, "got %u for drive spec '%s'\n",
118 type, wine_dbgstr_w(drive));
120 drive[1] = '?'; /* C? */
121 type = GetDriveTypeW(drive);
122 ok(type == DRIVE_NO_ROOT_DIR, "got %u for drive spec '%s'\n", type, wine_dbgstr_w(drive));
124 drive[1] = 0; /* C */
125 type = GetDriveTypeW(drive);
126 ok(type == DRIVE_NO_ROOT_DIR, "got %u for drive spec '%s'\n", type, wine_dbgstr_w(drive));
128 drive[0] = '?'; /* the string "?" */
129 type = GetDriveTypeW(drive);
130 ok(type == DRIVE_NO_ROOT_DIR, "got %u for drive spec '%s'\n", type, wine_dbgstr_w(drive));
132 drive[0] = 0; /* the empty string */
133 type = GetDriveTypeW(drive);
134 ok(type == DRIVE_NO_ROOT_DIR, "got %u for drive spec '%s'\n", type, wine_dbgstr_w(drive));
137 static void test_GetDiskFreeSpaceA(void)
139 BOOL ret;
140 DWORD sectors_per_cluster, bytes_per_sector, free_clusters, total_clusters;
141 char drive[] = "?:\\";
142 DWORD logical_drives;
144 ret = GetDiskFreeSpaceA(NULL, &sectors_per_cluster, &bytes_per_sector, &free_clusters, &total_clusters);
145 ok(ret, "GetDiskFreeSpaceA error %d\n", GetLastError());
147 ret = GetDiskFreeSpaceA("", &sectors_per_cluster, &bytes_per_sector, &free_clusters, &total_clusters);
148 ok(!ret && (GetLastError() == ERROR_PATH_NOT_FOUND || GetLastError() == ERROR_INVALID_NAME),
149 "GetDiskFreeSpaceA(\"\"): ret=%d GetLastError=%d\n",
150 ret, GetLastError());
152 ret = GetDiskFreeSpaceA("\\", &sectors_per_cluster, &bytes_per_sector, &free_clusters, &total_clusters);
153 ok(ret, "GetDiskFreeSpaceA error %d\n", GetLastError());
155 ret = GetDiskFreeSpaceA("/", &sectors_per_cluster, &bytes_per_sector, &free_clusters, &total_clusters);
156 ok(ret, "GetDiskFreeSpaceA error %d\n", GetLastError());
158 logical_drives = GetLogicalDrives();
159 ok(logical_drives != 0, "GetLogicalDrives error %d\n", GetLastError());
161 for (drive[0] = 'A'; drive[0] <= 'Z'; drive[0]++)
163 UINT drivetype = GetDriveTypeA(drive);
164 /* Skip floppy drives because NT pops up a MessageBox if no
165 * floppy is present
167 if (drivetype != DRIVE_REMOVABLE && drivetype != DRIVE_NO_ROOT_DIR)
169 ret = GetDiskFreeSpaceA(drive, &sectors_per_cluster, &bytes_per_sector, &free_clusters, &total_clusters);
170 if (!(logical_drives & 1))
171 ok(!ret && (GetLastError() == ERROR_PATH_NOT_FOUND || GetLastError() == ERROR_INVALID_DRIVE),
172 "GetDiskFreeSpaceA(%s): ret=%d GetLastError=%d\n",
173 drive, ret, GetLastError());
174 else
177 if (!ret)
178 /* GetDiskFreeSpaceA() should succeed, but it can fail with too many
179 different GetLastError() results to be usable for an ok() */
180 trace("GetDiskFreeSpaceA(%s) failed with %d\n", drive, GetLastError());
182 if( GetVersion() & 0x80000000)
183 /* win3.0 through winME */
184 ok( total_clusters <= 65535,
185 "total clusters is %d > 65535\n", total_clusters);
186 else if (pGetDiskFreeSpaceExA) {
187 /* NT, 2k, XP : GetDiskFreeSpace should be accurate */
188 ULARGE_INTEGER totEx, tot, d;
190 tot.QuadPart = sectors_per_cluster;
191 tot.QuadPart = (tot.QuadPart * bytes_per_sector) * total_clusters;
192 ret = pGetDiskFreeSpaceExA( drive, &d, &totEx, NULL);
194 if (!ret)
195 /* GetDiskFreeSpaceExA() should succeed, but it can fail with too many
196 different GetLastError() results to be usable for an ok() */
197 trace("GetDiskFreeSpaceExA(%s) failed with %d\n", drive, GetLastError());
199 ok( bytes_per_sector == 0 || /* empty cd rom drive */
200 totEx.QuadPart <= tot.QuadPart,
201 "GetDiskFreeSpaceA should report at least as much bytes on disk %s as GetDiskFreeSpaceExA\n", drive);
205 logical_drives >>= 1;
209 static void test_GetDiskFreeSpaceW(void)
211 BOOL ret;
212 DWORD sectors_per_cluster, bytes_per_sector, free_clusters, total_clusters;
213 WCHAR drive[] = {'?',':','\\',0};
214 DWORD logical_drives;
215 static const WCHAR empty_pathW[] = { 0 };
216 static const WCHAR root_pathW[] = { '\\', 0 };
217 static const WCHAR unix_style_root_pathW[] = { '/', 0 };
219 ret = GetDiskFreeSpaceW(NULL, &sectors_per_cluster, &bytes_per_sector, &free_clusters, &total_clusters);
220 if (ret == 0 && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
222 win_skip("GetDiskFreeSpaceW is not available\n");
223 return;
225 ok(ret, "GetDiskFreeSpaceW error %d\n", GetLastError());
227 ret = GetDiskFreeSpaceW(empty_pathW, &sectors_per_cluster, &bytes_per_sector, &free_clusters, &total_clusters);
228 ok(!ret && GetLastError() == ERROR_PATH_NOT_FOUND,
229 "GetDiskFreeSpaceW(\"\"): ret=%d GetLastError=%d\n",
230 ret, GetLastError());
232 ret = GetDiskFreeSpaceW(root_pathW, &sectors_per_cluster, &bytes_per_sector, &free_clusters, &total_clusters);
233 ok(ret, "GetDiskFreeSpaceW(\"\") error %d\n", GetLastError());
235 ret = GetDiskFreeSpaceW(unix_style_root_pathW, &sectors_per_cluster, &bytes_per_sector, &free_clusters, &total_clusters);
236 ok(ret, "GetDiskFreeSpaceW error %d\n", GetLastError());
238 logical_drives = GetLogicalDrives();
239 ok(logical_drives != 0, "GetLogicalDrives error %d\n", GetLastError());
241 for (drive[0] = 'A'; drive[0] <= 'Z'; drive[0]++)
243 UINT drivetype = GetDriveTypeW(drive);
244 /* Skip floppy drives because NT4 pops up a MessageBox if no floppy is present */
245 if (drivetype != DRIVE_REMOVABLE && drivetype != DRIVE_NO_ROOT_DIR)
247 ret = GetDiskFreeSpaceW(drive, &sectors_per_cluster, &bytes_per_sector, &free_clusters, &total_clusters);
248 if (!(logical_drives & 1))
249 ok(!ret && GetLastError() == ERROR_PATH_NOT_FOUND,
250 "GetDiskFreeSpaceW(%c): ret=%d GetLastError=%d\n",
251 drive[0], ret, GetLastError());
252 else if (!ret)
253 /* GetDiskFreeSpaceW() should succeed, but it can fail with too many
254 different GetLastError() results to be usable for an ok() */
255 trace("GetDiskFreeSpaceW(%c) failed with %d\n", drive[0], GetLastError());
257 logical_drives >>= 1;
261 START_TEST(drive)
263 HANDLE hkernel32 = GetModuleHandleA("kernel32");
264 pGetDiskFreeSpaceExA = (void *) GetProcAddress(hkernel32, "GetDiskFreeSpaceExA");
266 test_GetDriveTypeA();
267 test_GetDriveTypeW();
269 test_GetDiskFreeSpaceA();
270 test_GetDiskFreeSpaceW();