From 24379873f589cff33965f1104041f61c0c4503e0 Mon Sep 17 00:00:00 2001 From: Sean Hall Date: Sun, 22 Dec 2019 10:31:33 +1100 Subject: Move the responsibility of wrapping the binary interfaces from mbahost to the new mbanative dll of WixToolset.Mba.Core. --- .../BaseBootstrapperApplicationFactoryFixture.cs | 113 +++++++++++++++++++++ .../WixToolsetTest.Mba.Core.csproj | 29 ++++++ .../WixToolsetTest.Mba.Core.v3.ncrunchproject | 5 + 3 files changed, 147 insertions(+) create mode 100644 src/test/WixToolsetTest.Mba.Core/BaseBootstrapperApplicationFactoryFixture.cs create mode 100644 src/test/WixToolsetTest.Mba.Core/WixToolsetTest.Mba.Core.csproj create mode 100644 src/test/WixToolsetTest.Mba.Core/WixToolsetTest.Mba.Core.v3.ncrunchproject (limited to 'src/test') diff --git a/src/test/WixToolsetTest.Mba.Core/BaseBootstrapperApplicationFactoryFixture.cs b/src/test/WixToolsetTest.Mba.Core/BaseBootstrapperApplicationFactoryFixture.cs new file mode 100644 index 00000000..12483ddf --- /dev/null +++ b/src/test/WixToolsetTest.Mba.Core/BaseBootstrapperApplicationFactoryFixture.cs @@ -0,0 +1,113 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. + +namespace WixToolsetTest.Util +{ + using System; + using System.Runtime.InteropServices; + using WixToolset.Mba.Core; + using Xunit; + + public class BaseBootstrapperApplicationFactoryFixture + { + [Fact] + public void CanCreateBA() + { + var command = new TestCommand + { + action = LaunchAction.Install, + cbSize = Marshal.SizeOf(typeof(TestCommand)), + display = Display.Full, + wzCommandLine = "this \"is a\" test", + }; + var pCommand = Marshal.AllocHGlobal(command.cbSize); + try + { + Marshal.StructureToPtr(command, pCommand, false); + var createArgs = new BootstrapperCreateArgs(0, IntPtr.Zero, IntPtr.Zero, pCommand); + var pArgs = Marshal.AllocHGlobal(createArgs.cbSize); + try + { + Marshal.StructureToPtr(createArgs, pArgs, false); + var createResults = new TestCreateResults + { + cbSize = Marshal.SizeOf(), + }; + var pResults = Marshal.AllocHGlobal(createResults.cbSize); + try + { + var baFactory = new TestBAFactory(); + baFactory.Create(pArgs, pResults); + + createResults = Marshal.PtrToStructure(pResults); + Assert.Equal(baFactory.BA, createResults.pBA); + Assert.Equal(baFactory.BA.Command.Action, command.action); + Assert.Equal(baFactory.BA.Command.Display, command.display); + Assert.Equal(baFactory.BA.Command.CommandLineArgs, new string[] { "this", "is a", "test" }); + } + finally + { + Marshal.FreeHGlobal(pResults); + } + } + finally + { + Marshal.FreeHGlobal(pArgs); + } + } + finally + { + Marshal.FreeHGlobal(pCommand); + } + } + + internal class TestBAFactory : BaseBootstrapperApplicationFactory + { + public TestBA BA { get; private set; } + + protected override IBootstrapperApplication Create(IEngine engine, IBootstrapperCommand bootstrapperCommand) + { + this.BA = new TestBA(engine, bootstrapperCommand); + return this.BA; + } + } + + internal class TestBA : BootstrapperApplication + { + public IBootstrapperCommand Command { get; } + + public TestBA(IEngine engine, IBootstrapperCommand command) + : base(engine) + { + this.Command = command; + } + + protected override void Run() + { + } + } + + [StructLayout(LayoutKind.Sequential)] + public struct TestCommand + { + public int cbSize; + public LaunchAction action; + public Display display; + public Restart restart; + [MarshalAs(UnmanagedType.LPWStr)] public string wzCommandLine; + public int nCmdShow; + public ResumeType resume; + public IntPtr hwndSplashScreen; + public RelationType relation; + [MarshalAs(UnmanagedType.Bool)] public bool passthrough; + [MarshalAs(UnmanagedType.LPWStr)] public string wzLayoutDirectory; + } + + [StructLayout(LayoutKind.Sequential)] + public struct TestCreateResults + { + public int cbSize; + public IntPtr pBAProc; + [MarshalAs(UnmanagedType.Interface)] public IBootstrapperApplication pBA; + } + } +} diff --git a/src/test/WixToolsetTest.Mba.Core/WixToolsetTest.Mba.Core.csproj b/src/test/WixToolsetTest.Mba.Core/WixToolsetTest.Mba.Core.csproj new file mode 100644 index 00000000..d401d877 --- /dev/null +++ b/src/test/WixToolsetTest.Mba.Core/WixToolsetTest.Mba.Core.csproj @@ -0,0 +1,29 @@ + + + + + + netcoreapp2.1 + false + AnyCPU;x86;x64 + + + + NU1701 + + + + + {665E0441-17F9-4105-B202-EDF274657F6E} + Content + Always + + + + + + + + + + diff --git a/src/test/WixToolsetTest.Mba.Core/WixToolsetTest.Mba.Core.v3.ncrunchproject b/src/test/WixToolsetTest.Mba.Core/WixToolsetTest.Mba.Core.v3.ncrunchproject new file mode 100644 index 00000000..7b5b2139 --- /dev/null +++ b/src/test/WixToolsetTest.Mba.Core/WixToolsetTest.Mba.Core.v3.ncrunchproject @@ -0,0 +1,5 @@ + + + True + + \ No newline at end of file -- cgit v1.2.3-55-g6feb