OverlappedTests.cs 20 KB

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