aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSean Hall <r.sean.hall@gmail.com>2020-04-29 19:36:24 +1000
committerSean Hall <r.sean.hall@gmail.com>2020-04-29 19:53:29 +1000
commitae1751902076edfd8978b7fb42f24d3ac3f7ad55 (patch)
tree92011d854d8820cfd61136b7f6aa4378ba31b752 /src
parenta79ce0b907676e50332139b4c4a8acb5d22a4b46 (diff)
downloadwix-ae1751902076edfd8978b7fb42f24d3ac3f7ad55.tar.gz
wix-ae1751902076edfd8978b7fb42f24d3ac3f7ad55.tar.bz2
wix-ae1751902076edfd8978b7fb42f24d3ac3f7ad55.zip
Add WPF .NET Core test.
Diffstat (limited to 'src')
-rw-r--r--src/test/WixToolsetTest.ManagedHost/DncHostFixture.cs34
-rw-r--r--src/test/WixToolsetTest.ManagedHost/TestData/WPFCoreMBA/FrameworkDependentBundle.wxs17
-rw-r--r--src/test/WixToolsetTest.ManagedHost/WixToolsetTest.ManagedHost.csproj17
-rw-r--r--src/test/examples/TestEngine/Example.TestEngine.vcxproj2
-rw-r--r--src/test/examples/TestEngine/ExampleTestEngine.cpp21
-rw-r--r--src/test/examples/TestEngine/ReloadEngine.cpp12
-rw-r--r--src/test/examples/TestEngine/ShutdownEngine.cpp6
-rw-r--r--src/test/examples/TestEngine/TestEngine.cpp83
-rw-r--r--src/test/examples/TestEngine/TestEngine.h35
-rw-r--r--src/test/examples/TestEngine/WaitForQuitEngine.cpp35
-rw-r--r--src/test/examples/TestEngine/WaitForQuitEngine.h8
-rw-r--r--src/test/examples/TestEngine/precomp.h1
-rw-r--r--src/test/examples/WPFCoreMBA/AssemblyInfo.cs12
-rw-r--r--src/test/examples/WPFCoreMBA/Example.WPFCoreMBA.csproj16
-rw-r--r--src/test/examples/WPFCoreMBA/MainWindow.xaml16
-rw-r--r--src/test/examples/WPFCoreMBA/MainWindow.xaml.cs17
-rw-r--r--src/test/examples/WPFCoreMBA/WPFCoreBA.cs42
-rw-r--r--src/test/examples/WPFCoreMBA/WPFCoreBAFactory.cs22
18 files changed, 384 insertions, 12 deletions
diff --git a/src/test/WixToolsetTest.ManagedHost/DncHostFixture.cs b/src/test/WixToolsetTest.ManagedHost/DncHostFixture.cs
index 7f40ee26..f33709ab 100644
--- a/src/test/WixToolsetTest.ManagedHost/DncHostFixture.cs
+++ b/src/test/WixToolsetTest.ManagedHost/DncHostFixture.cs
@@ -335,5 +335,39 @@ namespace WixToolsetTest.ManagedHost
335 Assert.Equal("Shutdown,Restart,0", logMessages[8]); 335 Assert.Equal("Shutdown,Restart,0", logMessages[8]);
336 } 336 }
337 } 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 }
338 } 372 }
339} 373}
diff --git a/src/test/WixToolsetTest.ManagedHost/TestData/WPFCoreMBA/FrameworkDependentBundle.wxs b/src/test/WixToolsetTest.ManagedHost/TestData/WPFCoreMBA/FrameworkDependentBundle.wxs
new file mode 100644
index 00000000..ecc5e8c1
--- /dev/null
+++ b/src/test/WixToolsetTest.ManagedHost/TestData/WPFCoreMBA/FrameworkDependentBundle.wxs
@@ -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>
diff --git a/src/test/WixToolsetTest.ManagedHost/WixToolsetTest.ManagedHost.csproj b/src/test/WixToolsetTest.ManagedHost/WixToolsetTest.ManagedHost.csproj
index 958c63fc..ff472322 100644
--- a/src/test/WixToolsetTest.ManagedHost/WixToolsetTest.ManagedHost.csproj
+++ b/src/test/WixToolsetTest.ManagedHost/WixToolsetTest.ManagedHost.csproj
@@ -14,6 +14,7 @@
14 <PropertyGroup> 14 <PropertyGroup>
15 <EarliestCoreMBAProjectPath>..\examples\EarliestCoreMBA\Example.EarliestCoreMBA.csproj</EarliestCoreMBAProjectPath> 15 <EarliestCoreMBAProjectPath>..\examples\EarliestCoreMBA\Example.EarliestCoreMBA.csproj</EarliestCoreMBAProjectPath>
16 <LatestCoreMBAProjectPath>..\examples\LatestCoreMBA\Example.LatestCoreMBA.csproj</LatestCoreMBAProjectPath> 16 <LatestCoreMBAProjectPath>..\examples\LatestCoreMBA\Example.LatestCoreMBA.csproj</LatestCoreMBAProjectPath>
17 <WPFCoreMBAProjectPath>..\examples\WPFCoreMBA\Example.WPFCoreMBA.csproj</WPFCoreMBAProjectPath>
17 <MBAPublishPath>$(OutputPath)examples\publish\</MBAPublishPath> 18 <MBAPublishPath>$(OutputPath)examples\publish\</MBAPublishPath>
18 </PropertyGroup> 19 </PropertyGroup>
19 20
@@ -30,6 +31,7 @@
30 <Content Include="TestData\LatestCoreMBA\HarvestedTrimmedSCD.wxs" CopyToOutputDirectory="PreserveNewest"/> 31 <Content Include="TestData\LatestCoreMBA\HarvestedTrimmedSCD.wxs" CopyToOutputDirectory="PreserveNewest"/>
31 <Content Include="TestData\LatestCoreMBA\SelfContainedBundle.wxs" CopyToOutputDirectory="PreserveNewest"/> 32 <Content Include="TestData\LatestCoreMBA\SelfContainedBundle.wxs" CopyToOutputDirectory="PreserveNewest"/>
32 <Content Include="TestData\LatestCoreMBA\TrimmedSelfContainedBundle.wxs" CopyToOutputDirectory="PreserveNewest"/> 33 <Content Include="TestData\LatestCoreMBA\TrimmedSelfContainedBundle.wxs" CopyToOutputDirectory="PreserveNewest"/>
34 <Content Include="TestData\WPFCoreMBA\FrameworkDependentBundle.wxs" CopyToOutputDirectory="PreserveNewest"/>
33 </ItemGroup> 35 </ItemGroup>
34 36
35 <Target Name="CopyExtensions" AfterTargets="Build"> 37 <Target Name="CopyExtensions" AfterTargets="Build">
@@ -43,11 +45,17 @@
43 <CoreMBAProject Include="$(LatestCoreMBAProjectPath)"> 45 <CoreMBAProject Include="$(LatestCoreMBAProjectPath)">
44 <PublishPath>$(MBAPublishPath)Example.LatestCoreMBA</PublishPath> 46 <PublishPath>$(MBAPublishPath)Example.LatestCoreMBA</PublishPath>
45 </CoreMBAProject> 47 </CoreMBAProject>
48 <CoreMBAProject Include="$(WPFCoreMBAProjectPath)">
49 <PublishPath>$(MBAPublishPath)Example.WPFCoreMBA</PublishPath>
50 <SkipSCD>true</SkipSCD>
51 <SkipTrimmedSCD>true</SkipTrimmedSCD>
52 </CoreMBAProject>
46 </ItemGroup> 53 </ItemGroup>
47 54
48 <ItemGroup> 55 <ItemGroup>
49 <ProjectReference Include="$(EarliestCoreMBAProjectPath)" /> 56 <ProjectReference Include="$(EarliestCoreMBAProjectPath)" />
50 <ProjectReference Include="$(LatestCoreMBAProjectPath)" /> 57 <ProjectReference Include="$(LatestCoreMBAProjectPath)" />
58 <ProjectReference Include="$(WPFCoreMBAProjectPath)" />
51 <ProjectReference Include="..\examples\FullFramework2MBA\Example.FullFramework2MBA.csproj" /> 59 <ProjectReference Include="..\examples\FullFramework2MBA\Example.FullFramework2MBA.csproj" />
52 <ProjectReference Include="..\examples\FullFramework4MBA\Example.FullFramework4MBA.csproj" /> 60 <ProjectReference Include="..\examples\FullFramework4MBA\Example.FullFramework4MBA.csproj" />
53 <ProjectReference Include="..\examples\TestEngine\Example.TestEngine.vcxproj" /> 61 <ProjectReference Include="..\examples\TestEngine\Example.TestEngine.vcxproj" />
@@ -69,8 +77,11 @@
69 </ItemGroup> 77 </ItemGroup>
70 78
71 <Target Name="PublishExamples" AfterTargets="Build"> 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)"' /> 80 <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)"' /> 81 Condition="'%(CoreMBAProject.SkipFDD)'==''" />
74 <Exec Command='dotnet publish -o "%(CoreMBAProject.PublishPath)\trimmedscd" -r win-x86 -c $(Configuration) --self-contained true -p:PublishTrimmed=true "%(CoreMBAProject.Identity)"' /> 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)'==''" />
75 </Target> 86 </Target>
76</Project> 87</Project>
diff --git a/src/test/examples/TestEngine/Example.TestEngine.vcxproj b/src/test/examples/TestEngine/Example.TestEngine.vcxproj
index be52105b..b9425295 100644
--- a/src/test/examples/TestEngine/Example.TestEngine.vcxproj
+++ b/src/test/examples/TestEngine/Example.TestEngine.vcxproj
@@ -50,12 +50,14 @@
50 <ClCompile Include="ShutdownEngine.cpp" /> 50 <ClCompile Include="ShutdownEngine.cpp" />
51 <ClCompile Include="ExampleTestEngine.cpp" /> 51 <ClCompile Include="ExampleTestEngine.cpp" />
52 <ClCompile Include="TestEngine.cpp" /> 52 <ClCompile Include="TestEngine.cpp" />
53 <ClCompile Include="WaitForQuitEngine.cpp" />
53 </ItemGroup> 54 </ItemGroup>
54 <ItemGroup> 55 <ItemGroup>
55 <ClInclude Include="precomp.h" /> 56 <ClInclude Include="precomp.h" />
56 <ClInclude Include="ReloadEngine.h" /> 57 <ClInclude Include="ReloadEngine.h" />
57 <ClInclude Include="ShutdownEngine.h" /> 58 <ClInclude Include="ShutdownEngine.h" />
58 <ClInclude Include="TestEngine.h" /> 59 <ClInclude Include="TestEngine.h" />
60 <ClInclude Include="WaitForQuitEngine.h" />
59 </ItemGroup> 61 </ItemGroup>
60 <ItemGroup> 62 <ItemGroup>
61 <None Include="packages.config" /> 63 <None Include="packages.config" />
diff --git a/src/test/examples/TestEngine/ExampleTestEngine.cpp b/src/test/examples/TestEngine/ExampleTestEngine.cpp
index a378c9a3..fc1938fe 100644
--- a/src/test/examples/TestEngine/ExampleTestEngine.cpp
+++ b/src/test/examples/TestEngine/ExampleTestEngine.cpp
@@ -4,9 +4,15 @@
4 4
5int __cdecl wmain(int argc, LPWSTR argv[]) 5int __cdecl wmain(int argc, LPWSTR argv[])
6{ 6{
7 HRESULT hr = E_INVALIDARG; 7 HRESULT hr = S_OK;
8 BOOL fComInitialized = FALSE;
8 BOOL fShowUsage = FALSE; 9 BOOL fShowUsage = FALSE;
9 10
11 // initialize COM
12 hr = ::CoInitializeEx(NULL, COINIT_MULTITHREADED);
13 ExitOnFailure(hr, "Failed to initialize COM.");
14 fComInitialized = TRUE;
15
10 ConsoleInitialize(); 16 ConsoleInitialize();
11 17
12 if (argc != 4) 18 if (argc != 4)
@@ -21,6 +27,10 @@ int __cdecl wmain(int argc, LPWSTR argv[])
21 { 27 {
22 hr = RunShutdownEngine(argv[2], argv[3]); 28 hr = RunShutdownEngine(argv[2], argv[3]);
23 } 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 }
24 else 34 else
25 { 35 {
26 fShowUsage = TRUE; 36 fShowUsage = TRUE;
@@ -28,9 +38,16 @@ int __cdecl wmain(int argc, LPWSTR argv[])
28 38
29 if (fShowUsage) 39 if (fShowUsage)
30 { 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");
32 } 42 }
33 43
34 ConsoleUninitialize(); 44 ConsoleUninitialize();
45
46LExit:
47 if (fComInitialized)
48 {
49 ::CoUninitialize();
50 }
51
35 return hr; 52 return hr;
36} 53}
diff --git a/src/test/examples/TestEngine/ReloadEngine.cpp b/src/test/examples/TestEngine/ReloadEngine.cpp
index 83541672..46fd9afa 100644
--- a/src/test/examples/TestEngine/ReloadEngine.cpp
+++ b/src/test/examples/TestEngine/ReloadEngine.cpp
@@ -22,6 +22,12 @@ HRESULT RunReloadEngine(
22 hr = pTestEngine->SendStartupEvent(); 22 hr = pTestEngine->SendStartupEvent();
23 ConsoleExitOnFailure(hr, CONSOLE_COLOR_RED, "BA returned failure for OnStartup."); 23 ConsoleExitOnFailure(hr, CONSOLE_COLOR_RED, "BA returned failure for OnStartup.");
24 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
25 hr = pTestEngine->SendShutdownEvent(BOOTSTRAPPER_SHUTDOWN_ACTION_RELOAD_BOOTSTRAPPER); 31 hr = pTestEngine->SendShutdownEvent(BOOTSTRAPPER_SHUTDOWN_ACTION_RELOAD_BOOTSTRAPPER);
26 ConsoleExitOnFailure(hr, CONSOLE_COLOR_RED, "BA returned failure for OnShutdown."); 32 ConsoleExitOnFailure(hr, CONSOLE_COLOR_RED, "BA returned failure for OnShutdown.");
27 33
@@ -33,6 +39,12 @@ HRESULT RunReloadEngine(
33 hr = pTestEngine->SendStartupEvent(); 39 hr = pTestEngine->SendStartupEvent();
34 ConsoleExitOnFailure(hr, CONSOLE_COLOR_RED, "BA returned failure for OnStartup."); 40 ConsoleExitOnFailure(hr, CONSOLE_COLOR_RED, "BA returned failure for OnStartup.");
35 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
36 hr = pTestEngine->SendShutdownEvent(BOOTSTRAPPER_SHUTDOWN_ACTION_RESTART); 48 hr = pTestEngine->SendShutdownEvent(BOOTSTRAPPER_SHUTDOWN_ACTION_RESTART);
37 ConsoleExitOnFailure(hr, CONSOLE_COLOR_RED, "BA returned failure for OnShutdown."); 49 ConsoleExitOnFailure(hr, CONSOLE_COLOR_RED, "BA returned failure for OnShutdown.");
38 50
diff --git a/src/test/examples/TestEngine/ShutdownEngine.cpp b/src/test/examples/TestEngine/ShutdownEngine.cpp
index 0dfbb429..3b876e4e 100644
--- a/src/test/examples/TestEngine/ShutdownEngine.cpp
+++ b/src/test/examples/TestEngine/ShutdownEngine.cpp
@@ -22,6 +22,12 @@ HRESULT RunShutdownEngine(
22 hr = pTestEngine->SendStartupEvent(); 22 hr = pTestEngine->SendStartupEvent();
23 ConsoleExitOnFailure(hr, CONSOLE_COLOR_RED, "BA returned failure for OnStartup."); 23 ConsoleExitOnFailure(hr, CONSOLE_COLOR_RED, "BA returned failure for OnStartup.");
24 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
25 hr = pTestEngine->SendShutdownEvent(BOOTSTRAPPER_SHUTDOWN_ACTION_RELOAD_BOOTSTRAPPER); 31 hr = pTestEngine->SendShutdownEvent(BOOTSTRAPPER_SHUTDOWN_ACTION_RELOAD_BOOTSTRAPPER);
26 ConsoleExitOnFailure(hr, CONSOLE_COLOR_RED, "BA returned failure for OnShutdown."); 32 ConsoleExitOnFailure(hr, CONSOLE_COLOR_RED, "BA returned failure for OnShutdown.");
27 33
diff --git a/src/test/examples/TestEngine/TestEngine.cpp b/src/test/examples/TestEngine/TestEngine.cpp
index f0811e0a..7b7dafce 100644
--- a/src/test/examples/TestEngine/TestEngine.cpp
+++ b/src/test/examples/TestEngine/TestEngine.cpp
@@ -7,12 +7,15 @@ HRESULT TestEngine::Initialize(
7 ) 7 )
8{ 8{
9 HRESULT hr = S_OK; 9 HRESULT hr = S_OK;
10 MSG msg = { };
10 11
11 LogInitialize(::GetModuleHandleW(NULL)); 12 LogInitialize(::GetModuleHandleW(NULL));
12 13
13 hr = LogOpen(NULL, PathFile(wzBundleFilePath), NULL, L"txt", FALSE, FALSE, NULL); 14 hr = LogOpen(NULL, PathFile(wzBundleFilePath), NULL, L"txt", FALSE, FALSE, NULL);
14 ConsoleExitOnFailure(hr, CONSOLE_COLOR_RED, "Failed to open log."); 15 ConsoleExitOnFailure(hr, CONSOLE_COLOR_RED, "Failed to open log.");
15 16
17 ::PeekMessageW(&msg, NULL, WM_USER, WM_USER, PM_NOREMOVE);
18
16LExit: 19LExit:
17 return hr; 20 return hr;
18} 21}
@@ -73,6 +76,29 @@ HRESULT TestEngine::Log(
73 return ConsoleWriteLine(CONSOLE_COLOR_NORMAL, "%ls", wzMessage); 76 return ConsoleWriteLine(CONSOLE_COLOR_NORMAL, "%ls", wzMessage);
74} 77}
75 78
79HRESULT 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
98LExit:
99 return hr;
100}
101
76HRESULT TestEngine::SendShutdownEvent( 102HRESULT TestEngine::SendShutdownEvent(
77 __in BOOTSTRAPPER_SHUTDOWN_ACTION defaultAction 103 __in BOOTSTRAPPER_SHUTDOWN_ACTION defaultAction
78 ) 104 )
@@ -98,6 +124,21 @@ HRESULT TestEngine::SendStartupEvent()
98 return hr; 124 return hr;
99} 125}
100 126
127HRESULT 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
101void TestEngine::UnloadBA() 142void TestEngine::UnloadBA()
102{ 143{
103 PFN_BOOTSTRAPPER_APPLICATION_DESTROY pfnDestroy = NULL; 144 PFN_BOOTSTRAPPER_APPLICATION_DESTROY pfnDestroy = NULL;
@@ -124,12 +165,27 @@ void TestEngine::UnloadBA()
124} 165}
125 166
126HRESULT TestEngine::BAEngineLog( 167HRESULT TestEngine::BAEngineLog(
127 __in TestEngine* pContext,
128 __in BAENGINE_LOG_ARGS* pArgs, 168 __in BAENGINE_LOG_ARGS* pArgs,
129 __in BAENGINE_LOG_RESULTS* /*pResults*/ 169 __in BAENGINE_LOG_RESULTS* /*pResults*/
130 ) 170 )
131{ 171{
132 return pContext->Log(pArgs->wzMessage); 172 return Log(pArgs->wzMessage);
173}
174
175HRESULT 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
187LExit:
188 return hr;
133} 189}
134 190
135HRESULT WINAPI TestEngine::EngineProc( 191HRESULT WINAPI TestEngine::EngineProc(
@@ -150,8 +206,10 @@ HRESULT WINAPI TestEngine::EngineProc(
150 switch (message) 206 switch (message)
151 { 207 {
152 case BOOTSTRAPPER_ENGINE_MESSAGE_LOG: 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));
154 break; 210 break;
211 case BOOTSTRAPPER_ENGINE_MESSAGE_QUIT:
212 hr = pContext->BAEngineQuit(reinterpret_cast<BAENGINE_QUIT_ARGS*>(pvArgs), reinterpret_cast<BAENGINE_QUIT_RESULTS*>(pvResults));
155 default: 213 default:
156 hr = E_NOTIMPL; 214 hr = E_NOTIMPL;
157 break; 215 break;
@@ -161,13 +219,30 @@ LExit:
161 return hr; 219 return hr;
162} 220}
163 221
222HRESULT 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
164TestEngine::TestEngine() 238TestEngine::TestEngine()
165{ 239{
166 m_hBAModule = NULL; 240 m_hBAModule = NULL;
167 m_pCreateResults = NULL; 241 m_pCreateResults = NULL;
242 m_dwThreadId = ::GetCurrentThreadId();
168} 243}
169 244
170TestEngine::~TestEngine() 245TestEngine::~TestEngine()
171{ 246{
172 ReleaseMem(m_pCreateResults); 247 ReleaseMem(m_pCreateResults);
173} \ No newline at end of file 248}
diff --git a/src/test/examples/TestEngine/TestEngine.h b/src/test/examples/TestEngine/TestEngine.h
index cf1c8aac..14b69999 100644
--- a/src/test/examples/TestEngine/TestEngine.h
+++ b/src/test/examples/TestEngine/TestEngine.h
@@ -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. 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 3
4 4
5enum 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
5class TestEngine 19class TestEngine
6{ 20{
7public: 21public:
@@ -17,19 +31,29 @@ public:
17 __in LPCWSTR wzMessage 31 __in LPCWSTR wzMessage
18 ); 32 );
19 33
34 HRESULT RunApplication();
35
20 HRESULT SendShutdownEvent( 36 HRESULT SendShutdownEvent(
21 __in BOOTSTRAPPER_SHUTDOWN_ACTION defaultAction 37 __in BOOTSTRAPPER_SHUTDOWN_ACTION defaultAction
22 ); 38 );
23 39
24 HRESULT SendStartupEvent(); 40 HRESULT SendStartupEvent();
25 41
42 HRESULT SimulateQuit(
43 __in DWORD dwExitCode
44 );
45
26 void UnloadBA(); 46 void UnloadBA();
27 47
28private: 48private:
29 static HRESULT BAEngineLog( 49 HRESULT BAEngineLog(
30 __in TestEngine* pContext,
31 __in BAENGINE_LOG_ARGS* pArgs, 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
33 ); 57 );
34 58
35 static HRESULT WINAPI EngineProc( 59 static HRESULT WINAPI EngineProc(
@@ -39,6 +63,10 @@ private:
39 __in_opt LPVOID pvContext 63 __in_opt LPVOID pvContext
40 ); 64 );
41 65
66 HRESULT ProcessBAMessage(
67 __in const MSG* pmsg
68 );
69
42public: 70public:
43 TestEngine(); 71 TestEngine();
44 72
@@ -47,4 +75,5 @@ public:
47private: 75private:
48 HMODULE m_hBAModule; 76 HMODULE m_hBAModule;
49 BOOTSTRAPPER_CREATE_RESULTS* m_pCreateResults; 77 BOOTSTRAPPER_CREATE_RESULTS* m_pCreateResults;
78 DWORD m_dwThreadId;
50}; \ No newline at end of file 79}; \ No newline at end of file
diff --git a/src/test/examples/TestEngine/WaitForQuitEngine.cpp b/src/test/examples/TestEngine/WaitForQuitEngine.cpp
new file mode 100644
index 00000000..2f80ba75
--- /dev/null
+++ b/src/test/examples/TestEngine/WaitForQuitEngine.cpp
@@ -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
5HRESULT 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
33LExit:
34 return hr;
35}
diff --git a/src/test/examples/TestEngine/WaitForQuitEngine.h b/src/test/examples/TestEngine/WaitForQuitEngine.h
new file mode 100644
index 00000000..99e3f63c
--- /dev/null
+++ b/src/test/examples/TestEngine/WaitForQuitEngine.h
@@ -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
5HRESULT RunWaitForQuitEngine(
6 __in LPCWSTR wzBundleFilePath,
7 __in LPCWSTR wzBAFilePath
8 );
diff --git a/src/test/examples/TestEngine/precomp.h b/src/test/examples/TestEngine/precomp.h
index 3fbc7e90..f943f420 100644
--- a/src/test/examples/TestEngine/precomp.h
+++ b/src/test/examples/TestEngine/precomp.h
@@ -17,3 +17,4 @@
17#include "TestEngine.h" 17#include "TestEngine.h"
18#include "ReloadEngine.h" 18#include "ReloadEngine.h"
19#include "ShutdownEngine.h" 19#include "ShutdownEngine.h"
20#include "WaitForQuitEngine.h"
diff --git a/src/test/examples/WPFCoreMBA/AssemblyInfo.cs b/src/test/examples/WPFCoreMBA/AssemblyInfo.cs
new file mode 100644
index 00000000..03a5c7fa
--- /dev/null
+++ b/src/test/examples/WPFCoreMBA/AssemblyInfo.cs
@@ -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
3using 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)]
diff --git a/src/test/examples/WPFCoreMBA/Example.WPFCoreMBA.csproj b/src/test/examples/WPFCoreMBA/Example.WPFCoreMBA.csproj
new file mode 100644
index 00000000..3b559f9b
--- /dev/null
+++ b/src/test/examples/WPFCoreMBA/Example.WPFCoreMBA.csproj
@@ -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
diff --git a/src/test/examples/WPFCoreMBA/MainWindow.xaml b/src/test/examples/WPFCoreMBA/MainWindow.xaml
new file mode 100644
index 00000000..40a27a06
--- /dev/null
+++ b/src/test/examples/WPFCoreMBA/MainWindow.xaml
@@ -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>
diff --git a/src/test/examples/WPFCoreMBA/MainWindow.xaml.cs b/src/test/examples/WPFCoreMBA/MainWindow.xaml.cs
new file mode 100644
index 00000000..4f61b807
--- /dev/null
+++ b/src/test/examples/WPFCoreMBA/MainWindow.xaml.cs
@@ -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
3namespace 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}
diff --git a/src/test/examples/WPFCoreMBA/WPFCoreBA.cs b/src/test/examples/WPFCoreMBA/WPFCoreBA.cs
new file mode 100644
index 00000000..d50be813
--- /dev/null
+++ b/src/test/examples/WPFCoreMBA/WPFCoreBA.cs
@@ -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
3namespace 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}
diff --git a/src/test/examples/WPFCoreMBA/WPFCoreBAFactory.cs b/src/test/examples/WPFCoreMBA/WPFCoreBAFactory.cs
new file mode 100644
index 00000000..a3ccdf9f
--- /dev/null
+++ b/src/test/examples/WPFCoreMBA/WPFCoreBAFactory.cs
@@ -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))]
4namespace 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}