From 391057093e45db2d4b2450bd236b9e1fc4cfd53c Mon Sep 17 00:00:00 2001 From: Sean Hall Date: Wed, 13 Feb 2019 20:13:57 -0600 Subject: Add test for creating a Managed BA through mbahost. --- src/Cpp.Build.props | 10 +-- .../BootstrapperApplicationData.xml | Bin 0 -> 20128 bytes src/test/WixToolsetTest.MbaHost/EngineForTest.cpp | 45 ++++++++++ src/test/WixToolsetTest.MbaHost/EngineForTest.h | 63 ++++++++++++++ src/test/WixToolsetTest.MbaHost/MbaHostFixture.cpp | 70 ++++++++++++++++ .../TestManagedBootstrapperApplication.h | 30 +++++++ .../WixToolset.BootstrapperCore.config | 26 ++++++ .../WixToolsetTest.MbaHost.vcxproj | 91 +++++++++++++++++++++ src/test/WixToolsetTest.MbaHost/packages.config | 14 ++++ src/test/WixToolsetTest.MbaHost/precomp.cpp | 3 + src/test/WixToolsetTest.MbaHost/precomp.h | 15 ++++ 11 files changed, 361 insertions(+), 6 deletions(-) create mode 100644 src/test/WixToolsetTest.MbaHost/BootstrapperApplicationData.xml create mode 100644 src/test/WixToolsetTest.MbaHost/EngineForTest.cpp create mode 100644 src/test/WixToolsetTest.MbaHost/EngineForTest.h create mode 100644 src/test/WixToolsetTest.MbaHost/MbaHostFixture.cpp create mode 100644 src/test/WixToolsetTest.MbaHost/TestManagedBootstrapperApplication.h create mode 100644 src/test/WixToolsetTest.MbaHost/WixToolset.BootstrapperCore.config create mode 100644 src/test/WixToolsetTest.MbaHost/WixToolsetTest.MbaHost.vcxproj create mode 100644 src/test/WixToolsetTest.MbaHost/packages.config create mode 100644 src/test/WixToolsetTest.MbaHost/precomp.cpp create mode 100644 src/test/WixToolsetTest.MbaHost/precomp.h (limited to 'src') diff --git a/src/Cpp.Build.props b/src/Cpp.Build.props index 0e00132b..a90fec2c 100644 --- a/src/Cpp.Build.props +++ b/src/Cpp.Build.props @@ -11,6 +11,10 @@ $([Microsoft.Build.Utilities.ToolLocationHelper]::GetLatestSDKTargetPlatformVersion('Windows', '10.0')) + + + 4564;4691 + @@ -95,10 +99,4 @@ MultiThreadedDll - - - $(LinkKeyFile) - $(LinkDelaySign) - - diff --git a/src/test/WixToolsetTest.MbaHost/BootstrapperApplicationData.xml b/src/test/WixToolsetTest.MbaHost/BootstrapperApplicationData.xml new file mode 100644 index 00000000..7c4169b1 Binary files /dev/null and b/src/test/WixToolsetTest.MbaHost/BootstrapperApplicationData.xml differ diff --git a/src/test/WixToolsetTest.MbaHost/EngineForTest.cpp b/src/test/WixToolsetTest.MbaHost/EngineForTest.cpp new file mode 100644 index 00000000..b2567a7b --- /dev/null +++ b/src/test/WixToolsetTest.MbaHost/EngineForTest.cpp @@ -0,0 +1,45 @@ +// 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. + +#include "precomp.h" + +static HRESULT BAEngineLog( + __in BOOTSTRAPPER_ENGINE_CONTEXT* pContext, + __in BAENGINE_LOG_ARGS* pArgs, + __in BAENGINE_LOG_RESULTS* /*pResults*/ +) +{ + HRESULT hr = S_OK; + + pContext->pfnLog(pArgs->wzMessage); + + return hr; +} + +HRESULT WINAPI EngineForTestProc( + __in BOOTSTRAPPER_ENGINE_MESSAGE message, + __in const LPVOID pvArgs, + __inout LPVOID pvResults, + __in_opt LPVOID pvContext +) +{ + HRESULT hr = S_OK; + BOOTSTRAPPER_ENGINE_CONTEXT* pContext = reinterpret_cast(pvContext); + + if (!pContext || !pvArgs || !pvResults) + { + ExitFunction1(hr = E_INVALIDARG); + } + + switch (message) + { + case BOOTSTRAPPER_ENGINE_MESSAGE_LOG: + hr = BAEngineLog(pContext, reinterpret_cast(pvArgs), reinterpret_cast(pvResults)); + break; + default: + hr = E_NOTIMPL; + break; + } + +LExit: + return hr; +} \ No newline at end of file diff --git a/src/test/WixToolsetTest.MbaHost/EngineForTest.h b/src/test/WixToolsetTest.MbaHost/EngineForTest.h new file mode 100644 index 00000000..6058e67c --- /dev/null +++ b/src/test/WixToolsetTest.MbaHost/EngineForTest.h @@ -0,0 +1,63 @@ +#pragma once +// 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. + +HRESULT WINAPI EngineForTestProc( + __in BOOTSTRAPPER_ENGINE_MESSAGE message, + __in const LPVOID pvArgs, + __inout LPVOID pvResults, + __in_opt LPVOID pvContext +); + +typedef void(WINAPI *PFN_TEST_LOG_PROC)( + __in LPCWSTR sczMessage + ); + +struct BOOTSTRAPPER_ENGINE_CONTEXT +{ + PFN_TEST_LOG_PROC pfnLog; +}; + +namespace WixToolsetTest +{ +namespace MbaHost +{ +namespace Native +{ + using namespace System; + using namespace System::Collections::Generic; + using namespace System::Runtime::InteropServices; + + public ref class EngineForTest + { + private: + delegate void LogDelegate(LPCWSTR); + LogDelegate^ _logDelegate; + List^ _messages; + + void Log(LPCWSTR sczMessage) + { + String^ message = gcnew String(sczMessage); + System::Diagnostics::Debug::WriteLine(message); + _messages->Add(message); + } + public: + EngineForTest() + { + _logDelegate = gcnew LogDelegate(this, &EngineForTest::Log); + _messages = gcnew List(); + } + + List^ GetLogMessages() + { + return _messages; + } + + PFN_TEST_LOG_PROC GetTestLogProc() + { + IntPtr functionPointer = Marshal::GetFunctionPointerForDelegate(_logDelegate); + return static_cast(functionPointer.ToPointer()); + } + }; +} +} +} \ No newline at end of file diff --git a/src/test/WixToolsetTest.MbaHost/MbaHostFixture.cpp b/src/test/WixToolsetTest.MbaHost/MbaHostFixture.cpp new file mode 100644 index 00000000..9328aacf --- /dev/null +++ b/src/test/WixToolsetTest.MbaHost/MbaHostFixture.cpp @@ -0,0 +1,70 @@ +// 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. + +#include "precomp.h" + +namespace WixToolsetTest +{ +namespace MbaHost +{ +namespace Native +{ + using namespace System; + using namespace Xunit; + + public ref class MbaHostFixture + { + public: + [Fact] + void CanLoadManagedBootstrapperApplication() + { + HMODULE hBAModule = NULL; + PFN_BOOTSTRAPPER_APPLICATION_CREATE pfnCreate = NULL; + HRESULT hr = S_OK; + + EngineForTest^ engine = gcnew EngineForTest(); + BOOTSTRAPPER_ENGINE_CONTEXT engineContext = { }; + engineContext.pfnLog = engine->GetTestLogProc(); + + LogInitialize(::GetModuleHandleW(NULL)); + + hr = LogOpen(NULL, L"MbaHostUnitTest", NULL, L"txt", FALSE, FALSE, NULL); + Assert::Equal(S_OK, hr); + + BOOTSTRAPPER_COMMAND command = { }; + BOOTSTRAPPER_CREATE_ARGS args = { }; + BOOTSTRAPPER_CREATE_RESULTS results = { }; + + args.cbSize = sizeof(BOOTSTRAPPER_CREATE_ARGS); + args.pCommand = &command; + args.pfnBootstrapperEngineProc = EngineForTestProc; + args.pvBootstrapperEngineProcContext = &engineContext; + args.qwEngineAPIVersion = MAKEQWORDVERSION(0, 0, 0, 1); + + results.cbSize = sizeof(BOOTSTRAPPER_CREATE_RESULTS); + + hBAModule = ::LoadLibraryExW(L"mbahost.dll", NULL, LOAD_WITH_ALTERED_SEARCH_PATH); + Assert::NotEqual(NULL, (int)hBAModule); + + pfnCreate = (PFN_BOOTSTRAPPER_APPLICATION_CREATE)::GetProcAddress(hBAModule, "BootstrapperApplicationCreate"); + Assert::NotEqual(NULL, (int)pfnCreate); + + hr = pfnCreate(&args, &results); + Assert::Equal(S_OK, hr); + + BA_ONSHUTDOWN_ARGS shutdownArgs = { }; + BA_ONSHUTDOWN_RESULTS shutdownResults = { }; + shutdownArgs.cbSize = sizeof(BA_ONSHUTDOWN_ARGS); + shutdownResults.action = BOOTSTRAPPER_SHUTDOWN_ACTION_RELOAD_BOOTSTRAPPER; + shutdownResults.cbSize = sizeof(BA_ONSHUTDOWN_RESULTS); + hr = results.pfnBootstrapperApplicationProc(BOOTSTRAPPER_APPLICATION_MESSAGE_ONSHUTDOWN, &shutdownArgs, &shutdownResults, results.pvBootstrapperApplicationProcContext); + Assert::Equal(S_OK, hr); + + List^ logMessages = engine->GetLogMessages(); + Assert::Equal(2, logMessages->Count); + Assert::Equal("Loading managed bootstrapper application.", logMessages[0]); + Assert::Equal("Shutdown,ReloadBootstrapper,0", logMessages[1]); + } + }; +} +} +} diff --git a/src/test/WixToolsetTest.MbaHost/TestManagedBootstrapperApplication.h b/src/test/WixToolsetTest.MbaHost/TestManagedBootstrapperApplication.h new file mode 100644 index 00000000..1dfd0d4d --- /dev/null +++ b/src/test/WixToolsetTest.MbaHost/TestManagedBootstrapperApplication.h @@ -0,0 +1,30 @@ +#pragma once +// 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. + +namespace WixToolsetTest +{ +namespace MbaHost +{ +namespace Native +{ + using namespace System; + using namespace WixToolset::BootstrapperCore; + + public ref class TestManagedBootstrapperApplication : BootstrapperApplication + { + public: + virtual void Run() override + { + } + + virtual void OnShutdown(ShutdownEventArgs^ e) override + { + String^ message = "Shutdown," + e->Action.ToString() + "," + e->HResult.ToString(); + this->Engine->Log(LogLevel::Standard, message); + } + }; + + [assembly:BootstrapperApplication(TestManagedBootstrapperApplication::typeid)]; +} +} +} \ No newline at end of file diff --git a/src/test/WixToolsetTest.MbaHost/WixToolset.BootstrapperCore.config b/src/test/WixToolsetTest.MbaHost/WixToolset.BootstrapperCore.config new file mode 100644 index 00000000..b4c67a82 --- /dev/null +++ b/src/test/WixToolsetTest.MbaHost/WixToolset.BootstrapperCore.config @@ -0,0 +1,26 @@ + + + + + + + +
+ + + + + + + + + + + + + + diff --git a/src/test/WixToolsetTest.MbaHost/WixToolsetTest.MbaHost.vcxproj b/src/test/WixToolsetTest.MbaHost/WixToolsetTest.MbaHost.vcxproj new file mode 100644 index 00000000..557aaff0 --- /dev/null +++ b/src/test/WixToolsetTest.MbaHost/WixToolsetTest.MbaHost.vcxproj @@ -0,0 +1,91 @@ + + + + + + + + + + Debug + Win32 + + + Release + Win32 + + + + {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942} + {8C131CB9-7B1C-4B06-A328-E69CE9EDC763} + WixToolsetTest.MbaHost + ManagedCProj + DynamicLibrary + v141 + Unicode + true + v4.6.1 + + + + + + + + + + + Create + + + + + + + + + + + + + + + + + + ..\..\..\packages\xunit.abstractions.2.0.2\lib\net35\xunit.abstractions.dll + + + ..\..\..\packages\xunit.assert.2.4.0\lib\netstandard2.0\xunit.assert.dll + + + ..\..\..\packages\xunit.extensibility.core.2.4.0\lib\net452\xunit.core.dll + + + ..\..\..\packages\xunit.extensibility.execution.2.4.0\lib\net452\xunit.execution.desktop.dll + + + ..\..\..\packages\WixToolset.BootstrapperCore.4.0.3\lib\net20\WixToolset.BootstrapperCore.dll + + + + + {12c87c77-3547-44f8-8134-29bc915cb19d} + + + + + + + + + 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}. + + + + + + + + + \ No newline at end of file diff --git a/src/test/WixToolsetTest.MbaHost/packages.config b/src/test/WixToolsetTest.MbaHost/packages.config new file mode 100644 index 00000000..c3b6551c --- /dev/null +++ b/src/test/WixToolsetTest.MbaHost/packages.config @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/WixToolsetTest.MbaHost/precomp.cpp b/src/test/WixToolsetTest.MbaHost/precomp.cpp new file mode 100644 index 00000000..37664a1c --- /dev/null +++ b/src/test/WixToolsetTest.MbaHost/precomp.cpp @@ -0,0 +1,3 @@ +// 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. + +#include "precomp.h" diff --git a/src/test/WixToolsetTest.MbaHost/precomp.h b/src/test/WixToolsetTest.MbaHost/precomp.h new file mode 100644 index 00000000..aa4b6ddc --- /dev/null +++ b/src/test/WixToolsetTest.MbaHost/precomp.h @@ -0,0 +1,15 @@ +#pragma once +// 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. + + +#include +#include + +#include "dutil.h" +#include "logutil.h" + +#include "BootstrapperEngine.h" +#include "BootstrapperApplication.h" + +#include "EngineForTest.h" +#include "TestManagedBootstrapperApplication.h" -- cgit v1.2.3-55-g6feb