123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327 |
- using NStack;
- using System;
- using System.Collections.Generic;
- using System.Xml.Linq;
- using Xunit;
- using Xunit.Abstractions;
- //using GraphViewTests = Terminal.Gui.Views.GraphViewTests;
- // Alias Console to MockConsole so we don't accidentally use Console
- using Console = Terminal.Gui.FakeConsole;
- namespace Terminal.Gui.ViewTests {
- public class AbsoluteLayoutTests {
- readonly ITestOutputHelper output;
- public AbsoluteLayoutTests (ITestOutputHelper output)
- {
- this.output = output;
- }
- [Fact]
- public void AbsoluteLayout_Constructor ()
- {
- var frame = new Rect (1, 2, 3, 4);
- var v = new View (frame);
- Assert.True (v.LayoutStyle == LayoutStyle.Absolute);
- Assert.Equal (frame, v.Frame);
- Assert.Equal (new Rect(0, 0, frame.Width, frame.Height), v.Bounds); // With Absolute Bounds *is* deterministic before Layout
- Assert.Null (v.X);
- Assert.Null (v.Y);
- Assert.Null (v.Height);
- Assert.Null (v.Width);
- v = new View (frame, "v");
- Assert.True (v.LayoutStyle == LayoutStyle.Absolute);
- Assert.Equal (frame, v.Frame);
- Assert.Equal (new Rect (0, 0, frame.Width, frame.Height), v.Bounds); // With Absolute Bounds *is* deterministic before Layout
- Assert.Null (v.X);
- Assert.Null (v.Y);
- Assert.Null (v.Height);
- Assert.Null (v.Width);
- v = new View (frame.X, frame.Y, "v");
- Assert.True (v.LayoutStyle == LayoutStyle.Absolute);
- // BUGBUG: v2 - I think the default size should be 0,0
- Assert.Equal (new Rect(frame.X, frame.Y, 1, 1), v.Frame);
- Assert.Equal (new Rect (0, 0, 1, 1), v.Bounds); // With Absolute Bounds *is* deterministic before Layout
- Assert.Null (v.X);
- Assert.Null (v.Y);
- Assert.Null (v.Height);
- Assert.Null (v.Width);
- }
- [Fact]
- public void AbsoluteLayout_Change_Frame ()
- {
- var frame = new Rect (1, 2, 3, 4);
- var newFrame = new Rect (1, 2, 30, 40);
- var v = new View (frame);
- v.Frame = newFrame;
- Assert.True (v.LayoutStyle == LayoutStyle.Absolute);
- Assert.Equal (newFrame, v.Frame);
- Assert.Equal (new Rect (0, 0, newFrame.Width, newFrame.Height), v.Bounds); // With Absolute Bounds *is* deterministic before Layout
- Assert.Null (v.X);
- Assert.Null (v.Y);
- Assert.Null (v.Height);
- Assert.Null (v.Width);
- v = new View (frame.X, frame.Y, "v");
- v.Frame = newFrame;
- Assert.Equal (newFrame, v.Frame);
- Assert.Equal (new Rect (0, 0, newFrame.Width, newFrame.Height), v.Bounds); // With Absolute Bounds *is* deterministic before Layout
- Assert.Null (v.X);
- Assert.Null (v.Y);
- Assert.Null (v.Height);
- Assert.Null (v.Width);
- newFrame = new Rect (10, 20, 30, 40);
- v = new View (frame);
- v.Frame = newFrame;
- Assert.Equal (newFrame, v.Frame);
- Assert.Equal (new Rect (0, 0, newFrame.Width, newFrame.Height), v.Bounds); // With Absolute Bounds *is* deterministic before Layout
- Assert.Null (v.X);
- Assert.Null (v.Y);
- Assert.Null (v.Height);
- Assert.Null (v.Width);
- v = new View (frame.X, frame.Y, "v");
- v.Frame = newFrame;
- Assert.Equal (newFrame, v.Frame);
- Assert.Equal (new Rect (0, 0, newFrame.Width, newFrame.Height), v.Bounds); // With Absolute Bounds *is* deterministic before Layout
- Assert.Null (v.X);
- Assert.Null (v.Y);
- Assert.Null (v.Height);
- Assert.Null (v.Width);
- }
- [Fact]
- public void AbsoluteLayout_Change_Height_or_Width_Absolute ()
- {
- var frame = new Rect (1, 2, 3, 4);
- var newFrame = new Rect (1, 2, 30, 40);
- var v = new View (frame);
- v.Height = newFrame.Height;
- v.Width = newFrame.Width;
- Assert.True (v.LayoutStyle == LayoutStyle.Absolute);
- Assert.Equal (newFrame, v.Frame);
- Assert.Equal (new Rect (0, 0, newFrame.Width, newFrame.Height), v.Bounds); // With Absolute Bounds *is* deterministic before Layout
- Assert.Null (v.X);
- Assert.Null (v.Y);
- Assert.Equal ($"Absolute({newFrame.Height})", v.Height.ToString());
- Assert.Equal ($"Absolute({newFrame.Width})", v.Width.ToString ());
- }
- [Fact]
- public void AbsoluteLayout_Change_Height_or_Width_NotAbsolute ()
- {
- var v = new View (Rect.Empty);
- v.Height = Dim.Fill ();
- v.Width = Dim.Fill ();
- Assert.True (v.LayoutStyle == LayoutStyle.Absolute); // BUGBUG: v2 - Changing the Height or Width should change the LayoutStyle
- }
- [Fact]
- public void AbsoluteLayout_Change_Height_or_Width_Null ()
- {
- var v = new View (Rect.Empty);
- v.Height = null;
- v.Width = null;
- Assert.True (v.LayoutStyle == LayoutStyle.Absolute);
- }
- [Fact]
- public void AbsoluteLayout_Change_X_or_Y_Absolute ()
- {
- var frame = new Rect (1, 2, 3, 4);
- var newFrame = new Rect (10, 20, 3, 4);
- var v = new View (frame);
- v.X = newFrame.X;
- v.Y = newFrame.Y;
- Assert.True (v.LayoutStyle == LayoutStyle.Absolute);
- Assert.Equal (newFrame, v.Frame);
- Assert.Equal (new Rect (0, 0, newFrame.Width, newFrame.Height), v.Bounds); // With Absolute Bounds *is* deterministic before Layout
- Assert.Equal ($"Absolute({newFrame.X})", v.X.ToString ());
- Assert.Equal ($"Absolute({newFrame.Y})", v.Y.ToString ());
- Assert.Null (v.Height);
- Assert.Null (v.Width);
- }
- [Fact]
- public void AbsoluteLayout_Change_X_or_Y_NotAbsolute ()
- {
- var v = new View (Rect.Empty);
- v.X = Pos.Center ();
- v.Y = Pos.Center ();
- Assert.True (v.LayoutStyle == LayoutStyle.Absolute); // BUGBUG: v2 - Changing the Height or Width should change the LayoutStyle
- }
- [Fact]
- public void AbsoluteLayout_Change_X_or_Y_Null ()
- {
- var v = new View (Rect.Empty);
- v.X = null;
- Assert.True (v.LayoutStyle == LayoutStyle.Absolute);
- v = new View (Rect.Empty);
- v.X = Pos.Center ();
- Assert.True (v.LayoutStyle == LayoutStyle.Absolute); // BUGBUG: v2 - Changing the Height or Width should change the LayoutStyle
- v.X = null;
- Assert.True (v.LayoutStyle == LayoutStyle.Absolute);
- v = new View (Rect.Empty);
- v.Y = null;
- Assert.True (v.LayoutStyle == LayoutStyle.Absolute);
- v = new View (Rect.Empty);
- v.Y = Pos.Center ();
- Assert.True (v.LayoutStyle == LayoutStyle.Absolute); // BUGBUG: v2 - Changing the Height or Width should change the LayoutStyle
- v.Y = null;
- Assert.True (v.LayoutStyle == LayoutStyle.Absolute);
- }
- [Fact]
- public void AbsoluteLayout_Change_X_Y_Height_Width_Absolute ()
- {
- var v = new View (Rect.Empty);
- v.X = 1;
- v.Y = 2;
- v.Height = 3;
- v.Width = 4;
- Assert.True (v.LayoutStyle == LayoutStyle.Absolute);
- v = new View (Rect.Empty);
- v.X = Pos.Center ();
- v.Y = Pos.Center ();
- v.Width = Dim.Fill ();
- v.Height = Dim.Fill ();
- Assert.True (v.LayoutStyle == LayoutStyle.Absolute); // BUGBUG: v2 - Changing the Height or Width should change the LayoutStyle
- // BUGBUG: v2 - If all of X, Y, Width, and Height are null or Absolute(n), isn't that the same as LayoutStyle.Absoulte?
- v.X = null;
- v.Y = null;
- v.Height = null;
- v.Width = null;
- Assert.True (v.LayoutStyle == LayoutStyle.Absolute); // We never automatically change to Absolute from Computed??
- v = new View (Rect.Empty);
- v.X = Pos.Center ();
- v.Y = Pos.Center ();
- v.Width = Dim.Fill ();
- v.Height = Dim.Fill ();
- Assert.True (v.LayoutStyle == LayoutStyle.Absolute); // BUGBUG: v2 - Changing the Height or Width should change the LayoutStyle
- // BUGBUG: v2 - If all of X, Y, Width, and Height are null or Absolute(n), isn't that the same as LayoutStyle.Absoulte?
- v.X = 1;
- v.Y = null;
- v.Height = null;
- v.Width = null;
- Assert.True (v.LayoutStyle == LayoutStyle.Absolute); // We never automatically change to Absolute from Computed??
- v = new View (Rect.Empty);
- v.X = Pos.Center ();
- v.Y = Pos.Center ();
- v.Width = Dim.Fill ();
- v.Height = Dim.Fill ();
- Assert.True (v.LayoutStyle == LayoutStyle.Absolute); // BUGBUG: v2 - Changing the Height or Width should change the LayoutStyle
- // BUGBUG: v2 - If all of X, Y, Width, and Height are null or Absolute(n), isn't that the same as LayoutStyle.Absoulte?
- v.X = null;
- v.Y = 2;
- v.Height = null;
- v.Width = null;
- Assert.True (v.LayoutStyle == LayoutStyle.Absolute); // We never automatically change to Absolute from Computed??
- v = new View (Rect.Empty);
- v.X = Pos.Center ();
- v.Y = Pos.Center ();
- v.Width = Dim.Fill ();
- v.Height = Dim.Fill ();
- Assert.True (v.LayoutStyle == LayoutStyle.Absolute); // BUGBUG: v2 - Changing the Height or Width should change the LayoutStyle
- // BUGBUG: v2 - If all of X, Y, Width, and Height are null or Absolute(n), isn't that the same as LayoutStyle.Absoulte?
- v.X = null;
- v.Y = null;
- v.Height = 3;
- v.Width = null;
- Assert.True (v.LayoutStyle == LayoutStyle.Absolute); // We never automatically change to Absolute from Computed??
- v = new View (Rect.Empty);
- v.X = Pos.Center ();
- v.Y = Pos.Center ();
- v.Width = Dim.Fill ();
- v.Height = Dim.Fill ();
- Assert.True (v.LayoutStyle == LayoutStyle.Absolute); // BUGBUG: v2 - Changing the Height or Width should change the LayoutStyle
- // BUGBUG: v2 - If all of X, Y, Width, and Height are null or Absolute(n), isn't that the same as LayoutStyle.Absoulte?
- v.X = null;
- v.Y = null;
- v.Height = null;
- v.Width = 4;
- Assert.True (v.LayoutStyle == LayoutStyle.Absolute); // We never automatically change to Absolute from Computed??
- }
- [Fact]
- public void AbsoluteLayout_Change_X_Y_Height_Width_Null ()
- {
- var v = new View (Rect.Empty);
- v.X = null;
- v.Y = null;
- v.Height = null;
- v.Width = null;
- Assert.True (v.LayoutStyle == LayoutStyle.Absolute);
- v = new View (Rect.Empty);
- v.X = Pos.Center ();
- v.Y = Pos.Center ();
- v.Width = Dim.Fill ();
- v.Height = Dim.Fill ();
- Assert.True (v.LayoutStyle == LayoutStyle.Absolute); // BUGBUG: v2 - Changing the Height or Width should change the LayoutStyle
- // BUGBUG: v2 - If all of X, Y, Width, and Height are null or Absolute(n), isn't that the same as LayoutStyle.Absoulte?
- v.X = null;
- v.Y = null;
- v.Height = null;
- v.Width = null;
- Assert.True (v.LayoutStyle == LayoutStyle.Absolute); // We never automatically change to Absolute from Computed??
- }
- [Fact]
- public void AbsoluteLayout_Layout ()
- {
- var superRect = new Rect (0, 0, 100, 100);
- var super = new View (superRect, "super");
- Assert.True (super.LayoutStyle == LayoutStyle.Absolute);
- var v1 = new View () {
- X = 0,
- Y = 0,
- Width = 10,
- Height = 10
- };
- // BUGBUG: v2 - This should be LayoutStyle.Absolute
- Assert.True (v1.LayoutStyle == LayoutStyle.Computed);
- var v2 = new View () {
- X = 10,
- Y = 10,
- Width = 10,
- Height = 10
- };
- // BUGBUG: v2 - This should be LayoutStyle.Absolute
- Assert.True (v1.LayoutStyle == LayoutStyle.Computed);
- super.Add (v1, v2);
- super.LayoutSubviews ();
- Assert.Equal (new Rect (0, 0, 10, 10), v1.Frame);
- Assert.Equal (new Rect (10, 10, 10, 10), v2.Frame);
- }
- }
- }
|