| 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 BitnessFixture : BaseConverterFixture |
| 13 | { |
| 14 | [Fact] |
| 15 | public void FixComponentBitness() |
| 16 | { |
| 17 | var parse = String.Join(Environment.NewLine, |
| 18 | "<?xml version=\"1.0\" encoding=\"utf-16\"?>", |
| 19 | "<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>", |
| 20 | " <Fragment>", |
| 21 | " <Component>", |
| 22 | " <File Source='default.exe' />", |
| 23 | " </Component>", |
| 24 | " <Component Win64='no'>", |
| 25 | " <File Source='32bit.exe' />", |
| 26 | " </Component>", |
| 27 | " <Component Win64='yes'>", |
| 28 | " <File Source='64bit.exe' />", |
| 29 | " </Component>", |
| 30 | " <Component Win64='$(var.Win64)'>", |
| 31 | " <File Source='unconvert.exe' />", |
| 32 | " </Component>", |
| 33 | " </Fragment>", |
| 34 | "</Wix>"); |
| 35 | |
| 36 | var expected = new[] |
| 37 | { |
| 38 | "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">", |
| 39 | " <Fragment>", |
| 40 | " <Component>", |
| 41 | " <File Id=\"default.exe\" Source=\"default.exe\" />", |
| 42 | " </Component>", |
| 43 | " <Component Bitness=\"always32\">", |
| 44 | " <File Id=\"_32bit.exe\" Source=\"32bit.exe\" />", |
| 45 | " </Component>", |
| 46 | " <Component Bitness=\"always64\">", |
| 47 | " <File Id=\"_64bit.exe\" Source=\"64bit.exe\" />", |
| 48 | " </Component>", |
| 49 | " <Component Bitness=\"$(var.Win64)\">", |
| 50 | " <File Id=\"unconvert.exe\" Source=\"unconvert.exe\" />", |
| 51 | " </Component>", |
| 52 | " </Fragment>", |
| 53 | "</Wix>" |
| 54 | }; |
| 55 | |
| 56 | var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); |
| 57 | |
| 58 | var messaging = new MockMessaging(); |
| 59 | var converter = new WixConverter(messaging, 2, null, null); |
| 60 | |
| 61 | var errors = converter.ConvertDocument(document); |
| 62 | Assert.Equal(10, errors); |
| 63 | |
| 64 | var actualLines = UnformattedDocumentLines(document); |
| 65 | WixAssert.CompareLineByLine(expected, actualLines); |
| 66 | } |
| 67 | |
| 68 | [Fact] |
| 69 | public void FixRegistrySearchBitness() |
| 70 | { |
| 71 | var parse = String.Join(Environment.NewLine, |
| 72 | "<?xml version=\"1.0\" encoding=\"utf-16\"?>", |
| 73 | "<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>", |
| 74 | " <Fragment>", |
| 75 | " <Property Id='BITNESSDEFAULT'>", |
| 76 | " <RegistrySearch Id='SampleRegSearch' Root='HKLM' Key='SampleReg' Type='raw'></RegistrySearch>", |
| 77 | " </Property>", |
| 78 | " <Property Id='BITNESS32'>", |
| 79 | " <RegistrySearch Id='SampleRegSearch' Root='HKLM' Key='SampleReg' Type='raw' Win64='no'></RegistrySearch>", |
| 80 | " </Property>", |
| 81 | " <Property Id='BITNESS64'>", |
| 82 | " <RegistrySearch Id='SampleRegSearch' Root='HKLM' Key='SampleReg' Type='raw' Win64='yes'></RegistrySearch>", |
| 83 | " </Property>", |
| 84 | " </Fragment>", |
| 85 | "</Wix>"); |
| 86 | |
| 87 | var expected = new[] |
| 88 | { |
| 89 | "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">", |
| 90 | " <Fragment>", |
| 91 | " <Property Id=\"BITNESSDEFAULT\">", |
| 92 | " <RegistrySearch Id=\"SampleRegSearch\" Root=\"HKLM\" Key=\"SampleReg\" Type=\"raw\"></RegistrySearch>", |
| 93 | " </Property>", |
| 94 | " <Property Id=\"BITNESS32\">", |
| 95 | " <RegistrySearch Id=\"SampleRegSearch\" Root=\"HKLM\" Key=\"SampleReg\" Type=\"raw\" Bitness=\"always32\"></RegistrySearch>", |
| 96 | " </Property>", |
| 97 | " <Property Id=\"BITNESS64\">", |
| 98 | " <RegistrySearch Id=\"SampleRegSearch\" Root=\"HKLM\" Key=\"SampleReg\" Type=\"raw\" Bitness=\"always64\"></RegistrySearch>", |
| 99 | " </Property>", |
| 100 | " </Fragment>", |
| 101 | "</Wix>" |
| 102 | }; |
| 103 | |
| 104 | var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); |
| 105 | |
| 106 | var messaging = new MockMessaging(); |
| 107 | var converter = new WixConverter(messaging, 2, null, null); |
| 108 | |
| 109 | var errors = converter.ConvertDocument(document); |
| 110 | Assert.Equal(4, errors); |
| 111 | |
| 112 | var actualLines = UnformattedDocumentLines(document); |
| 113 | WixAssert.CompareLineByLine(expected, actualLines); |
| 114 | } |
| 115 | |
| 116 | [Fact] |
| 117 | public void FixUtilRegistrySearchBitness() |
| 118 | { |
| 119 | var parse = String.Join(Environment.NewLine, |
| 120 | "<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi' xmlns:util='http://schemas.microsoft.com/wix/UtilExtension'>", |
| 121 | " <Fragment>", |
| 122 | " <util:RegistrySearch Id='RegValue' Root='HKLM' Key='Converter' Variable='Test' />", |
| 123 | " <util:RegistrySearch Id='RegValue2' Root='HKLM' Key='Converter' Variable='Test' Result='value' Win64='no' />", |
| 124 | " <util:RegistrySearch Id='RegValue3' Root='HKLM' Key='Converter' Variable='Test' Result='exists' Win64='yes' />", |
| 125 | " </Fragment>", |
| 126 | "</Wix>"); |
| 127 | |
| 128 | var expected = new[] |
| 129 | { |
| 130 | "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\" xmlns:util=\"http://wixtoolset.org/schemas/v4/wxs/util\">", |
| 131 | " <Fragment>", |
| 132 | " <util:RegistrySearch Id=\"RegValue\" Root=\"HKLM\" Key=\"Converter\" Variable=\"Test\" />", |
| 133 | " <util:RegistrySearch Id=\"RegValue2\" Root=\"HKLM\" Key=\"Converter\" Variable=\"Test\" Result=\"value\" Bitness=\"always32\" />", |
| 134 | " <util:RegistrySearch Id=\"RegValue3\" Root=\"HKLM\" Key=\"Converter\" Variable=\"Test\" Result=\"exists\" Bitness=\"always64\" />", |
| 135 | " </Fragment>", |
| 136 | "</Wix>" |
| 137 | }; |
| 138 | |
| 139 | var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); |
| 140 | |
| 141 | var messaging = new MockMessaging(); |
| 142 | var converter = new WixConverter(messaging, 2, null, null); |
| 143 | |
| 144 | var errors = converter.ConvertDocument(document); |
| 145 | Assert.Equal(6, errors); |
| 146 | |
| 147 | var actualLines = UnformattedDocumentLines(document); |
| 148 | WixAssert.CompareLineByLine(expected, actualLines); |
| 149 | } |
| 150 | |
| 151 | [Fact] |
| 152 | public void FixApprovedExeBitness() |
| 153 | { |
| 154 | var parse = String.Join(Environment.NewLine, |
| 155 | "<?xml version=\"1.0\" encoding=\"utf-16\"?>", |
| 156 | "<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>", |
| 157 | " <Bundle>", |
| 158 | " <ApprovedExeForElevation Id='Default' Key='WixToolset\\BurnTesting' Value='Test' />", |
| 159 | " <ApprovedExeForElevation Id='Bitness32' Key='WixToolset\\BurnTesting' Value='Test' Win64='no' />", |
| 160 | " <ApprovedExeForElevation Id='Bitness64' Key='WixToolset\\BurnTesting' Value='Test' Win64='yes' />", |
| 161 | " </Bundle>", |
| 162 | "</Wix>"); |
| 163 | |
| 164 | var expected = new[] |
| 165 | { |
| 166 | "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">", |
| 167 | " <Bundle>", |
| 168 | " <ApprovedExeForElevation Id=\"Default\" Key=\"WixToolset\\BurnTesting\" Value=\"Test\" />", |
| 169 | " <ApprovedExeForElevation Id=\"Bitness32\" Key=\"WixToolset\\BurnTesting\" Value=\"Test\" Bitness=\"always32\" />", |
| 170 | " <ApprovedExeForElevation Id=\"Bitness64\" Key=\"WixToolset\\BurnTesting\" Value=\"Test\" Bitness=\"always64\" />", |
| 171 | " </Bundle>", |
| 172 | "</Wix>" |
| 173 | }; |
| 174 | |
| 175 | var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); |
| 176 | |
| 177 | var messaging = new MockMessaging(); |
| 178 | var converter = new WixConverter(messaging, 2, null, null); |
| 179 | |
| 180 | var errors = converter.ConvertDocument(document); |
| 181 | Assert.Equal(4, errors); |
| 182 | |
| 183 | var actualLines = UnformattedDocumentLines(document); |
| 184 | WixAssert.CompareLineByLine(expected, actualLines); |
| 185 | } |
| 186 | } |
| 187 | } |