Fix issue where the TestViewsDisposeCorrectly was not doing what it was supposed to do (#2964)

* add Disposal Test and fix an ssue where the CopyClipboard test was failing

* Update ViewDisposalTest.cs

* Update ViewDisposalTest.cs: Some Formatting, and adding code comments.

* Fix ViewDisposalTests (Wasn't working the way it was supposed to)

* update test

* update test

* update test

* try to fix as many conflicts as possible

* make test output prettier

* fix formatting

* Fix Subviews not being empty after disposing on all views.

* The fail cause was Application.Top not being disposed.

* Fix others containers that weren't being removed.

* Revert "The fail cause was Application.Top not being disposed."

This reverts commit 0c2183ed9e.

* Application.Top isn't null and need disposing.

* Fixes #2985. Application.RunState must be responsible for dispose the Toplevel property.

* Change the unit test with ans without Application.Shutdown method.

* Update ViewDisposeTests to actually check wether ALL views have been disposed (not just container)

* small additional check just to be safe

* Update ViewDisposalTest.cs: Formatting

* Update ViewDisposalTest.cs: Minor change to re-trigger Action

TestVKPacket is acting up again. Maybe the test is running async and is receiving scan codes from other instances?

---------

Co-authored-by: John Züchler <john.zuechler@eks-intec.de>
Co-authored-by: BDisp <bd.bdisp@gmail.com>
Co-authored-by: Tig <tig@users.noreply.github.com>
This commit is contained in:
usr
2023-11-15 17:22:22 +01:00
committed by GitHub
parent 91865eed22
commit c7942ae3bb
12 changed files with 140 additions and 50 deletions

View File

@@ -48,12 +48,11 @@ namespace Terminal.Gui.ApplicationTests {
rs = new Application.RunState (top);
Assert.NotNull (rs);
// Should throw because Toplevel was not cleaned up
Assert.Throws<InvalidOperationException> (() => rs.Dispose ());
// Should not throw because Toplevel was cleaned up
var exception = Record.Exception (() => rs.Dispose ());
Assert.Null (exception);
rs.Toplevel.Dispose ();
rs.Toplevel = null;
rs.Dispose ();
Assert.Null (rs.Toplevel);
#if DEBUG_IDISPOSABLE
Assert.True (rs.WasDisposed);
Assert.True (top.WasDisposed);
@@ -63,7 +62,7 @@ namespace Terminal.Gui.ApplicationTests {
void Init ()
{
Application.Init (new FakeDriver ());
Assert.NotNull (Application.Driver);
Assert.NotNull (Application.MainLoop);
Assert.NotNull (SynchronizationContext.Current);
@@ -74,7 +73,7 @@ namespace Terminal.Gui.ApplicationTests {
Application.Shutdown ();
#if DEBUG_IDISPOSABLE
// Validate there are no outstanding RunState-based instances left
foreach (var inst in Application.RunState.Instances) Assert.True (inst.WasDisposed);
foreach (var inst in Application.RunState.Instances) Assert.True (inst.WasDisposed);
#endif
}
@@ -94,7 +93,7 @@ namespace Terminal.Gui.ApplicationTests {
Application.End (rs);
Assert.Null (Application.Current);
Assert.NotNull (Application.Top);
Assert.Null (Application.Top);
Assert.NotNull (Application.MainLoop);
Assert.NotNull (Application.Driver);
@@ -104,7 +103,46 @@ namespace Terminal.Gui.ApplicationTests {
Assert.True (rs.WasDisposed);
#endif
Assert.Null (Application.MainLoop);
Assert.Null (Application.Driver);
}
WeakReference CreateToplevelInstance ()
{
// Setup Mock driver
Init ();
var top = new Toplevel ();
var rs = Application.Begin (top);
Assert.NotNull (rs);
Assert.Equal (top, Application.Current);
Assert.Equal (top, Application.Top);
Application.End (rs);
#if DEBUG_IDISPOSABLE
Assert.True (rs.WasDisposed);
Assert.True (top.WasDisposed);
#endif
Assert.Null (Application.Current);
Assert.Null (Application.Top);
Assert.NotNull (top);
Assert.NotNull (Application.MainLoop);
Assert.NotNull (Application.Driver);
return new WeakReference (top, true);
}
[Fact]
public void Begin_End_Cleans_Up_RunState_Without_Shutdown ()
{
WeakReference wrInstance = CreateToplevelInstance ();
GC.Collect ();
GC.WaitForPendingFinalizers ();
Assert.False (wrInstance.IsAlive);
// Shutdown Mock driver
Shutdown ();
Assert.Null (Application.MainLoop);
Assert.Null (Application.Driver);
}