From 70f6c04122db39b5d234715c373d690f97892f8b Mon Sep 17 00:00:00 2001 From: Sean Hall Date: Sat, 1 May 2021 20:44:43 -0500 Subject: Add x64 Bundle tests. --- src/WixTestTools/BundleRegistration.cs | 5 +++-- src/WixTestTools/BundleVerifier.cs | 11 ++++++----- src/WixTestTools/PackageInstaller.cs | 14 ++++++++++++++ src/WixTestTools/PackageVerifier.cs | 30 +++++++++--------------------- src/WixTestTools/WixTestContext.cs | 10 ++++++---- 5 files changed, 38 insertions(+), 32 deletions(-) (limited to 'src/WixTestTools') diff --git a/src/WixTestTools/BundleRegistration.cs b/src/WixTestTools/BundleRegistration.cs index bf9e2903..75660838 100644 --- a/src/WixTestTools/BundleRegistration.cs +++ b/src/WixTestTools/BundleRegistration.cs @@ -88,9 +88,10 @@ namespace WixTestTools public string Version { get; set; } - public static bool TryGetPerMachineBundleRegistrationById(string bundleId, out BundleRegistration registration) + public static bool TryGetPerMachineBundleRegistrationById(string bundleId, bool x64, out BundleRegistration registration) { - var registrationKeyPath = $"{BURN_REGISTRATION_REGISTRY_UNINSTALL_KEY_WOW6432NODE}\\{bundleId}"; + var baseKeyPath = x64 ? BURN_REGISTRATION_REGISTRY_UNINSTALL_KEY : BURN_REGISTRATION_REGISTRY_UNINSTALL_KEY_WOW6432NODE; + var registrationKeyPath = $"{baseKeyPath}\\{bundleId}"; using var registrationKey = Registry.LocalMachine.OpenSubKey(registrationKeyPath); var success = registrationKey != null; registration = success ? GetBundleRegistration(registrationKey) : null; diff --git a/src/WixTestTools/BundleVerifier.cs b/src/WixTestTools/BundleVerifier.cs index 293da560..984df169 100644 --- a/src/WixTestTools/BundleVerifier.cs +++ b/src/WixTestTools/BundleVerifier.cs @@ -73,10 +73,11 @@ namespace WixTestTools public bool TryGetRegistration(out BundleRegistration registration) { var bundleSymbol = this.GetBundleSymbol(); + var x64 = bundleSymbol.Platform != Platform.X86; var bundleId = bundleSymbol.BundleId; if (bundleSymbol.PerMachine) { - return BundleRegistration.TryGetPerMachineBundleRegistrationById(bundleId, out registration); + return BundleRegistration.TryGetPerMachineBundleRegistrationById(bundleId, x64, out registration); } else { @@ -132,9 +133,9 @@ namespace WixTestTools Assert.True(Directory.Exists(cachePath)); } - public void VerifyExeTestRegistryRootDeleted(string name) + public void VerifyExeTestRegistryRootDeleted(string name, bool x64 = false) { - using var testRegistryRoot = this.TestContext.GetTestRegistryRoot(name); + using var testRegistryRoot = this.TestContext.GetTestRegistryRoot(x64, name); if (testRegistryRoot != null) { var actualValue = testRegistryRoot.GetValue("Version") as string; @@ -142,9 +143,9 @@ namespace WixTestTools } } - public void VerifyExeTestRegistryValue(string name, string expectedValue) + public void VerifyExeTestRegistryValue(string name, string expectedValue, bool x64 = false) { - using (var root = this.TestContext.GetTestRegistryRoot(name)) + using (var root = this.TestContext.GetTestRegistryRoot(x64, name)) { Assert.NotNull(root); var actualValue = root.GetValue("Version") as string; diff --git a/src/WixTestTools/PackageInstaller.cs b/src/WixTestTools/PackageInstaller.cs index 86376b9f..d32f499b 100644 --- a/src/WixTestTools/PackageInstaller.cs +++ b/src/WixTestTools/PackageInstaller.cs @@ -4,6 +4,10 @@ namespace WixTestTools { using System; using System.IO; + using System.Linq; + using WixToolset.Data; + using WixToolset.Data.Symbols; + using WixToolset.Data.WindowsInstaller; using static WixTestTools.MSIExec; public partial class PackageInstaller : IDisposable @@ -13,6 +17,16 @@ namespace WixTestTools this.Package = Path.Combine(testContext.TestDataFolder, $"{filename}.msi"); this.PackagePdb = Path.Combine(testContext.TestDataFolder, $"{filename}.wixpdb"); this.TestContext = testContext; + + using var wixOutput = WixOutput.Read(this.PackagePdb); + + var intermediate = Intermediate.Load(wixOutput); + var section = intermediate.Sections.Single(); + var platformSummary = section.Symbols.OfType().Single(s => s.PropertyId == SummaryInformationType.PlatformAndLanguage); + var platformString = platformSummary.Value.Split(new char[] { ';' }, 2)[0]; + this.IsX64 = platformString != "Intel"; + + this.WiData = WindowsInstallerData.Load(wixOutput); } public string Package { get; } diff --git a/src/WixTestTools/PackageVerifier.cs b/src/WixTestTools/PackageVerifier.cs index 073e83b0..2f42dd21 100644 --- a/src/WixTestTools/PackageVerifier.cs +++ b/src/WixTestTools/PackageVerifier.cs @@ -5,7 +5,6 @@ namespace WixTestTools using System; using System.IO; using System.Linq; - using WixToolset.Data; using WixToolset.Data.WindowsInstaller; using WixToolset.Data.WindowsInstaller.Rows; using Xunit; @@ -14,28 +13,18 @@ namespace WixTestTools { public string PackagePdb { get; } - private WindowsInstallerData WiData { get; set; } + private bool IsX64 { get; } - public string GetInstalledFilePath(string filename) - { - return this.TestContext.GetTestInstallFolder(Path.Combine(this.GetInstallFolderName(), filename)); - } + private WindowsInstallerData WiData { get; } - private WindowsInstallerData GetWindowsInstallerData() + public string GetInstalledFilePath(string filename) { - if (this.WiData == null) - { - using var wixOutput = WixOutput.Read(this.PackagePdb); - this.WiData = WindowsInstallerData.Load(wixOutput); - } - - return this.WiData; + return this.TestContext.GetTestInstallFolder(this.IsX64, Path.Combine(this.GetInstallFolderName(), filename)); } public string GetInstallFolderName() { - var wiData = this.GetWindowsInstallerData(); - var row = wiData.Tables["Directory"].Rows.Single(r => r.FieldAsString(0) == "INSTALLFOLDER"); + var row = this.WiData.Tables["Directory"].Rows.Single(r => r.FieldAsString(0) == "INSTALLFOLDER"); var value = row.FieldAsString(2); var longNameIndex = value.IndexOf('|') + 1; if (longNameIndex > 0) @@ -47,8 +36,7 @@ namespace WixTestTools public string GetProperty(string name) { - var wiData = this.GetWindowsInstallerData(); - var row = wiData.Tables["Property"].Rows.Cast().Single(r => r.Property == name); + var row = this.WiData.Tables["Property"].Rows.Cast().Single(r => r.Property == name); return row.Value; } @@ -67,7 +55,7 @@ namespace WixTestTools public void DeleteTestRegistryValue(string name) { - using (var root = this.TestContext.GetTestRegistryRoot()) + using (var root = this.TestContext.GetTestRegistryRoot(this.IsX64)) { Assert.NotNull(root); root.DeleteValue(name); @@ -76,13 +64,13 @@ namespace WixTestTools public void VerifyTestRegistryRootDeleted() { - using var testRegistryRoot = this.TestContext.GetTestRegistryRoot(); + using var testRegistryRoot = this.TestContext.GetTestRegistryRoot(this.IsX64); Assert.Null(testRegistryRoot); } public void VerifyTestRegistryValue(string name, string expectedValue) { - using (var root = this.TestContext.GetTestRegistryRoot()) + using (var root = this.TestContext.GetTestRegistryRoot(this.IsX64)) { Assert.NotNull(root); var actualValue = root.GetValue(name) as string; diff --git a/src/WixTestTools/WixTestContext.cs b/src/WixTestTools/WixTestContext.cs index c00f5723..a4e666f1 100644 --- a/src/WixTestTools/WixTestContext.cs +++ b/src/WixTestTools/WixTestContext.cs @@ -42,9 +42,10 @@ namespace WixTestTools /// /// The package or bundle must install into [ProgramFilesFolder]\~Test WiX\[TestGroupName]\([Additional]). /// - public string GetTestInstallFolder(string additionalPath = null) + public string GetTestInstallFolder(bool x64, string additionalPath = null) { - return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), "~Test WiX", this.TestGroupName, additionalPath ?? String.Empty); + var baseDirectory = x64 ? Environment.SpecialFolder.ProgramFiles : Environment.SpecialFolder.ProgramFilesX86; + return Path.Combine(Environment.GetFolderPath(baseDirectory), "~Test WiX", this.TestGroupName, additionalPath ?? String.Empty); } /// @@ -55,9 +56,10 @@ namespace WixTestTools /// /// The package must write into HKLM\Software\WiX\Tests\[TestGroupName]\([Additional]). /// - public RegistryKey GetTestRegistryRoot(string additionalPath = null) + public RegistryKey GetTestRegistryRoot(bool x64, string additionalPath = null) { - var key = String.Format(@"Software\WOW6432Node\WiX\Tests\{0}\{1}", this.TestGroupName, additionalPath ?? String.Empty); + var baseKey = x64 ? "Software" : @"Software\WOW6432Node"; + var key = String.Format(@"{0}\WiX\Tests\{1}\{2}", baseKey, this.TestGroupName, additionalPath ?? String.Empty); return Registry.LocalMachine.OpenSubKey(key, true); } -- cgit v1.2.3-55-g6feb