Fix the error codes returned by DeleteFile{A,W} to match NT.

Adapt the DeleteFileA error code checks to take into account variations
between Win9x and NT.
Test DeleteFile(NULL).
Add tests for DeleteFileW.
On NT, calling _lclose on an already closed handle will cause memory
corruption and thus sometimes crash -> removed the relevant test.
Skip the Unicode tests when on Win9x.
This commit is contained in:
Francois Gouget 2002-12-12 03:54:01 +00:00 committed by Alexandre Julliard
parent 72e1c64345
commit e948ad1fc7
2 changed files with 33 additions and 16 deletions

View File

@ -184,10 +184,6 @@ static void test__lclose( void )
ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains" ); ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains" );
ok( HFILE_ERROR == _lclose(filehandle), "_lclose should whine about this" );
ok( HFILE_ERROR == _lclose(filehandle), "_lclose should whine about this" );
ok( DeleteFileA( filename ) != 0, "DeleteFile failed (%ld)", GetLastError( ) ); ok( DeleteFileA( filename ) != 0, "DeleteFile failed (%ld)", GetLastError( ) );
} }
@ -501,6 +497,8 @@ void test_CopyFileW(void)
DWORD ret; DWORD ret;
ret = GetTempPathW(MAX_PATH, temp_path); ret = GetTempPathW(MAX_PATH, temp_path);
if (ret==0 && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED)
return;
ok(ret != 0, "GetTempPathW error %ld", GetLastError()); ok(ret != 0, "GetTempPathW error %ld", GetLastError());
ok(ret < MAX_PATH, "temp path should fit into MAX_PATH"); ok(ret < MAX_PATH, "temp path should fit into MAX_PATH");
@ -556,6 +554,8 @@ void test_CreateFileW(void)
DWORD ret; DWORD ret;
ret = GetTempPathW(MAX_PATH, temp_path); ret = GetTempPathW(MAX_PATH, temp_path);
if (ret==0 && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED)
return;
ok(ret != 0, "GetTempPathW error %ld", GetLastError()); ok(ret != 0, "GetTempPathW error %ld", GetLastError());
ok(ret < MAX_PATH, "temp path should fit into MAX_PATH"); ok(ret < MAX_PATH, "temp path should fit into MAX_PATH");
@ -574,9 +574,32 @@ void test_CreateFileW(void)
static void test_DeleteFileA( void ) static void test_DeleteFileA( void )
{ {
BOOL ret; BOOL ret;
ret = DeleteFileA(NULL);
ok(!ret && (GetLastError() == ERROR_INVALID_PARAMETER ||
GetLastError() == ERROR_PATH_NOT_FOUND),
"DeleteFileA(NULL) returned ret=%d error=%ld",ret,GetLastError());
ret = DeleteFileA(""); ret = DeleteFileA("");
ok((!ret) && (GetLastError() == ERROR_FILE_NOT_FOUND), ok(!ret && (GetLastError() == ERROR_PATH_NOT_FOUND ||
"DeleteFile should fail with an empty path, and last error value should be ERROR_FILE_NOT_FOUND"); GetLastError() == ERROR_BAD_PATHNAME),
"DeleteFileA(\"\") returned ret=%d error=%ld",ret,GetLastError());
}
static void test_DeleteFileW( void )
{
BOOL ret;
WCHAR emptyW[]={'\0'};
ret = DeleteFileW(NULL);
if (ret==0 && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED)
return;
ok(!ret && GetLastError() == ERROR_PATH_NOT_FOUND,
"DeleteFileW(NULL) returned ret=%d error=%ld",ret,GetLastError());
ret = DeleteFileW(emptyW);
ok(!ret && GetLastError() == ERROR_PATH_NOT_FOUND,
"DeleteFileW(\"\") returned ret=%d error=%ld",ret,GetLastError());
} }
#define PATTERN_OFFSET 0x10 #define PATTERN_OFFSET 0x10
@ -657,5 +680,6 @@ START_TEST(file)
test_CreateFileA(); test_CreateFileA();
test_CreateFileW(); test_CreateFileW();
test_DeleteFileA(); test_DeleteFileA();
test_DeleteFileW();
test_offset_in_overlapped_structure(); test_offset_in_overlapped_structure();
} }

View File

@ -2418,17 +2418,10 @@ BOOL WINAPI DeleteFileW( LPCWSTR path )
DOS_FULL_NAME full_name; DOS_FULL_NAME full_name;
HANDLE hFile; HANDLE hFile;
if (!path)
{
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}
TRACE("%s\n", debugstr_w(path) ); TRACE("%s\n", debugstr_w(path) );
if (!path || !*path)
if (!*path)
{ {
WARN("Empty path passed\n"); SetLastError(ERROR_PATH_NOT_FOUND);
SetLastError( ERROR_FILE_NOT_FOUND );
return FALSE; return FALSE;
} }
if (DOSFS_GetDevice( path )) if (DOSFS_GetDevice( path ))