diff options
Diffstat (limited to 'src/burn/test')
-rw-r--r-- | src/burn/test/BurnUnitTest/BurnUnitTest.vcxproj | 1 | ||||
-rw-r--r-- | src/burn/test/BurnUnitTest/BurnUnitTest.vcxproj.filters | 3 | ||||
-rw-r--r-- | src/burn/test/BurnUnitTest/ElevationTest.cpp | 2 | ||||
-rw-r--r-- | src/burn/test/BurnUnitTest/EmbeddedTest.cpp | 175 | ||||
-rw-r--r-- | src/burn/test/BurnUnitTest/precomp.h | 1 |
5 files changed, 181 insertions, 1 deletions
diff --git a/src/burn/test/BurnUnitTest/BurnUnitTest.vcxproj b/src/burn/test/BurnUnitTest/BurnUnitTest.vcxproj index f07418a7..5f8004b4 100644 --- a/src/burn/test/BurnUnitTest/BurnUnitTest.vcxproj +++ b/src/burn/test/BurnUnitTest/BurnUnitTest.vcxproj | |||
@@ -47,6 +47,7 @@ | |||
47 | <ClCompile Include="AssemblyInfo.cpp" /> | 47 | <ClCompile Include="AssemblyInfo.cpp" /> |
48 | <ClCompile Include="CacheTest.cpp" /> | 48 | <ClCompile Include="CacheTest.cpp" /> |
49 | <ClCompile Include="ElevationTest.cpp" /> | 49 | <ClCompile Include="ElevationTest.cpp" /> |
50 | <ClCompile Include="EmbeddedTest.cpp" /> | ||
50 | <ClCompile Include="ManifestHelpers.cpp" /> | 51 | <ClCompile Include="ManifestHelpers.cpp" /> |
51 | <ClCompile Include="ManifestTest.cpp" /> | 52 | <ClCompile Include="ManifestTest.cpp" /> |
52 | <ClCompile Include="PlanTest.cpp" /> | 53 | <ClCompile Include="PlanTest.cpp" /> |
diff --git a/src/burn/test/BurnUnitTest/BurnUnitTest.vcxproj.filters b/src/burn/test/BurnUnitTest/BurnUnitTest.vcxproj.filters index 90290f52..9cfe9ee6 100644 --- a/src/burn/test/BurnUnitTest/BurnUnitTest.vcxproj.filters +++ b/src/burn/test/BurnUnitTest/BurnUnitTest.vcxproj.filters | |||
@@ -24,6 +24,9 @@ | |||
24 | <ClCompile Include="ElevationTest.cpp"> | 24 | <ClCompile Include="ElevationTest.cpp"> |
25 | <Filter>Source Files</Filter> | 25 | <Filter>Source Files</Filter> |
26 | </ClCompile> | 26 | </ClCompile> |
27 | <ClCompile Include="EmbeddedTest.cpp"> | ||
28 | <Filter>Source Files</Filter> | ||
29 | </ClCompile> | ||
27 | <ClCompile Include="ManifestHelpers.cpp"> | 30 | <ClCompile Include="ManifestHelpers.cpp"> |
28 | <Filter>Source Files</Filter> | 31 | <Filter>Source Files</Filter> |
29 | </ClCompile> | 32 | </ClCompile> |
diff --git a/src/burn/test/BurnUnitTest/ElevationTest.cpp b/src/burn/test/BurnUnitTest/ElevationTest.cpp index ce34b4b1..8d4cc7ff 100644 --- a/src/burn/test/BurnUnitTest/ElevationTest.cpp +++ b/src/burn/test/BurnUnitTest/ElevationTest.cpp | |||
@@ -61,7 +61,7 @@ namespace Bootstrapper | |||
61 | try | 61 | try |
62 | { | 62 | { |
63 | ShelFunctionOverride(ElevateTest_ShellExecuteExW); | 63 | ShelFunctionOverride(ElevateTest_ShellExecuteExW); |
64 | CoreFunctionOverride(ThrdWaitForCompletion); | 64 | CoreFunctionOverride(NULL, ThrdWaitForCompletion); |
65 | 65 | ||
66 | PipeConnectionInitialize(pConnection); | 66 | PipeConnectionInitialize(pConnection); |
67 | 67 | ||
diff --git a/src/burn/test/BurnUnitTest/EmbeddedTest.cpp b/src/burn/test/BurnUnitTest/EmbeddedTest.cpp new file mode 100644 index 00000000..cac1ba81 --- /dev/null +++ b/src/burn/test/BurnUnitTest/EmbeddedTest.cpp | |||
@@ -0,0 +1,175 @@ | |||
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 | |||
6 | const HRESULT S_TEST_SUCCEEDED = 0x3133; | ||
7 | const DWORD TEST_EXIT_CODE = 666; | ||
8 | |||
9 | struct BUNDLE_RUNNER_CONTEXT | ||
10 | { | ||
11 | DWORD dwResult; | ||
12 | }; | ||
13 | |||
14 | |||
15 | static BOOL STDAPICALLTYPE EmbeddedTest_CreateProcessW( | ||
16 | __in_opt LPCWSTR lpApplicationName, | ||
17 | __inout_opt LPWSTR lpCommandLine, | ||
18 | __in_opt LPSECURITY_ATTRIBUTES lpProcessAttributes, | ||
19 | __in_opt LPSECURITY_ATTRIBUTES lpThreadAttributes, | ||
20 | __in BOOL bInheritHandles, | ||
21 | __in DWORD dwCreationFlags, | ||
22 | __in_opt LPVOID lpEnvironment, | ||
23 | __in_opt LPCWSTR lpCurrentDirectory, | ||
24 | __in LPSTARTUPINFOW lpStartupInfo, | ||
25 | __out LPPROCESS_INFORMATION lpProcessInformation | ||
26 | ); | ||
27 | static DWORD CALLBACK EmbeddedTest_ThreadProc( | ||
28 | __in LPVOID lpThreadParameter | ||
29 | ); | ||
30 | static int EmbeddedTest_GenericMessageHandler( | ||
31 | __in GENERIC_EXECUTE_MESSAGE* pMessage, | ||
32 | __in LPVOID pvContext | ||
33 | ); | ||
34 | |||
35 | namespace Microsoft | ||
36 | { | ||
37 | namespace Tools | ||
38 | { | ||
39 | namespace WindowsInstallerXml | ||
40 | { | ||
41 | namespace Test | ||
42 | { | ||
43 | namespace Bootstrapper | ||
44 | { | ||
45 | using namespace System; | ||
46 | using namespace System::IO; | ||
47 | using namespace System::Threading; | ||
48 | using namespace Xunit; | ||
49 | |||
50 | public ref class EmbeddedTest : BurnUnitTest | ||
51 | { | ||
52 | public: | ||
53 | EmbeddedTest(BurnTestFixture^ fixture) : BurnUnitTest(fixture) | ||
54 | { | ||
55 | } | ||
56 | |||
57 | [Fact] | ||
58 | void EmbeddedProtocolTest() | ||
59 | { | ||
60 | HRESULT hr = S_OK; | ||
61 | BUNDLE_RUNNER_CONTEXT bundleRunnerContext = { }; | ||
62 | DWORD dwExitCode = 0; | ||
63 | |||
64 | try | ||
65 | { | ||
66 | CoreFunctionOverride(EmbeddedTest_CreateProcessW, ThrdWaitForCompletion); | ||
67 | |||
68 | // | ||
69 | // bundle runner setup | ||
70 | // | ||
71 | hr = EmbeddedRunBundle(L"C:\\ignored\\target.exe", L"\"C:\\ignored\\target.exe\"", NULL, EmbeddedTest_GenericMessageHandler, &bundleRunnerContext, &dwExitCode); | ||
72 | TestThrowOnFailure(hr, L"Failed to run embedded bundle."); | ||
73 | |||
74 | // check results | ||
75 | Assert::Equal<HRESULT>(S_TEST_SUCCEEDED, (HRESULT)bundleRunnerContext.dwResult); | ||
76 | Assert::Equal<DWORD>(TEST_EXIT_CODE, dwExitCode); | ||
77 | } | ||
78 | finally | ||
79 | { | ||
80 | } | ||
81 | } | ||
82 | }; | ||
83 | } | ||
84 | } | ||
85 | } | ||
86 | } | ||
87 | } | ||
88 | |||
89 | |||
90 | static BOOL STDAPICALLTYPE EmbeddedTest_CreateProcessW( | ||
91 | __in_opt LPCWSTR /*lpApplicationName*/, | ||
92 | __inout_opt LPWSTR lpCommandLine, | ||
93 | __in_opt LPSECURITY_ATTRIBUTES /*lpProcessAttributes*/, | ||
94 | __in_opt LPSECURITY_ATTRIBUTES /*lpThreadAttributes*/, | ||
95 | __in BOOL /*bInheritHandles*/, | ||
96 | __in DWORD /*dwCreationFlags*/, | ||
97 | __in_opt LPVOID /*lpEnvironment*/, | ||
98 | __in_opt LPCWSTR /*lpCurrentDirectory*/, | ||
99 | __in LPSTARTUPINFOW /*lpStartupInfo*/, | ||
100 | __out LPPROCESS_INFORMATION lpProcessInformation | ||
101 | ) | ||
102 | { | ||
103 | HRESULT hr = S_OK; | ||
104 | LPWSTR scz = NULL; | ||
105 | LPCWSTR wzArgs = lpCommandLine + 24; //skip '"C:\ignored\target.exe" ' | ||
106 | |||
107 | hr = StrAllocString(&scz, wzArgs, 0); | ||
108 | ExitOnFailure(hr, "Failed to copy arguments."); | ||
109 | |||
110 | // Pretend this thread is the embedded process. | ||
111 | lpProcessInformation->hProcess = ::CreateThread(NULL, 0, EmbeddedTest_ThreadProc, scz, 0, NULL); | ||
112 | ExitOnNullWithLastError(lpProcessInformation->hProcess, hr, "Failed to create thread."); | ||
113 | |||
114 | scz = NULL; | ||
115 | |||
116 | LExit: | ||
117 | ReleaseStr(scz); | ||
118 | |||
119 | return SUCCEEDED(hr); | ||
120 | } | ||
121 | |||
122 | static DWORD CALLBACK EmbeddedTest_ThreadProc( | ||
123 | __in LPVOID lpThreadParameter | ||
124 | ) | ||
125 | { | ||
126 | HRESULT hr = S_OK; | ||
127 | LPWSTR sczArguments = (LPWSTR)lpThreadParameter; | ||
128 | BURN_ENGINE_STATE engineState = { }; | ||
129 | BURN_PIPE_CONNECTION* pConnection = &engineState.embeddedConnection; | ||
130 | DWORD dwResult = 0; | ||
131 | |||
132 | engineState.internalCommand.mode = BURN_MODE_EMBEDDED; | ||
133 | |||
134 | PipeConnectionInitialize(pConnection); | ||
135 | |||
136 | StrAlloc(&pConnection->sczName, MAX_PATH); | ||
137 | StrAlloc(&pConnection->sczSecret, MAX_PATH); | ||
138 | |||
139 | // parse command line arguments | ||
140 | if (3 != swscanf_s(sczArguments, L"-burn.embedded %s %s %u", pConnection->sczName, MAX_PATH, pConnection->sczSecret, MAX_PATH, &pConnection->dwProcessId)) | ||
141 | { | ||
142 | ExitWithRootFailure(hr, E_INVALIDARG, "Failed to parse argument string."); | ||
143 | } | ||
144 | |||
145 | // set up connection with parent bundle runner | ||
146 | hr = PipeChildConnect(pConnection, FALSE); | ||
147 | ExitOnFailure(hr, "Failed to connect to parent bundle runner."); | ||
148 | |||
149 | // post known message | ||
150 | hr = ExternalEngineSendEmbeddedError(&engineState, S_TEST_SUCCEEDED, NULL, 0, reinterpret_cast<int*>(&dwResult)); | ||
151 | ExitOnFailure(hr, "Failed to post known message to parent bundle runner."); | ||
152 | |||
153 | LExit: | ||
154 | PipeConnectionUninitialize(pConnection); | ||
155 | ReleaseStr(sczArguments); | ||
156 | |||
157 | return FAILED(hr) ? (DWORD)hr : dwResult; | ||
158 | } | ||
159 | |||
160 | static int EmbeddedTest_GenericMessageHandler( | ||
161 | __in GENERIC_EXECUTE_MESSAGE* pMessage, | ||
162 | __in LPVOID pvContext | ||
163 | ) | ||
164 | { | ||
165 | BUNDLE_RUNNER_CONTEXT* pContext = reinterpret_cast<BUNDLE_RUNNER_CONTEXT*>(pvContext); | ||
166 | DWORD dwResult = 0; | ||
167 | |||
168 | if (GENERIC_EXECUTE_MESSAGE_ERROR == pMessage->type) | ||
169 | { | ||
170 | pContext->dwResult = pMessage->error.dwErrorCode; | ||
171 | dwResult = TEST_EXIT_CODE; | ||
172 | } | ||
173 | |||
174 | return dwResult; | ||
175 | } | ||
diff --git a/src/burn/test/BurnUnitTest/precomp.h b/src/burn/test/BurnUnitTest/precomp.h index 69c62cb2..84e989a4 100644 --- a/src/burn/test/BurnUnitTest/precomp.h +++ b/src/burn/test/BurnUnitTest/precomp.h | |||
@@ -73,6 +73,7 @@ | |||
73 | #include "manifest.h" | 73 | #include "manifest.h" |
74 | #include "splashscreen.h" | 74 | #include "splashscreen.h" |
75 | #include "detect.h" | 75 | #include "detect.h" |
76 | #include "externalengine.h" | ||
76 | 77 | ||
77 | #include "engine.version.h" | 78 | #include "engine.version.h" |
78 | 79 | ||