From 8b3488c8c77959f425d0e5f70d27c5b2b1c86125 Mon Sep 17 00:00:00 2001 From: Sean Hall Date: Sun, 28 Feb 2021 21:05:49 -0600 Subject: Use new PackagePayload symbols for the package's payload. #4183 --- .../PackagePayloadFixture.cs | 207 +++++++++++++++++++++ .../PackagePayload/MissingSourceFileAndHash.wxs | 10 + .../PackagePayload/MissingSourceFileAndName.wxs | 10 + .../PackagePayloadInPayloadGroup.wxs | 15 ++ .../TestData/PackagePayload/SpecifiedHash.wxs | 10 + .../SpecifiedHashAndMissingDownloadUrl.wxs | 10 + .../PackagePayload/SpecifiedSourceFileAndHash.wxs | 10 + .../WrongPackagePayloadInPayloadGroup.wxs | 15 ++ .../SingleExeBundle/SingleExeRemotePayload.wxs | 9 +- 9 files changed, 291 insertions(+), 5 deletions(-) create mode 100644 src/test/WixToolsetTest.CoreIntegration/PackagePayloadFixture.cs create mode 100644 src/test/WixToolsetTest.CoreIntegration/TestData/PackagePayload/MissingSourceFileAndHash.wxs create mode 100644 src/test/WixToolsetTest.CoreIntegration/TestData/PackagePayload/MissingSourceFileAndName.wxs create mode 100644 src/test/WixToolsetTest.CoreIntegration/TestData/PackagePayload/PackagePayloadInPayloadGroup.wxs create mode 100644 src/test/WixToolsetTest.CoreIntegration/TestData/PackagePayload/SpecifiedHash.wxs create mode 100644 src/test/WixToolsetTest.CoreIntegration/TestData/PackagePayload/SpecifiedHashAndMissingDownloadUrl.wxs create mode 100644 src/test/WixToolsetTest.CoreIntegration/TestData/PackagePayload/SpecifiedSourceFileAndHash.wxs create mode 100644 src/test/WixToolsetTest.CoreIntegration/TestData/PackagePayload/WrongPackagePayloadInPayloadGroup.wxs (limited to 'src/test') diff --git a/src/test/WixToolsetTest.CoreIntegration/PackagePayloadFixture.cs b/src/test/WixToolsetTest.CoreIntegration/PackagePayloadFixture.cs new file mode 100644 index 00000000..77a21f61 --- /dev/null +++ b/src/test/WixToolsetTest.CoreIntegration/PackagePayloadFixture.cs @@ -0,0 +1,207 @@ +// 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.CoreIntegration +{ + using System.Collections.Generic; + using System.IO; + using System.Linq; + using WixBuildTools.TestSupport; + using WixToolset.Core.TestPackage; + using Xunit; + + public class PackagePayloadFixture + { + [Fact] + public void CanSpecifyPackagePayloadInPayloadGroup() + { + var folder = TestData.Get(@"TestData"); + + using (var fs = new DisposableFileSystem()) + { + var baseFolder = fs.GetFolder(); + var intermediateFolder = Path.Combine(baseFolder, "obj"); + var bundlePath = Path.Combine(baseFolder, @"bin\test.exe"); + var baFolderPath = Path.Combine(baseFolder, "ba"); + var extractFolderPath = Path.Combine(baseFolder, "extract"); + + var result = WixRunner.Execute(new[] + { + "build", + Path.Combine(folder, "PackagePayload", "PackagePayloadInPayloadGroup.wxs"), + Path.Combine(folder, "BundleWithPackageGroupRef", "Bundle.wxs"), + "-bindpath", Path.Combine(folder, "SimpleBundle", "data"), + "-bindpath", Path.Combine(folder, ".Data"), + "-intermediateFolder", intermediateFolder, + "-o", bundlePath, + }); + + result.AssertSuccess(); + + Assert.True(File.Exists(bundlePath)); + + var extractResult = BundleExtractor.ExtractBAContainer(null, bundlePath, baFolderPath, extractFolderPath); + extractResult.AssertSuccess(); + + var exePackageElements = extractResult.SelectManifestNodes("/burn:BurnManifest/burn:Chain/burn:ExePackage"); + var ignoreAttributesByElementName = new Dictionary> + { + { "ExePackage", new List { "CacheId", "InstallSize", "Size" } }, + }; + Assert.Equal(1, exePackageElements.Count); + Assert.Equal("", exePackageElements[0].GetTestXml(ignoreAttributesByElementName)); + } + } + + [Fact] + public void ErrorWhenMissingSourceFileAndHash() + { + var folder = TestData.Get(@"TestData", "PackagePayload"); + + using (var fs = new DisposableFileSystem()) + { + var baseFolder = fs.GetFolder(); + + var result = WixRunner.Execute(false, new[] + { + "build", + Path.Combine(folder, "MissingSourceFileAndHash.wxs"), + "-o", Path.Combine(baseFolder, "test.wixlib") + }); + + Assert.Equal(44, result.ExitCode); + WixAssert.CompareLineByLine(new[] + { + "The MsuPackagePayload element's SourceFile or Hash attribute was not found; one of these is required.", + }, result.Messages.Select(m => m.ToString()).ToArray()); + } + } + + [Fact] + public void ErrorWhenMissingSourceFileAndName() + { + var folder = TestData.Get(@"TestData", "PackagePayload"); + + using (var fs = new DisposableFileSystem()) + { + var baseFolder = fs.GetFolder(); + + var result = WixRunner.Execute(false, new[] + { + "build", + Path.Combine(folder, "MissingSourceFileAndName.wxs"), + "-o", Path.Combine(baseFolder, "test.wixlib") + }); + + Assert.Equal(44, result.ExitCode); + WixAssert.CompareLineByLine(new[] + { + "The MsiPackagePayload element's Name or SourceFile attribute was not found; one of these is required.", + }, result.Messages.Select(m => m.ToString()).ToArray()); + } + } + + [Fact] + public void ErrorWhenSpecifiedHash() + { + var folder = TestData.Get(@"TestData", "PackagePayload"); + + using (var fs = new DisposableFileSystem()) + { + var baseFolder = fs.GetFolder(); + + var result = WixRunner.Execute(new[] + { + "build", + Path.Combine(folder, "SpecifiedHash.wxs"), + "-o", Path.Combine(baseFolder, "test.wixlib") + }); + + Assert.Equal(4, result.ExitCode); + WixAssert.CompareLineByLine(new[] + { + "The MspPackagePayload element contains an unexpected attribute 'Hash'.", + }, result.Messages.Select(m => m.ToString()).ToArray()); + } + } + + [Fact] + public void ErrorWhenSpecifiedHashAndMissingDownloadUrl() + { + var folder = TestData.Get(@"TestData", "PackagePayload"); + + using (var fs = new DisposableFileSystem()) + { + var baseFolder = fs.GetFolder(); + + var result = WixRunner.Execute(new[] + { + "build", + Path.Combine(folder, "SpecifiedHashAndMissingDownloadUrl.wxs"), + "-o", Path.Combine(baseFolder, "test.wixlib") + }); + + Assert.Equal(10, result.ExitCode); + WixAssert.CompareLineByLine(new[] + { + "The MsuPackagePayload/@DownloadUrl attribute was not found; it is required when attribute Hash is specified.", + }, result.Messages.Select(m => m.ToString()).ToArray()); + } + } + + [Fact] + public void ErrorWhenSpecifiedSourceFileAndHash() + { + var folder = TestData.Get(@"TestData", "PackagePayload"); + + using (var fs = new DisposableFileSystem()) + { + var baseFolder = fs.GetFolder(); + + var result = WixRunner.Execute(new[] + { + "build", + Path.Combine(folder, "SpecifiedSourceFileAndHash.wxs"), + "-o", Path.Combine(baseFolder, "test.wixlib") + }); + + Assert.Equal(35, result.ExitCode); + WixAssert.CompareLineByLine(new[] + { + "The ExePackagePayload/@Hash attribute cannot be specified when attribute SourceFile is present.", + }, result.Messages.Select(m => m.ToString()).ToArray()); + } + } + + [Fact] + public void ErrorWhenWrongPackagePayloadInPayloadGroup() + { + var folder = TestData.Get(@"TestData"); + + using (var fs = new DisposableFileSystem()) + { + var baseFolder = fs.GetFolder(); + var intermediateFolder = Path.Combine(baseFolder, "obj"); + var bundlePath = Path.Combine(baseFolder, @"bin\test.exe"); + + var result = WixRunner.Execute(new[] + { + "build", + Path.Combine(folder, "PackagePayload", "WrongPackagePayloadInPayloadGroup.wxs"), + Path.Combine(folder, "BundleWithPackageGroupRef", "Bundle.wxs"), + "-bindpath", Path.Combine(folder, "SimpleBundle", "data"), + "-bindpath", Path.Combine(folder, ".Data"), + "-intermediateFolder", intermediateFolder, + "-o", bundlePath, + }); + + Assert.Equal(407, result.ExitCode); + WixAssert.CompareLineByLine(new[] + { + "The ExePackagePayload element can only be used for ExePackages.", + "The location of the package related to previous error.", + "There is no payload defined for package 'WrongPackagePayloadInPayloadGroup'. This is specified on the MsiPackage element or a child MsiPackagePayload element.", + }, result.Messages.Select(m => m.ToString()).ToArray()); + } + } + } +} diff --git a/src/test/WixToolsetTest.CoreIntegration/TestData/PackagePayload/MissingSourceFileAndHash.wxs b/src/test/WixToolsetTest.CoreIntegration/TestData/PackagePayload/MissingSourceFileAndHash.wxs new file mode 100644 index 00000000..5e1b99ff --- /dev/null +++ b/src/test/WixToolsetTest.CoreIntegration/TestData/PackagePayload/MissingSourceFileAndHash.wxs @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/src/test/WixToolsetTest.CoreIntegration/TestData/PackagePayload/MissingSourceFileAndName.wxs b/src/test/WixToolsetTest.CoreIntegration/TestData/PackagePayload/MissingSourceFileAndName.wxs new file mode 100644 index 00000000..f220d81a --- /dev/null +++ b/src/test/WixToolsetTest.CoreIntegration/TestData/PackagePayload/MissingSourceFileAndName.wxs @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/src/test/WixToolsetTest.CoreIntegration/TestData/PackagePayload/PackagePayloadInPayloadGroup.wxs b/src/test/WixToolsetTest.CoreIntegration/TestData/PackagePayload/PackagePayloadInPayloadGroup.wxs new file mode 100644 index 00000000..149870a4 --- /dev/null +++ b/src/test/WixToolsetTest.CoreIntegration/TestData/PackagePayload/PackagePayloadInPayloadGroup.wxs @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/src/test/WixToolsetTest.CoreIntegration/TestData/PackagePayload/SpecifiedHash.wxs b/src/test/WixToolsetTest.CoreIntegration/TestData/PackagePayload/SpecifiedHash.wxs new file mode 100644 index 00000000..3c361c49 --- /dev/null +++ b/src/test/WixToolsetTest.CoreIntegration/TestData/PackagePayload/SpecifiedHash.wxs @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/src/test/WixToolsetTest.CoreIntegration/TestData/PackagePayload/SpecifiedHashAndMissingDownloadUrl.wxs b/src/test/WixToolsetTest.CoreIntegration/TestData/PackagePayload/SpecifiedHashAndMissingDownloadUrl.wxs new file mode 100644 index 00000000..8e62f660 --- /dev/null +++ b/src/test/WixToolsetTest.CoreIntegration/TestData/PackagePayload/SpecifiedHashAndMissingDownloadUrl.wxs @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/src/test/WixToolsetTest.CoreIntegration/TestData/PackagePayload/SpecifiedSourceFileAndHash.wxs b/src/test/WixToolsetTest.CoreIntegration/TestData/PackagePayload/SpecifiedSourceFileAndHash.wxs new file mode 100644 index 00000000..f79da874 --- /dev/null +++ b/src/test/WixToolsetTest.CoreIntegration/TestData/PackagePayload/SpecifiedSourceFileAndHash.wxs @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/src/test/WixToolsetTest.CoreIntegration/TestData/PackagePayload/WrongPackagePayloadInPayloadGroup.wxs b/src/test/WixToolsetTest.CoreIntegration/TestData/PackagePayload/WrongPackagePayloadInPayloadGroup.wxs new file mode 100644 index 00000000..dda306cf --- /dev/null +++ b/src/test/WixToolsetTest.CoreIntegration/TestData/PackagePayload/WrongPackagePayloadInPayloadGroup.wxs @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/src/test/WixToolsetTest.CoreIntegration/TestData/SingleExeBundle/SingleExeRemotePayload.wxs b/src/test/WixToolsetTest.CoreIntegration/TestData/SingleExeBundle/SingleExeRemotePayload.wxs index 79ba52d2..56f08ba9 100644 --- a/src/test/WixToolsetTest.CoreIntegration/TestData/SingleExeBundle/SingleExeRemotePayload.wxs +++ b/src/test/WixToolsetTest.CoreIntegration/TestData/SingleExeBundle/SingleExeRemotePayload.wxs @@ -13,11 +13,10 @@ Vital="yes" Permanent="yes" Protocol="netfx4" - DownloadUrl="C" - LogPathVariable="NetFx462FullLog" - Compressed="no" - Name="NDP462-KB3151802-Web.exe"> - +