Fixes #4374 - Nukes all (?) legacy Driver and Application stuff; revamps tests (#4376)

This commit is contained in:
Tig
2025-11-11 16:29:33 -07:00
committed by GitHub
parent 559dea9239
commit d53fcd7485
310 changed files with 14827 additions and 16911 deletions

View File

@@ -1,58 +0,0 @@
using UnitTests;
using Xunit.Abstractions;
namespace UnitTests.LayoutTests;
public class AllViewsDrawTests (ITestOutputHelper output) : TestsAllViews
{
[Theory]
[SetupFakeDriver] // Required for spinner view that wants to register timeouts
[MemberData (nameof (AllViewTypes))]
public void AllViews_Draw_Does_Not_Layout (Type viewType)
{
Application.ResetState (true);
// Required for spinner view that wants to register timeouts
var view = (View)CreateInstanceIfNotGeneric (viewType);
if (view == null)
{
output.WriteLine ($"Ignoring {viewType} - It's a Generic");
return;
}
output.WriteLine ($"Testing {viewType}");
if (view is IDesignable designable)
{
designable.EnableForDesign ();
}
var drawCompleteCount = 0;
view.DrawComplete += (s, e) => drawCompleteCount++;
var layoutStartedCount = 0;
view.SubViewLayout += (s, e) => layoutStartedCount++;
var layoutCompleteCount = 0;
view.SubViewsLaidOut += (s, e) => layoutCompleteCount++;
view.SetNeedsLayout ();
view.Layout ();
Assert.Equal (0, drawCompleteCount);
Assert.Equal (1, layoutStartedCount);
Assert.Equal (1, layoutCompleteCount);
if (view.Visible)
{
view.SetNeedsDraw ();
view.Draw ();
Assert.Equal (1, drawCompleteCount);
Assert.Equal (1, layoutStartedCount);
Assert.Equal (1, layoutCompleteCount);
}
}
}

View File

@@ -98,7 +98,7 @@ public class ClearViewportTests (ITestOutputHelper output)
}
[Fact]
[SetupFakeDriver]
[SetupFakeApplication]
public void Clear_ClearsEntireViewport ()
{
var superView = new View { Width = Dim.Fill (), Height = Dim.Fill () };
@@ -146,7 +146,7 @@ public class ClearViewportTests (ITestOutputHelper output)
}
[Fact]
[SetupFakeDriver]
[SetupFakeApplication]
public void Clear_WithClearVisibleContentOnly_ClearsVisibleContentOnly ()
{
var superView = new View { Width = Dim.Fill (), Height = Dim.Fill () };
@@ -337,7 +337,7 @@ public class ClearViewportTests (ITestOutputHelper output)
Toplevel top = new ();
top.Add (root);
RunState runState = Application.Begin (top);
SessionToken sessionToken = Application.Begin (top);
AutoInitShutdownAttribute.RunIteration ();
if (label)
@@ -406,7 +406,7 @@ cccccccccccccccccccc",
);
}
Application.End (runState);
Application.End (sessionToken);
top.Dispose ();
CM.Disable (resetToHardCodedDefaults: true);

View File

