Browse Source

Merge pull request #849 from BDisp/multi-thread-toplevels-test

Providing a simple test for Fixes #740. Multi thread toplevels.
Charlie Kindel 5 năm trước cách đây
mục cha
commit
a07da67a2c
1 tập tin đã thay đổi với 100 bổ sung0 xóa
  1. 100 0
      UnitTests/ViewTests.cs

+ 100 - 0
UnitTests/ViewTests.cs

@@ -899,5 +899,105 @@ namespace Terminal.Gui {
 			Application.Run ();
 			Application.Shutdown ();
 		}
+
+		[Fact]
+		public void Multi_Thread_Toplevels ()
+		{
+			Application.Init (new FakeDriver (), new NetMainLoop (() => FakeConsole.ReadKey (true)));
+
+			var t = Application.Top;
+			var w = new Window ();
+			t.Add (w);
+
+			int count = 0, count1 = 0, count2 = 0;
+			bool log = false, log1 = false, log2 = false;
+			bool fromTopStillKnowFirstIsRunning = false;
+			bool fromTopStillKnowSecondIsRunning = false;
+			bool fromFirstStillKnowSecondIsRunning = false;
+
+			Application.MainLoop.AddTimeout (TimeSpan.FromMilliseconds (100), (_) => {
+				count++;
+				if (count1 == 5) {
+					log1 = true;
+				}
+				if (count1 > 13 && count < 15) {
+					fromTopStillKnowFirstIsRunning = true;
+				}
+				if (count2 > 6 && count2 < 8) {
+					fromTopStillKnowSecondIsRunning = true;
+				}
+				if (count == 30) {
+					Assert.Equal (30, count);
+					Assert.Equal (20, count1);
+					Assert.Equal (10, count2);
+
+					Assert.True (log);
+					Assert.True (log1);
+					Assert.True (log2);
+
+					Assert.True (fromTopStillKnowFirstIsRunning);
+					Assert.True (fromTopStillKnowSecondIsRunning);
+					Assert.True (fromFirstStillKnowSecondIsRunning);
+
+					Application.RequestStop ();
+					return false;
+				}
+				return true;
+			});
+
+			t.Ready = () => {
+				FirstDialogToplevel ();
+			};
+
+			void FirstDialogToplevel ()
+			{
+				var od = new OpenDialog {
+					Ready = () => {
+						SecoundDialogToplevel ();
+					}
+				};
+
+				Application.MainLoop.AddTimeout (TimeSpan.FromMilliseconds (100), (_) => {
+					count1++;
+					if (count2 == 5) {
+						log2 = true;
+					}
+					if (count2 > 3 && count2 < 5) {
+						fromFirstStillKnowSecondIsRunning = true;
+					}
+					if (count1 == 20) {
+						Assert.Equal (20, count1);
+						Application.RequestStop ();
+						return false;
+					}
+					return true;
+				});
+
+				Application.Run (od);
+			}
+
+			void SecoundDialogToplevel ()
+			{
+				var d = new Dialog ();
+
+				Application.MainLoop.AddTimeout (TimeSpan.FromMilliseconds (100), (_) => {
+					count2++;
+					if (count < 30) {
+						log = true;
+					}
+					if (count2 == 10) {
+						Assert.Equal (10, count2);
+						Application.RequestStop ();
+						return false;
+					}
+					return true;
+				});
+
+				Application.Run (d);
+			}
+
+			Application.Run ();
+			Application.Shutdown ();
+		}
 	}
 }