diff options
| author | Sean Hall <r.sean.hall@gmail.com> | 2019-12-22 10:31:33 +1100 |
|---|---|---|
| committer | Sean Hall <r.sean.hall@gmail.com> | 2019-12-22 13:19:29 +1000 |
| commit | 24379873f589cff33965f1104041f61c0c4503e0 (patch) | |
| tree | b50fb0270d2de706cb6f3a4dea0af77ce2cae9e1 /src/test | |
| parent | f3c383c2412e376353d64a8b744184fa1cee1c6e (diff) | |
| download | wix-24379873f589cff33965f1104041f61c0c4503e0.tar.gz wix-24379873f589cff33965f1104041f61c0c4503e0.tar.bz2 wix-24379873f589cff33965f1104041f61c0c4503e0.zip | |
Move the responsibility of wrapping the binary interfaces from mbahost to the new mbanative dll of WixToolset.Mba.Core.
Diffstat (limited to 'src/test')
3 files changed, 147 insertions, 0 deletions
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 @@ | |||
| 1 | // 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. | ||
| 2 | |||
| 3 | namespace WixToolsetTest.Util | ||
| 4 | { | ||
| 5 | using System; | ||
| 6 | using System.Runtime.InteropServices; | ||
| 7 | using WixToolset.Mba.Core; | ||
| 8 | using Xunit; | ||
| 9 | |||
| 10 | public class BaseBootstrapperApplicationFactoryFixture | ||
| 11 | { | ||
| 12 | [Fact] | ||
| 13 | public void CanCreateBA() | ||
| 14 | { | ||
| 15 | var command = new TestCommand | ||
| 16 | { | ||
| 17 | action = LaunchAction.Install, | ||
| 18 | cbSize = Marshal.SizeOf(typeof(TestCommand)), | ||
| 19 | display = Display.Full, | ||
| 20 | wzCommandLine = "this \"is a\" test", | ||
| 21 | }; | ||
| 22 | var pCommand = Marshal.AllocHGlobal(command.cbSize); | ||
| 23 | try | ||
| 24 | { | ||
| 25 | Marshal.StructureToPtr(command, pCommand, false); | ||
| 26 | var createArgs = new BootstrapperCreateArgs(0, IntPtr.Zero, IntPtr.Zero, pCommand); | ||
| 27 | var pArgs = Marshal.AllocHGlobal(createArgs.cbSize); | ||
| 28 | try | ||
| 29 | { | ||
| 30 | Marshal.StructureToPtr(createArgs, pArgs, false); | ||
| 31 | var createResults = new TestCreateResults | ||
| 32 | { | ||
| 33 | cbSize = Marshal.SizeOf<TestCreateResults>(), | ||
| 34 | }; | ||
| 35 | var pResults = Marshal.AllocHGlobal(createResults.cbSize); | ||
| 36 | try | ||
| 37 | { | ||
| 38 | var baFactory = new TestBAFactory(); | ||
| 39 | baFactory.Create(pArgs, pResults); | ||
| 40 | |||
| 41 | createResults = Marshal.PtrToStructure<TestCreateResults>(pResults); | ||
| 42 | Assert.Equal(baFactory.BA, createResults.pBA); | ||
| 43 | Assert.Equal(baFactory.BA.Command.Action, command.action); | ||
| 44 | Assert.Equal(baFactory.BA.Command.Display, command.display); | ||
| 45 | Assert.Equal(baFactory.BA.Command.CommandLineArgs, new string[] { "this", "is a", "test" }); | ||
| 46 | } | ||
| 47 | finally | ||
| 48 | { | ||
| 49 | Marshal.FreeHGlobal(pResults); | ||
| 50 | } | ||
| 51 | } | ||
| 52 | finally | ||
| 53 | { | ||
| 54 | Marshal.FreeHGlobal(pArgs); | ||
| 55 | } | ||
| 56 | } | ||
| 57 | finally | ||
| 58 | { | ||
| 59 | Marshal.FreeHGlobal(pCommand); | ||
| 60 | } | ||
| 61 | } | ||
| 62 | |||
| 63 | internal class TestBAFactory : BaseBootstrapperApplicationFactory | ||
| 64 | { | ||
| 65 | public TestBA BA { get; private set; } | ||
| 66 | |||
| 67 | protected override IBootstrapperApplication Create(IEngine engine, IBootstrapperCommand bootstrapperCommand) | ||
| 68 | { | ||
| 69 | this.BA = new TestBA(engine, bootstrapperCommand); | ||
| 70 | return this.BA; | ||
| 71 | } | ||
| 72 | } | ||
| 73 | |||
| 74 | internal class TestBA : BootstrapperApplication | ||
| 75 | { | ||
| 76 | public IBootstrapperCommand Command { get; } | ||
| 77 | |||
| 78 | public TestBA(IEngine engine, IBootstrapperCommand command) | ||
| 79 | : base(engine) | ||
| 80 | { | ||
| 81 | this.Command = command; | ||
| 82 | } | ||
| 83 | |||
| 84 | protected override void Run() | ||
| 85 | { | ||
| 86 | } | ||
| 87 | } | ||
| 88 | |||
| 89 | [StructLayout(LayoutKind.Sequential)] | ||
| 90 | public struct TestCommand | ||
| 91 | { | ||
| 92 | public int cbSize; | ||
| 93 | public LaunchAction action; | ||
| 94 | public Display display; | ||
| 95 | public Restart restart; | ||
| 96 | [MarshalAs(UnmanagedType.LPWStr)] public string wzCommandLine; | ||
| 97 | public int nCmdShow; | ||
| 98 | public ResumeType resume; | ||
| 99 | public IntPtr hwndSplashScreen; | ||
| 100 | public RelationType relation; | ||
| 101 | [MarshalAs(UnmanagedType.Bool)] public bool passthrough; | ||
| 102 | [MarshalAs(UnmanagedType.LPWStr)] public string wzLayoutDirectory; | ||
| 103 | } | ||
| 104 | |||
| 105 | [StructLayout(LayoutKind.Sequential)] | ||
| 106 | public struct TestCreateResults | ||
| 107 | { | ||
| 108 | public int cbSize; | ||
| 109 | public IntPtr pBAProc; | ||
| 110 | [MarshalAs(UnmanagedType.Interface)] public IBootstrapperApplication pBA; | ||
| 111 | } | ||
| 112 | } | ||
| 113 | } | ||
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 @@ | |||
| 1 | <?xml version="1.0" encoding="utf-8"?> | ||
| 2 | <!-- 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. --> | ||
| 3 | |||
| 4 | <Project Sdk="Microsoft.NET.Sdk"> | ||
| 5 | <PropertyGroup> | ||
| 6 | <TargetFramework>netcoreapp2.1</TargetFramework> | ||
| 7 | <IsPackable>false</IsPackable> | ||
| 8 | <Platforms>AnyCPU;x86;x64</Platforms> | ||
| 9 | </PropertyGroup> | ||
| 10 | |||
| 11 | <PropertyGroup> | ||
| 12 | <NoWarn>NU1701</NoWarn> | ||
| 13 | </PropertyGroup> | ||
| 14 | |||
| 15 | <ItemGroup> | ||
| 16 | <ProjectReference Include="..\..\mbanative\mbanative.vcxproj"> | ||
| 17 | <Project>{665E0441-17F9-4105-B202-EDF274657F6E}</Project> | ||
| 18 | <OutputItemType>Content</OutputItemType> | ||
| 19 | <CopyToOutputDirectory>Always</CopyToOutputDirectory> | ||
| 20 | </ProjectReference> | ||
| 21 | <ProjectReference Include="..\..\WixToolset.Mba.Core\WixToolset.Mba.Core.csproj" /> | ||
| 22 | </ItemGroup> | ||
| 23 | |||
| 24 | <ItemGroup> | ||
| 25 | <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" /> | ||
| 26 | <PackageReference Include="xunit" Version="2.4.1" /> | ||
| 27 | <PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" PrivateAssets="All" /> | ||
| 28 | </ItemGroup> | ||
| 29 | </Project> | ||
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 @@ | |||
| 1 | <ProjectConfiguration> | ||
| 2 | <Settings> | ||
| 3 | <CopyReferencedAssembliesToWorkspace>True</CopyReferencedAssembliesToWorkspace> | ||
| 4 | </Settings> | ||
| 5 | </ProjectConfiguration> \ No newline at end of file | ||
