OverlappedTests.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678
  1. using System;
  2. using System.Diagnostics;
  3. using System.Linq;
  4. using System.Threading;
  5. using System.Threading.Tasks;
  6. using Terminal.Gui;
  7. using Xunit;
  8. // Alias Console to MockConsole so we don't accidentally use Console
  9. using Console = Terminal.Gui.FakeConsole;
  10. namespace Terminal.Gui.ViewsTests {
  11. public class OverlappedTests {
  12. public OverlappedTests ()
  13. {
  14. #if DEBUG_IDISPOSABLE
  15. Responder.Instances.Clear ();
  16. RunState.Instances.Clear ();
  17. #endif
  18. }
  19. [Fact, TestRespondersDisposed]
  20. public void Dispose_Toplevel_IsOverlappedContainer_False_With_Begin_End ()
  21. {
  22. Application.Init (new FakeDriver ());
  23. var top = new Toplevel ();
  24. var rs = Application.Begin (top);
  25. #if DEBUG_IDISPOSABLE
  26. Assert.Equal (4, Responder.Instances.Count);
  27. #endif
  28. Application.End (rs);
  29. Application.Shutdown ();
  30. #if DEBUG_IDISPOSABLE
  31. Assert.Empty (Responder.Instances);
  32. #endif
  33. }
  34. [Fact, TestRespondersDisposed]
  35. public void Dispose_Toplevel_IsOverlappedContainer_True_With_Begin ()
  36. {
  37. Application.Init (new FakeDriver ());
  38. var overlapped = new Toplevel { IsOverlappedContainer = true };
  39. var rs = Application.Begin (overlapped);
  40. Application.End (rs);
  41. Application.Shutdown ();
  42. }
  43. [Fact, AutoInitShutdown]
  44. public void Application_RequestStop_With_Params_On_A_Not_OverlappedContainer_Always_Use_Application_Current ()
  45. {
  46. var top1 = new Toplevel ();
  47. var top2 = new Toplevel ();
  48. var top3 = new Window ();
  49. var top4 = new Window ();
  50. var d = new Dialog ();
  51. // top1, top2, top3, d1 = 4
  52. var iterations = 4;
  53. top1.Ready += (s, e) => {
  54. Assert.Null (Application.OverlappedChildren);
  55. Application.Run (top2);
  56. };
  57. top2.Ready += (s, e) => {
  58. Assert.Null (Application.OverlappedChildren);
  59. Application.Run (top3);
  60. };
  61. top3.Ready += (s, e) => {
  62. Assert.Null (Application.OverlappedChildren);
  63. Application.Run (top4);
  64. };
  65. top4.Ready += (s, e) => {
  66. Assert.Null (Application.OverlappedChildren);
  67. Application.Run (d);
  68. };
  69. d.Ready += (s, e) => {
  70. Assert.Null (Application.OverlappedChildren);
  71. // This will close the d because on a not OverlappedContainer the Application.Current it always used.
  72. Application.RequestStop (top1);
  73. Assert.True (Application.Current == d);
  74. };
  75. d.Closed += (s, e) => Application.RequestStop (top1);
  76. Application.Iteration += (s, a) => {
  77. Assert.Null (Application.OverlappedChildren);
  78. if (iterations == 4) Assert.True (Application.Current == d);
  79. else if (iterations == 3) Assert.True (Application.Current == top4);
  80. else if (iterations == 2) Assert.True (Application.Current == top3);
  81. else if (iterations == 1) Assert.True (Application.Current == top2);
  82. else Assert.True (Application.Current == top1);
  83. Application.RequestStop (top1);
  84. iterations--;
  85. };
  86. Application.Run (top1);
  87. Assert.Null (Application.OverlappedChildren);
  88. }
  89. class Overlapped : Toplevel {
  90. public Overlapped ()
  91. {
  92. IsOverlappedContainer = true;
  93. }
  94. }
  95. [Fact]
  96. [AutoInitShutdown]
  97. public void OverlappedContainer_With_Toplevel_RequestStop_Balanced ()
  98. {
  99. var overlapped = new Overlapped ();
  100. var c1 = new Toplevel ();
  101. var c2 = new Window ();
  102. var c3 = new Window ();
  103. var d = new Dialog ();
  104. // OverlappedChild = c1, c2, c3
  105. // d1 = 1
  106. var iterations = 4;
  107. overlapped.Ready += (s, e) => {
  108. Assert.Empty (Application.OverlappedChildren);
  109. Application.Run (c1);
  110. };
  111. c1.Ready += (s, e) => {
  112. Assert.Single (Application.OverlappedChildren);
  113. Application.Run (c2);
  114. };
  115. c2.Ready += (s, e) => {
  116. Assert.Equal (2, Application.OverlappedChildren.Count);
  117. Application.Run (c3);
  118. };
  119. c3.Ready += (s, e) => {
  120. Assert.Equal (3, Application.OverlappedChildren.Count);
  121. Application.Run (d);
  122. };
  123. // More easy because the Overlapped Container handles all at once
  124. d.Ready += (s, e) => {
  125. Assert.Equal (3, Application.OverlappedChildren.Count);
  126. // This will not close the OverlappedContainer because d is a modal Toplevel and will be closed.
  127. overlapped.RequestStop ();
  128. };
  129. // Now this will close the OverlappedContainer propagating through the OverlappedChildren.
  130. d.Closed += (s, e) => {
  131. overlapped.RequestStop ();
  132. };
  133. Application.Iteration += (s, a) => {
  134. if (iterations == 4) {
  135. // The Dialog was not closed before and will be closed now.
  136. Assert.True (Application.Current == d);
  137. Assert.False (d.Running);
  138. } else {
  139. Assert.Equal (iterations, Application.OverlappedChildren.Count);
  140. for (int i = 0; i < iterations; i++) Assert.Equal ((iterations - i + 1).ToString (), Application.OverlappedChildren [i].Id);
  141. }
  142. iterations--;
  143. };
  144. Application.Run (overlapped);
  145. Assert.Empty (Application.OverlappedChildren);
  146. }
  147. [Fact]
  148. [AutoInitShutdown]
  149. public void OverlappedContainer_With_Application_RequestStop_OverlappedTop_With_Params ()
  150. {
  151. var overlapped = new Overlapped ();
  152. var c1 = new Toplevel ();
  153. var c2 = new Window ();
  154. var c3 = new Window ();
  155. var d = new Dialog ();
  156. // OverlappedChild = c1, c2, c3
  157. // d1 = 1
  158. var iterations = 4;
  159. overlapped.Ready += (s, e) => {
  160. Assert.Empty (Application.OverlappedChildren);
  161. Application.Run (c1);
  162. };
  163. c1.Ready += (s, e) => {
  164. Assert.Single (Application.OverlappedChildren);
  165. Application.Run (c2);
  166. };
  167. c2.Ready += (s, e) => {
  168. Assert.Equal (2, Application.OverlappedChildren.Count);
  169. Application.Run (c3);
  170. };
  171. c3.Ready += (s, e) => {
  172. Assert.Equal (3, Application.OverlappedChildren.Count);
  173. Application.Run (d);
  174. };
  175. // Also easy because the Overlapped Container handles all at once
  176. d.Ready += (s, e) => {
  177. Assert.Equal (3, Application.OverlappedChildren.Count);
  178. // This will not close the OverlappedContainer because d is a modal Toplevel
  179. Application.RequestStop (overlapped);
  180. };
  181. // Now this will close the OverlappedContainer propagating through the OverlappedChildren.
  182. d.Closed += (s, e) => Application.RequestStop (overlapped);
  183. Application.Iteration += (s, a) => {
  184. if (iterations == 4) {
  185. // The Dialog was not closed before and will be closed now.
  186. Assert.True (Application.Current == d);
  187. Assert.False (d.Running);
  188. } else {
  189. Assert.Equal (iterations, Application.OverlappedChildren.Count);
  190. for (int i = 0; i < iterations; i++) Assert.Equal ((iterations - i + 1).ToString (), Application.OverlappedChildren [i].Id);
  191. }
  192. iterations--;
  193. };
  194. Application.Run (overlapped);
  195. Assert.Empty (Application.OverlappedChildren);
  196. }
  197. [Fact]
  198. [AutoInitShutdown]
  199. public void OverlappedContainer_With_Application_RequestStop_OverlappedTop_Without_Params ()
  200. {
  201. var overlapped = new Overlapped ();
  202. var c1 = new Toplevel ();
  203. var c2 = new Window ();
  204. var c3 = new Window ();
  205. var d = new Dialog ();
  206. // OverlappedChild = c1, c2, c3 = 3
  207. // d1 = 1
  208. var iterations = 4;
  209. overlapped.Ready += (s, e) => {
  210. Assert.Empty (Application.OverlappedChildren);
  211. Application.Run (c1);
  212. };
  213. c1.Ready += (s, e) => {
  214. Assert.Single (Application.OverlappedChildren);
  215. Application.Run (c2);
  216. };
  217. c2.Ready += (s, e) => {
  218. Assert.Equal (2, Application.OverlappedChildren.Count);
  219. Application.Run (c3);
  220. };
  221. c3.Ready += (s, e) => {
  222. Assert.Equal (3, Application.OverlappedChildren.Count);
  223. Application.Run (d);
  224. };
  225. //More harder because it's sequential.
  226. d.Ready += (s, e) => {
  227. Assert.Equal (3, Application.OverlappedChildren.Count);
  228. // Close the Dialog
  229. Application.RequestStop ();
  230. };
  231. // Now this will close the OverlappedContainer propagating through the OverlappedChildren.
  232. d.Closed += (s, e) => Application.RequestStop (overlapped);
  233. Application.Iteration += (s, a) => {
  234. if (iterations == 4) {
  235. // The Dialog still is the current top and we can't request stop to OverlappedContainer
  236. // because we are not using parameter calls.
  237. Assert.True (Application.Current == d);
  238. Assert.False (d.Running);
  239. } else {
  240. Assert.Equal (iterations, Application.OverlappedChildren.Count);
  241. for (int i = 0; i < iterations; i++) Assert.Equal ((iterations - i + 1).ToString (), Application.OverlappedChildren [i].Id);
  242. }
  243. iterations--;
  244. };
  245. Application.Run (overlapped);
  246. Assert.Empty (Application.OverlappedChildren);
  247. }
  248. [Fact]
  249. [AutoInitShutdown]
  250. public void IsOverlappedChild_Testing ()
  251. {
  252. var overlapped = new Overlapped ();
  253. var c1 = new Toplevel ();
  254. var c2 = new Window ();
  255. var c3 = new Window ();
  256. var d = new Dialog ();
  257. Application.Iteration += (s, a) => {
  258. Assert.False (overlapped.IsOverlapped);
  259. Assert.True (c1.IsOverlapped);
  260. Assert.True (c2.IsOverlapped);
  261. Assert.True (c3.IsOverlapped);
  262. Assert.False (d.IsOverlapped);
  263. overlapped.RequestStop ();
  264. };
  265. Application.Run (overlapped);
  266. }
  267. [Fact]
  268. [AutoInitShutdown]
  269. public void Modal_Toplevel_Can_Open_Another_Modal_Toplevel_But_RequestStop_To_The_Caller_Also_Sets_Current_Running_To_False_Too ()
  270. {
  271. var overlapped = new Overlapped ();
  272. var c1 = new Toplevel ();
  273. var c2 = new Window ();
  274. var c3 = new Window ();
  275. var d1 = new Dialog ();
  276. var d2 = new Dialog ();
  277. // OverlappedChild = c1, c2, c3 = 3
  278. // d1, d2 = 2
  279. var iterations = 5;
  280. overlapped.Ready += (s, e) => {
  281. Assert.Empty (Application.OverlappedChildren);
  282. Application.Run (c1);
  283. };
  284. c1.Ready += (s, e) => {
  285. Assert.Single (Application.OverlappedChildren);
  286. Application.Run (c2);
  287. };
  288. c2.Ready += (s, e) => {
  289. Assert.Equal (2, Application.OverlappedChildren.Count);
  290. Application.Run (c3);
  291. };
  292. c3.Ready += (s, e) => {
  293. Assert.Equal (3, Application.OverlappedChildren.Count);
  294. Application.Run (d1);
  295. };
  296. d1.Ready += (s, e) => {
  297. Assert.Equal (3, Application.OverlappedChildren.Count);
  298. Application.Run (d2);
  299. };
  300. d2.Ready += (s, e) => {
  301. Assert.Equal (3, Application.OverlappedChildren.Count);
  302. Assert.True (Application.Current == d2);
  303. Assert.True (Application.Current.Running);
  304. // Trying to close the Dialog1
  305. d1.RequestStop ();
  306. };
  307. // Now this will close the OverlappedContainer propagating through the OverlappedChildren.
  308. d1.Closed += (s, e) => {
  309. Assert.True (Application.Current == d1);
  310. Assert.False (Application.Current.Running);
  311. overlapped.RequestStop ();
  312. };
  313. Application.Iteration += (s, a) => {
  314. if (iterations == 5) {
  315. // The Dialog2 still is the current top and we can't request stop to OverlappedContainer
  316. // because Dialog2 and Dialog1 must be closed first.
  317. // Dialog2 will be closed in this iteration.
  318. Assert.True (Application.Current == d2);
  319. Assert.False (Application.Current.Running);
  320. Assert.False (d1.Running);
  321. } else if (iterations == 4) {
  322. // Dialog1 will be closed in this iteration.
  323. Assert.True (Application.Current == d1);
  324. Assert.False (Application.Current.Running);
  325. } else {
  326. Assert.Equal (iterations, Application.OverlappedChildren.Count);
  327. for (int i = 0; i < iterations; i++) Assert.Equal ((iterations - i + 1).ToString (), Application.OverlappedChildren [i].Id);
  328. }
  329. iterations--;
  330. };
  331. Application.Run (overlapped);
  332. Assert.Empty (Application.OverlappedChildren);
  333. }
  334. [Fact]
  335. [AutoInitShutdown]
  336. public void Modal_Toplevel_Can_Open_Another_Not_Modal_Toplevel_But_RequestStop_To_The_Caller_Also_Sets_Current_Running_To_False_Too ()
  337. {
  338. var overlapped = new Overlapped ();
  339. var c1 = new Toplevel ();
  340. var c2 = new Window ();
  341. var c3 = new Window ();
  342. var d1 = new Dialog ();
  343. var c4 = new Toplevel ();
  344. // OverlappedChild = c1, c2, c3, c4 = 4
  345. // d1 = 1
  346. var iterations = 5;
  347. overlapped.Ready += (s, e) => {
  348. Assert.Empty (Application.OverlappedChildren);
  349. Application.Run (c1);
  350. };
  351. c1.Ready += (s, e) => {
  352. Assert.Single (Application.OverlappedChildren);
  353. Application.Run (c2);
  354. };
  355. c2.Ready += (s, e) => {
  356. Assert.Equal (2, Application.OverlappedChildren.Count);
  357. Application.Run (c3);
  358. };
  359. c3.Ready += (s, e) => {
  360. Assert.Equal (3, Application.OverlappedChildren.Count);
  361. Application.Run (d1);
  362. };
  363. d1.Ready += (s, e) => {
  364. Assert.Equal (3, Application.OverlappedChildren.Count);
  365. Application.Run (c4);
  366. };
  367. c4.Ready += (s, e) => {
  368. Assert.Equal (4, Application.OverlappedChildren.Count);
  369. // Trying to close the Dialog1
  370. d1.RequestStop ();
  371. };
  372. // Now this will close the OverlappedContainer propagating through the OverlappedChildren.
  373. d1.Closed += (s, e) => {
  374. overlapped.RequestStop ();
  375. };
  376. Application.Iteration += (s, a) => {
  377. if (iterations == 5) {
  378. // The Dialog2 still is the current top and we can't request stop to OverlappedContainer
  379. // because Dialog2 and Dialog1 must be closed first.
  380. // Using request stop here will call the Dialog again without need
  381. Assert.True (Application.Current == d1);
  382. Assert.False (Application.Current.Running);
  383. Assert.True (c4.Running);
  384. } else {
  385. Assert.Equal (iterations, Application.OverlappedChildren.Count);
  386. for (int i = 0; i < iterations; i++) Assert.Equal ((iterations - i + (iterations == 4 && i == 0 ? 2 : 1)).ToString (),
  387. Application.OverlappedChildren [i].Id);
  388. }
  389. iterations--;
  390. };
  391. Application.Run (overlapped);
  392. Assert.Empty (Application.OverlappedChildren);
  393. }
  394. [Fact]
  395. [AutoInitShutdown]
  396. public void MoveCurrent_Returns_False_If_The_Current_And_Top_Parameter_Are_Both_With_Running_Set_To_False ()
  397. {
  398. var overlapped = new Overlapped ();
  399. var c1 = new Toplevel ();
  400. var c2 = new Window ();
  401. var c3 = new Window ();
  402. // OverlappedChild = c1, c2, c3
  403. var iterations = 3;
  404. overlapped.Ready += (s, e) => {
  405. Assert.Empty (Application.OverlappedChildren);
  406. Application.Run (c1);
  407. };
  408. c1.Ready += (s, e) => {
  409. Assert.Single (Application.OverlappedChildren);
  410. Application.Run (c2);
  411. };
  412. c2.Ready += (s, e) => {
  413. Assert.Equal (2, Application.OverlappedChildren.Count);
  414. Application.Run (c3);
  415. };
  416. c3.Ready += (s, e) => {
  417. Assert.Equal (3, Application.OverlappedChildren.Count);
  418. c3.RequestStop ();
  419. c1.RequestStop ();
  420. };
  421. // Now this will close the OverlappedContainer propagating through the OverlappedChildren.
  422. c1.Closed += (s, e) => {
  423. overlapped.RequestStop ();
  424. };
  425. Application.Iteration += (s, a) => {
  426. if (iterations == 3) {
  427. // The Current still is c3 because Current.Running is false.
  428. Assert.True (Application.Current == c3);
  429. Assert.False (Application.Current.Running);
  430. // But the Children order were reorder by Running = false
  431. Assert.True (Application.OverlappedChildren [0] == c3);
  432. Assert.True (Application.OverlappedChildren [1] == c1);
  433. Assert.True (Application.OverlappedChildren [^1] == c2);
  434. } else if (iterations == 2) {
  435. // The Current is c1 and Current.Running is false.
  436. Assert.True (Application.Current == c1);
  437. Assert.False (Application.Current.Running);
  438. Assert.True (Application.OverlappedChildren [0] == c1);
  439. Assert.True (Application.OverlappedChildren [^1] == c2);
  440. } else if (iterations == 1) {
  441. // The Current is c2 and Current.Running is false.
  442. Assert.True (Application.Current == c2);
  443. Assert.False (Application.Current.Running);
  444. Assert.True (Application.OverlappedChildren [^1] == c2);
  445. } else {
  446. // The Current is overlapped.
  447. Assert.True (Application.Current == overlapped);
  448. Assert.Empty (Application.OverlappedChildren);
  449. }
  450. iterations--;
  451. };
  452. Application.Run (overlapped);
  453. Assert.Empty (Application.OverlappedChildren);
  454. }
  455. [Fact]
  456. [AutoInitShutdown]
  457. public void OverlappedContainer_Throws_If_More_Than_One ()
  458. {
  459. var overlapped = new Overlapped ();
  460. var overlapped2 = new Overlapped ();
  461. overlapped.Ready += (s, e) => {
  462. Assert.Throws<InvalidOperationException> (() => Application.Run (overlapped2));
  463. overlapped.RequestStop ();
  464. };
  465. Application.Run (overlapped);
  466. }
  467. [Fact]
  468. [AutoInitShutdown]
  469. public void OverlappedContainer_Open_And_Close_Modal_And_Open_Not_Modal_Toplevels_Randomly ()
  470. {
  471. var overlapped = new Overlapped ();
  472. var logger = new Toplevel ();
  473. var iterations = 1; // The logger
  474. var running = true;
  475. var stageCompleted = true;
  476. var allStageClosed = false;
  477. var overlappedRequestStop = false;
  478. overlapped.Ready += (s, e) => {
  479. Assert.Empty (Application.OverlappedChildren);
  480. Application.Run (logger);
  481. };
  482. logger.Ready += (s, e) => Assert.Single (Application.OverlappedChildren);
  483. Application.Iteration += (s, a) => {
  484. if (stageCompleted && running) {
  485. stageCompleted = false;
  486. var stage = new Window () { Modal = true };
  487. stage.Ready += (s, e) => {
  488. Assert.Equal (iterations, Application.OverlappedChildren.Count);
  489. stage.RequestStop ();
  490. };
  491. stage.Closed += (_, _) => {
  492. if (iterations == 11) allStageClosed = true;
  493. Assert.Equal (iterations, Application.OverlappedChildren.Count);
  494. if (running) {
  495. stageCompleted = true;
  496. var rpt = new Window ();
  497. rpt.Ready += (s, e) => {
  498. iterations++;
  499. Assert.Equal (iterations, Application.OverlappedChildren.Count);
  500. };
  501. Application.Run (rpt);
  502. }
  503. };
  504. Application.Run (stage);
  505. } else if (iterations == 11 && running) {
  506. running = false;
  507. Assert.Equal (iterations, Application.OverlappedChildren.Count);
  508. } else if (!overlappedRequestStop && running && !allStageClosed) Assert.Equal (iterations, Application.OverlappedChildren.Count);
  509. else if (!overlappedRequestStop && !running && allStageClosed) {
  510. Assert.Equal (iterations, Application.OverlappedChildren.Count);
  511. overlappedRequestStop = true;
  512. overlapped.RequestStop ();
  513. } else Assert.Empty (Application.OverlappedChildren);
  514. };
  515. Application.Run (overlapped);
  516. Assert.Empty (Application.OverlappedChildren);
  517. }
  518. [Fact]
  519. [AutoInitShutdown]
  520. public void AllChildClosed_Event_Test ()
  521. {
  522. var overlapped = new Overlapped ();
  523. var c1 = new Toplevel ();
  524. var c2 = new Window ();
  525. var c3 = new Window ();
  526. // OverlappedChild = c1, c2, c3
  527. var iterations = 3;
  528. overlapped.Ready += (s, e) => {
  529. Assert.Empty (Application.OverlappedChildren);
  530. Application.Run (c1);
  531. };
  532. c1.Ready += (s, e) => {
  533. Assert.Single (Application.OverlappedChildren);
  534. Application.Run (c2);
  535. };
  536. c2.Ready += (s, e) => {
  537. Assert.Equal (2, Application.OverlappedChildren.Count);
  538. Application.Run (c3);
  539. };
  540. c3.Ready += (s, e) => {
  541. Assert.Equal (3, Application.OverlappedChildren.Count);
  542. c3.RequestStop ();
  543. c2.RequestStop ();
  544. c1.RequestStop ();
  545. };
  546. // Now this will close the OverlappedContainer when all OverlappedChildren was closed
  547. overlapped.AllChildClosed += (s, e) => {
  548. overlapped.RequestStop ();
  549. };
  550. Application.Iteration += (s, a) => {
  551. if (iterations == 3) {
  552. // The Current still is c3 because Current.Running is false.
  553. Assert.True (Application.Current == c3);
  554. Assert.False (Application.Current.Running);
  555. // But the Children order were reorder by Running = false
  556. Assert.True (Application.OverlappedChildren [0] == c3);
  557. Assert.True (Application.OverlappedChildren [1] == c2);
  558. Assert.True (Application.OverlappedChildren [^1] == c1);
  559. } else if (iterations == 2) {
  560. // The Current is c2 and Current.Running is false.
  561. Assert.True (Application.Current == c2);
  562. Assert.False (Application.Current.Running);
  563. Assert.True (Application.OverlappedChildren [0] == c2);
  564. Assert.True (Application.OverlappedChildren [^1] == c1);
  565. } else if (iterations == 1) {
  566. // The Current is c1 and Current.Running is false.
  567. Assert.True (Application.Current == c1);
  568. Assert.False (Application.Current.Running);
  569. Assert.True (Application.OverlappedChildren [^1] == c1);
  570. } else {
  571. // The Current is overlapped.
  572. Assert.True (Application.Current == overlapped);
  573. Assert.False (Application.Current.Running);
  574. Assert.Empty (Application.OverlappedChildren);
  575. }
  576. iterations--;
  577. };
  578. Application.Run (overlapped);
  579. Assert.Empty (Application.OverlappedChildren);
  580. }
  581. [Fact]
  582. public void MoveToOverlappedChild_Throw_NullReferenceException_Passing_Null_Parameter ()
  583. {
  584. Assert.Throws<NullReferenceException> (delegate { Application.MoveToOverlappedChild (null); });
  585. }
  586. }
  587. }