From 4a176b759c47fa1970fcfd0d9e25c294bda82ef4 Mon Sep 17 00:00:00 2001 From: Sean Hall Date: Sun, 22 Dec 2019 13:51:35 +1100 Subject: Update the MbaHost test project to use an external exe to load the BA, which allows loading a different .NET than the one running the tests. This also allows writing the tests in C# instead of C++/CLI. --- src/Custom.Build.props | 9 ++ .../WixToolsetTest.ManagedHost/MbaHostFixture.cs | 40 +++++++ src/test/WixToolsetTest.ManagedHost/TestEngine.cs | 53 ++++++++++ .../WixToolsetTest.ManagedHost/TestEngineResult.cs | 12 +++ .../WixToolsetTest.ManagedHost.csproj | 31 ++++++ .../BootstrapperApplicationData.xml | Bin 20128 -> 0 bytes src/test/WixToolsetTest.MbaHost/EngineForTest.cpp | 45 -------- src/test/WixToolsetTest.MbaHost/EngineForTest.h | 63 ----------- src/test/WixToolsetTest.MbaHost/MbaHostFixture.cpp | 70 ------------ .../TestManagedBootstrapperApplication.h | 34 ------ .../TestManagedBootstrapperApplicationFactory.h | 25 ----- .../WixToolset.Mba.Host.config | 26 ----- .../WixToolsetTest.MbaHost.vcxproj | 95 ----------------- src/test/WixToolsetTest.MbaHost/packages.config | 15 --- src/test/WixToolsetTest.MbaHost/precomp.cpp | 3 - src/test/WixToolsetTest.MbaHost/precomp.h | 16 --- .../BootstrapperApplicationData.xml | Bin 0 -> 20128 bytes .../Example.FullFramework2MBA.csproj | 77 ++++++++++++++ .../examples/FullFramework2MBA/FullFramework2BA.cs | 27 +++++ .../FullFramework2MBA/FullFramework2BAFactory.cs | 14 +++ .../FullFramework2MBA/Properties/AssemblyInfo.cs | 18 ++++ .../FullFramework2MBA/WixToolset.Mba.Host.config | 20 ++++ .../examples/FullFramework2MBA/packages.config | 4 + .../BootstrapperApplicationData.xml | Bin 0 -> 20128 bytes .../Example.FullFramework4MBA.csproj | 38 +++++++ .../examples/FullFramework4MBA/FullFramework4BA.cs | 27 +++++ .../FullFramework4MBA/FullFramework4BAFactory.cs | 15 +++ .../FullFramework4MBA/WixToolset.Mba.Host.config | 17 +++ .../examples/TestEngine/Example.TestEngine.vcxproj | 70 ++++++++++++ src/test/examples/TestEngine/ExampleTestEngine.cpp | 22 ++++ src/test/examples/TestEngine/ShutdownEngine.cpp | 23 ++++ src/test/examples/TestEngine/TestEngine.cpp | 117 +++++++++++++++++++++ src/test/examples/TestEngine/TestEngine.h | 42 ++++++++ src/test/examples/TestEngine/packages.config | 7 ++ src/test/examples/TestEngine/precomp.cpp | 3 + src/test/examples/TestEngine/precomp.h | 19 ++++ 36 files changed, 705 insertions(+), 392 deletions(-) create mode 100644 src/Custom.Build.props create mode 100644 src/test/WixToolsetTest.ManagedHost/MbaHostFixture.cs create mode 100644 src/test/WixToolsetTest.ManagedHost/TestEngine.cs create mode 100644 src/test/WixToolsetTest.ManagedHost/TestEngineResult.cs create mode 100644 src/test/WixToolsetTest.ManagedHost/WixToolsetTest.ManagedHost.csproj delete mode 100644 src/test/WixToolsetTest.MbaHost/BootstrapperApplicationData.xml delete mode 100644 src/test/WixToolsetTest.MbaHost/EngineForTest.cpp delete mode 100644 src/test/WixToolsetTest.MbaHost/EngineForTest.h delete mode 100644 src/test/WixToolsetTest.MbaHost/MbaHostFixture.cpp delete mode 100644 src/test/WixToolsetTest.MbaHost/TestManagedBootstrapperApplication.h delete mode 100644 src/test/WixToolsetTest.MbaHost/TestManagedBootstrapperApplicationFactory.h delete mode 100644 src/test/WixToolsetTest.MbaHost/WixToolset.Mba.Host.config delete mode 100644 src/test/WixToolsetTest.MbaHost/WixToolsetTest.MbaHost.vcxproj delete mode 100644 src/test/WixToolsetTest.MbaHost/packages.config delete mode 100644 src/test/WixToolsetTest.MbaHost/precomp.cpp delete mode 100644 src/test/WixToolsetTest.MbaHost/precomp.h create mode 100644 src/test/examples/FullFramework2MBA/BootstrapperApplicationData.xml create mode 100644 src/test/examples/FullFramework2MBA/Example.FullFramework2MBA.csproj create mode 100644 src/test/examples/FullFramework2MBA/FullFramework2BA.cs create mode 100644 src/test/examples/FullFramework2MBA/FullFramework2BAFactory.cs create mode 100644 src/test/examples/FullFramework2MBA/Properties/AssemblyInfo.cs create mode 100644 src/test/examples/FullFramework2MBA/WixToolset.Mba.Host.config create mode 100644 src/test/examples/FullFramework2MBA/packages.config create mode 100644 src/test/examples/FullFramework4MBA/BootstrapperApplicationData.xml create mode 100644 src/test/examples/FullFramework4MBA/Example.FullFramework4MBA.csproj create mode 100644 src/test/examples/FullFramework4MBA/FullFramework4BA.cs create mode 100644 src/test/examples/FullFramework4MBA/FullFramework4BAFactory.cs create mode 100644 src/test/examples/FullFramework4MBA/WixToolset.Mba.Host.config create mode 100644 src/test/examples/TestEngine/Example.TestEngine.vcxproj create mode 100644 src/test/examples/TestEngine/ExampleTestEngine.cpp create mode 100644 src/test/examples/TestEngine/ShutdownEngine.cpp create mode 100644 src/test/examples/TestEngine/TestEngine.cpp create mode 100644 src/test/examples/TestEngine/TestEngine.h create mode 100644 src/test/examples/TestEngine/packages.config create mode 100644 src/test/examples/TestEngine/precomp.cpp create mode 100644 src/test/examples/TestEngine/precomp.h (limited to 'src') diff --git a/src/Custom.Build.props b/src/Custom.Build.props new file mode 100644 index 00000000..f4352014 --- /dev/null +++ b/src/Custom.Build.props @@ -0,0 +1,9 @@ + + + + + + $(OutputPath)examples\$(ProjectName)\ + $(OutDir)examples\$(ProjectName)\ + + diff --git a/src/test/WixToolsetTest.ManagedHost/MbaHostFixture.cs b/src/test/WixToolsetTest.ManagedHost/MbaHostFixture.cs new file mode 100644 index 00000000..8da42e77 --- /dev/null +++ b/src/test/WixToolsetTest.ManagedHost/MbaHostFixture.cs @@ -0,0 +1,40 @@ +// 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.ManagedHost +{ + using WixBuildTools.TestSupport; + using Xunit; + + public class MbaHostFixture + { + [Fact] + public void CanLoadFullFramework2MBA() + { + var testEngine = new TestEngine(); + var baFile = TestData.Get(@"..\examples\Example.FullFramework2MBA\mbahost.dll"); + + var result = testEngine.RunShutdownEngine(baFile); + Assert.Equal(0, result.ExitCode); + + var logMessages = result.Output; + Assert.Equal(2, logMessages.Count); + Assert.Equal("Loading managed bootstrapper application.", logMessages[0]); + Assert.Equal("Shutdown,ReloadBootstrapper,0", logMessages[1]); + } + + [Fact] + public void CanLoadFullFramework4MBA() + { + var testEngine = new TestEngine(); + var baFile = TestData.Get(@"..\examples\Example.FullFramework4MBA\net48\mbahost.dll"); + + var result = testEngine.RunShutdownEngine(baFile); + Assert.Equal(0, result.ExitCode); + + var logMessages = result.Output; + 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.ManagedHost/TestEngine.cs b/src/test/WixToolsetTest.ManagedHost/TestEngine.cs new file mode 100644 index 00000000..4dd531ad --- /dev/null +++ b/src/test/WixToolsetTest.ManagedHost/TestEngine.cs @@ -0,0 +1,53 @@ +// 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.ManagedHost +{ + using System.Collections.Generic; + using System.Diagnostics; + using WixBuildTools.TestSupport; + + public class TestEngine + { + private static readonly string TestEngineFile = TestData.Get(@"..\Win32\examples\Example.TestEngine\Example.TestEngine.exe"); + + public TestEngineResult RunShutdownEngine(string baFile) + { + var args = new string[] { '"' + baFile + '"' }; + return RunProcessCaptureOutput(TestEngineFile, args); + } + + private static TestEngineResult RunProcessCaptureOutput(string executablePath, string[] arguments = null, string workingFolder = null) + { + var startInfo = new ProcessStartInfo(executablePath) + { + Arguments = string.Join(' ', arguments), + CreateNoWindow = true, + RedirectStandardError = true, + RedirectStandardOutput = true, + UseShellExecute = false, + WorkingDirectory = workingFolder, + }; + + var exitCode = 0; + var output = new List(); + + using (var process = Process.Start(startInfo)) + { + process.OutputDataReceived += (s, e) => { if (e.Data != null) { output.Add(e.Data); } }; + process.ErrorDataReceived += (s, e) => { if (e.Data != null) { output.Add(e.Data); } }; + + process.BeginErrorReadLine(); + process.BeginOutputReadLine(); + + process.WaitForExit(); + exitCode = process.ExitCode; + } + + return new TestEngineResult + { + ExitCode = exitCode, + Output = output, + }; + } + } +} diff --git a/src/test/WixToolsetTest.ManagedHost/TestEngineResult.cs b/src/test/WixToolsetTest.ManagedHost/TestEngineResult.cs new file mode 100644 index 00000000..63f6f7f5 --- /dev/null +++ b/src/test/WixToolsetTest.ManagedHost/TestEngineResult.cs @@ -0,0 +1,12 @@ +// 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.ManagedHost +{ + using System.Collections.Generic; + + public class TestEngineResult + { + public int ExitCode { get; set; } + public List Output { get; set; } + } +} diff --git a/src/test/WixToolsetTest.ManagedHost/WixToolsetTest.ManagedHost.csproj b/src/test/WixToolsetTest.ManagedHost/WixToolsetTest.ManagedHost.csproj new file mode 100644 index 00000000..cb1d1c78 --- /dev/null +++ b/src/test/WixToolsetTest.ManagedHost/WixToolsetTest.ManagedHost.csproj @@ -0,0 +1,31 @@ + + + + + + netcoreapp2.1 + false + + + + NU1701 + + + + + + + + + + + + + + + + + + + + diff --git a/src/test/WixToolsetTest.MbaHost/BootstrapperApplicationData.xml b/src/test/WixToolsetTest.MbaHost/BootstrapperApplicationData.xml deleted file mode 100644 index 7c4169b1..00000000 Binary files a/src/test/WixToolsetTest.MbaHost/BootstrapperApplicationData.xml and /dev/null differ diff --git a/src/test/WixToolsetTest.MbaHost/EngineForTest.cpp b/src/test/WixToolsetTest.MbaHost/EngineForTest.cpp deleted file mode 100644 index b2567a7b..00000000 --- a/src/test/WixToolsetTest.MbaHost/EngineForTest.cpp +++ /dev/null @@ -1,45 +0,0 @@ -// 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 deleted file mode 100644 index 6058e67c..00000000 --- a/src/test/WixToolsetTest.MbaHost/EngineForTest.h +++ /dev/null @@ -1,63 +0,0 @@ -#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 deleted file mode 100644 index 9328aacf..00000000 --- a/src/test/WixToolsetTest.MbaHost/MbaHostFixture.cpp +++ /dev/null @@ -1,70 +0,0 @@ -// 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 deleted file mode 100644 index d2b53718..00000000 --- a/src/test/WixToolsetTest.MbaHost/TestManagedBootstrapperApplication.h +++ /dev/null @@ -1,34 +0,0 @@ -#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::Mba::Core; - - public ref class TestManagedBootstrapperApplication : BootstrapperApplication - { - public: - TestManagedBootstrapperApplication(WixToolset::Mba::Core::IEngine^ engine) - : BootstrapperApplication(engine) - { - - } - - 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); - } - }; -} -} -} \ No newline at end of file diff --git a/src/test/WixToolsetTest.MbaHost/TestManagedBootstrapperApplicationFactory.h b/src/test/WixToolsetTest.MbaHost/TestManagedBootstrapperApplicationFactory.h deleted file mode 100644 index 86f6e3cb..00000000 --- a/src/test/WixToolsetTest.MbaHost/TestManagedBootstrapperApplicationFactory.h +++ /dev/null @@ -1,25 +0,0 @@ -#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::Mba::Core; - - public ref class TestManagedBootstrapperApplicationFactory : public BaseBootstrapperApplicationFactory - { - protected: - virtual IBootstrapperApplication^ Create(IEngine^ engine, IBootstrapperCommand^ /*command*/) override - { - return gcnew TestManagedBootstrapperApplication(engine); - } - }; - - [assembly:BootstrapperApplicationFactory(TestManagedBootstrapperApplicationFactory::typeid)]; -} -} -} \ No newline at end of file diff --git a/src/test/WixToolsetTest.MbaHost/WixToolset.Mba.Host.config b/src/test/WixToolsetTest.MbaHost/WixToolset.Mba.Host.config deleted file mode 100644 index 53a3d29e..00000000 --- a/src/test/WixToolsetTest.MbaHost/WixToolset.Mba.Host.config +++ /dev/null @@ -1,26 +0,0 @@ - - - - - - - -
- - - - - - - - - - - - - - diff --git a/src/test/WixToolsetTest.MbaHost/WixToolsetTest.MbaHost.vcxproj b/src/test/WixToolsetTest.MbaHost/WixToolsetTest.MbaHost.vcxproj deleted file mode 100644 index d8143880..00000000 --- a/src/test/WixToolsetTest.MbaHost/WixToolsetTest.MbaHost.vcxproj +++ /dev/null @@ -1,95 +0,0 @@ - - - - - - - - - - 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 - - - - - - - - - - - - - - - False - - - - - - - ..\..\..\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.Mba.Core.4.0.12\lib\net20\WixToolset.Mba.Core.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 deleted file mode 100644 index 4e9838f6..00000000 --- a/src/test/WixToolsetTest.MbaHost/packages.config +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/test/WixToolsetTest.MbaHost/precomp.cpp b/src/test/WixToolsetTest.MbaHost/precomp.cpp deleted file mode 100644 index 37664a1c..00000000 --- a/src/test/WixToolsetTest.MbaHost/precomp.cpp +++ /dev/null @@ -1,3 +0,0 @@ -// 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 deleted file mode 100644 index 7c451c03..00000000 --- a/src/test/WixToolsetTest.MbaHost/precomp.h +++ /dev/null @@ -1,16 +0,0 @@ -#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" -#include "TestManagedBootstrapperApplicationFactory.h" diff --git a/src/test/examples/FullFramework2MBA/BootstrapperApplicationData.xml b/src/test/examples/FullFramework2MBA/BootstrapperApplicationData.xml new file mode 100644 index 00000000..7c4169b1 Binary files /dev/null and b/src/test/examples/FullFramework2MBA/BootstrapperApplicationData.xml differ diff --git a/src/test/examples/FullFramework2MBA/Example.FullFramework2MBA.csproj b/src/test/examples/FullFramework2MBA/Example.FullFramework2MBA.csproj new file mode 100644 index 00000000..dec1ff1e --- /dev/null +++ b/src/test/examples/FullFramework2MBA/Example.FullFramework2MBA.csproj @@ -0,0 +1,77 @@ + + + + + + + + {CC4236FC-226E-4232-AB50-24CBEC4D314D} + Example.FullFramework2MBA + Library + Example.FullFramework2MBA + v2.0 + false + + + true + false + $(DefineConstants);DEBUG;TRACE + + + true + true + $(DefineConstants);TRACE + + + + + + + + + + + + + + + + + + + + ..\..\..\..\packages\WixToolset.Mba.Core.4.0.12\lib\net20\WixToolset.Mba.Core.dll + + + + + {12c87c77-3547-44f8-8134-29bc915cb19d} + false + + + {F2BA1935-70FA-4156-B161-FD03850B4FAA} + false + Content + PreserveNewest + + + + + + + + + + + + + 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/examples/FullFramework2MBA/FullFramework2BA.cs b/src/test/examples/FullFramework2MBA/FullFramework2BA.cs new file mode 100644 index 00000000..13d4673a --- /dev/null +++ b/src/test/examples/FullFramework2MBA/FullFramework2BA.cs @@ -0,0 +1,27 @@ +// 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 Example.FullFramework2MBA +{ + using WixToolset.Mba.Core; + + public class FullFramework2BA : BootstrapperApplication + { + public FullFramework2BA(IEngine engine) + : base(engine) + { + + } + + protected override void Run() + { + } + + protected override void OnShutdown(ShutdownEventArgs args) + { + base.OnShutdown(args); + + var message = "Shutdown," + args.Action.ToString() + "," + args.HResult.ToString(); + this.engine.Log(LogLevel.Standard, message); + } + } +} diff --git a/src/test/examples/FullFramework2MBA/FullFramework2BAFactory.cs b/src/test/examples/FullFramework2MBA/FullFramework2BAFactory.cs new file mode 100644 index 00000000..d3cafc70 --- /dev/null +++ b/src/test/examples/FullFramework2MBA/FullFramework2BAFactory.cs @@ -0,0 +1,14 @@ +// 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 Example.FullFramework2MBA +{ + using WixToolset.Mba.Core; + + public class FullFramework2BAFactory : BaseBootstrapperApplicationFactory + { + protected override IBootstrapperApplication Create(IEngine engine, IBootstrapperCommand bootstrapperCommand) + { + return new FullFramework2BA(engine); + } + } +} diff --git a/src/test/examples/FullFramework2MBA/Properties/AssemblyInfo.cs b/src/test/examples/FullFramework2MBA/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..640c17ad --- /dev/null +++ b/src/test/examples/FullFramework2MBA/Properties/AssemblyInfo.cs @@ -0,0 +1,18 @@ +// 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. + +using System; +using System.Reflection; +using System.Runtime.InteropServices; +using WixToolset.Mba.Core; + +[assembly: AssemblyTitle("Example.FullFramework2MBA")] +[assembly: AssemblyDescription("Example.FullFramework2MBA")] +[assembly: AssemblyProduct("WiX Toolset")] +[assembly: AssemblyCompany("WiX Toolset Team")] +[assembly: AssemblyCopyright("Copyright (c) .NET Foundation and contributors. All rights reserved.")] + +// Types should not be visible to COM by default. +[assembly: ComVisible(false)] +[assembly: Guid("7A671EAF-FAE5-41A2-83DD-C35AB3779651")] + +[assembly: BootstrapperApplicationFactory(typeof(Example.FullFramework2MBA.FullFramework2BAFactory))] diff --git a/src/test/examples/FullFramework2MBA/WixToolset.Mba.Host.config b/src/test/examples/FullFramework2MBA/WixToolset.Mba.Host.config new file mode 100644 index 00000000..be450a4f --- /dev/null +++ b/src/test/examples/FullFramework2MBA/WixToolset.Mba.Host.config @@ -0,0 +1,20 @@ + + + + + + + +
+ + + + + + + + + + + + diff --git a/src/test/examples/FullFramework2MBA/packages.config b/src/test/examples/FullFramework2MBA/packages.config new file mode 100644 index 00000000..77b7e398 --- /dev/null +++ b/src/test/examples/FullFramework2MBA/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/src/test/examples/FullFramework4MBA/BootstrapperApplicationData.xml b/src/test/examples/FullFramework4MBA/BootstrapperApplicationData.xml new file mode 100644 index 00000000..7c4169b1 Binary files /dev/null and b/src/test/examples/FullFramework4MBA/BootstrapperApplicationData.xml differ diff --git a/src/test/examples/FullFramework4MBA/Example.FullFramework4MBA.csproj b/src/test/examples/FullFramework4MBA/Example.FullFramework4MBA.csproj new file mode 100644 index 00000000..e044c6b1 --- /dev/null +++ b/src/test/examples/FullFramework4MBA/Example.FullFramework4MBA.csproj @@ -0,0 +1,38 @@ + + + + net48 + Full Framework v4 MBA + + + + + + + + + + + + + + + {12c87c77-3547-44f8-8134-29bc915cb19d} + false + + + {F2BA1935-70FA-4156-B161-FD03850B4FAA} + false + Content + PreserveNewest + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/examples/FullFramework4MBA/FullFramework4BA.cs b/src/test/examples/FullFramework4MBA/FullFramework4BA.cs new file mode 100644 index 00000000..556a61a7 --- /dev/null +++ b/src/test/examples/FullFramework4MBA/FullFramework4BA.cs @@ -0,0 +1,27 @@ +// 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 Example.FullFramework4MBA +{ + using WixToolset.Mba.Core; + + public class FullFramework4BA : BootstrapperApplication + { + public FullFramework4BA(IEngine engine) + : base(engine) + { + + } + + protected override void Run() + { + } + + protected override void OnShutdown(ShutdownEventArgs args) + { + base.OnShutdown(args); + + var message = "Shutdown," + args.Action.ToString() + "," + args.HResult.ToString(); + this.engine.Log(LogLevel.Standard, message); + } + } +} diff --git a/src/test/examples/FullFramework4MBA/FullFramework4BAFactory.cs b/src/test/examples/FullFramework4MBA/FullFramework4BAFactory.cs new file mode 100644 index 00000000..b7c8750d --- /dev/null +++ b/src/test/examples/FullFramework4MBA/FullFramework4BAFactory.cs @@ -0,0 +1,15 @@ +// 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. + +[assembly: WixToolset.Mba.Core.BootstrapperApplicationFactory(typeof(Example.FullFramework4MBA.FullFramework4BAFactory))] +namespace Example.FullFramework4MBA +{ + using WixToolset.Mba.Core; + + public class FullFramework4BAFactory : BaseBootstrapperApplicationFactory + { + protected override IBootstrapperApplication Create(IEngine engine, IBootstrapperCommand bootstrapperCommand) + { + return new FullFramework4BA(engine); + } + } +} diff --git a/src/test/examples/FullFramework4MBA/WixToolset.Mba.Host.config b/src/test/examples/FullFramework4MBA/WixToolset.Mba.Host.config new file mode 100644 index 00000000..96678cda --- /dev/null +++ b/src/test/examples/FullFramework4MBA/WixToolset.Mba.Host.config @@ -0,0 +1,17 @@ + + + + + + + +
+ + + + + + + + + diff --git a/src/test/examples/TestEngine/Example.TestEngine.vcxproj b/src/test/examples/TestEngine/Example.TestEngine.vcxproj new file mode 100644 index 00000000..ab79dacc --- /dev/null +++ b/src/test/examples/TestEngine/Example.TestEngine.vcxproj @@ -0,0 +1,70 @@ + + + + + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + {3D44B67D-A475-49BA-8310-E39F6C117CC9} + Application + Console + Example.TestEngine + v141 + Unicode + $([Microsoft.Build.Utilities.ToolLocationHelper]::GetLatestSDKTargetPlatformVersion('Windows', '10.0')) + + + + + + + + + + + + + + + Create + + + + + + + + + + + + + + + + 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/examples/TestEngine/ExampleTestEngine.cpp b/src/test/examples/TestEngine/ExampleTestEngine.cpp new file mode 100644 index 00000000..9f051875 --- /dev/null +++ b/src/test/examples/TestEngine/ExampleTestEngine.cpp @@ -0,0 +1,22 @@ +// 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" + +int __cdecl wmain(int argc, LPWSTR argv[]) +{ + HRESULT hr = E_INVALIDARG; + + ConsoleInitialize(); + + if (argc != 2) + { + ConsoleWriteError(hr, CONSOLE_COLOR_RED, "Usage: Example.TestEngine.exe BA.dll"); + } + else + { + hr = RunShutdownEngine(argv[1]); + } + + ConsoleUninitialize(); + return HRESULT_CODE(hr); +} diff --git a/src/test/examples/TestEngine/ShutdownEngine.cpp b/src/test/examples/TestEngine/ShutdownEngine.cpp new file mode 100644 index 00000000..69321d91 --- /dev/null +++ b/src/test/examples/TestEngine/ShutdownEngine.cpp @@ -0,0 +1,23 @@ +// 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" + +HRESULT RunShutdownEngine( + __in LPCWSTR wzBAFilePath + ) +{ + HRESULT hr = S_OK; + TestEngine* pTestEngine = NULL; + + pTestEngine = new TestEngine(); + ConsoleExitOnNull(pTestEngine, hr, E_OUTOFMEMORY, CONSOLE_COLOR_RED, "Failed to create new test engine."); + + hr = pTestEngine->LoadBA(wzBAFilePath); + ConsoleExitOnFailure(hr, CONSOLE_COLOR_RED, "Failed to load BA."); + + hr = pTestEngine->SendShutdownEvent(BOOTSTRAPPER_SHUTDOWN_ACTION_RELOAD_BOOTSTRAPPER); + ConsoleExitOnFailure(hr, CONSOLE_COLOR_RED, "BA returned failure for OnShutdown."); + +LExit: + return hr; +} 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 @@ +// 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" + +HRESULT TestEngine::LoadBA( + __in LPCWSTR wzBAFilePath + ) +{ + HRESULT hr = S_OK; + BOOTSTRAPPER_COMMAND command = { }; + BOOTSTRAPPER_CREATE_ARGS args = { }; + HMODULE hBAModule = NULL; + PFN_BOOTSTRAPPER_APPLICATION_CREATE pfnCreate = NULL; + + if (m_pCreateResults) + { + ExitFunction1(hr = E_INVALIDSTATE); + } + + LogInitialize(::GetModuleHandleW(NULL)); + + hr = LogOpen(NULL, L"ExampleTestEngine", NULL, L"txt", FALSE, FALSE, NULL); + ConsoleExitOnFailure(hr, CONSOLE_COLOR_RED, "Failed to open log."); + + m_pCreateResults = static_cast(MemAlloc(sizeof(BOOTSTRAPPER_CREATE_RESULTS), TRUE)); + + command.cbSize = sizeof(BOOTSTRAPPER_COMMAND); + + args.cbSize = sizeof(BOOTSTRAPPER_CREATE_ARGS); + args.pCommand = &command; + args.pfnBootstrapperEngineProc = TestEngine::EngineProc; + args.pvBootstrapperEngineProcContext = this; + args.qwEngineAPIVersion = MAKEQWORDVERSION(0, 0, 0, 1); + + m_pCreateResults->cbSize = sizeof(BOOTSTRAPPER_CREATE_RESULTS); + + hBAModule = ::LoadLibraryExW(wzBAFilePath, NULL, LOAD_WITH_ALTERED_SEARCH_PATH); + ExitOnNullWithLastError(hBAModule, hr, "Failed to load BA dll."); + + pfnCreate = (PFN_BOOTSTRAPPER_APPLICATION_CREATE)::GetProcAddress(hBAModule, "BootstrapperApplicationCreate"); + ConsoleExitOnNull(pfnCreate, hr, E_OUTOFMEMORY, CONSOLE_COLOR_RED, "Failed to get address for BootstrapperApplicationCreate."); + + hr = pfnCreate(&args, m_pCreateResults); + ConsoleExitOnFailure(hr, CONSOLE_COLOR_RED, "BA returned failure on BootstrapperApplicationCreate."); + +LExit: + return hr; +} + +HRESULT TestEngine::Log( + __in LPCWSTR wzMessage + ) +{ + return ConsoleWriteLine(CONSOLE_COLOR_NORMAL, "%ls", wzMessage); +} + +HRESULT TestEngine::SendShutdownEvent( + __in BOOTSTRAPPER_SHUTDOWN_ACTION defaultAction + ) +{ + HRESULT hr = S_OK; + BA_ONSHUTDOWN_ARGS shutdownArgs = { }; + BA_ONSHUTDOWN_RESULTS shutdownResults = { }; + shutdownArgs.cbSize = sizeof(BA_ONSHUTDOWN_ARGS); + shutdownResults.action = defaultAction; + shutdownResults.cbSize = sizeof(BA_ONSHUTDOWN_RESULTS); + hr = m_pCreateResults->pfnBootstrapperApplicationProc(BOOTSTRAPPER_APPLICATION_MESSAGE_ONSHUTDOWN, &shutdownArgs, &shutdownResults, m_pCreateResults->pvBootstrapperApplicationProcContext); + return hr; +} + +HRESULT TestEngine::BAEngineLog( + __in TestEngine* pContext, + __in BAENGINE_LOG_ARGS* pArgs, + __in BAENGINE_LOG_RESULTS* /*pResults*/ + ) +{ + return pContext->Log(pArgs->wzMessage); +} + +HRESULT WINAPI TestEngine::EngineProc( + __in BOOTSTRAPPER_ENGINE_MESSAGE message, + __in const LPVOID pvArgs, + __inout LPVOID pvResults, + __in_opt LPVOID pvContext + ) +{ + HRESULT hr = S_OK; + TestEngine* pContext = (TestEngine*)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; +} + +TestEngine::TestEngine() +{ + m_pCreateResults = NULL; +} + +TestEngine::~TestEngine() +{ + ReleaseMem(m_pCreateResults); +} \ No newline at end of file diff --git a/src/test/examples/TestEngine/TestEngine.h b/src/test/examples/TestEngine/TestEngine.h new file mode 100644 index 00000000..52872100 --- /dev/null +++ b/src/test/examples/TestEngine/TestEngine.h @@ -0,0 +1,42 @@ +#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 "precomp.h" + +class TestEngine +{ +public: + HRESULT LoadBA( + __in LPCWSTR wzBAFilePath + ); + + HRESULT Log( + __in LPCWSTR wzMessage + ); + + HRESULT SendShutdownEvent( + __in BOOTSTRAPPER_SHUTDOWN_ACTION defaultAction + ); + +private: + static HRESULT BAEngineLog( + __in TestEngine* pContext, + __in BAENGINE_LOG_ARGS* pArgs, + __in BAENGINE_LOG_RESULTS* /*pResults*/ + ); + + static HRESULT WINAPI EngineProc( + __in BOOTSTRAPPER_ENGINE_MESSAGE message, + __in const LPVOID pvArgs, + __inout LPVOID pvResults, + __in_opt LPVOID pvContext + ); + +public: + TestEngine(); + + ~TestEngine(); + +private: + BOOTSTRAPPER_CREATE_RESULTS* m_pCreateResults; +}; \ No newline at end of file diff --git a/src/test/examples/TestEngine/packages.config b/src/test/examples/TestEngine/packages.config new file mode 100644 index 00000000..f209d5fb --- /dev/null +++ b/src/test/examples/TestEngine/packages.config @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/src/test/examples/TestEngine/precomp.cpp b/src/test/examples/TestEngine/precomp.cpp new file mode 100644 index 00000000..37664a1c --- /dev/null +++ b/src/test/examples/TestEngine/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/examples/TestEngine/precomp.h b/src/test/examples/TestEngine/precomp.h new file mode 100644 index 00000000..6e867e89 --- /dev/null +++ b/src/test/examples/TestEngine/precomp.h @@ -0,0 +1,19 @@ +#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 "conutil.h" +#include "logutil.h" +#include "memutil.h" + +#include "BootstrapperEngine.h" +#include "BootstrapperApplication.h" + +#include "TestEngine.h" + +HRESULT RunShutdownEngine( + __in LPCWSTR wzBAFilePath + ); -- cgit v1.2.3-55-g6feb