main
cs 1,043 lines 40.4 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.Xml.Linq;
7 using WixInternal.TestSupport;
8 using WixToolset.Converters;
9 using WixToolsetTest.Converters.Mocks;
10 using Xunit;
11
12 public class ConditionFixture : BaseConverterFixture
13 {
14 [Fact]
15 public void FixControlCondition()
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 " <UI>",
22 " <Dialog Id='Dlg1'>",
23 " <Control Id='Control1'>",
24 " <Condition Action='disable'>$(var.x)=$(var.y)</Condition>",
25 " <Condition Action='hide'>$(var.a)&lt;>$(var.b)</Condition>",
26 " </Control>",
27 " </Dialog>",
28 " </UI>",
29 " </Fragment>",
30 "</Wix>");
31
32 var expected = new[]
33 {
34 "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">",
35 " <Fragment>",
36 " <UI>",
37 " <Dialog Id=\"Dlg1\">",
38 " <Control Id=\"Control1\" DisableCondition=\"$(var.x)=$(var.y)\" HideCondition=\"$(var.a)&lt;&gt;$(var.b)\" />",
39 " </Dialog>",
40 " </UI>",
41 " </Fragment>",
42 "</Wix>"
43 };
44
45 var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo);
46
47 var messaging = new MockMessaging();
48 var converter = new WixConverter(messaging, 2, null, null);
49
50 var errors = converter.ConvertDocument(document);
51 Assert.Equal(4, errors);
52
53 var actualLines = UnformattedDocumentLines(document);
54 WixAssert.CompareLineByLine(expected, actualLines);
55 }
56
57 [Fact]
58 public void FixDoubleControlCondition()
59 {
60 var parse = String.Join(Environment.NewLine,
61 "<?xml version=\"1.0\" encoding=\"utf-16\"?>",
62 "<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>",
63 " <Fragment>",
64 " <UI>",
65 " <Dialog Id='Dlg1'>",
66 " <Control Id='Control1'>",
67 " <Condition Action='hide'>$(var.x)=$(var.y)</Condition>",
68 " <Condition Action='hide'>$(var.a)&lt;>$(var.b)</Condition>",
69 " </Control>",
70 " </Dialog>",
71 " </UI>",
72 " </Fragment>",
73 "</Wix>");
74
75 var expected = new[]
76 {
77 "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">",
78 " <Fragment>",
79 " <UI>",
80 " <Dialog Id=\"Dlg1\">",
81 " <Control Id=\"Control1\" HideCondition=\"($(var.x)=$(var.y)) OR ($(var.a)&lt;&gt;$(var.b))\" />",
82 " </Dialog>",
83 " </UI>",
84 " </Fragment>",
85 "</Wix>"
86 };
87
88 var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo);
89
90 var messaging = new MockMessaging();
91 var converter = new WixConverter(messaging, 2, null, null);
92
93 var errors = converter.ConvertDocument(document);
94 Assert.Equal(4, errors);
95
96 var actualLines = UnformattedDocumentLines(document);
97 WixAssert.CompareLineByLine(expected, actualLines);
98 }
99
100 [Fact]
101 public void FixControlConditionWithComment()
102 {
103 var parse = String.Join(Environment.NewLine,
104 "<?xml version=\"1.0\" encoding=\"utf-16\"?>",
105 "<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>",
106 " <Fragment>",
107 " <UI>",
108 " <Dialog Id='Dlg1'>",
109 " <Control Id='Control1'>",
110 " <Condition Action='disable'><!-- Comment 1 -->$(var.x)=$(var.y)</Condition>",
111 " <Condition Action='hide'><!-- Comment 2 -->$(var.a)&lt;>$(var.b)</Condition>",
112 " </Control>",
113 " </Dialog>",
114 " </UI>",
115 " </Fragment>",
116 "</Wix>");
117
118 var expected = new[]
119 {
120 "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">",
121 " <Fragment>",
122 " <UI>",
123 " <Dialog Id=\"Dlg1\">",
124 " <!-- Comment 1 -->",
125 " <!-- Comment 2 -->",
126 " <Control Id=\"Control1\" DisableCondition=\"$(var.x)=$(var.y)\" HideCondition=\"$(var.a)&lt;&gt;$(var.b)\" />",
127 " </Dialog>",
128 " </UI>",
129 " </Fragment>",
130 "</Wix>"
131 };
132
133 var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo);
134
135 var messaging = new MockMessaging();
136 var converter = new WixConverter(messaging, 2, null, null);
137
138 var errors = converter.ConvertDocument(document);
139 Assert.Equal(4, errors);
140
141 var actualLines = UnformattedDocumentLines(document);
142 WixAssert.CompareLineByLine(expected, actualLines);
143 }
144
145 [Fact]
146 public void DemonstrateTheHandlingOfQuotedBackslashesInInnerText()
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 " <Fragment>",
152 " <UI>",
153 " <Dialog Id='Dlg1'>",
154 " <Control Id='Control1'>",
155 " <Condition Action='hide'>\"\\\"=$(var.separator)</Condition>",
156 " </Control>",
157 " </Dialog>",
158 " </UI>",
159 " </Fragment>",
160 "</Wix>");
161
162 var expected = new[]
163 {
164 "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">",
165 " <Fragment>",
166 " <UI>",
167 " <Dialog Id=\"Dlg1\">",
168 " <Control Id=\"Control1\" HideCondition=\"&quot;\\&quot;=$(var.separator)\" />",
169 " </Dialog>",
170 " </UI>",
171 " </Fragment>",
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
182 var actualLines = UnformattedDocumentLines(document);
183 WixAssert.CompareLineByLine(expected, actualLines);
184 }
185
186 [Fact]
187 public void FixControlConditionWithStringConstants()
188 {
189 var parse = String.Join(Environment.NewLine,
190 "<?xml version=\"1.0\" encoding=\"utf-16\"?>",
191 "<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>",
192 " <Fragment>",
193 " <UI>",
194 " <Dialog Id='Dlg1'>",
195 " <Control Id='Control1'>",
196 " <Condition Action='hide'>\"x\"=$(var.y)</Condition>",
197 " <Condition Action='hide'>\"x's\"=$(var.y)</Condition>",
198 " </Control>",
199 " </Dialog>",
200 " </UI>",
201 " </Fragment>",
202 "</Wix>");
203
204 var expected = new[]
205 {
206 "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">",
207 " <Fragment>",
208 " <UI>",
209 " <Dialog Id=\"Dlg1\">",
210 " <Control Id=\"Control1\" HideCondition=\"(&quot;x&quot;=$(var.y)) OR (&quot;x's&quot;=$(var.y))\" />",
211 " </Dialog>",
212 " </UI>",
213 " </Fragment>",
214 "</Wix>"
215 };
216
217 var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo);
218
219 var messaging = new MockMessaging();
220 var converter = new WixConverter(messaging, 2, null, null);
221
222 var errors = converter.ConvertDocument(document);
223 Assert.Equal(4, errors);
224
225 var actualLines = UnformattedDocumentLines(document);
226 WixAssert.CompareLineByLine(expected, actualLines);
227 }
228
229 [Fact]
230 public void FixPublishCondition()
231 {
232 var parse = String.Join(Environment.NewLine,
233 "<?xml version=\"1.0\" encoding=\"utf-16\"?>",
234 "<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>",
235 " <Fragment>",
236 " <UI>",
237 " <Dialog Id='Dlg1'>",
238 " <Control Id='Control1'>",
239 " <Publish Value='abc'>1&lt;2</Publish>",
240 " <Publish Value='gone'>1</Publish>",
241 " </Control>",
242 " </Dialog>",
243 " </UI>",
244 " </Fragment>",
245 "</Wix>");
246
247 var expected = new[]
248 {
249 "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">",
250 " <Fragment>",
251 " <UI>",
252 " <Dialog Id=\"Dlg1\">",
253 " <Control Id=\"Control1\">",
254 " <Publish Value=\"abc\" Condition=\"1&lt;2\" />",
255 " <Publish Value=\"gone\" />",
256 " </Control>",
257 " </Dialog>",
258 " </UI>",
259 " </Fragment>",
260 "</Wix>"
261 };
262
263 var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo);
264
265 var messaging = new MockMessaging();
266 var converter = new WixConverter(messaging, 2, null, null);
267
268 var errors = converter.ConvertDocument(document);
269 Assert.Equal(5, errors);
270
271 var actualLines = UnformattedDocumentLines(document);
272 WixAssert.CompareLineByLine(expected, actualLines);
273 }
274
275 [Fact]
276 public void FixPublishConditionWithComment()
277 {
278 var parse = String.Join(Environment.NewLine,
279 "<?xml version=\"1.0\" encoding=\"utf-16\"?>",
280 "<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>",
281 " <Fragment>",
282 " <UI>",
283 " <Dialog Id='Dlg1'>",
284 " <Control Id='Control1'>",
285 " <Publish Value='abc'><!-- Comment 1 -->1&lt;2</Publish>",
286 " <Publish Value='gone'><!-- Comment 2 -->1</Publish>",
287 " </Control>",
288 " </Dialog>",
289 " </UI>",
290 " </Fragment>",
291 "</Wix>");
292
293 var expected = new[]
294 {
295 "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">",
296 " <Fragment>",
297 " <UI>",
298 " <Dialog Id=\"Dlg1\">",
299 " <Control Id=\"Control1\">",
300 " <!-- Comment 1 -->",
301 " <Publish Value=\"abc\" Condition=\"1&lt;2\" />",
302 " <!-- Comment 2 -->",
303 " <Publish Value=\"gone\" />",
304 " </Control>",
305 " </Dialog>",
306 " </UI>",
307 " </Fragment>",
308 "</Wix>"
309 };
310
311 var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo);
312
313 var messaging = new MockMessaging();
314 var converter = new WixConverter(messaging, 2, null, null);
315
316 var errors = converter.ConvertDocument(document);
317 Assert.Equal(5, errors);
318
319 var actualLines = UnformattedDocumentLines(document);
320 WixAssert.CompareLineByLine(expected, actualLines);
321 }
322
323 [Fact]
324 public void FixComponentCondition()
325 {
326 var parse = String.Join(Environment.NewLine,
327 "<?xml version=\"1.0\" encoding=\"utf-16\"?>",
328 "<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>",
329 " <Fragment>",
330 " <Component Id='Comp1' Directory='ApplicationFolder'>",
331 " <Condition>1&lt;2</Condition>",
332 " </Component>",
333 " </Fragment>",
334 "</Wix>");
335
336 var expected = new[]
337 {
338 "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">",
339 " <Fragment>",
340 " <Component Id=\"Comp1\" Directory=\"ApplicationFolder\" Condition=\"1&lt;2\" />",
341 " </Fragment>",
342 "</Wix>"
343 };
344
345 var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo);
346
347 var messaging = new MockMessaging();
348 var converter = new WixConverter(messaging, 2, null, null);
349
350 var errors = converter.ConvertDocument(document);
351 Assert.Equal(3, errors);
352
353 var actualLines = UnformattedDocumentLines(document);
354 WixAssert.CompareLineByLine(expected, actualLines);
355 }
356
357 [Fact]
358 public void FixComponentConditionWithComment()
359 {
360 var parse = String.Join(Environment.NewLine,
361 "<?xml version=\"1.0\" encoding=\"utf-16\"?>",
362 "<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>",
363 " <Fragment>",
364 " <Component Id='Comp1' Directory='ApplicationFolder'>",
365 " <Condition><!-- Comment -->1&lt;2</Condition>",
366 " </Component>",
367 " </Fragment>",
368 "</Wix>");
369
370 var expected = new[]
371 {
372 "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">",
373 " <Fragment>",
374 " <!-- Comment -->",
375 " <Component Id=\"Comp1\" Directory=\"ApplicationFolder\" Condition=\"1&lt;2\" />",
376 " </Fragment>",
377 "</Wix>"
378 };
379
380 var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo);
381
382 var messaging = new MockMessaging();
383 var converter = new WixConverter(messaging, 2, null, null);
384
385 var errors = converter.ConvertDocument(document);
386 Assert.Equal(3, errors);
387
388 var actualLines = UnformattedDocumentLines(document);
389 WixAssert.CompareLineByLine(expected, actualLines);
390 }
391
392 [Fact]
393 public void FixMultilineComponentCondition()
394 {
395 var parse = String.Join(Environment.NewLine,
396 "<?xml version=\"1.0\" encoding=\"utf-16\"?>",
397 "<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>",
398 " <Fragment>",
399 " <Component Id='Comp1' Directory='ApplicationFolder'>",
400 " <Condition>1&lt;2</Condition>",
401 " </Component>",
402 " </Fragment>",
403 "</Wix>");
404
405 var expected = new[]
406 {
407 "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">",
408 " <Fragment>",
409 " <Component Id=\"Comp1\" Directory=\"ApplicationFolder\" Condition=\"1&lt;2\" />",
410 " </Fragment>",
411 "</Wix>"
412 };
413
414 var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo);
415
416 var messaging = new MockMessaging();
417 var converter = new WixConverter(messaging, 2, null, null);
418
419 var errors = converter.ConvertDocument(document);
420 Assert.Equal(3, errors);
421
422 var actualLines = UnformattedDocumentLines(document);
423 WixAssert.CompareLineByLine(expected, actualLines);
424 }
425
426 [Fact]
427 public void FixMultilineComponentConditionWithComment()
428 {
429 var parse = String.Join(Environment.NewLine,
430 "<?xml version=\"1.0\" encoding=\"utf-16\"?>",
431 "<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>",
432 " <Fragment>",
433 " <Component Id='Comp1' Directory='ApplicationFolder'>",
434 " <Condition>",
435 " <!-- Comment -->",
436 " 1&lt;2 OR ",
437 " 4&lt;3",
438 " </Condition>",
439 " </Component>",
440 " </Fragment>",
441 "</Wix>");
442 var expected = new[]
443 {
444 "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">",
445 " <Fragment>",
446 " <!-- Comment -->",
447 " <Component Id=\"Comp1\" Directory=\"ApplicationFolder\" Condition=\"1&lt;2 OR 4&lt;3\" />",
448 " </Fragment>",
449 "</Wix>"
450 };
451
452 var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo);
453
454 var messaging = new MockMessaging();
455 var converter = new WixConverter(messaging, 2, null, null);
456
457 var errors = converter.ConvertDocument(document);
458 Assert.Equal(3, errors);
459
460 var actualLines = UnformattedDocumentLines(document);
461 WixAssert.CompareLineByLine(expected, actualLines);
462 }
463
464 [Fact]
465 public void FixEmptyCondition()
466 {
467 var parse = String.Join(Environment.NewLine,
468 "<?xml version=\"1.0\" encoding=\"utf-16\"?>",
469 "<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>",
470 " <Fragment>",
471 " <Condition Message='Empty new line'>",
472 " </Condition>",
473 " <Condition Message='Empty cdata'><![CDATA[]]></Condition>",
474 " </Fragment>",
475 "</Wix>");
476
477 var expected = new[]
478 {
479 "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">",
480 " <Fragment>",
481 " <Launch Condition=\"\" Message=\"Empty new line\" />",
482 " <Launch Condition=\"\" Message=\"Empty cdata\" />",
483 " </Fragment>",
484 "</Wix>"
485 };
486
487 var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo);
488
489 var messaging = new MockMessaging();
490 var converter = new WixConverter(messaging, 2, null, null);
491
492 var errors = converter.ConvertDocument(document);
493
494 var actualLines = UnformattedDocumentLines(document);
495 WixAssert.CompareLineByLine(expected, actualLines);
496
497 Assert.Equal(4, errors);
498 }
499
500 [Fact]
501 public void FixConditionWithComment()
502 {
503 var parse = String.Join(Environment.NewLine,
504 "<?xml version=\"1.0\" encoding=\"utf-16\"?>",
505 "<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>",
506 " <Fragment>",
507 " <Condition Message='commented cdata'><!-- commented conditional -->",
508 "<![CDATA[cdatacontent]]></Condition>",
509 " </Fragment>",
510 "</Wix>");
511
512 var expected = new[]
513 {
514 "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">",
515 " <Fragment>",
516 " <!-- commented conditional -->",
517 " <Launch Condition=\"cdatacontent\" Message=\"commented cdata\" />",
518 " </Fragment>",
519 "</Wix>"
520 };
521
522 var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo);
523
524 var messaging = new MockMessaging();
525 var converter = new WixConverter(messaging, 2, null, null);
526
527 var errors = converter.ConvertDocument(document);
528
529 var actualLines = UnformattedDocumentLines(document);
530 WixAssert.CompareLineByLine(expected, actualLines);
531
532 Assert.Equal(3, errors);
533 }
534
535 [Fact]
536 public void FixConditionFromWxi()
537 {
538 var parse = String.Join(Environment.NewLine,
539 "<?xml version=\"1.0\" encoding=\"utf-16\"?>",
540 "<Include xmlns='http://schemas.microsoft.com/wix/2006/wi'>",
541 " <Condition Message='from wxi'>",
542 " wxicondition",
543 " </Condition>",
544 "</Include>");
545
546 var expected = new[]
547 {
548 "<Include xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">",
549 " <Launch Condition=\"wxicondition\" Message=\"from wxi\" />",
550 "</Include>"
551 };
552
553 var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo);
554
555 var messaging = new MockMessaging();
556 var converter = new WixConverter(messaging, 2, null, null);
557
558 var errors = converter.ConvertDocument(document);
559
560 var actualLines = UnformattedDocumentLines(document);
561 WixAssert.CompareLineByLine(expected, actualLines);
562
563 Assert.Equal(3, errors);
564 }
565
566 [Fact]
567 public void FixFeatureCondition()
568 {
569 var parse = String.Join(Environment.NewLine,
570 "<?xml version=\"1.0\" encoding=\"utf-16\"?>",
571 "<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>",
572 " <Fragment>",
573 " <Feature Id='Feature1'>",
574 " <Condition Level='0'>PROP = 1</Condition>",
575 " </Feature>",
576 " </Fragment>",
577 "</Wix>");
578
579 var expected = new[]
580 {
581 "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">",
582 " <Fragment>",
583 " <Feature Id=\"Feature1\">",
584 " <Level Value=\"0\" Condition=\"PROP = 1\" />",
585 " </Feature>",
586 " </Fragment>",
587 "</Wix>"
588 };
589
590 var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo);
591
592 var messaging = new MockMessaging();
593 var converter = new WixConverter(messaging, 2, null, null);
594
595 var errors = converter.ConvertDocument(document);
596 Assert.Equal(3, errors);
597
598 var actualLines = UnformattedDocumentLines(document);
599 WixAssert.CompareLineByLine(expected, actualLines);
600 }
601
602 [Fact]
603 public void FixFeatureConditionWithComment()
604 {
605 var parse = String.Join(Environment.NewLine,
606 "<?xml version=\"1.0\" encoding=\"utf-16\"?>",
607 "<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>",
608 " <Fragment>",
609 " <Feature Id='Feature1'>",
610 " <Condition Level='0'><!-- Comment -->PROP = 1</Condition>",
611 " </Feature>",
612 " </Fragment>",
613 "</Wix>");
614
615 var expected = new[]
616 {
617 "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">",
618 " <Fragment>",
619 " <Feature Id=\"Feature1\">",
620 " <!-- Comment -->",
621 " <Level Value=\"0\" Condition=\"PROP = 1\" />",
622 " </Feature>",
623 " </Fragment>",
624 "</Wix>"
625 };
626
627 var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo);
628
629 var messaging = new MockMessaging();
630 var converter = new WixConverter(messaging, 2, null, null);
631
632 var errors = converter.ConvertDocument(document);
633 Assert.Equal(3, errors);
634
635 var actualLines = UnformattedDocumentLines(document);
636 WixAssert.CompareLineByLine(expected, actualLines);
637 }
638
639 [Fact]
640 public void FixMultilineFeatureCondition()
641 {
642 var parse = String.Join(Environment.NewLine,
643 "<?xml version=\"1.0\" encoding=\"utf-16\"?>",
644 "<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>",
645 " <Fragment>",
646 " <Feature Id='ShellExtensionFeature' Level='0' InstallDefault='local' >",
647 " <Condition Level='1'>",
648 " (NOT Installed AND NOT PERUSER) OR",
649 " (Installed AND ZOS_SHELL_EXTENSION_INSTALLLED)",
650 " </Condition>",
651 " <ComponentGroupRef Id='ShellExtComponents' />",
652 " </Feature>",
653 " </Fragment>",
654 "</Wix>");
655
656 var expected = new[]
657 {
658 "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">",
659 " <Fragment>",
660 " <Feature Id=\"ShellExtensionFeature\" Level=\"0\" InstallDefault=\"local\">",
661 " <Level Value=\"1\" Condition=\"(NOT Installed AND NOT PERUSER) OR (Installed AND ZOS_SHELL_EXTENSION_INSTALLLED)\" />",
662 " <ComponentGroupRef Id=\"ShellExtComponents\" />",
663 " </Feature>",
664 " </Fragment>",
665 "</Wix>"
666 };
667
668 var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo);
669
670 var messaging = new MockMessaging();
671 var converter = new WixConverter(messaging, 2, null, null);
672
673 var errors = converter.ConvertDocument(document);
674 Assert.Equal(3, errors);
675
676 var actualLines = UnformattedDocumentLines(document);
677 WixAssert.CompareLineByLine(expected, actualLines);
678 }
679
680 [Fact]
681 public void FixMultilineFeatureConditionWithComment()
682 {
683 var parse = String.Join(Environment.NewLine,
684 "<?xml version=\"1.0\" encoding=\"utf-16\"?>",
685 "<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>",
686 " <Fragment>",
687 " <Feature Id='ShellExtensionFeature' Level='0' InstallDefault='local' >",
688 " <Condition Level='1'>",
689 " <!-- Comment -->",
690 " (NOT Installed AND NOT PERUSER) OR",
691 " (Installed AND ZOS_SHELL_EXTENSION_INSTALLLED)",
692 " </Condition>",
693 " <ComponentGroupRef Id='ShellExtComponents' />",
694 " </Feature>",
695 " </Fragment>",
696 "</Wix>");
697
698 var expected = new[]
699 {
700 "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">",
701 " <Fragment>",
702 " <Feature Id=\"ShellExtensionFeature\" Level=\"0\" InstallDefault=\"local\">",
703 " <!-- Comment -->",
704 " <Level Value=\"1\" Condition=\"(NOT Installed AND NOT PERUSER) OR (Installed AND ZOS_SHELL_EXTENSION_INSTALLLED)\" />",
705 " <ComponentGroupRef Id=\"ShellExtComponents\" />",
706 " </Feature>",
707 " </Fragment>",
708 "</Wix>"
709 };
710
711 var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo);
712
713 var messaging = new MockMessaging();
714 var converter = new WixConverter(messaging, 2, null, null);
715
716 var errors = converter.ConvertDocument(document);
717 Assert.Equal(3, errors);
718
719 var actualLines = UnformattedDocumentLines(document);
720 WixAssert.CompareLineByLine(expected, actualLines);
721 }
722
723 [Fact]
724 public void FixLaunchConditionInFragment()
725 {
726 var parse = String.Join(Environment.NewLine,
727 "<?xml version=\"1.0\" encoding=\"utf-16\"?>",
728 "<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>",
729 " <Fragment>",
730 " <Condition Message='Stop the install'>",
731 " 1&lt;2",
732 " </Condition>",
733 " <Condition Message='Do not stop'>",
734 " 1=2",
735 " </Condition>",
736 " </Fragment>",
737 "</Wix>");
738
739 var expected = new[]
740 {
741 "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">",
742 " <Fragment>",
743 " <Launch Condition=\"1&lt;2\" Message=\"Stop the install\" />",
744 " <Launch Condition=\"1=2\" Message=\"Do not stop\" />",
745 " </Fragment>",
746 "</Wix>"
747 };
748
749 var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo);
750
751 var messaging = new MockMessaging();
752 var converter = new WixConverter(messaging, 2, null, null);
753
754 var errors = converter.ConvertDocument(document);
755 Assert.Equal(4, errors);
756
757 var actualLines = UnformattedDocumentLines(document);
758 WixAssert.CompareLineByLine(expected, actualLines);
759 }
760
761 [Fact]
762 public void FixLaunchConditionInFragmentWithComment()
763 {
764 var parse = String.Join(Environment.NewLine,
765 "<?xml version=\"1.0\" encoding=\"utf-16\"?>",
766 "<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>",
767 " <Fragment>",
768 " <Condition Message='Stop the install'>",
769 " <!-- Comment 1 -->1&lt;2",
770 " </Condition>",
771 " <Condition Message='Do not stop'>",
772 " <!-- Comment 2 -->1=2",
773 " </Condition>",
774 " </Fragment>",
775 "</Wix>");
776
777 var expected = new[]
778 {
779 "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">",
780 " <Fragment>",
781 " <!-- Comment 1 -->",
782 " <Launch Condition=\"1&lt;2\" Message=\"Stop the install\" />",
783 " <!-- Comment 2 -->",
784 " <Launch Condition=\"1=2\" Message=\"Do not stop\" />",
785 " </Fragment>",
786 "</Wix>"
787 };
788
789 var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo);
790
791 var messaging = new MockMessaging();
792 var converter = new WixConverter(messaging, 2, null, null);
793
794 var errors = converter.ConvertDocument(document);
795 Assert.Equal(4, errors);
796
797 var actualLines = UnformattedDocumentLines(document);
798 WixAssert.CompareLineByLine(expected, actualLines);
799 }
800
801 [Fact]
802 public void FixMultilineLaunchConditionInFragment()
803 {
804 var parse = String.Join(Environment.NewLine,
805 "<?xml version=\"1.0\" encoding=\"utf-16\"?>",
806 "<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>",
807 " <Fragment>",
808 " <Condition Message='Stop the install'>",
809 " 1&lt;2 OR ",
810 " 4&lt;3",
811 " </Condition>",
812 " <Condition Message='Do not stop'>",
813 " 1=2",
814 " </Condition>",
815 " </Fragment>",
816 "</Wix>");
817
818 var expected = new[]
819 {
820 "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">",
821 " <Fragment>",
822 " <Launch Condition=\"1&lt;2 OR 4&lt;3\" Message=\"Stop the install\" />",
823 " <Launch Condition=\"1=2\" Message=\"Do not stop\" />",
824 " </Fragment>",
825 "</Wix>"
826 };
827
828 var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo);
829
830 var messaging = new MockMessaging();
831 var converter = new WixConverter(messaging, 2, null, null);
832
833 var errors = converter.ConvertDocument(document);
834 Assert.Equal(4, errors);
835
836 var actualLines = UnformattedDocumentLines(document);
837 WixAssert.CompareLineByLine(expected, actualLines);
838 }
839
840 [Fact]
841 public void FixMultilineLaunchConditionInFragmentWithComment()
842 {
843 var parse = String.Join(Environment.NewLine,
844 "<?xml version=\"1.0\" encoding=\"utf-16\"?>",
845 "<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>",
846 " <Fragment>",
847 " <Condition Message='Stop the install'>",
848 " <!-- Comment 1 -->",
849 " 1&lt;2 OR",
850 " 4&lt;3",
851 " </Condition>",
852 " <Condition Message='Do not stop'>",
853 " <!-- Comment 2 -->1=2",
854 " </Condition>",
855 " </Fragment>",
856 "</Wix>");
857
858 var expected = new[]
859 {
860 "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">",
861 " <Fragment>",
862 " <!-- Comment 1 -->",
863 " <Launch Condition=\"1&lt;2 OR 4&lt;3\" Message=\"Stop the install\" />",
864 " <!-- Comment 2 -->",
865 " <Launch Condition=\"1=2\" Message=\"Do not stop\" />",
866 " </Fragment>",
867 "</Wix>"
868 };
869
870 var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo);
871
872 var messaging = new MockMessaging();
873 var converter = new WixConverter(messaging, 2, null, null);
874
875 var errors = converter.ConvertDocument(document);
876 Assert.Equal(4, errors);
877
878 var actualLines = UnformattedDocumentLines(document);
879 WixAssert.CompareLineByLine(expected, actualLines);
880 }
881
882 [Fact]
883 public void FixLaunchConditionInProduct()
884 {
885 var parse = String.Join(Environment.NewLine,
886 "<?xml version=\"1.0\" encoding=\"utf-16\"?>",
887 "<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>",
888 " <Product>",
889 " <Package />",
890 " <Condition Message='Stop the install'>",
891 " 1&lt;2",
892 " </Condition>",
893 " <Condition Message='Do not stop'>",
894 " 1=2",
895 " </Condition>",
896 " </Product>",
897 "</Wix>");
898
899 var expected = new[]
900 {
901 "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">",
902 " <Package Compressed=\"no\">",
903 " ",
904 " <Launch Condition=\"1&lt;2\" Message=\"Stop the install\" />",
905 " <Launch Condition=\"1=2\" Message=\"Do not stop\" />",
906 " </Package>",
907 "</Wix>"
908 };
909
910 var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo);
911
912 var messaging = new MockMessaging();
913 var converter = new WixConverter(messaging, 2, null, null);
914
915 var errors = converter.ConvertDocument(document);
916 Assert.Equal(6, errors);
917
918 var actualLines = UnformattedDocumentLines(document);
919 WixAssert.CompareLineByLine(expected, actualLines);
920 }
921
922 [Fact]
923 public void FixLaunchConditionInProductWithComment()
924 {
925 var parse = String.Join(Environment.NewLine,
926 "<?xml version=\"1.0\" encoding=\"utf-16\"?>",
927 "<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>",
928 " <Product>",
929 " <Package />",
930 " <Condition Message='Stop the install'>",
931 " <!-- Comment 1 -->1&lt;2",
932 " </Condition>",
933 " <Condition Message='Do not stop'>",
934 " <!-- Comment 2 -->1=2",
935 " </Condition>",
936 " </Product>",
937 "</Wix>");
938
939 var expected = new[]
940 {
941 "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">",
942 " <Package Compressed=\"no\">",
943 " ",
944 " <!-- Comment 1 -->",
945 " <Launch Condition=\"1&lt;2\" Message=\"Stop the install\" />",
946 " <!-- Comment 2 -->",
947 " <Launch Condition=\"1=2\" Message=\"Do not stop\" />",
948 " </Package>",
949 "</Wix>"
950 };
951
952 var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo);
953
954 var messaging = new MockMessaging();
955 var converter = new WixConverter(messaging, 2, null, null);
956
957 var errors = converter.ConvertDocument(document);
958 Assert.Equal(6, errors);
959
960 var actualLines = UnformattedDocumentLines(document);
961 WixAssert.CompareLineByLine(expected, actualLines);
962 }
963
964 [Fact]
965 public void FixPermissionExCondition()
966 {
967 var parse = String.Join(Environment.NewLine,
968 "<!-- comment -->",
969 "<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>",
970 " <Fragment>",
971 " <Component Id='Comp1' Guid='*' Directory='ApplicationFolder'>",
972 " <PermissionEx Sddl='sddl'>",
973 " <Condition>1&lt;2</Condition>",
974 " </PermissionEx>",
975 " </Component>",
976 " </Fragment>",
977 "</Wix>");
978
979 var expected = new[]
980 {
981 "<!-- comment -->",
982 "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">",
983 " <Fragment>",
984 " <Component Id=\"Comp1\" Directory=\"ApplicationFolder\">",
985 " <PermissionEx Sddl=\"sddl\" Condition=\"1&lt;2\" />",
986 " </Component>",
987 " </Fragment>",
988 "</Wix>"
989 };
990
991 var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo);
992
993 var messaging = new MockMessaging();
994 var converter = new WixConverter(messaging, 2, null, null);
995
996 var errors = converter.ConvertDocument(document);
997 Assert.Equal(3, errors);
998
999 var actualLines = UnformattedDocumentLines(document);
1000 WixAssert.CompareLineByLine(expected, actualLines);
1001 }
1002
1003 [Fact]
1004 public void FixPermissionExConditionWithComment()
1005 {
1006 var parse = String.Join(Environment.NewLine,
1007 "<!-- Comment 1 -->",
1008 "<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>",
1009 " <Fragment>",
1010 " <Component Id='Comp1' Guid='*' Directory='ApplicationFolder'>",
1011 " <PermissionEx Sddl='sddl'>",
1012 " <Condition><!-- Comment 2 -->1&lt;2</Condition>",
1013 " </PermissionEx>",
1014 " </Component>",
1015 " </Fragment>",
1016 "</Wix>");
1017
1018 var expected = new[]
1019 {
1020 "<!-- Comment 1 -->",
1021 "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">",
1022 " <Fragment>",
1023 " <Component Id=\"Comp1\" Directory=\"ApplicationFolder\">",
1024 " <!-- Comment 2 -->",
1025 " <PermissionEx Sddl=\"sddl\" Condition=\"1&lt;2\" />",
1026 " </Component>",
1027 " </Fragment>",
1028 "</Wix>"
1029 };
1030
1031 var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo);
1032
1033 var messaging = new MockMessaging();
1034 var converter = new WixConverter(messaging, 2, null, null);
1035
1036 var errors = converter.ConvertDocument(document);
1037 Assert.Equal(3, errors);
1038
1039 var actualLines = UnformattedDocumentLines(document);
1040 WixAssert.CompareLineByLine(expected, actualLines);
1041 }
1042 }
1043 }