Files
Terminal.Gui/UnitTests/Application/SynchronizatonContextTests.cs
Tig 6851b42a49 Fixes #2921 - MainLoop refactoring (#2922)
* Adds basic MainLoop unit tests

* Remove WinChange action from Curses

* Remove WinChange action from Curses

* Remove ProcessInput action from Windows MainLoop

* Simplified MainLoop/ConsoleDriver by making MainLoop internal and moving impt fns to Application

* Modernized Terminal resize events

* Modernized Terminal resize events

* Removed un used property

* for _isWindowsTerminal devenv->wininit; not sure what changed

* Modernized mouse/keyboard events (Action->EventHandler)

* Updated OnMouseEvent API docs

* Using WT_SESSION to detect WT

* removes hacky GetParentProcess

* Updates to fix #2634 (clear last line)

* removes hacky GetParentProcess2

* Addressed mac resize issue

* Addressed mac resize issue

* Removes ConsoleDriver.PrepareToRun, has Init return MainLoop

* Removes unneeded Attribute methods

* Removed GetProcesssName

* Removed GetProcesssName

* Refactored KeyEvent and KeyEventEventArgs into a single class

* Revert "Refactored KeyEvent and KeyEventEventArgs into a single class"

This reverts commit 88a00658db.

* Fixed key repeat issue; reverted stupidity on 1049/1047 confusion

* Updated CSI API Docs

* merge
2023-10-21 08:06:04 -07:00

84 lines
1.9 KiB
C#

using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Linq;
using System.Runtime.InteropServices.ComTypes;
using System.Threading;
using System.Threading.Tasks;
using Terminal.Gui;
using Xunit;
using Xunit.Sdk;
// Alias Console to MockConsole so we don't accidentally use Console
using Console = Terminal.Gui.FakeConsole;
namespace Terminal.Gui.ApplicationTests {
public class SyncrhonizationContextTests {
[Fact, AutoInitShutdown]
public void SynchronizationContext_Post ()
{
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.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);
}
[Fact, AutoInitShutdown]
public void SynchronizationContext_Send ()
{
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.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);
}
[Fact, AutoInitShutdown]
public void SynchronizationContext_CreateCopy ()
{
var context = SynchronizationContext.Current;
Assert.NotNull (context);
var contextCopy = context.CreateCopy ();
Assert.NotNull (contextCopy);
Assert.NotEqual (context, contextCopy);
}
}
}