ソースを参照

Tweaked unit tests

Tig 1 年間 前
コミット
73a6e66139

+ 8 - 5
Terminal.Gui/Application.cs

@@ -383,6 +383,10 @@ public static partial class Application
             throw new ArgumentNullException (nameof (Toplevel));
         }
 
+#if DEBUG_IDISPOSABLE
+        Debug.Assert (!Toplevel.WasDisposed);
+#endif
+
         if (Toplevel.IsOverlappedContainer && OverlappedTop != Toplevel && OverlappedTop is { })
         {
             throw new InvalidOperationException ("Only one Overlapped Container is allowed.");
@@ -1028,12 +1032,11 @@ public static partial class Application
             Refresh ();
         }
 
-        if (Top == runState.Toplevel)
-        {
-           // Top = null;
-        }
+        //if (Top == runState.Toplevel)
+        //{
+        //   Top = null;
+        //}
 
-        Debug.Assert(Current != runState.Toplevel);
         runState.Toplevel?.Dispose ();
         runState.Toplevel = null;
         runState.Dispose ();

+ 21 - 1
UnitTests/Application/ApplicationTests.cs

@@ -46,6 +46,26 @@ public class ApplicationTests
         Assert.Equal (new Rectangle (0, 0, 5, 5), Application.Top.Frame);
     }
 
+    [Fact]
+    public void End_Disposes_Runstate_Toplevel ()
+    {
+        Init ();
+
+        RunState rs = Application.Begin (Application.Top);
+        Application.End (rs);
+
+#if DEBUG_IDISPOSABLE
+        Assert.True (rs.WasDisposed);
+        Assert.True (Application.Top.WasDisposed);
+#endif
+
+        Assert.Null (rs.Toplevel);
+
+        Shutdown ();
+
+        Assert.Null (Application.Top);
+    }
+
     [Fact]
     public void Init_Begin_End_Cleans_Up ()
     {
@@ -678,7 +698,7 @@ public class ApplicationTests
                                          Application.OnMouseEvent (
                                                                    new MouseEventEventArgs (
                                                                                             new MouseEvent
-                                                                                                { X = 0, Y = 0, Flags = MouseFlags.ReportMousePosition }
+                                                                                            { X = 0, Y = 0, Flags = MouseFlags.ReportMousePosition }
                                                                                            )
                                                                   );
                                          Assert.False (top.NeedsDisplay);

+ 0 - 37
UnitTests/Views/LabelTests.cs

@@ -201,52 +201,15 @@ public class LabelTests
     }
 
     [Fact]
-    [AutoInitShutdown]
     public void Constructors_Defaults ()
     {
         var label = new Label ();
         Assert.Equal (string.Empty, label.Text);
-        Application.Top.Add (label);
-        RunState rs = Application.Begin (Application.Top);
-
         Assert.Equal (TextAlignment.Left, label.TextAlignment);
         Assert.True (label.AutoSize);
         Assert.False (label.CanFocus);
         Assert.Equal (new Rectangle (0, 0, 0, 0), label.Frame);
         Assert.Equal (KeyCode.Null, label.HotKey);
-        var expected = @"";
-        TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
-        Application.End (rs);
-
-        label = new Label { Text = "Test" };
-        Assert.True (label.AutoSize);
-        Assert.Equal ("Test", label.Text);
-        Application.Top.Add (label);
-        rs = Application.Begin (Application.Top);
-
-        Assert.Equal ("Test", label.TextFormatter.Text);
-        Assert.Equal (new Rectangle (0, 0, 4, 1), label.Frame);
-
-        expected = @"
-Test
-";
-        TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
-        Application.End (rs);
-
-        label = new Label { X = 3, Y = 4, Text = "Test" };
-        Assert.Equal ("Test", label.Text);
-        Application.Top.Add (label);
-        rs = Application.Begin (Application.Top);
-
-        Assert.Equal ("Test", label.TextFormatter.Text);
-        Assert.Equal (new Rectangle (3, 4, 4, 1), label.Frame);
-
-        expected = @"
-   Test
-";
-        TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
-
-        Application.End (rs);
     }
 
     [Fact]