diff options
Diffstat (limited to 'src/dtf/WixToolsetTests.Dtf.WindowsInstaller/EmbeddedExternalUI.cs')
-rw-r--r-- | src/dtf/WixToolsetTests.Dtf.WindowsInstaller/EmbeddedExternalUI.cs | 173 |
1 files changed, 173 insertions, 0 deletions
diff --git a/src/dtf/WixToolsetTests.Dtf.WindowsInstaller/EmbeddedExternalUI.cs b/src/dtf/WixToolsetTests.Dtf.WindowsInstaller/EmbeddedExternalUI.cs new file mode 100644 index 00000000..b0fc00a8 --- /dev/null +++ b/src/dtf/WixToolsetTests.Dtf.WindowsInstaller/EmbeddedExternalUI.cs | |||
@@ -0,0 +1,173 @@ | |||
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 WixToolset.Dtf.Test | ||
4 | { | ||
5 | using System; | ||
6 | using System.IO; | ||
7 | using System.Reflection; | ||
8 | using System.Windows.Forms; | ||
9 | using System.Globalization; | ||
10 | using System.Collections.Generic; | ||
11 | using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
12 | using WixToolset.Dtf.WindowsInstaller; | ||
13 | using View = WixToolset.Dtf.WindowsInstaller.View; | ||
14 | |||
15 | [TestClass] | ||
16 | public class EmbeddedExternalUI | ||
17 | { | ||
18 | const InstallLogModes TestLogModes = | ||
19 | InstallLogModes.FatalExit | | ||
20 | InstallLogModes.Error | | ||
21 | InstallLogModes.Warning | | ||
22 | InstallLogModes.User | | ||
23 | InstallLogModes.Info | | ||
24 | InstallLogModes.ResolveSource | | ||
25 | InstallLogModes.OutOfDiskSpace | | ||
26 | InstallLogModes.ActionStart | | ||
27 | InstallLogModes.ActionData | | ||
28 | InstallLogModes.CommonData; | ||
29 | |||
30 | #if DEBUG | ||
31 | const string EmbeddedUISampleBinDir = @"..\..\build\debug\"; | ||
32 | #else | ||
33 | const string EmbeddedUISampleBinDir = @"..\..\build\release\"; | ||
34 | #endif | ||
35 | |||
36 | [TestMethod] | ||
37 | [Ignore] // Requires elevation. | ||
38 | public void EmbeddedUISingleInstall() | ||
39 | { | ||
40 | string dbFile = "EmbeddedUISingleInstall.msi"; | ||
41 | string productCode; | ||
42 | |||
43 | string uiDir = Path.GetFullPath(EmbeddedExternalUI.EmbeddedUISampleBinDir); | ||
44 | string uiFile = "WixToolset.Dtf.Samples.EmbeddedUI.dll"; | ||
45 | |||
46 | using (Database db = new Database(dbFile, DatabaseOpenMode.CreateDirect)) | ||
47 | { | ||
48 | WindowsInstallerUtils.InitializeProductDatabase(db); | ||
49 | WindowsInstallerUtils.CreateTestProduct(db); | ||
50 | |||
51 | productCode = db.ExecuteStringQuery("SELECT `Value` FROM `Property` WHERE `Property` = 'ProductCode'")[0]; | ||
52 | |||
53 | using (Record uiRec = new Record(5)) | ||
54 | { | ||
55 | uiRec[1] = "TestEmbeddedUI"; | ||
56 | uiRec[2] = Path.GetFileNameWithoutExtension(uiFile) + ".Wrapper.dll"; | ||
57 | uiRec[3] = 1; | ||
58 | uiRec[4] = (int) ( | ||
59 | EmbeddedExternalUI.TestLogModes | | ||
60 | InstallLogModes.Progress | | ||
61 | InstallLogModes.Initialize | | ||
62 | InstallLogModes.Terminate | | ||
63 | InstallLogModes.ShowDialog); | ||
64 | uiRec.SetStream(5, Path.Combine(uiDir, uiFile)); | ||
65 | db.Execute(db.Tables["MsiEmbeddedUI"].SqlInsertString, uiRec); | ||
66 | } | ||
67 | |||
68 | db.Commit(); | ||
69 | } | ||
70 | |||
71 | Installer.SetInternalUI(InstallUIOptions.Full); | ||
72 | |||
73 | ProductInstallation installation = new ProductInstallation(productCode); | ||
74 | Assert.IsFalse(installation.IsInstalled, "Checking that product is not installed before starting."); | ||
75 | |||
76 | Exception caughtEx = null; | ||
77 | try | ||
78 | { | ||
79 | Installer.EnableLog(EmbeddedExternalUI.TestLogModes, "install.log"); | ||
80 | Installer.InstallProduct(dbFile, String.Empty); | ||
81 | } | ||
82 | catch (Exception ex) { caughtEx = ex; } | ||
83 | Assert.IsNull(caughtEx, "Exception thrown while installing product: " + caughtEx); | ||
84 | |||
85 | Assert.IsTrue(installation.IsInstalled, "Checking that product is installed."); | ||
86 | Console.WriteLine(); | ||
87 | Console.WriteLine(); | ||
88 | Console.WriteLine(); | ||
89 | Console.WriteLine("==================================================================="); | ||
90 | Console.WriteLine(); | ||
91 | Console.WriteLine(); | ||
92 | Console.WriteLine(); | ||
93 | |||
94 | try | ||
95 | { | ||
96 | Installer.EnableLog(EmbeddedExternalUI.TestLogModes, "uninstall.log"); | ||
97 | Installer.InstallProduct(dbFile, "REMOVE=All"); | ||
98 | } | ||
99 | catch (Exception ex) { caughtEx = ex; } | ||
100 | Assert.IsNull(caughtEx, "Exception thrown while uninstalling product: " + caughtEx); | ||
101 | } | ||
102 | |||
103 | // This test does not pass if run normally. | ||
104 | // It only passes when a failure is injected into the EmbeddedUI launcher. | ||
105 | ////[TestMethod] | ||
106 | public void EmbeddedUIInitializeFails() | ||
107 | { | ||
108 | string dbFile = "EmbeddedUIInitializeFails.msi"; | ||
109 | string productCode; | ||
110 | |||
111 | string uiDir = Path.GetFullPath(EmbeddedExternalUI.EmbeddedUISampleBinDir); | ||
112 | string uiFile = "WixToolset.Dtf.Samples.EmbeddedUI.dll"; | ||
113 | |||
114 | // A number that will be used to check whether a type 19 CA runs. | ||
115 | const string magicNumber = "3.14159265358979323846264338327950"; | ||
116 | |||
117 | using (Database db = new Database(dbFile, DatabaseOpenMode.CreateDirect)) | ||
118 | { | ||
119 | WindowsInstallerUtils.InitializeProductDatabase(db); | ||
120 | WindowsInstallerUtils.CreateTestProduct(db); | ||
121 | |||
122 | const string failureActionName = "EmbeddedUIInitializeFails"; | ||
123 | db.Execute("INSERT INTO `CustomAction` (`Action`, `Type`, `Source`, `Target`) " + | ||
124 | "VALUES ('{0}', 19, '', 'Logging magic number: {1}')", failureActionName, magicNumber); | ||
125 | |||
126 | // This type 19 CA (launch condition) is given a condition of 'UILevel = 3' so that it only runs if the | ||
127 | // installation is running in BASIC UI mode, which is what we expect if the EmbeddedUI fails to initialize. | ||
128 | db.Execute("INSERT INTO `InstallExecuteSequence` (`Action`, `Condition`, `Sequence`) " + | ||
129 | "VALUES ('{0}', 'UILevel = 3', 1)", failureActionName); | ||
130 | |||
131 | productCode = db.ExecuteStringQuery("SELECT `Value` FROM `Property` WHERE `Property` = 'ProductCode'")[0]; | ||
132 | |||
133 | using (Record uiRec = new Record(5)) | ||
134 | { | ||
135 | uiRec[1] = "TestEmbeddedUI"; | ||
136 | uiRec[2] = Path.GetFileNameWithoutExtension(uiFile) + ".Wrapper.dll"; | ||
137 | uiRec[3] = 1; | ||
138 | uiRec[4] = (int)( | ||
139 | EmbeddedExternalUI.TestLogModes | | ||
140 | InstallLogModes.Progress | | ||
141 | InstallLogModes.Initialize | | ||
142 | InstallLogModes.Terminate | | ||
143 | InstallLogModes.ShowDialog); | ||
144 | uiRec.SetStream(5, Path.Combine(uiDir, uiFile)); | ||
145 | db.Execute(db.Tables["MsiEmbeddedUI"].SqlInsertString, uiRec); | ||
146 | } | ||
147 | |||
148 | db.Commit(); | ||
149 | } | ||
150 | |||
151 | Installer.SetInternalUI(InstallUIOptions.Full); | ||
152 | |||
153 | ProductInstallation installation = new ProductInstallation(productCode); | ||
154 | Assert.IsFalse(installation.IsInstalled, "Checking that product is not installed before starting."); | ||
155 | |||
156 | string logFile = "install.log"; | ||
157 | Exception caughtEx = null; | ||
158 | try | ||
159 | { | ||
160 | Installer.EnableLog(EmbeddedExternalUI.TestLogModes, logFile); | ||
161 | Installer.InstallProduct(dbFile, String.Empty); | ||
162 | } | ||
163 | catch (Exception ex) { caughtEx = ex; } | ||
164 | Assert.IsInstanceOfType(caughtEx, typeof(InstallerException), | ||
165 | "Excpected InstallerException installing product; caught: " + caughtEx); | ||
166 | |||
167 | Assert.IsFalse(installation.IsInstalled, "Checking that product is not installed."); | ||
168 | |||
169 | string logText = File.ReadAllText(logFile); | ||
170 | Assert.IsTrue(logText.Contains(magicNumber), "Checking that the type 19 custom action ran."); | ||
171 | } | ||
172 | } | ||
173 | } | ||