|
@@ -84,6 +84,7 @@ namespace Terminal.Gui.Core {
|
|
Application.Init (new FakeDriver (), new FakeMainLoop (() => FakeConsole.ReadKey (true)));
|
|
Application.Init (new FakeDriver (), new FakeMainLoop (() => FakeConsole.ReadKey (true)));
|
|
Assert.NotNull (Application.Driver);
|
|
Assert.NotNull (Application.Driver);
|
|
Assert.NotNull (Application.MainLoop);
|
|
Assert.NotNull (Application.MainLoop);
|
|
|
|
+ Assert.NotNull (SynchronizationContext.Current);
|
|
}
|
|
}
|
|
|
|
|
|
void Shutdown ()
|
|
void Shutdown ()
|
|
@@ -1335,5 +1336,77 @@ namespace Terminal.Gui.Core {
|
|
Assert.True (delegatesRun >= numberOfThreads * numberOfTimeoutsPerThread * 2);
|
|
Assert.True (delegatesRun >= numberOfThreads * numberOfTimeoutsPerThread * 2);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ [Fact]
|
|
|
|
+ public void SynchronizationContext_Post ()
|
|
|
|
+ {
|
|
|
|
+ Init ();
|
|
|
|
+ var context = SynchronizationContext.Current;
|
|
|
|
+
|
|
|
|
+ var success = false;
|
|
|
|
+ Task.Run (() => {
|
|
|
|
+ Thread.Sleep (1_000);
|
|
|
|
+
|
|
|
|
+ // non blocking
|
|
|
|
+ context.Post (
|
|
|
|
+ delegate (object o) {
|
|
|
|
+ success = true;
|
|
|
|
+
|
|
|
|
+ // then tell the application to quit
|
|
|
|
+ Application.MainLoop.Invoke (() => Application.RequestStop ());
|
|
|
|
+ }, null);
|
|
|
|
+ Assert.False (success);
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ // blocks here until the RequestStop is processed at the end of the test
|
|
|
|
+ Application.Run ();
|
|
|
|
+ Assert.True (success);
|
|
|
|
+
|
|
|
|
+ Application.Shutdown ();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ [Fact]
|
|
|
|
+ public void SynchronizationContext_Send ()
|
|
|
|
+ {
|
|
|
|
+ Init ();
|
|
|
|
+ var context = SynchronizationContext.Current;
|
|
|
|
+
|
|
|
|
+ var success = false;
|
|
|
|
+ Task.Run (() => {
|
|
|
|
+ Thread.Sleep (1_000);
|
|
|
|
+
|
|
|
|
+ // blocking
|
|
|
|
+ context.Send (
|
|
|
|
+ delegate (object o) {
|
|
|
|
+ success = true;
|
|
|
|
+
|
|
|
|
+ // then tell the application to quit
|
|
|
|
+ Application.MainLoop.Invoke (() => Application.RequestStop ());
|
|
|
|
+ }, null);
|
|
|
|
+ Assert.True (success);
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ // blocks here until the RequestStop is processed at the end of the test
|
|
|
|
+ Application.Run ();
|
|
|
|
+ Assert.True (success);
|
|
|
|
+
|
|
|
|
+ Application.Shutdown ();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ [Fact]
|
|
|
|
+ public void SynchronizationContext_CreateCopy ()
|
|
|
|
+ {
|
|
|
|
+ Init ();
|
|
|
|
+
|
|
|
|
+ var context = SynchronizationContext.Current;
|
|
|
|
+ Assert.NotNull (context);
|
|
|
|
+
|
|
|
|
+ var contextCopy = context.CreateCopy ();
|
|
|
|
+ Assert.NotNull (contextCopy);
|
|
|
|
+
|
|
|
|
+ Assert.NotEqual (context, contextCopy);
|
|
|
|
+
|
|
|
|
+ Application.Shutdown ();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|