| 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 WixInternal.TestSupport; |
| 8 | using WixToolset.Converters; |
| 9 | using WixToolsetTest.Converters.Mocks; |
| 10 | using Xunit; |
| 11 | |
| 12 | public class UtilExtensionFixture : BaseConverterFixture |
| 13 | { |
| 14 | [Fact] |
| 15 | public void FixCloseAppsCondition() |
| 16 | { |
| 17 | var parse = String.Join(Environment.NewLine, |
| 18 | "<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi' xmlns:util='http://schemas.microsoft.com/wix/UtilExtension'>", |
| 19 | " <Fragment>", |
| 20 | " <util:CloseApplication Id='EndApp' Target='example.exe'>", |
| 21 | " a<>b", |
| 22 | " </util:CloseApplication>", |
| 23 | " </Fragment>", |
| 24 | "</Wix>"); |
| 25 | |
| 26 | var expected = new[] |
| 27 | { |
| 28 | "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\" xmlns:util=\"http://wixtoolset.org/schemas/v4/wxs/util\">", |
| 29 | " <Fragment>", |
| 30 | " <util:CloseApplication Id=\"EndApp\" Target=\"example.exe\" Condition=\"a<>b\" />", |
| 31 | " </Fragment>", |
| 32 | "</Wix>" |
| 33 | }; |
| 34 | |
| 35 | var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); |
| 36 | |
| 37 | var messaging = new MockMessaging(); |
| 38 | var converter = new WixConverter(messaging, 2, null, null); |
| 39 | |
| 40 | var errors = converter.ConvertDocument(document); |
| 41 | Assert.Equal(3, errors); |
| 42 | |
| 43 | var actualLines = UnformattedDocumentLines(document); |
| 44 | WixAssert.CompareLineByLine(expected, actualLines); |
| 45 | } |
| 46 | |
| 47 | [Fact] |
| 48 | public void FixCloseAppsConditionWithComment() |
| 49 | { |
| 50 | var parse = String.Join(Environment.NewLine, |
| 51 | "<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi' xmlns:util='http://schemas.microsoft.com/wix/UtilExtension'>", |
| 52 | " <Fragment>", |
| 53 | " <util:CloseApplication Id='EndApp' Target='example.exe'>", |
| 54 | " <!-- Comment -->a<>b", |
| 55 | " </util:CloseApplication>", |
| 56 | " </Fragment>", |
| 57 | "</Wix>"); |
| 58 | |
| 59 | var expected = new[] |
| 60 | { |
| 61 | "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\" xmlns:util=\"http://wixtoolset.org/schemas/v4/wxs/util\">", |
| 62 | " <Fragment>", |
| 63 | " <!-- Comment -->", |
| 64 | " <util:CloseApplication Id=\"EndApp\" Target=\"example.exe\" Condition=\"a<>b\" />", |
| 65 | " </Fragment>", |
| 66 | "</Wix>" |
| 67 | }; |
| 68 | |
| 69 | var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); |
| 70 | |
| 71 | var messaging = new MockMessaging(); |
| 72 | var converter = new WixConverter(messaging, 2, null, null); |
| 73 | |
| 74 | var errors = converter.ConvertDocument(document); |
| 75 | Assert.Equal(3, errors); |
| 76 | |
| 77 | var actualLines = UnformattedDocumentLines(document); |
| 78 | WixAssert.CompareLineByLine(expected, actualLines); |
| 79 | } |
| 80 | |
| 81 | [Fact] |
| 82 | public void FixXmlConfigValue() |
| 83 | { |
| 84 | var parse = String.Join(Environment.NewLine, |
| 85 | "<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi' xmlns:util='http://schemas.microsoft.com/wix/UtilExtension'>", |
| 86 | " <Fragment>", |
| 87 | " <util:XmlConfig Id='Change' ElementPath='book'>", |
| 88 | " a<>b", |
| 89 | " </util:XmlConfig>", |
| 90 | " </Fragment>", |
| 91 | "</Wix>"); |
| 92 | |
| 93 | var expected = new[] |
| 94 | { |
| 95 | "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\" xmlns:util=\"http://wixtoolset.org/schemas/v4/wxs/util\">", |
| 96 | " <Fragment>", |
| 97 | " <util:XmlConfig Id=\"Change\" ElementPath=\"book\" Value=\"a<>b\" />", |
| 98 | " </Fragment>", |
| 99 | "</Wix>" |
| 100 | }; |
| 101 | |
| 102 | var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); |
| 103 | |
| 104 | var messaging = new MockMessaging(); |
| 105 | var converter = new WixConverter(messaging, 2, null, null); |
| 106 | |
| 107 | var errors = converter.ConvertDocument(document); |
| 108 | Assert.Equal(3, errors); |
| 109 | |
| 110 | var actualLines = UnformattedDocumentLines(document); |
| 111 | WixAssert.CompareLineByLine(expected, actualLines); |
| 112 | } |
| 113 | |
| 114 | [Fact] |
| 115 | public void FixXmlConfigValueWithComment() |
| 116 | { |
| 117 | var parse = String.Join(Environment.NewLine, |
| 118 | "<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi' xmlns:util='http://schemas.microsoft.com/wix/UtilExtension'>", |
| 119 | " <Fragment>", |
| 120 | " <util:XmlConfig Id='Change' ElementPath='book'>", |
| 121 | " <!-- Comment -->a<>b", |
| 122 | " </util:XmlConfig>", |
| 123 | " </Fragment>", |
| 124 | "</Wix>"); |
| 125 | |
| 126 | var expected = new[] |
| 127 | { |
| 128 | "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\" xmlns:util=\"http://wixtoolset.org/schemas/v4/wxs/util\">", |
| 129 | " <Fragment>", |
| 130 | " <!-- Comment -->", |
| 131 | " <util:XmlConfig Id=\"Change\" ElementPath=\"book\" Value=\"a<>b\" />", |
| 132 | " </Fragment>", |
| 133 | "</Wix>" |
| 134 | }; |
| 135 | |
| 136 | var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); |
| 137 | |
| 138 | var messaging = new MockMessaging(); |
| 139 | var converter = new WixConverter(messaging, 2, null, null); |
| 140 | |
| 141 | var errors = converter.ConvertDocument(document); |
| 142 | Assert.Equal(3, errors); |
| 143 | |
| 144 | var actualLines = UnformattedDocumentLines(document); |
| 145 | WixAssert.CompareLineByLine(expected, actualLines); |
| 146 | } |
| 147 | |
| 148 | [Fact] |
| 149 | public void WarnsOnAllRegistryValueSearches() |
| 150 | { |
| 151 | var parse = String.Join(Environment.NewLine, |
| 152 | "<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi' xmlns:util='http://schemas.microsoft.com/wix/UtilExtension'>", |
| 153 | " <Fragment>", |
| 154 | " <util:RegistrySearch Id='RegValue' Root='HKLM' Key='Converter' Variable='Test' />", |
| 155 | " <util:RegistrySearch Id='RegValue2' Root='HKLM' Key='Converter' Variable='Test' Result='value' />", |
| 156 | " <util:RegistrySearch Id='RegValue3' Root='HKLM' Key='Converter' Variable='Test' Result='exists' />", |
| 157 | " </Fragment>", |
| 158 | "</Wix>"); |
| 159 | |
| 160 | var expected = new[] |
| 161 | { |
| 162 | "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\" xmlns:util=\"http://wixtoolset.org/schemas/v4/wxs/util\">", |
| 163 | " <Fragment>", |
| 164 | " <util:RegistrySearch Id=\"RegValue\" Root=\"HKLM\" Key=\"Converter\" Variable=\"Test\" />", |
| 165 | " <util:RegistrySearch Id=\"RegValue2\" Root=\"HKLM\" Key=\"Converter\" Variable=\"Test\" Result=\"value\" />", |
| 166 | " <util:RegistrySearch Id=\"RegValue3\" Root=\"HKLM\" Key=\"Converter\" Variable=\"Test\" Result=\"exists\" />", |
| 167 | " </Fragment>", |
| 168 | "</Wix>" |
| 169 | }; |
| 170 | |
| 171 | var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); |
| 172 | |
| 173 | var messaging = new MockMessaging(); |
| 174 | var converter = new WixConverter(messaging, 2, null, null); |
| 175 | |
| 176 | var errors = converter.ConvertDocument(document); |
| 177 | Assert.Equal(4, errors); |
| 178 | |
| 179 | var actualLines = UnformattedDocumentLines(document); |
| 180 | WixAssert.CompareLineByLine(expected, actualLines); |
| 181 | } |
| 182 | |
| 183 | [Fact] |
| 184 | public void FixXmlConfigValueCData() |
| 185 | { |
| 186 | var parse = String.Join(Environment.NewLine, |
| 187 | "<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi' xmlns:util='http://schemas.microsoft.com/wix/UtilExtension'>", |
| 188 | " <Fragment>", |
| 189 | " <util:XmlConfig Id='Change' ElementPath='book'>", |
| 190 | " <![CDATA[a<>b]]>", |
| 191 | " </util:XmlConfig>", |
| 192 | " </Fragment>", |
| 193 | "</Wix>"); |
| 194 | |
| 195 | var expected = new[] |
| 196 | { |
| 197 | "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\" xmlns:util=\"http://wixtoolset.org/schemas/v4/wxs/util\">", |
| 198 | " <Fragment>", |
| 199 | " <util:XmlConfig Id=\"Change\" ElementPath=\"book\" Value=\"a<>b\" />", |
| 200 | " </Fragment>", |
| 201 | "</Wix>" |
| 202 | }; |
| 203 | |
| 204 | var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); |
| 205 | |
| 206 | var messaging = new MockMessaging(); |
| 207 | var converter = new WixConverter(messaging, 2, null, null); |
| 208 | |
| 209 | var errors = converter.ConvertDocument(document); |
| 210 | Assert.Equal(3, errors); |
| 211 | |
| 212 | var actualLines = UnformattedDocumentLines(document); |
| 213 | WixAssert.CompareLineByLine(expected, actualLines); |
| 214 | } |
| 215 | |
| 216 | [Fact] |
| 217 | public void FixQueryOsPropertyRefs() |
| 218 | { |
| 219 | var parse = String.Join(Environment.NewLine, |
| 220 | "<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi' xmlns:util='http://schemas.microsoft.com/wix/UtilExtension'>", |
| 221 | " <Fragment>", |
| 222 | " <PropertyRef Id=\"WIX_SUITE_ENTERPRISE\" />", |
| 223 | " <PropertyRef Id=\"WIX_DIR_COMMON_DOCUMENTS\" />", |
| 224 | " <CustomActionRef Id=\"WixFailWhenDeferred\" />", |
| 225 | " <UI>", |
| 226 | " <PropertyRef Id=\"WIX_ACCOUNT_LOCALSERVICE\" />", |
| 227 | " </UI>", |
| 228 | " </Fragment>", |
| 229 | "</Wix>"); |
| 230 | |
| 231 | var expected = new[] |
| 232 | { |
| 233 | "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\" xmlns:util=\"http://wixtoolset.org/schemas/v4/wxs/util\">", |
| 234 | " <Fragment>", |
| 235 | " <util:QueryWindowsSuiteInfo />", |
| 236 | " <util:QueryWindowsDirectories />", |
| 237 | " <util:FailWhenDeferred />", |
| 238 | " <UI>", |
| 239 | " <util:QueryWindowsWellKnownSIDs />", |
| 240 | " </UI>", |
| 241 | " </Fragment>", |
| 242 | "</Wix>" |
| 243 | }; |
| 244 | |
| 245 | var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); |
| 246 | |
| 247 | var messaging = new MockMessaging(); |
| 248 | var converter = new WixConverter(messaging, 2, null, null); |
| 249 | |
| 250 | var errors = converter.ConvertDocument(document); |
| 251 | Assert.Equal(6, errors); |
| 252 | |
| 253 | var actualLines = UnformattedDocumentLines(document); |
| 254 | WixAssert.CompareLineByLine(expected, actualLines); |
| 255 | } |
| 256 | } |
| 257 | } |