ReactOS 0.4.15-dev-6067-g0b695a6
drive.c File Reference
#include <stdarg.h>
#include "wine/test.h"
#include "windef.h"
#include "winbase.h"
#include "winerror.h"
Include dependency graph for drive.c:

Go to the source code of this file.

Functions

static DWORD (WINAPI *pGetDiskFreeSpaceExA)(LPCSTR
 
static void test_GetDriveTypeA (void)
 
static void test_GetDriveTypeW (void)
 
static void test_GetDiskFreeSpaceA (void)
 
static void test_GetDiskFreeSpaceW (void)
 
 START_TEST (drive)
 

Variables

static PULARGE_INTEGER
 

Function Documentation

◆ DWORD()

static DWORD ( WINAPI pGetDiskFreeSpaceExA)
static

◆ START_TEST()

START_TEST ( drive  )

Definition at line 261 of file drive.c.

262{
263 HANDLE hkernel32 = GetModuleHandleA("kernel32");
264 pGetDiskFreeSpaceExA = (void *) GetProcAddress(hkernel32, "GetDiskFreeSpaceExA");
265
268
271}
#define GetProcAddress(x, y)
Definition: compat.h:753
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:812
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 HINSTANCE hkernel32
Definition: process.c:66

◆ test_GetDiskFreeSpaceA()

static void test_GetDiskFreeSpaceA ( void  )
static

Definition at line 137 of file drive.c.

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}
#define trace
Definition: atltest.h:70
#define ok(value,...)
Definition: atltest.h:57
#define NULL
Definition: types.h:112
#define ERROR_INVALID_NAME
Definition: compat.h:103
UINT WINAPI GetDriveTypeA(IN LPCSTR lpRootPathName)
Definition: disk.c:468
BOOL WINAPI GetDiskFreeSpaceA(IN LPCSTR lpRootPathName, OUT LPDWORD lpSectorsPerCluster, OUT LPDWORD lpBytesPerSector, OUT LPDWORD lpNumberOfFreeClusters, OUT LPDWORD lpTotalNumberOfClusters)
Definition: disk.c:142
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
#define d
Definition: ke_i.h:81
static int sectors_per_cluster
Definition: mkdosfs.c:546
unsigned int UINT
Definition: ndis.h:50
DWORD WINAPI GetVersion()
Definition: redirtest.c:5
ULONGLONG QuadPart
Definition: ms-dtyp.idl:185
int ret
#define DRIVE_NO_ROOT_DIR
Definition: winbase.h:257
DWORD WINAPI GetLastError(void)
Definition: except.c:1040
DWORD WINAPI GetLogicalDrives(void)
Definition: disk.c:110
#define DRIVE_REMOVABLE
Definition: winbase.h:251
#define ERROR_PATH_NOT_FOUND
Definition: winerror.h:106
#define ERROR_INVALID_DRIVE
Definition: winerror.h:118

Referenced by START_TEST().

◆ test_GetDiskFreeSpaceW()

static void test_GetDiskFreeSpaceW ( void  )
static

Definition at line 209 of file drive.c.

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}
#define ERROR_CALL_NOT_IMPLEMENTED
Definition: compat.h:102
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
#define win_skip
Definition: test.h:160
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by START_TEST().

◆ test_GetDriveTypeA()

static void test_GetDriveTypeA ( void  )
static

Definition at line 30 of file drive.c.

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}
#define skip(...)
Definition: atltest.h:64
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
#define DRIVE_UNKNOWN
Definition: winbase.h:256
#define DRIVE_RAMDISK
Definition: winbase.h:255

Referenced by START_TEST().

◆ test_GetDriveTypeW()

static void test_GetDriveTypeW ( void  )
static

Definition at line 83 of file drive.c.

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}
#define wine_dbgstr_w
Definition: kernel32.h:34

Referenced by START_TEST().

Variable Documentation

◆ PULARGE_INTEGER

Definition at line 28 of file drive.c.