aboutsummaryrefslogtreecommitdiff
path: root/src/test/examples/TestEngine
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/test/examples/TestEngine
parenta79ce0b907676e50332139b4c4a8acb5d22a4b46 (diff)
downloadwix-ae1751902076edfd8978b7fb42f24d3ac3f7ad55.tar.gz
wix-ae1751902076edfd8978b7fb42f24d3ac3f7ad55.tar.bz2
wix-ae1751902076edfd8978b7fb42f24d3ac3f7ad55.zip
Add WPF .NET Core test.
Diffstat (limited to 'src/test/examples/TestEngine')
-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
9 files changed, 194 insertions, 9 deletions
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"