|
@@ -1,3 +1,4 @@
|
|
|
+using SixLabors.ImageSharp.Processing.Processors.Quantization;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Linq;
|
|
@@ -23,21 +24,38 @@ namespace UnitTests.ViewsTests {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- [Fact]
|
|
|
- [AutoInitShutdown]
|
|
|
- public void TestViewsDisposeCorrectly ()
|
|
|
+ [Theory]
|
|
|
+ [InlineData (true)]
|
|
|
+ [InlineData (false)]
|
|
|
+ public void TestViewsDisposeCorrectly (bool callShutdown)
|
|
|
{
|
|
|
- var reference = DoTest ();
|
|
|
- for (var i = 0; i < 10 && reference.IsAlive; i++) {
|
|
|
+ var refs = DoTest (callShutdown);
|
|
|
+ //var reference = refs [0];
|
|
|
+ for (var i = 0; i < 10 && refs [0].IsAlive; i++) {
|
|
|
GC.Collect ();
|
|
|
GC.WaitForPendingFinalizers ();
|
|
|
}
|
|
|
+ foreach (var reference in refs) {
|
|
|
+ if (reference.IsAlive) {
|
|
|
#if DEBUG_IDISPOSABLE
|
|
|
- if (reference.IsAlive) {
|
|
|
- Assert.True (((View)reference.Target).WasDisposed);
|
|
|
- Assert.Fail ($"Some Views didnt get Garbage Collected: {((View)reference.Target).Subviews}");
|
|
|
- }
|
|
|
+ Assert.True (((View)reference.Target).WasDisposed);
|
|
|
#endif
|
|
|
+ string alive = ""; // Instead of just checking the subviews of the container, we now iterate through a list
|
|
|
+ foreach (var r in refs) { // of Weakreferences Referencing every View that was tested. This makes more sense because
|
|
|
+ if (r.IsAlive) { // View.Dispose removes all of its subviews, wich is why View.Subviews is always empty
|
|
|
+ if (r == refs [0]) { // after View.Dispose has run. Luckily I didnt discover any more bugs or this wouldv'e
|
|
|
+ alive += "\n View (Container)"; // been a little bit annoying to find an answer for. Thanks to BDisp for listening to
|
|
|
+ } // me and giving his best to help me fix this thing. If you take a look at the commit log
|
|
|
+ alive += ",\n--"; // you will find that he did most of the work. -a-usr
|
|
|
+ alive += r.Target.GetType ().Name;
|
|
|
+ } // NOTE: DELETE BEFORE NEXT COMMIT
|
|
|
+ }
|
|
|
+ Assert.Fail ($"Some Views didnt get Garbage Collected: {alive}");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!callShutdown) {
|
|
|
+ Application.Shutdown ();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
void getSpecialParams ()
|
|
@@ -46,11 +64,16 @@ namespace UnitTests.ViewsTests {
|
|
|
//special_params.Add (typeof (LineView), new object [] { Orientation.Horizontal });
|
|
|
}
|
|
|
|
|
|
- WeakReference DoTest ()
|
|
|
+ List<WeakReference> DoTest (bool callShutdown)
|
|
|
{
|
|
|
+ var driver = new FakeDriver ();
|
|
|
+ Application.Init (driver, new FakeMainLoop (driver));
|
|
|
getSpecialParams ();
|
|
|
View Container = new View ();
|
|
|
- Toplevel top = Application.Top;
|
|
|
+ List<WeakReference> refs = new List<WeakReference> { new WeakReference (Container, true) };
|
|
|
+ Container.Add (new View ());
|
|
|
+ Toplevel top = new ();
|
|
|
+ var state = Application.Begin (top);
|
|
|
var views = GetViews ();
|
|
|
foreach (var view in views) {
|
|
|
View instance;
|
|
@@ -63,6 +86,8 @@ namespace UnitTests.ViewsTests {
|
|
|
|
|
|
Assert.NotNull (instance);
|
|
|
Container.Add (instance);
|
|
|
+
|
|
|
+ refs.Add (new WeakReference (instance, true));
|
|
|
output.WriteLine ($"Added instance of {view}!");
|
|
|
}
|
|
|
top.Add (Container);
|
|
@@ -72,9 +97,22 @@ namespace UnitTests.ViewsTests {
|
|
|
}
|
|
|
|
|
|
top.Remove (Container);
|
|
|
- WeakReference reference = new (Container, true);
|
|
|
+ Application.End (state);
|
|
|
+ Assert.True (refs.All (r => r.IsAlive));
|
|
|
+#if DEBUG_IDISPOSABLE
|
|
|
+ Assert.True (top.WasDisposed);
|
|
|
+ Assert.False (Container.WasDisposed);
|
|
|
+#endif
|
|
|
+ Assert.Null (Application.Top);
|
|
|
Container.Dispose ();
|
|
|
- return reference;
|
|
|
+#if DEBUG_IDISPOSABLE
|
|
|
+ Assert.True (Container.WasDisposed);
|
|
|
+#endif
|
|
|
+ if (callShutdown) {
|
|
|
+ Application.Shutdown ();
|
|
|
+ }
|
|
|
+
|
|
|
+ return refs;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|