Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #3368. Fix unit tests to dispose properly #3369

Merged
merged 55 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
013482a
Updated docs
tig Apr 1, 2024
dfe746a
Updated View.Add/Remove API docs
tig Apr 1, 2024
327957a
Fixed some unit tests. Prepared for Issue #3368
tig Apr 1, 2024
3b3906a
Updated Add/Remove API docs
tig Apr 1, 2024
52322a3
Rebased.
tig May 30, 2024
486ca8f
Fixed DialogTests
tig May 30, 2024
c39c67a
Fixed WizardTests
tig May 30, 2024
161bc27
Fixed AttributeTests
tig May 30, 2024
2f449e5
Fixed RulerTests
tig May 30, 2024
b6b730e
Fixed Thicknesstests
tig May 30, 2024
d318f22
Fixed LineCanvasTests
tig May 30, 2024
1c8622a
Fixed ThicknessTests
tig May 30, 2024
d775e85
Fixed FileDialogTests
tig May 30, 2024
8abf1df
Fixed EscSeq tests
tig May 30, 2024
ce89434
Fixed DimFillTests
tig May 30, 2024
37653cd
Fixed DimTests
tig May 30, 2024
315438a
Fixed PosAnchorEndTests
tig May 30, 2024
90ef9fd
Fixed PosCenterTests
tig May 30, 2024
c6a57da
Fixed PosPercentTests
tig May 30, 2024
801c2d2
Fixed AppendAutoCompleteTests
tig May 30, 2024
059d8f4
Fixed AutoCompleteTests
tig May 30, 2024
dd99231
Fixed CheckBoxtests
tig May 30, 2024
adac560
Fixed ColorPickerTests
tig May 30, 2024
43e34c3
Fixed ComboBoxTests
tig May 30, 2024
6c310c7
Fixed ContextMenuTests
tig May 30, 2024
7c34751
Fixed Frameviewtest
tig May 30, 2024
3c3d55f
Fixed HexViewTest
tig May 30, 2024
6b089fb
Fixed Labeltests
tig May 30, 2024
1872e6a
Fixed ListViewTests
tig May 30, 2024
8781708
Fixed MenuBarTests
tig May 30, 2024
123149c
Fixed OverlappedTests
tig May 30, 2024
852922b
Fixed RadioTests
tig May 30, 2024
31b6efe
Fixed ScrollBarViewTests
tig May 30, 2024
ccdaada
Fixed ScrollViewTests
tig May 30, 2024
6db3d37
Fixed ScrollViewTests
tig May 30, 2024
7704a2e
Fixed SpinnerViewTests
tig May 30, 2024
4f3d721
Fixed StatusBarTests
tig May 30, 2024
07ba55c
Fixed TableViewTests
tig May 30, 2024
6b2585b
Fixed TabViewTests
tig May 30, 2024
c5d34b2
Fixed TextFieldTests
tig May 30, 2024
db0f066
Fixed TextViewTests
tig May 30, 2024
82a1397
Fixed ToplevelTests
tig May 30, 2024
dae84a2
Fixed TreeTableSourceTests
tig May 30, 2024
7973d53
Fixed TreeViewTests
tig May 30, 2024
349f1f6
Fixed WindowTests
tig May 30, 2024
94ce280
Fixed BorderTests
tig May 30, 2024
577ef9e
Fixed DrawTests
tig May 30, 2024
6abd2e4
Fixed MarginTests
tig May 30, 2024
7896210
Fixed NavigationTests
tig May 30, 2024
1a4cf43
Fixed PaddingTests
tig May 30, 2024
0bd2118
Fixed TextTests
tig May 30, 2024
0e39f5d
Fixed ViewKeyBindingTestsTests
tig May 30, 2024
f32df9a
ReFixed DrawTests
tig May 30, 2024
dde1fe4
Fixed unit test warnings
tig May 30, 2024
7046914
Merge branch 'v2_develop' into v2_3368_unit_tests_dispose
tig May 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion Terminal.Gui/View/View.cs
Original file line number Diff line number Diff line change
Expand Up @@ -503,9 +503,23 @@ public virtual bool OnTitleChanging (string oldTitle, string newTitle)
/// <returns></returns>
public override string ToString () { return $"{GetType ().Name}({Id}){Frame}"; }

