Release 1.6-rc2.
[wine/testsucceed.git] / dlls / kernel32 / tests / drive.c
blobca6cb44d04454180503bc440fae9e12558027fa2
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
118 if (!ret)
119 /* GetDiskFreeSpaceA() should succeed, but it can fail with too many
120 different GetLastError() results to be usable for a ok() */
121 trace("GetDiskFreeSpaceA(%s) failed with %d\n", drive, GetLastError());
123 if( GetVersion() & 0x80000000)
124 /* win3.0 through winME */
125 ok( total_clusters <= 65535,
126 "total clusters is %d > 65535\n", total_clusters);
127 else if (pGetDiskFreeSpaceExA) {
128 /* NT, 2k, XP : GetDiskFreeSpace should be accurate */
129 ULARGE_INTEGER totEx, tot, d;
131 tot.QuadPart = sectors_per_cluster;
132 tot.QuadPart = (tot.QuadPart * bytes_per_sector) * total_clusters;
133 ret = pGetDiskFreeSpaceExA( drive, &d, &totEx, NULL);
135 if (!ret)
136 /* GetDiskFreeSpaceExA() should succeed, but it can fail with too many
137 different GetLastError() results to be usable for a ok() */
138 trace("GetDiskFreeSpaceExA(%s) failed with %d\n", drive, GetLastError());
140 ok( bytes_per_sector == 0 || /* empty cd rom drive */
141 totEx.QuadPart <= tot.QuadPart,
142 "GetDiskFreeSpaceA should report at least as much bytes on disk %s as GetDiskFreeSpaceExA\n", drive);
146 logical_drives >>= 1;
150 static void test_GetDiskFreeSpaceW(void)
152 BOOL ret;
153 DWORD sectors_per_cluster, bytes_per_sector, free_clusters, total_clusters;
154 WCHAR drive[] = {'?',':','\\',0};
155 DWORD logical_drives;
156 static const WCHAR empty_pathW[] = { 0 };
157 static const WCHAR root_pathW[] = { '\\', 0 };
158 static const WCHAR unix_style_root_pathW[] = { '/', 0 };
160 ret = GetDiskFreeSpaceW(NULL, &sectors_per_cluster, &bytes_per_sector, &free_clusters, &total_clusters);
161 if (ret == 0 && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
163 win_skip("GetDiskFreeSpaceW is not available\n");
164 return;
166 ok(ret, "GetDiskFreeSpaceW error %d\n", GetLastError());
168 ret = GetDiskFreeSpaceW(empty_pathW, &sectors_per_cluster, &bytes_per_sector, &free_clusters, &total_clusters);
169 ok(!ret && GetLastError() == ERROR_PATH_NOT_FOUND,
170 "GetDiskFreeSpaceW(\"\"): ret=%d GetLastError=%d\n",
171 ret, GetLastError());
173 ret = GetDiskFreeSpaceW(root_pathW, &sectors_per_cluster, &bytes_per_sector, &free_clusters, &total_clusters);
174 ok(ret, "GetDiskFreeSpaceW(\"\") error %d\n", GetLastError());
176 ret = GetDiskFreeSpaceW(unix_style_root_pathW, &sectors_per_cluster, &bytes_per_sector, &free_clusters, &total_clusters);
177 ok(ret, "GetDiskFreeSpaceW error %d\n", GetLastError());
179 logical_drives = GetLogicalDrives();
180 ok(logical_drives != 0, "GetLogicalDrives error %d\n", GetLastError());
182 for (drive[0] = 'A'; drive[0] <= 'Z'; drive[0]++)
184 UINT drivetype = GetDriveTypeW(drive);
185 /* Skip floppy drives because NT4 pops up a MessageBox if no floppy is present */
186 if (drivetype != DRIVE_REMOVABLE && drivetype != DRIVE_NO_ROOT_DIR)
188 ret = GetDiskFreeSpaceW(drive, &sectors_per_cluster, &bytes_per_sector, &free_clusters, &total_clusters);
189 if (!(logical_drives & 1))
190 ok(!ret && GetLastError() == ERROR_PATH_NOT_FOUND,
191 "GetDiskFreeSpaceW(%c): ret=%d GetLastError=%d\n",
192 drive[0], ret, GetLastError());
193 else if (!ret)
194 /* GetDiskFreeSpaceW() should succeed, but it can fail with too many
195 different GetLastError() results to be usable for a ok() */
196 trace("GetDiskFreeSpaceW(%c) failed with %d\n", drive[0], GetLastError());
198 logical_drives >>= 1;
202 START_TEST(drive)
204 HANDLE hkernel32 = GetModuleHandleA("kernel32");
205 pGetDiskFreeSpaceExA = (void *) GetProcAddress(hkernel32, "GetDiskFreeSpaceExA");
207 test_GetDriveTypeA();
208 test_GetDriveTypeW();
210 test_GetDiskFreeSpaceA();
211 test_GetDiskFreeSpaceW();