ntdll-FileDispositionInformation: Add additional tests for setting FileDispositionInformation on mapped files.

This commit is contained in:
Sebastian Lackner 2015-04-18 09:32:19 +02:00
parent 69f3294d35
commit b9a1a97057
2 changed files with 70 additions and 20 deletions

View File

@ -1,15 +1,15 @@
From 4090895abe5dafae64a25987bc1878dc5d727a67 Mon Sep 17 00:00:00 2001
From 915da8ef1214b9378683e144ba18e3a185909dbf Mon Sep 17 00:00:00 2001
From: Qian Hong <qhong@codeweavers.com>
Date: Fri, 17 Apr 2015 00:59:02 +0800
Subject: ntdll/tests: Added tests to set disposition on file which is mapped
to memory
---
dlls/ntdll/tests/file.c | 23 ++++++++++++++++++++++-
1 file changed, 22 insertions(+), 1 deletion(-)
dlls/ntdll/tests/file.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 70 insertions(+), 1 deletion(-)
diff --git a/dlls/ntdll/tests/file.c b/dlls/ntdll/tests/file.c
index 05ce517..6408eaa 100644
index 05ce517..1726546 100644
--- a/dlls/ntdll/tests/file.c
+++ b/dlls/ntdll/tests/file.c
@@ -1355,11 +1355,12 @@ static void test_file_disposition_information(void)
@ -26,11 +26,42 @@ index 05ce517..6408eaa 100644
GetTempPathA( MAX_PATH, tmp_path );
@@ -1523,6 +1524,26 @@ static void test_file_disposition_information(void)
@@ -1523,6 +1524,74 @@ static void test_file_disposition_information(void)
todo_wine
ok( !fileDeleted, "Directory shouldn't have been deleted\n" );
RemoveDirectoryA( buffer );
+
+ /* cannot set disposition on file with file mapping opened */
+ GetTempFileNameA( tmp_path, "dis", 0, buffer );
+ handle = CreateFileA(buffer, GENERIC_READ | GENERIC_WRITE | DELETE, 0, NULL, CREATE_ALWAYS, 0, 0);
+ ok( handle != INVALID_HANDLE_VALUE, "failed to create temp file\n" );
+ mapping = CreateFileMappingA( handle, NULL, PAGE_READWRITE, 0, 64 * 1024, "DelFileTest" );
+ ok( mapping != NULL, "failed to create file mapping\n");
+ fdi.DoDeleteFile = TRUE;
+ res = pNtSetInformationFile( handle, &io, &fdi, sizeof fdi, FileDispositionInformation );
+ todo_wine
+ ok( res == STATUS_CANNOT_DELETE, "unexpected FileDispositionInformation result (expected STATUS_CANNOT_DELETE, got %x)\n", res );
+ CloseHandle( handle );
+ fileDeleted = GetFileAttributesA( buffer ) == INVALID_FILE_ATTRIBUTES && GetLastError() == ERROR_FILE_NOT_FOUND;
+ ok( !fileDeleted, "File shouldn't have been deleted\n" );
+ CloseHandle( mapping );
+ DeleteFileA( buffer );
+
+ /* can set disposition on file with file mapping closed */
+ GetTempFileNameA( tmp_path, "dis", 0, buffer );
+ handle = CreateFileA(buffer, GENERIC_READ | GENERIC_WRITE | DELETE, 0, NULL, CREATE_ALWAYS, 0, 0);
+ ok( handle != INVALID_HANDLE_VALUE, "failed to create temp file\n" );
+ mapping = CreateFileMappingA( handle, NULL, PAGE_READWRITE, 0, 64 * 1024, "DelFileTest" );
+ ok( mapping != NULL, "failed to create file mapping\n");
+ CloseHandle( mapping );
+ fdi.DoDeleteFile = TRUE;
+ res = pNtSetInformationFile( handle, &io, &fdi, sizeof fdi, FileDispositionInformation );
+ ok( res == STATUS_SUCCESS, "unexpected FileDispositionInformation result (expected STATUS_SUCCESS, got %x)\n", res );
+ CloseHandle( handle );
+ fileDeleted = GetFileAttributesA( buffer ) == INVALID_FILE_ATTRIBUTES && GetLastError() == ERROR_FILE_NOT_FOUND;
+ ok( fileDeleted, "File should have been deleted\n" );
+ DeleteFileA( buffer );
+
+ /* cannot set disposition on file which is mapped to memory */
+ GetTempFileNameA( tmp_path, "dis", 0, buffer );
+ handle = CreateFileA(buffer, GENERIC_READ | GENERIC_WRITE | DELETE, 0, NULL, CREATE_ALWAYS, 0, 0);
@ -39,16 +70,33 @@ index 05ce517..6408eaa 100644
+ ok( mapping != NULL, "failed to create file mapping\n");
+ ptr = MapViewOfFile( mapping, FILE_MAP_READ, 0, 0, 4096 );
+ ok( ptr != NULL, "MapViewOfFile failed\n");
+ CloseHandle( mapping );
+ fdi.DoDeleteFile = TRUE;
+ res = pNtSetInformationFile( handle, &io, &fdi, sizeof fdi, FileDispositionInformation );
+todo_wine
+ todo_wine
+ ok( res == STATUS_CANNOT_DELETE, "unexpected FileDispositionInformation result (expected STATUS_CANNOT_DELETE, got %x)\n", res );
+ CloseHandle( handle );
+ UnmapViewOfFile( ptr );
+ CloseHandle( mapping );
+ fileDeleted = GetFileAttributesA( buffer ) == INVALID_FILE_ATTRIBUTES && GetLastError() == ERROR_FILE_NOT_FOUND;
+todo_wine
+ ok( !fileDeleted, "File shouldn't have been deleted\n" );
+ UnmapViewOfFile( ptr );
+ DeleteFileA( buffer );
+
+ /* can set disposition on file which is mapped to memory and unmapped again */
+ GetTempFileNameA( tmp_path, "dis", 0, buffer );
+ handle = CreateFileA(buffer, GENERIC_READ | GENERIC_WRITE | DELETE, 0, NULL, CREATE_ALWAYS, 0, 0);
+ ok( handle != INVALID_HANDLE_VALUE, "failed to create temp file\n" );
+ mapping = CreateFileMappingA( handle, NULL, PAGE_READWRITE, 0, 64 * 1024, "DelFileTest" );
+ ok( mapping != NULL, "failed to create file mapping\n");
+ ptr = MapViewOfFile( mapping, FILE_MAP_READ, 0, 0, 4096 );
+ ok( ptr != NULL, "MapViewOfFile failed\n");
+ CloseHandle( mapping );
+ UnmapViewOfFile( ptr );
+ fdi.DoDeleteFile = TRUE;
+ res = pNtSetInformationFile( handle, &io, &fdi, sizeof fdi, FileDispositionInformation );
+ ok( res == STATUS_SUCCESS, "unexpected FileDispositionInformation result (expected STATUS_SUCCESS, got %x)\n", res );
+ CloseHandle( handle );
+ fileDeleted = GetFileAttributesA( buffer ) == INVALID_FILE_ATTRIBUTES && GetLastError() == ERROR_FILE_NOT_FOUND;
+ ok( fileDeleted, "File should have been deleted\n" );
+ DeleteFileA( buffer );
}

