From c237bb3bb00d36c50271a70baac68f49890e35e1 Mon Sep 17 00:00:00 2001 From: Bob Arnson Date: Mon, 24 Aug 2020 17:25:00 -0400 Subject: Update decompiler to use XDocument rather than generated classes. - Use CompareXml for diffing. - Change CustomAction/@ScriptFile to @ScriptSourceFile. --- .../DecompileFixture.cs | 140 +++------------------ 1 file changed, 16 insertions(+), 124 deletions(-) (limited to 'src/test/WixToolsetTest.CoreIntegration/DecompileFixture.cs') diff --git a/src/test/WixToolsetTest.CoreIntegration/DecompileFixture.cs b/src/test/WixToolsetTest.CoreIntegration/DecompileFixture.cs index 9893a525..15082f2b 100644 --- a/src/test/WixToolsetTest.CoreIntegration/DecompileFixture.cs +++ b/src/test/WixToolsetTest.CoreIntegration/DecompileFixture.cs @@ -6,14 +6,14 @@ namespace WixToolsetTest.CoreIntegration using System.Xml.Linq; using WixBuildTools.TestSupport; using WixToolset.Core.TestPackage; + using WixToolset.Extensibility.Services; using Xunit; public class DecompileFixture { - [Fact] - public void CanDecompileSingleFileCompressed() + private static void DecompileAndCompare(string sourceFolder, string msiName, string expectedWxsName) { - var folder = TestData.Get(@"TestData\DecompileSingleFileCompressed"); + var folder = TestData.Get(sourceFolder); using (var fs = new DisposableFileSystem()) { @@ -23,75 +23,33 @@ namespace WixToolsetTest.CoreIntegration var result = WixRunner.Execute(new[] { "decompile", - Path.Combine(folder, "example.msi"), + Path.Combine(folder, msiName), "-intermediateFolder", intermediateFolder, "-o", outputPath }); result.AssertSuccess(); - var actual = File.ReadAllText(outputPath); - var actualFormatted = XDocument.Parse(actual, LoadOptions.PreserveWhitespace | LoadOptions.SetBaseUri | LoadOptions.SetLineInfo).ToString(); - var expected = XDocument.Load(Path.Combine(folder, "Expected.wxs"), LoadOptions.PreserveWhitespace | LoadOptions.SetBaseUri | LoadOptions.SetLineInfo).ToString(); - - Assert.Equal(expected, actualFormatted); + WixAssert.CompareXml(Path.Combine(folder, expectedWxsName), outputPath); } } [Fact] - public void CanDecompile64BitSingleFileCompressed() + public void CanDecompileSingleFileCompressed() { - var folder = TestData.Get(@"TestData\DecompileSingleFileCompressed64"); - - using (var fs = new DisposableFileSystem()) - { - var intermediateFolder = fs.GetFolder(); - var outputPath = Path.Combine(intermediateFolder, @"Actual.wxs"); - - var result = WixRunner.Execute(new[] - { - "decompile", - Path.Combine(folder, "example.msi"), - "-intermediateFolder", intermediateFolder, - "-o", outputPath - }); - - result.AssertSuccess(); - - var actual = File.ReadAllText(outputPath); - var actualFormatted = XDocument.Parse(actual, LoadOptions.PreserveWhitespace | LoadOptions.SetBaseUri | LoadOptions.SetLineInfo).ToString(); - var expected = XDocument.Load(Path.Combine(folder, "Expected.wxs"), LoadOptions.PreserveWhitespace | LoadOptions.SetBaseUri | LoadOptions.SetLineInfo).ToString(); + DecompileAndCompare(@"TestData\DecompileSingleFileCompressed", "example.msi", "Expected.wxs"); + } - Assert.Equal(expected, actualFormatted); - } + [Fact] + public void CanDecompile64BitSingleFileCompressed() + { + DecompileAndCompare(@"TestData\DecompileSingleFileCompressed64", "example.msi", "Expected.wxs"); } [Fact] public void CanDecompileNestedDirSearchUnderRegSearch() { - var folder = TestData.Get(@"TestData\AppSearch"); - - using (var fs = new DisposableFileSystem()) - { - var intermediateFolder = fs.GetFolder(); - var outputPath = Path.Combine(intermediateFolder, @"Actual.wxs"); - - var result = WixRunner.Execute(new[] - { - "decompile", - Path.Combine(folder, "NestedDirSearchUnderRegSearch.msi"), - "-intermediateFolder", intermediateFolder, - "-o", outputPath - }); - - result.AssertSuccess(); - - var actual = File.ReadAllText(outputPath); - var actualFormatted = XDocument.Parse(actual, LoadOptions.PreserveWhitespace | LoadOptions.SetBaseUri | LoadOptions.SetLineInfo).ToString(); - var expected = XDocument.Load(Path.Combine(folder, "DecompiledNestedDirSearchUnderRegSearch.wxs"), LoadOptions.PreserveWhitespace | LoadOptions.SetBaseUri | LoadOptions.SetLineInfo).ToString(); - - Assert.Equal(expected, actualFormatted); - } + DecompileAndCompare(@"TestData\AppSearch", "NestedDirSearchUnderRegSearch.msi", "DecompiledNestedDirSearchUnderRegSearch.wxs"); } [Fact] @@ -100,85 +58,19 @@ namespace WixToolsetTest.CoreIntegration // The input MSI was not created using standard methods, it is an example of a real world database that needs to be decompiled. // The Class/@Feature_ column has length of 32, the File/@Attributes has length of 2, // and numerous foreign key relationships are missing. - var folder = TestData.Get(@"TestData\Class"); - - using (var fs = new DisposableFileSystem()) - { - var intermediateFolder = fs.GetFolder(); - var outputPath = Path.Combine(intermediateFolder, @"Actual.wxs"); - - var result = WixRunner.Execute(new[] - { - "decompile", - Path.Combine(folder, "OldClassTableDef.msi"), - "-intermediateFolder", intermediateFolder, - "-o", outputPath - }); - - result.AssertSuccess(); - - var actual = File.ReadAllText(outputPath); - var actualFormatted = XDocument.Parse(actual, LoadOptions.PreserveWhitespace | LoadOptions.SetBaseUri | LoadOptions.SetLineInfo).ToString(); - var expected = XDocument.Load(Path.Combine(folder, "DecompiledOldClassTableDef.wxs"), LoadOptions.PreserveWhitespace | LoadOptions.SetBaseUri | LoadOptions.SetLineInfo).ToString(); - - Assert.Equal(expected, actualFormatted); - } + DecompileAndCompare(@"TestData\Class", "OldClassTableDef.msi", "DecompiledOldClassTableDef.wxs"); } [Fact] public void CanDecompileSequenceTables() { - var folder = TestData.Get(@"TestData\SequenceTables"); - - using (var fs = new DisposableFileSystem()) - { - var intermediateFolder = fs.GetFolder(); - var outputPath = Path.Combine(intermediateFolder, @"Actual.wxs"); - - var result = WixRunner.Execute(new[] - { - "decompile", - Path.Combine(folder, "SequenceTables.msi"), - "-intermediateFolder", intermediateFolder, - "-o", outputPath - }); - - result.AssertSuccess(); - - var actual = File.ReadAllText(outputPath); - var actualFormatted = XDocument.Parse(actual, LoadOptions.PreserveWhitespace | LoadOptions.SetBaseUri | LoadOptions.SetLineInfo).ToString(); - var expected = XDocument.Load(Path.Combine(folder, "DecompiledSequenceTables.wxs"), LoadOptions.PreserveWhitespace | LoadOptions.SetBaseUri | LoadOptions.SetLineInfo).ToString(); - - Assert.Equal(expected, actualFormatted); - } + DecompileAndCompare(@"TestData\SequenceTables", "SequenceTables.msi", "DecompiledSequenceTables.wxs"); } [Fact] public void CanDecompileShortcuts() { - var folder = TestData.Get(@"TestData\Shortcut"); - - using (var fs = new DisposableFileSystem()) - { - var intermediateFolder = fs.GetFolder(); - var outputPath = Path.Combine(intermediateFolder, @"Actual.wxs"); - - var result = WixRunner.Execute(new[] - { - "decompile", - Path.Combine(folder, "shortcuts.msi"), - "-intermediateFolder", intermediateFolder, - "-o", outputPath - }); - - result.AssertSuccess(); - - var actual = File.ReadAllText(outputPath); - var actualFormatted = XDocument.Parse(actual, LoadOptions.PreserveWhitespace | LoadOptions.SetBaseUri | LoadOptions.SetLineInfo).ToString(); - var expected = XDocument.Load(Path.Combine(folder, "DecompiledShortcuts.wxs"), LoadOptions.PreserveWhitespace | LoadOptions.SetBaseUri | LoadOptions.SetLineInfo).ToString(); - - Assert.Equal(expected, actualFormatted); - } + DecompileAndCompare(@"TestData\Shortcut", "shortcuts.msi", "DecompiledShortcuts.wxs"); } } } -- cgit v1.2.3-55-g6feb