From a48146af82eda21b5e390984a43ca24007285dc4 Mon Sep 17 00:00:00 2001 From: Tig Date: Thu, 18 Apr 2024 09:59:07 -0600 Subject: [PATCH] Tons of unit test updates --- Terminal.Gui/Text/TextFormatter.cs | 8 +- Terminal.Gui/View/Layout/ViewLayout.cs | 34 ++- Terminal.Gui/View/ViewText.cs | 6 + UICatalog/Scenarios/AllViewsTester.cs | 6 +- UnitTests/TestHelpers.cs | 121 ++++++----- UnitTests/UICatalog/ScenarioTests.cs | 44 ++-- UnitTests/View/KeyboardEventTests.cs | 58 ++--- UnitTests/View/Layout/DimAutoTests.cs | 80 +++++++ UnitTests/View/Layout/LayoutTests.cs | 96 ++++----- UnitTests/View/MouseTests.cs | 45 ++-- UnitTests/View/Text/AutoSizeFalseTests.cs | 6 +- UnitTests/View/Text/AutoSizeTrueTests.cs | 251 +++++++++++----------- UnitTests/View/ViewTests.cs | 10 +- UnitTests/Views/AllViewsTests.cs | 210 +++++++----------- 14 files changed, 508 insertions(+), 467 deletions(-) diff --git a/Terminal.Gui/Text/TextFormatter.cs b/Terminal.Gui/Text/TextFormatter.cs index db13b5930..4c8e5554c 100644 --- a/Terminal.Gui/Text/TextFormatter.cs +++ b/Terminal.Gui/Text/TextFormatter.cs @@ -43,7 +43,7 @@ public class TextFormatter { _autoSize = EnableNeedsFormat (value); - if (_autoSize && Alignment != TextAlignment.Justified && VerticalAlignment != VerticalTextAlignment.Justified) + if (_autoSize)// && Alignment != TextAlignment.Justified && VerticalAlignment != VerticalTextAlignment.Justified) { Size = CalcRect (0, 0, _text, Direction, TabWidth).Size; } @@ -65,7 +65,7 @@ public class TextFormatter { _textDirection = EnableNeedsFormat (value); - if (AutoSize && Alignment != TextAlignment.Justified && VerticalAlignment != VerticalTextAlignment.Justified) + if (AutoSize)// && Alignment != TextAlignment.Justified && VerticalAlignment != VerticalTextAlignment.Justified) { Size = CalcRect (0, 0, Text, Direction, TabWidth).Size; } @@ -148,7 +148,7 @@ public class TextFormatter get => _size; set { - if (AutoSize && Alignment != TextAlignment.Justified && VerticalAlignment != VerticalTextAlignment.Justified) + if (AutoSize)// && Alignment != TextAlignment.Justified && VerticalAlignment != VerticalTextAlignment.Justified) { _size = EnableNeedsFormat (CalcRect (0, 0, Text, Direction, TabWidth).Size); } @@ -175,7 +175,7 @@ public class TextFormatter bool textWasNull = _text is null && value != null; _text = EnableNeedsFormat (value); - if ((AutoSize && Alignment != TextAlignment.Justified && VerticalAlignment != VerticalTextAlignment.Justified) || (textWasNull && Size.IsEmpty)) + if (/*(Alignment != TextAlignment.Justified && VerticalAlignment != VerticalTextAlignment.Justified) ||*/ (textWasNull && Size.IsEmpty)) { Size = CalcRect (0, 0, _text, Direction, TabWidth).Size; } diff --git a/Terminal.Gui/View/Layout/ViewLayout.cs b/Terminal.Gui/View/Layout/ViewLayout.cs index 27f2f9a48..583ac3aa4 100644 --- a/Terminal.Gui/View/Layout/ViewLayout.cs +++ b/Terminal.Gui/View/Layout/ViewLayout.cs @@ -347,17 +347,37 @@ public partial class View get => _height is Dim.DimAuto && _width is Dim.DimAuto; set { - if (IsInitialized) - { - Height = Dim.Auto (Dim.DimAutoStyle.Text); - Width = Dim.Auto (Dim.DimAutoStyle.Text); + TextFormatter.AutoSize = value; + if (value) + { + UpdateTextFormatterText (); + if (IsInitialized) + { + Height = Dim.Auto (Dim.DimAutoStyle.Text); + Width = Dim.Auto (Dim.DimAutoStyle.Text); + } + else + { + _height = Dim.Auto (Dim.DimAutoStyle.Text); + _width = Dim.Auto (Dim.DimAutoStyle.Text); + OnResizeNeeded (); + } } else { - _height = Dim.Auto (Dim.DimAutoStyle.Text); - _width = Dim.Auto (Dim.DimAutoStyle.Text); - OnResizeNeeded(); + if (IsInitialized) + { + Height = Height.Anchor (ContentSize.Height); + Width = Width.Anchor (ContentSize.Width); + + } + else + { + _height = Height.Anchor (ContentSize.Height); + _width = Width.Anchor (ContentSize.Width); + OnResizeNeeded (); + } } } } diff --git a/Terminal.Gui/View/ViewText.cs b/Terminal.Gui/View/ViewText.cs index a82139e22..5effa8ae2 100644 --- a/Terminal.Gui/View/ViewText.cs +++ b/Terminal.Gui/View/ViewText.cs @@ -55,6 +55,12 @@ public partial class View string old = _text; _text = value; + + if (!string.IsNullOrEmpty (_text)) + { + + } + UpdateTextFormatterText (); OnResizeNeeded (); #if DEBUG diff --git a/UICatalog/Scenarios/AllViewsTester.cs b/UICatalog/Scenarios/AllViewsTester.cs index b9b20377e..37b8dfff7 100644 --- a/UICatalog/Scenarios/AllViewsTester.cs +++ b/UICatalog/Scenarios/AllViewsTester.cs @@ -12,7 +12,7 @@ namespace UICatalog.Scenarios; [ScenarioCategory ("Top Level Windows")] public class AllViewsTester : Scenario { - private readonly List _dimNames = new () { "Factor", "Fill", "Absolute" }; + private readonly List _dimNames = new () { "Auto", "Factor", "Fill", "Absolute" }; // TODO: This is missing some private readonly List _posNames = new () { "Factor", "AnchorEnd", "Center", "Absolute" }; @@ -208,7 +208,7 @@ public class AllViewsTester : Scenario Title = "Size (Dim)" }; - radioItems = new [] { "_Percent(width)", "_Fill(width)", "_Sized(width)" }; + radioItems = new [] { "Auto", "_Percent(width)", "_Fill(width)", "_Sized(width)" }; label = new Label { X = 0, Y = 0, Text = "Width:" }; _sizeFrame.Add (label); _wRadioGroup = new RadioGroup { X = 0, Y = Pos.Bottom (label), RadioLabels = radioItems }; @@ -240,7 +240,7 @@ public class AllViewsTester : Scenario _sizeFrame.Add (_wText); _sizeFrame.Add (_wRadioGroup); - radioItems = new [] { "P_ercent(height)", "F_ill(height)", "Si_zed(height)" }; + radioItems = new [] { "_Auto", "P_ercent(height)", "F_ill(height)", "Si_zed(height)" }; label = new Label { X = Pos.Right (_wRadioGroup) + 1, Y = 0, Text = "Height:" }; _sizeFrame.Add (label); _hText = new TextField { X = Pos.Right (label) + 1, Y = 0, Width = 4, Text = $"{_hVal}" }; diff --git a/UnitTests/TestHelpers.cs b/UnitTests/TestHelpers.cs index 84c52482b..32b68eb37 100644 --- a/UnitTests/TestHelpers.cs +++ b/UnitTests/TestHelpers.cs @@ -1,4 +1,5 @@ -using System.Diagnostics; +using System.Collections; +using System.Diagnostics; using System.Globalization; using System.Reflection; using System.Text; @@ -521,64 +522,56 @@ internal partial class TestHelpers return sb.ToString (); } - // TODO: Update all tests that use GetALlViews to use GetAllViewsTheoryData instead - /// Gets a list of instances of all classes derived from View. - /// List of View objects - public static List GetAllViews () - { - return typeof (View).Assembly.GetTypes () - .Where ( - type => type.IsClass - && !type.IsAbstract - && type.IsPublic - && type.IsSubclassOf (typeof (View)) - ) - .Select (type => CreateView (type, type.GetConstructor (Array.Empty ()))) - .ToList (); - } + //// TODO: Update all tests that use GetALlViews to use GetAllViewsTheoryData instead + ///// Gets a list of instances of all classes derived from View. + ///// List of View objects + //public static List GetAllViews () + //{ + // return typeof (View).Assembly.GetTypes () + // .Where ( + // type => type.IsClass + // && !type.IsAbstract + // && type.IsPublic + // && type.IsSubclassOf (typeof (View)) + // ) + // .Select (type => CreateView (type, type.GetConstructor (Array.Empty ()))) + // .ToList (); + //} - public static TheoryData GetAllViewsTheoryData () - { - // TODO: Figure out how to simplify this. I couldn't figure out how to not have to iterate over ret. - (View view, string name)[] ret = - typeof (View).Assembly - .GetTypes () - .Where ( - type => type.IsClass - && !type.IsAbstract - && type.IsPublic - && type.IsSubclassOf (typeof (View)) - ) - .Select ( - type => ( - view: CreateView ( - type, type.GetConstructor (Array.Empty ())), - name: type.Name) - ).ToArray(); + //public class AllViewsData : IEnumerable + //{ + // private Lazy> data; - TheoryData td = new (); - foreach ((View view, string name) in ret) - { - td.Add(view, name); - } + // public AllViewsData () + // { + // data = new Lazy> (GetTestData); + // } - return td; - } + // public IEnumerator GetEnumerator () + // { + // return data.Value.GetEnumerator (); + // } + // IEnumerator IEnumerable.GetEnumerator () => GetEnumerator (); - public static TheoryData GetAllScenarioTheoryData () - { - // TODO: Figure out how to simplify this. I couldn't figure out how to not have to iterate over ret. - var scenarios = Scenario.GetScenarios (); - (Scenario scenario, string name) [] ret = scenarios.Select (s => (scenario: s, name: s.GetName ())).ToArray(); - TheoryData td = new (); - foreach ((Scenario scenario, string name) in ret) - { - td.Add (scenario, name); - } + // private List GetTestData () + // { + // var viewTypes = typeof (View).Assembly + // .GetTypes () + // .Where (type => type.IsClass && !type.IsAbstract && type.IsPublic && type.IsSubclassOf (typeof (View))); + + // var testData = new List (); + + // foreach (var type in viewTypes) + // { + // var view = CreateView (type, type.GetConstructor (Array.Empty ())); + // testData.Add (new object [] { view, type.Name }); + // } + + // return testData; + // } + //} - return td; - } /// /// Verifies the console used all the when rendering. If one or more of the @@ -851,3 +844,25 @@ internal partial class TestHelpers [GeneratedRegex ("\\s+$", RegexOptions.Multiline)] private static partial Regex TrailingWhiteSpaceRegEx (); } + +public class TestsAllViews +{ + public static IEnumerable AllViewTypes => + typeof (View).Assembly + .GetTypes () + .Where (type => type.IsClass && !type.IsAbstract && type.IsPublic && type.IsSubclassOf (typeof (View))) + .Select (type => new object [] { type }); + + public static View CreateInstanceIfNotGeneric (Type type) + { + if (type.IsGenericType) + { + // Return null for generic types + return null; + } + + return Activator.CreateInstance (type) as View; + } + +} + diff --git a/UnitTests/UICatalog/ScenarioTests.cs b/UnitTests/UICatalog/ScenarioTests.cs index c02cf94f7..c61841528 100644 --- a/UnitTests/UICatalog/ScenarioTests.cs +++ b/UnitTests/UICatalog/ScenarioTests.cs @@ -3,7 +3,7 @@ using Xunit.Abstractions; namespace UICatalog.Tests; -public class ScenarioTests +public class ScenarioTests : TestsAllViews { private readonly ITestOutputHelper _output; @@ -14,18 +14,25 @@ public class ScenarioTests #endif _output = output; } + + public static IEnumerable AllScenarioTypes => + typeof (Scenario).Assembly + .GetTypes () + .Where (type => type.IsClass && !type.IsAbstract && type.IsSubclassOf (typeof (Scenario))) + .Select (type => new object [] { type }); - public static TheoryData AllScenarios => TestHelpers.GetAllScenarioTheoryData (); /// /// This runs through all Scenarios defined in UI Catalog, calling Init, Setup, and Run. /// Should find any Scenarios which crash on load or do not respond to . /// [Theory] - [MemberData (nameof (AllScenarios))] - public void Run_All_Scenarios (Scenario scenario, string viewName) + [MemberData (nameof (AllScenarioTypes))] + public void Run_All_Scenarios (Type scenarioType) { - _output.WriteLine ($"Running Scenario '{scenario.GetName ()}'"); + _output.WriteLine ($"Running Scenario '{scenarioType}'"); + + Scenario scenario = (Scenario)Activator.CreateInstance (scenarioType); Application.Init (new FakeDriver ()); @@ -116,16 +123,13 @@ public class ScenarioTests TextField _hText; var _hVal = 0; List posNames = new () { "Factor", "AnchorEnd", "Center", "Absolute" }; - List dimNames = new () { "Factor", "Fill", "Absolute" }; + List dimNames = new () { "Auto", "Factor", "Fill", "Absolute" }; Application.Init (new FakeDriver ()); var top = new Toplevel (); - _viewClasses = GetAllViewClassesCollection () - .OrderBy (t => t.Name) - .Select (t => new KeyValuePair (t.Name, t)) - .ToDictionary (t => t.Key, t => t.Value); + _viewClasses = TestHelpers.GetAllViewClasses ().ToDictionary(t => t.Name); _leftPane = new() { @@ -200,7 +204,7 @@ public class ScenarioTests Title = "Size (Dim)" }; - radioItems = new [] { "Percent(width)", "Fill(width)", "Sized(width)" }; + radioItems = new [] { "Auto()", "Percent(width)", "Fill(width)", "Sized(width)" }; label = new() { X = 0, Y = 0, Text = "width:" }; _sizeFrame.Add (label); _wRadioGroup = new() { X = 0, Y = Pos.Bottom (label), RadioLabels = radioItems }; @@ -208,7 +212,7 @@ public class ScenarioTests _sizeFrame.Add (_wText); _sizeFrame.Add (_wRadioGroup); - radioItems = new [] { "Percent(height)", "Fill(height)", "Sized(height)" }; + radioItems = new [] { "Auto()", "Percent(height)", "Fill(height)", "Sized(height)" }; label = new() { X = Pos.Right (_wRadioGroup) + 1, Y = 0, Text = "height:" }; _sizeFrame.Add (label); _hText = new() { X = Pos.Right (label) + 1, Y = 0, Width = 4, Text = $"{_hVal}" }; @@ -452,22 +456,6 @@ public class ScenarioTests void UpdateTitle (View view) { _hostPane.Title = $"{view.GetType ().Name} - {view.X}, {view.Y}, {view.Width}, {view.Height}"; } - List GetAllViewClassesCollection () - { - List types = new (); - - foreach (Type type in typeof (View).Assembly.GetTypes () - .Where ( - myType => - myType.IsClass && !myType.IsAbstract && myType.IsPublic && myType.IsSubclassOf (typeof (View)) - )) - { - types.Add (type); - } - - return types; - } - View CreateClass (Type type) { // If we are to create a generic Type diff --git a/UnitTests/View/KeyboardEventTests.cs b/UnitTests/View/KeyboardEventTests.cs index 63ba79106..61e9de9d3 100644 --- a/UnitTests/View/KeyboardEventTests.cs +++ b/UnitTests/View/KeyboardEventTests.cs @@ -4,26 +4,26 @@ namespace Terminal.Gui.ViewTests; -public class KeyboardEventTests (ITestOutputHelper output) +public class KeyboardEventTests (ITestOutputHelper output) : TestsAllViews { - public static TheoryData AllViews => TestHelpers.GetAllViewsTheoryData (); - /// /// This tests that when a new key down event is sent to the view will fire the 3 key-down related /// events: KeyDown, InvokingKeyBindings, and ProcessKeyDown. Note that KeyUp is independent. /// [Theory] - [MemberData (nameof (AllViews))] - public void AllViews_KeyDown_All_EventsFire (View view, string viewName) + [MemberData (nameof (AllViewTypes))] + public void AllViews_KeyDown_All_EventsFire (Type viewType) { + var view = CreateInstanceIfNotGeneric (viewType); + if (view == null) { - output.WriteLine ($"ERROR: Skipping generic view: {viewName}"); + output.WriteLine ($"ERROR: Skipping generic view: {viewType}"); return; } - output.WriteLine ($"Testing {viewName}"); + output.WriteLine ($"Testing {viewType}"); var keyDown = false; @@ -60,32 +60,32 @@ public class KeyboardEventTests (ITestOutputHelper output) /// This tests that when a new key up event is sent to the view the view will fire the 1 key-up related event: /// KeyUp /// - [Fact] - public void AllViews_KeyUp_All_EventsFire () + [Theory] + [MemberData (nameof (AllViewTypes))] + public void AllViews_KeyUp_All_EventsFire (Type viewType) { - foreach (View view in TestHelpers.GetAllViews ()) + var view = CreateInstanceIfNotGeneric (viewType); + + if (view == null) { - if (view == null) - { - output.WriteLine ($"ERROR: null view from {nameof (TestHelpers.GetAllViews)}"); + output.WriteLine ($"ERROR: Generic view {viewType}"); - continue; - } - - output.WriteLine ($"Testing {view.GetType ().Name}"); - - var keyUp = false; - - view.KeyUp += (s, a) => - { - a.Handled = true; - keyUp = true; - }; - - Assert.True (view.NewKeyUpEvent (Key.A)); // this will be true because the KeyUp event handled it - Assert.True (keyUp); - view.Dispose (); + return; } + + output.WriteLine ($"Testing {view.GetType ().Name}"); + + var keyUp = false; + + view.KeyUp += (s, a) => + { + a.Handled = true; + keyUp = true; + }; + + Assert.True (view.NewKeyUpEvent (Key.A)); // this will be true because the KeyUp event handled it + Assert.True (keyUp); + view.Dispose (); } [Theory] diff --git a/UnitTests/View/Layout/DimAutoTests.cs b/UnitTests/View/Layout/DimAutoTests.cs index 2e016aab4..7757df344 100644 --- a/UnitTests/View/Layout/DimAutoTests.cs +++ b/UnitTests/View/Layout/DimAutoTests.cs @@ -538,5 +538,85 @@ public class DimAutoTests Assert.Equal (expectedSuperWidth, superView.Frame.Width); } + [Theory] + [InlineData (0, 1, 1)] + [InlineData (1, 1, 1)] + [InlineData (9, 1, 1)] + [InlineData (10, 1, 1)] + [InlineData (0, 10, 10)] + [InlineData (1, 10, 10)] + [InlineData (9, 10, 10)] + [InlineData (10, 10, 10)] + public void Width_Auto_Text_Does_Not_Constrain_To_SuperView (int subX, int textLen, int expectedSubWidth) + { + var superView = new View + { + X = 0, + Y = 0, + Width = 10, + Height = 1, + ValidatePosDim = true + }; + + var subView = new View + { + Text = new string ('*', textLen), + X = subX, + Y = 0, + Width = Dim.Auto (Dim.DimAutoStyle.Text), + Height = 1, + ValidatePosDim = true + }; + + superView.Add (subView); + + superView.BeginInit (); + superView.EndInit (); + superView.SetRelativeLayout (superView.ContentSize); + + superView.LayoutSubviews (); + Assert.Equal (expectedSubWidth, subView.Frame.Width); + } + + [Theory] + [InlineData (0, 1, 1)] + [InlineData (1, 1, 1)] + [InlineData (9, 1, 1)] + [InlineData (10, 1, 1)] + [InlineData (0, 10, 10)] + [InlineData (1, 10, 10)] + [InlineData (9, 10, 10)] + [InlineData (10, 10, 10)] + public void Width_Auto_Subviews_Does_Not_Constrain_To_SuperView (int subX, int textLen, int expectedSubWidth) + { + var superView = new View + { + X = 0, + Y = 0, + Width = 10, + Height = 1, + ValidatePosDim = true + }; + + var subView = new View + { + Text = new string ('*', textLen), + X = subX, + Y = 0, + Width = Dim.Auto (Dim.DimAutoStyle.Subviews), + Height = 1, + ValidatePosDim = true + }; + + superView.Add (subView); + + superView.BeginInit (); + superView.EndInit (); + superView.SetRelativeLayout (superView.ContentSize); + + superView.LayoutSubviews (); + Assert.Equal (expectedSubWidth, subView.Frame.Width); + } + // Test variations of Frame } diff --git a/UnitTests/View/Layout/LayoutTests.cs b/UnitTests/View/Layout/LayoutTests.cs index d7c0b8d3a..444e30cbb 100644 --- a/UnitTests/View/Layout/LayoutTests.cs +++ b/UnitTests/View/Layout/LayoutTests.cs @@ -620,66 +620,66 @@ public class LayoutTests sub2.Dispose (); } - [Fact] - [AutoInitShutdown] - public void TrySetHeight_ForceValidatePosDim () - { - var top = new View { X = 0, Y = 0, Height = 20 }; + //[Fact] + //[AutoInitShutdown] + //public void TrySetHeight_ForceValidatePosDim () + //{ + // var top = new View { X = 0, Y = 0, Height = 20 }; - var v = new View { Height = Dim.Fill (), ValidatePosDim = true }; - top.Add (v); + // var v = new View { Height = Dim.Fill (), ValidatePosDim = true }; + // top.Add (v); - Assert.False (v.TrySetHeight (10, out int rHeight)); - Assert.Equal (10, rHeight); + // Assert.False (v.TrySetHeight (10, out int rHeight)); + // Assert.Equal (10, rHeight); - v.Height = Dim.Fill (1); - Assert.False (v.TrySetHeight (10, out rHeight)); - Assert.Equal (9, rHeight); + // v.Height = Dim.Fill (1); + // Assert.False (v.TrySetHeight (10, out rHeight)); + // Assert.Equal (9, rHeight); - v.Height = 0; - Assert.True (v.TrySetHeight (10, out rHeight)); - Assert.Equal (10, rHeight); - Assert.False (v.IsInitialized); + // v.Height = 0; + // Assert.True (v.TrySetHeight (10, out rHeight)); + // Assert.Equal (10, rHeight); + // Assert.False (v.IsInitialized); - var toplevel = new Toplevel (); - toplevel.Add (top); - Application.Begin (toplevel); + // var toplevel = new Toplevel (); + // toplevel.Add (top); + // Application.Begin (toplevel); - Assert.True (v.IsInitialized); + // Assert.True (v.IsInitialized); - v.Height = 15; - Assert.True (v.TrySetHeight (5, out rHeight)); - Assert.Equal (5, rHeight); - } + // v.Height = 15; + // Assert.True (v.TrySetHeight (5, out rHeight)); + // Assert.Equal (5, rHeight); + //} - [Fact] - [AutoInitShutdown] - public void TrySetWidth_ForceValidatePosDim () - { - var top = new View { X = 0, Y = 0, Width = 80 }; + //[Fact] + //[AutoInitShutdown] + //public void TrySetWidth_ForceValidatePosDim () + //{ + // var top = new View { X = 0, Y = 0, Width = 80 }; - var v = new View { Width = Dim.Fill (), ValidatePosDim = true }; - top.Add (v); + // var v = new View { Width = Dim.Fill (), ValidatePosDim = true }; + // top.Add (v); - Assert.False (v.TrySetWidth (70, out int rWidth)); - Assert.Equal (70, rWidth); + // Assert.False (v.TrySetWidth (70, out int rWidth)); + // Assert.Equal (70, rWidth); - v.Width = Dim.Fill (1); - Assert.False (v.TrySetWidth (70, out rWidth)); - Assert.Equal (69, rWidth); + // v.Width = Dim.Fill (1); + // Assert.False (v.TrySetWidth (70, out rWidth)); + // Assert.Equal (69, rWidth); - v.Width = 0; - Assert.True (v.TrySetWidth (70, out rWidth)); - Assert.Equal (70, rWidth); - Assert.False (v.IsInitialized); + // v.Width = 0; + // Assert.True (v.TrySetWidth (70, out rWidth)); + // Assert.Equal (70, rWidth); + // Assert.False (v.IsInitialized); - var toplevel = new Toplevel (); - toplevel.Add (top); - Application.Begin (toplevel); + // var toplevel = new Toplevel (); + // toplevel.Add (top); + // Application.Begin (toplevel); - Assert.True (v.IsInitialized); - v.Width = 75; - Assert.True (v.TrySetWidth (60, out rWidth)); - Assert.Equal (60, rWidth); - } + // Assert.True (v.IsInitialized); + // v.Width = 75; + // Assert.True (v.TrySetWidth (60, out rWidth)); + // Assert.Equal (60, rWidth); + //} } diff --git a/UnitTests/View/MouseTests.cs b/UnitTests/View/MouseTests.cs index 6c2345eb2..6c798b8cd 100644 --- a/UnitTests/View/MouseTests.cs +++ b/UnitTests/View/MouseTests.cs @@ -3,7 +3,7 @@ using Xunit.Abstractions; namespace Terminal.Gui.ViewTests; -public class MouseTests (ITestOutputHelper output) +public class MouseTests (ITestOutputHelper output) : TestsAllViews { [Theory] [InlineData (false, false, false)] @@ -93,30 +93,29 @@ public class MouseTests (ITestOutputHelper output) Assert.Equal (mouseFlagsFromEvent, expectedMouseFlagsFromEvent); } - public static TheoryData AllViews => TestHelpers.GetAllViewsTheoryData (); - - [Theory] - [MemberData (nameof (AllViews))] + [MemberData (nameof (AllViewTypes))] - public void AllViews_Enter_Leave_Events (View view, string viewName) + public void AllViews_Enter_Leave_Events (Type viewType) { + var view = CreateInstanceIfNotGeneric (viewType); + if (view == null) { - output.WriteLine ($"Ignoring {viewName} - It's a Generic"); + output.WriteLine ($"Ignoring {viewType} - It's a Generic"); return; } if (!view.CanFocus) { - output.WriteLine ($"Ignoring {viewName} - It can't focus."); + output.WriteLine ($"Ignoring {viewType} - It can't focus."); return; } if (view is Toplevel && ((Toplevel)view).Modal) { - output.WriteLine ($"Ignoring {viewName} - It's a Modal Toplevel"); + output.WriteLine ($"Ignoring {viewType} - It's a Modal Toplevel"); return; } @@ -189,26 +188,28 @@ public class MouseTests (ITestOutputHelper output) [Theory] - [MemberData (nameof (AllViews))] + [MemberData (nameof (AllViewTypes))] - public void AllViews_Enter_Leave_Events_Visible_False (View view, string viewName) + public void AllViews_Enter_Leave_Events_Visible_False (Type viewType) { + var view = CreateInstanceIfNotGeneric (viewType); + if (view == null) { - output.WriteLine ($"Ignoring {viewName} - It's a Generic"); + output.WriteLine ($"Ignoring {viewType} - It's a Generic"); return; } if (!view.CanFocus) { - output.WriteLine ($"Ignoring {viewName} - It can't focus."); + output.WriteLine ($"Ignoring {viewType} - It can't focus."); return; } if (view is Toplevel && ((Toplevel)view).Modal) { - output.WriteLine ($"Ignoring {viewName} - It's a Modal Toplevel"); + output.WriteLine ($"Ignoring {viewType} - It's a Modal Toplevel"); return; } @@ -304,12 +305,14 @@ public class MouseTests (ITestOutputHelper output) } [Theory] - [MemberData (nameof (AllViews))] - public void AllViews_NewMouseEvent_Enabled_False_Does_Not_Set_Handled (View view, string viewName) + [MemberData (nameof (AllViewTypes))] + public void AllViews_NewMouseEvent_Enabled_False_Does_Not_Set_Handled (Type viewType) { + var view = CreateInstanceIfNotGeneric (viewType); + if (view == null) { - output.WriteLine ($"Ignoring {viewName} - It's a Generic"); + output.WriteLine ($"Ignoring {viewType} - It's a Generic"); return; } @@ -321,12 +324,14 @@ public class MouseTests (ITestOutputHelper output) } [Theory] - [MemberData (nameof (AllViews))] - public void AllViews_NewMouseEvent_Clicked_Enabled_False_Does_Not_Set_Handled (View view, string viewName) + [MemberData (nameof (AllViewTypes))] + public void AllViews_NewMouseEvent_Clicked_Enabled_False_Does_Not_Set_Handled (Type viewType) { + var view = CreateInstanceIfNotGeneric (viewType); + if (view == null) { - output.WriteLine ($"Ignoring {viewName} - It's a Generic"); + output.WriteLine ($"Ignoring {viewType} - It's a Generic"); return; } diff --git a/UnitTests/View/Text/AutoSizeFalseTests.cs b/UnitTests/View/Text/AutoSizeFalseTests.cs index e971a0ec2..9e77bf1b3 100644 --- a/UnitTests/View/Text/AutoSizeFalseTests.cs +++ b/UnitTests/View/Text/AutoSizeFalseTests.cs @@ -192,10 +192,8 @@ public class AutoSizeFalseTests Assert.Equal ("Absolute(1)", view.Height.ToString ()); view.AutoSize = true; - - // There's no Text, so the view should be sized (0, 0) - Assert.Equal ("Absolute(0)", view.Width.ToString ()); - Assert.Equal ("Absolute(0)", view.Height.ToString ()); + Assert.Equal (Dim.Auto(Dim.DimAutoStyle.Text), view.Width); + Assert.Equal (Dim.Auto (Dim.DimAutoStyle.Text), view.Height); view.AutoSize = false; Assert.Equal ("Absolute(0)", view.Width.ToString ()); diff --git a/UnitTests/View/Text/AutoSizeTrueTests.cs b/UnitTests/View/Text/AutoSizeTrueTests.cs index 2045c71b2..f828fb6b8 100644 --- a/UnitTests/View/Text/AutoSizeTrueTests.cs +++ b/UnitTests/View/Text/AutoSizeTrueTests.cs @@ -1,3 +1,4 @@ +using System.Reflection.Emit; using System.Text; using Xunit.Abstractions; @@ -1123,11 +1124,11 @@ public class AutoSizeTrueTests { var text = "Label"; var label = new Label { Text = text }; - Assert.Equal ("Absolute(1)", label.Height.ToString ()); + Assert.Equal (Dim.Auto(Dim.DimAutoStyle.Text), label.Height); label.AutoSize = false; label.Width = Dim.Fill () - text.Length; label.Height = 1; - Assert.Equal ("Absolute(1)", label.Height.ToString ()); + Assert.Equal (Dim.Sized (1), label.Height); var win = new FrameView { Width = Dim.Fill (), Height = Dim.Fill () }; win.Add (label); @@ -1255,8 +1256,8 @@ public class AutoSizeTrueTests Text = "Say Hello view4 你", AutoSize = true, - //Width = 10, - //Height = 5, + //Width = 1, + //Height = 18, TextDirection = TextDirection.TopBottom_LeftRight, ValidatePosDim = true }; @@ -1291,26 +1292,26 @@ public class AutoSizeTrueTests Assert.False (view5.IsInitialized); Assert.True (view1.AutoSize); Assert.Equal (new (0, 0, 18, 1), view1.Frame); - Assert.Equal ("Absolute(18)", view1.Width.ToString ()); - Assert.Equal ("Absolute(1)", view1.Height.ToString ()); + Assert.Equal (Dim.Auto (Dim.DimAutoStyle.Text), view1.Width); + Assert.Equal (Dim.Auto (Dim.DimAutoStyle.Text), view1.Height); Assert.True (view2.AutoSize); - Assert.Equal ("Say Hello view2 你".GetColumns (), view2.Width); - Assert.Equal (18, view2.Width); - Assert.Equal (new (0, 0, 18, 5), view2.Frame); - Assert.Equal ("Absolute(18)", view2.Width.ToString ()); - Assert.Equal ("Absolute(5)", view2.Height.ToString ()); + Assert.Equal ("Say Hello view2 你".GetColumns (), view2.Frame.Width); + Assert.Equal (18, view2.Frame.Width); + Assert.Equal (new (0, 0, 18, 1), view2.Frame); + Assert.Equal (Dim.Auto (Dim.DimAutoStyle.Text), view2.Width); + Assert.Equal (Dim.Auto (Dim.DimAutoStyle.Text), view2.Height); Assert.True (view3.AutoSize); Assert.Equal (new (0, 0, 18, 1), view3.Frame); // BUGBUG: AutoSize = true, so the height should be 1. - Assert.Equal ("Absolute(18)", view2.Width.ToString ()); - Assert.Equal ("Absolute(1)", view3.Height.ToString ()); + Assert.Equal (Dim.Auto (Dim.DimAutoStyle.Text), view3.Width); + Assert.Equal (Dim.Auto (Dim.DimAutoStyle.Text), view3.Height); + + // Vertical text Assert.True (view4.AutoSize); + Assert.Equal (Dim.Auto (Dim.DimAutoStyle.Text), view4.Width); + Assert.Equal (Dim.Auto (Dim.DimAutoStyle.Text), view4.Height); + Assert.Equal ("Say Hello view4 你".GetColumns (), view4.Frame.Height); + Assert.Equal (new (0, 0, 1, 17), view4.Frame); - Assert.Equal ("Say Hello view4 你".GetColumns (), view2.Width); - Assert.Equal (18, view2.Width); - - Assert.Equal (new (0, 0, 18, 17), view4.Frame); - Assert.Equal ("Absolute(18)", view4.Width.ToString ()); - Assert.Equal ("Absolute(17)", view4.Height.ToString ()); Assert.True (view5.AutoSize); Assert.Equal (new (0, 0, 18, 17), view5.Frame); Assert.True (view6.AutoSize); @@ -1326,29 +1327,17 @@ public class AutoSizeTrueTests Assert.True (view5.IsInitialized); Assert.True (view1.AutoSize); Assert.Equal (new (0, 0, 18, 1), view1.Frame); - Assert.Equal ("Absolute(18)", view1.Width.ToString ()); - Assert.Equal ("Absolute(1)", view1.Height.ToString ()); Assert.True (view2.AutoSize); Assert.Equal (new (0, 0, 18, 5), view2.Frame); - Assert.Equal ("Absolute(18)", view2.Width.ToString ()); - Assert.Equal ("Absolute(5)", view2.Height.ToString ()); Assert.True (view3.AutoSize); Assert.Equal (new (0, 0, 18, 1), view3.Frame); // BUGBUG: AutoSize = true, so the height should be 1. - Assert.Equal ("Absolute(18)", view5.Width.ToString ()); - Assert.Equal ("Absolute(1)", view3.Height.ToString ()); Assert.True (view4.AutoSize); Assert.Equal (new (0, 0, 18, 17), view4.Frame); - Assert.Equal ("Absolute(18)", view5.Width.ToString ()); - Assert.Equal ("Absolute(17)", view4.Height.ToString ()); Assert.True (view5.AutoSize); Assert.Equal (new (0, 0, 18, 17), view5.Frame); - Assert.Equal ("Absolute(18)", view5.Width.ToString ()); - Assert.Equal ("Absolute(17)", view5.Height.ToString ()); Assert.True (view6.AutoSize); Assert.Equal (new (0, 0, 2, 17), view6.Frame); // BUGBUG: AutoSize = true, so the Width should be 2. - Assert.Equal ("Absolute(2)", view6.Width.ToString ()); - Assert.Equal ("Absolute(17)", view6.Height.ToString ()); } [Fact] @@ -1574,7 +1563,7 @@ Y label.Text = "Hello"; Application.Refresh (); - Assert.Equal (new (0, 0, 1, 5), label.Frame); // BUGBUG: AutoSize = true, so the Width should be 1. + Assert.Equal (new (0, 0, 1, 5), label.Frame); var expected = @" HX @@ -2307,69 +2296,69 @@ Y Application.End (rs); } - [Fact] - public void GetCurrentHeight_TrySetHeight () - { - var top = new View { X = 0, Y = 0, Height = 20 }; + //[Fact] + //public void GetCurrentHeight_TrySetHeight () + //{ + // var top = new View { X = 0, Y = 0, Height = 20 }; - var v = new View { Height = Dim.Fill (), ValidatePosDim = true }; - top.Add (v); - top.BeginInit (); - top.EndInit (); - top.LayoutSubviews (); + // var v = new View { Height = Dim.Fill (), ValidatePosDim = true }; + // top.Add (v); + // top.BeginInit (); + // top.EndInit (); + // top.LayoutSubviews (); - Assert.False (v.AutoSize); - Assert.False (v.TrySetHeight (0, out _)); - Assert.Equal (20, v.Frame.Height); + // Assert.False (v.AutoSize); + // Assert.False (v.TrySetHeight (0, out _)); + // Assert.Equal (20, v.Frame.Height); - v.Height = Dim.Fill (1); - top.LayoutSubviews (); + // v.Height = Dim.Fill (1); + // top.LayoutSubviews (); - Assert.False (v.TrySetHeight (0, out _)); - Assert.True (v.Height is Dim.DimFill); - Assert.Equal (19, v.Frame.Height); + // Assert.False (v.TrySetHeight (0, out _)); + // Assert.True (v.Height is Dim.DimFill); + // Assert.Equal (19, v.Frame.Height); - v.AutoSize = true; - top.LayoutSubviews (); + // v.AutoSize = true; + // top.LayoutSubviews (); - Assert.True (v.TrySetHeight (0, out _)); - Assert.True (v.Height is Dim.DimAbsolute); - Assert.Equal (0, v.Frame.Height); // No text, so height is 0 - top.Dispose (); - } + // Assert.True (v.TrySetHeight (0, out _)); + // Assert.True (v.Height is Dim.DimAbsolute); + // Assert.Equal (0, v.Frame.Height); // No text, so height is 0 + // top.Dispose (); + //} - [Fact] - [TestRespondersDisposed] - public void GetCurrentWidth_TrySetWidth () - { - var top = new View { X = 0, Y = 0, Width = 80 }; + //[Fact] + //[TestRespondersDisposed] + //public void GetCurrentWidth_TrySetWidth () + //{ + // var top = new View { X = 0, Y = 0, Width = 80 }; - var v = new View { Width = Dim.Fill (), ValidatePosDim = true }; - top.Add (v); - top.BeginInit (); - top.EndInit (); - top.LayoutSubviews (); + // var v = new View { Width = Dim.Fill (), ValidatePosDim = true }; + // top.Add (v); + // top.BeginInit (); + // top.EndInit (); + // top.LayoutSubviews (); - Assert.False (v.AutoSize); - Assert.False (v.TrySetWidth (0, out _)); - Assert.True (v.Width is Dim.DimFill); - Assert.Equal (80, v.Frame.Width); + // Assert.False (v.AutoSize); + // Assert.False (v.TrySetWidth (0, out _)); + // Assert.True (v.Width is Dim.DimFill); + // Assert.Equal (80, v.Frame.Width); - v.Width = Dim.Fill (1); - top.LayoutSubviews (); + // v.Width = Dim.Fill (1); + // top.LayoutSubviews (); - Assert.False (v.TrySetWidth (0, out _)); - Assert.True (v.Width is Dim.DimFill); - Assert.Equal (79, v.Frame.Width); + // Assert.False (v.TrySetWidth (0, out _)); + // Assert.True (v.Width is Dim.DimFill); + // Assert.Equal (79, v.Frame.Width); - v.AutoSize = true; - top.LayoutSubviews (); + // v.AutoSize = true; + // top.LayoutSubviews (); - Assert.True (v.TrySetWidth (0, out _)); - Assert.True (v.Width is Dim.DimAbsolute); - Assert.Equal (0, v.Frame.Width); // No text, so width is 0 - top.Dispose (); - } + // Assert.True (v.TrySetWidth (0, out _)); + // Assert.True (v.Width is Dim.DimAbsolute); + // Assert.Equal (0, v.Frame.Width); // No text, so width is 0 + // top.Dispose (); + //} // [Fact] // [AutoInitShutdown] @@ -2735,7 +2724,7 @@ Y view.Text = "01234567890123456789"; Assert.True (view.AutoSize); - Assert.Equal (LayoutStyle.Absolute, view.LayoutStyle); + Assert.Equal (LayoutStyle.Computed, view.LayoutStyle); Assert.Equal (new (0, 0, 20, 1), view.Frame); Assert.Equal ("Absolute(0)", view.X.ToString ()); Assert.Equal ("Absolute(0)", view.Y.ToString ()); @@ -2813,68 +2802,68 @@ Y Application.End (rs); } - [Fact] - [AutoInitShutdown] - public void TrySetHeight_ForceValidatePosDim () - { - var top = new View { X = 0, Y = 0, Height = 20 }; + //[Fact] + //[AutoInitShutdown] + //public void TrySetHeight_ForceValidatePosDim () + //{ + // var top = new View { X = 0, Y = 0, Height = 20 }; - var v = new View { Height = Dim.Fill (), ValidatePosDim = true }; - top.Add (v); + // var v = new View { Height = Dim.Fill (), ValidatePosDim = true }; + // top.Add (v); - Assert.False (v.TrySetHeight (10, out int rHeight)); - Assert.Equal (10, rHeight); + // Assert.False (v.TrySetHeight (10, out int rHeight)); + // Assert.Equal (10, rHeight); - v.Height = Dim.Fill (1); - Assert.False (v.TrySetHeight (10, out rHeight)); - Assert.Equal (9, rHeight); + // v.Height = Dim.Fill (1); + // Assert.False (v.TrySetHeight (10, out rHeight)); + // Assert.Equal (9, rHeight); - v.Height = 0; - Assert.True (v.TrySetHeight (10, out rHeight)); - Assert.Equal (10, rHeight); - Assert.False (v.IsInitialized); + // v.Height = 0; + // Assert.True (v.TrySetHeight (10, out rHeight)); + // Assert.Equal (10, rHeight); + // Assert.False (v.IsInitialized); - var toplevel = new Toplevel (); - toplevel.Add (top); - Application.Begin (toplevel); + // var toplevel = new Toplevel (); + // toplevel.Add (top); + // Application.Begin (toplevel); - Assert.True (v.IsInitialized); + // Assert.True (v.IsInitialized); - v.Height = 15; - Assert.True (v.TrySetHeight (5, out rHeight)); - Assert.Equal (5, rHeight); - } + // v.Height = 15; + // Assert.True (v.TrySetHeight (5, out rHeight)); + // Assert.Equal (5, rHeight); + //} - [Fact] - [AutoInitShutdown] - public void TrySetWidth_ForceValidatePosDim () - { - var top = new View { X = 0, Y = 0, Width = 80 }; + //[Fact] + //[AutoInitShutdown] + //public void TrySetWidth_ForceValidatePosDim () + //{ + // var top = new View { X = 0, Y = 0, Width = 80 }; - var v = new View { Width = Dim.Fill (), ValidatePosDim = true }; - top.Add (v); + // var v = new View { Width = Dim.Fill (), ValidatePosDim = true }; + // top.Add (v); - Assert.False (v.TrySetWidth (70, out int rWidth)); - Assert.Equal (70, rWidth); + // Assert.False (v.TrySetWidth (70, out int rWidth)); + // Assert.Equal (70, rWidth); - v.Width = Dim.Fill (1); - Assert.False (v.TrySetWidth (70, out rWidth)); - Assert.Equal (69, rWidth); + // v.Width = Dim.Fill (1); + // Assert.False (v.TrySetWidth (70, out rWidth)); + // Assert.Equal (69, rWidth); - v.Width = 0; - Assert.True (v.TrySetWidth (70, out rWidth)); - Assert.Equal (70, rWidth); - Assert.False (v.IsInitialized); + // v.Width = 0; + // Assert.True (v.TrySetWidth (70, out rWidth)); + // Assert.Equal (70, rWidth); + // Assert.False (v.IsInitialized); - var toplevel = new Toplevel (); - toplevel.Add (top); - Application.Begin (toplevel); + // var toplevel = new Toplevel (); + // toplevel.Add (top); + // Application.Begin (toplevel); - Assert.True (v.IsInitialized); - v.Width = 75; - Assert.True (v.TrySetWidth (60, out rWidth)); - Assert.Equal (60, rWidth); - } + // Assert.True (v.IsInitialized); + // v.Width = 75; + // Assert.True (v.TrySetWidth (60, out rWidth)); + // Assert.Equal (60, rWidth); + //} [Theory] [AutoInitShutdown] diff --git a/UnitTests/View/ViewTests.cs b/UnitTests/View/ViewTests.cs index a67667c50..03aac0c06 100644 --- a/UnitTests/View/ViewTests.cs +++ b/UnitTests/View/ViewTests.cs @@ -160,6 +160,7 @@ public class ViewTests { Assert.True (v.AutoSize); Assert.False (v.CanFocus); + // The text is 100 characters long, but Dim.Auto constrains to SuperView, so it should be truncated. Assert.Equal (new Rectangle (0, 0, 100, 1), v.Frame); } else @@ -442,7 +443,7 @@ At 0,0 tv.DrawContentComplete += (s, e) => tvCalled = true; var top = new Toplevel (); - top.Add (view, tv); + top.Add (view, tv); Application.Begin (top); Assert.True (viewCalled); @@ -741,7 +742,7 @@ At 0,0 view.EndInit (); view.Draw (); - TestHelpers.AssertDriverContentsWithFrameAre ( text, _output); + TestHelpers.AssertDriverContentsWithFrameAre (text, _output); } [Fact] @@ -832,7 +833,7 @@ At 0,0 Text = "Vertical View", TextDirection = TextDirection.TopBottom_LeftRight, AutoSize = true }; // BUGBUG: AutoSize or Height need be set Assert.NotNull (r); - Assert.Equal (LayoutStyle.Absolute, r.LayoutStyle); + Assert.Equal (LayoutStyle.Computed, r.LayoutStyle); // BUGBUG: IsInitialized must be true to process calculation r.BeginInit (); @@ -1209,7 +1210,8 @@ At 0,0 Assert.True (acceptInvoked); return; - void ViewOnAccept (object sender, CancelEventArgs e) { + void ViewOnAccept (object sender, CancelEventArgs e) + { acceptInvoked = true; e.Cancel = true; } diff --git a/UnitTests/Views/AllViewsTests.cs b/UnitTests/Views/AllViewsTests.cs index a96ab7e26..5528428fe 100644 --- a/UnitTests/Views/AllViewsTests.cs +++ b/UnitTests/Views/AllViewsTests.cs @@ -1,22 +1,24 @@ -using System.Reflection; +using System.Collections; +using System.Reflection; using Xunit.Abstractions; namespace Terminal.Gui.ViewsTests; -public class AllViewsTests (ITestOutputHelper output) +public class AllViewsTests (ITestOutputHelper output) : TestsAllViews { // TODO: Update all these tests to use AllViews like AllViews_Center_Properly does - public static TheoryData AllViews => TestHelpers.GetAllViewsTheoryData (); + [Theory] - [MemberData (nameof (AllViews))] - public void AllViews_Center_Properly (View view, string viewName) + [MemberData (nameof (AllViewTypes))] + public void AllViews_Center_Properly (Type viewType) { + var view = (View)CreateInstanceIfNotGeneric (viewType); // See https://github.com/gui-cs/Terminal.Gui/issues/3156 if (view == null) { - output.WriteLine ($"Ignoring {viewName} - It's a Generic"); + output.WriteLine ($"Ignoring {viewType} - It's a Generic"); Application.Shutdown (); return; @@ -55,102 +57,91 @@ public class AllViewsTests (ITestOutputHelper output) } - [Fact] - public void AllViews_Enter_Leave_Events () + [Theory] + [MemberData (nameof (AllViewTypes))] + + public void AllViews_Enter_Leave_Events (Type viewType) { - foreach (Type type in TestHelpers.GetAllViewClasses ()) + var vType = (View)CreateInstanceIfNotGeneric (viewType); + + if (vType == null) { - output.WriteLine ($"Testing {type.Name}"); + output.WriteLine ($"Ignoring {viewType} - It's a Generic"); - Application.Init (new FakeDriver ()); + return; + } - Toplevel top = new (); - View vType = TestHelpers.CreateViewFromType (type, type.GetConstructor (Array.Empty ())); + Application.Init (new FakeDriver ()); - if (vType == null) - { - output.WriteLine ($"Ignoring {type} - It's a Generic"); - top.Dispose (); - Application.Shutdown (); + Toplevel top = new (); - continue; - } + vType.AutoSize = false; + vType.X = 0; + vType.Y = 0; + vType.Width = 10; + vType.Height = 1; - vType.AutoSize = false; - vType.X = 0; - vType.Y = 0; - vType.Width = 10; - vType.Height = 1; + var view = new View + { + X = 0, + Y = 1, + Width = 10, + Height = 1, + CanFocus = true + }; + var vTypeEnter = 0; + var vTypeLeave = 0; + var viewEnter = 0; + var viewLeave = 0; - var view = new View - { - X = 0, - Y = 1, - Width = 10, - Height = 1, - CanFocus = true - }; - var vTypeEnter = 0; - var vTypeLeave = 0; - var viewEnter = 0; - var viewLeave = 0; + vType.Enter += (s, e) => vTypeEnter++; + vType.Leave += (s, e) => vTypeLeave++; + view.Enter += (s, e) => viewEnter++; + view.Leave += (s, e) => viewLeave++; - vType.Enter += (s, e) => vTypeEnter++; - vType.Leave += (s, e) => vTypeLeave++; - view.Enter += (s, e) => viewEnter++; - view.Leave += (s, e) => viewLeave++; + top.Add (vType, view); + Application.Begin (top); - top.Add (vType, view); - Application.Begin (top); + if (!vType.CanFocus || (vType is Toplevel && ((Toplevel)vType).Modal)) + { + top.Dispose (); + Application.Shutdown (); - if (!vType.CanFocus || (vType is Toplevel && ((Toplevel)vType).Modal)) - { - top.Dispose (); - Application.Shutdown (); + return; + } - continue; - } - - if (vType is TextView) + if (vType is TextView) + { + top.NewKeyDownEvent (Key.Tab.WithCtrl); + } + else if (vType is DatePicker) + { + for (var i = 0; i < 4; i++) { top.NewKeyDownEvent (Key.Tab.WithCtrl); } - else if (vType is DatePicker) - { - for (var i = 0; i < 4; i++) - { - top.NewKeyDownEvent (Key.Tab.WithCtrl); - } - } - else - { - top.NewKeyDownEvent (Key.Tab); - } - - top.NewKeyDownEvent (Key.Tab); - - Assert.Equal (2, vTypeEnter); - Assert.Equal (1, vTypeLeave); - Assert.Equal (1, viewEnter); - Assert.Equal (1, viewLeave); - - top.Dispose (); - Application.Shutdown (); } + else + { + top.NewKeyDownEvent (Key.Tab); + } + + top.NewKeyDownEvent (Key.Tab); + + Assert.Equal (2, vTypeEnter); + Assert.Equal (1, vTypeLeave); + Assert.Equal (1, viewEnter); + Assert.Equal (1, viewLeave); + + top.Dispose (); + Application.Shutdown (); } - - [Fact] - public void AllViews_Tests_All_Constructors () + [Theory] + [MemberData (nameof (AllViewTypes))] + public void AllViews_Tests_All_Constructors (Type viewType) { - Application.Init (new FakeDriver ()); - - foreach (Type type in TestHelpers.GetAllViewClasses ()) - { - Assert.True (Test_All_Constructors_Of_Type (type)); - } - - Application.Shutdown (); + Assert.True (Test_All_Constructors_Of_Type (viewType)); } //[Fact] @@ -179,57 +170,4 @@ public class AllViewsTests (ITestOutputHelper output) return true; } - - // BUGBUG: This is a hack. We should figure out how to dynamically - // create the right type of argument for the constructor. - private static void AddArguments (Type paramType, List pTypes) - { - if (paramType == typeof (Rectangle)) - { - pTypes.Add (Rectangle.Empty); - } - else if (paramType == typeof (string)) - { - pTypes.Add (string.Empty); - } - else if (paramType == typeof (int)) - { - pTypes.Add (0); - } - else if (paramType == typeof (bool)) - { - pTypes.Add (true); - } - else if (paramType.Name == "IList") - { - pTypes.Add (new List ()); - } - else if (paramType.Name == "View") - { - var top = new Toplevel (); - var view = new View (); - top.Add (view); - pTypes.Add (view); - } - else if (paramType.Name == "View[]") - { - pTypes.Add (new View [] { }); - } - else if (paramType.Name == "Stream") - { - pTypes.Add (new MemoryStream ()); - } - else if (paramType.Name == "String") - { - pTypes.Add (string.Empty); - } - else if (paramType.Name == "TreeView`1[T]") - { - pTypes.Add (string.Empty); - } - else - { - pTypes.Add (null); - } - } }