View File

@ -1,4 +1,4 @@
From 7e203fc3b7ef5b5a69fa60f99b57ca02a9a63033 Mon Sep 17 00:00:00 2001
From f32616e681bebc98e6969e142edabbd4b5cf86dd Mon Sep 17 00:00:00 2001
From: Qian Hong <qhong@codeweavers.com>
Date: Fri, 17 Apr 2015 18:39:59 +0800
Subject: server: Do not allow to set disposition on file which has a file
@ -10,23 +10,25 @@ Subject: server: Do not allow to set disposition on file which has a file
2 files changed, 15 insertions(+), 2 deletions(-)
diff --git a/dlls/ntdll/tests/file.c b/dlls/ntdll/tests/file.c
index 6408eaa..5620815 100644
index 1726546..2784e9b 100644
--- a/dlls/ntdll/tests/file.c
+++ b/dlls/ntdll/tests/file.c
@@ -1535,13 +1535,11 @@ static void test_file_disposition_information(void)
ok( ptr != NULL, "MapViewOfFile failed\n");
@@ -1533,7 +1533,6 @@ static void test_file_disposition_information(void)
ok( mapping != NULL, "failed to create file mapping\n");
fdi.DoDeleteFile = TRUE;
res = pNtSetInformationFile( handle, &io, &fdi, sizeof fdi, FileDispositionInformation );
-todo_wine
- todo_wine
ok( res == STATUS_CANNOT_DELETE, "unexpected FileDispositionInformation result (expected STATUS_CANNOT_DELETE, got %x)\n", res );
CloseHandle( handle );
fileDeleted = GetFileAttributesA( buffer ) == INVALID_FILE_ATTRIBUTES && GetLastError() == ERROR_FILE_NOT_FOUND;
@@ -1567,7 +1566,6 @@ static void test_file_disposition_information(void)
CloseHandle( mapping );
fdi.DoDeleteFile = TRUE;
res = pNtSetInformationFile( handle, &io, &fdi, sizeof fdi, FileDispositionInformation );
- todo_wine
ok( res == STATUS_CANNOT_DELETE, "unexpected FileDispositionInformation result (expected STATUS_CANNOT_DELETE, got %x)\n", res );
CloseHandle( handle );
UnmapViewOfFile( ptr );
CloseHandle( mapping );
fileDeleted = GetFileAttributesA( buffer ) == INVALID_FILE_ATTRIBUTES && GetLastError() == ERROR_FILE_NOT_FOUND;
-todo_wine
ok( !fileDeleted, "File shouldn't have been deleted\n" );
DeleteFileA( buffer );
}
diff --git a/server/fd.c b/server/fd.c
index 036478a..90487cc 100644
--- a/server/fd.c