mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-27 00:07:58 +01:00
* Tons of API doc updates * Removed stale test * Removed stale tests * Fixed Skipped Shadow test 1 * Fixed Skipped Shadow test 2 * Fixed Skipped Shadow test 3 * Removed stale test * Removed stale test2 * Explicit unregister of event handler on Application.Driver!.ClearedContents * Added Toplevels to dict * code cleanup * spelling error * Removed stale test3 * Removed stale test4 * Removed stale test5 * added script * tweaked script * tweaked script * Created StressTests project; moved some tests * Created IntegrationTests project; moved some tests * New yml * made old yml just unit tests * Tweaked Button_IsDefault_Raises_Accepted_Correctly * tweaked script * cleaned up ymls * tweakled up ymls * stress tests... * stress tests on ubuntu only * Fixed WindowsDriver in InvokeLeakTest * Fixed WindowsDriver in InvokeLeakTest2 * Added Directory.Packages.props. Added Directory.Build.props * Shortened StressTest time * Removed dupe file. * DemoFiles * Moved all tests to ./Tests dir. * Fixed release build issue * Fixed .sln file * Fixed .sl* files * Fixing ymls * Fixing interation tests * Create link to the file TestHelpers. * Created Tests/UnitTestsParallelizable. Moved all obviously parallelizable tests. Updated yml. * fixing logs * fixing logs2 * fixing logs3 * don't require stress to pass for PRs * Fix a failure? * tweaked script * Coudl this be it? * Moved tons of tests to parallelizable * Fixed some stuff * Script to find duplicate tests * Testing workflows * Updated to v4 * Fix RelativeBasePath issue * Replace powershell to pwsh * Add ignore projects. * Removed dupe unit tests * Code cleanup of tests * Cleaned up test warnings * yml tweak * Moved setter * tweak ymls * just randomly throwing spaghetti at a wall * Enable runing 5 test runners in par * Turned off DEBUG_DISPOSABLE for par tests * RunningUnitTests=true * code cleanup (forcing more Action runs) * DISABLE_DEBUG_IDISPOSABLE * Added View.DebugIDisposable. False by default. * Remobed bogus tareet * Remobed bogus tareet2 * fixed warning * added api doc * fixed warning * fixed warning * fixed warning2 * fixed warning3 * fixed warning4 --------- Co-authored-by: BDisp <bd.bdisp@gmail.com>
305 lines
9.4 KiB
C#
305 lines
9.4 KiB
C#
namespace Terminal.Gui.LayoutTests;
|
|
|
|
public class FrameTests
|
|
{
|
|
[Fact]
|
|
public void Frame_Empty_Default ()
|
|
{
|
|
View view = new ();
|
|
Assert.Equal (Rectangle.Empty, view.Frame);
|
|
|
|
view.BeginInit ();
|
|
view.EndInit ();
|
|
Assert.Equal (Rectangle.Empty, view.Frame);
|
|
}
|
|
|
|
[Fact]
|
|
public void Frame_Empty_Initializer_Overrides_Base ()
|
|
{
|
|
// Prove TestView is correct
|
|
FrameTestView view = new ();
|
|
Assert.True (view.NeedsLayout);
|
|
|
|
view.Layout ();
|
|
Assert.Equal (new (10, 20, 30, 40), view.Frame);
|
|
Assert.Equal (10, view.X.GetAnchor (0));
|
|
Assert.Equal (20, view.Y.GetAnchor (0));
|
|
Assert.Equal (30, view.Width!.GetAnchor (0));
|
|
Assert.Equal (40, view.Height!.GetAnchor (0));
|
|
Assert.Equal (new (0, 0, 30, 40), view.Viewport);
|
|
|
|
// Set Frame via init
|
|
Rectangle frame = new (1, 2, 3, 4);
|
|
|
|
view = new ()
|
|
{
|
|
Frame = frame
|
|
};
|
|
Assert.Equal (frame, view.Frame);
|
|
Assert.False (view.NeedsLayout);
|
|
Assert.Equal (frame.Size, view.Viewport.Size);
|
|
|
|
Assert.Equal (view.X, frame.X);
|
|
Assert.Equal (view.Y, frame.Y);
|
|
Assert.Equal (view.Width, frame.Width);
|
|
Assert.Equal (view.Height, frame.Height);
|
|
|
|
// Set Frame via init to empty
|
|
frame = Rectangle.Empty;
|
|
|
|
view = new ()
|
|
{
|
|
Frame = frame
|
|
};
|
|
Assert.Equal (frame, view.Frame);
|
|
Assert.False (view.NeedsLayout);
|
|
Assert.Equal (frame.Size, view.Viewport.Size);
|
|
|
|
Assert.Equal (view.X, frame.X);
|
|
Assert.Equal (view.Y, frame.Y);
|
|
Assert.Equal (view.Width, frame.Width);
|
|
Assert.Equal (view.Height, frame.Height);
|
|
|
|
// Set back to original state
|
|
view.X = Pos.Func (() => 10);
|
|
view.Y = Pos.Func (() => 20);
|
|
view.Width = Dim.Func (() => 30);
|
|
view.Height = Dim.Func (() => 40);
|
|
Assert.True (view.NeedsLayout);
|
|
|
|
view.Layout ();
|
|
Assert.Equal (new (10, 20, 30, 40), view.Frame);
|
|
Assert.Equal (10, view.X.GetAnchor (0));
|
|
Assert.Equal (20, view.Y.GetAnchor (0));
|
|
Assert.Equal (30, view.Width!.GetAnchor (0));
|
|
Assert.Equal (40, view.Height!.GetAnchor (0));
|
|
Assert.Equal (new (0, 0, 30, 40), view.Viewport);
|
|
|
|
view.Frame = frame;
|
|
Assert.Equal (frame, view.Frame);
|
|
Assert.False (view.NeedsLayout);
|
|
Assert.Equal (frame.Size, view.Viewport.Size);
|
|
|
|
Assert.Equal (view.X, frame.X);
|
|
Assert.Equal (view.Y, frame.Y);
|
|
Assert.Equal (view.Width, frame.Width);
|
|
Assert.Equal (view.Height, frame.Height);
|
|
}
|
|
|
|
[Fact]
|
|
public void Frame_Empty_Initializer_Sets ()
|
|
{
|
|
Rectangle frame = new (1, 2, 3, 4);
|
|
|
|
View view = new ()
|
|
{
|
|
Frame = frame
|
|
};
|
|
|
|
Assert.Equal (frame, view.Frame);
|
|
Assert.False (view.NeedsLayout);
|
|
Assert.Equal (frame.Size, view.Viewport.Size);
|
|
|
|
Assert.Equal (view.X, frame.X);
|
|
Assert.Equal (view.Y, frame.Y);
|
|
Assert.Equal (view.Width, frame.Width);
|
|
Assert.Equal (view.Height, frame.Height);
|
|
|
|
view.Frame = Rectangle.Empty;
|
|
Assert.Equal (Rectangle.Empty, view.Frame);
|
|
Assert.False (view.NeedsLayout);
|
|
Assert.Equal (Rectangle.Empty.Size, view.Viewport.Size);
|
|
|
|
Assert.Equal (view.X, Rectangle.Empty.X);
|
|
Assert.Equal (view.Y, Rectangle.Empty.Y);
|
|
Assert.Equal (view.Width, Rectangle.Empty.Width);
|
|
Assert.Equal (view.Height, Rectangle.Empty.Height);
|
|
|
|
view.Width = Dim.Fill ();
|
|
view.Height = Dim.Fill ();
|
|
Assert.True (view.NeedsLayout);
|
|
view.Layout ();
|
|
Assert.False (view.NeedsLayout);
|
|
Assert.Equal (Application.Screen, view.Frame);
|
|
|
|
view.Frame = Rectangle.Empty;
|
|
Assert.Equal (Rectangle.Empty, view.Frame);
|
|
Assert.False (view.NeedsLayout);
|
|
Assert.Equal (Rectangle.Empty.Size, view.Viewport.Size);
|
|
|
|
Assert.Equal (view.X, Rectangle.Empty.X);
|
|
Assert.Equal (view.Y, Rectangle.Empty.Y);
|
|
Assert.Equal (view.Width, Rectangle.Empty.Width);
|
|
Assert.Equal (view.Height, Rectangle.Empty.Height);
|
|
}
|
|
|
|
[Fact]
|
|
public void Frame_Initializer_Sets ()
|
|
{
|
|
Rectangle frame = new (1, 2, 3, 4);
|
|
|
|
View view = new ()
|
|
{
|
|
Frame = frame
|
|
};
|
|
|
|
Assert.Equal (frame, view.Frame);
|
|
Assert.False (view.NeedsLayout);
|
|
Assert.Equal (frame.Size, view.Viewport.Size);
|
|
|
|
Assert.Equal (view.X, frame.X);
|
|
Assert.Equal (view.Y, frame.Y);
|
|
Assert.Equal (view.Width, frame.Width);
|
|
Assert.Equal (view.Height, frame.Height);
|
|
}
|
|
|
|
// Moved this test from AbsoluteLayoutTests
|
|
// TODO: Refactor as Theory
|
|
[Fact]
|
|
public void Frame_Set ()
|
|
{
|
|
var frame = new Rectangle (1, 2, 3, 4);
|
|
var newFrame = new Rectangle (1, 2, 30, 40);
|
|
|
|
var v = new View ();
|
|
Assert.Equal (Rectangle.Empty, v.Frame);
|
|
v.Dispose ();
|
|
|
|
v = new() { Frame = frame };
|
|
Assert.Equal (frame, v.Frame);
|
|
|
|
v.Frame = newFrame;
|
|
Assert.Equal (newFrame, v.Frame);
|
|
|
|
Assert.Equal (
|
|
new (0, 0, newFrame.Width, newFrame.Height),
|
|
v.Viewport
|
|
); // With Absolute Viewport *is* deterministic before Layout
|
|
Assert.Equal (Pos.Absolute (1), v.X);
|
|
Assert.Equal (Pos.Absolute (2), v.Y);
|
|
Assert.Equal (Dim.Absolute (30), v.Width);
|
|
Assert.Equal (Dim.Absolute (40), v.Height);
|
|
v.Dispose ();
|
|
|
|
v = new() { X = frame.X, Y = frame.Y, Text = "v" };
|
|
v.Frame = newFrame;
|
|
Assert.Equal (newFrame, v.Frame);
|
|
|
|
Assert.Equal (
|
|
new (0, 0, newFrame.Width, newFrame.Height),
|
|
v.Viewport
|
|
); // With Absolute Viewport *is* deterministic before Layout
|
|
Assert.Equal (Pos.Absolute (1), v.X);
|
|
Assert.Equal (Pos.Absolute (2), v.Y);
|
|
Assert.Equal (Dim.Absolute (30), v.Width);
|
|
Assert.Equal (Dim.Absolute (40), v.Height);
|
|
v.Dispose ();
|
|
|
|
newFrame = new (10, 20, 30, 40);
|
|
v = new() { Frame = frame };
|
|
v.Frame = newFrame;
|
|
Assert.Equal (newFrame, v.Frame);
|
|
|
|
Assert.Equal (
|
|
new (0, 0, newFrame.Width, newFrame.Height),
|
|
v.Viewport
|
|
); // With Absolute Viewport *is* deterministic before Layout
|
|
Assert.Equal (Pos.Absolute (10), v.X);
|
|
Assert.Equal (Pos.Absolute (20), v.Y);
|
|
Assert.Equal (Dim.Absolute (30), v.Width);
|
|
Assert.Equal (Dim.Absolute (40), v.Height);
|
|
v.Dispose ();
|
|
|
|
v = new() { X = frame.X, Y = frame.Y, Text = "v" };
|
|
v.Frame = newFrame;
|
|
Assert.Equal (newFrame, v.Frame);
|
|
|
|
Assert.Equal (
|
|
new (0, 0, newFrame.Width, newFrame.Height),
|
|
v.Viewport
|
|
); // With Absolute Viewport *is* deterministic before Layout
|
|
Assert.Equal (Pos.Absolute (10), v.X);
|
|
Assert.Equal (Pos.Absolute (20), v.Y);
|
|
Assert.Equal (Dim.Absolute (30), v.Width);
|
|
Assert.Equal (Dim.Absolute (40), v.Height);
|
|
v.Dispose ();
|
|
}
|
|
|
|
[Fact]
|
|
public void Frame_Set_Sets ()
|
|
{
|
|
Rectangle frame = new (1, 2, 3, 4);
|
|
View view = new ();
|
|
Assert.True (view.NeedsLayout);
|
|
Assert.Equal (Rectangle.Empty, view.Frame);
|
|
|
|
view.Frame = frame;
|
|
Assert.Equal (frame, view.Frame);
|
|
Assert.False (view.NeedsLayout);
|
|
|
|
Assert.Equal (view.X, frame.X);
|
|
Assert.Equal (view.Y, frame.Y);
|
|
Assert.Equal (view.Width, frame.Width);
|
|
Assert.Equal (view.Height, frame.Height);
|
|
}
|
|
|
|
[Fact]
|
|
public void FrameChanged_Event_Raised_When_Frame_Changes ()
|
|
{
|
|
// Arrange
|
|
var view = new TestFrameEventsView ();
|
|
var initialFrame = new Rectangle (0, 0, 10, 10);
|
|
var newFrame = new Rectangle (0, 0, 20, 20);
|
|
view.Frame = initialFrame;
|
|
Assert.Equal (1, view.FrameChangedEventCallCount);
|
|
|
|
// Act
|
|
view.Frame = newFrame;
|
|
|
|
// Assert
|
|
Assert.Equal (2, view.FrameChangedEventCallCount);
|
|
}
|
|
|
|
[Fact]
|
|
public void OnFrameChanged_Called_When_Frame_Changes ()
|
|
{
|
|
// Arrange
|
|
var view = new TestFrameEventsView ();
|
|
var initialFrame = new Rectangle (0, 0, 10, 10);
|
|
var newFrame = new Rectangle (0, 0, 20, 20);
|
|
view.Frame = initialFrame;
|
|
Assert.Equal (1, view.OnFrameChangedCallCount);
|
|
|
|
// Act
|
|
view.Frame = newFrame;
|
|
|
|
// Assert
|
|
Assert.Equal (2, view.OnFrameChangedCallCount);
|
|
}
|
|
|
|
private class FrameTestView : View
|
|
{
|
|
public FrameTestView ()
|
|
{
|
|
X = Pos.Func (() => 10);
|
|
Y = Pos.Func (() => 20);
|
|
Width = Dim.Func (() => 30);
|
|
Height = Dim.Func (() => 40);
|
|
}
|
|
}
|
|
|
|
private class TestFrameEventsView : View
|
|
{
|
|
public TestFrameEventsView () { FrameChanged += (sender, args) => FrameChangedEventCallCount++; }
|
|
|
|
public int FrameChangedEventCallCount { get; private set; }
|
|
public int OnFrameChangedCallCount { get; private set; }
|
|
|
|
protected override void OnFrameChanged (in Rectangle frame)
|
|
{
|
|
OnFrameChangedCallCount++;
|
|
base.OnFrameChanged (frame);
|
|
}
|
|
}
|
|
}
|