2002-08-27 03:56:08 +02:00
|
|
|
/*
|
|
|
|
* Unit test suite for drive functions.
|
|
|
|
*
|
|
|
|
* Copyright 2002 Dmitry Timoshkov
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2002-08-27 03:56:08 +02:00
|
|
|
*/
|
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
|
|
|
|
2002-08-27 03:56:08 +02:00
|
|
|
#include "wine/test.h"
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "windef.h"
|
2002-08-27 03:56:08 +02:00
|
|
|
#include "winbase.h"
|
|
|
|
#include "winerror.h"
|
|
|
|
|
2005-11-15 17:53:09 +01:00
|
|
|
static DWORD (WINAPI *pGetDiskFreeSpaceExA)(LPCSTR, PULARGE_INTEGER, PULARGE_INTEGER, PULARGE_INTEGER);
|
|
|
|
|
2005-05-31 11:30:45 +02:00
|
|
|
static void test_GetDriveTypeA(void)
|
2002-08-27 03:56:08 +02:00
|
|
|
{
|
|
|
|
char drive[] = "?:\\";
|
|
|
|
DWORD logical_drives;
|
|
|
|
UINT type;
|
|
|
|
|
|
|
|
logical_drives = GetLogicalDrives();
|
2006-10-10 01:06:48 +02:00
|
|
|
ok(logical_drives != 0, "GetLogicalDrives error %d\n", GetLastError());
|
2002-08-27 03:56:08 +02:00
|
|
|
|
|
|
|
for (drive[0] = 'A'; drive[0] <= 'Z'; drive[0]++)
|
|
|
|
{
|
|
|
|
type = GetDriveTypeA(drive);
|
2009-05-18 12:07:22 +02:00
|
|
|
ok(type > DRIVE_UNKNOWN && type <= DRIVE_RAMDISK,
|
|
|
|
"not a valid drive %c: type %u\n", drive[0], type);
|
2002-08-27 03:56:08 +02:00
|
|
|
|
|
|
|
if (!(logical_drives & 1))
|
|
|
|
ok(type == DRIVE_NO_ROOT_DIR,
|
2007-12-07 21:01:34 +01:00
|
|
|
"GetDriveTypeA should return DRIVE_NO_ROOT_DIR for inexistent drive %c: but not %u\n",
|
2002-08-27 03:56:08 +02:00
|
|
|
drive[0], type);
|
|
|
|
|
|
|
|
logical_drives >>= 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-05-31 11:30:45 +02:00
|
|
|
static void test_GetDriveTypeW(void)
|
2002-08-27 03:56:08 +02:00
|
|
|
{
|
|
|
|
WCHAR drive[] = {'?',':','\\',0};
|
|
|
|
DWORD logical_drives;
|
|
|
|
UINT type;
|
|
|
|
|
|
|
|
logical_drives = GetLogicalDrives();
|
2006-10-10 01:06:48 +02:00
|
|
|
ok(logical_drives != 0, "GetLogicalDrives error %d\n", GetLastError());
|
2002-08-27 03:56:08 +02:00
|
|
|
|
|
|
|
for (drive[0] = 'A'; drive[0] <= 'Z'; drive[0]++)
|
|
|
|
{
|
|
|
|
type = GetDriveTypeW(drive);
|
2009-05-18 12:07:22 +02:00
|
|
|
ok(type > DRIVE_UNKNOWN && type <= DRIVE_RAMDISK,
|
|
|
|
"not a valid drive %c: type %u\n", drive[0], type);
|
2002-08-27 03:56:08 +02:00
|
|
|
|
|
|
|
if (!(logical_drives & 1))
|
|
|
|
ok(type == DRIVE_NO_ROOT_DIR,
|
2007-12-07 21:01:34 +01:00
|
|
|
"GetDriveTypeW should return DRIVE_NO_ROOT_DIR for inexistent drive %c: but not %u\n",
|
2002-08-27 03:56:08 +02:00
|
|
|
drive[0], type);
|
|
|
|
|
|
|
|
logical_drives >>= 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-05-31 11:30:45 +02:00
|
|
|
static void test_GetDiskFreeSpaceA(void)
|
2002-08-27 03:56:08 +02:00
|
|
|
{
|
|
|
|
BOOL ret;
|
|
|
|
DWORD sectors_per_cluster, bytes_per_sector, free_clusters, total_clusters;
|
|
|
|
char drive[] = "?:\\";
|
|
|
|
DWORD logical_drives;
|
|
|
|
|
|
|
|
ret = GetDiskFreeSpaceA(NULL, §ors_per_cluster, &bytes_per_sector, &free_clusters, &total_clusters);
|
2006-10-10 01:06:48 +02:00
|
|
|
ok(ret, "GetDiskFreeSpaceA error %d\n", GetLastError());
|
2002-08-27 03:56:08 +02:00
|
|
|
|
|
|
|
ret = GetDiskFreeSpaceA("", §ors_per_cluster, &bytes_per_sector, &free_clusters, &total_clusters);
|
2002-11-30 20:02:53 +01:00
|
|
|
ok(!ret && (GetLastError() == ERROR_PATH_NOT_FOUND || GetLastError() == ERROR_INVALID_NAME),
|
2006-10-10 01:06:48 +02:00
|
|
|
"GetDiskFreeSpaceA(\"\"): ret=%d GetLastError=%d\n",
|
2002-11-30 20:02:53 +01:00
|
|
|
ret, GetLastError());
|
2002-08-27 03:56:08 +02:00
|
|
|
|
|
|
|
ret = GetDiskFreeSpaceA("\\", §ors_per_cluster, &bytes_per_sector, &free_clusters, &total_clusters);
|
2006-10-10 01:06:48 +02:00
|
|
|
ok(ret, "GetDiskFreeSpaceA error %d\n", GetLastError());
|
2002-08-27 03:56:08 +02:00
|
|
|
|
|
|
|
ret = GetDiskFreeSpaceA("/", §ors_per_cluster, &bytes_per_sector, &free_clusters, &total_clusters);
|
2006-10-10 01:06:48 +02:00
|
|
|
ok(ret, "GetDiskFreeSpaceA error %d\n", GetLastError());
|
2002-08-27 03:56:08 +02:00
|
|
|
|
|
|
|
logical_drives = GetLogicalDrives();
|
2006-10-10 01:06:48 +02:00
|
|
|
ok(logical_drives != 0, "GetLogicalDrives error %d\n", GetLastError());
|
2002-08-27 03:56:08 +02:00
|
|
|
|
|
|
|
for (drive[0] = 'A'; drive[0] <= 'Z'; drive[0]++)
|
|
|
|
{
|
2005-06-09 11:42:49 +02:00
|
|
|
UINT drivetype = GetDriveTypeA(drive);
|
2002-11-30 20:02:53 +01:00
|
|
|
/* Skip floppy drives because NT pops up a MessageBox if no
|
|
|
|
* floppy is present
|
|
|
|
*/
|
2005-06-09 11:42:49 +02:00
|
|
|
if (drivetype != DRIVE_REMOVABLE && drivetype != DRIVE_NO_ROOT_DIR)
|
2002-11-30 20:02:53 +01:00
|
|
|
{
|
|
|
|
ret = GetDiskFreeSpaceA(drive, §ors_per_cluster, &bytes_per_sector, &free_clusters, &total_clusters);
|
|
|
|
if (!(logical_drives & 1))
|
|
|
|
ok(!ret && (GetLastError() == ERROR_PATH_NOT_FOUND || GetLastError() == ERROR_INVALID_DRIVE),
|
2006-10-10 01:06:48 +02:00
|
|
|
"GetDiskFreeSpaceA(%s): ret=%d GetLastError=%d\n",
|
2002-11-30 20:02:53 +01:00
|
|
|
drive, ret, GetLastError());
|
|
|
|
else
|
2005-10-20 13:36:40 +02:00
|
|
|
{
|
2013-03-11 00:11:22 +01:00
|
|
|
|
|
|
|
if (!ret)
|
|
|
|
/* GetDiskFreeSpaceA() should succeed, but it can fail with too many
|
2013-12-03 14:25:04 +01:00
|
|
|
different GetLastError() results to be usable for an ok() */
|
2013-03-11 00:11:22 +01:00
|
|
|
trace("GetDiskFreeSpaceA(%s) failed with %d\n", drive, GetLastError());
|
|
|
|
|
2005-10-20 13:36:40 +02:00
|
|
|
if( GetVersion() & 0x80000000)
|
2012-05-15 10:15:32 +02:00
|
|
|
/* win3.0 through winME */
|
2005-10-20 13:36:40 +02:00
|
|
|
ok( total_clusters <= 65535,
|
2006-10-10 01:06:48 +02:00
|
|
|
"total clusters is %d > 65535\n", total_clusters);
|
2005-11-15 17:53:09 +01:00
|
|
|
else if (pGetDiskFreeSpaceExA) {
|
2008-01-23 15:16:30 +01:00
|
|
|
/* NT, 2k, XP : GetDiskFreeSpace should be accurate */
|
2005-10-20 13:36:40 +02:00
|
|
|
ULARGE_INTEGER totEx, tot, d;
|
2005-11-15 17:53:09 +01:00
|
|
|
|
2005-10-20 13:36:40 +02:00
|
|
|
tot.QuadPart = sectors_per_cluster;
|
|
|
|
tot.QuadPart = (tot.QuadPart * bytes_per_sector) * total_clusters;
|
2005-11-15 17:53:09 +01:00
|
|
|
ret = pGetDiskFreeSpaceExA( drive, &d, &totEx, NULL);
|
2013-03-11 00:11:22 +01:00
|
|
|
|
|
|
|
if (!ret)
|
|
|
|
/* GetDiskFreeSpaceExA() should succeed, but it can fail with too many
|
2013-12-03 14:25:04 +01:00
|
|
|
different GetLastError() results to be usable for an ok() */
|
2013-03-11 00:11:22 +01:00
|
|
|
trace("GetDiskFreeSpaceExA(%s) failed with %d\n", drive, GetLastError());
|
|
|
|
|
2005-10-20 13:36:40 +02:00
|
|
|
ok( bytes_per_sector == 0 || /* empty cd rom drive */
|
|
|
|
totEx.QuadPart <= tot.QuadPart,
|
|
|
|
"GetDiskFreeSpaceA should report at least as much bytes on disk %s as GetDiskFreeSpaceExA\n", drive);
|
|
|
|
}
|
|
|
|
}
|
2002-11-30 20:02:53 +01:00
|
|
|
}
|
2002-08-27 03:56:08 +02:00
|
|
|
logical_drives >>= 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-05-31 11:30:45 +02:00
|
|
|
static void test_GetDiskFreeSpaceW(void)
|
2002-08-27 03:56:08 +02:00
|
|
|
{
|
|
|
|
BOOL ret;
|
|
|
|
DWORD sectors_per_cluster, bytes_per_sector, free_clusters, total_clusters;
|
|
|
|
WCHAR drive[] = {'?',':','\\',0};
|
|
|
|
DWORD logical_drives;
|
|
|
|
static const WCHAR empty_pathW[] = { 0 };
|
|
|
|
static const WCHAR root_pathW[] = { '\\', 0 };
|
|
|
|
static const WCHAR unix_style_root_pathW[] = { '/', 0 };
|
|
|
|
|
|
|
|
ret = GetDiskFreeSpaceW(NULL, §ors_per_cluster, &bytes_per_sector, &free_clusters, &total_clusters);
|
2009-05-18 11:24:26 +02:00
|
|
|
if (ret == 0 && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
|
2002-11-30 20:02:53 +01:00
|
|
|
{
|
2009-05-18 11:24:26 +02:00
|
|
|
win_skip("GetDiskFreeSpaceW is not available\n");
|
2002-11-30 20:02:53 +01:00
|
|
|
return;
|
|
|
|
}
|
2006-10-10 01:06:48 +02:00
|
|
|
ok(ret, "GetDiskFreeSpaceW error %d\n", GetLastError());
|
2002-08-27 03:56:08 +02:00
|
|
|
|
|
|
|
ret = GetDiskFreeSpaceW(empty_pathW, §ors_per_cluster, &bytes_per_sector, &free_clusters, &total_clusters);
|
2002-11-30 20:02:53 +01:00
|
|
|
ok(!ret && GetLastError() == ERROR_PATH_NOT_FOUND,
|
2006-10-10 01:06:48 +02:00
|
|
|
"GetDiskFreeSpaceW(\"\"): ret=%d GetLastError=%d\n",
|
2002-11-30 20:02:53 +01:00
|
|
|
ret, GetLastError());
|
2002-08-27 03:56:08 +02:00
|
|
|
|
|
|
|
ret = GetDiskFreeSpaceW(root_pathW, §ors_per_cluster, &bytes_per_sector, &free_clusters, &total_clusters);
|
2006-10-10 01:06:48 +02:00
|
|
|
ok(ret, "GetDiskFreeSpaceW(\"\") error %d\n", GetLastError());
|
2002-08-27 03:56:08 +02:00
|
|
|
|
|
|
|
ret = GetDiskFreeSpaceW(unix_style_root_pathW, §ors_per_cluster, &bytes_per_sector, &free_clusters, &total_clusters);
|
2006-10-10 01:06:48 +02:00
|
|
|
ok(ret, "GetDiskFreeSpaceW error %d\n", GetLastError());
|
2002-08-27 03:56:08 +02:00
|
|
|
|
|
|
|
logical_drives = GetLogicalDrives();
|
2006-10-10 01:06:48 +02:00
|
|
|
ok(logical_drives != 0, "GetLogicalDrives error %d\n", GetLastError());
|
2002-08-27 03:56:08 +02:00
|
|
|
|
|
|
|
for (drive[0] = 'A'; drive[0] <= 'Z'; drive[0]++)
|
|
|
|
{
|
2005-06-09 11:42:49 +02:00
|
|
|
UINT drivetype = GetDriveTypeW(drive);
|
2002-11-30 20:02:53 +01:00
|
|
|
/* Skip floppy drives because NT4 pops up a MessageBox if no floppy is present */
|
2005-06-09 11:42:49 +02:00
|
|
|
if (drivetype != DRIVE_REMOVABLE && drivetype != DRIVE_NO_ROOT_DIR)
|
2002-11-30 20:02:53 +01:00
|
|
|
{
|
|
|
|
ret = GetDiskFreeSpaceW(drive, §ors_per_cluster, &bytes_per_sector, &free_clusters, &total_clusters);
|
|
|
|
if (!(logical_drives & 1))
|
|
|
|
ok(!ret && GetLastError() == ERROR_PATH_NOT_FOUND,
|
2006-10-10 01:06:48 +02:00
|
|
|
"GetDiskFreeSpaceW(%c): ret=%d GetLastError=%d\n",
|
2002-11-30 20:02:53 +01:00
|
|
|
drive[0], ret, GetLastError());
|
2013-03-11 00:11:22 +01:00
|
|
|
else if (!ret)
|
|
|
|
/* GetDiskFreeSpaceW() should succeed, but it can fail with too many
|
2013-12-03 14:25:04 +01:00
|
|
|
different GetLastError() results to be usable for an ok() */
|
2013-03-11 00:11:22 +01:00
|
|
|
trace("GetDiskFreeSpaceW(%c) failed with %d\n", drive[0], GetLastError());
|
2002-11-30 20:02:53 +01:00
|
|
|
}
|
2002-08-27 03:56:08 +02:00
|
|
|
logical_drives >>= 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
START_TEST(drive)
|
|
|
|
{
|
2005-11-15 17:53:09 +01:00
|
|
|
HANDLE hkernel32 = GetModuleHandleA("kernel32");
|
|
|
|
pGetDiskFreeSpaceExA = (void *) GetProcAddress(hkernel32, "GetDiskFreeSpaceExA");
|
|
|
|
|
2002-08-27 03:56:08 +02:00
|
|
|
test_GetDriveTypeA();
|
|
|
|
test_GetDriveTypeW();
|
|
|
|
|
|
|
|
test_GetDiskFreeSpaceA();
|
|
|
|
test_GetDiskFreeSpaceW();
|
|
|
|
}
|