mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-28 08:47:59 +01:00
Refactored tests and code to align with the modern instance-based application model. Key changes include: - Disabled Sixel rendering in `OutputBase.cs` due to dependency on legacy static `Application` object. - Hardcoded `force16Colors` to `false` in `WindowsOutput.cs` with a `BUGBUG` note. - Updated `ApplicationImplTests` to use `ApplicationImpl.SetInstance` and return `ApplicationImpl.Instance`. - Refactored `ApplicationModelFencingTests` to use `Application.Create()` and added `ResetModelUsageTracking()` for model switching. - Removed legacy `DriverTests` and reintroduced updated versions with cross-platform driver tests. - Reverted `ArrangementTests` and `ShortcutTests` to use legacy static `ApplicationImpl.Instance`. - Reintroduced driver tests in `DriverTests.cs` with modern `Application.Create()` and added `TestTop` for driver content verification. - General cleanup, including removal of outdated code and addition of `BUGBUG` notes for temporary workarounds.
107 lines
3.5 KiB
C#
107 lines
3.5 KiB
C#
using UnitTests;
|
|
using Xunit.Abstractions;
|
|
|
|
namespace UnitTests_Parallelizable.DriverTests;
|
|
|
|
public class DriverTests (ITestOutputHelper output) : FakeDriverBase
|
|
{
|
|
[Theory]
|
|
[InlineData (null, true)]
|
|
[InlineData ("", true)]
|
|
[InlineData ("a", true)]
|
|
[InlineData ("👩❤️💋👨", false)]
|
|
public void IsValidLocation (string text, bool positive)
|
|
{
|
|
IDriver driver = CreateFakeDriver ();
|
|
driver.SetScreenSize (10, 10);
|
|
|
|
// positive
|
|
Assert.True (driver.IsValidLocation (text, 0, 0));
|
|
Assert.True (driver.IsValidLocation (text, 1, 1));
|
|
Assert.Equal (positive, driver.IsValidLocation (text, driver.Cols - 1, driver.Rows - 1));
|
|
|
|
// negative
|
|
Assert.False (driver.IsValidLocation (text, -1, 0));
|
|
Assert.False (driver.IsValidLocation (text, 0, -1));
|
|
Assert.False (driver.IsValidLocation (text, -1, -1));
|
|
Assert.False (driver.IsValidLocation (text, driver.Cols, driver.Rows - 1));
|
|
Assert.False (driver.IsValidLocation (text, driver.Cols, driver.Rows - 1));
|
|
Assert.False (driver.IsValidLocation (text, driver.Cols, driver.Rows));
|
|
|
|
// Define a clip rectangle
|
|
driver.Clip = new (new Rectangle (5, 5, 5, 5));
|
|
|
|
// positive
|
|
Assert.True (driver.IsValidLocation (text, 5, 5));
|
|
Assert.Equal (positive, driver.IsValidLocation (text, 9, 9));
|
|
|
|
// negative
|
|
Assert.False (driver.IsValidLocation (text, 4, 5));
|
|
Assert.False (driver.IsValidLocation (text, 5, 4));
|
|
Assert.False (driver.IsValidLocation (text, 10, 9));
|
|
Assert.False (driver.IsValidLocation (text, 9, 10));
|
|
Assert.False (driver.IsValidLocation (text, -1, 0));
|
|
Assert.False (driver.IsValidLocation (text, 0, -1));
|
|
Assert.False (driver.IsValidLocation (text, -1, -1));
|
|
Assert.False (driver.IsValidLocation (text, driver.Cols, driver.Rows - 1));
|
|
Assert.False (driver.IsValidLocation (text, driver.Cols, driver.Rows - 1));
|
|
Assert.False (driver.IsValidLocation (text, driver.Cols, driver.Rows));
|
|
|
|
driver.End ();
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData ("fake")]
|
|
[InlineData ("windows")]
|
|
[InlineData ("dotnet")]
|
|
[InlineData ("unix")]
|
|
public void All_Drivers_Init_Shutdown_Cross_Platform (string driverName)
|
|
{
|
|
IApplication? app = Application.Create ();
|
|
app.Init (driverName);
|
|
app.Shutdown ();
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData ("fake")]
|
|
[InlineData ("windows")]
|
|
[InlineData ("dotnet")]
|
|
[InlineData ("unix")]
|
|
public void All_Drivers_Run_Cross_Platform (string driverName)
|
|
{
|
|
IApplication? app = Application.Create ();
|
|
app.Init (driverName);
|
|
app.StopAfterFirstIteration = true;
|
|
app.Run ().Dispose ();
|
|
app.Shutdown ();
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData ("fake")]
|
|
[InlineData ("windows")]
|
|
[InlineData ("dotnet")]
|
|
[InlineData ("unix")]
|
|
public void All_Drivers_LayoutAndDraw_Cross_Platform (string driverName)
|
|
{
|
|
IApplication? app = Application.Create ();
|
|
app.Init (driverName);
|
|
app.StopAfterFirstIteration = true;
|
|
app.Run<TestTop> ().Dispose ();
|
|
|
|
DriverAssert.AssertDriverContentsWithFrameAre (driverName!, output, app.Driver);
|
|
|
|
app.Shutdown ();
|
|
}
|
|
}
|
|
|
|
public class TestTop : Toplevel
|
|
{
|
|
/// <inheritdoc/>
|
|
public override void BeginInit ()
|
|
{
|
|
Text = Driver!.GetName ()!;
|
|
BorderStyle = LineStyle.None;
|
|
base.BeginInit ();
|
|
}
|
|
}
|