mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-26 07:47:54 +01:00
* Initial plan * Migrate Category A test files to UnitTests.Parallelizable (135 tests) Co-authored-by: tig <585482+tig@users.noreply.github.com> * Add 11 ButtonTests to Parallelizable, remove from UnitTests Co-authored-by: tig <585482+tig@users.noreply.github.com> * Add comprehensive test migration report Co-authored-by: tig <585482+tig@users.noreply.github.com> * Add comprehensive performance analysis of UnitTests Co-authored-by: tig <585482+tig@users.noreply.github.com> * Migrate 2 Autocomplete tests and add Text tests analysis Co-authored-by: tig <585482+tig@users.noreply.github.com> * Add proof-of-concept: TextFormatter.Draw works in parallel tests with local driver Co-authored-by: tig <585482+tig@users.noreply.github.com> * Add CreateFakeDriver helper to ParallelizableBase and migrate 4 TextFormatterTests Co-authored-by: tig <585482+tig@users.noreply.github.com> * Remove proof-of-concept test from AutocompleteTests Co-authored-by: tig <585482+tig@users.noreply.github.com> * Move Scheme-accessing tests back to UnitTests to fix intermittent failures Co-authored-by: tig <585482+tig@users.noreply.github.com> * Update parallel tests README to document ConfigurationManager/SchemeManager restrictions Co-authored-by: tig <585482+tig@users.noreply.github.com> * Document static member restriction in parallel tests README Co-authored-by: tig <585482+tig@users.noreply.github.com> * Restore accidentally deleted ButtonTests.Accept_Cancel_Event_OnAccept_Returns_True test Co-authored-by: tig <585482+tig@users.noreply.github.com> * Migrate Accept_Cancel_Event_OnAccept_Returns_True test to Parallelizable Co-authored-by: tig <585482+tig@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: tig <585482+tig@users.noreply.github.com>
301 lines
12 KiB
C#
301 lines
12 KiB
C#
using Xunit.Abstractions;
|
|
|
|
// Alias Console to MockConsole so we don't accidentally use Console
|
|
|
|
namespace Terminal.Gui.DriverTests;
|
|
|
|
public class MainLoopDriverTests : UnitTests.Parallelizable.ParallelizableBase
|
|
{
|
|
public MainLoopDriverTests (ITestOutputHelper output) { ConsoleDriver.RunningUnitTests = true; }
|
|
|
|
[Theory]
|
|
[InlineData (typeof (FakeDriver), typeof (FakeMainLoop))]
|
|
//[InlineData (typeof (DotNetDriver), typeof (NetMainLoop))]
|
|
//[InlineData (typeof (UnixDriver), typeof (UnixMainLoop))]
|
|
//[InlineData (typeof (WindowsDriver), typeof (WindowsMainLoop))]
|
|
|
|
//[InlineData (typeof (ANSIDriver), typeof (AnsiMainLoopDriver))]
|
|
public void MainLoop_AddTimeout_ValidIdleHandler_ReturnsToken (Type driverType, Type mainLoopDriverType)
|
|
{
|
|
var driver = (IConsoleDriver)Activator.CreateInstance (driverType);
|
|
var mainLoopDriver = (IMainLoopDriver)Activator.CreateInstance (mainLoopDriverType, driver);
|
|
var mainLoop = new MainLoop (mainLoopDriver);
|
|
var idleHandlerInvoked = false;
|
|
|
|
bool IdleHandler ()
|
|
{
|
|
idleHandlerInvoked = true;
|
|
|
|
return false;
|
|
}
|
|
|
|
var token = mainLoop.TimedEvents.Add(TimeSpan.Zero, IdleHandler);
|
|
|
|
Assert.NotNull (token);
|
|
Assert.False (idleHandlerInvoked); // Idle handler should not be invoked immediately
|
|
mainLoop.RunIteration (); // Run an iteration to process the idle handler
|
|
Assert.True (idleHandlerInvoked); // Idle handler should be invoked after processing
|
|
mainLoop.Dispose ();
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData (typeof (FakeDriver), typeof (FakeMainLoop))]
|
|
//[InlineData (typeof (DotNetDriver), typeof (NetMainLoop))]
|
|
//[InlineData (typeof (UnixDriver), typeof (UnixMainLoop))]
|
|
//[InlineData (typeof (WindowsDriver), typeof (WindowsMainLoop))]
|
|
|
|
//[InlineData (typeof (ANSIDriver), typeof (AnsiMainLoopDriver))]
|
|
public void MainLoop_AddTimeout_ValidParameters_ReturnsToken (Type driverType, Type mainLoopDriverType)
|
|
{
|
|
var driver = (IConsoleDriver)Activator.CreateInstance (driverType);
|
|
var mainLoopDriver = (IMainLoopDriver)Activator.CreateInstance (mainLoopDriverType, driver);
|
|
var mainLoop = new MainLoop (mainLoopDriver);
|
|
var callbackInvoked = false;
|
|
|
|
object token = mainLoop.TimedEvents.Add (
|
|
TimeSpan.FromMilliseconds (100),
|
|
() =>
|
|
{
|
|
callbackInvoked = true;
|
|
|
|
return false;
|
|
}
|
|
);
|
|
|
|
Assert.NotNull (token);
|
|
mainLoop.RunIteration (); // Run an iteration to process the timeout
|
|
Assert.False (callbackInvoked); // Callback should not be invoked immediately
|
|
Thread.Sleep (200); // Wait for the timeout
|
|
mainLoop.RunIteration (); // Run an iteration to process the timeout
|
|
Assert.True (callbackInvoked); // Callback should be invoked after the timeout
|
|
mainLoop.Dispose ();
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData (typeof (FakeDriver), typeof (FakeMainLoop))]
|
|
//[InlineData (typeof (DotNetDriver), typeof (NetMainLoop))]
|
|
//[InlineData (typeof (UnixDriver), typeof (UnixMainLoop))]
|
|
//[InlineData (typeof (WindowsDriver), typeof (WindowsMainLoop))]
|
|
|
|
//[InlineData (typeof (ANSIDriver), typeof (AnsiMainLoopDriver))]
|
|
public void MainLoop_CheckTimersAndIdleHandlers_IdleHandlersActive_ReturnsTrue (
|
|
Type driverType,
|
|
Type mainLoopDriverType
|
|
)
|
|
{
|
|
var driver = (IConsoleDriver)Activator.CreateInstance (driverType);
|
|
var mainLoopDriver = (IMainLoopDriver)Activator.CreateInstance (mainLoopDriverType, driver);
|
|
var mainLoop = new MainLoop (mainLoopDriver);
|
|
|
|
mainLoop.TimedEvents.Add (TimeSpan.Zero, () => false);
|
|
bool result = mainLoop.TimedEvents.CheckTimers (out int waitTimeout);
|
|
|
|
Assert.True (result);
|
|
Assert.Equal (0, waitTimeout);
|
|
mainLoop.Dispose ();
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData (typeof (FakeDriver), typeof (FakeMainLoop))]
|
|
//[InlineData (typeof (DotNetDriver), typeof (NetMainLoop))]
|
|
//[InlineData (typeof (UnixDriver), typeof (UnixMainLoop))]
|
|
//[InlineData (typeof (WindowsDriver), typeof (WindowsMainLoop))]
|
|
|
|
//[InlineData (typeof (ANSIDriver), typeof (AnsiMainLoopDriver))]
|
|
public void MainLoop_CheckTimers_NoTimersOrIdleHandlers_ReturnsFalse (
|
|
Type driverType,
|
|
Type mainLoopDriverType
|
|
)
|
|
{
|
|
var driver = (IConsoleDriver)Activator.CreateInstance (driverType);
|
|
var mainLoopDriver = (IMainLoopDriver)Activator.CreateInstance (mainLoopDriverType, driver);
|
|
var mainLoop = new MainLoop (mainLoopDriver);
|
|
|
|
bool result = mainLoop.TimedEvents.CheckTimers (out int waitTimeout);
|
|
|
|
Assert.False (result);
|
|
Assert.Equal (-1, waitTimeout);
|
|
mainLoop.Dispose ();
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData (typeof (FakeDriver), typeof (FakeMainLoop))]
|
|
//[InlineData (typeof (DotNetDriver), typeof (NetMainLoop))]
|
|
//[InlineData (typeof (UnixDriver), typeof (UnixMainLoop))]
|
|
//[InlineData (typeof (WindowsDriver), typeof (WindowsMainLoop))]
|
|
|
|
//[InlineData (typeof (ANSIDriver), typeof (AnsiMainLoopDriver))]
|
|
public void MainLoop_CheckTimersAndIdleHandlers_TimersActive_ReturnsTrue (
|
|
Type driverType,
|
|
Type mainLoopDriverType
|
|
)
|
|
{
|
|
var driver = (IConsoleDriver)Activator.CreateInstance (driverType);
|
|
var mainLoopDriver = (IMainLoopDriver)Activator.CreateInstance (mainLoopDriverType, driver);
|
|
var mainLoop = new MainLoop (mainLoopDriver);
|
|
|
|
mainLoop.TimedEvents.Add (TimeSpan.FromMilliseconds (100), () => false);
|
|
bool result = mainLoop.TimedEvents.CheckTimers(out int waitTimeout);
|
|
|
|
Assert.True (result);
|
|
Assert.True (waitTimeout >= 0);
|
|
mainLoop.Dispose ();
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData (typeof (FakeDriver), typeof (FakeMainLoop))]
|
|
//[InlineData (typeof (DotNetDriver), typeof (NetMainLoop))]
|
|
//[InlineData (typeof (UnixDriver), typeof (UnixMainLoop))]
|
|
//[InlineData (typeof (WindowsDriver), typeof (WindowsMainLoop))]
|
|
|
|
//[InlineData (typeof (ANSIDriver), typeof (AnsiMainLoopDriver))]
|
|
public void MainLoop_Constructs_Disposes (Type driverType, Type mainLoopDriverType)
|
|
{
|
|
var driver = (IConsoleDriver)Activator.CreateInstance (driverType);
|
|
var mainLoopDriver = (IMainLoopDriver)Activator.CreateInstance (mainLoopDriverType, driver);
|
|
var mainLoop = new MainLoop (mainLoopDriver);
|
|
|
|
// Check default values
|
|
Assert.NotNull (mainLoop);
|
|
Assert.Equal (mainLoopDriver, mainLoop.MainLoopDriver);
|
|
Assert.Empty (mainLoop.TimedEvents.Timeouts);
|
|
Assert.False (mainLoop.Running);
|
|
|
|
// Clean up
|
|
mainLoop.Dispose ();
|
|
|
|
// TODO: It'd be nice if we could really verify IMainLoopDriver.TearDown was called
|
|
// and that it was actually cleaned up.
|
|
Assert.Null (mainLoop.MainLoopDriver);
|
|
Assert.Empty (mainLoop.TimedEvents.Timeouts);
|
|
Assert.False (mainLoop.Running);
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData (typeof (FakeDriver), typeof (FakeMainLoop))]
|
|
//[InlineData (typeof (DotNetDriver), typeof (NetMainLoop))]
|
|
//[InlineData (typeof (UnixDriver), typeof (UnixMainLoop))]
|
|
//[InlineData (typeof (WindowsDriver), typeof (WindowsMainLoop))]
|
|
|
|
//[InlineData (typeof (ANSIDriver), typeof (AnsiMainLoopDriver))]
|
|
public void MainLoop_RemoveIdle_InvalidToken_ReturnsFalse (Type driverType, Type mainLoopDriverType)
|
|
{
|
|
var driver = (IConsoleDriver)Activator.CreateInstance (driverType);
|
|
var mainLoopDriver = (IMainLoopDriver)Activator.CreateInstance (mainLoopDriverType, driver);
|
|
var mainLoop = new MainLoop (mainLoopDriver);
|
|
|
|
bool result = mainLoop.TimedEvents.Remove("flibble");
|
|
|
|
Assert.False (result);
|
|
mainLoop.Dispose ();
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData (typeof (FakeDriver), typeof (FakeMainLoop))]
|
|
//[InlineData (typeof (DotNetDriver), typeof (NetMainLoop))]
|
|
//[InlineData (typeof (UnixDriver), typeof (UnixMainLoop))]
|
|
//[InlineData (typeof (WindowsDriver), typeof (WindowsMainLoop))]
|
|
|
|
//[InlineData (typeof (ANSIDriver), typeof (AnsiMainLoopDriver))]
|
|
public void MainLoop_RemoveIdle_ValidToken_ReturnsTrue (Type driverType, Type mainLoopDriverType)
|
|
{
|
|
var driver = (IConsoleDriver)Activator.CreateInstance (driverType);
|
|
var mainLoopDriver = (IMainLoopDriver)Activator.CreateInstance (mainLoopDriverType, driver);
|
|
var mainLoop = new MainLoop (mainLoopDriver);
|
|
|
|
bool IdleHandler () { return false; }
|
|
|
|
|
|
var token = mainLoop.TimedEvents.Add (TimeSpan.Zero, IdleHandler);
|
|
bool result = mainLoop.TimedEvents.Remove (token);
|
|
|
|
Assert.True (result);
|
|
mainLoop.Dispose ();
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData (typeof (FakeDriver), typeof (FakeMainLoop))]
|
|
//[InlineData (typeof (DotNetDriver), typeof (NetMainLoop))]
|
|
//[InlineData (typeof (UnixDriver), typeof (UnixMainLoop))]
|
|
//[InlineData (typeof (WindowsDriver), typeof (WindowsMainLoop))]
|
|
|
|
//[InlineData (typeof (ANSIDriver), typeof (AnsiMainLoopDriver))]
|
|
public void MainLoop_RemoveTimeout_InvalidToken_ReturnsFalse (Type driverType, Type mainLoopDriverType)
|
|
{
|
|
var driver = (IConsoleDriver)Activator.CreateInstance (driverType);
|
|
var mainLoopDriver = (IMainLoopDriver)Activator.CreateInstance (mainLoopDriverType, driver);
|
|
var mainLoop = new MainLoop (mainLoopDriver);
|
|
|
|
bool result = mainLoop.TimedEvents.Remove (new object ());
|
|
|
|
Assert.False (result);
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData (typeof (FakeDriver), typeof (FakeMainLoop))]
|
|
//[InlineData (typeof (DotNetDriver), typeof (NetMainLoop))]
|
|
//[InlineData (typeof (UnixDriver), typeof (UnixMainLoop))]
|
|
//[InlineData (typeof (WindowsDriver), typeof (WindowsMainLoop))]
|
|
|
|
//[InlineData (typeof (ANSIDriver), typeof (AnsiMainLoopDriver))]
|
|
public void MainLoop_RemoveTimeout_ValidToken_ReturnsTrue (Type driverType, Type mainLoopDriverType)
|
|
{
|
|
var driver = (IConsoleDriver)Activator.CreateInstance (driverType);
|
|
var mainLoopDriver = (IMainLoopDriver)Activator.CreateInstance (mainLoopDriverType, driver);
|
|
var mainLoop = new MainLoop (mainLoopDriver);
|
|
|
|
object token = mainLoop.TimedEvents.Add (TimeSpan.FromMilliseconds (100), () => false);
|
|
bool result = mainLoop.TimedEvents.Remove (token);
|
|
|
|
Assert.True (result);
|
|
mainLoop.Dispose ();
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData (typeof (FakeDriver), typeof (FakeMainLoop))]
|
|
//[InlineData (typeof (DotNetDriver), typeof (NetMainLoop))]
|
|
//[InlineData (typeof (UnixDriver), typeof (UnixMainLoop))]
|
|
//[InlineData (typeof (WindowsDriver), typeof (WindowsMainLoop))]
|
|
|
|
//[InlineData (typeof (ANSIDriver), typeof (AnsiMainLoopDriver))]
|
|
public void MainLoop_RunIteration_ValidIdleHandler_CallsIdleHandler (Type driverType, Type mainLoopDriverType)
|
|
{
|
|
var driver = (IConsoleDriver)Activator.CreateInstance (driverType);
|
|
var mainLoopDriver = (IMainLoopDriver)Activator.CreateInstance (mainLoopDriverType, driver);
|
|
var mainLoop = new MainLoop (mainLoopDriver);
|
|
var idleHandlerInvoked = false;
|
|
|
|
Func<bool> idleHandler = () =>
|
|
{
|
|
idleHandlerInvoked = true;
|
|
|
|
return false;
|
|
};
|
|
|
|
mainLoop.TimedEvents.Add (TimeSpan.Zero, idleHandler);
|
|
mainLoop.RunIteration (); // Run an iteration to process the idle handler
|
|
|
|
Assert.True (idleHandlerInvoked);
|
|
mainLoop.Dispose ();
|
|
}
|
|
|
|
//[Theory]
|
|
//[InlineData (typeof (FakeDriver), typeof (FakeMainLoop))]
|
|
////[InlineData (typeof (DotNetDriver), typeof (NetMainLoop))]
|
|
////[InlineData (typeof (UnixDriver), typeof (UnixMainLoop))]
|
|
////[InlineData (typeof (WindowsDriver), typeof (WindowsMainLoop))]
|
|
//public void MainLoop_Invoke_ValidAction_RunsAction (Type driverType, Type mainLoopDriverType)
|
|
//{
|
|
// var driver = (IConsoleDriver)Activator.CreateInstance (driverType);
|
|
// var mainLoopDriver = (IMainLoopDriver)Activator.CreateInstance (mainLoopDriverType, new object [] { driver });
|
|
// var mainLoop = new MainLoop (mainLoopDriver);
|
|
// var actionInvoked = false;
|
|
|
|
// mainLoop.Invoke (() => { actionInvoked = true; });
|
|
// mainLoop.RunIteration (); // Run an iteration to process the action.
|
|
|
|
// Assert.True (actionInvoked);
|
|
// mainLoop.Dispose ();
|
|
//}
|
|
}
|