aboutsummaryrefslogtreecommitdiff
path: root/src/ext/Bal/test/examples/TestEngine
diff options
context:
space:
mode:
authorRob Mensching <rob@firegiant.com>2021-05-03 15:55:48 -0700
committerRob Mensching <rob@firegiant.com>2021-05-03 15:55:48 -0700
commitba7bab476501c16e437b0aee71c1be02c3dda176 (patch)
tree814fba485c29a7dfe1adb396169e27ed641ef9a3 /src/ext/Bal/test/examples/TestEngine
parent14987a72cc1a3493ca8f80693d273352fc314bd9 (diff)
downloadwix-ba7bab476501c16e437b0aee71c1be02c3dda176.tar.gz
wix-ba7bab476501c16e437b0aee71c1be02c3dda176.tar.bz2
wix-ba7bab476501c16e437b0aee71c1be02c3dda176.zip
Move Bal.wixext into ext
Diffstat (limited to 'src/ext/Bal/test/examples/TestEngine')
-rw-r--r--src/ext/Bal/test/examples/TestEngine/Example.TestEngine.vcxproj83
-rw-r--r--src/ext/Bal/test/examples/TestEngine/ExampleTestEngine.cpp53
-rw-r--r--src/ext/Bal/test/examples/TestEngine/ReloadEngine.cpp55
-rw-r--r--src/ext/Bal/test/examples/TestEngine/ReloadEngine.h8
-rw-r--r--src/ext/Bal/test/examples/TestEngine/ShutdownEngine.cpp38
-rw-r--r--src/ext/Bal/test/examples/TestEngine/ShutdownEngine.h8
-rw-r--r--src/ext/Bal/test/examples/TestEngine/TestEngine.cpp256
-rw-r--r--src/ext/Bal/test/examples/TestEngine/TestEngine.h80
-rw-r--r--src/ext/Bal/test/examples/TestEngine/WaitForQuitEngine.cpp35
-rw-r--r--src/ext/Bal/test/examples/TestEngine/WaitForQuitEngine.h8
-rw-r--r--src/ext/Bal/test/examples/TestEngine/packages.config7
-rw-r--r--src/ext/Bal/test/examples/TestEngine/precomp.cpp3
-rw-r--r--src/ext/Bal/test/examples/TestEngine/precomp.h20
13 files changed, 654 insertions, 0 deletions
diff --git a/src/ext/Bal/test/examples/TestEngine/Example.TestEngine.vcxproj b/src/ext/Bal/test/examples/TestEngine/Example.TestEngine.vcxproj
new file mode 100644
index 00000000..99eb917e
--- /dev/null
+++ b/src/ext/Bal/test/examples/TestEngine/Example.TestEngine.vcxproj
@@ -0,0 +1,83 @@
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<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
4 <Import Project="..\..\..\..\packages\WixToolset.BalUtil.4.0.58\build\WixToolset.BalUtil.props" Condition="Exists('..\..\..\..\packages\WixToolset.BalUtil.4.0.58\build\WixToolset.BalUtil.props')" />
5 <Import Project="..\..\..\..\packages\WixToolset.BootstrapperCore.Native.4.0.141\build\WixToolset.BootstrapperCore.Native.props" Condition="Exists('..\..\..\..\packages\WixToolset.BootstrapperCore.Native.4.0.141\build\WixToolset.BootstrapperCore.Native.props')" />
6 <Import Project="..\..\..\..\packages\WixToolset.DUtil.4.0.72\build\WixToolset.DUtil.props" Condition="Exists('..\..\..\..\packages\WixToolset.DUtil.4.0.72\build\WixToolset.DUtil.props')" />
7 <ItemGroup Label="ProjectConfigurations">
8 <ProjectConfiguration Include="Debug|ARM64">
9 <Configuration>Debug</Configuration>
10 <Platform>ARM64</Platform>
11 </ProjectConfiguration>
12 <ProjectConfiguration Include="Release|ARM64">
13 <Configuration>Release</Configuration>
14 <Platform>ARM64</Platform>
15 </ProjectConfiguration>
16 <ProjectConfiguration Include="Debug|Win32">
17 <Configuration>Debug</Configuration>
18 <Platform>Win32</Platform>
19 </ProjectConfiguration>
20 <ProjectConfiguration Include="Release|Win32">
21 <Configuration>Release</Configuration>
22 <Platform>Win32</Platform>
23 </ProjectConfiguration>
24 <ProjectConfiguration Include="Debug|x64">
25 <Configuration>Debug</Configuration>
26 <Platform>x64</Platform>
27 </ProjectConfiguration>
28 <ProjectConfiguration Include="Release|x64">
29 <Configuration>Release</Configuration>
30 <Platform>x64</Platform>
31 </ProjectConfiguration>
32 </ItemGroup>
33 <PropertyGroup Label="Globals">
34 <ProjectGuid>{3D44B67D-A475-49BA-8310-E39F6C117CC9}</ProjectGuid>
35 <ConfigurationType>Application</ConfigurationType>
36 <ProjectSubSystem>Console</ProjectSubSystem>
37 <TargetName>Example.TestEngine</TargetName>
38 <PlatformToolset>v142</PlatformToolset>
39 <CharacterSet>Unicode</CharacterSet>
40 <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
41 </PropertyGroup>
42 <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
43 <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
44 <ImportGroup Label="ExtensionSettings">
45 </ImportGroup>
46 <ImportGroup Label="Shared">
47 <Import Project="..\..\..\..\packages\Nerdbank.GitVersioning.3.3.37\build\Nerdbank.GitVersioning.targets" Condition="Exists('..\..\..\..\packages\Nerdbank.GitVersioning.3.3.37\build\Nerdbank.GitVersioning.targets')" />
48 </ImportGroup>
49 <PropertyGroup>
50 <ProjectAdditionalLinkLibraries>
51 </ProjectAdditionalLinkLibraries>
52 </PropertyGroup>
53 <ItemGroup>
54 <ClCompile Include="precomp.cpp">
55 <PrecompiledHeader>Create</PrecompiledHeader>
56 </ClCompile>
57 <ClCompile Include="ReloadEngine.cpp" />
58 <ClCompile Include="ShutdownEngine.cpp" />
59 <ClCompile Include="ExampleTestEngine.cpp" />
60 <ClCompile Include="TestEngine.cpp" />
61 <ClCompile Include="WaitForQuitEngine.cpp" />
62 </ItemGroup>
63 <ItemGroup>
64 <ClInclude Include="precomp.h" />
65 <ClInclude Include="ReloadEngine.h" />
66 <ClInclude Include="ShutdownEngine.h" />
67 <ClInclude Include="TestEngine.h" />
68 <ClInclude Include="WaitForQuitEngine.h" />
69 </ItemGroup>
70 <ItemGroup>
71 <None Include="packages.config" />
72 </ItemGroup>
73 <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
74 <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
75 <PropertyGroup>
76 <ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
77 </PropertyGroup>
78 <Error Condition="!Exists('..\..\..\..\packages\Nerdbank.GitVersioning.3.3.37\build\Nerdbank.GitVersioning.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\..\packages\Nerdbank.GitVersioning.3.3.37\build\Nerdbank.GitVersioning.targets'))" />
79 <Error Condition="!Exists('..\..\..\..\packages\WixToolset.BalUtil.4.0.58\build\WixToolset.BalUtil.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\..\packages\WixToolset.BalUtil.4.0.58\build\WixToolset.BalUtil.props'))" />
80 <Error Condition="!Exists('..\..\..\..\packages\WixToolset.BootstrapperCore.Native.4.0.141\build\WixToolset.BootstrapperCore.Native.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\..\packages\WixToolset.BootstrapperCore.Native.4.0.141\build\WixToolset.BootstrapperCore.Native.props'))" />
81 <Error Condition="!Exists('..\..\..\..\packages\WixToolset.DUtil.4.0.72\build\WixToolset.DUtil.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\..\packages\WixToolset.DUtil.4.0.72\build\WixToolset.DUtil.props'))" />
82 </Target>
83</Project> \ No newline at end of file
diff --git a/src/ext/Bal/test/examples/TestEngine/ExampleTestEngine.cpp b/src/ext/Bal/test/examples/TestEngine/ExampleTestEngine.cpp
new file mode 100644
index 00000000..fc1938fe
--- /dev/null
+++ b/src/ext/Bal/test/examples/TestEngine/ExampleTestEngine.cpp
@@ -0,0 +1,53 @@
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
5int __cdecl wmain(int argc, LPWSTR argv[])
6{
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)
19 {
20 fShowUsage = TRUE;
21 }
22 else if (CSTR_EQUAL == ::CompareString(LOCALE_INVARIANT, NORM_IGNORECASE, argv[1], -1, L"reload", -1))
23 {
24 hr = RunReloadEngine(argv[2], argv[3]);
25 }
26 else if (CSTR_EQUAL == ::CompareString(LOCALE_INVARIANT, NORM_IGNORECASE, argv[1], -1, L"shutdown", -1))
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;
37 }
38
39 if (fShowUsage)
40 {
41 ConsoleWriteError(hr = E_INVALIDARG, CONSOLE_COLOR_RED, "Usage: Example.TestEngine.exe {reload|shutdown|waitforquit} Bundle.exe BA.dll");
42 }
43
44 ConsoleUninitialize();
45
46LExit:
47 if (fComInitialized)
48 {
49 ::CoUninitialize();
50 }
51
52 return hr;
53}
diff --git a/src/ext/Bal/test/examples/TestEngine/ReloadEngine.cpp b/src/ext/Bal/test/examples/TestEngine/ReloadEngine.cpp
new file mode 100644
index 00000000..46fd9afa
--- /dev/null
+++ b/src/ext/Bal/test/examples/TestEngine/ReloadEngine.cpp
@@ -0,0 +1,55 @@
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 RunReloadEngine(
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->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
34 pTestEngine->UnloadBA();
35
36 hr = pTestEngine->LoadBA(wzBAFilePath);
37 ConsoleExitOnFailure(hr, CONSOLE_COLOR_RED, "Failed to load BA.");
38
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
51 pTestEngine->UnloadBA();
52
53LExit:
54 return hr;
55}
diff --git a/src/ext/Bal/test/examples/TestEngine/ReloadEngine.h b/src/ext/Bal/test/examples/TestEngine/ReloadEngine.h
new file mode 100644
index 00000000..0e8456af
--- /dev/null
+++ b/src/ext/Bal/test/examples/TestEngine/ReloadEngine.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 RunReloadEngine(
6 __in LPCWSTR wzBundleFilePath,
7 __in LPCWSTR wzBAFilePath
8 );
diff --git a/src/ext/Bal/test/examples/TestEngine/ShutdownEngine.cpp b/src/ext/Bal/test/examples/TestEngine/ShutdownEngine.cpp
new file mode 100644
index 00000000..3b876e4e
--- /dev/null
+++ b/src/ext/Bal/test/examples/TestEngine/ShutdownEngine.cpp
@@ -0,0 +1,38 @@
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 RunShutdownEngine(
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->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
34 pTestEngine->UnloadBA();
35
36LExit:
37 return hr;
38}
diff --git a/src/ext/Bal/test/examples/TestEngine/ShutdownEngine.h b/src/ext/Bal/test/examples/TestEngine/ShutdownEngine.h
new file mode 100644
index 00000000..0cfa147a
--- /dev/null
+++ b/src/ext/Bal/test/examples/TestEngine/ShutdownEngine.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 RunShutdownEngine(
6 __in LPCWSTR wzBundleFilePath,
7 __in LPCWSTR wzBAFilePath
8 );
diff --git a/src/ext/Bal/test/examples/TestEngine/TestEngine.cpp b/src/ext/Bal/test/examples/TestEngine/TestEngine.cpp
new file mode 100644
index 00000000..4c7ec1c3
--- /dev/null
+++ b/src/ext/Bal/test/examples/TestEngine/TestEngine.cpp
@@ -0,0 +1,256 @@
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 TestEngine::Initialize(
6 __in LPCWSTR wzBundleFilePath
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
19LExit:
20 return hr;
21}
22
23HRESULT TestEngine::LoadBA(
24 __in LPCWSTR wzBAFilePath
25 )
26{
27 HRESULT hr = S_OK;
28 BOOTSTRAPPER_COMMAND command = { };
29 BOOTSTRAPPER_CREATE_ARGS args = { };
30 PFN_BOOTSTRAPPER_APPLICATION_CREATE pfnCreate = NULL;
31
32 if (m_pCreateResults || m_hBAModule)
33 {
34 ExitFunction1(hr = E_INVALIDSTATE);
35 }
36
37 m_pCreateResults = static_cast<BOOTSTRAPPER_CREATE_RESULTS*>(MemAlloc(sizeof(BOOTSTRAPPER_CREATE_RESULTS), TRUE));
38
39 command.cbSize = sizeof(BOOTSTRAPPER_COMMAND);
40
41 hr = PathGetDirectory(wzBAFilePath, &command.wzBootstrapperWorkingFolder);
42 ConsoleExitOnFailure(hr, CONSOLE_COLOR_RED, "Failed to allocate wzBootstrapperWorkingFolder");
43
44 hr = PathConcat(command.wzBootstrapperWorkingFolder, L"BootstrapperApplicationData.xml", &command.wzBootstrapperApplicationDataPath);
45 ConsoleExitOnFailure(hr, CONSOLE_COLOR_RED, "Failed to allocate wzBootstrapperApplicationDataPath");
46
47 args.cbSize = sizeof(BOOTSTRAPPER_CREATE_ARGS);
48 args.pCommand = &command;
49 args.pfnBootstrapperEngineProc = TestEngine::EngineProc;
50 args.pvBootstrapperEngineProcContext = this;
51 args.qwEngineAPIVersion = MAKEQWORDVERSION(0, 0, 0, 1);
52
53 m_pCreateResults->cbSize = sizeof(BOOTSTRAPPER_CREATE_RESULTS);
54
55 m_hBAModule = ::LoadLibraryExW(wzBAFilePath, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
56 ConsoleExitOnNullWithLastError(m_hBAModule, hr, CONSOLE_COLOR_RED, "Failed to load BA dll.");
57
58 pfnCreate = (PFN_BOOTSTRAPPER_APPLICATION_CREATE)::GetProcAddress(m_hBAModule, "BootstrapperApplicationCreate");
59 ConsoleExitOnNull(pfnCreate, hr, E_OUTOFMEMORY, CONSOLE_COLOR_RED, "Failed to get address for BootstrapperApplicationCreate.");
60
61 hr = pfnCreate(&args, m_pCreateResults);
62 ConsoleExitOnFailure(hr, CONSOLE_COLOR_RED, "BA returned failure on BootstrapperApplicationCreate.");
63
64LExit:
65 ReleaseStr(command.wzBootstrapperApplicationDataPath);
66 ReleaseStr(command.wzBootstrapperWorkingFolder);
67
68 return hr;
69}
70
71HRESULT TestEngine::Log(
72 __in BOOTSTRAPPER_LOG_LEVEL level,
73 __in LPCWSTR wzMessage
74 )
75{
76 switch (level)
77 {
78 case BOOTSTRAPPER_LOG_LEVEL_NONE:
79 case BOOTSTRAPPER_LOG_LEVEL_DEBUG:
80 return S_OK;
81 default:
82 LogStringLine(REPORT_STANDARD, "%ls", wzMessage);
83 return ConsoleWriteLine(CONSOLE_COLOR_NORMAL, "%ls", wzMessage);
84 }
85}
86
87HRESULT TestEngine::RunApplication()
88{
89 HRESULT hr = S_OK;
90 MSG msg = { };
91 BOOL fRet = FALSE;
92
93 // Enter the message pump.
94 while (0 != (fRet = ::GetMessageW(&msg, NULL, 0, 0)))
95 {
96 if (-1 == fRet)
97 {
98 ConsoleExitOnFailure(hr = E_UNEXPECTED, CONSOLE_COLOR_RED, "Unexpected return value from message pump.");
99 }
100 else
101 {
102 ProcessBAMessage(&msg);
103 }
104 }
105
106LExit:
107 return hr;
108}
109
110HRESULT TestEngine::SendShutdownEvent(
111 __in BOOTSTRAPPER_SHUTDOWN_ACTION defaultAction
112 )
113{
114 HRESULT hr = S_OK;
115 BA_ONSHUTDOWN_ARGS shutdownArgs = { };
116 BA_ONSHUTDOWN_RESULTS shutdownResults = { };
117 shutdownArgs.cbSize = sizeof(BA_ONSHUTDOWN_ARGS);
118 shutdownResults.action = defaultAction;
119 shutdownResults.cbSize = sizeof(BA_ONSHUTDOWN_RESULTS);
120 hr = m_pCreateResults->pfnBootstrapperApplicationProc(BOOTSTRAPPER_APPLICATION_MESSAGE_ONSHUTDOWN, &shutdownArgs, &shutdownResults, m_pCreateResults->pvBootstrapperApplicationProcContext);
121 return hr;
122}
123
124HRESULT TestEngine::SendStartupEvent()
125{
126 HRESULT hr = S_OK;
127 BA_ONSTARTUP_ARGS startupArgs = { };
128 BA_ONSTARTUP_RESULTS startupResults = { };
129 startupArgs.cbSize = sizeof(BA_ONSTARTUP_ARGS);
130 startupResults.cbSize = sizeof(BA_ONSTARTUP_RESULTS);
131 hr = m_pCreateResults->pfnBootstrapperApplicationProc(BOOTSTRAPPER_APPLICATION_MESSAGE_ONSTARTUP, &startupArgs, &startupResults, m_pCreateResults->pvBootstrapperApplicationProcContext);
132 return hr;
133}
134
135HRESULT TestEngine::SimulateQuit(
136 __in DWORD dwExitCode
137 )
138{
139 BAENGINE_QUIT_ARGS args = { };
140 BAENGINE_QUIT_RESULTS results = { };
141
142 args.cbSize = sizeof(BAENGINE_QUIT_ARGS);
143 args.dwExitCode = dwExitCode;
144
145 results.cbSize = sizeof(BAENGINE_QUIT_RESULTS);
146
147 return BAEngineQuit(&args, &results);
148}
149
150void TestEngine::UnloadBA()
151{
152 PFN_BOOTSTRAPPER_APPLICATION_DESTROY pfnDestroy = NULL;
153 BOOL fDisableUnloading = m_pCreateResults && m_pCreateResults->fDisableUnloading;
154
155 ReleaseNullMem(m_pCreateResults);
156
157 pfnDestroy = (PFN_BOOTSTRAPPER_APPLICATION_DESTROY)::GetProcAddress(m_hBAModule, "BootstrapperApplicationDestroy");
158
159 if (pfnDestroy)
160 {
161 pfnDestroy();
162 }
163
164 if (m_hBAModule)
165 {
166 if (!fDisableUnloading)
167 {
168 ::FreeLibrary(m_hBAModule);
169 }
170
171 m_hBAModule = NULL;
172 }
173}
174
175HRESULT TestEngine::BAEngineLog(
176 __in BAENGINE_LOG_ARGS* pArgs,
177 __in BAENGINE_LOG_RESULTS* /*pResults*/
178 )
179{
180 return Log(pArgs->level, pArgs->wzMessage);
181}
182
183HRESULT TestEngine::BAEngineQuit(
184 __in BAENGINE_QUIT_ARGS* pArgs,
185 __in BAENGINE_QUIT_RESULTS* /*pResults*/
186 )
187{
188 HRESULT hr = S_OK;
189
190 if (!::PostThreadMessageW(m_dwThreadId, WM_TESTENG_QUIT, static_cast<WPARAM>(pArgs->dwExitCode), 0))
191 {
192 ConsoleExitWithLastError(hr, CONSOLE_COLOR_RED, "Failed to post shutdown message.");
193 }
194
195LExit:
196 return hr;
197}
198
199HRESULT WINAPI TestEngine::EngineProc(
200 __in BOOTSTRAPPER_ENGINE_MESSAGE message,
201 __in const LPVOID pvArgs,
202 __inout LPVOID pvResults,
203 __in_opt LPVOID pvContext
204 )
205{
206 HRESULT hr = S_OK;
207 TestEngine* pContext = (TestEngine*)pvContext;
208
209 if (!pContext || !pvArgs || !pvResults)
210 {
211 ExitFunction1(hr = E_INVALIDARG);
212 }
213
214 switch (message)
215 {
216 case BOOTSTRAPPER_ENGINE_MESSAGE_LOG:
217 hr = pContext->BAEngineLog(reinterpret_cast<BAENGINE_LOG_ARGS*>(pvArgs), reinterpret_cast<BAENGINE_LOG_RESULTS*>(pvResults));
218 break;
219 case BOOTSTRAPPER_ENGINE_MESSAGE_QUIT:
220 hr = pContext->BAEngineQuit(reinterpret_cast<BAENGINE_QUIT_ARGS*>(pvArgs), reinterpret_cast<BAENGINE_QUIT_RESULTS*>(pvResults));
221 default:
222 hr = E_NOTIMPL;
223 break;
224 }
225
226LExit:
227 return hr;
228}
229
230HRESULT TestEngine::ProcessBAMessage(
231 __in const MSG* pmsg
232 )
233{
234 HRESULT hr = S_OK;
235
236 switch (pmsg->message)
237 {
238 case WM_TESTENG_QUIT:
239 ::PostQuitMessage(static_cast<int>(pmsg->wParam)); // go bye-bye.
240 break;
241 }
242
243 return hr;
244}
245
246TestEngine::TestEngine()
247{
248 m_hBAModule = NULL;
249 m_pCreateResults = NULL;
250 m_dwThreadId = ::GetCurrentThreadId();
251}
252
253TestEngine::~TestEngine()
254{
255 ReleaseMem(m_pCreateResults);
256}
diff --git a/src/ext/Bal/test/examples/TestEngine/TestEngine.h b/src/ext/Bal/test/examples/TestEngine/TestEngine.h
new file mode 100644
index 00000000..44e813bd
--- /dev/null
+++ b/src/ext/Bal/test/examples/TestEngine/TestEngine.h
@@ -0,0 +1,80 @@
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
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
19class TestEngine
20{
21public:
22 HRESULT Initialize(
23 __in LPCWSTR wzBundleFilePath
24 );
25
26 HRESULT LoadBA(
27 __in LPCWSTR wzBAFilePath
28 );
29
30 HRESULT Log(
31 __in BOOTSTRAPPER_LOG_LEVEL level,
32 __in LPCWSTR wzMessage
33 );
34
35 HRESULT RunApplication();
36
37 HRESULT SendShutdownEvent(
38 __in BOOTSTRAPPER_SHUTDOWN_ACTION defaultAction
39 );
40
41 HRESULT SendStartupEvent();
42
43 HRESULT SimulateQuit(
44 __in DWORD dwExitCode
45 );
46
47 void UnloadBA();
48
49private:
50 HRESULT BAEngineLog(
51 __in BAENGINE_LOG_ARGS* pArgs,
52 __in BAENGINE_LOG_RESULTS* pResults
53 );
54
55 HRESULT BAEngineQuit(
56 __in BAENGINE_QUIT_ARGS* pArgs,
57 __in BAENGINE_QUIT_RESULTS* pResults
58 );
59
60 static HRESULT WINAPI EngineProc(
61 __in BOOTSTRAPPER_ENGINE_MESSAGE message,
62 __in const LPVOID pvArgs,
63 __inout LPVOID pvResults,
64 __in_opt LPVOID pvContext
65 );
66
67 HRESULT ProcessBAMessage(
68 __in const MSG* pmsg
69 );
70
71public:
72 TestEngine();
73
74 ~TestEngine();
75
76private:
77 HMODULE m_hBAModule;
78 BOOTSTRAPPER_CREATE_RESULTS* m_pCreateResults;
79 DWORD m_dwThreadId;
80}; \ No newline at end of file
diff --git a/src/ext/Bal/test/examples/TestEngine/WaitForQuitEngine.cpp b/src/ext/Bal/test/examples/TestEngine/WaitForQuitEngine.cpp
new file mode 100644
index 00000000..2f80ba75
--- /dev/null
+++ b/src/ext/Bal/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/ext/Bal/test/examples/TestEngine/WaitForQuitEngine.h b/src/ext/Bal/test/examples/TestEngine/WaitForQuitEngine.h
new file mode 100644
index 00000000..99e3f63c
--- /dev/null
+++ b/src/ext/Bal/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/ext/Bal/test/examples/TestEngine/packages.config b/src/ext/Bal/test/examples/TestEngine/packages.config
new file mode 100644
index 00000000..548ddb48
--- /dev/null
+++ b/src/ext/Bal/test/examples/TestEngine/packages.config
@@ -0,0 +1,7 @@
1<?xml version="1.0" encoding="utf-8"?>
2<packages>
3 <package id="Nerdbank.GitVersioning" version="3.3.37" targetFramework="native" developmentDependency="true" />
4 <package id="WixToolset.BootstrapperCore.Native" version="4.0.141" targetFramework="native" />
5 <package id="WixToolset.BalUtil" version="4.0.58" targetFramework="native" />
6 <package id="WixToolset.DUtil" version="4.0.72" targetFramework="native" />
7</packages> \ No newline at end of file
diff --git a/src/ext/Bal/test/examples/TestEngine/precomp.cpp b/src/ext/Bal/test/examples/TestEngine/precomp.cpp
new file mode 100644
index 00000000..37664a1c
--- /dev/null
+++ b/src/ext/Bal/test/examples/TestEngine/precomp.cpp
@@ -0,0 +1,3 @@
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"
diff --git a/src/ext/Bal/test/examples/TestEngine/precomp.h b/src/ext/Bal/test/examples/TestEngine/precomp.h
new file mode 100644
index 00000000..f943f420
--- /dev/null
+++ b/src/ext/Bal/test/examples/TestEngine/precomp.h
@@ -0,0 +1,20 @@
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#include <windows.h>
5#include <MsiQuery.h>
6
7#include "dutil.h"
8#include "conutil.h"
9#include "logutil.h"
10#include "memutil.h"
11#include "pathutil.h"
12#include "strutil.h"
13
14#include "BootstrapperEngine.h"
15#include "BootstrapperApplication.h"
16
17#include "TestEngine.h"
18#include "ReloadEngine.h"
19#include "ShutdownEngine.h"
20#include "WaitForQuitEngine.h"