From da8727b126a3dc358c9d265c6e183b151ed8ec44 Mon Sep 17 00:00:00 2001 From: Bob Arnson Date: Wed, 23 Oct 2019 21:25:57 -0400 Subject: Use strongly-typed tuple creation... ...especially for tuples shared with WixToolset.Data. Add bundle tests. --- src/FindLocalWix.props | 2 +- .../WixToolsetTest.Util/TestData/.Data/burn.exe | Bin 0 -> 463360 bytes .../TestData/BundleWithSearches/Bundle.en-us.wxl | 10 ++ .../TestData/BundleWithSearches/Bundle.wxs | 35 +++++++ .../BundleWithSearches/data/MsiPackage/Shared.dll | 1 + .../BundleWithSearches/data/MsiPackage/test.txt | 1 + .../TestData/BundleWithSearches/data/fakeba.dll | 1 + .../TestData/BundleWithSearches/data/test.msi | Bin 0 -> 32768 bytes .../WixToolsetTest.Util/UtilExtensionFixture.cs | 67 +++++++++++++ .../WixToolsetTest.Util/WixToolsetTest.Util.csproj | 7 ++ src/wixext/UtilCompiler.cs | 104 +++++++-------------- src/wixlib/packages.config | 2 +- src/wixlib/util.wixproj | 4 +- 13 files changed, 159 insertions(+), 75 deletions(-) create mode 100644 src/test/WixToolsetTest.Util/TestData/.Data/burn.exe create mode 100644 src/test/WixToolsetTest.Util/TestData/BundleWithSearches/Bundle.en-us.wxl create mode 100644 src/test/WixToolsetTest.Util/TestData/BundleWithSearches/Bundle.wxs create mode 100644 src/test/WixToolsetTest.Util/TestData/BundleWithSearches/data/MsiPackage/Shared.dll create mode 100644 src/test/WixToolsetTest.Util/TestData/BundleWithSearches/data/MsiPackage/test.txt create mode 100644 src/test/WixToolsetTest.Util/TestData/BundleWithSearches/data/fakeba.dll create mode 100644 src/test/WixToolsetTest.Util/TestData/BundleWithSearches/data/test.msi diff --git a/src/FindLocalWix.props b/src/FindLocalWix.props index a784e352..1666e4fe 100644 --- a/src/FindLocalWix.props +++ b/src/FindLocalWix.props @@ -3,6 +3,6 @@ - $(MSBuildThisFileDirectory)..\..\Tools\build\Debug\net461\wix.targets + $(MSBuildThisFileDirectory)..\..\Tools\build\Debug\net461\wix.targets diff --git a/src/test/WixToolsetTest.Util/TestData/.Data/burn.exe b/src/test/WixToolsetTest.Util/TestData/.Data/burn.exe new file mode 100644 index 00000000..2a4f423f Binary files /dev/null and b/src/test/WixToolsetTest.Util/TestData/.Data/burn.exe differ diff --git a/src/test/WixToolsetTest.Util/TestData/BundleWithSearches/Bundle.en-us.wxl b/src/test/WixToolsetTest.Util/TestData/BundleWithSearches/Bundle.en-us.wxl new file mode 100644 index 00000000..bc1dee83 --- /dev/null +++ b/src/test/WixToolsetTest.Util/TestData/BundleWithSearches/Bundle.en-us.wxl @@ -0,0 +1,10 @@ + + + + + + ~TestBundle + + diff --git a/src/test/WixToolsetTest.Util/TestData/BundleWithSearches/Bundle.wxs b/src/test/WixToolsetTest.Util/TestData/BundleWithSearches/Bundle.wxs new file mode 100644 index 00000000..cafd4255 --- /dev/null +++ b/src/test/WixToolsetTest.Util/TestData/BundleWithSearches/Bundle.wxs @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/test/WixToolsetTest.Util/TestData/BundleWithSearches/data/MsiPackage/Shared.dll b/src/test/WixToolsetTest.Util/TestData/BundleWithSearches/data/MsiPackage/Shared.dll new file mode 100644 index 00000000..0e461ba8 --- /dev/null +++ b/src/test/WixToolsetTest.Util/TestData/BundleWithSearches/data/MsiPackage/Shared.dll @@ -0,0 +1 @@ +This is Shared.dll. \ No newline at end of file diff --git a/src/test/WixToolsetTest.Util/TestData/BundleWithSearches/data/MsiPackage/test.txt b/src/test/WixToolsetTest.Util/TestData/BundleWithSearches/data/MsiPackage/test.txt new file mode 100644 index 00000000..8b986220 --- /dev/null +++ b/src/test/WixToolsetTest.Util/TestData/BundleWithSearches/data/MsiPackage/test.txt @@ -0,0 +1 @@ +This is test.txt \ No newline at end of file diff --git a/src/test/WixToolsetTest.Util/TestData/BundleWithSearches/data/fakeba.dll b/src/test/WixToolsetTest.Util/TestData/BundleWithSearches/data/fakeba.dll new file mode 100644 index 00000000..970efdf0 --- /dev/null +++ b/src/test/WixToolsetTest.Util/TestData/BundleWithSearches/data/fakeba.dll @@ -0,0 +1 @@ +This is a fakeba.dll \ No newline at end of file diff --git a/src/test/WixToolsetTest.Util/TestData/BundleWithSearches/data/test.msi b/src/test/WixToolsetTest.Util/TestData/BundleWithSearches/data/test.msi new file mode 100644 index 00000000..0722d60e Binary files /dev/null and b/src/test/WixToolsetTest.Util/TestData/BundleWithSearches/data/test.msi differ diff --git a/src/test/WixToolsetTest.Util/UtilExtensionFixture.cs b/src/test/WixToolsetTest.Util/UtilExtensionFixture.cs index 74cf9769..f2f06af8 100644 --- a/src/test/WixToolsetTest.Util/UtilExtensionFixture.cs +++ b/src/test/WixToolsetTest.Util/UtilExtensionFixture.cs @@ -2,9 +2,12 @@ namespace WixToolsetTest.Util { + using System.IO; using System.Linq; using WixBuildTools.TestSupport; using WixToolset.Core.TestPackage; + using WixToolset.Data; + using WixToolset.Data.Tuples; using WixToolset.Util; using Xunit; @@ -24,6 +27,70 @@ namespace WixToolsetTest.Util }, results.OrderBy(s => s).ToArray()); } + [Fact] + public void CanBuildBundleWithSearches() + { + var burnStubPath = TestData.Get(@"TestData\.Data\burn.exe"); + var folder = TestData.Get(@"TestData\BundleWithSearches"); + var rootFolder = TestData.Get(); + var wixext = Path.Combine(rootFolder, "WixToolset.Util.wixext.dll"); + + using (var fs = new DisposableFileSystem()) + { + var baseFolder = fs.GetFolder(); + var intermediateFolder = Path.Combine(baseFolder, "obj"); + + var result = WixRunner.Execute(new[] + { + "build", + Path.Combine(folder, "Bundle.wxs"), + "-ext", wixext, + "-loc", Path.Combine(folder, "Bundle.en-us.wxl"), + "-bindpath", Path.Combine(folder, "data"), + "-intermediateFolder", intermediateFolder, + "-burnStub", burnStubPath, + "-o", Path.Combine(baseFolder, @"bin\test.exe") + }); + + result.AssertSuccess(); + + Assert.True(File.Exists(Path.Combine(baseFolder, @"bin\test.exe"))); +#if TODO + Assert.True(File.Exists(Path.Combine(baseFolder, @"bin\test.wixpdb"))); +#endif + + var intermediate = Intermediate.Load(Path.Combine(intermediateFolder, @"test.wir")); + var section = intermediate.Sections.Single(); + + var searchTuples = section.Tuples.OfType().OrderBy(t => t.Id.Id).ToList(); + Assert.Equal(3, searchTuples.Count); + Assert.Equal("FileSearchId", searchTuples[0].Id.Id); + Assert.Equal("FileSearchVariable", searchTuples[0].Variable); + Assert.Equal("ProductSearchId", searchTuples[1].Id.Id); + Assert.Equal("ProductSearchVariable", searchTuples[1].Variable); + Assert.Equal("1 & 2 < 3", searchTuples[1].Condition); + Assert.Equal("RegistrySearchId", searchTuples[2].Id.Id); + Assert.Equal("RegistrySearchVariable", searchTuples[2].Variable); + + var fileSearchTuple = section.Tuples.OfType().Single(); + Assert.Equal("FileSearchId", fileSearchTuple.Id.Id); + Assert.Equal(@"%windir%\System32\mscoree.dll", fileSearchTuple.Path); + Assert.Equal(WixFileSearchAttributes.Default | WixFileSearchAttributes.WantExists, fileSearchTuple.Attributes); + + var productSearchTuple = section.Tuples.OfType().Single(); + Assert.Equal("ProductSearchId", productSearchTuple.Id.Id); + Assert.Equal("{738D02BF-E231-4370-8209-E9FD4E1BE2A1}", productSearchTuple.Guid); + Assert.Equal(WixProductSearchAttributes.Version | WixProductSearchAttributes.UpgradeCode, productSearchTuple.Attributes); + + var registrySearchTuple = section.Tuples.OfType().Single(); + Assert.Equal("RegistrySearchId", registrySearchTuple.Id.Id); + Assert.Equal(RegistryRootType.LocalMachine, registrySearchTuple.Root); + Assert.Equal(@"SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full", registrySearchTuple.Key); + Assert.Equal("Release", registrySearchTuple.Value); + Assert.Equal(WixRegistrySearchAttributes.WantValue | WixRegistrySearchAttributes.Raw, registrySearchTuple.Attributes); + } + } + private static void Build(string[] args) { var result = WixRunner.Execute(args) diff --git a/src/test/WixToolsetTest.Util/WixToolsetTest.Util.csproj b/src/test/WixToolsetTest.Util/WixToolsetTest.Util.csproj index 294844ac..6cf001a2 100644 --- a/src/test/WixToolsetTest.Util/WixToolsetTest.Util.csproj +++ b/src/test/WixToolsetTest.Util/WixToolsetTest.Util.csproj @@ -12,6 +12,13 @@ + + + + + + + diff --git a/src/wixext/UtilCompiler.cs b/src/wixext/UtilCompiler.cs index cc51733a..19f4af06 100644 --- a/src/wixext/UtilCompiler.cs +++ b/src/wixext/UtilCompiler.cs @@ -34,55 +34,12 @@ namespace WixToolset.Util internal const int UserDontCreateUser = 0x00000200; internal const int UserNonVital = 0x00000400; - [Flags] - internal enum WixFileSearchAttributes - { - Default = 0x001, - MinVersionInclusive = 0x002, - MaxVersionInclusive = 0x004, - MinSizeInclusive = 0x008, - MaxSizeInclusive = 0x010, - MinDateInclusive = 0x020, - MaxDateInclusive = 0x040, - WantVersion = 0x080, - WantExists = 0x100, - IsDirectory = 0x200, - } - internal enum WixRegistrySearchFormat { Raw, Compatible, } - [Flags] - internal enum WixRegistrySearchAttributes - { - Raw = 0x01, - Compatible = 0x02, - ExpandEnvironmentVariables = 0x04, - WantValue = 0x08, - WantExists = 0x10, - Win64 = 0x20, - } - - internal enum WixComponentSearchAttributes - { - KeyPath = 0x1, - State = 0x2, - WantDirectory = 0x4, - } - - [Flags] - internal enum WixProductSearchAttributes - { - Version = 0x01, - Language = 0x02, - State = 0x04, - Assignment = 0x08, - UpgradeCode = 0x10, - } - internal enum WixRestartResourceAttributes { Filename = 1, @@ -505,10 +462,12 @@ namespace WixToolset.Util break; } - var row = this.ParseHelper.CreateTuple(section, sourceLineNumbers, "WixComponentSearch", id); - row.Set(1, guid); - row.Set(2, productCode); - row.Set(3, (int)attributes); + section.Tuples.Add(new WixComponentSearchTuple(sourceLineNumbers, id) + { + Guid = guid, + ProductCode = productCode, + Attributes = attributes, + }); } } @@ -1087,16 +1046,11 @@ namespace WixToolset.Util /// private void CreateWixFileSearchRow(IntermediateSection section, SourceLineNumber sourceLineNumbers, Identifier id, string path, WixFileSearchAttributes attributes) { - var row = this.ParseHelper.CreateTuple(section, sourceLineNumbers, "WixFileSearch", id); - row.Set(1, path); - //row.Set(2, minVersion; - //row.Set(3, maxVersion; - //row.Set(4, minSize; - //row.Set(5, maxSize; - //row.Set(6, minDate; - //row.Set(7, maxDate; - //row.Set(8, languages; - row.Set(9, (int)attributes); + section.Tuples.Add(new WixFileSearchTuple(sourceLineNumbers, id) + { + Path = path, + Attributes = attributes, + }); } /// @@ -1108,9 +1062,11 @@ namespace WixToolset.Util /// A condition to test before evaluating the search. private void CreateWixSearchRow(IntermediateSection section, SourceLineNumber sourceLineNumbers, Identifier id, string variable, string condition) { - var row = this.ParseHelper.CreateTuple(section, sourceLineNumbers, "WixSearch", id); - row.Set(1, variable); - row.Set(2, condition); + section.Tuples.Add(new WixSearchTuple(sourceLineNumbers, id) + { + Variable = variable, + Condition = condition, + }); } /// @@ -1122,9 +1078,11 @@ namespace WixToolset.Util /// Further details about the relation between id and parentId. private void CreateWixSearchRelationRow(IntermediateSection section, SourceLineNumber sourceLineNumbers, Identifier id, string parentId, int attributes) { - var row = this.ParseHelper.CreateTuple(section, sourceLineNumbers, "WixSearchRelation", id); - row.Set(1, parentId); - row.Set(2, attributes); + section.Tuples.Add(new WixSearchRelationTuple(sourceLineNumbers, id) + { + ParentSearchRef = parentId, + Attributes = attributes, + }); } /// @@ -2680,9 +2638,11 @@ namespace WixToolset.Util attributes |= WixProductSearchAttributes.UpgradeCode; } - var row = this.ParseHelper.CreateTuple(section, sourceLineNumbers, "WixProductSearch", id); - row.Set(1, productCode ?? upgradeCode); - row.Set(2, (int)attributes); + section.Tuples.Add(new WixProductSearchTuple(sourceLineNumbers, id) + { + Guid = productCode ?? upgradeCode, + Attributes = attributes, + }); } } @@ -2836,11 +2796,13 @@ namespace WixToolset.Util this.CreateWixSearchRelationRow(section, sourceLineNumbers, id, after, 2); } - var row = this.ParseHelper.CreateTuple(section, sourceLineNumbers, "WixRegistrySearch", id); - row.Set(1, (int)root); - row.Set(2, key); - row.Set(3, value); - row.Set(4, (int)attributes); + section.Tuples.Add(new WixRegistrySearchTuple(sourceLineNumbers, id) + { + Root = (RegistryRootType)root, + Key = key, + Value = value, + Attributes = attributes, + }); } } diff --git a/src/wixlib/packages.config b/src/wixlib/packages.config index 251c740a..ba4482d2 100644 --- a/src/wixlib/packages.config +++ b/src/wixlib/packages.config @@ -1,5 +1,5 @@  - + \ No newline at end of file diff --git a/src/wixlib/util.wixproj b/src/wixlib/util.wixproj index 3af40366..cc68d92c 100644 --- a/src/wixlib/util.wixproj +++ b/src/wixlib/util.wixproj @@ -1,7 +1,7 @@ - + {1ACFFEFD-505A-41A5-ACBF-A02B7B473AA2} @@ -46,7 +46,7 @@ This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - + -- cgit v1.2.3-55-g6feb