/// <inheritdoc/>
/// <summary>Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.</summary>
/// <remarks>
/// <para>
/// Subviews added to this view via <see cref="Add(View)"/> have their lifetime owned by this view and <see cref="Dispose"/> will
/// dispose them. To prevent this, and have the creator of the Subview instance handle disposal, use <see cref="Remove"/> to remove
/// the subview first.
/// </para>
/// <para>
/// If disposing equals true, the method has been called directly or indirectly by a user's code. Managed and
/// unmanaged resources can be disposed. If disposing equals false, the method has been called by the runtime from
/// inside the finalizer, and you should not reference other objects. Only unmanaged resources can be disposed.
/// </para>
/// </remarks>
/// <param name="disposing"></param>
protected override void Dispose (bool disposing)
{
// BUGBUG: We should only dispose these objects if disposing == true
LineCanvas.Dispose ();

DisposeAdornments ();
Expand Down
4 changes: 2 additions & 2 deletions Terminal.Gui/Views/TableView/TableView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -908,10 +908,10 @@ public override void OnDrawContent (Rectangle viewport)
// What columns to render at what X offset in viewport
ColumnToRender [] columnsToRender = CalculateViewport (Viewport).ToArray ();

Driver.SetAttribute (GetNormalColor ());
Driver?.SetAttribute (GetNormalColor ());

//invalidate current row (prevents scrolling around leaving old characters in the frame
Driver.AddStr (new string (' ', Viewport.Width));
Driver?.AddStr (new string (' ', Viewport.Width));

var line = 0;

Expand Down
8 changes: 4 additions & 4 deletions UnitTests/Application/ApplicationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,12 @@ public void Begin_Null_Toplevel_Throws ()
public void Begin_Sets_Application_Top_To_Console_Size ()
{
Assert.Null (Application.Top);
Application.Begin (new ());
Toplevel top = new ();
Application.Begin (top);
Assert.Equal (new (0, 0, 80, 25), Application.Top.Frame);
((FakeDriver)Application.Driver).SetBufferSize (5, 5);
Assert.Equal (new (0, 0, 5, 5), Application.Top.Frame);
top.Dispose ();
}

[Fact]
Expand Down Expand Up @@ -265,8 +267,6 @@ public void Init_Unbalanced_Throws ()
{
Application.Init (new FakeDriver ());

Toplevel topLevel = null;

Assert.Throws<InvalidOperationException> (
() =>
Application.InternalInit (
Expand All @@ -280,7 +280,6 @@ public void Init_Unbalanced_Throws ()
Assert.Null (Application.Driver);

// Now try the other way
topLevel = null;
Application.InternalInit (new FakeDriver ());

Assert.Throws<InvalidOperationException> (() => Application.Init (new FakeDriver ()));
Expand Down Expand Up @@ -347,6 +346,7 @@ public void Internal_Properties_Correct ()
Assert.Null (Application.MouseGrabView); // public
Assert.Null (Application.WantContinuousButtonPressedView); // public
Assert.False (Application.MoveToOverlappedChild (Application.Top));
Application.Top.Dispose ();
}

// Invoke Tests
Expand Down
5 changes: 5 additions & 0 deletions UnitTests/Application/KeyboardTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ public void EnsuresTopOnFront_CanFocus_False_By_Keyboard ()
Assert.True (win2.CanFocus);
Assert.True (win2.HasFocus);
Assert.Equal ("win2", ((Window)top.Subviews [^1]).Title);
top.Dispose ();
}

[Fact]
Expand Down Expand Up @@ -224,6 +225,7 @@ public void EnsuresTopOnFront_CanFocus_True_By_Keyboard_ ()
Assert.True (win2.CanFocus);
Assert.False (win2.HasFocus);
Assert.Equal ("win", ((Window)top.Subviews [^1]).Title);
top.Dispose ();
}

[Fact]
Expand Down Expand Up @@ -358,6 +360,7 @@ public void OnKeyDown_Application_KeyBinding ()
Assert.True (view.ApplicationCommand);
Assert.True (view.HotKeyCommand);
Assert.False (view.FocusedCommand);
top.Dispose ();
}

[Fact]
Expand Down Expand Up @@ -385,6 +388,7 @@ public void OnKeyDown_Application_KeyBinding_Negative ()
Assert.False (view.ApplicationCommand);
Assert.False (view.HotKeyCommand);
Assert.False (view.FocusedCommand);
top.Dispose ();
}

