diff options
Diffstat (limited to 'src/test/examples/TestEngine/TestEngine.cpp')
-rw-r--r-- | src/test/examples/TestEngine/TestEngine.cpp | 117 |
1 files changed, 117 insertions, 0 deletions
diff --git a/src/test/examples/TestEngine/TestEngine.cpp b/src/test/examples/TestEngine/TestEngine.cpp new file mode 100644 index 00000000..c0a62eda --- /dev/null +++ b/src/test/examples/TestEngine/TestEngine.cpp | |||
@@ -0,0 +1,117 @@ | |||
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 TestEngine::LoadBA( | ||
6 | __in LPCWSTR wzBAFilePath | ||
7 | ) | ||
8 | { | ||
9 | HRESULT hr = S_OK; | ||
10 | BOOTSTRAPPER_COMMAND command = { }; | ||
11 | BOOTSTRAPPER_CREATE_ARGS args = { }; | ||
12 | HMODULE hBAModule = NULL; | ||
13 | PFN_BOOTSTRAPPER_APPLICATION_CREATE pfnCreate = NULL; | ||
14 | |||
15 | if (m_pCreateResults) | ||
16 | { | ||
17 | ExitFunction1(hr = E_INVALIDSTATE); | ||
18 | } | ||
19 | |||
20 | LogInitialize(::GetModuleHandleW(NULL)); | ||
21 | |||
22 | hr = LogOpen(NULL, L"ExampleTestEngine", NULL, L"txt", FALSE, FALSE, NULL); | ||
23 | ConsoleExitOnFailure(hr, CONSOLE_COLOR_RED, "Failed to open log."); | ||
24 | |||
25 | m_pCreateResults = static_cast<BOOTSTRAPPER_CREATE_RESULTS*>(MemAlloc(sizeof(BOOTSTRAPPER_CREATE_RESULTS), TRUE)); | ||
26 | |||
27 | command.cbSize = sizeof(BOOTSTRAPPER_COMMAND); | ||
28 | |||
29 | args.cbSize = sizeof(BOOTSTRAPPER_CREATE_ARGS); | ||
30 | args.pCommand = &command; | ||
31 | args.pfnBootstrapperEngineProc = TestEngine::EngineProc; | ||
32 | args.pvBootstrapperEngineProcContext = this; | ||
33 | args.qwEngineAPIVersion = MAKEQWORDVERSION(0, 0, 0, 1); | ||
34 | |||
35 | m_pCreateResults->cbSize = sizeof(BOOTSTRAPPER_CREATE_RESULTS); | ||
36 | |||
37 | hBAModule = ::LoadLibraryExW(wzBAFilePath, NULL, LOAD_WITH_ALTERED_SEARCH_PATH); | ||
38 | ExitOnNullWithLastError(hBAModule, hr, "Failed to load BA dll."); | ||
39 | |||
40 | pfnCreate = (PFN_BOOTSTRAPPER_APPLICATION_CREATE)::GetProcAddress(hBAModule, "BootstrapperApplicationCreate"); | ||
41 | ConsoleExitOnNull(pfnCreate, hr, E_OUTOFMEMORY, CONSOLE_COLOR_RED, "Failed to get address for BootstrapperApplicationCreate."); | ||
42 | |||
43 | hr = pfnCreate(&args, m_pCreateResults); | ||
44 | ConsoleExitOnFailure(hr, CONSOLE_COLOR_RED, "BA returned failure on BootstrapperApplicationCreate."); | ||
45 | |||
46 | LExit: | ||
47 | return hr; | ||
48 | } | ||
49 | |||
50 | HRESULT TestEngine::Log( | ||
51 | __in LPCWSTR wzMessage | ||
52 | ) | ||
53 | { | ||
54 | return ConsoleWriteLine(CONSOLE_COLOR_NORMAL, "%ls", wzMessage); | ||
55 | } | ||
56 | |||
57 | HRESULT TestEngine::SendShutdownEvent( | ||
58 | __in BOOTSTRAPPER_SHUTDOWN_ACTION defaultAction | ||
59 | ) | ||
60 | { | ||
61 | HRESULT hr = S_OK; | ||
62 | BA_ONSHUTDOWN_ARGS shutdownArgs = { }; | ||
63 | BA_ONSHUTDOWN_RESULTS shutdownResults = { }; | ||
64 | shutdownArgs.cbSize = sizeof(BA_ONSHUTDOWN_ARGS); | ||
65 | shutdownResults.action = defaultAction; | ||
66 | shutdownResults.cbSize = sizeof(BA_ONSHUTDOWN_RESULTS); | ||
67 | hr = m_pCreateResults->pfnBootstrapperApplicationProc(BOOTSTRAPPER_APPLICATION_MESSAGE_ONSHUTDOWN, &shutdownArgs, &shutdownResults, m_pCreateResults->pvBootstrapperApplicationProcContext); | ||
68 | return hr; | ||
69 | } | ||
70 | |||
71 | HRESULT TestEngine::BAEngineLog( | ||
72 | __in TestEngine* pContext, | ||
73 | __in BAENGINE_LOG_ARGS* pArgs, | ||
74 | __in BAENGINE_LOG_RESULTS* /*pResults*/ | ||
75 | ) | ||
76 | { | ||
77 | return pContext->Log(pArgs->wzMessage); | ||
78 | } | ||
79 | |||
80 | HRESULT WINAPI TestEngine::EngineProc( | ||
81 | __in BOOTSTRAPPER_ENGINE_MESSAGE message, | ||
82 | __in const LPVOID pvArgs, | ||
83 | __inout LPVOID pvResults, | ||
84 | __in_opt LPVOID pvContext | ||
85 | ) | ||
86 | { | ||
87 | HRESULT hr = S_OK; | ||
88 | TestEngine* pContext = (TestEngine*)pvContext; | ||
89 | |||
90 | if (!pContext || !pvArgs || !pvResults) | ||
91 | { | ||
92 | ExitFunction1(hr = E_INVALIDARG); | ||
93 | } | ||
94 | |||
95 | switch (message) | ||
96 | { | ||
97 | case BOOTSTRAPPER_ENGINE_MESSAGE_LOG: | ||
98 | hr = BAEngineLog(pContext, reinterpret_cast<BAENGINE_LOG_ARGS*>(pvArgs), reinterpret_cast<BAENGINE_LOG_RESULTS*>(pvResults)); | ||
99 | break; | ||
100 | default: | ||
101 | hr = E_NOTIMPL; | ||
102 | break; | ||
103 | } | ||
104 | |||
105 | LExit: | ||
106 | return hr; | ||
107 | } | ||
108 | |||
109 | TestEngine::TestEngine() | ||
110 | { | ||
111 | m_pCreateResults = NULL; | ||
112 | } | ||
113 | |||
114 | TestEngine::~TestEngine() | ||
115 | { | ||
116 | ReleaseMem(m_pCreateResults); | ||
117 | } \ No newline at end of file | ||