aboutsummaryrefslogtreecommitdiff
path: root/src/test/WixToolsetTest.CoreIntegration/PatchFixture.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/WixToolsetTest.CoreIntegration/PatchFixture.cs')
-rw-r--r--src/test/WixToolsetTest.CoreIntegration/PatchFixture.cs112
1 files changed, 112 insertions, 0 deletions
diff --git a/src/test/WixToolsetTest.CoreIntegration/PatchFixture.cs b/src/test/WixToolsetTest.CoreIntegration/PatchFixture.cs
new file mode 100644
index 00000000..584f86fe
--- /dev/null
+++ b/src/test/WixToolsetTest.CoreIntegration/PatchFixture.cs
@@ -0,0 +1,112 @@
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
3namespace WixToolsetTest.CoreIntegration
4{
5 using System.ComponentModel;
6 using System.IO;
7 using System.Linq;
8 using System.Runtime.InteropServices;
9 using System.Text;
10 using System.Xml.Linq;
11 using WixBuildTools.TestSupport;
12 using WixToolset.Core.TestPackage;
13 using Xunit;
14
15 public class PatchFixture
16 {
17 private static readonly XNamespace PatchNamespace = "http://www.microsoft.com/msi/patch_applicability.xsd";
18
19 [Fact(Skip = "Skip until patches have files in them")]
20 public void CanBuildSimplePatch()
21 {
22 var folder = TestData.Get(@"TestData\PatchSingle");
23
24 using (var fs = new DisposableFileSystem())
25 {
26 var tempFolder = fs.GetFolder();
27
28 var baselinePdb = BuildMsi("Baseline.msi", folder, tempFolder, "1.0.0", "1.0.0", "1.0.0");
29 var update1Pdb = BuildMsi("Update.msi", folder, tempFolder, "1.0.1", "1.0.1", "1.0.1");
30 var patchPdb = BuildMsp("Patch1.msp", folder, tempFolder, "1.0.1");
31 var baselinePath = Path.ChangeExtension(baselinePdb, ".msp");
32 var patchPath = Path.ChangeExtension(patchPdb, ".msp");
33
34 Assert.True(File.Exists(baselinePdb));
35 Assert.True(File.Exists(update1Pdb));
36
37 var doc = GetExtractPatchXml(patchPath);
38 Assert.Equal("{7D326855-E790-4A94-8611-5351F8321FCA}", doc.Root.Element(PatchNamespace + "TargetProductCode").Value);
39
40 var names = Query.GetSubStorageNames(patchPath);
41 Assert.Equal(new[] { "#RTM.1", "RTM.1" }, names);
42
43 var cab = Path.Combine(tempFolder, "foo.cab");
44 Query.ExtractStream(patchPath, "foo.cab", cab);
45 Assert.True(File.Exists(cab));
46
47 var files = Query.GetCabinetFiles(cab);
48 Assert.Equal(new[] { "a", "b" }, files.Select(f => f.ArchiveName).ToArray()); // This test may not be quite correct, yet.
49 }
50 }
51
52 private static string BuildMsi(string outputName, string sourceFolder, string baseFolder, string defineV, string defineA, string defineB)
53 {
54 var outputPath = Path.Combine(baseFolder, Path.Combine("bin", outputName));
55
56 var result = WixRunner.Execute(new[]
57 {
58 "build",
59 Path.Combine(sourceFolder, @"Package.wxs"),
60 "-d", "V=" + defineV,
61 "-d", "A=" + defineA,
62 "-d", "B=" + defineB,
63 "-bindpath", Path.Combine(sourceFolder, ".data"),
64 "-intermediateFolder", Path.Combine(baseFolder, "obj"),
65 "-o", outputPath
66 });
67
68 result.AssertSuccess();
69
70 return Path.ChangeExtension(outputPath, ".wixpdb");
71 }
72
73 private static string BuildMsp(string outputName, string sourceFolder, string baseFolder, string defineV)
74 {
75 var outputPath = Path.Combine(baseFolder, Path.Combine("bin", outputName));
76
77 var result = WixRunner.Execute(new[]
78 {
79 "build",
80 Path.Combine(sourceFolder, @"Patch.wxs"),
81 "-d", "V=" + defineV,
82 "-bindpath", Path.Combine(baseFolder, "bin"),
83 "-intermediateFolder", Path.Combine(baseFolder, "obj"),
84 "-o", outputPath
85 });
86
87 result.AssertSuccess();
88
89 return Path.ChangeExtension(outputPath, ".wixpdb");
90 }
91
92 private static XDocument GetExtractPatchXml(string path)
93 {
94 var buffer = new StringBuilder(65535);
95 var size = buffer.Capacity;
96
97 var er = MsiExtractPatchXMLData(path, 0, buffer, ref size);
98 if (er != 0)
99 {
100 throw new Win32Exception(er);
101 }
102
103 return XDocument.Parse(buffer.ToString());
104 }
105
106 [DllImport("msi.dll", EntryPoint = "MsiExtractPatchXMLDataW", CharSet = CharSet.Unicode, ExactSpelling = true)]
107 private static extern int MsiExtractPatchXMLData(string szPatchPath, int dwReserved, StringBuilder szXMLData, ref int pcchXMLData);
108
109 [DllImport("msi.dll", EntryPoint = "MsiApplyPatchW", CharSet = CharSet.Unicode, ExactSpelling = true)]
110 private static extern int MsiApplyPatch(string szPatchPackage, string szInstallPackage, int eInstallType, string szCommandLine);
111 }
112}