[Fact]
Expand Down Expand Up @@ -423,6 +427,7 @@ public void QuitKey_Getter_Setter ()

// Reset the QuitKey to avoid throws errors on another tests
Application.QuitKey = Key.Q.WithCtrl;
top.Dispose ();
}

// test Application key Bindings
Expand Down
2 changes: 2 additions & 0 deletions UnitTests/Application/MainLoopTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,7 @@ public async Task InvokeLeakTest ()
await task; // Propagate exception if any occurred

Assert.Equal (numIncrements * numPasses, tbCounter);
top.Dispose ();
}

[Theory]
Expand Down Expand Up @@ -714,6 +715,7 @@ int pfour
};

Application.Run (top);
top.Dispose ();

Assert.True (taskCompleted);
Assert.Equal (clickMe, btn.Text);
Expand Down
4 changes: 4 additions & 0 deletions UnitTests/Application/MouseTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ bool expectedClicked

Application.OnMouseEvent (mouseEvent);
Assert.Equal (expectedClicked, clicked);
top.Dispose ();
}

/// <summary>
Expand Down Expand Up @@ -224,6 +225,7 @@ bool expectedClicked

Application.OnMouseEvent (mouseEvent);
Assert.Equal (expectedClicked, clicked);
top.Dispose ();
}

#endregion mouse coordinate tests
Expand Down Expand Up @@ -290,6 +292,7 @@ public void MouseGrabView_WithNullMouseEventView ()
};

Application.Run (top);
top.Dispose ();
}

[Fact]
Expand Down Expand Up @@ -396,6 +399,7 @@ public void View_Is_Responsible_For_Calling_UnGrabMouse_Before_Being_Disposed ()
Application.OnMouseEvent (new () { Position = new (0, 0), Flags = MouseFlags.Button1Pressed });
Assert.Null (Application.MouseGrabView);
Assert.Equal (0, count);
top.Dispose ();
}
#endregion
}
11 changes: 10 additions & 1 deletion UnitTests/Dialogs/DialogTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -906,8 +906,10 @@ public void Dialog_In_Window_With_Size_One_Button_Aligns ()
};

Run (dlg);
dlg.Dispose ();
};
Run (win);
win.Dispose ();
}

[Theory]
Expand Down Expand Up @@ -988,6 +990,7 @@ public void Dialog_In_Window_Without_Size_One_Button_Aligns (int height, string
Height = Dim.Percent (85)
};
Run (dlg);
dlg.Dispose ();
}
else if (iterations == 1)
{
Expand All @@ -1001,6 +1004,7 @@ public void Dialog_In_Window_Without_Size_One_Button_Aligns (int height, string
};

Run (win);
win.Dispose ();
}

[Fact]
Expand Down Expand Up @@ -1134,6 +1138,7 @@ public void Location_Default ()
// Default location is centered, so 100 / 2 - 85 / 2 = 7
var expected = 7;
Assert.Equal (new (expected, expected), d.Frame.Location);
d.Dispose ();
}

[Fact]
Expand All @@ -1147,6 +1152,7 @@ public void Location_Not_Default ()
// Default location is centered, so 100 / 2 - 85 / 2 = 7
var expected = 1;
Assert.Equal (new (expected, expected), d.Frame.Location);
d.Dispose ();
}

[Fact]
Expand All @@ -1170,6 +1176,7 @@ public void Location_When_Application_Top_Not_Default ()
└───┘",
_output
);
d.Dispose ();
}

[Fact]
Expand Down Expand Up @@ -1263,6 +1270,7 @@ public void Location_When_Not_Application_Top_Not_Default ()

((FakeDriver)Driver).SetBufferSize (20, 10);
Run (top);
top.Dispose ();
}

[Fact]
Expand All @@ -1282,14 +1290,15 @@ public void One_Button_Works ()
int width = buttonRow.Length;
d.SetBufferSize (buttonRow.Length, 10);

(runstate, Dialog _) = RunButtonTestDialog (
(runstate, Dialog dlg) = RunButtonTestDialog (
title,
width,
Alignment.Center,
new Button { Text = btnText }
);
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
End (runstate);
dlg.Dispose ();
}

[Fact]
Expand Down
Loading
Loading