|
@@ -15,7 +15,7 @@ namespace Terminal.Gui.ViewTests {
|
|
|
this.output = output;
|
|
|
}
|
|
|
|
|
|
- [Fact]
|
|
|
+ [Fact, TestRespondersDisposed]
|
|
|
public void New_Initializes ()
|
|
|
{
|
|
|
// Parameterless
|
|
@@ -41,7 +41,8 @@ namespace Terminal.Gui.ViewTests {
|
|
|
Assert.Null (r.SuperView);
|
|
|
Assert.Null (r.MostFocused);
|
|
|
Assert.Equal (TextDirection.LeftRight_TopBottom, r.TextDirection);
|
|
|
-
|
|
|
+ r.Dispose ();
|
|
|
+
|
|
|
// Empty Rect
|
|
|
r = new View (Rect.Empty);
|
|
|
Assert.NotNull (r);
|
|
@@ -65,6 +66,7 @@ namespace Terminal.Gui.ViewTests {
|
|
|
Assert.Null (r.SuperView);
|
|
|
Assert.Null (r.MostFocused);
|
|
|
Assert.Equal (TextDirection.LeftRight_TopBottom, r.TextDirection);
|
|
|
+ r.Dispose ();
|
|
|
|
|
|
// Rect with values
|
|
|
r = new View (new Rect (1, 2, 3, 4));
|
|
@@ -89,6 +91,7 @@ namespace Terminal.Gui.ViewTests {
|
|
|
Assert.Null (r.SuperView);
|
|
|
Assert.Null (r.MostFocused);
|
|
|
Assert.Equal (TextDirection.LeftRight_TopBottom, r.TextDirection);
|
|
|
+ r.Dispose ();
|
|
|
|
|
|
// Initializes a view with a vertical direction
|
|
|
r = new View ("Vertical View", TextDirection.TopBottom_LeftRight);
|
|
@@ -113,10 +116,11 @@ namespace Terminal.Gui.ViewTests {
|
|
|
Assert.Null (r.SuperView);
|
|
|
Assert.Null (r.MostFocused);
|
|
|
Assert.Equal (TextDirection.TopBottom_LeftRight, r.TextDirection);
|
|
|
-
|
|
|
+ r.Dispose ();
|
|
|
+
|
|
|
}
|
|
|
|
|
|
- [Fact]
|
|
|
+ [Fact, TestRespondersDisposed]
|
|
|
public void New_Methods_Return_False ()
|
|
|
{
|
|
|
var r = new View ();
|
|
@@ -129,13 +133,22 @@ namespace Terminal.Gui.ViewTests {
|
|
|
Assert.False (r.MouseEvent (new MouseEvent () { Flags = MouseFlags.AllEvents }));
|
|
|
Assert.False (r.OnMouseEnter (new MouseEvent () { Flags = MouseFlags.AllEvents }));
|
|
|
Assert.False (r.OnMouseLeave (new MouseEvent () { Flags = MouseFlags.AllEvents }));
|
|
|
- Assert.False (r.OnEnter (new View ()));
|
|
|
- Assert.False (r.OnLeave (new View ()));
|
|
|
+
|
|
|
+ var v1 = new View ();
|
|
|
+ Assert.False (r.OnEnter (v1));
|
|
|
+ v1.Dispose ();
|
|
|
+
|
|
|
+ var v2 = new View ();
|
|
|
+ Assert.False (r.OnLeave (v2));
|
|
|
+ v2.Dispose ();
|
|
|
+
|
|
|
+ r.Dispose ();
|
|
|
+
|
|
|
|
|
|
// TODO: Add more
|
|
|
}
|
|
|
|
|
|
- [Fact]
|
|
|
+ [Fact, TestRespondersDisposed]
|
|
|
public void View_With_No_Difference_Between_An_Object_Initializer_And_A_Constructor ()
|
|
|
{
|
|
|
// Object Initializer
|
|
@@ -168,7 +181,12 @@ namespace Terminal.Gui.ViewTests {
|
|
|
Assert.Equal (4, view.Height);
|
|
|
Assert.False (view.Frame.IsEmpty);
|
|
|
Assert.False (view.Bounds.IsEmpty);
|
|
|
+ super.Dispose ();
|
|
|
|
|
|
+#if DEBUG_IDISPOSABLE
|
|
|
+ Assert.Empty (Responder.Instances);
|
|
|
+#endif
|
|
|
+
|
|
|
// Default Constructor
|
|
|
view = new View ();
|
|
|
Assert.Null (view.X);
|
|
@@ -177,6 +195,7 @@ namespace Terminal.Gui.ViewTests {
|
|
|
Assert.Null (view.Height);
|
|
|
Assert.True (view.Frame.IsEmpty);
|
|
|
Assert.True (view.Bounds.IsEmpty);
|
|
|
+ view.Dispose ();
|
|
|
|
|
|
// Constructor
|
|
|
view = new View (1, 2, "");
|
|
@@ -186,6 +205,7 @@ namespace Terminal.Gui.ViewTests {
|
|
|
Assert.Null (view.Height);
|
|
|
Assert.False (view.Frame.IsEmpty);
|
|
|
Assert.True (view.Bounds.IsEmpty);
|
|
|
+ view.Dispose ();
|
|
|
|
|
|
// Default Constructor and post assignment equivalent to Object Initializer
|
|
|
view = new View ();
|
|
@@ -206,9 +226,10 @@ namespace Terminal.Gui.ViewTests {
|
|
|
Assert.Equal (new Rect (1, 2, 3, 4), view.Frame);
|
|
|
Assert.False (view.Bounds.IsEmpty);
|
|
|
Assert.Equal (new Rect (0, 0, 3, 4), view.Bounds);
|
|
|
+ super.Dispose ();
|
|
|
}
|
|
|
|
|
|
- [Fact]
|
|
|
+ [Fact, TestRespondersDisposed]
|
|
|
public void Added_Removed ()
|
|
|
{
|
|
|
var v = new View (new Rect (0, 0, 10, 24));
|
|
@@ -231,9 +252,12 @@ namespace Terminal.Gui.ViewTests {
|
|
|
|
|
|
t.Remove (v);
|
|
|
Assert.True (t.Subviews.Count == 0);
|
|
|
+
|
|
|
+ t.Dispose ();
|
|
|
+ v.Dispose ();
|
|
|
}
|
|
|
|
|
|
- [Fact]
|
|
|
+ [Fact, TestRespondersDisposed]
|
|
|
public void Initialized_Event_Comparing_With_Added_Event ()
|
|
|
{
|
|
|
Application.Init (new FakeDriver ());
|
|
@@ -330,9 +354,10 @@ namespace Terminal.Gui.ViewTests {
|
|
|
|
|
|
v1.CanFocus = true;
|
|
|
Assert.False (sv1.CanFocus); // False because sv1 was disposed and it isn't a subview of v1.
|
|
|
+
|
|
|
}
|
|
|
|
|
|
- [Fact]
|
|
|
+ [Fact, TestRespondersDisposed]
|
|
|
public void Initialized_Event_Will_Be_Invoked_When_Added_Dynamically ()
|
|
|
{
|
|
|
Application.Init (new FakeDriver ());
|
|
@@ -409,104 +434,11 @@ namespace Terminal.Gui.ViewTests {
|
|
|
Assert.True (w.CanFocus);
|
|
|
Assert.False (v1.CanFocus);
|
|
|
Assert.False (v2.CanFocus);
|
|
|
- }
|
|
|
-
|
|
|
- [Fact]
|
|
|
- public void Multi_Thread_Toplevels ()
|
|
|
- {
|
|
|
- Application.Init (new FakeDriver ());
|
|
|
-
|
|
|
- var t = Application.Top;
|
|
|
- var w = new Window ();
|
|
|
- t.Add (w);
|
|
|
-
|
|
|
- int count = 0, count1 = 0, count2 = 0;
|
|
|
- bool log = false, log1 = false, log2 = false;
|
|
|
- bool fromTopStillKnowFirstIsRunning = false;
|
|
|
- bool fromTopStillKnowSecondIsRunning = false;
|
|
|
- bool fromFirstStillKnowSecondIsRunning = false;
|
|
|
-
|
|
|
- Application.MainLoop.AddTimeout (TimeSpan.FromMilliseconds (100), (_) => {
|
|
|
- count++;
|
|
|
- if (count1 == 5) {
|
|
|
- log1 = true;
|
|
|
- }
|
|
|
- if (count1 == 14 && count2 == 10 && count == 15) { // count2 is already stopped
|
|
|
- fromTopStillKnowFirstIsRunning = true;
|
|
|
- }
|
|
|
- if (count1 == 7 && count2 == 7 && count == 8) {
|
|
|
- fromTopStillKnowSecondIsRunning = true;
|
|
|
- }
|
|
|
- if (count == 30) {
|
|
|
- Assert.Equal (30, count);
|
|
|
- Assert.Equal (20, count1);
|
|
|
- Assert.Equal (10, count2);
|
|
|
-
|
|
|
- Assert.True (log);
|
|
|
- Assert.True (log1);
|
|
|
- Assert.True (log2);
|
|
|
-
|
|
|
- Assert.True (fromTopStillKnowFirstIsRunning);
|
|
|
- Assert.True (fromTopStillKnowSecondIsRunning);
|
|
|
- Assert.True (fromFirstStillKnowSecondIsRunning);
|
|
|
-
|
|
|
- Application.RequestStop ();
|
|
|
- return false;
|
|
|
- }
|
|
|
- return true;
|
|
|
- });
|
|
|
-
|
|
|
- t.Ready += FirstDialogToplevel;
|
|
|
-
|
|
|
- void FirstDialogToplevel (object sender, EventArgs args)
|
|
|
- {
|
|
|
- var od = new OpenDialog ();
|
|
|
- od.Ready += SecondDialogToplevel;
|
|
|
-
|
|
|
- Application.MainLoop.AddTimeout (TimeSpan.FromMilliseconds (100), (_) => {
|
|
|
- count1++;
|
|
|
- if (count2 == 5) {
|
|
|
- log2 = true;
|
|
|
- }
|
|
|
- if (count2 == 4 && count1 == 5 && count == 5) {
|
|
|
- fromFirstStillKnowSecondIsRunning = true;
|
|
|
- }
|
|
|
- if (count1 == 20) {
|
|
|
- Assert.Equal (20, count1);
|
|
|
- Application.RequestStop ();
|
|
|
- return false;
|
|
|
- }
|
|
|
- return true;
|
|
|
- });
|
|
|
-
|
|
|
- Application.Run (od);
|
|
|
- }
|
|
|
|
|
|
- void SecondDialogToplevel (object sender, EventArgs args)
|
|
|
- {
|
|
|
- var d = new Dialog ();
|
|
|
-
|
|
|
- Application.MainLoop.AddTimeout (TimeSpan.FromMilliseconds (100), (_) => {
|
|
|
- count2++;
|
|
|
- if (count < 30) {
|
|
|
- log = true;
|
|
|
- }
|
|
|
- if (count2 == 10) {
|
|
|
- Assert.Equal (10, count2);
|
|
|
- Application.RequestStop ();
|
|
|
- return false;
|
|
|
- }
|
|
|
- return true;
|
|
|
- });
|
|
|
-
|
|
|
- Application.Run (d);
|
|
|
- }
|
|
|
-
|
|
|
- Application.Run ();
|
|
|
- Application.Shutdown ();
|
|
|
}
|
|
|
|
|
|
- [Theory]
|
|
|
+
|
|
|
+ [Theory, TestRespondersDisposed]
|
|
|
[InlineData (1)]
|
|
|
[InlineData (2)]
|
|
|
[InlineData (3)]
|
|
@@ -544,8 +476,7 @@ namespace Terminal.Gui.ViewTests {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- [Fact]
|
|
|
- [AutoInitShutdown]
|
|
|
+ [Fact, AutoInitShutdown]
|
|
|
public void Internal_Tests ()
|
|
|
{
|
|
|
Assert.Equal (new [] { View.Direction.Forward, View.Direction.Backward },
|
|
@@ -574,7 +505,7 @@ namespace Terminal.Gui.ViewTests {
|
|
|
Assert.Equal (top.Bounds, view.ScreenClip (top.Bounds));
|
|
|
Assert.True (view.LayoutStyle == LayoutStyle.Absolute);
|
|
|
|
|
|
- Application.Begin (top);
|
|
|
+ var runState = Application.Begin (top);
|
|
|
|
|
|
view.Width = Dim.Fill ();
|
|
|
view.Height = Dim.Fill ();
|
|
@@ -618,10 +549,11 @@ namespace Terminal.Gui.ViewTests {
|
|
|
view.ViewToScreen (0, 0, out rcol, out rrow);
|
|
|
Assert.Equal (-41, rcol);
|
|
|
Assert.Equal (-13, rrow);
|
|
|
+
|
|
|
+ Application.End (runState);
|
|
|
}
|
|
|
|
|
|
- [Fact]
|
|
|
- [AutoInitShutdown]
|
|
|
+ [Fact, AutoInitShutdown]
|
|
|
public void Visible_Sets_Also_Sets_Subviews ()
|
|
|
{
|
|
|
var button = new Button ("Click Me");
|
|
@@ -689,8 +621,7 @@ namespace Terminal.Gui.ViewTests {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- [Fact]
|
|
|
- [AutoInitShutdown]
|
|
|
+ [Fact, AutoInitShutdown]
|
|
|
public void GetTopSuperView_Test ()
|
|
|
{
|
|
|
var v1 = new View ();
|
|
@@ -713,9 +644,18 @@ namespace Terminal.Gui.ViewTests {
|
|
|
|
|
|
Assert.Equal (top1, v1.GetTopSuperView ());
|
|
|
Assert.Equal (top2, v2.GetTopSuperView ());
|
|
|
- }
|
|
|
-
|
|
|
|
|
|
+ v1.Dispose ();
|
|
|
+ fv1.Dispose ();
|
|
|
+ tf1.Dispose ();
|
|
|
+ w1.Dispose ();
|
|
|
+ top1.Dispose ();
|
|
|
+ v2.Dispose ();
|
|
|
+ fv2.Dispose ();
|
|
|
+ tf2.Dispose ();
|
|
|
+ w2.Dispose ();
|
|
|
+ top2.Dispose ();
|
|
|
+ }
|
|
|
|
|
|
[Fact, AutoInitShutdown]
|
|
|
public void Clear_Can_Use_Driver_AddRune_Or_AddStr_Methods ()
|
|
@@ -868,7 +808,7 @@ namespace Terminal.Gui.ViewTests {
|
|
|
//Assert.Equal (verticalView.Frame.Size, verticalView.GetSizeNeededForTextWithoutHotKey ());
|
|
|
}
|
|
|
|
|
|
- [Fact]
|
|
|
+ [Fact, TestRespondersDisposed]
|
|
|
public void IsAdded_Added_Removed ()
|
|
|
{
|
|
|
var top = new Toplevel ();
|
|
@@ -878,6 +818,9 @@ namespace Terminal.Gui.ViewTests {
|
|
|
Assert.True (view.IsAdded);
|
|
|
top.Remove (view);
|
|
|
Assert.False (view.IsAdded);
|
|
|
+
|
|
|
+ top.Dispose ();
|
|
|
+ view.Dispose ();
|
|
|
}
|
|
|
|
|
|
[Fact, AutoInitShutdown]
|
|
@@ -911,6 +854,7 @@ namespace Terminal.Gui.ViewTests {
|
|
|
│ │
|
|
|
└────────────────────────────┘
|
|
|
", output);
|
|
|
+ Application.End (rs);
|
|
|
}
|
|
|
|
|
|
[Fact, AutoInitShutdown]
|
|
@@ -940,6 +884,7 @@ namespace Terminal.Gui.ViewTests {
|
|
|
|
|
|
view.Enabled = false;
|
|
|
Assert.Equal (view.ColorScheme.Disabled, view.GetNormalColor ());
|
|
|
+ view.Dispose ();
|
|
|
}
|
|
|
|
|
|
[Fact, AutoInitShutdown]
|
|
@@ -951,6 +896,7 @@ namespace Terminal.Gui.ViewTests {
|
|
|
|
|
|
view.Enabled = false;
|
|
|
Assert.Equal (view.ColorScheme.Disabled, view.GetHotNormalColor ());
|
|
|
+ view.Dispose ();
|
|
|
}
|
|
|
|
|
|
[Theory, AutoInitShutdown]
|
|
@@ -973,7 +919,7 @@ namespace Terminal.Gui.ViewTests {
|
|
|
root.Add (v);
|
|
|
|
|
|
Application.Top.Add (root);
|
|
|
- Application.Begin (Application.Top);
|
|
|
+ var runState = Application.Begin (Application.Top);
|
|
|
|
|
|
if (label) {
|
|
|
Assert.True (v.AutoSize);
|
|
@@ -1014,6 +960,7 @@ cccccccccccccccccccc", output);
|
|
|
222222222222222222220
|
|
|
111111111111111111110", attributes);
|
|
|
}
|
|
|
+ Application.End (runState);
|
|
|
}
|
|
|
|
|
|
public class DerivedView : View {
|
|
@@ -1081,7 +1028,7 @@ cccccccccccccccccccc", output);
|
|
|
};
|
|
|
var top = Application.Top;
|
|
|
top.Add (label, view);
|
|
|
- Application.Begin (top);
|
|
|
+ var runState = Application.Begin (top);
|
|
|
|
|
|
top.Draw ();
|
|
|
TestHelpers.AssertDriverContentsWithFrameAre (@"
|
|
@@ -1100,6 +1047,7 @@ At 0,0
|
|
|
TestHelpers.AssertDriverContentsWithFrameAre (@"
|
|
|
At 0,0
|
|
|
A text wit", output);
|
|
|
+ Application.End (runState);
|
|
|
}
|
|
|
|
|
|
[Fact, AutoInitShutdown]
|
|
@@ -1115,7 +1063,7 @@ At 0,0
|
|
|
};
|
|
|
var top = Application.Top;
|
|
|
top.Add (label, view);
|
|
|
- Application.Begin (top);
|
|
|
+ var runState = Application.Begin (top);
|
|
|
|
|
|
top.Draw ();
|
|
|
TestHelpers.AssertDriverContentsWithFrameAre (@"
|
|
@@ -1135,6 +1083,7 @@ At 0,0
|
|
|
TestHelpers.AssertDriverContentsWithFrameAre (@"
|
|
|
At 0,0
|
|
|
A text wit", output);
|
|
|
+ Application.End (runState);
|
|
|
}
|
|
|
|
|
|
[Fact, AutoInitShutdown]
|
|
@@ -1150,7 +1099,7 @@ At 0,0
|
|
|
};
|
|
|
var top = Application.Top;
|
|
|
top.Add (label, view);
|
|
|
- Application.Begin (top);
|
|
|
+ var runState = Application.Begin (top);
|
|
|
|
|
|
view.Draw ();
|
|
|
TestHelpers.AssertDriverContentsWithFrameAre (@"
|
|
@@ -1171,6 +1120,7 @@ At 0,0
|
|
|
A text wit
|
|
|
A text with some long width
|
|
|
and also with two lines. ", output);
|
|
|
+ Application.End (runState);
|
|
|
}
|
|
|
|
|
|
[Fact, AutoInitShutdown]
|
|
@@ -1186,7 +1136,7 @@ At 0,0
|
|
|
};
|
|
|
var top = Application.Top;
|
|
|
top.Add (label, view);
|
|
|
- Application.Begin (top);
|
|
|
+ var runState = Application.Begin (top);
|
|
|
|
|
|
view.Draw ();
|
|
|
TestHelpers.AssertDriverContentsWithFrameAre (@"
|
|
@@ -1208,6 +1158,7 @@ At 0,0
|
|
|
A text wit
|
|
|
A text with some long width
|
|
|
and also with two lines. ", output);
|
|
|
+ Application.End (runState);
|
|
|
}
|
|
|
|
|
|
[Fact, AutoInitShutdown]
|
|
@@ -1223,7 +1174,7 @@ At 0,0
|
|
|
};
|
|
|
var top = Application.Top;
|
|
|
top.Add (label, view);
|
|
|
- Application.Begin (top);
|
|
|
+ var runState = Application.Begin (top);
|
|
|
|
|
|
TestHelpers.AssertDriverContentsWithFrameAre (@"
|
|
|
At 0,0
|
|
@@ -1243,6 +1194,7 @@ At 0,0
|
|
|
|
|
|
|
|
|
A text wit", output);
|
|
|
+ Application.End (runState);
|
|
|
}
|
|
|
|
|
|
[Fact, AutoInitShutdown]
|
|
@@ -1258,7 +1210,7 @@ At 0,0
|
|
|
};
|
|
|
var top = Application.Top;
|
|
|
top.Add (label, view);
|
|
|
- Application.Begin (top);
|
|
|
+ var runState = Application.Begin (top);
|
|
|
|
|
|
top.Draw ();
|
|
|
TestHelpers.AssertDriverContentsWithFrameAre (@"
|
|
@@ -1280,6 +1232,7 @@ At 0,0
|
|
|
|
|
|
|
|
|
A text wit", output);
|
|
|
+ Application.End (runState);
|
|
|
}
|
|
|
|
|
|
[Fact, AutoInitShutdown]
|
|
@@ -1295,7 +1248,7 @@ At 0,0
|
|
|
};
|
|
|
var top = Application.Top;
|
|
|
top.Add (label, view);
|
|
|
- Application.Begin (top);
|
|
|
+ var runState = Application.Begin (top);
|
|
|
|
|
|
view.Draw ();
|
|
|
TestHelpers.AssertDriverContentsWithFrameAre (@"
|
|
@@ -1313,6 +1266,7 @@ At 0,0
|
|
|
|
|
|
A text with some long width
|
|
|
A text witith two lines. ", output);
|
|
|
+ Application.End (runState);
|
|
|
}
|
|
|
|
|
|
[Fact, AutoInitShutdown]
|
|
@@ -1328,7 +1282,7 @@ At 0,0
|
|
|
};
|
|
|
var top = Application.Top;
|
|
|
top.Add (label, view);
|
|
|
- Application.Begin (top);
|
|
|
+ var runState = Application.Begin (top);
|
|
|
|
|
|
view.Draw ();
|
|
|
TestHelpers.AssertDriverContentsWithFrameAre (@"
|
|
@@ -1350,6 +1304,7 @@ At 0,0
|
|
|
|
|
|
A text with some long width
|
|
|
A text witith two lines. ", output);
|
|
|
+ Application.End (runState);
|
|
|
}
|
|
|
|
|
|
[Fact, AutoInitShutdown]
|
|
@@ -1377,10 +1332,12 @@ At 0,0
|
|
|
───────────
|
|
|
222";
|
|
|
TestHelpers.AssertDriverContentsAre (looksLike, output);
|
|
|
+ v.Dispose ();
|
|
|
+ top.Dispose ();
|
|
|
+ bottom.Dispose ();
|
|
|
}
|
|
|
|
|
|
- [Fact]
|
|
|
- [AutoInitShutdown]
|
|
|
+ [Fact, AutoInitShutdown]
|
|
|
public void Frame_Set_After_Initialize_Update_NeededDisplay ()
|
|
|
{
|
|
|
var frame = new FrameView ();
|
|
@@ -1409,7 +1366,7 @@ At 0,0
|
|
|
|
|
|
top.Add (frame);
|
|
|
|
|
|
- Application.Begin (top);
|
|
|
+ var runState = Application.Begin (top);
|
|
|
|
|
|
top.LayoutComplete += (s, e) => {
|
|
|
Assert.Equal (new Rect (0, 0, 80, 25), top._needsDisplayRect);
|
|
@@ -1447,9 +1404,10 @@ At 0,0
|
|
|
";
|
|
|
|
|
|
TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
|
|
|
+ Application.End (runState);
|
|
|
}
|
|
|
|
|
|
- [Fact]
|
|
|
+ [Fact, TestRespondersDisposed]
|
|
|
public void Dispose_View ()
|
|
|
{
|
|
|
var view = new View ();
|
|
@@ -1457,10 +1415,15 @@ At 0,0
|
|
|
Assert.NotNull (view.Border);
|
|
|
Assert.NotNull (view.Padding);
|
|
|
|
|
|
+#if DEBUG_IDISPOSABLE
|
|
|
+ Assert.Equal (4, Responder.Instances.Count);
|
|
|
+#endif
|
|
|
+
|
|
|
view.Dispose ();
|
|
|
Assert.Null (view.Margin);
|
|
|
Assert.Null (view.Border);
|
|
|
Assert.Null (view.Padding);
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
}
|