Skip to content

Commit

Permalink
Automate the test for GetRelatedBundleVariable.
Browse files Browse the repository at this point in the history
  • Loading branch information
rseanhall committed Nov 11, 2022
1 parent 3f6a633 commit 209c921
Show file tree
Hide file tree
Showing 15 changed files with 97 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,9 @@
#include "BalBaseBAFunctions.h"
#include "BalBaseBAFunctionsProc.h"

const DWORD VARIABLE_GROW_FACTOR = 80;
const LPCWSTR STRING_VARIABLE = L"AString";
const LPCWSTR NUMBER_VARIABLE = L"ANumber";

static void CALLBACK BafRelatedBundleVariableTestingTraceError(
__in_z LPCSTR szFile,
__in int iLine,
__in REPORT_LEVEL rl,
__in UINT source,
__in HRESULT hrError,
__in_z __format_string LPCSTR szFormat,
__in va_list args
);

class CBafRelatedBundleVariableTesting : public CBalBaseBAFunctions
{
public: // IBAFunctions
Expand All @@ -32,7 +21,7 @@ class CBafRelatedBundleVariableTesting : public CBalBaseBAFunctions
__in LPCWSTR wzVersion,
__in BOOL fMissingFromCache,
__inout BOOL* pfCancel
)
)
{

HRESULT hr = S_OK;
Expand All @@ -44,14 +33,14 @@ class CBafRelatedBundleVariableTesting : public CBalBaseBAFunctions

if (wzValue)
{
BalLog(BOOTSTRAPPER_LOG_LEVEL_STANDARD, "AString = %ws", wzValue);
BalLog(BOOTSTRAPPER_LOG_LEVEL_STANDARD, "Retrieved related bundle variable with BAFunctions: AString = %ws", wzValue);
}

hr = BalGetRelatedBundleVariable(wzBundleId, NUMBER_VARIABLE, &wzValue);

if (wzValue)
{
BalLog(BOOTSTRAPPER_LOG_LEVEL_STANDARD, "ANumber = %ws", wzValue);
BalLog(BOOTSTRAPPER_LOG_LEVEL_STANDARD, "Retrieved related bundle variable with BAFunctions: ANumber = %ws", wzValue);
}

hr = __super::OnDetectRelatedBundle(wzBundleId, relationType, wzBundleTag, fPerMachine, wzVersion, fMissingFromCache, pfCancel);
Expand Down Expand Up @@ -95,8 +84,6 @@ HRESULT WINAPI CreateBAFunctions(
CBafRelatedBundleVariableTesting* pBAFunctions = NULL;
IBootstrapperEngine* pEngine = NULL;

DutilInitialize(&BafRelatedBundleVariableTestingTraceError);

hr = BalInitializeFromCreateArgs(pArgs->pBootstrapperCreateArgs, &pEngine);
ExitOnFailure(hr, "Failed to initialize Bal.");

Expand All @@ -113,21 +100,3 @@ HRESULT WINAPI CreateBAFunctions(

return hr;
}

static void CALLBACK BafRelatedBundleVariableTestingTraceError(
__in_z LPCSTR /*szFile*/,
__in int /*iLine*/,
__in REPORT_LEVEL /*rl*/,
__in UINT source,
__in HRESULT hrError,
__in_z __format_string LPCSTR szFormat,
__in va_list args
)
{
// BalLogError currently uses the Exit... macros,
// so if expanding the scope need to ensure this doesn't get called recursively.
if (DUTIL_SOURCE_THMUTIL == source)
{
BalLogErrorArgs(hrError, szFormat, args);
}
}
Original file line number Diff line number Diff line change
@@ -1,22 +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. -->
<Project Sdk="WixToolset.Sdk">
<Project>
<PropertyGroup>
<OutputType>Bundle</OutputType>
<BA>customHyperlinkLicense</BA>
<BA>hyperlinkLicense</BA>
<UpgradeCode>{98ACBCF6-B54A-46AF-8990-DFB8795B965B}</UpgradeCode>
<Version Condition=" '$(Version)' == '' ">1.0.0.0</Version>
</PropertyGroup>
<ItemGroup>
<Compile Include="..\..\Templates\Bundle.wxs" Link="Bundle.wxs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\BafRelatedBundleVariableTesting\BafRelatedBundleVariableTesting.vcxproj" Properties="Platform=x86" ReferenceOutputAssembly="false" />
<ProjectReference Include="..\PackageA\PackageA.wixproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="WixToolset.Bal.wixext" />
</ItemGroup>
<Target Name="CopyManualInstructions" AfterTargets="AfterBuild">
<Copy SourceFiles="ManualTests.txt" DestinationFiles="$(OutputPath)ManualTests.txt" />
</Target>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!-- 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. -->
<Project Sdk="WixToolset.Sdk">
<Import Project="BundleA.props" />
<ItemGroup>
<ProjectReference Include="..\PackageAv1\PackageAv1.wixproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="WixToolset.Bal.wixext" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
<!-- 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. -->
<!-- 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. -->


<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs" xmlns:bal="http://wixtoolset.org/schemas/v4/wxs/bal">
<Fragment>
<BootstrapperApplication Id="customHyperlinkLicense">
<!-- WixStandardBootstrapperApplication.RtfLicense -->
<bal:WixStandardBootstrapperApplication LicenseUrl="" Theme="hyperlinkLicense" />
<BootstrapperApplication>
<Payload SourceFile="$(var.BafRelatedBundleVariableTesting.TargetPath)" bal:BAFunctions="yes" />
</BootstrapperApplication>
<PackageGroup Id="BundlePackages">
<MsiPackage Id="PackageA" SourceFile="$(var.PackageA.TargetPath)" />
<MsiPackage Id="PackageA" SourceFile="$(var.PackageAv1.TargetPath)" />
</PackageGroup>
<Variable Name="ANumber" bal:Overridable="yes" Value="42" Persisted="yes" />
<Variable Name="AString" bal:Overridable="yes" Value="This is a test" Persisted="yes" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- 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. -->
<Project Sdk="WixToolset.Sdk">
<Import Project="..\BundleAv1\BundleA.props" />
<PropertyGroup>
<Version>2.0.0.0</Version>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\PackageAv2\PackageAv2.wixproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="WixToolset.Bal.wixext" />
</ItemGroup>
</Project>
15 changes: 15 additions & 0 deletions src/test/burn/TestData/BAFunctionsTests/BundleAv2/BundleAv2.wxs
Original file line number Diff line number Diff line change
@@ -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. -->


<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs" xmlns:bal="http://wixtoolset.org/schemas/v4/wxs/bal">
<Fragment>
<BootstrapperApplication>
<Payload SourceFile="$(var.BafRelatedBundleVariableTesting.TargetPath)" bal:BAFunctions="yes" />
</BootstrapperApplication>
<PackageGroup Id="BundlePackages">
<MsiPackage Id="PackageA" SourceFile="$(var.PackageAv2.TargetPath)" />
</PackageGroup>
<Variable Name="ANumber" bal:Overridable="yes" Value="4242" Persisted="yes" />
<Variable Name="AString" bal:Overridable="yes" Value="This is a test v2" Persisted="yes" />
</Fragment>
</Wix>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!-- 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. -->
<Project>
<PropertyGroup>
<UpgradeCode>{F5E0E236-395D-4E7F-BE0A-00B20F7EAF4B}</UpgradeCode>
</PropertyGroup>
<ItemGroup>
<Compile Include="..\..\Templates\Package.wxs" Link="Package.wxs" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<!-- 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. -->
<Project Sdk="WixToolset.Sdk">
<Import Project="PackageA.props" />
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<!-- 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. -->
<Project Sdk="WixToolset.Sdk">
<Import Project="..\PackageAv1\PackageA.props" />
<PropertyGroup>
<Version>2.0.0.0</Version>
</PropertyGroup>
</Project>
10 changes: 0 additions & 10 deletions src/test/burn/TestData/Manual/BundleD/ManualTests.txt

This file was deleted.

31 changes: 31 additions & 0 deletions src/test/burn/WixToolsetTest.BurnE2E/BAFunctionsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// 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.BurnE2E
{
using WixTestTools;
using Xunit;
using Xunit.Abstractions;

public class BAFunctionsTests : BurnE2ETests
{
public BAFunctionsTests(ITestOutputHelper testOutputHelper) : base(testOutputHelper) { }

[RuntimeFact]
public void LogsPersistedRelatedBundleVariables()
{
this.CreatePackageInstaller("PackageAv1");
this.CreatePackageInstaller("PackageAv2");
var bundleAv1 = this.CreateBundleInstaller("BundleAv1");
var bundleAv2 = this.CreateBundleInstaller("BundleAv2");

bundleAv1.Install();
bundleAv1.VerifyRegisteredAndInPackageCache();

var bundleAv2InstallLogFilePath = bundleAv2.Install();
bundleAv2.VerifyRegisteredAndInPackageCache();

Assert.True(LogVerifier.MessageInLogFileRegex(bundleAv2InstallLogFilePath, @"Retrieved related bundle variable with BAFunctions: ANumber = 42"));
Assert.True(LogVerifier.MessageInLogFileRegex(bundleAv2InstallLogFilePath, @"Retrieved related bundle variable with BAFunctions: AString = This is a test"));
}
}
}

0 comments on commit 209c921

Please sign in to comment.