Piotr Caban : kernet32: Added DuplicateHandle tests with DUPLICATE_CLOSE_SOURCE flag.
Alexandre Julliard
julliard at winehq.org
Wed Jun 5 13:47:02 CDT 2013
Module: wine
Branch: master
Commit: c9dbef3d96b39e4e09aa20b1813d491e4f0238f2
URL: http://source.winehq.org/git/wine.git/?a=commit;h=c9dbef3d96b39e4e09aa20b1813d491e4f0238f2
Author: Piotr Caban <piotr at codeweavers.com>
Date: Wed Jun 5 11:33:29 2013 +0200
kernet32: Added DuplicateHandle tests with DUPLICATE_CLOSE_SOURCE flag.
---
dlls/kernel32/tests/process.c | 98 +++++++++++++++++++++++++++++++++++++++++
1 files changed, 98 insertions(+), 0 deletions(-)
diff --git a/dlls/kernel32/tests/process.c b/dlls/kernel32/tests/process.c
index 9d3e983..1fef8ac 100644
--- a/dlls/kernel32/tests/process.c
+++ b/dlls/kernel32/tests/process.c
@@ -1963,6 +1963,103 @@ static void test_TerminateProcess(void)
CloseHandle(pi.hThread);
}
+static void test_DuplicateHandle(void)
+{
+ char path[MAX_PATH], file_name[MAX_PATH];
+ HANDLE f, fmin, out;
+ DWORD info;
+ BOOL r;
+
+ r = DuplicateHandle(GetCurrentProcess(), GetCurrentProcess(),
+ GetCurrentProcess(), &out, 0, FALSE,
+ DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE);
+ ok(r, "DuplicateHandle error %u\n", GetLastError());
+ r = GetHandleInformation(out, &info);
+ ok(r, "GetHandleInformation error %u\n", GetLastError());
+ ok(info == 0, "info = %x\n", info);
+ ok(out != GetCurrentProcess(), "out = GetCurrentProcess()\n");
+ CloseHandle(out);
+
+ r = DuplicateHandle(GetCurrentProcess(), GetCurrentProcess(),
+ GetCurrentProcess(), &out, 0, TRUE,
+ DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE);
+ ok(r, "DuplicateHandle error %u\n", GetLastError());
+ r = GetHandleInformation(out, &info);
+ ok(r, "GetHandleInformation error %u\n", GetLastError());
+ ok(info == HANDLE_FLAG_INHERIT, "info = %x\n", info);
+ ok(out != GetCurrentProcess(), "out = GetCurrentProcess()\n");
+ CloseHandle(out);
+
+ GetTempPath(MAX_PATH, path);
+ GetTempFileName(path, "wt", 0, file_name);
+ f = CreateFile(file_name, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, 0);
+ if (f == INVALID_HANDLE_VALUE)
+ {
+ ok(0, "could not create %s\n", file_name);
+ return;
+ }
+
+ r = DuplicateHandle(GetCurrentProcess(), f, GetCurrentProcess(), &out,
+ 0, FALSE, DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE);
+ ok(r, "DuplicateHandle error %u\n", GetLastError());
+ ok(f == out, "f != out\n");
+ r = GetHandleInformation(out, &info);
+ ok(r, "GetHandleInformation error %u\n", GetLastError());
+ ok(info == 0, "info = %x\n", info);
+
+ r = DuplicateHandle(GetCurrentProcess(), f, GetCurrentProcess(), &out,
+ 0, TRUE, DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE);
+ ok(r, "DuplicateHandle error %u\n", GetLastError());
+ ok(f == out, "f != out\n");
+ r = GetHandleInformation(out, &info);
+ ok(r, "GetHandleInformation error %u\n", GetLastError());
+ ok(info == HANDLE_FLAG_INHERIT, "info = %x\n", info);
+
+ r = SetHandleInformation(f, HANDLE_FLAG_PROTECT_FROM_CLOSE, HANDLE_FLAG_PROTECT_FROM_CLOSE);
+ ok(r, "SetHandleInformation error %u\n", GetLastError());
+ r = DuplicateHandle(GetCurrentProcess(), f, GetCurrentProcess(), &out,
+ 0, TRUE, DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE);
+ ok(r, "DuplicateHandle error %u\n", GetLastError());
+ ok(f != out, "f == out\n");
+ r = GetHandleInformation(out, &info);
+ ok(r, "GetHandleInformation error %u\n", GetLastError());
+ ok(info == HANDLE_FLAG_INHERIT, "info = %x\n", info);
+ r = SetHandleInformation(f, HANDLE_FLAG_PROTECT_FROM_CLOSE, 0);
+ ok(r, "SetHandleInformation error %u\n", GetLastError());
+
+ /* Test if DuplicateHandle allocates first free handle */
+ if (f > out)
+ {
+ fmin = out;
+ }
+ else
+ {
+ fmin = f;
+ f = out;
+ }
+ CloseHandle(fmin);
+ r = DuplicateHandle(GetCurrentProcess(), f, GetCurrentProcess(), &out,
+ 0, TRUE, DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE);
+ ok(r, "DuplicateHandle error %u\n", GetLastError());
+ ok(f == out, "f != out\n");
+ CloseHandle(out);
+ DeleteFile(file_name);
+
+ f = CreateFile("CONIN$", GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, 0);
+ if (!is_console(f))
+ {
+ skip("DuplicateHandle on console handle");
+ CloseHandle(f);
+ return;
+ }
+
+ r = DuplicateHandle(GetCurrentProcess(), f, GetCurrentProcess(), &out,
+ 0, FALSE, DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE);
+ ok(r, "DuplicateHandle error %u\n", GetLastError());
+ todo_wine ok(f != out, "f == out\n");
+ CloseHandle(out);
+}
+
START_TEST(process)
{
int b = init();
@@ -1991,6 +2088,7 @@ START_TEST(process)
test_Handles();
test_SystemInfo();
test_RegistryQuota();
+ test_DuplicateHandle();
/* things that can be tested:
* lookup: check the way program to be executed is searched
* handles: check the handle inheritance stuff (+sec options)
More information about the wine-cvs
mailing list