diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/WixToolset.Converters/Wix3Converter.cs | 54 | ||||
| -rw-r--r-- | src/test/WixToolsetTest.Converters/CustomTableFixture.cs | 50 |
2 files changed, 103 insertions, 1 deletions
diff --git a/src/WixToolset.Converters/Wix3Converter.cs b/src/WixToolset.Converters/Wix3Converter.cs index 66ccd9d3..559e5368 100644 --- a/src/WixToolset.Converters/Wix3Converter.cs +++ b/src/WixToolset.Converters/Wix3Converter.cs | |||
| @@ -26,6 +26,7 @@ namespace WixToolset.Converters | |||
| 26 | private static readonly XNamespace WixNamespace = "http://wixtoolset.org/schemas/v4/wxs"; | 26 | private static readonly XNamespace WixNamespace = "http://wixtoolset.org/schemas/v4/wxs"; |
| 27 | private static readonly XNamespace WixUtilNamespace = "http://wixtoolset.org/schemas/v4/wxs/util"; | 27 | private static readonly XNamespace WixUtilNamespace = "http://wixtoolset.org/schemas/v4/wxs/util"; |
| 28 | 28 | ||
| 29 | private static readonly XName ColumnElementName = WixNamespace + "Column"; | ||
| 29 | private static readonly XName CreateFolderElementName = WixNamespace + "CreateFolder"; | 30 | private static readonly XName CreateFolderElementName = WixNamespace + "CreateFolder"; |
| 30 | private static readonly XName CustomTableElementName = WixNamespace + "CustomTable"; | 31 | private static readonly XName CustomTableElementName = WixNamespace + "CustomTable"; |
| 31 | private static readonly XName DirectoryElementName = WixNamespace + "Directory"; | 32 | private static readonly XName DirectoryElementName = WixNamespace + "Directory"; |
| @@ -82,6 +83,7 @@ namespace WixToolset.Converters | |||
| 82 | { | 83 | { |
| 83 | this.ConvertElementMapping = new Dictionary<XName, Action<XElement>> | 84 | this.ConvertElementMapping = new Dictionary<XName, Action<XElement>> |
| 84 | { | 85 | { |
| 86 | { Wix3Converter.ColumnElementName, this.ConvertColumnElement }, | ||
| 85 | { Wix3Converter.CustomTableElementName, this.ConvertCustomTableElement }, | 87 | { Wix3Converter.CustomTableElementName, this.ConvertCustomTableElement }, |
| 86 | { Wix3Converter.DirectoryElementName, this.ConvertDirectoryElement }, | 88 | { Wix3Converter.DirectoryElementName, this.ConvertDirectoryElement }, |
| 87 | { Wix3Converter.FileElementName, this.ConvertFileElement }, | 89 | { Wix3Converter.FileElementName, this.ConvertFileElement }, |
| @@ -298,6 +300,31 @@ namespace WixToolset.Converters | |||
| 298 | } | 300 | } |
| 299 | } | 301 | } |
| 300 | 302 | ||
| 303 | private void ConvertColumnElement(XElement element) | ||
| 304 | { | ||
| 305 | var category = element.Attribute("Category"); | ||
| 306 | if (category != null) | ||
| 307 | { | ||
| 308 | var camelCaseValue = LowercaseFirstChar(category.Value); | ||
| 309 | if (category.Value != camelCaseValue && | ||
| 310 | this.OnError(ConverterTestType.ColumnCategoryCamelCase, element, "The CustomTable Category attribute contains an incorrectly cased '{0}' value. Lowercase the first character instead.", category.Name)) | ||
| 311 | { | ||
| 312 | category.Value = camelCaseValue; | ||
| 313 | } | ||
| 314 | } | ||
| 315 | |||
| 316 | var modularization = element.Attribute("Modularize"); | ||
| 317 | if (modularization != null) | ||
| 318 | { | ||
| 319 | var camelCaseValue = LowercaseFirstChar(modularization.Value); | ||
| 320 | if (category.Value != camelCaseValue && | ||
| 321 | this.OnError(ConverterTestType.ColumnModularizeCamelCase, element, "The CustomTable Modularize attribute contains an incorrectly cased '{0}' value. Lowercase the first character instead.", modularization.Name)) | ||
| 322 | { | ||
| 323 | modularization.Value = camelCaseValue; | ||
| 324 | } | ||
| 325 | } | ||
| 326 | } | ||
| 327 | |||
| 301 | private void ConvertCustomTableElement(XElement element) | 328 | private void ConvertCustomTableElement(XElement element) |
| 302 | { | 329 | { |
| 303 | var bootstrapperApplicationData = element.Attribute("BootstrapperApplicationData"); | 330 | var bootstrapperApplicationData = element.Attribute("BootstrapperApplicationData"); |
| @@ -583,7 +610,7 @@ namespace WixToolset.Converters | |||
| 583 | /// <remarks>This is duplicated from WiX's Common class.</remarks> | 610 | /// <remarks>This is duplicated from WiX's Common class.</remarks> |
| 584 | private static string GetIdentifierFromName(string name) | 611 | private static string GetIdentifierFromName(string name) |
| 585 | { | 612 | { |
| 586 | string result = IllegalIdentifierCharacters.Replace(name, "_"); // replace illegal characters with "_". | 613 | var result = IllegalIdentifierCharacters.Replace(name, "_"); // replace illegal characters with "_". |
| 587 | 614 | ||
| 588 | // MSI identifiers must begin with an alphabetic character or an | 615 | // MSI identifiers must begin with an alphabetic character or an |
| 589 | // underscore. Prefix all other values with an underscore. | 616 | // underscore. Prefix all other values with an underscore. |
| @@ -595,6 +622,21 @@ namespace WixToolset.Converters | |||
| 595 | return result; | 622 | return result; |
| 596 | } | 623 | } |
| 597 | 624 | ||
| 625 | private static string LowercaseFirstChar(string value) | ||
| 626 | { | ||
| 627 | if (!String.IsNullOrEmpty(value)) | ||
| 628 | { | ||
| 629 | var c = Char.ToLowerInvariant(value[0]); | ||
| 630 | if (c != value[0]) | ||
| 631 | { | ||
| 632 | var remainder = value.Length > 1 ? value.Substring(1) : String.Empty; | ||
| 633 | return c + remainder; | ||
| 634 | } | ||
| 635 | } | ||
| 636 | |||
| 637 | return value; | ||
| 638 | } | ||
| 639 | |||
| 598 | /// <summary> | 640 | /// <summary> |
| 599 | /// Converter test types. These are used to condition error messages down to warnings. | 641 | /// Converter test types. These are used to condition error messages down to warnings. |
| 600 | /// </summary> | 642 | /// </summary> |
| @@ -699,6 +741,16 @@ namespace WixToolset.Converters | |||
| 699 | /// Inheritable is new and is now defaulted to 'yes' which is a change in behavior for all but children of CreateFolder. | 741 | /// Inheritable is new and is now defaulted to 'yes' which is a change in behavior for all but children of CreateFolder. |
| 700 | /// </summary> | 742 | /// </summary> |
| 701 | AssignPermissionExInheritable, | 743 | AssignPermissionExInheritable, |
| 744 | |||
| 745 | /// <summary> | ||
| 746 | /// Column element's Category attribute is camel-case. | ||
| 747 | /// </summary> | ||
| 748 | ColumnCategoryCamelCase, | ||
| 749 | |||
| 750 | /// <summary> | ||
| 751 | /// Column element's Modularize attribute is camel-case. | ||
| 752 | /// </summary> | ||
| 753 | ColumnModularizeCamelCase, | ||
| 702 | } | 754 | } |
| 703 | } | 755 | } |
| 704 | } | 756 | } |
diff --git a/src/test/WixToolsetTest.Converters/CustomTableFixture.cs b/src/test/WixToolsetTest.Converters/CustomTableFixture.cs new file mode 100644 index 00000000..5a572294 --- /dev/null +++ b/src/test/WixToolsetTest.Converters/CustomTableFixture.cs | |||
| @@ -0,0 +1,50 @@ | |||
| 1 | // 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. | ||
| 2 | |||
| 3 | namespace WixToolsetTest.Converters | ||
| 4 | { | ||
| 5 | using System; | ||
| 6 | using System.Xml.Linq; | ||
| 7 | using WixToolset.Converters; | ||
| 8 | using WixToolsetTest.Converters.Mocks; | ||
| 9 | using Xunit; | ||
| 10 | |||
| 11 | public class CustomTableFixture : BaseConverterFixture | ||
| 12 | { | ||
| 13 | [Fact] | ||
| 14 | public void FixCustomTableCategoryAndModularization() | ||
| 15 | { | ||
| 16 | var parse = String.Join(Environment.NewLine, | ||
| 17 | "<?xml version=\"1.0\" encoding=\"utf-16\"?>", | ||
| 18 | "<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>", | ||
| 19 | " <Fragment>", | ||
| 20 | " <CustomTable Id='Custom1'>", | ||
| 21 | " <Column Id='Column1' Type='string' Category='Text' Modularize='Column' />", | ||
| 22 | " </CustomTable>", | ||
| 23 | " </Fragment>", | ||
| 24 | "</Wix>"); | ||
| 25 | |||
| 26 | var expected = new[] | ||
| 27 | { | ||
| 28 | "<?xml version=\"1.0\" encoding=\"utf-16\"?>", | ||
| 29 | "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">", | ||
| 30 | " <Fragment>", | ||
| 31 | " <CustomTable Id=\"Custom1\">", | ||
| 32 | " <Column Id=\"Column1\" Type=\"string\" Category=\"text\" Modularize=\"column\" />", | ||
| 33 | " </CustomTable>", | ||
| 34 | " </Fragment>", | ||
| 35 | "</Wix>" | ||
| 36 | }; | ||
| 37 | |||
| 38 | var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); | ||
| 39 | |||
| 40 | var messaging = new MockMessaging(); | ||
| 41 | var converter = new Wix3Converter(messaging, 2, null, null); | ||
| 42 | |||
| 43 | var errors = converter.ConvertDocument(document); | ||
| 44 | Assert.Equal(4, errors); | ||
| 45 | |||
| 46 | var actualLines = UnformattedDocumentLines(document); | ||
| 47 | CompareLineByLine(expected, actualLines); | ||
| 48 | } | ||
| 49 | } | ||
| 50 | } | ||
