Minor tweaks to PR #386

pull/387/head
David Hall 2023-04-04 08:00:22 -06:00
parent a9ff5e3c8f
commit 44d9c2a3b2
2 changed files with 264 additions and 264 deletions

View File

@ -68,13 +68,13 @@ namespace Vanara.PInvoke.Tests
[Test]
public void DbgUiSetThreadDebugObjectAndNtRemoveProcessDebugTest()
{
Kernel32.STARTUPINFO StartInfo = new Kernel32.STARTUPINFO
Kernel32.STARTUPINFO StartInfo = new()
{
dwFlags = Kernel32.STARTF.STARTF_USESHOWWINDOW,
wShowWindow = (ushort)ShowWindowCommand.SW_HIDE
};
Assert.IsTrue(Kernel32.CreateProcess("notepad.exe", dwCreationFlags: Kernel32.CREATE_PROCESS.DEBUG_PROCESS | Kernel32.CREATE_PROCESS.CREATE_UNICODE_ENVIRONMENT, lpStartupInfo: StartInfo, lpProcessInformation: out Kernel32.SafePROCESS_INFORMATION Information));
Assert.That(Kernel32.CreateProcess(@"C:\Program Files\Notepad++\notepad++.exe", dwCreationFlags: Kernel32.CREATE_PROCESS.DEBUG_PROCESS | Kernel32.CREATE_PROCESS.CREATE_UNICODE_ENVIRONMENT, lpStartupInfo: StartInfo, lpProcessInformation: out Kernel32.SafePROCESS_INFORMATION Information), ResultIs.Successful);
using (Information)
using (NtQueryResult<IntPtr> DebugObjectHandleQueryResult = NtQueryInformationProcess<IntPtr>(Information.hProcess, PROCESSINFOCLASS.ProcessDebugObjectHandle))
@ -84,7 +84,7 @@ namespace Vanara.PInvoke.Tests
try
{
Assert.DoesNotThrow(() => DbgUiSetThreadDebugObject(DebugObjectHandleQueryResult.Value).ThrowIfFailed());
Assert.That(DbgUiSetThreadDebugObject(DebugObjectHandleQueryResult.Value), ResultIs.Successful);
try
{
@ -94,7 +94,7 @@ namespace Vanara.PInvoke.Tests
{
while (true)
{
Assert.IsTrue(Kernel32.WaitForDebugEvent(out Kernel32.DEBUG_EVENT Event, Kernel32.INFINITE));
Assert.That(Kernel32.WaitForDebugEvent(out Kernel32.DEBUG_EVENT Event, Kernel32.INFINITE), ResultIs.Successful);
if (Event.dwDebugEventCode == Kernel32.DEBUG_EVENT_CODE.CREATE_PROCESS_DEBUG_EVENT)
{
@ -102,10 +102,10 @@ namespace Vanara.PInvoke.Tests
break;
}
Assert.IsTrue(Kernel32.ContinueDebugEvent(Event.dwProcessId, Event.dwThreadId, Kernel32.DEBUG_CONTINUE.DBG_CONTINUE));
Assert.That(Kernel32.ContinueDebugEvent(Event.dwProcessId, Event.dwThreadId, Kernel32.DEBUG_CONTINUE.DBG_CONTINUE), ResultIs.Successful);
}
Assert.AreNotEqual(Kernel32.SafeHPROCESS.Null, DebugProcessHandle);
Assert.False(DebugProcessHandle.IsNull);
}
finally
{
@ -114,13 +114,13 @@ namespace Vanara.PInvoke.Tests
}
finally
{
Assert.DoesNotThrow(() => DbgUiSetThreadDebugObject(IntPtr.Zero).ThrowIfFailed());
Assert.That(DbgUiSetThreadDebugObject(IntPtr.Zero), ResultIs.Successful);
}
}
finally
{
Assert.IsTrue(Kernel32.TerminateProcess(Information.hProcess, 0));
Assert.DoesNotThrow(() => NtRemoveProcessDebug(Information.hProcess, DebugObjectHandleQueryResult.Value).ThrowIfFailed());
Assert.That(Kernel32.TerminateProcess(Information.hProcess, 0), ResultIs.Successful);
Assert.That(NtRemoveProcessDebug(Information.hProcess, DebugObjectHandleQueryResult.Value), ResultIs.Successful);
}
}
}