diff --git a/UnitTests/DimPosTests.cs b/UnitTests/DimPosTests.cs new file mode 100644 index 000000000..175ed3967 --- /dev/null +++ b/UnitTests/DimPosTests.cs @@ -0,0 +1,127 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.IO; +using System.Linq; +using Terminal.Gui; +using Xunit; + +// Alais Console to MockConsole so we don't accidentally use Console +using Console = Terminal.Gui.MockConsole; + +namespace Terminal.Gui { + public class DimPosTests { + [Fact] + public void TestNew () + { + var pos = new Pos (); + Assert.Equal ("Terminal.Gui.Pos", pos.ToString ()); + } + + [Fact] + public void TestAnchorEnd () + { + var pos = Pos.AnchorEnd (); + Assert.Equal ("Pos.AnchorEnd(margin=0)", pos.ToString ()); + + pos = Pos.AnchorEnd (5); + Assert.Equal ("Pos.AnchorEnd(margin=5)", pos.ToString ()); + } + + [Fact] + public void TestAt () + { + var pos = Pos.At (0); + Assert.Equal ("Pos.Absolute(0)", pos.ToString ()); + + pos = Pos.At (5); + Assert.Equal ("Pos.Absolute(5)", pos.ToString ()); + + //Assert.Throws (() => pos = Pos.At (-1)); + } + + [Fact] + public void TestLeft () + { + var pos = Pos.Left (null); + Assert.Throws (() => pos.ToString ()); + + pos = Pos.Left (new View ()); + Assert.Equal ("Pos.View(side=x, target=View()({X=0,Y=0,Width=0,Height=0})", pos.ToString ()); + + pos = Pos.Left (new View (new Rect (1, 2, 3, 4))); + Assert.Equal ("Pos.View(side=x, target=View()({X=1,Y=2,Width=3,Height=4})", pos.ToString ()); + } + + [Fact] + public void TestTop () + { + var pos = Pos.Top (null); + Assert.Throws (() => pos.ToString ()); + + pos = Pos.Top (new View ()); + Assert.Equal ("Pos.View(side=y, target=View()({X=0,Y=0,Width=0,Height=0})", pos.ToString ()); + + pos = Pos.Top (new View (new Rect (1, 2, 3, 4))); + Assert.Equal ("Pos.View(side=y, target=View()({X=1,Y=2,Width=3,Height=4})", pos.ToString ()); + } + + [Fact] + public void TestRight () + { + var pos = Pos.Right (null); + Assert.Throws (() => pos.ToString ()); + + pos = Pos.Right (new View ()); + Assert.Equal ("Pos.View(side=right, target=View()({X=0,Y=0,Width=0,Height=0})", pos.ToString ()); + + pos = Pos.Right (new View (new Rect (1, 2, 3, 4))); + Assert.Equal ("Pos.View(side=right, target=View()({X=1,Y=2,Width=3,Height=4})", pos.ToString ()); + } + + [Fact] + public void TestBottom () + { + var pos = Pos.Bottom (null); + Assert.Throws (() => pos.ToString ()); + + pos = Pos.Bottom (new View ()); + Assert.Equal ("Pos.View(side=bottom, target=View()({X=0,Y=0,Width=0,Height=0})", pos.ToString ()); + + pos = Pos.Bottom (new View (new Rect (1, 2, 3, 4))); + Assert.Equal ("Pos.View(side=bottom, target=View()({X=1,Y=2,Width=3,Height=4})", pos.ToString ()); + + //Assert.Throws (() => pos = Pos.Bottom (new View (new Rect (0, 0, -3, -4)))); + + } + + [Fact] + public void TestCenter () + { + var pos = Pos.Center (); + Assert.Equal ("Pos.Center", pos.ToString ()); + } + + [Fact] + public void TestPercent () + { + var pos = Pos.Percent (0); + Assert.Equal ("Pos.Factor(0)", pos.ToString ()); + + pos = Pos.Percent (0.5F); + Assert.Equal ("Pos.Factor(0.005)", pos.ToString ()); + + pos = Pos.Percent (100); + Assert.Equal ("Pos.Factor(1)", pos.ToString ()); + + Assert.Throws (() => pos = Pos.Percent (-1)); + Assert.Throws (() => pos = Pos.Percent (101)); + Assert.Throws (() => pos = Pos.Percent (100.0001F)); + Assert.Throws (() => pos = Pos.Percent (1000001)); + } + + // TODO: Test operators + + // TODO: Test Dim + } +} diff --git a/UnitTests/ResponderTests.cs b/UnitTests/ResponderTests.cs new file mode 100644 index 000000000..3d8680604 --- /dev/null +++ b/UnitTests/ResponderTests.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Terminal.Gui; +using Xunit; + +// Alais Console to MockConsole so we don't accidentally use Console +using Console = Terminal.Gui.MockConsole; + +namespace Terminal.Gui { + public class ResponderTests { + [Fact] + public void TestNew () + { + var r = new Responder (); + Assert.NotNull (r); + Assert.Equal ("Terminal.Gui.Responder", r.ToString ()); + Assert.False (r.CanFocus); + Assert.False (r.HasFocus); + } + + [Fact] + public void TestMethods () + { + var r = new Responder (); + + Assert.False (r.ProcessKey (new KeyEvent () { Key = Key.Unknown })); + Assert.False (r.ProcessHotKey (new KeyEvent () { Key = Key.Unknown })); + Assert.False (r.ProcessColdKey (new KeyEvent () { Key = Key.Unknown })); + Assert.False (r.OnKeyDown (new KeyEvent () { Key = Key.Unknown })); + Assert.False (r.OnKeyUp (new KeyEvent () { Key = Key.Unknown })); + Assert.False (r.MouseEvent (new MouseEvent () { Flags = MouseFlags.AllEvents })); + Assert.False (r.OnMouseEnter (new MouseEvent () { Flags = MouseFlags.AllEvents })); + Assert.False (r.OnMouseLeave (new MouseEvent () { Flags = MouseFlags.AllEvents })); + Assert.False (r.OnEnter ()); + Assert.False (r.OnLeave ()); + } + } +} diff --git a/UnitTests/ViewTests.cs b/UnitTests/ViewTests.cs new file mode 100644 index 000000000..5fe17f35f --- /dev/null +++ b/UnitTests/ViewTests.cs @@ -0,0 +1,111 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.IO; +using System.Linq; +using Terminal.Gui; +using Xunit; + +// Alais Console to MockConsole so we don't accidentally use Console +using Console = Terminal.Gui.MockConsole; + +namespace Terminal.Gui { + public class ViewTests { + [Fact] + public void TestNew () + { + // Parameterless + var r = new View (); + Assert.NotNull (r); + Assert.Equal (LayoutStyle.Computed, r.LayoutStyle); + Assert.Equal ("View()({X=0,Y=0,Width=0,Height=0})", r.ToString ()); + Assert.False (r.CanFocus); + Assert.False (r.HasFocus); + Assert.Equal (new Rect (0, 0, 0, 0), r.Bounds); + Assert.Equal (new Rect (0, 0, 0, 0), r.Frame); + Assert.Null (r.Focused); + Assert.Null (r.ColorScheme); + Assert.Equal (Dim.Sized (0), r.Height); + Assert.Equal (Dim.Sized (0), r.Height); + // BUGBUG: Pos needs eqality implemented + //Assert.Equal (Pos.At (0), r.X); + //Assert.Equal (Pos.At (0), r.Y); + Assert.False (r.IsCurrentTop); + Assert.Empty (r.Id); + Assert.Empty (r.Subviews); + Assert.False (r.WantContinuousButtonPressed); + Assert.False (r.WantMousePositionReports); + Assert.Null (r.GetEnumerator().Current); + Assert.Null (r.SuperView); + Assert.Null (r.MostFocused); + + // Empty Rect + r = new View (Rect.Empty); + Assert.NotNull (r); + Assert.Equal (LayoutStyle.Absolute, r.LayoutStyle); + Assert.Equal ("View()({X=0,Y=0,Width=0,Height=0})", r.ToString ()); + Assert.False (r.CanFocus); + Assert.False (r.HasFocus); + Assert.Equal (new Rect (0, 0, 0, 0), r.Bounds); + Assert.Equal (new Rect (0, 0, 0, 0), r.Frame); + Assert.Null (r.Focused); + Assert.Null (r.ColorScheme); + Assert.Null (r.Height); + Assert.Null (r.Height); + Assert.Null (r.X); + Assert.Null (r.Y); + Assert.False (r.IsCurrentTop); + Assert.Empty (r.Id); + Assert.Empty (r.Subviews); + Assert.False (r.WantContinuousButtonPressed); + Assert.False (r.WantMousePositionReports); + Assert.Null (r.GetEnumerator ().Current); + Assert.Null (r.SuperView); + Assert.Null (r.MostFocused); + + // Rect with values + r = new View (new Rect(1, 2, 3, 4)); + Assert.NotNull (r); + Assert.Equal (LayoutStyle.Absolute, r.LayoutStyle); + Assert.Equal ("View()({X=1,Y=2,Width=3,Height=4})", r.ToString ()); + Assert.False (r.CanFocus); + Assert.False (r.HasFocus); + Assert.Equal (new Rect (0, 0, 3, 4), r.Bounds); + Assert.Equal (new Rect (1, 2, 3, 4), r.Frame); + Assert.Null (r.Focused); + Assert.Null (r.ColorScheme); + Assert.Null (r.Height); + Assert.Null (r.Height); + Assert.Null (r.X); + Assert.Null (r.Y); + Assert.False (r.IsCurrentTop); + Assert.Empty (r.Id); + Assert.Empty (r.Subviews); + Assert.False (r.WantContinuousButtonPressed); + Assert.False (r.WantMousePositionReports); + Assert.Null (r.GetEnumerator ().Current); + Assert.Null (r.SuperView); + Assert.Null (r.MostFocused); + + } + + [Fact] + public void TestMethods () + { + var r = new View (); + + Assert.False (r.ProcessKey (new KeyEvent () { Key = Key.Unknown })); + Assert.False (r.ProcessHotKey (new KeyEvent () { Key = Key.Unknown })); + Assert.False (r.ProcessColdKey (new KeyEvent () { Key = Key.Unknown })); + Assert.False (r.OnKeyDown (new KeyEvent () { Key = Key.Unknown })); + Assert.False (r.OnKeyUp (new KeyEvent () { Key = Key.Unknown })); + Assert.False (r.MouseEvent (new MouseEvent () { Flags = MouseFlags.AllEvents })); + Assert.False (r.OnMouseEnter (new MouseEvent () { Flags = MouseFlags.AllEvents })); + Assert.False (r.OnMouseLeave (new MouseEvent () { Flags = MouseFlags.AllEvents })); + Assert.False (r.OnEnter ()); + Assert.False (r.OnLeave ()); + + // TODO: Add more + } + } +}