From c9cb0eaa9f9a2e391a7bdd8dd45506431c74e1c7 Mon Sep 17 00:00:00 2001
From: Next Turn <45985406+nxtn@users.noreply.github.com>
Date: Sun, 29 Jan 2023 15:30:39 +0800
Subject: [PATCH] Fix tests
---
src/WinSW.Tests/CommandLineTests.cs | 2 +-
src/WinSW.Tests/NativeMethods.txt | 1 +
.../Util/InterProcessCodeCoverageSession.cs | 14 ++++----------
src/WinSW.Tests/WinSW.Tests.csproj | 4 ++++
4 files changed, 10 insertions(+), 11 deletions(-)
create mode 100644 src/WinSW.Tests/NativeMethods.txt
diff --git a/src/WinSW.Tests/CommandLineTests.cs b/src/WinSW.Tests/CommandLineTests.cs
index 3c711b2..d8eb883 100644
--- a/src/WinSW.Tests/CommandLineTests.cs
+++ b/src/WinSW.Tests/CommandLineTests.cs
@@ -27,7 +27,7 @@ namespace WinSW.Tests
Assert.Equal(ServiceControllerStatus.Stopped, controller.Status);
Assert.Equal(ServiceType.Win32OwnProcess, controller.ServiceType);
-#if NETFRAMEWORK
+#if NET
InterProcessCodeCoverageSession session = null;
try
{
diff --git a/src/WinSW.Tests/NativeMethods.txt b/src/WinSW.Tests/NativeMethods.txt
new file mode 100644
index 0000000..2c9cb77
--- /dev/null
+++ b/src/WinSW.Tests/NativeMethods.txt
@@ -0,0 +1 @@
+Windows.Win32.System.Diagnostics.Debug.DebugCreate
diff --git a/src/WinSW.Tests/Util/InterProcessCodeCoverageSession.cs b/src/WinSW.Tests/Util/InterProcessCodeCoverageSession.cs
index 6ccef86..fb5f515 100644
--- a/src/WinSW.Tests/Util/InterProcessCodeCoverageSession.cs
+++ b/src/WinSW.Tests/Util/InterProcessCodeCoverageSession.cs
@@ -6,6 +6,7 @@ using System.Runtime.InteropServices;
using System.Threading;
using Microsoft.Diagnostics.Runtime;
using Microsoft.Diagnostics.Runtime.Interop;
+using Windows.Win32;
using WinSW.Native;
using Xunit;
@@ -36,20 +37,19 @@ namespace WinSW.Tests.Util
Assert.True(processId >= 0);
var guid = new Guid("27fe5639-8407-4f47-8364-ee118fb08ac8");
- int hr = Native.DebugCreate(guid, out object unknown);
- AssertEx.Succeeded(hr);
+ PInvoke.DebugCreate(guid, out object unknown).ThrowOnFailure();
var client = (IDebugClient)unknown;
this.control = (IDebugControl)unknown;
- hr = client.AttachProcess(0, (uint)processId, DEBUG_ATTACH.DEFAULT);
+ int hr = client.AttachProcess(0, (uint)processId, DEBUG_ATTACH.DEFAULT);
AssertEx.Succeeded(hr);
hr = client.SetEventCallbacks(this);
AssertEx.Succeeded(hr);
var pointer = Marshal.GetIUnknownForObject(client);
- Assert.Equal(1, Marshal.Release(pointer));
+ Assert.Equal(3, Marshal.Release(pointer));
target = DataTarget.CreateFromDbgEng(pointer);
@@ -181,11 +181,5 @@ namespace WinSW.Tests.Util
{
throw new NotImplementedException();
}
-
- private static class Native
- {
- [DllImport("dbgeng.dll")]
- internal static extern int DebugCreate(in Guid InterfaceId, [MarshalAs(UnmanagedType.IUnknown)] out object Interface);
- }
}
}
diff --git a/src/WinSW.Tests/WinSW.Tests.csproj b/src/WinSW.Tests/WinSW.Tests.csproj
index 6288ec4..1b5b35c 100644
--- a/src/WinSW.Tests/WinSW.Tests.csproj
+++ b/src/WinSW.Tests/WinSW.Tests.csproj
@@ -13,6 +13,10 @@
+
+ all
+ runtime; build; native; contentfiles; analyzers
+
runtime; build; native; contentfiles; analyzers; buildtransitive