Add WPF .NET Core test.
Sean Hall committed
Apr 29, 2020 at 19:36 UTC
ae1751902076edfd8978b7fb42f24d3ac3f7ad55
19 files changed
+400
-13
Bal.wixext.sln
+16
-1
@@ -13,7 +13,7 @@ Project("{930C7802-8A8C-48F9-8165-68863BCCD9DD}") = "bal", "src\wixlib\bal.wixpr
13
EndProject
14
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WixToolset.Bal.wixext", "src\wixext\WixToolset.Bal.wixext.csproj", "{BF720A63-9D7B-456E-B60C-8122852D9FED}"
15
EndProject
16
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WixToolset.Dnc.Host", "src\WixToolset.Dnc.Host\WixToolset.Dnc.Host.csproj", "{0D780900-C2FF-4FA2-8CB5-8A19768724C5}"
16
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WixToolset.Dnc.Host", "src\WixToolset.Dnc.Host\WixToolset.Dnc.Host.csproj", "{0D780900-C2FF-4FA2-8CB5-8A19768724C5}"
17
EndProject
18
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WixToolset.Mba.Host", "src\WixToolset.Mba.Host\WixToolset.Mba.Host.csproj", "{F2BA1935-70FA-4156-B161-FD03850B4FAA}"
19
EndProject
@@ -35,6 +35,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "dnchost", "src\dnchost\dnch
35
EndProject
36
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Example.LatestCoreMBA", "src\test\examples\LatestCoreMBA\Example.LatestCoreMBA.csproj", "{A4247D9D-3CC9-4BE1-B23A-BEC166AF3618}"
37
EndProject
38
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Example.WPFCoreMBA", "src\test\examples\WPFCoreMBA\Example.WPFCoreMBA.csproj", "{8E707BF2-FD72-4649-8727-BA5955D48D40}"
39
+EndProject
40
Global
41
GlobalSection(SolutionConfigurationPlatforms) = preSolution
42
Debug|Any CPU = Debug|Any CPU
@@ -215,6 +217,18 @@ Global
217
{A4247D9D-3CC9-4BE1-B23A-BEC166AF3618}.Release|x64.Build.0 = Release|Any CPU
218
{A4247D9D-3CC9-4BE1-B23A-BEC166AF3618}.Release|x86.ActiveCfg = Release|Any CPU
219
{A4247D9D-3CC9-4BE1-B23A-BEC166AF3618}.Release|x86.Build.0 = Release|Any CPU
220
+ {8E707BF2-FD72-4649-8727-BA5955D48D40}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
221
+ {8E707BF2-FD72-4649-8727-BA5955D48D40}.Debug|Any CPU.Build.0 = Debug|Any CPU
222
+ {8E707BF2-FD72-4649-8727-BA5955D48D40}.Debug|x64.ActiveCfg = Debug|Any CPU
223
+ {8E707BF2-FD72-4649-8727-BA5955D48D40}.Debug|x64.Build.0 = Debug|Any CPU
224
+ {8E707BF2-FD72-4649-8727-BA5955D48D40}.Debug|x86.ActiveCfg = Debug|Any CPU
225
+ {8E707BF2-FD72-4649-8727-BA5955D48D40}.Debug|x86.Build.0 = Debug|Any CPU
226
+ {8E707BF2-FD72-4649-8727-BA5955D48D40}.Release|Any CPU.ActiveCfg = Release|Any CPU
227
+ {8E707BF2-FD72-4649-8727-BA5955D48D40}.Release|Any CPU.Build.0 = Release|Any CPU
228
+ {8E707BF2-FD72-4649-8727-BA5955D48D40}.Release|x64.ActiveCfg = Release|Any CPU
229
+ {8E707BF2-FD72-4649-8727-BA5955D48D40}.Release|x64.Build.0 = Release|Any CPU
230
+ {8E707BF2-FD72-4649-8727-BA5955D48D40}.Release|x86.ActiveCfg = Release|Any CPU
231
+ {8E707BF2-FD72-4649-8727-BA5955D48D40}.Release|x86.Build.0 = Release|Any CPU
232
EndGlobalSection
233
GlobalSection(SolutionProperties) = preSolution
234
HideSolutionNode = FALSE
@@ -225,6 +239,7 @@ Global
239
{44297646-706D-4508-8E96-1B35B109694C} = {C70E3534-A018-4D0A-A340-916C9777EEF7}
240
{1E86D8DF-DABD-4B6E-A812-64CD2040C73A} = {C70E3534-A018-4D0A-A340-916C9777EEF7}
241
{A4247D9D-3CC9-4BE1-B23A-BEC166AF3618} = {C70E3534-A018-4D0A-A340-916C9777EEF7}
242
+ {8E707BF2-FD72-4649-8727-BA5955D48D40} = {C70E3534-A018-4D0A-A340-916C9777EEF7}
243
EndGlobalSection
244
GlobalSection(ExtensibilityGlobals) = postSolution
245
SolutionGuid = {74046961-48BF-467A-A6C2-F886C75CE0BE}
src/test/WixToolsetTest.ManagedHost/DncHostFixture.cs
+34
@@ -335,5 +335,39 @@ namespace WixToolsetTest.ManagedHost
335
Assert.Equal("Shutdown,Restart,0", logMessages[8]);
336
}
337
}
338
+
339
+ [Fact]
340
+ public void CanLoadFDDWPFCoreMBA()
341
+ {
342
+ using (var fs = new DisposableFileSystem())
343
+ {
344
+ var baseFolder = fs.GetFolder();
345
+ var binFolder = Path.Combine(baseFolder, "bin");
346
+ var bundleFile = Path.Combine(binFolder, "FDDWPFCoreMBA.exe");
347
+ var baSourceFolder = TestData.Get(@"..\examples");
348
+ var bundleSourceFolder = TestData.Get(@"TestData\WPFCoreMBA");
349
+ var intermediateFolder = Path.Combine(baseFolder, "obj");
350
+
351
+ var compileResult = WixRunner.Execute(new[]
352
+ {
353
+ "build",
354
+ Path.Combine(bundleSourceFolder, "FrameworkDependentBundle.wxs"),
355
+ "-ext", TestData.Get(@"WixToolset.Bal.wixext.dll"),
356
+ "-intermediateFolder", intermediateFolder,
357
+ "-bindpath", baSourceFolder,
358
+ "-burnStub", TestEngine.BurnStubFile,
359
+ "-o", bundleFile,
360
+ });
361
+ compileResult.AssertSuccess();
362
+ var testEngine = new TestEngine();
363
+
364
+ var result = testEngine.RunShutdownEngine(bundleFile, baseFolder);
365
+ var logMessages = result.Output;
366
+ Assert.Equal("Loading .NET Core FDD bootstrapper application.", logMessages[0]);
367
+ Assert.Equal("Creating BA thread to run asynchronously.", logMessages[1]);
368
+ Assert.Equal("WPFCoreBA", logMessages[2]);
369
+ Assert.Equal("Shutdown,ReloadBootstrapper,0", logMessages[3]);
370
+ }
371
+ }
372
}
373
}
src/test/WixToolsetTest.ManagedHost/TestData/WPFCoreMBA/FrameworkDependentBundle.wxs
new
+17
@@ -0,0 +1,17 @@
1
+<?xml version="1.0" encoding="utf-8"?>
2
+<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs"
3
+ xmlns:bal="http://wixtoolset.org/schemas/v4/wxs/bal">
4
+ <Bundle Name="FDDWPFCoreMBA" Version="1.0.0.0" Manufacturer="Example Corporation" UpgradeCode="5CE5B5C7-4B6B-4B95-B297-731F1F956533">
5
+ <BootstrapperApplicationRef Id="DotNetCoreBootstrapperApplicationHost">
6
+ <Payload SourceFile='publish\Example.WPFCoreMBA\fdd\Example.WPFCoreMBA.deps.json' Name='Example.WPFCoreMBA.deps.json' />
7
+ <Payload SourceFile='publish\Example.WPFCoreMBA\fdd\Example.WPFCoreMBA.dll' Name='Example.WPFCoreMBA.dll' bal:BAFactoryAssembly='yes' />
8
+ <Payload SourceFile='publish\Example.WPFCoreMBA\fdd\Example.WPFCoreMBA.pdb' Name='Example.WPFCoreMBA.pdb' />
9
+ <Payload SourceFile='publish\Example.WPFCoreMBA\fdd\Example.WPFCoreMBA.runtimeconfig.json' Name='Example.WPFCoreMBA.runtimeconfig.json' />
10
+ <Payload SourceFile='publish\Example.WPFCoreMBA\fdd\mbanative.dll' Name='mbanative.dll' />
11
+ <Payload SourceFile='publish\Example.WPFCoreMBA\fdd\WixToolset.Mba.Core.dll' Name='WixToolset.Mba.Core.dll' />
12
+ </BootstrapperApplicationRef>
13
+ <Chain>
14
+ <ExePackage SourceFile="c:\windows\system32\kernel32.dll" bal:PrereqPackage="yes" />
15
+ </Chain>
16
+ </Bundle>
17
+</Wix>
src/test/WixToolsetTest.ManagedHost/WixToolsetTest.ManagedHost.csproj
+14
-3
@@ -14,6 +14,7 @@
14
<PropertyGroup>
15
<EarliestCoreMBAProjectPath>..\examples\EarliestCoreMBA\Example.EarliestCoreMBA.csproj</EarliestCoreMBAProjectPath>
16
<LatestCoreMBAProjectPath>..\examples\LatestCoreMBA\Example.LatestCoreMBA.csproj</LatestCoreMBAProjectPath>
17
+ <WPFCoreMBAProjectPath>..\examples\WPFCoreMBA\Example.WPFCoreMBA.csproj</WPFCoreMBAProjectPath>
18
<MBAPublishPath>$(OutputPath)examples\publish\</MBAPublishPath>
19
</PropertyGroup>
20
@@ -30,6 +31,7 @@
31
<Content Include="TestData\LatestCoreMBA\HarvestedTrimmedSCD.wxs" CopyToOutputDirectory="PreserveNewest"/>
32
<Content Include="TestData\LatestCoreMBA\SelfContainedBundle.wxs" CopyToOutputDirectory="PreserveNewest"/>
33
<Content Include="TestData\LatestCoreMBA\TrimmedSelfContainedBundle.wxs" CopyToOutputDirectory="PreserveNewest"/>
34
+ <Content Include="TestData\WPFCoreMBA\FrameworkDependentBundle.wxs" CopyToOutputDirectory="PreserveNewest"/>
35
</ItemGroup>
36
37
<Target Name="CopyExtensions" AfterTargets="Build">
@@ -43,11 +45,17 @@
45
<CoreMBAProject Include="$(LatestCoreMBAProjectPath)">
46
<PublishPath>$(MBAPublishPath)Example.LatestCoreMBA</PublishPath>
47
</CoreMBAProject>
48
+ <CoreMBAProject Include="$(WPFCoreMBAProjectPath)">
49
+ <PublishPath>$(MBAPublishPath)Example.WPFCoreMBA</PublishPath>
50
+ <SkipSCD>true</SkipSCD>
51
+ <SkipTrimmedSCD>true</SkipTrimmedSCD>
52
+ </CoreMBAProject>
53
</ItemGroup>
54
55
<ItemGroup>
56
<ProjectReference Include="$(EarliestCoreMBAProjectPath)" />
57
<ProjectReference Include="$(LatestCoreMBAProjectPath)" />
58
+ <ProjectReference Include="$(WPFCoreMBAProjectPath)" />
59
<ProjectReference Include="..\examples\FullFramework2MBA\Example.FullFramework2MBA.csproj" />
60
<ProjectReference Include="..\examples\FullFramework4MBA\Example.FullFramework4MBA.csproj" />
61
<ProjectReference Include="..\examples\TestEngine\Example.TestEngine.vcxproj" />
@@ -69,8 +77,11 @@
77
</ItemGroup>
78
79
<Target Name="PublishExamples" AfterTargets="Build">
72
- <Exec Command='dotnet publish -o "%(CoreMBAProject.PublishPath)\fdd" -r win-x86 -c $(Configuration) --self-contained false "%(CoreMBAProject.Identity)"' />
73
- <Exec Command='dotnet publish -o "%(CoreMBAProject.PublishPath)\scd" -r win-x86 -c $(Configuration) --self-contained true "%(CoreMBAProject.Identity)"' />
74
- <Exec Command='dotnet publish -o "%(CoreMBAProject.PublishPath)\trimmedscd" -r win-x86 -c $(Configuration) --self-contained true -p:PublishTrimmed=true "%(CoreMBAProject.Identity)"' />
80
+ <Exec Command='dotnet publish -o "%(CoreMBAProject.PublishPath)\fdd" -r win-x86 -c $(Configuration) --self-contained false "%(CoreMBAProject.Identity)"'
81
+ Condition="'%(CoreMBAProject.SkipFDD)'==''" />
82
+ <Exec Command='dotnet publish -o "%(CoreMBAProject.PublishPath)\scd" -r win-x86 -c $(Configuration) --self-contained true "%(CoreMBAProject.Identity)"'
83
+ Condition="'%(CoreMBAProject.SkipSCD)'==''" />
84
+ <Exec Command='dotnet publish -o "%(CoreMBAProject.PublishPath)\trimmedscd" -r win-x86 -c $(Configuration) --self-contained true -p:PublishTrimmed=true "%(CoreMBAProject.Identity)"'
85
+ Condition="'%(CoreMBAProject.SkipTrimmedSCD)'==''" />
86
</Target>
87
</Project>
src/test/examples/TestEngine/Example.TestEngine.vcxproj
+2
@@ -50,12 +50,14 @@
50
<ClCompile Include="ShutdownEngine.cpp" />
51
<ClCompile Include="ExampleTestEngine.cpp" />
52
<ClCompile Include="TestEngine.cpp" />
53
+ <ClCompile Include="WaitForQuitEngine.cpp" />
54
</ItemGroup>
55
<ItemGroup>
56
<ClInclude Include="precomp.h" />
57
<ClInclude Include="ReloadEngine.h" />
58
<ClInclude Include="ShutdownEngine.h" />
59
<ClInclude Include="TestEngine.h" />
60
+ <ClInclude Include="WaitForQuitEngine.h" />
61
</ItemGroup>
62
<ItemGroup>
63
<None Include="packages.config" />
src/test/examples/TestEngine/ExampleTestEngine.cpp
+19
-2
@@ -4,9 +4,15 @@
4
5
int __cdecl wmain(int argc, LPWSTR argv[])
6
{
7
- HRESULT hr = E_INVALIDARG;
7
+ HRESULT hr = S_OK;
8
+ BOOL fComInitialized = FALSE;
9
BOOL fShowUsage = FALSE;
10
11
+ // initialize COM
12
+ hr = ::CoInitializeEx(NULL, COINIT_MULTITHREADED);
13
+ ExitOnFailure(hr, "Failed to initialize COM.");
14
+ fComInitialized = TRUE;
15
+
16
ConsoleInitialize();
17
18
if (argc != 4)
@@ -21,6 +27,10 @@ int __cdecl wmain(int argc, LPWSTR argv[])
27
{
28
hr = RunShutdownEngine(argv[2], argv[3]);
29
}
30
+ else if (CSTR_EQUAL == ::CompareString(LOCALE_INVARIANT, NORM_IGNORECASE, argv[1], -1, L"waitforquit", -1))
31
+ {
32
+ hr = RunWaitForQuitEngine(argv[2], argv[3]);
33
+ }
34
else
35
{
36
fShowUsage = TRUE;
@@ -28,9 +38,16 @@ int __cdecl wmain(int argc, LPWSTR argv[])
38
39
if (fShowUsage)
40
{
31
- ConsoleWriteError(hr, CONSOLE_COLOR_RED, "Usage: {reload|shutdown} Example.TestEngine.exe Bundle.exe BA.dll");
41
+ ConsoleWriteError(hr = E_INVALIDARG, CONSOLE_COLOR_RED, "Usage: Example.TestEngine.exe {reload|shutdown|waitforquit} Bundle.exe BA.dll");
42
}
43
44
ConsoleUninitialize();
45
+
46
+LExit:
47
+ if (fComInitialized)
48
+ {
49
+ ::CoUninitialize();
50
+ }
51
+
52
return hr;
53
}
src/test/examples/TestEngine/ReloadEngine.cpp
+12
@@ -22,6 +22,12 @@ HRESULT RunReloadEngine(
22
hr = pTestEngine->SendStartupEvent();
23
ConsoleExitOnFailure(hr, CONSOLE_COLOR_RED, "BA returned failure for OnStartup.");
24
25
+ hr = pTestEngine->SimulateQuit(0);
26
+ ConsoleExitOnFailure(hr, CONSOLE_COLOR_RED, "Failed to simulate quit.");
27
+
28
+ hr = pTestEngine->RunApplication();
29
+ ConsoleExitOnFailure(hr, CONSOLE_COLOR_RED, "Failed to run engine.");
30
+
31
hr = pTestEngine->SendShutdownEvent(BOOTSTRAPPER_SHUTDOWN_ACTION_RELOAD_BOOTSTRAPPER);
32
ConsoleExitOnFailure(hr, CONSOLE_COLOR_RED, "BA returned failure for OnShutdown.");
33
@@ -33,6 +39,12 @@ HRESULT RunReloadEngine(
39
hr = pTestEngine->SendStartupEvent();
40
ConsoleExitOnFailure(hr, CONSOLE_COLOR_RED, "BA returned failure for OnStartup.");
41
42
+ hr = pTestEngine->SimulateQuit(0);
43
+ ConsoleExitOnFailure(hr, CONSOLE_COLOR_RED, "Failed to simulate quit.");
44
+
45
+ hr = pTestEngine->RunApplication();
46
+ ConsoleExitOnFailure(hr, CONSOLE_COLOR_RED, "Failed to run engine.");
47
+
48
hr = pTestEngine->SendShutdownEvent(BOOTSTRAPPER_SHUTDOWN_ACTION_RESTART);
49
ConsoleExitOnFailure(hr, CONSOLE_COLOR_RED, "BA returned failure for OnShutdown.");
50
src/test/examples/TestEngine/ShutdownEngine.cpp
+6
@@ -22,6 +22,12 @@ HRESULT RunShutdownEngine(
22
hr = pTestEngine->SendStartupEvent();
23
ConsoleExitOnFailure(hr, CONSOLE_COLOR_RED, "BA returned failure for OnStartup.");
24
25
+ hr = pTestEngine->SimulateQuit(0);
26
+ ConsoleExitOnFailure(hr, CONSOLE_COLOR_RED, "Failed to simulate quit.");
27
+
28
+ hr = pTestEngine->RunApplication();
29
+ ConsoleExitOnFailure(hr, CONSOLE_COLOR_RED, "Failed to run engine.");
30
+
31
hr = pTestEngine->SendShutdownEvent(BOOTSTRAPPER_SHUTDOWN_ACTION_RELOAD_BOOTSTRAPPER);
32
ConsoleExitOnFailure(hr, CONSOLE_COLOR_RED, "BA returned failure for OnShutdown.");
33
src/test/examples/TestEngine/TestEngine.cpp
+79
-4
@@ -7,12 +7,15 @@ HRESULT TestEngine::Initialize(
7
)
8
{
9
HRESULT hr = S_OK;
10
+ MSG msg = { };
11
12
LogInitialize(::GetModuleHandleW(NULL));
13
14
hr = LogOpen(NULL, PathFile(wzBundleFilePath), NULL, L"txt", FALSE, FALSE, NULL);
15
ConsoleExitOnFailure(hr, CONSOLE_COLOR_RED, "Failed to open log.");
16
17
+ ::PeekMessageW(&msg, NULL, WM_USER, WM_USER, PM_NOREMOVE);
18
+
19
LExit:
20
return hr;
21
}
@@ -73,6 +76,29 @@ HRESULT TestEngine::Log(
76
return ConsoleWriteLine(CONSOLE_COLOR_NORMAL, "%ls", wzMessage);
77
}
78
79
+HRESULT TestEngine::RunApplication()
80
+{
81
+ HRESULT hr = S_OK;
82
+ MSG msg = { };
83
+ BOOL fRet = FALSE;
84
+
85
+ // Enter the message pump.
86
+ while (0 != (fRet = ::GetMessageW(&msg, NULL, 0, 0)))
87
+ {
88
+ if (-1 == fRet)
89
+ {
90
+ ConsoleExitOnFailure(hr = E_UNEXPECTED, CONSOLE_COLOR_RED, "Unexpected return value from message pump.");
91
+ }
92
+ else
93
+ {
94
+ ProcessBAMessage(&msg);
95
+ }
96
+ }
97
+
98
+LExit:
99
+ return hr;
100
+}
101
+
102
HRESULT TestEngine::SendShutdownEvent(
103
__in BOOTSTRAPPER_SHUTDOWN_ACTION defaultAction
104
)
@@ -98,6 +124,21 @@ HRESULT TestEngine::SendStartupEvent()
124
return hr;
125
}
126
127
+HRESULT TestEngine::SimulateQuit(
128
+ __in DWORD dwExitCode
129
+ )
130
+{
131
+ BAENGINE_QUIT_ARGS args = { };
132
+ BAENGINE_QUIT_RESULTS results = { };
133
+
134
+ args.cbSize = sizeof(BAENGINE_QUIT_ARGS);
135
+ args.dwExitCode = dwExitCode;
136
+
137
+ results.cbSize = sizeof(BAENGINE_QUIT_RESULTS);
138
+
139
+ return BAEngineQuit(&args, &results);
140
+}
141
+
142
void TestEngine::UnloadBA()
143
{
144
PFN_BOOTSTRAPPER_APPLICATION_DESTROY pfnDestroy = NULL;
@@ -124,12 +165,27 @@ void TestEngine::UnloadBA()
165
}
166
167
HRESULT TestEngine::BAEngineLog(
127
- __in TestEngine* pContext,
168
__in BAENGINE_LOG_ARGS* pArgs,
169
__in BAENGINE_LOG_RESULTS* /*pResults*/
170
)
171
{
132
- return pContext->Log(pArgs->wzMessage);
172
+ return Log(pArgs->wzMessage);
173
+}
174
+
175
+HRESULT TestEngine::BAEngineQuit(
176
+ __in BAENGINE_QUIT_ARGS* pArgs,
177
+ __in BAENGINE_QUIT_RESULTS* /*pResults*/
178
+ )
179
+{
180
+ HRESULT hr = S_OK;
181
+
182
+ if (!::PostThreadMessageW(m_dwThreadId, WM_TESTENG_QUIT, static_cast<WPARAM>(pArgs->dwExitCode), 0))
183
+ {
184
+ ExitWithLastError(hr, "Failed to post shutdown message.");
185
+ }
186
+
187
+LExit:
188
+ return hr;
189
}
190
191
HRESULT WINAPI TestEngine::EngineProc(
@@ -150,8 +206,10 @@ HRESULT WINAPI TestEngine::EngineProc(
206
switch (message)
207
{
208
case BOOTSTRAPPER_ENGINE_MESSAGE_LOG:
153
- hr = BAEngineLog(pContext, reinterpret_cast<BAENGINE_LOG_ARGS*>(pvArgs), reinterpret_cast<BAENGINE_LOG_RESULTS*>(pvResults));
209
+ hr = pContext->BAEngineLog(reinterpret_cast<BAENGINE_LOG_ARGS*>(pvArgs), reinterpret_cast<BAENGINE_LOG_RESULTS*>(pvResults));
210
break;
211
+ case BOOTSTRAPPER_ENGINE_MESSAGE_QUIT:
212
+ hr = pContext->BAEngineQuit(reinterpret_cast<BAENGINE_QUIT_ARGS*>(pvArgs), reinterpret_cast<BAENGINE_QUIT_RESULTS*>(pvResults));
213
default:
214
hr = E_NOTIMPL;
215
break;
@@ -161,13 +219,30 @@ LExit:
219
return hr;
220
}
221
222
+HRESULT TestEngine::ProcessBAMessage(
223
+ __in const MSG* pmsg
224
+ )
225
+{
226
+ HRESULT hr = S_OK;
227
+
228
+ switch (pmsg->message)
229
+ {
230
+ case WM_TESTENG_QUIT:
231
+ ::PostQuitMessage(static_cast<int>(pmsg->wParam)); // go bye-bye.
232
+ break;
233
+ }
234
+
235
+ return hr;
236
+}
237
+
238
TestEngine::TestEngine()
239
{
240
m_hBAModule = NULL;
241
m_pCreateResults = NULL;
242
+ m_dwThreadId = ::GetCurrentThreadId();
243
}
244
245
TestEngine::~TestEngine()
246
{
247
ReleaseMem(m_pCreateResults);
173
-}
\ No newline at end of file
248
+}
src/test/examples/TestEngine/TestEngine.h
+32
-3
@@ -2,6 +2,20 @@
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
5
+enum WM_TESTENG
6
+{
7
+ WM_TESTENG_FIRST = WM_APP + 0xFFF, // this enum value must always be first.
8
+
9
+ WM_TESTENG_DETECT,
10
+ WM_TESTENG_PLAN,
11
+ WM_TESTENG_ELEVATE,
12
+ WM_TESTENG_APPLY,
13
+ WM_TESTENG_LAUNCH_APPROVED_EXE,
14
+ WM_TESTENG_QUIT,
15
+
16
+ WM_TESTENG_LAST, // this enum value must always be last.
17
+};
18
+
19
class TestEngine
20
{
21
public:
@@ -17,19 +31,29 @@ public:
31
__in LPCWSTR wzMessage
32
);
33
34
+ HRESULT RunApplication();
35
+
36
HRESULT SendShutdownEvent(
37
__in BOOTSTRAPPER_SHUTDOWN_ACTION defaultAction
38
);
39
40
HRESULT SendStartupEvent();
41
42
+ HRESULT SimulateQuit(
43
+ __in DWORD dwExitCode
44
+ );
45
+
46
void UnloadBA();
47
48
private:
29
- static HRESULT BAEngineLog(
30
- __in TestEngine* pContext,
49
+ HRESULT BAEngineLog(
50
__in BAENGINE_LOG_ARGS* pArgs,
32
- __in BAENGINE_LOG_RESULTS* /*pResults*/
51
+ __in BAENGINE_LOG_RESULTS* pResults
52
+ );
53
+
54
+ HRESULT BAEngineQuit(
55
+ __in BAENGINE_QUIT_ARGS* pArgs,
56
+ __in BAENGINE_QUIT_RESULTS* pResults
57
);
58
59
static HRESULT WINAPI EngineProc(
@@ -39,6 +63,10 @@ private:
63
__in_opt LPVOID pvContext
64
);
65
66
+ HRESULT ProcessBAMessage(
67
+ __in const MSG* pmsg
68
+ );
69
+
70
public:
71
TestEngine();
72
@@ -47,4 +75,5 @@ public:
75
private:
76
HMODULE m_hBAModule;
77
BOOTSTRAPPER_CREATE_RESULTS* m_pCreateResults;
78
+ DWORD m_dwThreadId;
79
};
\ No newline at end of file
src/test/examples/TestEngine/WaitForQuitEngine.cpp
new
+35
@@ -0,0 +1,35 @@
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
+#include "precomp.h"
4
+
5
+HRESULT RunWaitForQuitEngine(
6
+ __in LPCWSTR wzBundleFilePath,
7
+ __in LPCWSTR wzBAFilePath
8
+ )
9
+{
10
+ HRESULT hr = S_OK;
11
+ TestEngine* pTestEngine = NULL;
12
+
13
+ pTestEngine = new TestEngine();
14
+ ConsoleExitOnNull(pTestEngine, hr, E_OUTOFMEMORY, CONSOLE_COLOR_RED, "Failed to create new test engine.");
15
+
16
+ hr = pTestEngine->Initialize(wzBundleFilePath);
17
+ ConsoleExitOnFailure(hr, CONSOLE_COLOR_RED, "Failed to initialize engine.");
18
+
19
+ hr = pTestEngine->LoadBA(wzBAFilePath);
20
+ ConsoleExitOnFailure(hr, CONSOLE_COLOR_RED, "Failed to load BA.");
21
+
22
+ hr = pTestEngine->SendStartupEvent();
23
+ ConsoleExitOnFailure(hr, CONSOLE_COLOR_RED, "BA returned failure for OnStartup.");
24
+
25
+ hr = pTestEngine->RunApplication();
26
+ ConsoleExitOnFailure(hr, CONSOLE_COLOR_RED, "Failed to run engine.");
27
+
28
+ hr = pTestEngine->SendShutdownEvent(BOOTSTRAPPER_SHUTDOWN_ACTION_RELOAD_BOOTSTRAPPER);
29
+ ConsoleExitOnFailure(hr, CONSOLE_COLOR_RED, "BA returned failure for OnShutdown.");
30
+
31
+ pTestEngine->UnloadBA();
32
+
33
+LExit:
34
+ return hr;
35
+}
src/test/examples/TestEngine/WaitForQuitEngine.h
new
+8
@@ -0,0 +1,8 @@
1
+#pragma once
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
+
5
+HRESULT RunWaitForQuitEngine(
6
+ __in LPCWSTR wzBundleFilePath,
7
+ __in LPCWSTR wzBAFilePath
8
+ );
src/test/examples/TestEngine/precomp.h
+1
@@ -17,3 +17,4 @@
17
#include "TestEngine.h"
18
#include "ReloadEngine.h"
19
#include "ShutdownEngine.h"
20
+#include "WaitForQuitEngine.h"
src/test/examples/WPFCoreMBA/AssemblyInfo.cs
new
+12
@@ -0,0 +1,12 @@
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
+using System.Windows;
4
+
5
+[assembly:ThemeInfo(
6
+ ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
7
+ //(used if a resource is not found in the page,
8
+ // or application resource dictionaries)
9
+ ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
10
+ //(used if a resource is not found in the page,
11
+ // app, or any theme specific resource dictionaries)
12
+)]
src/test/examples/WPFCoreMBA/Example.WPFCoreMBA.csproj
new
+16
@@ -0,0 +1,16 @@
1
+<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
2
+
3
+ <PropertyGroup>
4
+ <TargetFramework>netcoreapp3.1</TargetFramework>
5
+ <RuntimeIdentifiers>win-x86;win-x64</RuntimeIdentifiers>
6
+ <EnableDynamicLoading>true</EnableDynamicLoading>
7
+ <Description>WPF .NET Core MBA</Description>
8
+ <UseWPF>true</UseWPF>
9
+ </PropertyGroup>
10
+
11
+
12
+ <ItemGroup>
13
+ <PackageReference Include="Nerdbank.GitVersioning" Version="2.1.65" PrivateAssets="all" />
14
+ <PackageReference Include="WixToolset.Mba.Core" Version="4.0.19" />
15
+ </ItemGroup>
16
+</Project>
\ No newline at end of file
src/test/examples/WPFCoreMBA/MainWindow.xaml
new
+16
@@ -0,0 +1,16 @@
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
+
5
+<Window x:Class="Example.WPFCoreMBA.MainWindow"
6
+ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
7
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
8
+ xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
9
+ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
10
+ xmlns:local="clr-namespace:Example.WPFCoreMBA"
11
+ mc:Ignorable="d"
12
+ Title="MainWindow" Height="450" Width="800">
13
+ <Grid>
14
+
15
+ </Grid>
16
+</Window>
src/test/examples/WPFCoreMBA/MainWindow.xaml.cs
new
+17
@@ -0,0 +1,17 @@
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 Example.WPFCoreMBA
4
+{
5
+ using System.Windows;
6
+
7
+ /// <summary>
8
+ /// Interaction logic for MainWindow.xaml
9
+ /// </summary>
10
+ public partial class MainWindow : Window
11
+ {
12
+ public MainWindow()
13
+ {
14
+ this.InitializeComponent();
15
+ }
16
+ }
17
+}
src/test/examples/WPFCoreMBA/WPFCoreBA.cs
new
+42
@@ -0,0 +1,42 @@
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 Example.WPFCoreMBA
4
+{
5
+ using System.Windows.Threading;
6
+ using WixToolset.Mba.Core;
7
+
8
+ public class WPFCoreBA : BootstrapperApplication
9
+ {
10
+ public WPFCoreBA(IEngine engine)
11
+ : base(engine)
12
+ {
13
+ }
14
+
15
+ public Dispatcher BADispatcher { get; private set; }
16
+
17
+ protected override void Run()
18
+ {
19
+ this.BADispatcher = Dispatcher.CurrentDispatcher;
20
+ var window = new MainWindow();
21
+ window.Closed += (s, e) => this.BADispatcher.InvokeShutdown();
22
+ //window.Show();
23
+ //Dispatcher.Run();
24
+ //this.engine.Quit(0);
25
+ }
26
+
27
+ protected override void OnStartup(StartupEventArgs args)
28
+ {
29
+ base.OnStartup(args);
30
+
31
+ this.engine.Log(LogLevel.Standard, nameof(WPFCoreBA));
32
+ }
33
+
34
+ protected override void OnShutdown(ShutdownEventArgs args)
35
+ {
36
+ base.OnShutdown(args);
37
+
38
+ var message = "Shutdown," + args.Action.ToString() + "," + args.HResult.ToString();
39
+ this.engine.Log(LogLevel.Standard, message);
40
+ }
41
+ }
42
+}
src/test/examples/WPFCoreMBA/WPFCoreBAFactory.cs
new
+22
@@ -0,0 +1,22 @@
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
+[assembly: WixToolset.Mba.Core.BootstrapperApplicationFactory(typeof(Example.WPFCoreMBA.WPFCoreBAFactory))]
4
+namespace Example.WPFCoreMBA
5
+{
6
+ using WixToolset.Mba.Core;
7
+
8
+ public class WPFCoreBAFactory : BaseBootstrapperApplicationFactory
9
+ {
10
+ private static int loadCount = 0;
11
+
12
+ protected override IBootstrapperApplication Create(IEngine engine, IBootstrapperCommand bootstrapperCommand)
13
+ {
14
+ if (loadCount > 0)
15
+ {
16
+ engine.Log(LogLevel.Standard, $"Reloaded {loadCount} time(s)");
17
+ }
18
+ ++loadCount;
19
+ return new WPFCoreBA(engine);
20
+ }
21
+ }
22
+}