aboutsummaryrefslogtreecommitdiff
path: root/src/api/burn/test/WixToolsetTest.Mba.Core
diff options
context:
space:
mode:
authorRob Mensching <rob@firegiant.com>2021-04-22 05:46:03 -0700
committerRob Mensching <rob@firegiant.com>2021-04-29 16:41:44 -0700
commitc00516901e6b67e398396b14fe7682d0376f8643 (patch)
treeb0d62089a1c5700c7f2c3e3790750bf2d8ea33c0 /src/api/burn/test/WixToolsetTest.Mba.Core
parent8eb98efd2175d9ece2e4639d43081667af9a4990 (diff)
downloadwix-c00516901e6b67e398396b14fe7682d0376f8643.tar.gz
wix-c00516901e6b67e398396b14fe7682d0376f8643.tar.bz2
wix-c00516901e6b67e398396b14fe7682d0376f8643.zip
Move balutil into API/burn
Diffstat (limited to 'src/api/burn/test/WixToolsetTest.Mba.Core')
-rw-r--r--src/api/burn/test/WixToolsetTest.Mba.Core/BaseBootstrapperApplicationFactoryFixture.cs132
-rw-r--r--src/api/burn/test/WixToolsetTest.Mba.Core/VerUtilFixture.cs93
-rw-r--r--src/api/burn/test/WixToolsetTest.Mba.Core/WixToolsetTest.Mba.Core.csproj21
-rw-r--r--src/api/burn/test/WixToolsetTest.Mba.Core/WixToolsetTest.Mba.Core.v3.ncrunchproject5
4 files changed, 251 insertions, 0 deletions
diff --git a/src/api/burn/test/WixToolsetTest.Mba.Core/BaseBootstrapperApplicationFactoryFixture.cs b/src/api/burn/test/WixToolsetTest.Mba.Core/BaseBootstrapperApplicationFactoryFixture.cs
new file mode 100644
index 00000000..aaf5ee29
--- /dev/null
+++ b/src/api/burn/test/WixToolsetTest.Mba.Core/BaseBootstrapperApplicationFactoryFixture.cs
@@ -0,0 +1,132 @@
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
3namespace WixToolsetTest.Mba.Core
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 BootstrapperCreateArgs
107 {
108 [MarshalAs(UnmanagedType.I4)] public readonly int cbSize;
109 [MarshalAs(UnmanagedType.I8)] public readonly long qwEngineAPIVersion;
110 public readonly IntPtr pfnBootstrapperEngineProc;
111 public readonly IntPtr pvBootstrapperEngineProcContext;
112 public readonly IntPtr pCommand;
113
114 public BootstrapperCreateArgs(long version, IntPtr pEngineProc, IntPtr pEngineContext, IntPtr pCommand)
115 {
116 this.cbSize = Marshal.SizeOf(typeof(BootstrapperCreateArgs));
117 this.qwEngineAPIVersion = version;
118 this.pfnBootstrapperEngineProc = pEngineProc;
119 this.pvBootstrapperEngineProcContext = pEngineContext;
120 this.pCommand = pCommand;
121 }
122 }
123
124 [StructLayout(LayoutKind.Sequential)]
125 public struct TestCreateResults
126 {
127 public int cbSize;
128 public IntPtr pBAProc;
129 [MarshalAs(UnmanagedType.Interface)] public IBootstrapperApplication pBA;
130 }
131 }
132}
diff --git a/src/api/burn/test/WixToolsetTest.Mba.Core/VerUtilFixture.cs b/src/api/burn/test/WixToolsetTest.Mba.Core/VerUtilFixture.cs
new file mode 100644
index 00000000..44142e3d
--- /dev/null
+++ b/src/api/burn/test/WixToolsetTest.Mba.Core/VerUtilFixture.cs
@@ -0,0 +1,93 @@
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
3namespace WixToolsetTest.Mba.Core
4{
5 using System;
6 using WixToolset.Mba.Core;
7 using Xunit;
8
9 public class VerUtilFixture
10 {
11 [Fact]
12 public void CanCompareStringVersions()
13 {
14 var version1 = "1.2.3.4+abcd";
15 var version2 = "1.2.3.4+zyxw";
16
17 Assert.Equal(0, VerUtil.CompareStringVersions(version1, version2, strict: false));
18 }
19
20 [Fact]
21 public void CanCopyVersion()
22 {
23 var version = "1.2.3.4-5.6.7.8.9.0";
24
25 VerUtilVersion copiedVersion = null;
26 try
27 {
28 using (var parsedVersion = VerUtil.ParseVersion(version, strict: true))
29 {
30 copiedVersion = VerUtil.CopyVersion(parsedVersion);
31 }
32
33 using (var secondVersion = VerUtil.ParseVersion(version, strict: true))
34 {
35 Assert.Equal(0, VerUtil.CompareParsedVersions(copiedVersion, secondVersion));
36 }
37 }
38 finally
39 {
40 copiedVersion?.Dispose();
41 }
42 }
43
44 [Fact]
45 public void CanCreateFromQword()
46 {
47 var version = new Version(100, 200, 300, 400);
48 var qwVersion = Engine.VersionToLong(version);
49
50 using var parsedVersion = VerUtil.VersionFromQword(qwVersion);
51 Assert.Equal("100.200.300.400", parsedVersion.Version);
52 Assert.Equal(100u, parsedVersion.Major);
53 Assert.Equal(200u, parsedVersion.Minor);
54 Assert.Equal(300u, parsedVersion.Patch);
55 Assert.Equal(400u, parsedVersion.Revision);
56 Assert.Empty(parsedVersion.ReleaseLabels);
57 Assert.Equal("", parsedVersion.Metadata);
58 Assert.False(parsedVersion.IsInvalid);
59 }
60
61 [Fact]
62 public void CanParseVersion()
63 {
64 var version = "1.2.3.4-a.b.c.d.5.+abc123";
65
66 using var parsedVersion = VerUtil.ParseVersion(version, strict: false);
67 Assert.Equal(version, parsedVersion.Version);
68 Assert.Equal(1u, parsedVersion.Major);
69 Assert.Equal(2u, parsedVersion.Minor);
70 Assert.Equal(3u, parsedVersion.Patch);
71 Assert.Equal(4u, parsedVersion.Revision);
72 Assert.Equal(5, parsedVersion.ReleaseLabels.Length);
73 Assert.Equal("+abc123", parsedVersion.Metadata);
74 Assert.True(parsedVersion.IsInvalid);
75
76 Assert.Equal("a", parsedVersion.ReleaseLabels[0].Label);
77 Assert.False(parsedVersion.ReleaseLabels[0].IsNumeric);
78
79 Assert.Equal("b", parsedVersion.ReleaseLabels[1].Label);
80 Assert.False(parsedVersion.ReleaseLabels[1].IsNumeric);
81
82 Assert.Equal("c", parsedVersion.ReleaseLabels[2].Label);
83 Assert.False(parsedVersion.ReleaseLabels[2].IsNumeric);
84
85 Assert.Equal("d", parsedVersion.ReleaseLabels[3].Label);
86 Assert.False(parsedVersion.ReleaseLabels[3].IsNumeric);
87
88 Assert.Equal("5", parsedVersion.ReleaseLabels[4].Label);
89 Assert.True(parsedVersion.ReleaseLabels[4].IsNumeric);
90 Assert.Equal(5u, parsedVersion.ReleaseLabels[4].Value);
91 }
92 }
93}
diff --git a/src/api/burn/test/WixToolsetTest.Mba.Core/WixToolsetTest.Mba.Core.csproj b/src/api/burn/test/WixToolsetTest.Mba.Core/WixToolsetTest.Mba.Core.csproj
new file mode 100644
index 00000000..53d82f7e
--- /dev/null
+++ b/src/api/burn/test/WixToolsetTest.Mba.Core/WixToolsetTest.Mba.Core.csproj
@@ -0,0 +1,21 @@
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>netcoreapp3.1</TargetFramework>
7 <IsPackable>false</IsPackable>
8 <RuntimeIdentifier>win-x86</RuntimeIdentifier>
9 <SignOutput>false</SignOutput>
10 </PropertyGroup>
11
12 <ItemGroup>
13 <ProjectReference Include="..\..\WixToolset.Mba.Core\WixToolset.Mba.Core.csproj" />
14 </ItemGroup>
15
16 <ItemGroup>
17 <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.3.0" />
18 <PackageReference Include="xunit" Version="2.4.1" />
19 <PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" PrivateAssets="All" />
20 </ItemGroup>
21</Project>
diff --git a/src/api/burn/test/WixToolsetTest.Mba.Core/WixToolsetTest.Mba.Core.v3.ncrunchproject b/src/api/burn/test/WixToolsetTest.Mba.Core/WixToolsetTest.Mba.Core.v3.ncrunchproject
new file mode 100644
index 00000000..7b5b2139
--- /dev/null
+++ b/src/api/burn/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