@@ -9,7 +9,7 @@ namespace UnitTests.ViewTests;
public class ClipTests (ITestOutputHelper _output)
{
[Fact]
[SetupFakeDriver]
[SetupFakeApplication]
public void Move_Is_Not_Constrained_To_Viewport ()
{
var view = new View
@@ -31,7 +31,7 @@ public class ClipTests (ITestOutputHelper _output)
}
[Fact]
[SetupFakeDriver]
[SetupFakeApplication]
public void AddRune_Is_Constrained_To_Viewport ()
{
var view = new View
@@ -64,7 +64,7 @@ public class ClipTests (ITestOutputHelper _output)
[InlineData (0, 0, 1, 1)]
[InlineData (0, 0, 2, 2)]
[InlineData (-1, -1, 2, 2)]
[SetupFakeDriver]
[SetupFakeApplication]
public void FillRect_Fills_HonorsClip (int x, int y, int width, int height)
{
var superView = new View { Width = Dim.Fill (), Height = Dim.Fill () };
@@ -167,7 +167,7 @@ public class ClipTests (ITestOutputHelper _output)
// TODO: Simplify this test to just use AddRune directly
[Fact]
[SetupFakeDriver]
[SetupFakeApplication]
[Trait ("Category", "Unicode")]
public void Clipping_Wide_Runes ()
{
@@ -235,7 +235,7 @@ public class ClipTests (ITestOutputHelper _output)
// TODO: Add more AddRune tests to cover all the cases where wide runes are clipped
[Fact]
[SetupFakeDriver]
[SetupFakeApplication]
public void SetClip_ClipVisibleContentOnly_VisibleContentIsClipped ()
{
// Screen is 25x25
@@ -269,10 +269,11 @@ public class ClipTests (ITestOutputHelper _output)
}
[Fact]
[SetupFakeDriver]
[SetupFakeApplication]
public void SetClip_Default_ClipsToViewport ()
{
// Screen is 25x25
Application.Driver!.SetScreenSize (25, 25);
// View is 25x25
// Viewport is (0, 0, 23, 23)
// ContentSize is (10, 10)

View File

@@ -111,7 +111,7 @@ public class DrawTests (ITestOutputHelper output)
}
[Fact]
[SetupFakeDriver]
[SetupFakeApplication]
public void Draw_Minimum_Full_Border_With_Empty_Viewport ()
{
var view = new View { Width = 2, Height = 2, BorderStyle = LineStyle.Single };
@@ -136,7 +136,7 @@ public class DrawTests (ITestOutputHelper output)
}
[Fact]
[SetupFakeDriver]
[SetupFakeApplication]
public void Draw_Minimum_Full_Border_With_Empty_Viewport_Without_Bottom ()
{
var view = new View { Width = 2, Height = 1, BorderStyle = LineStyle.Single };
@@ -154,7 +154,7 @@ public class DrawTests (ITestOutputHelper output)
}
[Fact]
[SetupFakeDriver]
[SetupFakeApplication]
public void Draw_Minimum_Full_Border_With_Empty_Viewport_Without_Left ()
{
var view = new View { Width = 1, Height = 2, BorderStyle = LineStyle.Single };
@@ -179,7 +179,7 @@ public class DrawTests (ITestOutputHelper output)
}
[Fact]
[SetupFakeDriver]
[SetupFakeApplication]
public void Draw_Minimum_Full_Border_With_Empty_Viewport_Without_Right ()
{
var view = new View { Width = 1, Height = 2, BorderStyle = LineStyle.Single };
@@ -204,7 +204,7 @@ public class DrawTests (ITestOutputHelper output)
}
[Fact]
[SetupFakeDriver]
[SetupFakeApplication]
public void Draw_Minimum_Full_Border_With_Empty_Viewport_Without_Top ()
{
var view = new View { Width = 2, Height = 1, BorderStyle = LineStyle.Single };
@@ -582,7 +582,7 @@ public class DrawTests (ITestOutputHelper output)
}
[Theory]
[SetupFakeDriver]
[SetupFakeApplication]
[InlineData ("𝔽𝕆𝕆𝔹𝔸R")]
[InlineData ("a𐐀b")]
public void DrawHotString_NonBmp (string expected)
@@ -635,22 +635,15 @@ public class DrawTests (ITestOutputHelper output)
}
[Fact]
[TestRespondersDisposed]
[AutoInitShutdown]
public void Draw_Throws_IndexOutOfRangeException_With_Negative_Bounds ()
{
Application.Init (new FakeDriver ());
Toplevel top = new ();
var view = new View { X = -2, Text = "view" };
top.Add (view);
Application.Iteration += (s, a) =>
{
Assert.Equal (-2, view.X);
Application.RequestStop ();
};
Application.Iteration += OnApplicationOnIteration;
try
{
@@ -661,11 +654,24 @@ public class DrawTests (ITestOutputHelper output)
// After the fix this exception will not be caught.
Assert.IsType<IndexOutOfRangeException> (ex);
}
finally
{
Application.Iteration -= OnApplicationOnIteration;
}
top.Dispose ();
// Shutdown must be called to safely clean up Application if Init has been called
Application.Shutdown ();
return;
void OnApplicationOnIteration (object? s, IterationEventArgs a)
{
Assert.Equal (-2, view.X);
Application.RequestStop ();
}
}
@@ -685,7 +691,7 @@ public class DrawTests (ITestOutputHelper output)
};
Toplevel top = new ();
top.Add (label, view);
RunState runState = Application.Begin (top);
SessionToken sessionToken = Application.Begin (top);
AutoInitShutdownAttribute.RunIteration ();
DriverAssert.AssertDriverContentsWithFrameAre (
@@ -713,7 +719,7 @@ At 0,0
A text wit",
output
);
Application.End (runState);
Application.End (sessionToken);
top.Dispose ();
}
@@ -733,7 +739,7 @@ At 0,0
};
Toplevel top = new ();
top.Add (label, view);
RunState runState = Application.Begin (top);
SessionToken sessionToken = Application.Begin (top);
top.Draw ();
@@ -766,7 +772,7 @@ At 0,0
,
output
);
Application.End (runState);
Application.End (sessionToken);
top.Dispose ();
}
@@ -786,7 +792,7 @@ At 0,0
};
Toplevel top = new ();
top.Add (label, view);
RunState runState = Application.Begin (top);
SessionToken sessionToken = Application.Begin (top);
AutoInitShutdownAttribute.RunIteration ();
DriverAssert.AssertDriverContentsWithFrameAre (
@@ -812,7 +818,7 @@ At 0,0
,
output
);
Application.End (runState);
Application.End (sessionToken);
top.Dispose ();
}
@@ -832,7 +838,7 @@ At 0,0
};
Toplevel top = new ();
top.Add (label, view);
RunState runState = Application.Begin (top);
SessionToken sessionToken = Application.Begin (top);
top.Draw ();
@@ -864,7 +870,7 @@ At 0,0
,
output
);
Application.End (runState);
Application.End (sessionToken);
top.Dispose ();
}
public class DerivedView : View

View File

@@ -37,7 +37,7 @@ public class NeedsDrawTests ()
top.Add (frame);
RunState runState = Application.Begin (top);
SessionToken sessionToken = Application.Begin (top);
Application.Driver!.SetScreenSize (80,25);
@@ -62,7 +62,7 @@ public class NeedsDrawTests ()
);
Assert.Equal (new (0, 0, 30, 1), label.Frame);
Assert.Equal (new (0, 1, 9, 1), view.Frame); // this proves frame was set
Application.End (runState);
Application.End (sessionToken);
top.Dispose ();
}
}

View File

@@ -8,7 +8,7 @@ namespace UnitTests.ViewTests;
public class TransparentTests (ITestOutputHelper output)
{
[Fact]
[SetupFakeDriver]
[SetupFakeApplication]
public void Transparent_Text_Occludes ()
{
@@ -52,7 +52,7 @@ public class TransparentTests (ITestOutputHelper output)
}
[Fact]
[SetupFakeDriver]
[SetupFakeApplication]
public void Transparent_SubView_Occludes ()
{