ReactOS 0.4.16-dev-197-g92996da
drive.c
Go to the documentation of this file.
1/*
2 * Unit test suite for drive functions.
3 *
4 * Copyright 2002 Dmitry Timoshkov
5 *
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.
10 *
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.
15 *
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
19 */
20
21#include <stdarg.h>
22
23#include "wine/test.h"
24#include "windef.h"
25#include "winbase.h"
26#include "winerror.h"
27
29
30static void test_GetDriveTypeA(void)
31{
32 char drive[] = "?:\\";
33 char existing_drive_letter = 0;
34 DWORD logical_drives;
35 UINT type;
36
37 logical_drives = GetLogicalDrives();
38 ok(logical_drives != 0, "GetLogicalDrives error %d\n", GetLastError());
39
40 for (drive[0] = 'A'; drive[0] <= 'Z'; drive[0]++)
41 {
44 "not a valid drive %c: type %u\n", drive[0], type);
45
46 if (!(logical_drives & 1))
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];
52
53 logical_drives >>= 1;
54 }
55
56 if (!existing_drive_letter) {
57 skip("No drives found, skipping drive spec format tests.\n");
58 return;
59 }
60
61 drive[0] = existing_drive_letter;
62 drive[2] = 0; /* C: */
64 ok(type > DRIVE_NO_ROOT_DIR && type <= DRIVE_RAMDISK, "got %u for drive spec '%s'\n", type, drive);
65
66 drive[1] = '?'; /* C? */
68 ok(type == DRIVE_NO_ROOT_DIR, "got %u for drive spec '%s'\n", type, drive);
69
70 drive[1] = 0; /* C */
72 ok(type == DRIVE_NO_ROOT_DIR, "got %u for drive spec '%s'\n", type, drive);
73
74 drive[0] = '?'; /* the string "?" */
76 ok(type == DRIVE_NO_ROOT_DIR, "got %u for drive spec '%s'\n", type, drive);
77
78 drive[0] = 0; /* the empty string */
80 ok(type == DRIVE_NO_ROOT_DIR, "got %u for drive spec '%s'\n", type, drive);
81}
82
83static void test_GetDriveTypeW(void)
84{
85 WCHAR drive[] = {'?',':','\\',0};
86 WCHAR existing_drive_letter = 0;
87 DWORD logical_drives;
88 UINT type;
89
90 logical_drives = GetLogicalDrives();
91 ok(logical_drives != 0, "GetLogicalDrives error %d\n", GetLastError());
92
93 for (drive[0] = 'A'; drive[0] <= 'Z'; drive[0]++)
94 {
97 "not a valid drive %c: type %u\n", drive[0], type);
98
99 if (!(logical_drives & 1))
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];
105
106 logical_drives >>= 1;
107 }
108
109 if (!existing_drive_letter) {
110 skip("No drives found, skipping drive spec format tests.\n");
111 return;
112 }
113
114 drive[0] = existing_drive_letter;
115 drive[2] = 0; /* C: */
117 ok(type > DRIVE_NO_ROOT_DIR && type <= DRIVE_RAMDISK, "got %u for drive spec '%s'\n",
119
120 drive[1] = '?'; /* C? */
122 ok(type == DRIVE_NO_ROOT_DIR, "got %u for drive spec '%s'\n", type, wine_dbgstr_w(drive));
123
124 drive[1] = 0; /* C */
126 ok(type == DRIVE_NO_ROOT_DIR, "got %u for drive spec '%s'\n", type, wine_dbgstr_w(drive));
127
128 drive[0] = '?'; /* the string "?" */
130 ok(type == DRIVE_NO_ROOT_DIR, "got %u for drive spec '%s'\n", type, wine_dbgstr_w(drive));
131
132 drive[0] = 0; /* the empty string */
134 ok(type == DRIVE_NO_ROOT_DIR, "got %u for drive spec '%s'\n", type, wine_dbgstr_w(drive));
135}
136
137static void test_GetDiskFreeSpaceA(void)
138{
139 BOOL ret;
140 DWORD sectors_per_cluster, bytes_per_sector, free_clusters, total_clusters;
141 char drive[] = "?:\\";
142 DWORD logical_drives;
143
144 ret = GetDiskFreeSpaceA(NULL, &sectors_per_cluster, &bytes_per_sector, &free_clusters, &total_clusters);
145 ok(ret, "GetDiskFreeSpaceA error %d\n", GetLastError());
146
147 ret = GetDiskFreeSpaceA("", &sectors_per_cluster, &bytes_per_sector, &free_clusters, &total_clusters);
149 "GetDiskFreeSpaceA(\"\"): ret=%d GetLastError=%d\n",
150 ret, GetLastError());
151
152 ret = GetDiskFreeSpaceA("\\", &sectors_per_cluster, &bytes_per_sector, &free_clusters, &total_clusters);
153 ok(ret, "GetDiskFreeSpaceA error %d\n", GetLastError());
154
155 ret = GetDiskFreeSpaceA("/", &sectors_per_cluster, &bytes_per_sector, &free_clusters, &total_clusters);
156 ok(ret, "GetDiskFreeSpaceA error %d\n", GetLastError());
157
158 logical_drives = GetLogicalDrives();
159 ok(logical_drives != 0, "GetLogicalDrives error %d\n", GetLastError());
160
161 for (drive[0] = 'A'; drive[0] <= 'Z'; drive[0]++)
162 {
163 UINT drivetype = GetDriveTypeA(drive);
164 /* Skip floppy drives because NT pops up a MessageBox if no
165 * floppy is present
166 */
167 if (drivetype != DRIVE_REMOVABLE && drivetype != DRIVE_NO_ROOT_DIR)
168 {
169 ret = GetDiskFreeSpaceA(drive, &sectors_per_cluster, &bytes_per_sector, &free_clusters, &total_clusters);
170 if (!(logical_drives & 1))
172 "GetDiskFreeSpaceA(%s): ret=%d GetLastError=%d\n",
174 else
175 {
176
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());
181
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;
189
191 tot.QuadPart = (tot.QuadPart * bytes_per_sector) * total_clusters;
192 ret = pGetDiskFreeSpaceExA( drive, &d, &totEx, NULL);
193
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());
198
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);
202 }
203 }
204 }
205 logical_drives >>= 1;
206 }
207}
208
209static void test_GetDiskFreeSpaceW(void)
210{
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 };
218
219 ret = GetDiskFreeSpaceW(NULL, &sectors_per_cluster, &bytes_per_sector, &free_clusters, &total_clusters);
221 {
222 win_skip("GetDiskFreeSpaceW is not available\n");
223 return;
224 }
225 ok(ret, "GetDiskFreeSpaceW error %d\n", GetLastError());
226
227 ret = GetDiskFreeSpaceW(empty_pathW, &sectors_per_cluster, &bytes_per_sector, &free_clusters, &total_clusters);
229 "GetDiskFreeSpaceW(\"\"): ret=%d GetLastError=%d\n",
230 ret, GetLastError());
231
232 ret = GetDiskFreeSpaceW(root_pathW, &sectors_per_cluster, &bytes_per_sector, &free_clusters, &total_clusters);
233 ok(ret, "GetDiskFreeSpaceW(\"\") error %d\n", GetLastError());
234
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());
237
238 logical_drives = GetLogicalDrives();
239 ok(logical_drives != 0, "GetLogicalDrives error %d\n", GetLastError());
240
241 for (drive[0] = 'A'; drive[0] <= 'Z'; drive[0]++)
242 {
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)
246 {
247 ret = GetDiskFreeSpaceW(drive, &sectors_per_cluster, &bytes_per_sector, &free_clusters, &total_clusters);
248 if (!(logical_drives & 1))
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());
256 }
257 logical_drives >>= 1;
258 }
259}
260
262{
263 HANDLE hkernel32 = GetModuleHandleA("kernel32");
264 pGetDiskFreeSpaceExA = (void *) GetProcAddress(hkernel32, "GetDiskFreeSpaceExA");
265
268
271}
#define trace
Definition: atltest.h:70
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
#define START_TEST(x)
Definition: atltest.h:75
#define NULL
Definition: types.h:112
#define ERROR_CALL_NOT_IMPLEMENTED
Definition: compat.h:102
#define GetProcAddress(x, y)
Definition: compat.h:753
#define ERROR_INVALID_NAME
Definition: compat.h:103
UINT WINAPI GetDriveTypeA(IN LPCSTR lpRootPathName)
Definition: disk.c:468
UINT WINAPI GetDriveTypeW(IN LPCWSTR lpRootPathName)
Definition: disk.c:497
BOOL WINAPI GetDiskFreeSpaceW(IN LPCWSTR lpRootPathName, OUT LPDWORD lpSectorsPerCluster, OUT LPDWORD lpBytesPerSector, OUT LPDWORD lpNumberOfFreeClusters, OUT LPDWORD lpTotalNumberOfClusters)
Definition: disk.c:173
BOOL WINAPI GetDiskFreeSpaceA(IN LPCSTR lpRootPathName, OUT LPDWORD lpSectorsPerCluster, OUT LPDWORD lpBytesPerSector, OUT LPDWORD lpNumberOfFreeClusters, OUT LPDWORD lpTotalNumberOfClusters)
Definition: disk.c:142
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:812
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
#define d
Definition: ke_i.h:81
#define wine_dbgstr_w
Definition: kernel32.h:34
static int sectors_per_cluster
Definition: mkdosfs.c:546
static void test_GetDiskFreeSpaceW(void)
Definition: drive.c:209
static void test_GetDriveTypeA(void)
Definition: drive.c:30
static void test_GetDriveTypeW(void)
Definition: drive.c:83
static void test_GetDiskFreeSpaceA(void)
Definition: drive.c:137
static PULARGE_INTEGER
Definition: drive.c:28
static HINSTANCE hkernel32
Definition: process.c:66
unsigned int UINT
Definition: ndis.h:50
#define DWORD
Definition: nt_native.h:44
DWORD WINAPI GetVersion()
Definition: redirtest.c:5
#define win_skip
Definition: test.h:163
ULONGLONG QuadPart
Definition: ms-dtyp.idl:185
int ret
#define DRIVE_UNKNOWN
Definition: winbase.h:281
#define DRIVE_NO_ROOT_DIR
Definition: winbase.h:282
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
DWORD WINAPI GetLogicalDrives(void)
Definition: disk.c:110
#define DRIVE_RAMDISK
Definition: winbase.h:280
#define DRIVE_REMOVABLE
Definition: winbase.h:276
#define WINAPI
Definition: msvc.h:6
#define ERROR_PATH_NOT_FOUND
Definition: winerror.h:106
#define ERROR_INVALID_DRIVE
Definition: winerror.h:118
const char * LPCSTR
Definition: xmlstorage.h:183
__wchar_t WCHAR
Definition: xmlstorage.h:180