From e948ad1fc7e18a22304487c5db674469e9d7e8a7 Mon Sep 17 00:00:00 2001 From: Francois Gouget Date: Thu, 12 Dec 2002 03:54:01 +0000 Subject: [PATCH] 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. --- dlls/kernel/tests/file.c | 38 +++++++++++++++++++++++++++++++------- files/file.c | 11 ++--------- 2 files changed, 33 insertions(+), 16 deletions(-) diff --git a/dlls/kernel/tests/file.c b/dlls/kernel/tests/file.c index 7250b8f401d..a8b1fcc919a 100644 --- a/dlls/kernel/tests/file.c +++ b/dlls/kernel/tests/file.c @@ -184,10 +184,6 @@ static void test__lclose( void ) 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( ) ); } @@ -501,6 +497,8 @@ void test_CopyFileW(void) DWORD ret; ret = GetTempPathW(MAX_PATH, temp_path); + if (ret==0 && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED) + return; ok(ret != 0, "GetTempPathW error %ld", GetLastError()); ok(ret < MAX_PATH, "temp path should fit into MAX_PATH"); @@ -556,6 +554,8 @@ void test_CreateFileW(void) DWORD ret; ret = GetTempPathW(MAX_PATH, temp_path); + if (ret==0 && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED) + return; ok(ret != 0, "GetTempPathW error %ld", GetLastError()); ok(ret < MAX_PATH, "temp path should fit into MAX_PATH"); @@ -574,12 +574,35 @@ void test_CreateFileW(void) static void test_DeleteFileA( void ) { 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(""); - ok((!ret) && (GetLastError() == ERROR_FILE_NOT_FOUND), - "DeleteFile should fail with an empty path, and last error value should be ERROR_FILE_NOT_FOUND"); + ok(!ret && (GetLastError() == ERROR_PATH_NOT_FOUND || + GetLastError() == ERROR_BAD_PATHNAME), + "DeleteFileA(\"\") returned ret=%d error=%ld",ret,GetLastError()); } -#define PATTERN_OFFSET 0x10 +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 void test_offset_in_overlapped_structure(void) { @@ -657,5 +680,6 @@ START_TEST(file) test_CreateFileA(); test_CreateFileW(); test_DeleteFileA(); + test_DeleteFileW(); test_offset_in_overlapped_structure(); } diff --git a/files/file.c b/files/file.c index f8bf49c59c4..0ae97d29aea 100644 --- a/files/file.c +++ b/files/file.c @@ -2418,17 +2418,10 @@ BOOL WINAPI DeleteFileW( LPCWSTR path ) DOS_FULL_NAME full_name; HANDLE hFile; - if (!path) - { - SetLastError(ERROR_INVALID_PARAMETER); - return FALSE; - } TRACE("%s\n", debugstr_w(path) ); - - if (!*path) + if (!path || !*path) { - WARN("Empty path passed\n"); - SetLastError( ERROR_FILE_NOT_FOUND ); + SetLastError(ERROR_PATH_NOT_FOUND); return FALSE; } if (DOSFS_GetDevice( path ))