From 347d22f5d5e17bf020fc0c99f1e121e77fcc805c Mon Sep 17 00:00:00 2001 From: Sean Hall Date: Wed, 27 Jan 2021 20:16:39 -0600 Subject: Port the patch tests from the old repo. --- src/TestData/PatchTests/BundleA/BundleA.wixproj | 18 +++ src/TestData/PatchTests/BundleA/BundleA.wxs | 11 ++ .../PatchTests/BundlePatchA/BundlePatchA.wixproj | 18 +++ .../PatchTests/BundlePatchA/BundlePatchA.wxs | 11 ++ .../PatchTests/BundlePatchA2/BundlePatchA2.wixproj | 19 +++ .../PatchTests/BundlePatchA2/BundlePatchA2.wxs | 12 ++ src/TestData/PatchTests/PackageAv1/PackageA.props | 12 ++ .../PatchTests/PackageAv1/PackageAv1.wixproj | 4 + .../PatchTests/PackageAv1/ProductComponents.wxs | 17 +++ .../PackageAv1_0_1/PackageAv1_0_1.wixproj | 10 ++ src/TestData/PatchTests/PatchA/PatchA.wixproj | 12 ++ src/TestData/PatchTests/PatchA/PatchA.wxs | 24 ++++ src/TestData/PatchTests/PatchA2/PatchA2.wixproj | 12 ++ src/TestData/PatchTests/PatchA2/PatchA2.wxs | 23 ++++ src/TestData/Templates/Package.wxs | 9 +- src/Wix.Build.targets | 2 + src/WixToolsetTest.BurnE2E/BurnE2ETests.cs | 4 +- src/WixToolsetTest.BurnE2E/PackageInstaller.cs | 7 +- src/WixToolsetTest.BurnE2E/PackageVerifier.cs | 33 ++++- src/WixToolsetTest.BurnE2E/PatchTests.cs | 137 +++++++++++++++++++++ src/WixToolsetTest.BurnE2E/WixTestContext.cs | 2 +- .../WixToolsetTest.BurnE2E.csproj | 2 +- 22 files changed, 387 insertions(+), 12 deletions(-) create mode 100644 src/TestData/PatchTests/BundleA/BundleA.wixproj create mode 100644 src/TestData/PatchTests/BundleA/BundleA.wxs create mode 100644 src/TestData/PatchTests/BundlePatchA/BundlePatchA.wixproj create mode 100644 src/TestData/PatchTests/BundlePatchA/BundlePatchA.wxs create mode 100644 src/TestData/PatchTests/BundlePatchA2/BundlePatchA2.wixproj create mode 100644 src/TestData/PatchTests/BundlePatchA2/BundlePatchA2.wxs create mode 100644 src/TestData/PatchTests/PackageAv1/PackageA.props create mode 100644 src/TestData/PatchTests/PackageAv1/PackageAv1.wixproj create mode 100644 src/TestData/PatchTests/PackageAv1/ProductComponents.wxs create mode 100644 src/TestData/PatchTests/PackageAv1_0_1/PackageAv1_0_1.wixproj create mode 100644 src/TestData/PatchTests/PatchA/PatchA.wixproj create mode 100644 src/TestData/PatchTests/PatchA/PatchA.wxs create mode 100644 src/TestData/PatchTests/PatchA2/PatchA2.wixproj create mode 100644 src/TestData/PatchTests/PatchA2/PatchA2.wxs create mode 100644 src/WixToolsetTest.BurnE2E/PatchTests.cs (limited to 'src') diff --git a/src/TestData/PatchTests/BundleA/BundleA.wixproj b/src/TestData/PatchTests/BundleA/BundleA.wixproj new file mode 100644 index 00000000..bbdace55 --- /dev/null +++ b/src/TestData/PatchTests/BundleA/BundleA.wixproj @@ -0,0 +1,18 @@ + + + + Bundle + {486FC795-69A5-4130-8727-4068F645A0A1} + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/TestData/PatchTests/BundleA/BundleA.wxs b/src/TestData/PatchTests/BundleA/BundleA.wxs new file mode 100644 index 00000000..d40351a1 --- /dev/null +++ b/src/TestData/PatchTests/BundleA/BundleA.wxs @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/src/TestData/PatchTests/BundlePatchA/BundlePatchA.wixproj b/src/TestData/PatchTests/BundlePatchA/BundlePatchA.wixproj new file mode 100644 index 00000000..5846fce5 --- /dev/null +++ b/src/TestData/PatchTests/BundlePatchA/BundlePatchA.wixproj @@ -0,0 +1,18 @@ + + + + Bundle + {AA083618-6280-44B8-9899-57BCC57906A5} + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/TestData/PatchTests/BundlePatchA/BundlePatchA.wxs b/src/TestData/PatchTests/BundlePatchA/BundlePatchA.wxs new file mode 100644 index 00000000..89f24936 --- /dev/null +++ b/src/TestData/PatchTests/BundlePatchA/BundlePatchA.wxs @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/src/TestData/PatchTests/BundlePatchA2/BundlePatchA2.wixproj b/src/TestData/PatchTests/BundlePatchA2/BundlePatchA2.wixproj new file mode 100644 index 00000000..dee4a0f3 --- /dev/null +++ b/src/TestData/PatchTests/BundlePatchA2/BundlePatchA2.wixproj @@ -0,0 +1,19 @@ + + + + Bundle + {1BE09331-2327-4534-9223-59B54EFAE7A5} + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/TestData/PatchTests/BundlePatchA2/BundlePatchA2.wxs b/src/TestData/PatchTests/BundlePatchA2/BundlePatchA2.wxs new file mode 100644 index 00000000..f2c44ad4 --- /dev/null +++ b/src/TestData/PatchTests/BundlePatchA2/BundlePatchA2.wxs @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/src/TestData/PatchTests/PackageAv1/PackageA.props b/src/TestData/PatchTests/PackageAv1/PackageA.props new file mode 100644 index 00000000..1209d09e --- /dev/null +++ b/src/TestData/PatchTests/PackageAv1/PackageA.props @@ -0,0 +1,12 @@ + + + + PackageA + true + {724F9BA5-DD9D-4851-855E-ECC35B27BF11} + {C56DA396-7A9A-4177-8264-638161CE9EB8} + + + + + \ No newline at end of file diff --git a/src/TestData/PatchTests/PackageAv1/PackageAv1.wixproj b/src/TestData/PatchTests/PackageAv1/PackageAv1.wixproj new file mode 100644 index 00000000..45d3b2c8 --- /dev/null +++ b/src/TestData/PatchTests/PackageAv1/PackageAv1.wixproj @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/src/TestData/PatchTests/PackageAv1/ProductComponents.wxs b/src/TestData/PatchTests/PackageAv1/ProductComponents.wxs new file mode 100644 index 00000000..81c6da0c --- /dev/null +++ b/src/TestData/PatchTests/PackageAv1/ProductComponents.wxs @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + diff --git a/src/TestData/PatchTests/PackageAv1_0_1/PackageAv1_0_1.wixproj b/src/TestData/PatchTests/PackageAv1_0_1/PackageAv1_0_1.wixproj new file mode 100644 index 00000000..9ceda117 --- /dev/null +++ b/src/TestData/PatchTests/PackageAv1_0_1/PackageAv1_0_1.wixproj @@ -0,0 +1,10 @@ + + + + + 1.0.1.0 + + + + + \ No newline at end of file diff --git a/src/TestData/PatchTests/PatchA/PatchA.wixproj b/src/TestData/PatchTests/PatchA/PatchA.wixproj new file mode 100644 index 00000000..da9acb5e --- /dev/null +++ b/src/TestData/PatchTests/PatchA/PatchA.wixproj @@ -0,0 +1,12 @@ + + + + PatchCreation + .msp + 1079 + + + + + + \ No newline at end of file diff --git a/src/TestData/PatchTests/PatchA/PatchA.wxs b/src/TestData/PatchTests/PatchA/PatchA.wxs new file mode 100644 index 00000000..067f25ca --- /dev/null +++ b/src/TestData/PatchTests/PatchA/PatchA.wxs @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/src/TestData/PatchTests/PatchA2/PatchA2.wixproj b/src/TestData/PatchTests/PatchA2/PatchA2.wixproj new file mode 100644 index 00000000..da9acb5e --- /dev/null +++ b/src/TestData/PatchTests/PatchA2/PatchA2.wixproj @@ -0,0 +1,12 @@ + + + + PatchCreation + .msp + 1079 + + + + + + \ No newline at end of file diff --git a/src/TestData/PatchTests/PatchA2/PatchA2.wxs b/src/TestData/PatchTests/PatchA2/PatchA2.wxs new file mode 100644 index 00000000..a06401cc --- /dev/null +++ b/src/TestData/PatchTests/PatchA2/PatchA2.wxs @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + diff --git a/src/TestData/Templates/Package.wxs b/src/TestData/Templates/Package.wxs index 5522b9a3..4923e1aa 100644 --- a/src/TestData/Templates/Package.wxs +++ b/src/TestData/Templates/Package.wxs @@ -6,8 +6,12 @@ + + + + - + @@ -20,6 +24,9 @@ + + + diff --git a/src/Wix.Build.targets b/src/Wix.Build.targets index e6018b67..3fe78ae3 100644 --- a/src/Wix.Build.targets +++ b/src/Wix.Build.targets @@ -7,6 +7,8 @@ TestGroupName=$(TestGroupName);PackageName=$(PackageName);BundleName=$(BundleName);$(DefineConstants) BA=$(BA);$(DefineConstants) CabPrefix=$(CabPrefix);$(DefineConstants) + ProductCode=$(ProductCode);$(DefineConstants) + ProductComponents=1;$(DefineConstants) UpgradeCode=$(UpgradeCode);$(DefineConstants) Version=$(Version);$(DefineConstants) diff --git a/src/WixToolsetTest.BurnE2E/BurnE2ETests.cs b/src/WixToolsetTest.BurnE2E/BurnE2ETests.cs index 8d1cca23..f3b3e583 100644 --- a/src/WixToolsetTest.BurnE2E/BurnE2ETests.cs +++ b/src/WixToolsetTest.BurnE2E/BurnE2ETests.cs @@ -21,9 +21,9 @@ namespace WixToolsetTest.BurnE2E return installer; } - protected PackageInstaller CreatePackageInstaller(string name) + protected PackageInstaller CreatePackageInstaller(string filename) { - var installer = new PackageInstaller(this.TestContext, name); + var installer = new PackageInstaller(this.TestContext, filename); this.Installers.Enqueue(installer); return installer; } diff --git a/src/WixToolsetTest.BurnE2E/PackageInstaller.cs b/src/WixToolsetTest.BurnE2E/PackageInstaller.cs index 95d6cd90..bd1e30cc 100644 --- a/src/WixToolsetTest.BurnE2E/PackageInstaller.cs +++ b/src/WixToolsetTest.BurnE2E/PackageInstaller.cs @@ -8,11 +8,10 @@ namespace WixToolsetTest.BurnE2E public partial class PackageInstaller : IDisposable { - public PackageInstaller(WixTestContext testContext, string name) + public PackageInstaller(WixTestContext testContext, string filename) { - this.Package = Path.Combine(testContext.TestDataFolder, $"{name}.msi"); - this.PackagePdb = Path.Combine(testContext.TestDataFolder, $"{name}.wixpdb"); - this.PackageName = name; + this.Package = Path.Combine(testContext.TestDataFolder, $"{filename}.msi"); + this.PackagePdb = Path.Combine(testContext.TestDataFolder, $"{filename}.wixpdb"); this.TestContext = testContext; } diff --git a/src/WixToolsetTest.BurnE2E/PackageVerifier.cs b/src/WixToolsetTest.BurnE2E/PackageVerifier.cs index 7b4bbfef..7a4fea88 100644 --- a/src/WixToolsetTest.BurnE2E/PackageVerifier.cs +++ b/src/WixToolsetTest.BurnE2E/PackageVerifier.cs @@ -12,15 +12,13 @@ namespace WixToolsetTest.BurnE2E public partial class PackageInstaller { - private string PackageName { get; } - public string PackagePdb { get; } private WindowsInstallerData WiData { get; set; } public string GetInstalledFilePath(string filename) { - return this.TestContext.GetTestInstallFolder(Path.Combine(this.PackageName, filename)); + return this.TestContext.GetTestInstallFolder(Path.Combine(this.GetInstallFolderName(), filename)); } private WindowsInstallerData GetWindowsInstallerData() @@ -34,6 +32,19 @@ namespace WixToolsetTest.BurnE2E return this.WiData; } + public string GetInstallFolderName() + { + var wiData = this.GetWindowsInstallerData(); + var row = wiData.Tables["Directory"].Rows.Single(r => r.FieldAsString(0) == "INSTALLFOLDER"); + var value = row.FieldAsString(2); + var longNameIndex = value.IndexOf('|') + 1; + if (longNameIndex > 0) + { + return value.Substring(longNameIndex); + } + return value; + } + public string GetProperty(string name) { var wiData = this.GetWindowsInstallerData(); @@ -46,5 +57,21 @@ namespace WixToolsetTest.BurnE2E var productCode = this.GetProperty("ProductCode"); Assert.Equal(installed, MsiUtilities.IsProductInstalled(productCode)); } + + public void VerifyTestRegistryRootDeleted() + { + using var testRegistryRoot = this.TestContext.GetTestRegistryRoot(); + Assert.Null(testRegistryRoot); + } + + public void VerifyTestRegistryValue(string name, string expectedValue) + { + using (var root = this.TestContext.GetTestRegistryRoot()) + { + Assert.NotNull(root); + var actualValue = root.GetValue(name) as string; + Assert.Equal(expectedValue, actualValue); + } + } } } diff --git a/src/WixToolsetTest.BurnE2E/PatchTests.cs b/src/WixToolsetTest.BurnE2E/PatchTests.cs new file mode 100644 index 00000000..19adf8db --- /dev/null +++ b/src/WixToolsetTest.BurnE2E/PatchTests.cs @@ -0,0 +1,137 @@ +// 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 System; + using System.IO; + using System.Xml; + using Xunit; + using Xunit.Abstractions; + + public class PatchTests : BurnE2ETests + { + public PatchTests(ITestOutputHelper testOutputHelper) : base(testOutputHelper) { } + + [Fact] + public void CanRunDetectMultipleTimesWithPatches() + { + var testBAController = this.CreateTestBAController(); + testBAController.SetRedetectCount(1); + + this.CanInstallBundleWithPatchThenRemoveIt(); + } + + [Fact] + public void CanInstallBundleWithPatchThenRemoveIt() + { + var originalVersion = "1.0.0.0"; + var patchedVersion = "1.0.1.0"; + var testRegistryValue = "PackageA"; + + var packageAv1 = this.CreatePackageInstaller("PackageAv1"); + var bundleA = this.CreateBundleInstaller("BundleA"); + var bundlePatchA = this.CreateBundleInstaller("BundlePatchA"); + + bundleA.Install(); + bundleA.VerifyRegisteredAndInPackageCache(); + + packageAv1.VerifyInstalled(true); + packageAv1.VerifyTestRegistryValue(testRegistryValue, originalVersion); + + bundlePatchA.Install(); + bundlePatchA.VerifyRegisteredAndInPackageCache(); + + packageAv1.VerifyTestRegistryValue(testRegistryValue, patchedVersion); + + bundlePatchA.Uninstall(); + bundlePatchA.VerifyUnregisteredAndRemovedFromPackageCache(); + + packageAv1.VerifyTestRegistryValue(testRegistryValue, originalVersion); + + bundleA.Uninstall(); + bundleA.VerifyUnregisteredAndRemovedFromPackageCache(); + + packageAv1.VerifyInstalled(false); + packageAv1.VerifyTestRegistryRootDeleted(); + } + + [Fact(Skip = "https://github.com/wixtoolset/issues/issues/5949")] + public void CanPatchSwidTag() + { + var originalVersion = "1.0.0.0"; + var patchedVersion = "1.0.1.0"; + var packageTagName = "~PatchTests - PackageA"; + var bundleTagName = "~PatchTests - BundleA"; + var bundlePatchTagName = "~PatchTests - BundlePatchA"; + + this.CreatePackageInstaller("PackageAv1"); + var bundleA = this.CreateBundleInstaller("BundleA"); + var bundlePatchA = this.CreateBundleInstaller("BundlePatchA"); + + bundleA.Install(); + VerifySwidTagVersion(bundleTagName, originalVersion); + VerifySwidTagVersion(packageTagName, originalVersion); + + bundlePatchA.Install(); + VerifySwidTagVersion(bundlePatchTagName, patchedVersion); + VerifySwidTagVersion(packageTagName, patchedVersion); + + bundlePatchA.Uninstall(); + VerifySwidTagVersion(packageTagName, originalVersion); + + bundleA.Uninstall(); + VerifySwidTagVersion(bundleTagName, null); + VerifySwidTagVersion(packageTagName, null); + } + + [Fact] + public void CanInstallBundleWithPatchesTargetingSingleProductThenRemoveIt() + { + var originalVersion = "1.0.0.0"; + var patchedVersion = "1.0.1.0"; + var testRegistryValue = "PackageA"; + var testRegistryValue2 = "PackageA2"; + + var packageAv1 = this.CreatePackageInstaller("PackageAv1"); + var bundlePatchA2 = this.CreateBundleInstaller("BundlePatchA2"); + + packageAv1.InstallProduct(); + packageAv1.VerifyInstalled(true); + packageAv1.VerifyTestRegistryValue(testRegistryValue, originalVersion); + packageAv1.VerifyTestRegistryValue(testRegistryValue2, originalVersion); + + bundlePatchA2.Install(); + bundlePatchA2.VerifyRegisteredAndInPackageCache(); + + packageAv1.VerifyTestRegistryValue(testRegistryValue, patchedVersion); + packageAv1.VerifyTestRegistryValue(testRegistryValue2, patchedVersion); + + bundlePatchA2.Uninstall(); + bundlePatchA2.VerifyUnregisteredAndRemovedFromPackageCache(); + + packageAv1.VerifyTestRegistryValue(testRegistryValue, originalVersion); + packageAv1.VerifyTestRegistryValue(testRegistryValue2, originalVersion); + } + + private static void VerifySwidTagVersion(string tagName, string expectedVersion) + { + var regidFolder = Environment.ExpandEnvironmentVariables(@"%ProgramData%\regid.1995-08.com.example"); + var tagPath = Path.Combine(regidFolder, "regid.1995-08.com.example " + tagName + ".swidtag"); + string version = null; + + if (File.Exists(tagPath)) + { + var doc = new XmlDocument(); + doc.Load(tagPath); + + var ns = new XmlNamespaceManager(doc.NameTable); + ns.AddNamespace("s", "http://standards.iso.org/iso/19770/-2/2009/schema.xsd"); + + var versionNode = doc.SelectSingleNode("/s:software_identification_tag/s:product_version/s:name", ns); + version = versionNode?.InnerText ?? String.Empty; + } + + Assert.Equal(expectedVersion, version); + } + } +} diff --git a/src/WixToolsetTest.BurnE2E/WixTestContext.cs b/src/WixToolsetTest.BurnE2E/WixTestContext.cs index 5620c6a7..0ae99a77 100644 --- a/src/WixToolsetTest.BurnE2E/WixTestContext.cs +++ b/src/WixToolsetTest.BurnE2E/WixTestContext.cs @@ -57,7 +57,7 @@ namespace WixToolsetTest.BurnE2E /// public RegistryKey GetTestRegistryRoot(string additionalPath = null) { - var key = String.Format(@"Software\WiX\Tests\{0}\{1}", this.TestName, additionalPath ?? String.Empty); + var key = String.Format(@"Software\WOW6432Node\WiX\Tests\{0}\{1}", this.TestGroupName, additionalPath ?? String.Empty); return Registry.LocalMachine.OpenSubKey(key, true); } diff --git a/src/WixToolsetTest.BurnE2E/WixToolsetTest.BurnE2E.csproj b/src/WixToolsetTest.BurnE2E/WixToolsetTest.BurnE2E.csproj index 86ad4410..3ffc892f 100644 --- a/src/WixToolsetTest.BurnE2E/WixToolsetTest.BurnE2E.csproj +++ b/src/WixToolsetTest.BurnE2E/WixToolsetTest.BurnE2E.csproj @@ -16,7 +16,7 @@ - + -- cgit v1.2.3-55-g6feb