wine.inf: We should not override existing associations.
[wine/hacks.git] / dlls / kernel / tests / drive.c
bloba6c0b7f0124c8563f850bccfadfc4744467d1515
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 %ld\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 inexistant drive %c: but not %u\n",
47 drive[0], type);
49 logical_drives >>= 1;
53 static void test_GetDriveTypeW(void)
55 WCHAR drive[] = {'?',':','\\',0};
56 DWORD logical_drives;
57 UINT type;
59 logical_drives = GetLogicalDrives();
60 ok(logical_drives != 0, "GetLogicalDrives error %ld\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 */
68 return;
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 inexistant drive %c: but not %u\n",
75 drive[0], type);
77 logical_drives >>= 1;
81 static void test_GetDiskFreeSpaceA(void)
83 BOOL ret;
84 DWORD sectors_per_cluster, bytes_per_sector, free_clusters, total_clusters;
85 char drive[] = "?:\\";
86 DWORD logical_drives;
88 ret = GetDiskFreeSpaceA(NULL, &sectors_per_cluster, &bytes_per_sector, &free_clusters, &total_clusters);
89 ok(ret, "GetDiskFreeSpaceA error %ld\n", GetLastError());
91 ret = GetDiskFreeSpaceA("", &sectors_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=%ld\n",
94 ret, GetLastError());
96 ret = GetDiskFreeSpaceA("\\", &sectors_per_cluster, &bytes_per_sector, &free_clusters, &total_clusters);
97 ok(ret, "GetDiskFreeSpaceA error %ld\n", GetLastError());
99 ret = GetDiskFreeSpaceA("/", &sectors_per_cluster, &bytes_per_sector, &free_clusters, &total_clusters);
100 ok(ret, "GetDiskFreeSpaceA error %ld\n", GetLastError());
102 logical_drives = GetLogicalDrives();
103 ok(logical_drives != 0, "GetLogicalDrives error %ld\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
109 * floppy is present
111 if (drivetype != DRIVE_REMOVABLE && drivetype != DRIVE_NO_ROOT_DIR)
113 ret = GetDiskFreeSpaceA(drive, &sectors_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=%ld\n",
117 drive, ret, GetLastError());
118 else
120 ok(ret ||
121 (!ret && (GetLastError() == ERROR_NOT_READY || GetLastError() == ERROR_INVALID_DRIVE)),
122 "GetDiskFreeSpaceA(%s): ret=%d GetLastError=%ld\n",
123 drive, ret, GetLastError());
124 if( GetVersion() & 0x80000000)
125 /* win3.0 thru winME */
126 ok( total_clusters <= 65535,
127 "total clusters is %ld > 65535\n", total_clusters);
128 else if (pGetDiskFreeSpaceExA) {
129 /* NT, 2k, XP : GetDiskFreeSpace shoud 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=%ld\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)
149 BOOL ret;
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, &sectors_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 */
161 return;
163 ok(ret, "GetDiskFreeSpaceW error %ld\n", GetLastError());
165 ret = GetDiskFreeSpaceW(empty_pathW, &sectors_per_cluster, &bytes_per_sector, &free_clusters, &total_clusters);
166 ok(!ret && GetLastError() == ERROR_PATH_NOT_FOUND,
167 "GetDiskFreeSpaceW(\"\"): ret=%d GetLastError=%ld\n",
168 ret, GetLastError());
170 ret = GetDiskFreeSpaceW(root_pathW, &sectors_per_cluster, &bytes_per_sector, &free_clusters, &total_clusters);
171 ok(ret, "GetDiskFreeSpaceW(\"\") error %ld\n", GetLastError());
173 ret = GetDiskFreeSpaceW(unix_style_root_pathW, &sectors_per_cluster, &bytes_per_sector, &free_clusters, &total_clusters);
174 ok(ret, "GetDiskFreeSpaceW error %ld\n", GetLastError());
176 logical_drives = GetLogicalDrives();
177 ok(logical_drives != 0, "GetLogicalDrives error %ld\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, &sectors_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=%ld\n",
189 drive[0], ret, GetLastError());
190 else
191 ok(ret || GetLastError() == ERROR_NOT_READY,
192 "GetDiskFreeSpaceW(%c): ret=%d GetLastError=%ld\n",
193 drive[0], ret, GetLastError());
195 logical_drives >>= 1;
199 START_TEST(drive)
201 HANDLE hkernel32 = GetModuleHandleA("kernel32");
202 pGetDiskFreeSpaceExA = (void *) GetProcAddress(hkernel32, "GetDiskFreeSpaceExA");
204 test_GetDriveTypeA();
205 test_GetDriveTypeW();
207 test_GetDiskFreeSpaceA();
208 test_GetDiskFreeSpaceW();