comctl32: Remove redundant parameter from a helper.
[wine/multimedia.git] / dlls / kernel32 / tests / drive.c
blobdb9c9c437f99966541587cba3c7e80ed22739a1e
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 DWORD logical_drives;
34 UINT type;
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",
48 drive[0], type);
50 logical_drives >>= 1;
54 static void test_GetDriveTypeW(void)
56 WCHAR drive[] = {'?',':','\\',0};
57 DWORD logical_drives;
58 UINT type;
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 ok(type > DRIVE_UNKNOWN && type <= DRIVE_RAMDISK,
67 "not a valid drive %c: type %u\n", drive[0], type);
69 if (!(logical_drives & 1))
70 ok(type == DRIVE_NO_ROOT_DIR,
71 "GetDriveTypeW should return DRIVE_NO_ROOT_DIR for inexistent drive %c: but not %u\n",
72 drive[0], type);
74 logical_drives >>= 1;
78 static void test_GetDiskFreeSpaceA(void)
80 BOOL ret;
81 DWORD sectors_per_cluster, bytes_per_sector, free_clusters, total_clusters;
82 char drive[] = "?:\\";
83 DWORD logical_drives;
85 ret = GetDiskFreeSpaceA(NULL, &sectors_per_cluster, &bytes_per_sector, &free_clusters, &total_clusters);
86 ok(ret, "GetDiskFreeSpaceA error %d\n", GetLastError());
88 ret = GetDiskFreeSpaceA("", &sectors_per_cluster, &bytes_per_sector, &free_clusters, &total_clusters);
89 ok(!ret && (GetLastError() == ERROR_PATH_NOT_FOUND || GetLastError() == ERROR_INVALID_NAME),
90 "GetDiskFreeSpaceA(\"\"): ret=%d GetLastError=%d\n",
91 ret, GetLastError());
93 ret = GetDiskFreeSpaceA("\\", &sectors_per_cluster, &bytes_per_sector, &free_clusters, &total_clusters);
94 ok(ret, "GetDiskFreeSpaceA error %d\n", GetLastError());
96 ret = GetDiskFreeSpaceA("/", &sectors_per_cluster, &bytes_per_sector, &free_clusters, &total_clusters);
97 ok(ret, "GetDiskFreeSpaceA error %d\n", GetLastError());
99 logical_drives = GetLogicalDrives();
100 ok(logical_drives != 0, "GetLogicalDrives error %d\n", GetLastError());
102 for (drive[0] = 'A'; drive[0] <= 'Z'; drive[0]++)
104 UINT drivetype = GetDriveTypeA(drive);
105 /* Skip floppy drives because NT pops up a MessageBox if no
106 * floppy is present
108 if (drivetype != DRIVE_REMOVABLE && drivetype != DRIVE_NO_ROOT_DIR)
110 ret = GetDiskFreeSpaceA(drive, &sectors_per_cluster, &bytes_per_sector, &free_clusters, &total_clusters);
111 if (!(logical_drives & 1))
112 ok(!ret && (GetLastError() == ERROR_PATH_NOT_FOUND || GetLastError() == ERROR_INVALID_DRIVE),
113 "GetDiskFreeSpaceA(%s): ret=%d GetLastError=%d\n",
114 drive, ret, GetLastError());
115 else
117 ok(ret ||
118 GetLastError() == ERROR_NOT_READY ||
119 GetLastError() == ERROR_INVALID_FUNCTION ||
120 GetLastError() == ERROR_INVALID_DRIVE ||
121 GetLastError() == ERROR_PATH_NOT_FOUND ||
122 GetLastError() == ERROR_REQUEST_ABORTED ||
123 GetLastError() == ERROR_NETNAME_DELETED ||
124 GetLastError() == ERROR_UNRECOGNIZED_VOLUME,
125 "GetDiskFreeSpaceA(%s): ret=%d GetLastError=%d\n",
126 drive, ret, GetLastError());
127 if( GetVersion() & 0x80000000)
128 /* win3.0 thru winME */
129 ok( total_clusters <= 65535,
130 "total clusters is %d > 65535\n", total_clusters);
131 else if (pGetDiskFreeSpaceExA) {
132 /* NT, 2k, XP : GetDiskFreeSpace should be accurate */
133 ULARGE_INTEGER totEx, tot, d;
135 tot.QuadPart = sectors_per_cluster;
136 tot.QuadPart = (tot.QuadPart * bytes_per_sector) * total_clusters;
137 ret = pGetDiskFreeSpaceExA( drive, &d, &totEx, NULL);
138 ok( ret ||
139 GetLastError() == ERROR_NOT_READY ||
140 GetLastError() == ERROR_INVALID_FUNCTION ||
141 GetLastError() == ERROR_PATH_NOT_FOUND ||
142 GetLastError() == ERROR_REQUEST_ABORTED ||
143 GetLastError() == ERROR_NETNAME_DELETED ||
144 GetLastError() == ERROR_UNRECOGNIZED_VOLUME,
145 "GetDiskFreeSpaceExA( %s ) failed. GetLastError=%d\n", drive, GetLastError());
146 ok( bytes_per_sector == 0 || /* empty cd rom drive */
147 totEx.QuadPart <= tot.QuadPart,
148 "GetDiskFreeSpaceA should report at least as much bytes on disk %s as GetDiskFreeSpaceExA\n", drive);
152 logical_drives >>= 1;
156 static void test_GetDiskFreeSpaceW(void)
158 BOOL ret;
159 DWORD sectors_per_cluster, bytes_per_sector, free_clusters, total_clusters;
160 WCHAR drive[] = {'?',':','\\',0};
161 DWORD logical_drives;
162 static const WCHAR empty_pathW[] = { 0 };
163 static const WCHAR root_pathW[] = { '\\', 0 };
164 static const WCHAR unix_style_root_pathW[] = { '/', 0 };
166 ret = GetDiskFreeSpaceW(NULL, &sectors_per_cluster, &bytes_per_sector, &free_clusters, &total_clusters);
167 if (ret == 0 && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
169 win_skip("GetDiskFreeSpaceW is not available\n");
170 return;
172 ok(ret, "GetDiskFreeSpaceW error %d\n", GetLastError());
174 ret = GetDiskFreeSpaceW(empty_pathW, &sectors_per_cluster, &bytes_per_sector, &free_clusters, &total_clusters);
175 ok(!ret && GetLastError() == ERROR_PATH_NOT_FOUND,
176 "GetDiskFreeSpaceW(\"\"): ret=%d GetLastError=%d\n",
177 ret, GetLastError());
179 ret = GetDiskFreeSpaceW(root_pathW, &sectors_per_cluster, &bytes_per_sector, &free_clusters, &total_clusters);
180 ok(ret, "GetDiskFreeSpaceW(\"\") error %d\n", GetLastError());
182 ret = GetDiskFreeSpaceW(unix_style_root_pathW, &sectors_per_cluster, &bytes_per_sector, &free_clusters, &total_clusters);
183 ok(ret, "GetDiskFreeSpaceW error %d\n", GetLastError());
185 logical_drives = GetLogicalDrives();
186 ok(logical_drives != 0, "GetLogicalDrives error %d\n", GetLastError());
188 for (drive[0] = 'A'; drive[0] <= 'Z'; drive[0]++)
190 UINT drivetype = GetDriveTypeW(drive);
191 /* Skip floppy drives because NT4 pops up a MessageBox if no floppy is present */
192 if (drivetype != DRIVE_REMOVABLE && drivetype != DRIVE_NO_ROOT_DIR)
194 ret = GetDiskFreeSpaceW(drive, &sectors_per_cluster, &bytes_per_sector, &free_clusters, &total_clusters);
195 if (!(logical_drives & 1))
196 ok(!ret && GetLastError() == ERROR_PATH_NOT_FOUND,
197 "GetDiskFreeSpaceW(%c): ret=%d GetLastError=%d\n",
198 drive[0], ret, GetLastError());
199 else
200 ok( ret ||
201 GetLastError() == ERROR_NOT_READY ||
202 GetLastError() == ERROR_INVALID_FUNCTION ||
203 GetLastError() == ERROR_PATH_NOT_FOUND ||
204 GetLastError() == ERROR_REQUEST_ABORTED ||
205 GetLastError() == ERROR_UNRECOGNIZED_VOLUME,
206 "GetDiskFreeSpaceW(%c): ret=%d GetLastError=%d\n",
207 drive[0], ret, GetLastError());
209 logical_drives >>= 1;
213 START_TEST(drive)
215 HANDLE hkernel32 = GetModuleHandleA("kernel32");
216 pGetDiskFreeSpaceExA = (void *) GetProcAddress(hkernel32, "GetDiskFreeSpaceExA");
218 test_GetDriveTypeA();
219 test_GetDriveTypeW();
221 test_GetDiskFreeSpaceA();
222 test_GetDiskFreeSpaceW();