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 > 0 && type <= 6, "not a valid drive %c: type %u\n", drive[0], type);
44 if (!(logical_drives & 1))
45 ok(type == DRIVE_NO_ROOT_DIR,
46 "GetDriveTypeA should return DRIVE_NO_ROOT_DIR for inexistent drive %c: but not %u\n",
53 static void test_GetDriveTypeW(void)
55 WCHAR drive[] = {'?',':','\\',0};
59 logical_drives = GetLogicalDrives();
60 ok(logical_drives != 0, "GetLogicalDrives error %d\n", GetLastError());
62 for (drive[0] = 'A'; drive[0] <= 'Z'; drive[0]++)
64 type = GetDriveTypeW(drive);
65 if (type == DRIVE_UNKNOWN && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED)
67 /* Must be Win9x which doesn't support the Unicode functions */
70 ok(type > 0 && type <= 6, "not a valid drive %c: type %u\n", drive[0], type);
72 if (!(logical_drives & 1))
73 ok(type == DRIVE_NO_ROOT_DIR,
74 "GetDriveTypeW should return DRIVE_NO_ROOT_DIR for inexistent drive %c: but not %u\n",
81 static void test_GetDiskFreeSpaceA(void)
84 DWORD sectors_per_cluster, bytes_per_sector, free_clusters, total_clusters;
85 char drive[] = "?:\\";
88 ret = GetDiskFreeSpaceA(NULL, §ors_per_cluster, &bytes_per_sector, &free_clusters, &total_clusters);
89 ok(ret, "GetDiskFreeSpaceA error %d\n", GetLastError());
91 ret = GetDiskFreeSpaceA("", §ors_per_cluster, &bytes_per_sector, &free_clusters, &total_clusters);
92 ok(!ret && (GetLastError() == ERROR_PATH_NOT_FOUND || GetLastError() == ERROR_INVALID_NAME),
93 "GetDiskFreeSpaceA(\"\"): ret=%d GetLastError=%d\n",
96 ret = GetDiskFreeSpaceA("\\", §ors_per_cluster, &bytes_per_sector, &free_clusters, &total_clusters);
97 ok(ret, "GetDiskFreeSpaceA error %d\n", GetLastError());
99 ret = GetDiskFreeSpaceA("/", §ors_per_cluster, &bytes_per_sector, &free_clusters, &total_clusters);
100 ok(ret, "GetDiskFreeSpaceA error %d\n", GetLastError());
102 logical_drives = GetLogicalDrives();
103 ok(logical_drives != 0, "GetLogicalDrives error %d\n", GetLastError());
105 for (drive[0] = 'A'; drive[0] <= 'Z'; drive[0]++)
107 UINT drivetype = GetDriveTypeA(drive);
108 /* Skip floppy drives because NT pops up a MessageBox if no
111 if (drivetype != DRIVE_REMOVABLE && drivetype != DRIVE_NO_ROOT_DIR)
113 ret = GetDiskFreeSpaceA(drive, §ors_per_cluster, &bytes_per_sector, &free_clusters, &total_clusters);
114 if (!(logical_drives & 1))
115 ok(!ret && (GetLastError() == ERROR_PATH_NOT_FOUND || GetLastError() == ERROR_INVALID_DRIVE),
116 "GetDiskFreeSpaceA(%s): ret=%d GetLastError=%d\n",
117 drive, ret, GetLastError());
121 (!ret && (GetLastError() == ERROR_NOT_READY || GetLastError() == ERROR_INVALID_DRIVE)),
122 "GetDiskFreeSpaceA(%s): ret=%d GetLastError=%d\n",
123 drive, ret, GetLastError());
124 if( GetVersion() & 0x80000000)
125 /* win3.0 thru winME */
126 ok( total_clusters <= 65535,
127 "total clusters is %d > 65535\n", total_clusters);
128 else if (pGetDiskFreeSpaceExA) {
129 /* NT, 2k, XP : GetDiskFreeSpace should be accurate */
130 ULARGE_INTEGER totEx, tot, d;
132 tot.QuadPart = sectors_per_cluster;
133 tot.QuadPart = (tot.QuadPart * bytes_per_sector) * total_clusters;
134 ret = pGetDiskFreeSpaceExA( drive, &d, &totEx, NULL);
135 ok( ret || (!ret && ERROR_NOT_READY == GetLastError()),
136 "GetDiskFreeSpaceExA( %s ) failed. GetLastError=%d\n", drive, GetLastError());
137 ok( bytes_per_sector == 0 || /* empty cd rom drive */
138 totEx.QuadPart <= tot.QuadPart,
139 "GetDiskFreeSpaceA should report at least as much bytes on disk %s as GetDiskFreeSpaceExA\n", drive);
143 logical_drives >>= 1;
147 static void test_GetDiskFreeSpaceW(void)
150 DWORD sectors_per_cluster, bytes_per_sector, free_clusters, total_clusters;
151 WCHAR drive[] = {'?',':','\\',0};
152 DWORD logical_drives;
153 static const WCHAR empty_pathW[] = { 0 };
154 static const WCHAR root_pathW[] = { '\\', 0 };
155 static const WCHAR unix_style_root_pathW[] = { '/', 0 };
157 ret = GetDiskFreeSpaceW(NULL, §ors_per_cluster, &bytes_per_sector, &free_clusters, &total_clusters);
158 if (ret == 0 && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED)
160 /* Must be Win9x which doesn't support the Unicode functions */
163 ok(ret, "GetDiskFreeSpaceW error %d\n", GetLastError());
165 ret = GetDiskFreeSpaceW(empty_pathW, §ors_per_cluster, &bytes_per_sector, &free_clusters, &total_clusters);
166 ok(!ret && GetLastError() == ERROR_PATH_NOT_FOUND,
167 "GetDiskFreeSpaceW(\"\"): ret=%d GetLastError=%d\n",
168 ret, GetLastError());
170 ret = GetDiskFreeSpaceW(root_pathW, §ors_per_cluster, &bytes_per_sector, &free_clusters, &total_clusters);
171 ok(ret, "GetDiskFreeSpaceW(\"\") error %d\n", GetLastError());
173 ret = GetDiskFreeSpaceW(unix_style_root_pathW, §ors_per_cluster, &bytes_per_sector, &free_clusters, &total_clusters);
174 ok(ret, "GetDiskFreeSpaceW error %d\n", GetLastError());
176 logical_drives = GetLogicalDrives();
177 ok(logical_drives != 0, "GetLogicalDrives error %d\n", GetLastError());
179 for (drive[0] = 'A'; drive[0] <= 'Z'; drive[0]++)
181 UINT drivetype = GetDriveTypeW(drive);
182 /* Skip floppy drives because NT4 pops up a MessageBox if no floppy is present */
183 if (drivetype != DRIVE_REMOVABLE && drivetype != DRIVE_NO_ROOT_DIR)
185 ret = GetDiskFreeSpaceW(drive, §ors_per_cluster, &bytes_per_sector, &free_clusters, &total_clusters);
186 if (!(logical_drives & 1))
187 ok(!ret && GetLastError() == ERROR_PATH_NOT_FOUND,
188 "GetDiskFreeSpaceW(%c): ret=%d GetLastError=%d\n",
189 drive[0], ret, GetLastError());
191 ok(ret || GetLastError() == ERROR_NOT_READY,
192 "GetDiskFreeSpaceW(%c): ret=%d GetLastError=%d\n",
193 drive[0], ret, GetLastError());
195 logical_drives >>= 1;
201 HANDLE hkernel32 = GetModuleHandleA("kernel32");
202 pGetDiskFreeSpaceExA = (void *) GetProcAddress(hkernel32, "GetDiskFreeSpaceExA");
204 test_GetDriveTypeA();
205 test_GetDriveTypeW();
207 test_GetDiskFreeSpaceA();
208 test_GetDiskFreeSpaceW();