From: Joel Holdsworth joel@airwebreathe.org.uk
This change has the benefit that a file or directory can be deleted using a single combined operation. It can also be later adapted to include FILE_DISPOSITION_IGNORE_READONLY_ATTRIBUTE for deletion of read-only test files.
Signed-off-by: Joel Holdsworth joel@airwebreathe.org.uk --- dlls/ntdll/tests/file.c | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-)
diff --git a/dlls/ntdll/tests/file.c b/dlls/ntdll/tests/file.c index cf04ccc1264..a1841c5936c 100644 --- a/dlls/ntdll/tests/file.c +++ b/dlls/ntdll/tests/file.c @@ -1502,13 +1502,27 @@ static void test_file_all_information(void)
static void delete_object( WCHAR *path ) { - BOOL ret = DeleteFileW( path ); - ok( ret || GetLastError() == ERROR_FILE_NOT_FOUND || GetLastError() == ERROR_ACCESS_DENIED, - "DeleteFileW failed with %lu\n", GetLastError() ); - if (!ret && GetLastError() == ERROR_ACCESS_DENIED) - { - ret = RemoveDirectoryW( path ); - ok( ret, "RemoveDirectoryW failed with %lu\n", GetLastError() ); + UNICODE_STRING str; + OBJECT_ATTRIBUTES attr; + HANDLE handle; + FILE_DISPOSITION_INFORMATION_EX fdie; + IO_STATUS_BLOCK io; + NTSTATUS status; + + pRtlDosPathNameToNtPathName_U( path, &str, NULL, NULL ); + InitializeObjectAttributes( &attr, &str, 0, 0, NULL ); + io.Status = 0xdeadbeef; + status = pNtCreateFile( &handle, DELETE, &attr, &io, NULL, 0, 0, FILE_OPEN, 0, NULL, 0 ); + pRtlFreeUnicodeString( &str ); + ok(status == STATUS_SUCCESS || status == STATUS_OBJECT_NAME_NOT_FOUND, + "expected STATUS_SUCESS or STATUS_OBJECT_NAME_NOT_FOUND, got: %lx\n", io.Status); + if (status == STATUS_SUCCESS) { + fdie.Flags = FILE_DISPOSITION_DELETE; + io.Status = 0xdeadbeef; + status = pNtSetInformationFile( handle, &io, &fdie, sizeof fdie, FileDispositionInformationEx ); + ok ( status == STATUS_SUCCESS, "can't set file disposition, status: %lx\n", status ); + ok ( io.Status == STATUS_SUCCESS, "can't set file disposition, io.Status: %lx\n", io.Status ); + CloseHandle( handle ); } }