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. --- .../CustomTableFixture.cs | 15 +-- .../DecompileFixture.cs | 140 +++------------------ .../TestData/CustomTable/CustomTable-Expected.wxs | 8 +- 3 files changed, 22 insertions(+), 141 deletions(-) (limited to 'src/test/WixToolsetTest.CoreIntegration') diff --git a/src/test/WixToolsetTest.CoreIntegration/CustomTableFixture.cs b/src/test/WixToolsetTest.CoreIntegration/CustomTableFixture.cs index 0a45c914..4a5cf544 100644 --- a/src/test/WixToolsetTest.CoreIntegration/CustomTableFixture.cs +++ b/src/test/WixToolsetTest.CoreIntegration/CustomTableFixture.cs @@ -3,6 +3,7 @@ namespace WixToolsetTest.CoreIntegration { using System.IO; + using System.Xml.Linq; using WixBuildTools.TestSupport; using WixToolset.Core.TestPackage; using Xunit; @@ -224,20 +225,8 @@ namespace WixToolsetTest.CoreIntegration result.AssertSuccess(); - CompareLineByLine(expectedFile, decompiledWxsPath); + WixAssert.CompareXml(expectedFile, decompiledWxsPath); } } - - private static void CompareLineByLine(string expectedFile, string actualFile) - { - var expectedLines = File.ReadAllLines(expectedFile); - var actualLines = File.ReadAllLines(actualFile); - for (var i = 0; i < expectedLines.Length; ++i) - { - Assert.True(actualLines.Length > i, $"{i}: Expected file longer than actual file"); - Assert.Equal($"{i}: {expectedLines[i]}", $"{i}: {actualLines[i]}"); - } - Assert.True(expectedLines.Length == actualLines.Length, "Actual file longer than expected file"); - } } } 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"); } } } diff --git a/src/test/WixToolsetTest.CoreIntegration/TestData/CustomTable/CustomTable-Expected.wxs b/src/test/WixToolsetTest.CoreIntegration/TestData/CustomTable/CustomTable-Expected.wxs index c55f4ed0..22036ae5 100644 --- a/src/test/WixToolsetTest.CoreIntegration/TestData/CustomTable/CustomTable-Expected.wxs +++ b/src/test/WixToolsetTest.CoreIntegration/TestData/CustomTable/CustomTable-Expected.wxs @@ -6,12 +6,12 @@ - Row1 - test.txt + + - Row2 - test.txt + + -- cgit v1.2.3-55-g6feb