aboutsummaryrefslogtreecommitdiff
path: root/src/Utilities/TestBA/TestBA.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Utilities/TestBA/TestBA.cs')
-rw-r--r--src/Utilities/TestBA/TestBA.cs82
1 files changed, 62 insertions, 20 deletions
diff --git a/src/Utilities/TestBA/TestBA.cs b/src/Utilities/TestBA/TestBA.cs
index c68c2b61..1348ce98 100644
--- a/src/Utilities/TestBA/TestBA.cs
+++ b/src/Utilities/TestBA/TestBA.cs
@@ -18,14 +18,17 @@ namespace WixToolset.Test.BA
18 { 18 {
19 private const string BurnBundleVersionVariable = "WixBundleVersion"; 19 private const string BurnBundleVersionVariable = "WixBundleVersion";
20 20
21 private ApplicationContext appContext;
22 private Form dummyWindow; 21 private Form dummyWindow;
22 private IntPtr windowHandle;
23 private LaunchAction action; 23 private LaunchAction action;
24 private ManualResetEvent wait;
24 private int result; 25 private int result;
25 26
26 private string updateBundlePath; 27 private string updateBundlePath;
27 28
28 private int redetectCount; 29 private bool immediatelyQuit;
30 private bool quitAfterDetect;
31 private int redetectRemaining;
29 private int sleepDuringCache; 32 private int sleepDuringCache;
30 private int cancelCacheAtProgress; 33 private int cancelCacheAtProgress;
31 private int sleepDuringExecute; 34 private int sleepDuringExecute;
@@ -45,6 +48,7 @@ namespace WixToolset.Test.BA
45 : base(engine) 48 : base(engine)
46 { 49 {
47 this.Command = bootstrapperCommand; 50 this.Command = bootstrapperCommand;
51 this.wait = new ManualResetEvent(false);
48 } 52 }
49 53
50 /// <summary> 54 /// <summary>
@@ -60,8 +64,17 @@ namespace WixToolset.Test.BA
60 /// <summary> 64 /// <summary>
61 /// UI Thread entry point for TestUX. 65 /// UI Thread entry point for TestUX.
62 /// </summary> 66 /// </summary>
63 protected override void Run() 67 protected override void OnStartup(StartupEventArgs args)
64 { 68 {
69 string immediatelyQuit = this.ReadPackageAction(null, "ImmediatelyQuit");
70 if (!String.IsNullOrEmpty(immediatelyQuit) && Boolean.TryParse(immediatelyQuit, out this.immediatelyQuit) && this.immediatelyQuit)
71 {
72 this.Engine.Quit(0);
73 return;
74 }
75
76 base.OnStartup(args);
77
65 this.action = this.Command.Action; 78 this.action = this.Command.Action;
66 this.TestVariables(); 79 this.TestVariables();
67 80
@@ -102,20 +115,46 @@ namespace WixToolset.Test.BA
102 return; 115 return;
103 } 116 }
104 117
105 this.dummyWindow = new Form(); 118 int redetectCount;
106 this.dummyWindow.CreateControl();
107 this.appContext = new ApplicationContext();
108
109 this.redetectCount = 0;
110 string redetect = this.ReadPackageAction(null, "RedetectCount"); 119 string redetect = this.ReadPackageAction(null, "RedetectCount");
111 if (String.IsNullOrEmpty(redetect) || !Int32.TryParse(redetect, out this.redetectCount)) 120 if (String.IsNullOrEmpty(redetect) || !Int32.TryParse(redetect, out redetectCount))
121 {
122 redetectCount = 0;
123 }
124
125 string quitAfterDetect = this.ReadPackageAction(null, "QuitAfterDetect");
126 if (String.IsNullOrEmpty(quitAfterDetect) || !Boolean.TryParse(quitAfterDetect, out this.quitAfterDetect))
112 { 127 {
113 this.redetectCount = 0; 128 this.quitAfterDetect = false;
114 } 129 }
115 130
116 this.Engine.Detect(); 131 this.wait.WaitOne();
132
133 this.redetectRemaining = redetectCount;
134 for (int i = -1; i < redetectCount; i++)
135 {
136 this.Engine.Detect(this.windowHandle);
137 }
138 }
139
140 protected override void Run()
141 {
142 this.dummyWindow = new Form();
143 this.windowHandle = this.dummyWindow.Handle;
144
145 this.Log("Running TestBA application");
146 this.wait.Set();
147 Application.Run();
148 }
149
150 private void ShutdownUiThread()
151 {
152 if (this.dummyWindow != null)
153 {
154 this.dummyWindow.Invoke(new Action(Application.ExitThread));
155 this.dummyWindow.Dispose();
156 }
117 157
118 Application.Run(this.appContext);
119 this.Engine.Quit(this.result & 0xFFFF); // return plain old Win32 error, not HRESULT. 158 this.Engine.Quit(this.result & 0xFFFF); // return plain old Win32 error, not HRESULT.
120 } 159 }
121 160
@@ -167,10 +206,13 @@ namespace WixToolset.Test.BA
167 if (Hresult.Succeeded(this.result) && 206 if (Hresult.Succeeded(this.result) &&
168 (this.UpdateAvailable || LaunchAction.UpdateReplaceEmbedded != this.action && LaunchAction.UpdateReplace != this.action)) 207 (this.UpdateAvailable || LaunchAction.UpdateReplaceEmbedded != this.action && LaunchAction.UpdateReplace != this.action))
169 { 208 {
170 if (this.redetectCount > 0) 209 if (this.redetectRemaining > 0)
210 {
211 this.Log("Completed detection phase: {0} re-runs remaining", this.redetectRemaining--);
212 }
213 else if (this.quitAfterDetect)
171 { 214 {
172 this.Log("Completed detection phase: {0} re-runs remaining", this.redetectCount--); 215 this.ShutdownUiThread();
173 this.Engine.Detect();
174 } 216 }
175 else 217 else
176 { 218 {
@@ -179,7 +221,7 @@ namespace WixToolset.Test.BA
179 } 221 }
180 else 222 else
181 { 223 {
182 this.appContext.ExitThread(); 224 this.ShutdownUiThread();
183 } 225 }
184 } 226 }
185 227
@@ -218,11 +260,11 @@ namespace WixToolset.Test.BA
218 this.result = args.Status; 260 this.result = args.Status;
219 if (Hresult.Succeeded(this.result)) 261 if (Hresult.Succeeded(this.result))
220 { 262 {
221 this.Engine.Apply(this.dummyWindow.Handle); 263 this.Engine.Apply(this.windowHandle);
222 } 264 }
223 else 265 else
224 { 266 {
225 this.appContext.ExitThread(); 267 this.ShutdownUiThread();
226 } 268 }
227 } 269 }
228 270
@@ -402,7 +444,7 @@ namespace WixToolset.Test.BA
402 this.Log("After elevation: WixBundleElevated = {0}", this.Engine.GetVariableNumeric("WixBundleElevated")); 444 this.Log("After elevation: WixBundleElevated = {0}", this.Engine.GetVariableNumeric("WixBundleElevated"));
403 445
404 this.result = args.Status; 446 this.result = args.Status;
405 this.appContext.ExitThread(); 447 this.ShutdownUiThread();
406 } 448 }
407 449
408 protected override void OnSystemShutdown(SystemShutdownEventArgs args) 450 protected override void OnSystemShutdown(SystemShutdownEventArgs args)
@@ -411,7 +453,7 @@ namespace WixToolset.Test.BA
411 this.Log("Disallowed system request to shut down the bootstrapper application."); 453 this.Log("Disallowed system request to shut down the bootstrapper application.");
412 args.Cancel = true; 454 args.Cancel = true;
413 455
414 this.appContext.ExitThread(); 456 this.ShutdownUiThread();
415 } 457 }
416 458
417 private void TestVariables() 459 private void TestVariables()