diff options
author | Rob Mensching <rob@firegiant.com> | 2020-06-23 00:58:11 -0700 |
---|---|---|
committer | Rob Mensching <rob@firegiant.com> | 2020-06-23 16:56:04 -0700 |
commit | 7987d2f7e2d47427d7571ab7cc3640d7b0bbb7ff (patch) | |
tree | 97e5a295cc5ccfaa0ad47d692c3103d7d49b5962 /src | |
parent | 99cdb4f1d7829a2efb503881abe57033672c2b47 (diff) | |
download | wix-7987d2f7e2d47427d7571ab7cc3640d7b0bbb7ff.tar.gz wix-7987d2f7e2d47427d7571ab7cc3640d7b0bbb7ff.tar.bz2 wix-7987d2f7e2d47427d7571ab7cc3640d7b0bbb7ff.zip |
Convert inner text to appropriate attributes
Diffstat (limited to 'src')
-rw-r--r-- | src/WixToolset.Converters/Wix3Converter.cs | 280 | ||||
-rw-r--r-- | src/test/WixToolsetTest.Converters/ConditionFixture.cs | 208 | ||||
-rw-r--r-- | src/test/WixToolsetTest.Converters/ConverterFixture.cs | 151 | ||||
-rw-r--r-- | src/test/WixToolsetTest.Converters/CustomActionFixture.cs | 90 | ||||
-rw-r--r-- | src/test/WixToolsetTest.Converters/CustomTableFixture.cs | 145 | ||||
-rw-r--r-- | src/test/WixToolsetTest.Converters/PropertyFixture.cs | 114 | ||||
-rw-r--r-- | src/test/WixToolsetTest.Converters/SequenceFixture.cs | 50 |
7 files changed, 886 insertions, 152 deletions
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 | |||
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 AdminExecuteSequenceElementName = WixNamespace + "AdminExecuteSequence"; | ||
30 | private static readonly XName AdminUISequenceSequenceElementName = WixNamespace + "AdminUISequence"; | ||
31 | private static readonly XName AdvertiseExecuteSequenceElementName = WixNamespace + "AdvertiseExecuteSequence"; | ||
32 | private static readonly XName InstallExecuteSequenceElementName = WixNamespace + "InstallExecuteSequence"; | ||
33 | private static readonly XName InstallUISequenceSequenceElementName = WixNamespace + "InstallUISequence"; | ||
34 | private static readonly XName EmbeddedChainerElementName = WixNamespace + "EmbeddedChainer"; | ||
29 | private static readonly XName ColumnElementName = WixNamespace + "Column"; | 35 | private static readonly XName ColumnElementName = WixNamespace + "Column"; |
36 | private static readonly XName ComponentElementName = WixNamespace + "Component"; | ||
37 | private static readonly XName ControlElementName = WixNamespace + "Control"; | ||
38 | private static readonly XName ConditionElementName = WixNamespace + "Condition"; | ||
30 | private static readonly XName CreateFolderElementName = WixNamespace + "CreateFolder"; | 39 | private static readonly XName CreateFolderElementName = WixNamespace + "CreateFolder"; |
31 | private static readonly XName CustomTableElementName = WixNamespace + "CustomTable"; | 40 | private static readonly XName CustomTableElementName = WixNamespace + "CustomTable"; |
32 | private static readonly XName DirectoryElementName = WixNamespace + "Directory"; | 41 | private static readonly XName DirectoryElementName = WixNamespace + "Directory"; |
42 | private static readonly XName FeatureElementName = WixNamespace + "Feature"; | ||
33 | private static readonly XName FileElementName = WixNamespace + "File"; | 43 | private static readonly XName FileElementName = WixNamespace + "File"; |
44 | private static readonly XName FragmentElementName = WixNamespace + "Fragment"; | ||
45 | private static readonly XName ErrorElementName = WixNamespace + "Error"; | ||
46 | private static readonly XName LaunchElementName = WixNamespace + "Launch"; | ||
47 | private static readonly XName LevelElementName = WixNamespace + "Level"; | ||
34 | private static readonly XName ExePackageElementName = WixNamespace + "ExePackage"; | 48 | private static readonly XName ExePackageElementName = WixNamespace + "ExePackage"; |
35 | private static readonly XName MsiPackageElementName = WixNamespace + "MsiPackage"; | 49 | private static readonly XName MsiPackageElementName = WixNamespace + "MsiPackage"; |
36 | private static readonly XName MspPackageElementName = WixNamespace + "MspPackage"; | 50 | private static readonly XName MspPackageElementName = WixNamespace + "MspPackage"; |
37 | private static readonly XName MsuPackageElementName = WixNamespace + "MsuPackage"; | 51 | private static readonly XName MsuPackageElementName = WixNamespace + "MsuPackage"; |
38 | private static readonly XName PayloadElementName = WixNamespace + "Payload"; | 52 | private static readonly XName PayloadElementName = WixNamespace + "Payload"; |
53 | private static readonly XName PermissionExElementName = WixNamespace + "PermissionEx"; | ||
54 | private static readonly XName ProductElementName = WixNamespace + "Product"; | ||
55 | private static readonly XName ProgressTextElementName = WixNamespace + "ProgressText"; | ||
56 | private static readonly XName PublishElementName = WixNamespace + "Publish"; | ||
57 | private static readonly XName MultiStringValueElementName = WixNamespace + "MultiStringValue"; | ||
58 | private static readonly XName RequiredPrivilegeElementName = WixNamespace + "RequiredPrivilege"; | ||
59 | private static readonly XName RowElementName = WixNamespace + "Row"; | ||
60 | private static readonly XName ServiceArgumentElementName = WixNamespace + "ServiceArgument"; | ||
61 | private static readonly XName SetDirectoryElementName = WixNamespace + "SetDirectory"; | ||
62 | private static readonly XName SetPropertyElementName = WixNamespace + "SetProperty"; | ||
63 | private static readonly XName ShortcutPropertyElementName = WixNamespace + "ShortcutProperty"; | ||
64 | private static readonly XName TextElementName = WixNamespace + "Text"; | ||
65 | private static readonly XName UITextElementName = WixNamespace + "UIText"; | ||
39 | private static readonly XName UtilPermissionExElementName = WixUtilNamespace + "PermissionEx"; | 66 | private static readonly XName UtilPermissionExElementName = WixUtilNamespace + "PermissionEx"; |
40 | private static readonly XName CustomActionElementName = WixNamespace + "CustomAction"; | 67 | private static readonly XName CustomActionElementName = WixNamespace + "CustomAction"; |
41 | private static readonly XName PropertyElementName = WixNamespace + "Property"; | 68 | private static readonly XName PropertyElementName = WixNamespace + "Property"; |
@@ -83,16 +110,40 @@ namespace WixToolset.Converters | |||
83 | { | 110 | { |
84 | this.ConvertElementMapping = new Dictionary<XName, Action<XElement>> | 111 | this.ConvertElementMapping = new Dictionary<XName, Action<XElement>> |
85 | { | 112 | { |
113 | { Wix3Converter.AdminExecuteSequenceElementName, this.ConvertSequenceElement }, | ||
114 | { Wix3Converter.AdminUISequenceSequenceElementName, this.ConvertSequenceElement }, | ||
115 | { Wix3Converter.AdvertiseExecuteSequenceElementName, this.ConvertSequenceElement }, | ||
116 | { Wix3Converter.InstallUISequenceSequenceElementName, this.ConvertSequenceElement }, | ||
117 | { Wix3Converter.InstallExecuteSequenceElementName, this.ConvertSequenceElement }, | ||
86 | { Wix3Converter.ColumnElementName, this.ConvertColumnElement }, | 118 | { Wix3Converter.ColumnElementName, this.ConvertColumnElement }, |
87 | { Wix3Converter.CustomTableElementName, this.ConvertCustomTableElement }, | 119 | { Wix3Converter.CustomTableElementName, this.ConvertCustomTableElement }, |
120 | { Wix3Converter.ControlElementName, this.ConvertControlElement }, | ||
121 | { Wix3Converter.ComponentElementName, this.ConvertComponentElement }, | ||
88 | { Wix3Converter.DirectoryElementName, this.ConvertDirectoryElement }, | 122 | { Wix3Converter.DirectoryElementName, this.ConvertDirectoryElement }, |
123 | { Wix3Converter.FeatureElementName, this.ConvertFeatureElement }, | ||
89 | { Wix3Converter.FileElementName, this.ConvertFileElement }, | 124 | { Wix3Converter.FileElementName, this.ConvertFileElement }, |
125 | { Wix3Converter.FragmentElementName, this.ConvertFragmentElement }, | ||
126 | { Wix3Converter.EmbeddedChainerElementName, this.ConvertEmbeddedChainerElement }, | ||
127 | { Wix3Converter.ErrorElementName, this.ConvertErrorElement }, | ||
90 | { Wix3Converter.ExePackageElementName, this.ConvertSuppressSignatureValidation }, | 128 | { Wix3Converter.ExePackageElementName, this.ConvertSuppressSignatureValidation }, |
91 | { Wix3Converter.MsiPackageElementName, this.ConvertSuppressSignatureValidation }, | 129 | { Wix3Converter.MsiPackageElementName, this.ConvertSuppressSignatureValidation }, |
92 | { Wix3Converter.MspPackageElementName, this.ConvertSuppressSignatureValidation }, | 130 | { Wix3Converter.MspPackageElementName, this.ConvertSuppressSignatureValidation }, |
93 | { Wix3Converter.MsuPackageElementName, this.ConvertSuppressSignatureValidation }, | 131 | { Wix3Converter.MsuPackageElementName, this.ConvertSuppressSignatureValidation }, |
94 | { Wix3Converter.PayloadElementName, this.ConvertSuppressSignatureValidation }, | 132 | { Wix3Converter.PayloadElementName, this.ConvertSuppressSignatureValidation }, |
133 | { Wix3Converter.PermissionExElementName, this.ConvertPermissionExElement }, | ||
134 | { Wix3Converter.ProductElementName, this.ConvertProductElement }, | ||
135 | { Wix3Converter.ProgressTextElementName, this.ConvertProgressTextElement }, | ||
136 | { Wix3Converter.PublishElementName, this.ConvertPublishElement }, | ||
137 | { Wix3Converter.MultiStringValueElementName, this.ConvertMultiStringValueElement }, | ||
138 | { Wix3Converter.RequiredPrivilegeElementName, this.ConvertRequiredPrivilegeElement }, | ||
139 | { Wix3Converter.RowElementName, this.ConvertRowElement }, | ||
95 | { Wix3Converter.CustomActionElementName, this.ConvertCustomActionElement }, | 140 | { Wix3Converter.CustomActionElementName, this.ConvertCustomActionElement }, |
141 | { Wix3Converter.ServiceArgumentElementName, this.ConvertServiceArgumentElement }, | ||
142 | { Wix3Converter.SetDirectoryElementName, this.ConvertSetDirectoryElement }, | ||
143 | { Wix3Converter.SetPropertyElementName, this.ConvertSetPropertyElement }, | ||
144 | { Wix3Converter.ShortcutPropertyElementName, this.ConvertShortcutPropertyElement }, | ||
145 | { Wix3Converter.TextElementName, this.ConvertTextElement }, | ||
146 | { Wix3Converter.UITextElementName, this.ConvertUITextElement }, | ||
96 | { Wix3Converter.UtilPermissionExElementName, this.ConvertUtilPermissionExElement }, | 147 | { Wix3Converter.UtilPermissionExElementName, this.ConvertUtilPermissionExElement }, |
97 | { Wix3Converter.PropertyElementName, this.ConvertPropertyElement }, | 148 | { Wix3Converter.PropertyElementName, this.ConvertPropertyElement }, |
98 | { Wix3Converter.WixElementWithoutNamespaceName, this.ConvertElementWithoutNamespace }, | 149 | { Wix3Converter.WixElementWithoutNamespaceName, this.ConvertElementWithoutNamespace }, |
@@ -173,6 +224,8 @@ namespace WixToolset.Converters | |||
173 | /// <returns>The number of errors found.</returns> | 224 | /// <returns>The number of errors found.</returns> |
174 | public int ConvertDocument(XDocument document) | 225 | public int ConvertDocument(XDocument document) |
175 | { | 226 | { |
227 | this.Errors = 0; | ||
228 | |||
176 | var declaration = document.Declaration; | 229 | var declaration = document.Declaration; |
177 | 230 | ||
178 | // Convert the declaration. | 231 | // Convert the declaration. |
@@ -336,6 +389,36 @@ namespace WixToolset.Converters | |||
336 | } | 389 | } |
337 | } | 390 | } |
338 | 391 | ||
392 | private void ConvertControlElement(XElement element) | ||
393 | { | ||
394 | var xCondition = element.Element(ConditionElementName); | ||
395 | if (xCondition != null) | ||
396 | { | ||
397 | var action = UppercaseFirstChar(xCondition.Attribute("Action")?.Value); | ||
398 | if (!String.IsNullOrEmpty(action) && | ||
399 | TryGetInnerText(xCondition, out var text) && | ||
400 | this.OnError(ConverterTestType.InnerTextDeprecated, element, "Using {0} element text is deprecated. Use the '{1}Condition' attribute instead.", xCondition.Name.LocalName, action)) | ||
401 | { | ||
402 | element.Add(new XAttribute(action + "Condition", text)); | ||
403 | xCondition.Remove(); | ||
404 | } | ||
405 | } | ||
406 | } | ||
407 | |||
408 | private void ConvertComponentElement(XElement element) | ||
409 | { | ||
410 | var xCondition = element.Element(ConditionElementName); | ||
411 | if (xCondition != null) | ||
412 | { | ||
413 | if (TryGetInnerText(xCondition, out var text) && | ||
414 | this.OnError(ConverterTestType.InnerTextDeprecated, element, "Using {0} element text is deprecated. Use the 'Condition' attribute instead.", xCondition.Name.LocalName)) | ||
415 | { | ||
416 | element.Add(new XAttribute("Condition", text)); | ||
417 | xCondition.Remove(); | ||
418 | } | ||
419 | } | ||
420 | } | ||
421 | |||
339 | private void ConvertDirectoryElement(XElement element) | 422 | private void ConvertDirectoryElement(XElement element) |
340 | { | 423 | { |
341 | if (null == element.Attribute("Name")) | 424 | if (null == element.Attribute("Name")) |
@@ -353,6 +436,25 @@ namespace WixToolset.Converters | |||
353 | } | 436 | } |
354 | } | 437 | } |
355 | 438 | ||
439 | private void ConvertFeatureElement(XElement element) | ||
440 | { | ||
441 | var xCondition = element.Element(ConditionElementName); | ||
442 | if (xCondition != null) | ||
443 | { | ||
444 | var level = xCondition.Attribute("Level")?.Value; | ||
445 | if (!String.IsNullOrEmpty(level) && | ||
446 | TryGetInnerText(xCondition, out var text) && | ||
447 | this.OnError(ConverterTestType.InnerTextDeprecated, element, "Using {0} element text is deprecated. Use the 'Level' element instead.", xCondition.Name.LocalName)) | ||
448 | { | ||
449 | xCondition.AddAfterSelf(new XElement(LevelElementName, | ||
450 | new XAttribute("Value", level), | ||
451 | new XAttribute("Condition", text) | ||
452 | )); | ||
453 | xCondition.Remove(); | ||
454 | } | ||
455 | } | ||
456 | } | ||
457 | |||
356 | private void ConvertFileElement(XElement element) | 458 | private void ConvertFileElement(XElement element) |
357 | { | 459 | { |
358 | if (null == element.Attribute("Id")) | 460 | if (null == element.Attribute("Id")) |
@@ -379,6 +481,90 @@ namespace WixToolset.Converters | |||
379 | } | 481 | } |
380 | } | 482 | } |
381 | 483 | ||
484 | private void ConvertFragmentElement(XElement element) | ||
485 | { | ||
486 | var xCondition = element.Element(ConditionElementName); | ||
487 | if (xCondition != null) | ||
488 | { | ||
489 | var message = xCondition.Attribute("Message")?.Value; | ||
490 | |||
491 | if (!String.IsNullOrEmpty(message) && | ||
492 | TryGetInnerText(xCondition, out var text) && | ||
493 | this.OnError(ConverterTestType.InnerTextDeprecated, element, "Using {0} element text is deprecated. Use the 'Launch' element instead.", xCondition.Name.LocalName)) | ||
494 | { | ||
495 | xCondition.AddAfterSelf(new XElement(LaunchElementName, | ||
496 | new XAttribute("Condition", text), | ||
497 | new XAttribute("Message", message) | ||
498 | )); | ||
499 | xCondition.Remove(); | ||
500 | } | ||
501 | } | ||
502 | } | ||
503 | |||
504 | private void ConvertEmbeddedChainerElement(XElement element) => this.ConvertInnerTextToAttribute(element, "Condition"); | ||
505 | |||
506 | private void ConvertErrorElement(XElement element) => this.ConvertInnerTextToAttribute(element, "Message"); | ||
507 | |||
508 | private void ConvertPermissionExElement(XElement element) | ||
509 | { | ||
510 | var xCondition = element.Element(ConditionElementName); | ||
511 | if (xCondition != null) | ||
512 | { | ||
513 | if (TryGetInnerText(xCondition, out var text) && | ||
514 | this.OnError(ConverterTestType.InnerTextDeprecated, element, "Using {0} element text is deprecated. Use the 'Condition' attribute instead.", xCondition.Name.LocalName)) | ||
515 | { | ||
516 | element.Add(new XAttribute("Condition", text)); | ||
517 | xCondition.Remove(); | ||
518 | } | ||
519 | } | ||
520 | } | ||
521 | |||
522 | private void ConvertProgressTextElement(XElement element) => this.ConvertInnerTextToAttribute(element, "Message"); | ||
523 | |||
524 | private void ConvertProductElement(XElement element) | ||
525 | { | ||
526 | var xCondition = element.Element(ConditionElementName); | ||
527 | if (xCondition != null) | ||
528 | { | ||
529 | var message = element.Attribute("Message")?.Value; | ||
530 | |||
531 | if (!String.IsNullOrEmpty(message) && | ||
532 | TryGetInnerText(xCondition, out var text) && | ||
533 | this.OnError(ConverterTestType.InnerTextDeprecated, element, "Using {0} element text is deprecated. Use the 'Launch' element instead.", xCondition.Name.LocalName)) | ||
534 | { | ||
535 | xCondition.AddAfterSelf(new XElement(LaunchElementName, | ||
536 | new XAttribute("Condition", text), | ||
537 | new XAttribute("Message", message) | ||
538 | )); | ||
539 | xCondition.Remove(); | ||
540 | } | ||
541 | } | ||
542 | } | ||
543 | |||
544 | private void ConvertPublishElement(XElement element) => this.ConvertInnerTextToAttribute(element, "Condition"); | ||
545 | |||
546 | private void ConvertMultiStringValueElement(XElement element) => this.ConvertInnerTextToAttribute(element, "Value"); | ||
547 | |||
548 | private void ConvertRequiredPrivilegeElement(XElement element) => this.ConvertInnerTextToAttribute(element, "Name"); | ||
549 | |||
550 | private void ConvertRowElement(XElement element) => this.ConvertInnerTextToAttribute(element, "Value"); | ||
551 | |||
552 | private void ConvertSequenceElement(XElement element) | ||
553 | { | ||
554 | foreach (var child in element.Elements()) | ||
555 | { | ||
556 | this.ConvertInnerTextToAttribute(child, "Condition"); | ||
557 | } | ||
558 | } | ||
559 | |||
560 | private void ConvertServiceArgumentElement(XElement element) => this.ConvertInnerTextToAttribute(element, "Value"); | ||
561 | |||
562 | private void ConvertSetDirectoryElement(XElement element) => this.ConvertInnerTextToAttribute(element, "Condition"); | ||
563 | |||
564 | private void ConvertSetPropertyElement(XElement element) => this.ConvertInnerTextToAttribute(element, "Condition"); | ||
565 | |||
566 | private void ConvertShortcutPropertyElement(XElement element) => this.ConvertInnerTextToAttribute(element, "Value"); | ||
567 | |||
382 | private void ConvertSuppressSignatureValidation(XElement element) | 568 | private void ConvertSuppressSignatureValidation(XElement element) |
383 | { | 569 | { |
384 | var suppressSignatureValidation = element.Attribute("SuppressSignatureValidation"); | 570 | var suppressSignatureValidation = element.Attribute("SuppressSignatureValidation"); |
@@ -397,6 +583,10 @@ namespace WixToolset.Converters | |||
397 | } | 583 | } |
398 | } | 584 | } |
399 | 585 | ||
586 | private void ConvertTextElement(XElement element) => this.ConvertInnerTextToAttribute(element, "Value"); | ||
587 | |||
588 | private void ConvertUITextElement(XElement element) => this.ConvertInnerTextToAttribute(element, "Value"); | ||
589 | |||
400 | private void ConvertCustomActionElement(XElement xCustomAction) | 590 | private void ConvertCustomActionElement(XElement xCustomAction) |
401 | { | 591 | { |
402 | var xBinaryKey = xCustomAction.Attribute("BinaryKey"); | 592 | var xBinaryKey = xCustomAction.Attribute("BinaryKey"); |
@@ -436,6 +626,24 @@ namespace WixToolset.Converters | |||
436 | xProperty.Value = xProperty.Value.Replace("QtExec", "WixQuietExec"); | 626 | xProperty.Value = xProperty.Value.Replace("QtExec", "WixQuietExec"); |
437 | } | 627 | } |
438 | } | 628 | } |
629 | |||
630 | var xScript = xCustomAction.Attribute("Script"); | ||
631 | |||
632 | if (xScript != null && TryGetInnerText(xCustomAction, out var scriptText)) | ||
633 | { | ||
634 | 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)) | ||
635 | { | ||
636 | var scriptFolder = Path.GetDirectoryName(this.SourceFile) ?? String.Empty; | ||
637 | var id = xCustomAction.Attribute("Id")?.Value ?? Guid.NewGuid().ToString("N"); | ||
638 | var ext = (xScript.Value == "jscript") ? ".js" : (xScript.Value == "vbscript") ? ".vbs" : ".txt"; | ||
639 | |||
640 | var scriptFile = Path.Combine(scriptFolder, id + ext); | ||
641 | File.WriteAllText(scriptFile, scriptText); | ||
642 | |||
643 | RemoveChildren(xCustomAction); | ||
644 | xCustomAction.Add(new XAttribute("ScriptFile", scriptFile)); | ||
645 | } | ||
646 | } | ||
439 | } | 647 | } |
440 | 648 | ||
441 | private void ConvertPropertyElement(XElement xProperty) | 649 | private void ConvertPropertyElement(XElement xProperty) |
@@ -446,6 +654,8 @@ namespace WixToolset.Converters | |||
446 | { | 654 | { |
447 | this.OnError(ConverterTestType.QtExecCmdTimeoutAmbiguous, xProperty, "QtExecCmdTimeout was previously used for both CAQuietExec and CAQuietExec64. For WixQuietExec, use WixQuietExecCmdTimeout. For WixQuietExec64, use WixQuietExec64CmdTimeout."); | 655 | this.OnError(ConverterTestType.QtExecCmdTimeoutAmbiguous, xProperty, "QtExecCmdTimeout was previously used for both CAQuietExec and CAQuietExec64. For WixQuietExec, use WixQuietExecCmdTimeout. For WixQuietExec64, use WixQuietExec64CmdTimeout."); |
448 | } | 656 | } |
657 | |||
658 | this.ConvertInnerTextToAttribute(xProperty, "Value"); | ||
449 | } | 659 | } |
450 | 660 | ||
451 | private void ConvertUtilPermissionExElement(XElement element) | 661 | private void ConvertUtilPermissionExElement(XElement element) |
@@ -483,13 +693,22 @@ namespace WixToolset.Converters | |||
483 | } | 693 | } |
484 | } | 694 | } |
485 | 695 | ||
696 | private void ConvertInnerTextToAttribute(XElement element, string attributeName) | ||
697 | { | ||
698 | if (TryGetInnerText(element, out var text) && | ||
699 | this.OnError(ConverterTestType.InnerTextDeprecated, element, "Using {0} element text is deprecated. Use the '{1}' attribute instead.", element.Name.LocalName, attributeName)) | ||
700 | { | ||
701 | element.Add(new XAttribute(attributeName, text)); | ||
702 | RemoveChildren(element); | ||
703 | } | ||
704 | } | ||
705 | |||
486 | private IEnumerable<ConverterTestType> YieldConverterTypes(IEnumerable<string> types) | 706 | private IEnumerable<ConverterTestType> YieldConverterTypes(IEnumerable<string> types) |
487 | { | 707 | { |
488 | if (null != types) | 708 | if (null != types) |
489 | { | 709 | { |
490 | foreach (var type in types) | 710 | foreach (var type in types) |
491 | { | 711 | { |
492 | |||
493 | if (Enum.TryParse<ConverterTestType>(type, true, out var itt)) | 712 | if (Enum.TryParse<ConverterTestType>(type, true, out var itt)) |
494 | { | 713 | { |
495 | yield return itt; | 714 | yield return itt; |
@@ -637,6 +856,60 @@ namespace WixToolset.Converters | |||
637 | return value; | 856 | return value; |
638 | } | 857 | } |
639 | 858 | ||
859 | private static string UppercaseFirstChar(string value) | ||
860 | { | ||
861 | if (!String.IsNullOrEmpty(value)) | ||
862 | { | ||
863 | var c = Char.ToUpperInvariant(value[0]); | ||
864 | if (c != value[0]) | ||
865 | { | ||
866 | var remainder = value.Length > 1 ? value.Substring(1) : String.Empty; | ||
867 | return c + remainder; | ||
868 | } | ||
869 | } | ||
870 | |||
871 | return value; | ||
872 | } | ||
873 | |||
874 | private static bool TryGetInnerText(XElement element, out string value) | ||
875 | { | ||
876 | value = null; | ||
877 | |||
878 | var nodes = element.Nodes(); | ||
879 | |||
880 | if (nodes.All(e => e.NodeType == XmlNodeType.Text || e.NodeType == XmlNodeType.CDATA)) | ||
881 | { | ||
882 | value = String.Join(String.Empty, nodes.Cast<XText>().Select(TrimTextValue)); | ||
883 | } | ||
884 | |||
885 | return !String.IsNullOrEmpty(value); | ||
886 | } | ||
887 | |||
888 | private static string TrimTextValue(XText text) | ||
889 | { | ||
890 | var value = text.Value; | ||
891 | |||
892 | if (String.IsNullOrEmpty(value)) | ||
893 | { | ||
894 | return String.Empty; | ||
895 | } | ||
896 | else if (text.NodeType == XmlNodeType.CDATA && String.IsNullOrWhiteSpace(value)) | ||
897 | { | ||
898 | return " "; | ||
899 | } | ||
900 | |||
901 | return value.Trim(); | ||
902 | } | ||
903 | |||
904 | private static void RemoveChildren(XElement element) | ||
905 | { | ||
906 | var nodes = element.Nodes().ToList(); | ||
907 | foreach (var node in nodes) | ||
908 | { | ||
909 | node.Remove(); | ||
910 | } | ||
911 | } | ||
912 | |||
640 | /// <summary> | 913 | /// <summary> |
641 | /// Converter test types. These are used to condition error messages down to warnings. | 914 | /// Converter test types. These are used to condition error messages down to warnings. |
642 | /// </summary> | 915 | /// </summary> |
@@ -751,6 +1024,11 @@ namespace WixToolset.Converters | |||
751 | /// Column element's Modularize attribute is camel-case. | 1024 | /// Column element's Modularize attribute is camel-case. |
752 | /// </summary> | 1025 | /// </summary> |
753 | ColumnModularizeCamelCase, | 1026 | ColumnModularizeCamelCase, |
1027 | |||
1028 | /// <summary> | ||
1029 | /// Inner text value should move to an attribute. | ||
1030 | /// </summary> | ||
1031 | InnerTextDeprecated, | ||
754 | } | 1032 | } |
755 | } | 1033 | } |
756 | } | 1034 | } |
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 @@ | |||
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 ConditionFixture : BaseConverterFixture | ||
12 | { | ||
13 | [Fact] | ||
14 | public void FixControlCondition() | ||
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 | " <UI>", | ||
21 | " <Dialog Id='Dlg1'>", | ||
22 | " <Control Id='Control1'>", | ||
23 | " <Condition Action='hide'>a<>b</Condition>", | ||
24 | " </Control>", | ||
25 | " </Dialog>", | ||
26 | " </UI>", | ||
27 | " </Fragment>", | ||
28 | "</Wix>"); | ||
29 | |||
30 | var expected = new[] | ||
31 | { | ||
32 | "<?xml version=\"1.0\" encoding=\"utf-16\"?>", | ||
33 | "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">", | ||
34 | " <Fragment>", | ||
35 | " <UI>", | ||
36 | " <Dialog Id=\"Dlg1\">", | ||
37 | " <Control Id=\"Control1\" HideCondition=\"a<>b\">", | ||
38 | " ", | ||
39 | " </Control>", | ||
40 | " </Dialog>", | ||
41 | " </UI>", | ||
42 | " </Fragment>", | ||
43 | "</Wix>" | ||
44 | }; | ||
45 | |||
46 | var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); | ||
47 | |||
48 | var messaging = new MockMessaging(); | ||
49 | var converter = new Wix3Converter(messaging, 2, null, null); | ||
50 | |||
51 | var errors = converter.ConvertDocument(document); | ||
52 | Assert.Equal(3, errors); | ||
53 | |||
54 | var actualLines = UnformattedDocumentLines(document); | ||
55 | CompareLineByLine(expected, actualLines); | ||
56 | } | ||
57 | |||
58 | [Fact] | ||
59 | public void FixComponentCondition() | ||
60 | { | ||
61 | var parse = String.Join(Environment.NewLine, | ||
62 | "<?xml version=\"1.0\" encoding=\"utf-16\"?>", | ||
63 | "<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>", | ||
64 | " <Fragment>", | ||
65 | " <Component Id='Comp1' Directory='ApplicationFolder'>", | ||
66 | " <Condition>1<2</Condition>", | ||
67 | " </Component>", | ||
68 | " </Fragment>", | ||
69 | "</Wix>"); | ||
70 | |||
71 | var expected = new[] | ||
72 | { | ||
73 | "<?xml version=\"1.0\" encoding=\"utf-16\"?>", | ||
74 | "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">", | ||
75 | " <Fragment>", | ||
76 | " <Component Id=\"Comp1\" Directory=\"ApplicationFolder\" Condition=\"1<2\">", | ||
77 | " ", | ||
78 | " </Component>", | ||
79 | " </Fragment>", | ||
80 | "</Wix>" | ||
81 | }; | ||
82 | |||
83 | var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); | ||
84 | |||
85 | var messaging = new MockMessaging(); | ||
86 | var converter = new Wix3Converter(messaging, 2, null, null); | ||
87 | |||
88 | var errors = converter.ConvertDocument(document); | ||
89 | Assert.Equal(3, errors); | ||
90 | |||
91 | var actualLines = UnformattedDocumentLines(document); | ||
92 | CompareLineByLine(expected, actualLines); | ||
93 | } | ||
94 | |||
95 | [Fact] | ||
96 | public void FixFeatureCondition() | ||
97 | { | ||
98 | var parse = String.Join(Environment.NewLine, | ||
99 | "<?xml version=\"1.0\" encoding=\"utf-16\"?>", | ||
100 | "<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>", | ||
101 | " <Fragment>", | ||
102 | " <Feature Id='Feature1'>", | ||
103 | " <Condition Level='0'>PROP = 1</Condition>", | ||
104 | " </Feature>", | ||
105 | " </Fragment>", | ||
106 | "</Wix>"); | ||
107 | |||
108 | var expected = new[] | ||
109 | { | ||
110 | "<?xml version=\"1.0\" encoding=\"utf-16\"?>", | ||
111 | "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">", | ||
112 | " <Fragment>", | ||
113 | " <Feature Id=\"Feature1\">", | ||
114 | " <Level Value=\"0\" Condition=\"PROP = 1\" />", | ||
115 | " </Feature>", | ||
116 | " </Fragment>", | ||
117 | "</Wix>" | ||
118 | }; | ||
119 | |||
120 | var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); | ||
121 | |||
122 | var messaging = new MockMessaging(); | ||
123 | var converter = new Wix3Converter(messaging, 2, null, null); | ||
124 | |||
125 | var errors = converter.ConvertDocument(document); | ||
126 | Assert.Equal(3, errors); | ||
127 | |||
128 | var actualLines = UnformattedDocumentLines(document); | ||
129 | CompareLineByLine(expected, actualLines); | ||
130 | } | ||
131 | |||
132 | [Fact] | ||
133 | public void FixLaunchCondition() | ||
134 | { | ||
135 | var parse = String.Join(Environment.NewLine, | ||
136 | "<?xml version=\"1.0\" encoding=\"utf-16\"?>", | ||
137 | "<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>", | ||
138 | " <Fragment>", | ||
139 | " <Condition Message='Stop the install'>", | ||
140 | " 1<2", | ||
141 | " </Condition>", | ||
142 | " </Fragment>", | ||
143 | "</Wix>"); | ||
144 | |||
145 | var expected = new[] | ||
146 | { | ||
147 | "<?xml version=\"1.0\" encoding=\"utf-16\"?>", | ||
148 | "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">", | ||
149 | " <Fragment>", | ||
150 | " <Launch Condition=\"1<2\" Message=\"Stop the install\" />", | ||
151 | " </Fragment>", | ||
152 | "</Wix>" | ||
153 | }; | ||
154 | |||
155 | var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); | ||
156 | |||
157 | var messaging = new MockMessaging(); | ||
158 | var converter = new Wix3Converter(messaging, 2, null, null); | ||
159 | |||
160 | var errors = converter.ConvertDocument(document); | ||
161 | Assert.Equal(3, errors); | ||
162 | |||
163 | var actualLines = UnformattedDocumentLines(document); | ||
164 | CompareLineByLine(expected, actualLines); | ||
165 | } | ||
166 | |||
167 | [Fact] | ||
168 | public void FixPermissionExCondition() | ||
169 | { | ||
170 | var parse = String.Join(Environment.NewLine, | ||
171 | "<?xml version=\"1.0\" encoding=\"utf-16\"?>", | ||
172 | "<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>", | ||
173 | " <Fragment>", | ||
174 | " <Component Id='Comp1' Directory='ApplicationFolder'>", | ||
175 | " <PermissionEx Sddl='sddl'>", | ||
176 | " <Condition>1<2</Condition>", | ||
177 | " </PermissionEx>", | ||
178 | " </Component>", | ||
179 | " </Fragment>", | ||
180 | "</Wix>"); | ||
181 | |||
182 | var expected = new[] | ||
183 | { | ||
184 | "<?xml version=\"1.0\" encoding=\"utf-16\"?>", | ||
185 | "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">", | ||
186 | " <Fragment>", | ||
187 | " <Component Id=\"Comp1\" Directory=\"ApplicationFolder\">", | ||
188 | " <PermissionEx Sddl=\"sddl\" Condition=\"1<2\">", | ||
189 | " ", | ||
190 | " </PermissionEx>", | ||
191 | " </Component>", | ||
192 | " </Fragment>", | ||
193 | "</Wix>" | ||
194 | }; | ||
195 | |||
196 | var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); | ||
197 | |||
198 | var messaging = new MockMessaging(); | ||
199 | var converter = new Wix3Converter(messaging, 2, null, null); | ||
200 | |||
201 | var errors = converter.ConvertDocument(document); | ||
202 | Assert.Equal(3, errors); | ||
203 | |||
204 | var actualLines = UnformattedDocumentLines(document); | ||
205 | CompareLineByLine(expected, actualLines); | ||
206 | } | ||
207 | } | ||
208 | } | ||
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 | |||
@@ -169,95 +169,6 @@ namespace WixToolsetTest.Converters | |||
169 | } | 169 | } |
170 | 170 | ||
171 | [Fact] | 171 | [Fact] |
172 | public void CanFixCdataWhitespace() | ||
173 | { | ||
174 | var parse = String.Join(Environment.NewLine, | ||
175 | "<?xml version='1.0' encoding='utf-8'?>", | ||
176 | "<Wix xmlns='http://wixtoolset.org/schemas/v4/wxs'>", | ||
177 | " <Fragment>", | ||
178 | " <Property Id='Prop'>", | ||
179 | " <![CDATA[1<2]]>", | ||
180 | " </Property>", | ||
181 | " </Fragment>", | ||
182 | "</Wix>"); | ||
183 | |||
184 | var expected = String.Join(Environment.NewLine, | ||
185 | "<?xml version=\"1.0\" encoding=\"utf-16\"?>", | ||
186 | "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">", | ||
187 | " <Fragment>", | ||
188 | " <Property Id=\"Prop\"><![CDATA[1<2]]></Property>", | ||
189 | " </Fragment>", | ||
190 | "</Wix>"); | ||
191 | |||
192 | var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); | ||
193 | |||
194 | var messaging = new MockMessaging(); | ||
195 | var converter = new Wix3Converter(messaging, 2, null, null); | ||
196 | |||
197 | var errors = converter.ConvertDocument(document); | ||
198 | |||
199 | var actual = UnformattedDocumentString(document); | ||
200 | |||
201 | Assert.Equal(expected, actual); | ||
202 | Assert.Equal(2, errors); | ||
203 | } | ||
204 | |||
205 | [Fact] | ||
206 | public void CanFixCdataWithWhitespace() | ||
207 | { | ||
208 | var parse = String.Join(Environment.NewLine, | ||
209 | "<?xml version='1.0' encoding='utf-8'?>", | ||
210 | "<Wix xmlns='http://wixtoolset.org/schemas/v4/wxs'>", | ||
211 | " <Fragment>", | ||
212 | " <Property Id='Prop'>", | ||
213 | " <![CDATA[", | ||
214 | " 1<2", | ||
215 | " ]]>", | ||
216 | " </Property>", | ||
217 | " </Fragment>", | ||
218 | "</Wix>"); | ||
219 | |||
220 | var expected = String.Join(Environment.NewLine, | ||
221 | "<?xml version=\"1.0\" encoding=\"utf-16\"?>", | ||
222 | "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">", | ||
223 | " <Fragment>", | ||
224 | " <Property Id=\"Prop\"><![CDATA[1<2]]></Property>", | ||
225 | " </Fragment>", | ||
226 | "</Wix>"); | ||
227 | |||
228 | var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); | ||
229 | |||
230 | var messaging = new MockMessaging(); | ||
231 | var converter = new Wix3Converter(messaging, 2, null, null); | ||
232 | |||
233 | var errors = converter.ConvertDocument(document); | ||
234 | |||
235 | var actual = UnformattedDocumentString(document); | ||
236 | |||
237 | Assert.Equal(expected, actual); | ||
238 | Assert.Equal(2, errors); | ||
239 | } | ||
240 | |||
241 | [Fact] | ||
242 | public void CanKeepCdataWithOnlyWhitespace() | ||
243 | { | ||
244 | var parse = String.Join(Environment.NewLine, | ||
245 | "<?xml version='1.0' encoding='utf-8'?>", | ||
246 | "<Wix xmlns='http://wixtoolset.org/schemas/v4/wxs'>", | ||
247 | " <Fragment>", | ||
248 | " <Property Id='Prop'><![CDATA[ ]]></Property>", | ||
249 | " </Fragment>", | ||
250 | "</Wix>"); | ||
251 | |||
252 | var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); | ||
253 | |||
254 | var messaging = new MockMessaging(); | ||
255 | var converter = new Wix3Converter(messaging, 2, null, null); | ||
256 | var errors = converter.ConvertDocument(document); | ||
257 | Assert.Equal(0, errors); | ||
258 | } | ||
259 | |||
260 | [Fact] | ||
261 | public void CanConvertMainNamespace() | 172 | public void CanConvertMainNamespace() |
262 | { | 173 | { |
263 | var parse = String.Join(Environment.NewLine, | 174 | var parse = String.Join(Environment.NewLine, |
@@ -475,34 +386,6 @@ namespace WixToolsetTest.Converters | |||
475 | } | 386 | } |
476 | 387 | ||
477 | [Fact] | 388 | [Fact] |
478 | public void CanConvertCustomTableBootstrapperApplicationData() | ||
479 | { | ||
480 | var parse = String.Join(Environment.NewLine, | ||
481 | "<?xml version='1.0' encoding='utf-8'?>", | ||
482 | "<Wix xmlns='http://wixtoolset.org/schemas/v4/wxs'>", | ||
483 | " <CustomTable Id='FgAppx' BootstrapperApplicationData='yes' />", | ||
484 | "</Wix>"); | ||
485 | |||
486 | var expected = String.Join(Environment.NewLine, | ||
487 | "<?xml version=\"1.0\" encoding=\"utf-16\"?>", | ||
488 | "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">", | ||
489 | " <CustomTable Id=\"FgAppx\" Unreal=\"yes\" />", | ||
490 | "</Wix>"); | ||
491 | |||
492 | var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); | ||
493 | |||
494 | var messaging = new MockMessaging(); | ||
495 | var converter = new Wix3Converter(messaging, 2, null, null); | ||
496 | |||
497 | var errors = converter.ConvertDocument(document); | ||
498 | |||
499 | var actual = UnformattedDocumentString(document); | ||
500 | |||
501 | Assert.Equal(1, errors); | ||
502 | Assert.Equal(expected, actual); | ||
503 | } | ||
504 | |||
505 | [Fact] | ||
506 | public void CanConvertShortNameDirectoryWithoutName() | 389 | public void CanConvertShortNameDirectoryWithoutName() |
507 | { | 390 | { |
508 | var parse = String.Join(Environment.NewLine, | 391 | var parse = String.Join(Environment.NewLine, |
@@ -585,39 +468,5 @@ namespace WixToolsetTest.Converters | |||
585 | Assert.Equal(1, errors); | 468 | Assert.Equal(1, errors); |
586 | Assert.Equal(expected, actual); | 469 | Assert.Equal(expected, actual); |
587 | } | 470 | } |
588 | |||
589 | [Fact] | ||
590 | public void CanConvertCustomAction() | ||
591 | { | ||
592 | var parse = String.Join(Environment.NewLine, | ||
593 | "<?xml version='1.0' encoding='utf-8'?>", | ||
594 | "<Wix xmlns='http://wixtoolset.org/schemas/v4/wxs'>", | ||
595 | " <CustomAction Id='Foo' BinaryKey='WixCA' DllEntry='CAQuietExec' />", | ||
596 | " <CustomAction Id='Foo' BinaryKey='WixCA_x64' DllEntry='CAQuietExec64' />", | ||
597 | " <CustomAction Id='Foo' BinaryKey='UtilCA' DllEntry='WixQuietExec' />", | ||
598 | " <CustomAction Id='Foo' BinaryKey='UtilCA_x64' DllEntry='WixQuietExec64' />", | ||
599 | "</Wix>"); | ||
600 | |||
601 | var expected = String.Join(Environment.NewLine, | ||
602 | "<?xml version=\"1.0\" encoding=\"utf-16\"?>", | ||
603 | "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">", | ||
604 | " <CustomAction Id=\"Foo\" BinaryKey=\"Wix4UtilCA_X86\" DllEntry=\"WixQuietExec\" />", | ||
605 | " <CustomAction Id=\"Foo\" BinaryKey=\"Wix4UtilCA_X64\" DllEntry=\"WixQuietExec64\" />", | ||
606 | " <CustomAction Id=\"Foo\" BinaryKey=\"Wix4UtilCA_X86\" DllEntry=\"WixQuietExec\" />", | ||
607 | " <CustomAction Id=\"Foo\" BinaryKey=\"Wix4UtilCA_X64\" DllEntry=\"WixQuietExec64\" />", | ||
608 | "</Wix>"); | ||
609 | |||
610 | var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); | ||
611 | |||
612 | var messaging = new MockMessaging(); | ||
613 | var converter = new Wix3Converter(messaging, 2, null, null); | ||
614 | |||
615 | var errors = converter.ConvertDocument(document); | ||
616 | |||
617 | var actual = UnformattedDocumentString(document); | ||
618 | |||
619 | Assert.Equal(6, errors); | ||
620 | Assert.Equal(expected, actual); | ||
621 | } | ||
622 | } | 471 | } |
623 | } | 472 | } |
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 @@ | |||
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.IO; | ||
7 | using System.Xml.Linq; | ||
8 | using WixToolset.Converters; | ||
9 | using WixToolsetTest.Converters.Mocks; | ||
10 | using Xunit; | ||
11 | |||
12 | public class CustomActionFixture : BaseConverterFixture | ||
13 | { | ||
14 | [Fact] | ||
15 | public void CanConvertCustomAction() | ||
16 | { | ||
17 | var parse = String.Join(Environment.NewLine, | ||
18 | "<?xml version='1.0' encoding='utf-8'?>", | ||
19 | "<Wix xmlns='http://wixtoolset.org/schemas/v4/wxs'>", | ||
20 | " <CustomAction Id='Foo' BinaryKey='WixCA' DllEntry='CAQuietExec' />", | ||
21 | " <CustomAction Id='Foo' BinaryKey='WixCA_x64' DllEntry='CAQuietExec64' />", | ||
22 | " <CustomAction Id='Foo' BinaryKey='UtilCA' DllEntry='WixQuietExec' />", | ||
23 | " <CustomAction Id='Foo' BinaryKey='UtilCA_x64' DllEntry='WixQuietExec64' />", | ||
24 | "</Wix>"); | ||
25 | |||
26 | var expected = String.Join(Environment.NewLine, | ||
27 | "<?xml version=\"1.0\" encoding=\"utf-16\"?>", | ||
28 | "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">", | ||
29 | " <CustomAction Id=\"Foo\" BinaryKey=\"Wix4UtilCA_X86\" DllEntry=\"WixQuietExec\" />", | ||
30 | " <CustomAction Id=\"Foo\" BinaryKey=\"Wix4UtilCA_X64\" DllEntry=\"WixQuietExec64\" />", | ||
31 | " <CustomAction Id=\"Foo\" BinaryKey=\"Wix4UtilCA_X86\" DllEntry=\"WixQuietExec\" />", | ||
32 | " <CustomAction Id=\"Foo\" BinaryKey=\"Wix4UtilCA_X64\" DllEntry=\"WixQuietExec64\" />", | ||
33 | "</Wix>"); | ||
34 | |||
35 | var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); | ||
36 | |||
37 | var messaging = new MockMessaging(); | ||
38 | var converter = new Wix3Converter(messaging, 2, null, null); | ||
39 | |||
40 | var errors = converter.ConvertDocument(document); | ||
41 | |||
42 | var actual = UnformattedDocumentString(document); | ||
43 | |||
44 | Assert.Equal(6, errors); | ||
45 | Assert.Equal(expected, actual); | ||
46 | } | ||
47 | |||
48 | [Fact] | ||
49 | public void CanConvertCustomActionScript() | ||
50 | { | ||
51 | var parse = String.Join(Environment.NewLine, | ||
52 | "<?xml version='1.0' encoding='utf-8'?>", | ||
53 | "<Wix xmlns='http://wixtoolset.org/schemas/v4/wxs'>", | ||
54 | " <CustomAction Id='Foo' Script='jscript'>", | ||
55 | " function() {", | ||
56 | " var x = 0;", | ||
57 | " return x;", | ||
58 | " }", | ||
59 | " </CustomAction>", | ||
60 | "</Wix>"); | ||
61 | |||
62 | var expected = String.Join(Environment.NewLine, | ||
63 | "<?xml version=\"1.0\" encoding=\"utf-16\"?>", | ||
64 | "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">", | ||
65 | " <CustomAction Id=\"Foo\" Script=\"jscript\" ScriptFile=\"Foo.js\" />", | ||
66 | "</Wix>"); | ||
67 | |||
68 | var expectedScript = String.Join("\n", | ||
69 | "function() {", | ||
70 | " var x = 0;", | ||
71 | " return x;", | ||
72 | " }"); | ||
73 | |||
74 | var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); | ||
75 | |||
76 | var messaging = new MockMessaging(); | ||
77 | var converter = new Wix3Converter(messaging, 2, null, null); | ||
78 | |||
79 | var errors = converter.ConvertDocument(document); | ||
80 | |||
81 | var actual = UnformattedDocumentString(document); | ||
82 | |||
83 | Assert.Equal(1, errors); | ||
84 | Assert.Equal(expected, actual); | ||
85 | |||
86 | var script = File.ReadAllText("Foo.js"); | ||
87 | Assert.Equal(expectedScript, script); | ||
88 | } | ||
89 | } | ||
90 | } | ||
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 | |||
46 | var actualLines = UnformattedDocumentLines(document); | 46 | var actualLines = UnformattedDocumentLines(document); |
47 | CompareLineByLine(expected, actualLines); | 47 | CompareLineByLine(expected, actualLines); |
48 | } | 48 | } |
49 | |||
50 | [Fact] | ||
51 | public void FixCustomRowTextValue() | ||
52 | { | ||
53 | var parse = String.Join(Environment.NewLine, | ||
54 | "<?xml version=\"1.0\" encoding=\"utf-16\"?>", | ||
55 | "<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>", | ||
56 | " <Fragment>", | ||
57 | " <CustomTable Id='Custom1'>", | ||
58 | " <Row Id='Column1'>", | ||
59 | " Some value", | ||
60 | " </Row>", | ||
61 | " </CustomTable>", | ||
62 | " </Fragment>", | ||
63 | "</Wix>"); | ||
64 | |||
65 | var expected = new[] | ||
66 | { | ||
67 | "<?xml version=\"1.0\" encoding=\"utf-16\"?>", | ||
68 | "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">", | ||
69 | " <Fragment>", | ||
70 | " <CustomTable Id=\"Custom1\">", | ||
71 | " <Row Id=\"Column1\" Value=\"Some value\" />", | ||
72 | " </CustomTable>", | ||
73 | " </Fragment>", | ||
74 | "</Wix>" | ||
75 | }; | ||
76 | |||
77 | var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); | ||
78 | |||
79 | var messaging = new MockMessaging(); | ||
80 | var converter = new Wix3Converter(messaging, 2, null, null); | ||
81 | |||
82 | var errors = converter.ConvertDocument(document); | ||
83 | Assert.Equal(3, errors); | ||
84 | |||
85 | var actualLines = UnformattedDocumentLines(document); | ||
86 | CompareLineByLine(expected, actualLines); | ||
87 | } | ||
88 | |||
89 | [Fact] | ||
90 | public void FixCustomRowCdataValue() | ||
91 | { | ||
92 | var parse = String.Join(Environment.NewLine, | ||
93 | "<?xml version=\"1.0\" encoding=\"utf-16\"?>", | ||
94 | "<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>", | ||
95 | " <Fragment>", | ||
96 | " <CustomTable Id='Custom1'>", | ||
97 | " <Row Id='Column1'>", | ||
98 | " <![CDATA[", | ||
99 | " Some value", | ||
100 | " ]]>", | ||
101 | " </Row>", | ||
102 | " </CustomTable>", | ||
103 | " </Fragment>", | ||
104 | "</Wix>"); | ||
105 | |||
106 | var expected = new[] | ||
107 | { | ||
108 | "<?xml version=\"1.0\" encoding=\"utf-16\"?>", | ||
109 | "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">", | ||
110 | " <Fragment>", | ||
111 | " <CustomTable Id=\"Custom1\">", | ||
112 | " <Row Id=\"Column1\" Value=\"Some value\" />", | ||
113 | " </CustomTable>", | ||
114 | " </Fragment>", | ||
115 | "</Wix>" | ||
116 | }; | ||
117 | |||
118 | var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); | ||
119 | |||
120 | var messaging = new MockMessaging(); | ||
121 | var converter = new Wix3Converter(messaging, 2, null, null); | ||
122 | |||
123 | var errors = converter.ConvertDocument(document); | ||
124 | Assert.Equal(3, errors); | ||
125 | |||
126 | var actualLines = UnformattedDocumentLines(document); | ||
127 | CompareLineByLine(expected, actualLines); | ||
128 | } | ||
129 | |||
130 | [Fact] | ||
131 | public void FixCustomRowWithoutValue() | ||
132 | { | ||
133 | var parse = String.Join(Environment.NewLine, | ||
134 | "<?xml version=\"1.0\" encoding=\"utf-16\"?>", | ||
135 | "<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>", | ||
136 | " <Fragment>", | ||
137 | " <CustomTable Id='Custom1'>", | ||
138 | " <Row Id='Column1'></Row>", | ||
139 | " </CustomTable>", | ||
140 | " </Fragment>", | ||
141 | "</Wix>"); | ||
142 | |||
143 | var expected = new[] | ||
144 | { | ||
145 | "<?xml version=\"1.0\" encoding=\"utf-16\"?>", | ||
146 | "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">", | ||
147 | " <Fragment>", | ||
148 | " <CustomTable Id=\"Custom1\">", | ||
149 | " <Row Id=\"Column1\"></Row>", | ||
150 | " </CustomTable>", | ||
151 | " </Fragment>", | ||
152 | "</Wix>" | ||
153 | }; | ||
154 | |||
155 | var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); | ||
156 | |||
157 | var messaging = new MockMessaging(); | ||
158 | var converter = new Wix3Converter(messaging, 2, null, null); | ||
159 | |||
160 | var errors = converter.ConvertDocument(document); | ||
161 | Assert.Equal(2, errors); | ||
162 | |||
163 | var actualLines = UnformattedDocumentLines(document); | ||
164 | CompareLineByLine(expected, actualLines); | ||
165 | } | ||
166 | |||
167 | [Fact] | ||
168 | public void CanConvertCustomTableBootstrapperApplicationData() | ||
169 | { | ||
170 | var parse = String.Join(Environment.NewLine, | ||
171 | "<?xml version='1.0' encoding='utf-8'?>", | ||
172 | "<Wix xmlns='http://wixtoolset.org/schemas/v4/wxs'>", | ||
173 | " <CustomTable Id='FgAppx' BootstrapperApplicationData='yes' />", | ||
174 | "</Wix>"); | ||
175 | |||
176 | var expected = String.Join(Environment.NewLine, | ||
177 | "<?xml version=\"1.0\" encoding=\"utf-16\"?>", | ||
178 | "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">", | ||
179 | " <CustomTable Id=\"FgAppx\" Unreal=\"yes\" />", | ||
180 | "</Wix>"); | ||
181 | |||
182 | var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); | ||
183 | |||
184 | var messaging = new MockMessaging(); | ||
185 | var converter = new Wix3Converter(messaging, 2, null, null); | ||
186 | |||
187 | var errors = converter.ConvertDocument(document); | ||
188 | |||
189 | var actual = UnformattedDocumentString(document); | ||
190 | |||
191 | Assert.Equal(1, errors); | ||
192 | Assert.Equal(expected, actual); | ||
193 | } | ||
49 | } | 194 | } |
50 | } | 195 | } |
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 @@ | |||
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 PropertyFixture : BaseConverterFixture | ||
12 | { | ||
13 | [Fact] | ||
14 | public void CanFixCdataWhitespace() | ||
15 | { | ||
16 | var parse = String.Join(Environment.NewLine, | ||
17 | "<?xml version='1.0' encoding='utf-8'?>", | ||
18 | "<Wix xmlns='http://wixtoolset.org/schemas/v4/wxs'>", | ||
19 | " <Fragment>", | ||
20 | " <Property Id='Prop'>", | ||
21 | " <![CDATA[1<2]]>", | ||
22 | " </Property>", | ||
23 | " </Fragment>", | ||
24 | "</Wix>"); | ||
25 | |||
26 | var expected = String.Join(Environment.NewLine, | ||
27 | "<?xml version=\"1.0\" encoding=\"utf-16\"?>", | ||
28 | "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">", | ||
29 | " <Fragment>", | ||
30 | " <Property Id=\"Prop\" Value=\"1<2\" />", | ||
31 | " </Fragment>", | ||
32 | "</Wix>"); | ||
33 | |||
34 | var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); | ||
35 | |||
36 | var messaging = new MockMessaging(); | ||
37 | var converter = new Wix3Converter(messaging, 2, null, null); | ||
38 | |||
39 | var errors = converter.ConvertDocument(document); | ||
40 | |||
41 | var actual = UnformattedDocumentString(document); | ||
42 | |||
43 | Assert.Equal(expected, actual); | ||
44 | Assert.Equal(1, errors); | ||
45 | } | ||
46 | |||
47 | [Fact] | ||
48 | public void CanFixCdataWithWhitespace() | ||
49 | { | ||
50 | var parse = String.Join(Environment.NewLine, | ||
51 | "<?xml version='1.0' encoding='utf-8'?>", | ||
52 | "<Wix xmlns='http://wixtoolset.org/schemas/v4/wxs'>", | ||
53 | " <Fragment>", | ||
54 | " <Property Id='Prop'>", | ||
55 | " <![CDATA[", | ||
56 | " 1<2", | ||
57 | " ]]>", | ||
58 | " </Property>", | ||
59 | " </Fragment>", | ||
60 | "</Wix>"); | ||
61 | |||
62 | var expected = String.Join(Environment.NewLine, | ||
63 | "<?xml version=\"1.0\" encoding=\"utf-16\"?>", | ||
64 | "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">", | ||
65 | " <Fragment>", | ||
66 | " <Property Id=\"Prop\" Value=\"1<2\" />", | ||
67 | " </Fragment>", | ||
68 | "</Wix>"); | ||
69 | |||
70 | var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); | ||
71 | |||
72 | var messaging = new MockMessaging(); | ||
73 | var converter = new Wix3Converter(messaging, 2, null, null); | ||
74 | |||
75 | var errors = converter.ConvertDocument(document); | ||
76 | |||
77 | var actual = UnformattedDocumentString(document); | ||
78 | |||
79 | Assert.Equal(expected, actual); | ||
80 | Assert.Equal(1, errors); | ||
81 | } | ||
82 | |||
83 | [Fact] | ||
84 | public void CanKeepCdataWithOnlyWhitespace() | ||
85 | { | ||
86 | var parse = String.Join(Environment.NewLine, | ||
87 | "<?xml version='1.0' encoding='utf-8'?>", | ||
88 | "<Wix xmlns='http://wixtoolset.org/schemas/v4/wxs'>", | ||
89 | " <Fragment>", | ||
90 | " <Property Id='Prop'><![CDATA[ ]]></Property>", | ||
91 | " </Fragment>", | ||
92 | "</Wix>"); | ||
93 | |||
94 | var expected = String.Join(Environment.NewLine, | ||
95 | "<?xml version=\"1.0\" encoding=\"utf-16\"?>", | ||
96 | "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">", | ||
97 | " <Fragment>", | ||
98 | " <Property Id=\"Prop\" Value=\" \" />", | ||
99 | " </Fragment>", | ||
100 | "</Wix>"); | ||
101 | |||
102 | var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); | ||
103 | |||
104 | var messaging = new MockMessaging(); | ||
105 | var converter = new Wix3Converter(messaging, 2, null, null); | ||
106 | var errors = converter.ConvertDocument(document); | ||
107 | |||
108 | var actual = UnformattedDocumentString(document); | ||
109 | |||
110 | Assert.Equal(expected, actual); | ||
111 | Assert.Equal(1, errors); | ||
112 | } | ||
113 | } | ||
114 | } | ||
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 @@ | |||
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 SequenceFixture : BaseConverterFixture | ||
12 | { | ||
13 | [Fact] | ||
14 | public void FixCondition() | ||
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 | " <InstallUISequence>", | ||
21 | " <Custom Action='ExampleCA' After='InstallFiles'>NOT Installed</Custom>", | ||
22 | " </InstallUISequence>", | ||
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 | " <InstallUISequence>", | ||
32 | " <Custom Action=\"ExampleCA\" After=\"InstallFiles\" Condition=\"NOT Installed\" />", | ||
33 | " </InstallUISequence>", | ||
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(3, errors); | ||
45 | |||
46 | var actualLines = UnformattedDocumentLines(document); | ||
47 | CompareLineByLine(expected, actualLines); | ||
48 | } | ||
49 | } | ||
50 | } | ||