main
cs 278 lines 9.22 KB
Raw
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 WixInternal.TestSupport;
9 using WixToolset.Converters;
10 using WixInternal.Core.TestPackage;
11 using WixToolsetTest.Converters.Mocks;
12 using Xunit;
13
14 public class ProductPackageFixture : BaseConverterFixture
15 {
16 [Fact]
17 public void FixesCompressedWhenYes()
18 {
19 var parse = String.Join(Environment.NewLine,
20 "<?xml version=\"1.0\" encoding=\"utf-16\"?>",
21 "<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>",
22 " <Product>",
23 " <Package Compressed='yes' />",
24 " </Product>",
25 "</Wix>");
26
27 var expected = new[]
28 {
29 "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">",
30 " <Package>",
31 " ",
32 " </Package>",
33 "</Wix>"
34 };
35
36 AssertSuccess(parse, 4, expected);
37 }
38
39 [Fact]
40 public void FixesCompressedWhenNo()
41 {
42 var parse = String.Join(Environment.NewLine,
43 "<?xml version=\"1.0\" encoding=\"utf-16\"?>",
44 "<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>",
45 " <Product>",
46 " <Package Compressed='no' />",
47 " </Product>",
48 "</Wix>");
49
50 var expected = new[]
51 {
52 "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">",
53 " <Package Compressed=\"no\">",
54 " ",
55 " </Package>",
56 "</Wix>"
57 };
58
59 AssertSuccess(parse, 4, expected);
60 }
61
62 [Fact]
63 public void FixesCompressedWhenOmitted()
64 {
65 var parse = String.Join(Environment.NewLine,
66 "<?xml version=\"1.0\" encoding=\"utf-16\"?>",
67 "<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>",
68 " <Product>",
69 " <Package />",
70 " </Product>",
71 "</Wix>");
72
73 var expected = new[]
74 {
75 "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">",
76 " <Package Compressed=\"no\">",
77 " ",
78 " </Package>",
79 "</Wix>"
80 };
81
82 AssertSuccess(parse, 4, expected);
83 }
84
85 private static void AssertSuccess(string input, int expectedErrorCount, string[] expected)
86 {
87 var document = XDocument.Parse(input, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo);
88
89 var messaging = new MockMessaging();
90 var converter = new WixConverter(messaging, 2, null, null);
91
92 var errors = converter.ConvertDocument(document);
93 Assert.Equal(expectedErrorCount, errors);
94
95 var actualLines = UnformattedDocumentLines(document);
96 WixAssert.CompareLineByLine(expected, actualLines);
97 }
98
99 [Fact]
100 public void FixesInstallerVersion()
101 {
102 var parse = String.Join(Environment.NewLine,
103 "<?xml version=\"1.0\" encoding=\"utf-16\"?>",
104 "<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>",
105 " <Product>",
106 " <Package InstallerVersion='666' />",
107 " </Product>",
108 "</Wix>");
109
110 var expected = new[]
111 {
112 "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">",
113 " <Package Compressed=\"no\" InstallerVersion=\"666\">",
114 " ",
115 " </Package>",
116 "</Wix>"
117 };
118
119 AssertSuccess(parse, 3, expected);
120 }
121
122 [Fact]
123 public void FixesDefaultInstallerVersion()
124 {
125 var parse = String.Join(Environment.NewLine,
126 "<?xml version=\"1.0\" encoding=\"utf-16\"?>",
127 "<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>",
128 " <Product>",
129 " <Package InstallerVersion='500' />",
130 " </Product>",
131 "</Wix>");
132
133 var expected = new[]
134 {
135 "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">",
136 " <Package Compressed=\"no\">",
137 " ",
138 " </Package>",
139 "</Wix>"
140 };
141
142 AssertSuccess(parse, 3, expected);
143 }
144
145 [Fact]
146 public void FixesImplicitInstallerVersion()
147 {
148 var parse = String.Join(Environment.NewLine,
149 "<?xml version=\"1.0\" encoding=\"utf-16\"?>",
150 "<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>",
151 " <Product>",
152 " <Package />",
153 " </Product>",
154 "</Wix>");
155
156 var expected = new[]
157 {
158 "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">",
159 " <Package Compressed=\"no\">",
160 " ",
161 " </Package>",
162 "</Wix>"
163 };
164
165 AssertSuccess(parse, 4, expected);
166 }
167
168 [Fact]
169 public void FixesNonDefaultInstallerVersion()
170 {
171 var parse = String.Join(Environment.NewLine,
172 "<?xml version=\"1.0\" encoding=\"utf-16\"?>",
173 "<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>",
174 " <Product>",
175 " <Package InstallerVersion='200' />",
176 " </Product>",
177 "</Wix>");
178
179 var expected = new[]
180 {
181 "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">",
182 " <Package Compressed=\"no\" InstallerVersion=\"200\">",
183 " ",
184 " </Package>",
185 "</Wix>"
186 };
187
188 AssertSuccess(parse, 3, expected);
189 }
190
191 [Fact]
192 public void FixesLimitedInstallerPrivileges()
193 {
194 var parse = String.Join(Environment.NewLine,
195 "<?xml version=\"1.0\" encoding=\"utf-16\"?>",
196 "<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>",
197 " <Product>",
198 " <Package InstallPrivileges='limited' />",
199 " </Product>",
200 "</Wix>");
201
202 var expected = new[]
203 {
204 "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">",
205 " <Package Compressed=\"no\" Scope=\"perUser\">",
206 " ",
207 " </Package>",
208 "</Wix>"
209 };
210
211 AssertSuccess(parse, 4, expected);
212 }
213
214 [Fact]
215 public void FixesElevatedInstallerPrivileges()
216 {
217 var parse = String.Join(Environment.NewLine,
218 "<?xml version=\"1.0\" encoding=\"utf-16\"?>",
219 "<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>",
220 " <Product>",
221 " <Package InstallPrivileges='elevated' />",
222 " <Property Id='ALLUSERS' Value='1' />",
223 " </Product>",
224 "</Wix>");
225
226 var expected = new[]
227 {
228 "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">",
229 " <Package Compressed=\"no\">",
230 " ",
231 " ",
232 " </Package>",
233 "</Wix>"
234 };
235
236 AssertSuccess(parse, 4, expected);
237 }
238
239 [Fact]
240 public void CanDecompileAndRecompile()
241 {
242 using (var fs = new DisposableFileSystem())
243 {
244 var baseFolder = fs.GetFolder();
245 var intermediateFolder = Path.Combine(baseFolder, "obj");
246 var decompiledWxsPath = Path.Combine(baseFolder, "TypicalV3.wxs");
247
248 var folder = TestData.Get(@"TestData\PackageSummaryInformation");
249 var v3msiPath = Path.Combine(folder, "TypicalV3.msi");
250 var result = WixRunner.Execute(new[]
251 {
252 "msi", "decompile", v3msiPath,
253 "-intermediateFolder", intermediateFolder,
254 "-o", decompiledWxsPath
255 });
256
257 result.AssertSuccess();
258
259 var v4msiPath = Path.Combine(intermediateFolder, "TypicalV4.msi");
260 result = WixRunner.Execute(new[]
261 {
262 "build", decompiledWxsPath,
263 "-arch", "x64",
264 "-intermediateFolder", intermediateFolder,
265 "-o", v4msiPath
266 });
267
268 result.AssertSuccess();
269
270 Assert.True(File.Exists(v4msiPath));
271
272 var v3results = Query.QueryDatabase(v3msiPath, new[] { "_SummaryInformation", "Property" });
273 var v4results = Query.QueryDatabase(v4msiPath, new[] { "_SummaryInformation", "Property" });
274 WixAssert.CompareLineByLine(v3results, v4results);
275 }
276 }
277 }
278 }