kernel32/tests: Add tests for waiting on an job object.

This commit is contained in:
Sebastian Lackner 2015-04-03 17:20:05 +11:00 committed by Alexandre Julliard
parent 1d359a5827
commit 7984fb9fbe
1 changed files with 85 additions and 0 deletions

View File

@ -2443,6 +2443,90 @@ static void test_KillOnJobClose(void)
CloseHandle(pi.hThread);
}
static void test_WaitForJobObject(void)
{
HANDLE job;
PROCESS_INFORMATION pi;
BOOL ret;
DWORD dwret;
/* test waiting for a job object when the process is killed */
job = pCreateJobObjectW(NULL, NULL);
ok(job != NULL, "CreateJobObject error %u\n", GetLastError());
dwret = WaitForSingleObject(job, 100);
ok(dwret == WAIT_TIMEOUT, "WaitForSingleObject returned %u\n", dwret);
create_process("wait", &pi);
ret = pAssignProcessToJobObject(job, pi.hProcess);
ok(ret, "AssignProcessToJobObject error %u\n", GetLastError());
dwret = WaitForSingleObject(job, 100);
ok(dwret == WAIT_TIMEOUT, "WaitForSingleObject returned %u\n", dwret);
ret = pTerminateJobObject(job, 123);
ok(ret, "TerminateJobObject error %u\n", GetLastError());
dwret = WaitForSingleObject(job, 500);
todo_wine
ok(dwret == WAIT_OBJECT_0 || broken(dwret == WAIT_TIMEOUT),
"WaitForSingleObject returned %u\n", dwret);
if (dwret == WAIT_TIMEOUT) /* Win 2000/XP */
{
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
CloseHandle(job);
todo_wine
win_skip("TerminateJobObject doesn't signal job, skipping tests\n");
return;
}
/* the object is not reset immediately */
dwret = WaitForSingleObject(job, 100);
ok(dwret == WAIT_OBJECT_0, "WaitForSingleObject returned %u\n", dwret);
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
/* creating a new process doesn't reset the signalled state */
create_process("wait", &pi);
ret = pAssignProcessToJobObject(job, pi.hProcess);
ok(ret, "AssignProcessToJobObject error %u\n", GetLastError());
dwret = WaitForSingleObject(job, 100);
ok(dwret == WAIT_OBJECT_0, "WaitForSingleObject returned %u\n", dwret);
ret = pTerminateJobObject(job, 123);
ok(ret, "TerminateJobObject error %u\n", GetLastError());
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
CloseHandle(job);
/* repeat the test, but this time the process terminates properly */
job = pCreateJobObjectW(NULL, NULL);
ok(job != NULL, "CreateJobObject error %u\n", GetLastError());
dwret = WaitForSingleObject(job, 100);
ok(dwret == WAIT_TIMEOUT, "WaitForSingleObject returned %u\n", dwret);
create_process("exit", &pi);
ret = pAssignProcessToJobObject(job, pi.hProcess);
ok(ret, "AssignProcessToJobObject error %u\n", GetLastError());
dwret = WaitForSingleObject(job, 100);
ok(dwret == WAIT_TIMEOUT, "WaitForSingleObject returned %u\n", dwret);
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
CloseHandle(job);
}
static HANDLE test_AddSelfToJob(void)
{
HANDLE job;
@ -2625,6 +2709,7 @@ START_TEST(process)
test_QueryInformationJobObject();
test_CompletionPort();
test_KillOnJobClose();
test_WaitForJobObject();
job = test_AddSelfToJob();
test_jobInheritance(job);
test_BreakawayOk(job);