From 7987d2f7e2d47427d7571ab7cc3640d7b0bbb7ff Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Tue, 23 Jun 2020 00:58:11 -0700 Subject: Convert inner text to appropriate attributes --- src/WixToolset.Converters/Wix3Converter.cs | 280 ++++++++++++++++++++- .../WixToolsetTest.Converters/ConditionFixture.cs | 208 +++++++++++++++ .../WixToolsetTest.Converters/ConverterFixture.cs | 151 ----------- .../CustomActionFixture.cs | 90 +++++++ .../CustomTableFixture.cs | 145 +++++++++++ .../WixToolsetTest.Converters/PropertyFixture.cs | 114 +++++++++ .../WixToolsetTest.Converters/SequenceFixture.cs | 50 ++++ 7 files changed, 886 insertions(+), 152 deletions(-) create mode 100644 src/test/WixToolsetTest.Converters/ConditionFixture.cs create mode 100644 src/test/WixToolsetTest.Converters/CustomActionFixture.cs create mode 100644 src/test/WixToolsetTest.Converters/PropertyFixture.cs create mode 100644 src/test/WixToolsetTest.Converters/SequenceFixture.cs (limited to 'src') diff --git a/src/WixToolset.Converters/Wix3Converter.cs b/src/WixToolset.Converters/Wix3Converter.cs index 9329bd13..27c29e4d 100644 --- a/src/WixToolset.Converters/Wix3Converter.cs +++ b/src/WixToolset.Converters/Wix3Converter.cs @@ -26,16 +26,43 @@ namespace WixToolset.Converters private static readonly XNamespace WixNamespace = "http://wixtoolset.org/schemas/v4/wxs"; private static readonly XNamespace WixUtilNamespace = "http://wixtoolset.org/schemas/v4/wxs/util"; + private static readonly XName AdminExecuteSequenceElementName = WixNamespace + "AdminExecuteSequence"; + private static readonly XName AdminUISequenceSequenceElementName = WixNamespace + "AdminUISequence"; + private static readonly XName AdvertiseExecuteSequenceElementName = WixNamespace + "AdvertiseExecuteSequence"; + private static readonly XName InstallExecuteSequenceElementName = WixNamespace + "InstallExecuteSequence"; + private static readonly XName InstallUISequenceSequenceElementName = WixNamespace + "InstallUISequence"; + private static readonly XName EmbeddedChainerElementName = WixNamespace + "EmbeddedChainer"; private static readonly XName ColumnElementName = WixNamespace + "Column"; + private static readonly XName ComponentElementName = WixNamespace + "Component"; + private static readonly XName ControlElementName = WixNamespace + "Control"; + private static readonly XName ConditionElementName = WixNamespace + "Condition"; private static readonly XName CreateFolderElementName = WixNamespace + "CreateFolder"; private static readonly XName CustomTableElementName = WixNamespace + "CustomTable"; private static readonly XName DirectoryElementName = WixNamespace + "Directory"; + private static readonly XName FeatureElementName = WixNamespace + "Feature"; private static readonly XName FileElementName = WixNamespace + "File"; + private static readonly XName FragmentElementName = WixNamespace + "Fragment"; + private static readonly XName ErrorElementName = WixNamespace + "Error"; + private static readonly XName LaunchElementName = WixNamespace + "Launch"; + private static readonly XName LevelElementName = WixNamespace + "Level"; private static readonly XName ExePackageElementName = WixNamespace + "ExePackage"; private static readonly XName MsiPackageElementName = WixNamespace + "MsiPackage"; private static readonly XName MspPackageElementName = WixNamespace + "MspPackage"; private static readonly XName MsuPackageElementName = WixNamespace + "MsuPackage"; private static readonly XName PayloadElementName = WixNamespace + "Payload"; + private static readonly XName PermissionExElementName = WixNamespace + "PermissionEx"; + private static readonly XName ProductElementName = WixNamespace + "Product"; + private static readonly XName ProgressTextElementName = WixNamespace + "ProgressText"; + private static readonly XName PublishElementName = WixNamespace + "Publish"; + private static readonly XName MultiStringValueElementName = WixNamespace + "MultiStringValue"; + private static readonly XName RequiredPrivilegeElementName = WixNamespace + "RequiredPrivilege"; + private static readonly XName RowElementName = WixNamespace + "Row"; + private static readonly XName ServiceArgumentElementName = WixNamespace + "ServiceArgument"; + private static readonly XName SetDirectoryElementName = WixNamespace + "SetDirectory"; + private static readonly XName SetPropertyElementName = WixNamespace + "SetProperty"; + private static readonly XName ShortcutPropertyElementName = WixNamespace + "ShortcutProperty"; + private static readonly XName TextElementName = WixNamespace + "Text"; + private static readonly XName UITextElementName = WixNamespace + "UIText"; private static readonly XName UtilPermissionExElementName = WixUtilNamespace + "PermissionEx"; private static readonly XName CustomActionElementName = WixNamespace + "CustomAction"; private static readonly XName PropertyElementName = WixNamespace + "Property"; @@ -83,16 +110,40 @@ namespace WixToolset.Converters { this.ConvertElementMapping = new Dictionary> { + { Wix3Converter.AdminExecuteSequenceElementName, this.ConvertSequenceElement }, + { Wix3Converter.AdminUISequenceSequenceElementName, this.ConvertSequenceElement }, + { Wix3Converter.AdvertiseExecuteSequenceElementName, this.ConvertSequenceElement }, + { Wix3Converter.InstallUISequenceSequenceElementName, this.ConvertSequenceElement }, + { Wix3Converter.InstallExecuteSequenceElementName, this.ConvertSequenceElement }, { Wix3Converter.ColumnElementName, this.ConvertColumnElement }, { Wix3Converter.CustomTableElementName, this.ConvertCustomTableElement }, + { Wix3Converter.ControlElementName, this.ConvertControlElement }, + { Wix3Converter.ComponentElementName, this.ConvertComponentElement }, { Wix3Converter.DirectoryElementName, this.ConvertDirectoryElement }, + { Wix3Converter.FeatureElementName, this.ConvertFeatureElement }, { Wix3Converter.FileElementName, this.ConvertFileElement }, + { Wix3Converter.FragmentElementName, this.ConvertFragmentElement }, + { Wix3Converter.EmbeddedChainerElementName, this.ConvertEmbeddedChainerElement }, + { Wix3Converter.ErrorElementName, this.ConvertErrorElement }, { Wix3Converter.ExePackageElementName, this.ConvertSuppressSignatureValidation }, { Wix3Converter.MsiPackageElementName, this.ConvertSuppressSignatureValidation }, { Wix3Converter.MspPackageElementName, this.ConvertSuppressSignatureValidation }, { Wix3Converter.MsuPackageElementName, this.ConvertSuppressSignatureValidation }, { Wix3Converter.PayloadElementName, this.ConvertSuppressSignatureValidation }, + { Wix3Converter.PermissionExElementName, this.ConvertPermissionExElement }, + { Wix3Converter.ProductElementName, this.ConvertProductElement }, + { Wix3Converter.ProgressTextElementName, this.ConvertProgressTextElement }, + { Wix3Converter.PublishElementName, this.ConvertPublishElement }, + { Wix3Converter.MultiStringValueElementName, this.ConvertMultiStringValueElement }, + { Wix3Converter.RequiredPrivilegeElementName, this.ConvertRequiredPrivilegeElement }, + { Wix3Converter.RowElementName, this.ConvertRowElement }, { Wix3Converter.CustomActionElementName, this.ConvertCustomActionElement }, + { Wix3Converter.ServiceArgumentElementName, this.ConvertServiceArgumentElement }, + { Wix3Converter.SetDirectoryElementName, this.ConvertSetDirectoryElement }, + { Wix3Converter.SetPropertyElementName, this.ConvertSetPropertyElement }, + { Wix3Converter.ShortcutPropertyElementName, this.ConvertShortcutPropertyElement }, + { Wix3Converter.TextElementName, this.ConvertTextElement }, + { Wix3Converter.UITextElementName, this.ConvertUITextElement }, { Wix3Converter.UtilPermissionExElementName, this.ConvertUtilPermissionExElement }, { Wix3Converter.PropertyElementName, this.ConvertPropertyElement }, { Wix3Converter.WixElementWithoutNamespaceName, this.ConvertElementWithoutNamespace }, @@ -173,6 +224,8 @@ namespace WixToolset.Converters /// The number of errors found. public int ConvertDocument(XDocument document) { + this.Errors = 0; + var declaration = document.Declaration; // Convert the declaration. @@ -336,6 +389,36 @@ namespace WixToolset.Converters } } + private void ConvertControlElement(XElement element) + { + var xCondition = element.Element(ConditionElementName); + if (xCondition != null) + { + var action = UppercaseFirstChar(xCondition.Attribute("Action")?.Value); + if (!String.IsNullOrEmpty(action) && + TryGetInnerText(xCondition, out var text) && + this.OnError(ConverterTestType.InnerTextDeprecated, element, "Using {0} element text is deprecated. Use the '{1}Condition' attribute instead.", xCondition.Name.LocalName, action)) + { + element.Add(new XAttribute(action + "Condition", text)); + xCondition.Remove(); + } + } + } + + private void ConvertComponentElement(XElement element) + { + var xCondition = element.Element(ConditionElementName); + if (xCondition != null) + { + if (TryGetInnerText(xCondition, out var text) && + this.OnError(ConverterTestType.InnerTextDeprecated, element, "Using {0} element text is deprecated. Use the 'Condition' attribute instead.", xCondition.Name.LocalName)) + { + element.Add(new XAttribute("Condition", text)); + xCondition.Remove(); + } + } + } + private void ConvertDirectoryElement(XElement element) { if (null == element.Attribute("Name")) @@ -353,6 +436,25 @@ namespace WixToolset.Converters } } + private void ConvertFeatureElement(XElement element) + { + var xCondition = element.Element(ConditionElementName); + if (xCondition != null) + { + var level = xCondition.Attribute("Level")?.Value; + if (!String.IsNullOrEmpty(level) && + TryGetInnerText(xCondition, out var text) && + this.OnError(ConverterTestType.InnerTextDeprecated, element, "Using {0} element text is deprecated. Use the 'Level' element instead.", xCondition.Name.LocalName)) + { + xCondition.AddAfterSelf(new XElement(LevelElementName, + new XAttribute("Value", level), + new XAttribute("Condition", text) + )); + xCondition.Remove(); + } + } + } + private void ConvertFileElement(XElement element) { if (null == element.Attribute("Id")) @@ -379,6 +481,90 @@ namespace WixToolset.Converters } } + private void ConvertFragmentElement(XElement element) + { + var xCondition = element.Element(ConditionElementName); + if (xCondition != null) + { + var message = xCondition.Attribute("Message")?.Value; + + if (!String.IsNullOrEmpty(message) && + TryGetInnerText(xCondition, out var text) && + this.OnError(ConverterTestType.InnerTextDeprecated, element, "Using {0} element text is deprecated. Use the 'Launch' element instead.", xCondition.Name.LocalName)) + { + xCondition.AddAfterSelf(new XElement(LaunchElementName, + new XAttribute("Condition", text), + new XAttribute("Message", message) + )); + xCondition.Remove(); + } + } + } + + private void ConvertEmbeddedChainerElement(XElement element) => this.ConvertInnerTextToAttribute(element, "Condition"); + + private void ConvertErrorElement(XElement element) => this.ConvertInnerTextToAttribute(element, "Message"); + + private void ConvertPermissionExElement(XElement element) + { + var xCondition = element.Element(ConditionElementName); + if (xCondition != null) + { + if (TryGetInnerText(xCondition, out var text) && + this.OnError(ConverterTestType.InnerTextDeprecated, element, "Using {0} element text is deprecated. Use the 'Condition' attribute instead.", xCondition.Name.LocalName)) + { + element.Add(new XAttribute("Condition", text)); + xCondition.Remove(); + } + } + } + + private void ConvertProgressTextElement(XElement element) => this.ConvertInnerTextToAttribute(element, "Message"); + + private void ConvertProductElement(XElement element) + { + var xCondition = element.Element(ConditionElementName); + if (xCondition != null) + { + var message = element.Attribute("Message")?.Value; + + if (!String.IsNullOrEmpty(message) && + TryGetInnerText(xCondition, out var text) && + this.OnError(ConverterTestType.InnerTextDeprecated, element, "Using {0} element text is deprecated. Use the 'Launch' element instead.", xCondition.Name.LocalName)) + { + xCondition.AddAfterSelf(new XElement(LaunchElementName, + new XAttribute("Condition", text), + new XAttribute("Message", message) + )); + xCondition.Remove(); + } + } + } + + private void ConvertPublishElement(XElement element) => this.ConvertInnerTextToAttribute(element, "Condition"); + + private void ConvertMultiStringValueElement(XElement element) => this.ConvertInnerTextToAttribute(element, "Value"); + + private void ConvertRequiredPrivilegeElement(XElement element) => this.ConvertInnerTextToAttribute(element, "Name"); + + private void ConvertRowElement(XElement element) => this.ConvertInnerTextToAttribute(element, "Value"); + + private void ConvertSequenceElement(XElement element) + { + foreach (var child in element.Elements()) + { + this.ConvertInnerTextToAttribute(child, "Condition"); + } + } + + private void ConvertServiceArgumentElement(XElement element) => this.ConvertInnerTextToAttribute(element, "Value"); + + private void ConvertSetDirectoryElement(XElement element) => this.ConvertInnerTextToAttribute(element, "Condition"); + + private void ConvertSetPropertyElement(XElement element) => this.ConvertInnerTextToAttribute(element, "Condition"); + + private void ConvertShortcutPropertyElement(XElement element) => this.ConvertInnerTextToAttribute(element, "Value"); + private void ConvertSuppressSignatureValidation(XElement element) { var suppressSignatureValidation = element.Attribute("SuppressSignatureValidation"); @@ -397,6 +583,10 @@ namespace WixToolset.Converters } } + private void ConvertTextElement(XElement element) => this.ConvertInnerTextToAttribute(element, "Value"); + + private void ConvertUITextElement(XElement element) => this.ConvertInnerTextToAttribute(element, "Value"); + private void ConvertCustomActionElement(XElement xCustomAction) { var xBinaryKey = xCustomAction.Attribute("BinaryKey"); @@ -436,6 +626,24 @@ namespace WixToolset.Converters xProperty.Value = xProperty.Value.Replace("QtExec", "WixQuietExec"); } } + + var xScript = xCustomAction.Attribute("Script"); + + if (xScript != null && TryGetInnerText(xCustomAction, out var scriptText)) + { + if (this.OnError(ConverterTestType.InnerTextDeprecated, xCustomAction, "Using {0} element text is deprecated. Extract the text to a file and use the 'ScriptFile' attribute to reference it.", xCustomAction.Name.LocalName)) + { + var scriptFolder = Path.GetDirectoryName(this.SourceFile) ?? String.Empty; + var id = xCustomAction.Attribute("Id")?.Value ?? Guid.NewGuid().ToString("N"); + var ext = (xScript.Value == "jscript") ? ".js" : (xScript.Value == "vbscript") ? ".vbs" : ".txt"; + + var scriptFile = Path.Combine(scriptFolder, id + ext); + File.WriteAllText(scriptFile, scriptText); + + RemoveChildren(xCustomAction); + xCustomAction.Add(new XAttribute("ScriptFile", scriptFile)); + } + } } private void ConvertPropertyElement(XElement xProperty) @@ -446,6 +654,8 @@ namespace WixToolset.Converters { this.OnError(ConverterTestType.QtExecCmdTimeoutAmbiguous, xProperty, "QtExecCmdTimeout was previously used for both CAQuietExec and CAQuietExec64. For WixQuietExec, use WixQuietExecCmdTimeout. For WixQuietExec64, use WixQuietExec64CmdTimeout."); } + + this.ConvertInnerTextToAttribute(xProperty, "Value"); } private void ConvertUtilPermissionExElement(XElement element) @@ -483,13 +693,22 @@ namespace WixToolset.Converters } } + private void ConvertInnerTextToAttribute(XElement element, string attributeName) + { + if (TryGetInnerText(element, out var text) && + this.OnError(ConverterTestType.InnerTextDeprecated, element, "Using {0} element text is deprecated. Use the '{1}' attribute instead.", element.Name.LocalName, attributeName)) + { + element.Add(new XAttribute(attributeName, text)); + RemoveChildren(element); + } + } + private IEnumerable YieldConverterTypes(IEnumerable types) { if (null != types) { foreach (var type in types) { - if (Enum.TryParse(type, true, out var itt)) { yield return itt; @@ -637,6 +856,60 @@ namespace WixToolset.Converters return value; } + private static string UppercaseFirstChar(string value) + { + if (!String.IsNullOrEmpty(value)) + { + var c = Char.ToUpperInvariant(value[0]); + if (c != value[0]) + { + var remainder = value.Length > 1 ? value.Substring(1) : String.Empty; + return c + remainder; + } + } + + return value; + } + + private static bool TryGetInnerText(XElement element, out string value) + { + value = null; + + var nodes = element.Nodes(); + + if (nodes.All(e => e.NodeType == XmlNodeType.Text || e.NodeType == XmlNodeType.CDATA)) + { + value = String.Join(String.Empty, nodes.Cast().Select(TrimTextValue)); + } + + return !String.IsNullOrEmpty(value); + } + + private static string TrimTextValue(XText text) + { + var value = text.Value; + + if (String.IsNullOrEmpty(value)) + { + return String.Empty; + } + else if (text.NodeType == XmlNodeType.CDATA && String.IsNullOrWhiteSpace(value)) + { + return " "; + } + + return value.Trim(); + } + + private static void RemoveChildren(XElement element) + { + var nodes = element.Nodes().ToList(); + foreach (var node in nodes) + { + node.Remove(); + } + } + /// /// Converter test types. These are used to condition error messages down to warnings. /// @@ -751,6 +1024,11 @@ namespace WixToolset.Converters /// Column element's Modularize attribute is camel-case. /// ColumnModularizeCamelCase, + + /// + /// Inner text value should move to an attribute. + /// + InnerTextDeprecated, } } } diff --git a/src/test/WixToolsetTest.Converters/ConditionFixture.cs b/src/test/WixToolsetTest.Converters/ConditionFixture.cs new file mode 100644 index 00000000..bd7f52a8 --- /dev/null +++ b/src/test/WixToolsetTest.Converters/ConditionFixture.cs @@ -0,0 +1,208 @@ +// 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.Converters +{ + using System; + using System.Xml.Linq; + using WixToolset.Converters; + using WixToolsetTest.Converters.Mocks; + using Xunit; + + public class ConditionFixture : BaseConverterFixture + { + [Fact] + public void FixControlCondition() + { + var parse = String.Join(Environment.NewLine, + "", + "", + " ", + " ", + " ", + " ", + " a<>b", + " ", + " ", + " ", + " ", + ""); + + var expected = new[] + { + "", + "", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + "" + }; + + var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); + + var messaging = new MockMessaging(); + var converter = new Wix3Converter(messaging, 2, null, null); + + var errors = converter.ConvertDocument(document); + Assert.Equal(3, errors); + + var actualLines = UnformattedDocumentLines(document); + CompareLineByLine(expected, actualLines); + } + + [Fact] + public void FixComponentCondition() + { + var parse = String.Join(Environment.NewLine, + "", + "", + " ", + " ", + " 1<2", + " ", + " ", + ""); + + var expected = new[] + { + "", + "", + " ", + " ", + " ", + " ", + " ", + "" + }; + + var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); + + var messaging = new MockMessaging(); + var converter = new Wix3Converter(messaging, 2, null, null); + + var errors = converter.ConvertDocument(document); + Assert.Equal(3, errors); + + var actualLines = UnformattedDocumentLines(document); + CompareLineByLine(expected, actualLines); + } + + [Fact] + public void FixFeatureCondition() + { + var parse = String.Join(Environment.NewLine, + "", + "", + " ", + " ", + " PROP = 1", + " ", + " ", + ""); + + var expected = new[] + { + "", + "", + " ", + " ", + " ", + " ", + " ", + "" + }; + + var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); + + var messaging = new MockMessaging(); + var converter = new Wix3Converter(messaging, 2, null, null); + + var errors = converter.ConvertDocument(document); + Assert.Equal(3, errors); + + var actualLines = UnformattedDocumentLines(document); + CompareLineByLine(expected, actualLines); + } + + [Fact] + public void FixLaunchCondition() + { + var parse = String.Join(Environment.NewLine, + "", + "", + " ", + " ", + " 1<2", + " ", + " ", + ""); + + var expected = new[] + { + "", + "", + " ", + " ", + " ", + "" + }; + + var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); + + var messaging = new MockMessaging(); + var converter = new Wix3Converter(messaging, 2, null, null); + + var errors = converter.ConvertDocument(document); + Assert.Equal(3, errors); + + var actualLines = UnformattedDocumentLines(document); + CompareLineByLine(expected, actualLines); + } + + [Fact] + public void FixPermissionExCondition() + { + var parse = String.Join(Environment.NewLine, + "", + "", + " ", + " ", + " ", + " 1<2", + " ", + " ", + " ", + ""); + + var expected = new[] + { + "", + "", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + "" + }; + + var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); + + var messaging = new MockMessaging(); + var converter = new Wix3Converter(messaging, 2, null, null); + + var errors = converter.ConvertDocument(document); + Assert.Equal(3, errors); + + var actualLines = UnformattedDocumentLines(document); + CompareLineByLine(expected, actualLines); + } + } +} diff --git a/src/test/WixToolsetTest.Converters/ConverterFixture.cs b/src/test/WixToolsetTest.Converters/ConverterFixture.cs index 7a39b0c6..3378b804 100644 --- a/src/test/WixToolsetTest.Converters/ConverterFixture.cs +++ b/src/test/WixToolsetTest.Converters/ConverterFixture.cs @@ -168,95 +168,6 @@ namespace WixToolsetTest.Converters Assert.Equal(3, conversions); } - [Fact] - public void CanFixCdataWhitespace() - { - var parse = String.Join(Environment.NewLine, - "", - "", - " ", - " ", - " ", - " ", - " ", - ""); - - var expected = String.Join(Environment.NewLine, - "", - "", - " ", - " ", - " ", - ""); - - var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); - - var messaging = new MockMessaging(); - var converter = new Wix3Converter(messaging, 2, null, null); - - var errors = converter.ConvertDocument(document); - - var actual = UnformattedDocumentString(document); - - Assert.Equal(expected, actual); - Assert.Equal(2, errors); - } - - [Fact] - public void CanFixCdataWithWhitespace() - { - var parse = String.Join(Environment.NewLine, - "", - "", - " ", - " ", - " ", - " ", - " ", - ""); - - var expected = String.Join(Environment.NewLine, - "", - "", - " ", - " ", - " ", - ""); - - var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); - - var messaging = new MockMessaging(); - var converter = new Wix3Converter(messaging, 2, null, null); - - var errors = converter.ConvertDocument(document); - - var actual = UnformattedDocumentString(document); - - Assert.Equal(expected, actual); - Assert.Equal(2, errors); - } - - [Fact] - public void CanKeepCdataWithOnlyWhitespace() - { - var parse = String.Join(Environment.NewLine, - "", - "", - " ", - " ", - " ", - ""); - - var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); - - var messaging = new MockMessaging(); - var converter = new Wix3Converter(messaging, 2, null, null); - var errors = converter.ConvertDocument(document); - Assert.Equal(0, errors); - } - [Fact] public void CanConvertMainNamespace() { @@ -474,34 +385,6 @@ namespace WixToolsetTest.Converters Assert.Equal(expected, actual); } - [Fact] - public void CanConvertCustomTableBootstrapperApplicationData() - { - var parse = String.Join(Environment.NewLine, - "", - "", - " ", - ""); - - var expected = String.Join(Environment.NewLine, - "", - "", - " ", - ""); - - var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); - - var messaging = new MockMessaging(); - var converter = new Wix3Converter(messaging, 2, null, null); - - var errors = converter.ConvertDocument(document); - - var actual = UnformattedDocumentString(document); - - Assert.Equal(1, errors); - Assert.Equal(expected, actual); - } - [Fact] public void CanConvertShortNameDirectoryWithoutName() { @@ -585,39 +468,5 @@ namespace WixToolsetTest.Converters Assert.Equal(1, errors); Assert.Equal(expected, actual); } - - [Fact] - public void CanConvertCustomAction() - { - var parse = String.Join(Environment.NewLine, - "", - "", - " ", - " ", - " ", - " ", - ""); - - var expected = String.Join(Environment.NewLine, - "", - "", - " ", - " ", - " ", - " ", - ""); - - var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); - - var messaging = new MockMessaging(); - var converter = new Wix3Converter(messaging, 2, null, null); - - var errors = converter.ConvertDocument(document); - - var actual = UnformattedDocumentString(document); - - Assert.Equal(6, errors); - Assert.Equal(expected, actual); - } } } diff --git a/src/test/WixToolsetTest.Converters/CustomActionFixture.cs b/src/test/WixToolsetTest.Converters/CustomActionFixture.cs new file mode 100644 index 00000000..1eab0926 --- /dev/null +++ b/src/test/WixToolsetTest.Converters/CustomActionFixture.cs @@ -0,0 +1,90 @@ +// 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.Converters +{ + using System; + using System.IO; + using System.Xml.Linq; + using WixToolset.Converters; + using WixToolsetTest.Converters.Mocks; + using Xunit; + + public class CustomActionFixture : BaseConverterFixture + { + [Fact] + public void CanConvertCustomAction() + { + var parse = String.Join(Environment.NewLine, + "", + "", + " ", + " ", + " ", + " ", + ""); + + var expected = String.Join(Environment.NewLine, + "", + "", + " ", + " ", + " ", + " ", + ""); + + var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); + + var messaging = new MockMessaging(); + var converter = new Wix3Converter(messaging, 2, null, null); + + var errors = converter.ConvertDocument(document); + + var actual = UnformattedDocumentString(document); + + Assert.Equal(6, errors); + Assert.Equal(expected, actual); + } + + [Fact] + public void CanConvertCustomActionScript() + { + var parse = String.Join(Environment.NewLine, + "", + "", + " ", + " function() {", + " var x = 0;", + " return x;", + " }", + " ", + ""); + + var expected = String.Join(Environment.NewLine, + "", + "", + " ", + ""); + + var expectedScript = String.Join("\n", + "function() {", + " var x = 0;", + " return x;", + " }"); + + var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); + + var messaging = new MockMessaging(); + var converter = new Wix3Converter(messaging, 2, null, null); + + var errors = converter.ConvertDocument(document); + + var actual = UnformattedDocumentString(document); + + Assert.Equal(1, errors); + Assert.Equal(expected, actual); + + var script = File.ReadAllText("Foo.js"); + Assert.Equal(expectedScript, script); + } + } +} diff --git a/src/test/WixToolsetTest.Converters/CustomTableFixture.cs b/src/test/WixToolsetTest.Converters/CustomTableFixture.cs index 5a572294..c09534ee 100644 --- a/src/test/WixToolsetTest.Converters/CustomTableFixture.cs +++ b/src/test/WixToolsetTest.Converters/CustomTableFixture.cs @@ -46,5 +46,150 @@ namespace WixToolsetTest.Converters var actualLines = UnformattedDocumentLines(document); CompareLineByLine(expected, actualLines); } + + [Fact] + public void FixCustomRowTextValue() + { + var parse = String.Join(Environment.NewLine, + "", + "", + " ", + " ", + " ", + " Some value", + " ", + " ", + " ", + ""); + + var expected = new[] + { + "", + "", + " ", + " ", + " ", + " ", + " ", + "" + }; + + var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); + + var messaging = new MockMessaging(); + var converter = new Wix3Converter(messaging, 2, null, null); + + var errors = converter.ConvertDocument(document); + Assert.Equal(3, errors); + + var actualLines = UnformattedDocumentLines(document); + CompareLineByLine(expected, actualLines); + } + + [Fact] + public void FixCustomRowCdataValue() + { + var parse = String.Join(Environment.NewLine, + "", + "", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + ""); + + var expected = new[] + { + "", + "", + " ", + " ", + " ", + " ", + " ", + "" + }; + + var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); + + var messaging = new MockMessaging(); + var converter = new Wix3Converter(messaging, 2, null, null); + + var errors = converter.ConvertDocument(document); + Assert.Equal(3, errors); + + var actualLines = UnformattedDocumentLines(document); + CompareLineByLine(expected, actualLines); + } + + [Fact] + public void FixCustomRowWithoutValue() + { + var parse = String.Join(Environment.NewLine, + "", + "", + " ", + " ", + " ", + " ", + " ", + ""); + + var expected = new[] + { + "", + "", + " ", + " ", + " ", + " ", + " ", + "" + }; + + var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); + + var messaging = new MockMessaging(); + var converter = new Wix3Converter(messaging, 2, null, null); + + var errors = converter.ConvertDocument(document); + Assert.Equal(2, errors); + + var actualLines = UnformattedDocumentLines(document); + CompareLineByLine(expected, actualLines); + } + + [Fact] + public void CanConvertCustomTableBootstrapperApplicationData() + { + var parse = String.Join(Environment.NewLine, + "", + "", + " ", + ""); + + var expected = String.Join(Environment.NewLine, + "", + "", + " ", + ""); + + var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); + + var messaging = new MockMessaging(); + var converter = new Wix3Converter(messaging, 2, null, null); + + var errors = converter.ConvertDocument(document); + + var actual = UnformattedDocumentString(document); + + Assert.Equal(1, errors); + Assert.Equal(expected, actual); + } } } diff --git a/src/test/WixToolsetTest.Converters/PropertyFixture.cs b/src/test/WixToolsetTest.Converters/PropertyFixture.cs new file mode 100644 index 00000000..0449fb43 --- /dev/null +++ b/src/test/WixToolsetTest.Converters/PropertyFixture.cs @@ -0,0 +1,114 @@ +// 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.Converters +{ + using System; + using System.Xml.Linq; + using WixToolset.Converters; + using WixToolsetTest.Converters.Mocks; + using Xunit; + + public class PropertyFixture : BaseConverterFixture + { + [Fact] + public void CanFixCdataWhitespace() + { + var parse = String.Join(Environment.NewLine, + "", + "", + " ", + " ", + " ", + " ", + " ", + ""); + + var expected = String.Join(Environment.NewLine, + "", + "", + " ", + " ", + " ", + ""); + + var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); + + var messaging = new MockMessaging(); + var converter = new Wix3Converter(messaging, 2, null, null); + + var errors = converter.ConvertDocument(document); + + var actual = UnformattedDocumentString(document); + + Assert.Equal(expected, actual); + Assert.Equal(1, errors); + } + + [Fact] + public void CanFixCdataWithWhitespace() + { + var parse = String.Join(Environment.NewLine, + "", + "", + " ", + " ", + " ", + " ", + " ", + ""); + + var expected = String.Join(Environment.NewLine, + "", + "", + " ", + " ", + " ", + ""); + + var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); + + var messaging = new MockMessaging(); + var converter = new Wix3Converter(messaging, 2, null, null); + + var errors = converter.ConvertDocument(document); + + var actual = UnformattedDocumentString(document); + + Assert.Equal(expected, actual); + Assert.Equal(1, errors); + } + + [Fact] + public void CanKeepCdataWithOnlyWhitespace() + { + var parse = String.Join(Environment.NewLine, + "", + "", + " ", + " ", + " ", + ""); + + var expected = String.Join(Environment.NewLine, + "", + "", + " ", + " ", + " ", + ""); + + var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); + + var messaging = new MockMessaging(); + var converter = new Wix3Converter(messaging, 2, null, null); + var errors = converter.ConvertDocument(document); + + var actual = UnformattedDocumentString(document); + + Assert.Equal(expected, actual); + Assert.Equal(1, errors); + } + } +} diff --git a/src/test/WixToolsetTest.Converters/SequenceFixture.cs b/src/test/WixToolsetTest.Converters/SequenceFixture.cs new file mode 100644 index 00000000..997dcd6a --- /dev/null +++ b/src/test/WixToolsetTest.Converters/SequenceFixture.cs @@ -0,0 +1,50 @@ +// 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.Converters +{ + using System; + using System.Xml.Linq; + using WixToolset.Converters; + using WixToolsetTest.Converters.Mocks; + using Xunit; + + public class SequenceFixture : BaseConverterFixture + { + [Fact] + public void FixCondition() + { + var parse = String.Join(Environment.NewLine, + "", + "", + " ", + " ", + " NOT Installed", + " ", + " ", + ""); + + var expected = new[] + { + "", + "", + " ", + " ", + " ", + " ", + " ", + "" + }; + + var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); + + var messaging = new MockMessaging(); + var converter = new Wix3Converter(messaging, 2, null, null); + + var errors = converter.ConvertDocument(document); + Assert.Equal(3, errors); + + var actualLines = UnformattedDocumentLines(document); + CompareLineByLine(expected, actualLines); + } + } +} -- cgit v1.2.3-55-g6feb