1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243 |
- using Xunit.Abstractions;
- using static System.Net.Mime.MediaTypeNames;
- namespace Terminal.Gui.LayoutTests;
- /// <summary>
- /// Test the <see cref="View.FrameToScreen"/> and <see cref="View.ViewportToScreen"/> methods.
- /// DOES NOT TEST Adornment.xxxToScreen methods. Those are in ./Adornment/ToScreenTests.cs
- /// </summary>
- /// <param name="output"></param>
- public class ToScreenTests (ITestOutputHelper output)
- {
- private readonly ITestOutputHelper _output = output;
- // Test FrameToScreen
- [Theory]
- [InlineData (0, 0, 0, 0)]
- [InlineData (1, 0, 1, 0)]
- [InlineData (0, 1, 0, 1)]
- [InlineData (1, 1, 1, 1)]
- [InlineData (10, 10, 10, 10)]
- public void FrameToScreen_NoSuperView (int frameX, int frameY, int expectedScreenX, int expectedScreenY)
- {
- var view = new View { X = frameX, Y = frameY, Width = 10, Height = 10 };
- view.Layout ();
- var expected = new Rectangle (expectedScreenX, expectedScreenY, 10, 10);
- Rectangle actual = view.FrameToScreen ();
- Assert.Equal (expected, actual);
- }
- [Theory]
- [InlineData (0, 0, 0, 0, 0)]
- [InlineData (1, 0, 0, 1, 1)]
- [InlineData (2, 0, 0, 2, 2)]
- [InlineData (1, 1, 0, 2, 1)]
- [InlineData (1, 0, 1, 1, 2)]
- [InlineData (1, 1, 1, 2, 2)]
- [InlineData (1, 10, 10, 11, 11)]
- public void FrameToScreen_SuperView (
- int superOffset,
- int frameX,
- int frameY,
- int expectedScreenX,
- int expectedScreenY
- )
- {
- var super = new View { X = superOffset, Y = superOffset, Width = 20, Height = 20 };
- var view = new View { X = frameX, Y = frameY, Width = 10, Height = 10 };
- super.Add (view);
- super.Layout ();
- var expected = new Rectangle (expectedScreenX, expectedScreenY, 10, 10);
- Rectangle actual = view.FrameToScreen ();
- Assert.Equal (expected, actual);
- }
- [Theory]
- [InlineData (0, 0)]
- [InlineData (1, 1)]
- [InlineData (-1, -1)]
- [InlineData (11, 11)]
- public void FrameToScreen_NoSuperView_WithoutAdornments (int x, int expectedX)
- {
- // We test with only X because Y is equivalent. Height/Width are irrelevant.
- // Arrange
- var frame = new Rectangle (x, 0, 10, 10);
- var view = new View ();
- view.Frame = frame;
- // Act
- var screen = view.FrameToScreen ();
- // Assert
- Assert.Equal (expectedX, screen.X);
- }
- [Theory]
- [InlineData (0, 0)]
- [InlineData (1, 1)]
- [InlineData (-1, -1)]
- [InlineData (11, 11)]
- public void FrameToScreen_NoSuperView_WithAdornments (int x, int expectedX)
- {
- // We test with only X because Y is equivalent. Height/Width are irrelevant.
- // Arrange
- var frame = new Rectangle (x, 0, 10, 10);
- var view = new View ();
- view.BorderStyle = LineStyle.Single;
- view.Frame = frame;
- // Act
- var screen = view.FrameToScreen ();
- // Assert
- Assert.Equal (expectedX, screen.X);
- }
- [Theory]
- [InlineData (0, 1)]
- [InlineData (1, 2)]
- [InlineData (-1, 0)]
- [InlineData (11, 12)]
- public void FrameToScreen_NoSuperView_WithAdornment_WithSubview (int x, int expectedX)
- {
- // We test with only X because Y is equivalent. Height/Width are irrelevant.
- // Arrange
- var frame = new Rectangle (x, 0, 10, 10);
- var view = new View ();
- view.BorderStyle = LineStyle.Single;
- view.Frame = frame;
- var subviewOfBorder = new View ()
- {
- X = 1, // screen should be 1
- Y = 0,
- Width = 1,
- Height = 1
- };
- view.Border.Add (subviewOfBorder);
- view.BeginInit ();
- view.EndInit ();
- // Act
- var screen = subviewOfBorder.FrameToScreen ();
- // Assert
- Assert.Equal (expectedX, screen.X);
- }
- [Theory]
- [InlineData (0, 3)]
- [InlineData (1, 4)]
- [InlineData (-1, 2)]
- [InlineData (11, 14)]
- public void FrameToScreen_Adornment_WithSubview_WithSubview (int topX, int expectedX)
- {
- // We test with only X because Y is equivalent. Height/Width are irrelevant.
- // Arrange
- var adornmentFrame = new Rectangle (topX, 0, 10, 10);
- var adornment = new Adornment ();
- adornment.Frame = adornmentFrame;
- adornment.Thickness = new (1);
- var subviewOfAdornment = new View ()
- {
- Id = "subviewOfAdornment",
- X = 1, // screen should be 1
- Y = 0,
- Width = 1,
- Height = 1,
- };
- var subviewOfSubview = new View ()
- {
- Id = "subviewOfSubview",
- X = 2, // screen should be 3 (the subviewOfAdornment location is 1)
- Y = 0,
- Width = 1,
- Height = 1
- };
- subviewOfAdornment.Add (subviewOfSubview);
- adornment.Add (subviewOfAdornment);
- adornment.BeginInit ();
- adornment.EndInit ();
- // Act
- var screen = subviewOfSubview.FrameToScreen ();
- // Assert
- Assert.Equal (expectedX, screen.X);
- }
- [Theory]
- [InlineData (0, 0)]
- [InlineData (1, 1)]
- [InlineData (-1, -1)]
- [InlineData (11, 11)]
- public void FrameToScreen_SuperView_WithoutAdornments (int x, int expectedX)
- {
- // We test with only X because Y is equivalent. Height/Width are irrelevant.
- // Arrange
- var frame = new Rectangle (x, 0, 10, 10);
- var superView = new View ()
- {
- X = 0,
- Y = 0,
- Height = Dim.Fill (),
- Width = Dim.Fill ()
- };
- var view = new View ();
- view.Frame = frame;
- superView.Add (view);
- superView.LayoutSubviews ();
- // Act
- var screen = view.FrameToScreen ();
- // Assert
- Assert.Equal (expectedX, screen.X);
- }
- [Theory]
- [InlineData (0, 1)]
- [InlineData (1, 2)]
- [InlineData (-1, 0)]
- [InlineData (11, 12)]
- public void FrameToScreen_SuperView_WithAdornments (int x, int expectedX)
- {
- // We test with only X because Y is equivalent. Height/Width are irrelevant.
- // Arrange
- var frame = new Rectangle (x, 0, 10, 10);
- var superView = new View ()
- {
- X = 0,
- Y = 0,
- Height = Dim.Fill (),
- Width = Dim.Fill ()
- };
- superView.BorderStyle = LineStyle.Single;
- var view = new View ();
- view.Frame = frame;
- superView.Add (view);
- superView.LayoutSubviews ();
- // Act
- var screen = view.FrameToScreen ();
- // Assert
- Assert.Equal (expectedX, screen.X);
- }
- [Theory]
- [InlineData (0, 0)]
- [InlineData (1, 1)]
- [InlineData (-1, -1)]
- [InlineData (11, 11)]
- public void FrameToScreen_NestedSuperView_WithoutAdornments (int x, int expectedX)
- {
- // We test with only X because Y is equivalent. Height/Width are irrelevant.
- // Arrange
- var frame = new Rectangle (x, 0, 10, 10);
- var superSuperView = new View ()
- {
- X = 0,
- Y = 0,
- Height = Dim.Fill (),
- Width = Dim.Fill ()
- };
- var superView = new View ()
- {
- X = 0,
- Y = 0,
- Height = Dim.Fill (),
- Width = Dim.Fill ()
- };
- superSuperView.Add (superView);
- var view = new View ();
- view.Frame = frame;
- superView.Add (view);
- superView.LayoutSubviews ();
- // Act
- var screen = view.FrameToScreen ();
- // Assert
- Assert.Equal (expectedX, screen.X);
- }
- [Theory]
- [InlineData (0, 2)]
- [InlineData (1, 3)]
- [InlineData (-1, 1)]
- [InlineData (11, 13)]
- public void FrameToScreen_NestedSuperView_WithAdornments (int x, int expectedX)
- {
- // We test with only X because Y is equivalent. Height/Width are irrelevant.
- // Arrange
- var frame = new Rectangle (x, 0, 10, 10);
- var superSuperView = new View ()
- {
- X = 0,
- Y = 0,
- Height = Dim.Fill (),
- Width = Dim.Fill ()
- };
- superSuperView.BorderStyle = LineStyle.Single;
- var superView = new View ()
- {
- X = 0,
- Y = 0,
- Height = Dim.Fill (),
- Width = Dim.Fill ()
- };
- superSuperView.Add (superView);
- superView.BorderStyle = LineStyle.Single;
- var view = new View ();
- view.Frame = frame;
- superView.Add (view);
- superSuperView.Layout ();
- // Act
- var screen = view.FrameToScreen ();
- // Assert
- Assert.Equal (expectedX, screen.X);
- }
- // ContentToScreen tests ----------------------
- [Fact]
- public void ContentToScreen_With_Positive_Content_Location ()
- {
- View view = new ()
- {
- X = 1,
- Y = 1,
- Width = 10,
- Height = 10
- };
- view.Layout ();
- view.SetContentSize (new (20, 20));
- Point testPoint = new (0, 0);
- Assert.Equal (new Point (1, 1), view.ContentToScreen (testPoint));
- }
- [Theory]
- [InlineData (0, 0, 1)]
- [InlineData (1, 0, 2)]
- [InlineData (-1, 0, 0)]
- [InlineData (0, 1, 2)]
- [InlineData (1, 1, 3)]
- [InlineData (-1, 1, 1)]
- [InlineData (0, -1, 0)]
- [InlineData (1, -1, 1)]
- [InlineData (-1, -1, -1)]
- public void ContentToScreen_NoSuperView_WithAdornments (int frameX, int contentX, int expectedX)
- {
- // We test with only X because Y is equivalent. Height/Width are irrelevant.
- // Arrange
- var frame = new Rectangle (frameX, 0, 10, 10);
- var view = new View ();
- view.Frame = frame;
- view.SetContentSize (new (20, 20));
- view.BorderStyle = LineStyle.Single;
- // Act
- var screen = view.ContentToScreen (new (contentX, 0));
- // Assert
- Assert.Equal (expectedX, screen.X);
- }
- [Theory]
- [InlineData (0, 0, 0)]
- [InlineData (1, 0, 1)]
- [InlineData (-1, 0, -1)]
- [InlineData (11, 0, 11)]
- [InlineData (0, 1, 1)]
- [InlineData (1, 1, 2)]
- [InlineData (-1, 1, 0)]
- [InlineData (11, 1, 12)]
- [InlineData (0, -1, -1)]
- [InlineData (1, -1, 0)]
- [InlineData (-1, -1, -2)]
- [InlineData (11, -1, 10)]
- public void ContentToScreen_SuperView_WithoutAdornments (int frameX, int contentX, int expectedX)
- {
- // We test with only X because Y is equivalent. Height/Width are irrelevant.
- // Arrange
- var frame = new Rectangle (frameX, 0, 10, 10);
- var superView = new View ()
- {
- X = 0,
- Y = 0,
- Height = Dim.Fill (),
- Width = Dim.Fill ()
- };
- var view = new View ();
- view.Frame = frame;
- view.SetContentSize (new (20, 20));
- superView.Add (view);
- superView.LayoutSubviews ();
- // Act
- var screen = view.ContentToScreen (new (contentX, 0));
- // Assert
- Assert.Equal (expectedX, screen.X);
- }
- //[Theory]
- //[InlineData (0, 0, 1)]
- //[InlineData (1, 0, 2)]
- //[InlineData (-1, 0, 0)]
- //[InlineData (11, 0, 12)]
- //[InlineData (0, 1, 2)]
- //[InlineData (1, 1, 3)]
- //[InlineData (-1, 1, 1)]
- //[InlineData (11, 1, 13)]
- //[InlineData (0, -1, 0)]
- //[InlineData (1, -1, 1)]
- //[InlineData (-1, -1, -1)]
- //[InlineData (11, -1, 11)]
- //public void ContentToScreen_SuperView_WithAdornments (int frameX, int ContentX, int expectedX)
- //{
- // // We test with only X because Y is equivalent. Height/Width are irrelevant.
- // // Arrange
- // var frame = new Rectangle (frameX, 0, 10, 10);
- // var superView = new View ()
- // {
- // X = 0,
- // Y = 0,
- // Height = Dim.Fill (),
- // Width = Dim.Fill ()
- // };
- // superView.BorderStyle = LineStyle.Single;
- // var view = new View ();
- // view.Frame = frame;
- // superView.Add (view);
- // superView.LayoutSubviews ();
- // // Act
- // var screen = view.ContentToScreen (new (ContentX, 0, 0, 0));
- // // Assert
- // Assert.Equal (expectedX, screen.X);
- //}
- //[Theory]
- //[InlineData (0, 0, 0)]
- //[InlineData (1, 0, 1)]
- //[InlineData (-1, 0, -1)]
- //[InlineData (11, 0, 11)]
- //[InlineData (0, 1, 1)]
- //[InlineData (1, 1, 2)]
- //[InlineData (-1, 1, 0)]
- //[InlineData (11, 1, 12)]
- //[InlineData (0, -1, -1)]
- //[InlineData (1, -1, 0)]
- //[InlineData (-1, -1, -2)]
- //[InlineData (11, -1, 10)]
- //public void ContentToScreen_NestedSuperView_WithoutAdornments (int frameX, int ContentX, int expectedX)
- //{
- // // We test with only X because Y is equivalent. Height/Width are irrelevant.
- // // Arrange
- // var frame = new Rectangle (frameX, 0, 10, 10);
- // var superSuperView = new View ()
- // {
- // X = 0,
- // Y = 0,
- // Height = Dim.Fill (),
- // Width = Dim.Fill ()
- // };
- // var superView = new View ()
- // {
- // X = 0,
- // Y = 0,
- // Height = Dim.Fill (),
- // Width = Dim.Fill ()
- // };
- // superSuperView.Add (superView);
- // var view = new View ();
- // view.Frame = frame;
- // superView.Add (view);
- // superView.LayoutSubviews ();
- // // Act
- // var screen = view.ContentToScreen (new (ContentX, 0, 0, 0));
- // // Assert
- // Assert.Equal (expectedX, screen.X);
- //}
- //[Theory]
- //[InlineData (0, 0, 2)]
- //[InlineData (1, 0, 3)]
- //[InlineData (-1, 0, 1)]
- //[InlineData (11, 0, 13)]
- //[InlineData (0, 1, 3)]
- //[InlineData (1, 1, 4)]
- //[InlineData (-1, 1, 2)]
- //[InlineData (11, 1, 14)]
- //[InlineData (0, -1, 1)]
- //[InlineData (1, -1, 2)]
- //[InlineData (-1, -1, 0)]
- //[InlineData (11, -1, 12)]
- //public void ContentToScreen_NestedSuperView_WithAdornments (int frameX, int ContentX, int expectedX)
- //{
- // // We test with only X because Y is equivalent. Height/Width are irrelevant.
- // // Arrange
- // var frame = new Rectangle (frameX, 0, 10, 10);
- // var superSuperView = new View ()
- // {
- // X = 0,
- // Y = 0,
- // Height = Dim.Fill (),
- // Width = Dim.Fill ()
- // };
- // superSuperView.BorderStyle = LineStyle.Single;
- // var superView = new View ()
- // {
- // X = 0,
- // Y = 0,
- // Height = Dim.Fill (),
- // Width = Dim.Fill ()
- // };
- // superSuperView.Add (superView);
- // superView.BorderStyle = LineStyle.Single;
- // var view = new View ();
- // view.Frame = frame;
- // superView.Add (view);
- // superView.LayoutSubviews ();
- // // Act
- // var screen = view.ContentToScreen (new (ContentX, 0, 0, 0));
- // // Assert
- // Assert.Equal (expectedX, screen.X);
- //}
- //[Theory]
- //[InlineData (0, 0, 3)]
- //[InlineData (1, 0, 4)]
- //[InlineData (-1, 0, 2)]
- //[InlineData (11, 0, 14)]
- //[InlineData (0, 1, 4)]
- //[InlineData (1, 1, 5)]
- //[InlineData (-1, 1, 3)]
- //[InlineData (11, 1, 15)]
- //[InlineData (0, -1, 2)]
- //[InlineData (1, -1, 3)]
- //[InlineData (-1, -1, 1)]
- //[InlineData (11, -1, 13)]
- //public void ContentToScreen_Positive_NestedSuperView_WithAdornments (int frameX, int testX, int expectedX)
- //{
- // // We test with only X because Y is equivalent. Height/Width are irrelevant.
- // // Arrange
- // var frame = new Rectangle (frameX, 0, 10, 10);
- // var superSuperView = new View ()
- // {
- // X = 0,
- // Y = 0,
- // Height = Dim.Fill (),
- // Width = Dim.Fill ()
- // };
- // superSuperView.BorderStyle = LineStyle.Single;
- // var superView = new View ()
- // {
- // X = 0,
- // Y = 0,
- // Height = Dim.Fill (),
- // Width = Dim.Fill ()
- // };
- // superSuperView.Add (superView);
- // superView.BorderStyle = LineStyle.Single;
- // var view = new View ();
- // view.Frame = frame;
- // view.SetContentSize (new (11, 11));
- // view.Content = view.Content with { Location = new (1, 1) };
- // superView.Add (view);
- // superView.LayoutSubviews ();
- // // Act
- // var screen = view.ContentToScreen (new (testX, 0, 0, 0));
- // // Assert
- // Assert.Equal (expectedX, screen.X);
- //}
- // ViewportToScreen tests ----------------------
- [Fact]
- public void ViewportToScreen_With_Positive_Viewport_Location ()
- {
- View view = new ()
- {
- Width = 10,
- Height = 10,
- ViewportSettings = ViewportSettings.AllowNegativeLocation
- };
- view.Layout ();
- Rectangle testRect = new Rectangle (0, 0, 1, 1);
- Assert.Equal (new Point (0, 0), view.ViewportToScreen (testRect).Location);
- view.Viewport = view.Viewport with { Location = new Point (1, 1) };
- Assert.Equal (new Rectangle (1, 1, 10, 10), view.Viewport);
- Assert.Equal (new Point (0, 0), view.ViewportToScreen (testRect).Location);
- }
- [Theory]
- [InlineData (0, 0, 0)]
- [InlineData (1, 0, 1)]
- [InlineData (-1, 0, -1)]
- [InlineData (11, 0, 11)]
- public void ViewportToScreen_NoSuperView_WithoutAdornments (int frameX, int viewportX, int expectedX)
- {
- // We test with only X because Y is equivalent. Height/Width are irrelevant.
- // Arrange
- var frame = new Rectangle (frameX, 0, 10, 10);
- var view = new View ();
- view.Frame = frame;
- view.Layout ();
- // Act
- var screen = view.ViewportToScreen (new Point (viewportX, 0));
- // Assert
- Assert.Equal (expectedX, screen.X);
- }
- [Theory]
- [InlineData (0, 0, 1)]
- [InlineData (1, 0, 2)]
- [InlineData (-1, 0, 0)]
- [InlineData (11, 0, 12)]
- [InlineData (0, 1, 2)]
- [InlineData (1, 1, 3)]
- [InlineData (-1, 1, 1)]
- [InlineData (11, 1, 13)]
- [InlineData (0, -1, 0)]
- [InlineData (1, -1, 1)]
- [InlineData (-1, -1, -1)]
- [InlineData (11, -1, 11)]
- public void ViewportToScreen_NoSuperView_WithAdornments (int frameX, int viewportX, int expectedX)
- {
- // We test with only X because Y is equivalent. Height/Width are irrelevant.
- // Arrange
- var frame = new Rectangle (frameX, 0, 10, 10);
- var view = new View ();
- view.BorderStyle = LineStyle.Single;
- view.Frame = frame;
- // Act
- var screen = view.ViewportToScreen (new Point (viewportX, 0));
- // Assert
- Assert.Equal (expectedX, screen.X);
- }
- [Theory]
- [InlineData (0, 0, 0)]
- [InlineData (1, 0, 1)]
- [InlineData (-1, 0, -1)]
- [InlineData (11, 0, 11)]
- [InlineData (0, 1, 1)]
- [InlineData (1, 1, 2)]
- [InlineData (-1, 1, 0)]
- [InlineData (11, 1, 12)]
- [InlineData (0, -1, -1)]
- [InlineData (1, -1, 0)]
- [InlineData (-1, -1, -2)]
- [InlineData (11, -1, 10)]
- public void ViewportToScreen_SuperView_WithoutAdornments (int frameX, int viewportX, int expectedX)
- {
- // We test with only X because Y is equivalent. Height/Width are irrelevant.
- // Arrange
- var frame = new Rectangle (frameX, 0, 10, 10);
- var superView = new View ()
- {
- X = 0,
- Y = 0,
- Height = Dim.Fill (),
- Width = Dim.Fill ()
- };
- var view = new View ();
- view.Frame = frame;
- superView.Add (view);
- superView.LayoutSubviews ();
- // Act
- var screen = view.ViewportToScreen (new Point (viewportX, 0));
- // Assert
- Assert.Equal (expectedX, screen.X);
- }
- [Theory]
- [InlineData (0, 0, 1)]
- [InlineData (1, 0, 2)]
- [InlineData (-1, 0, 0)]
- [InlineData (11, 0, 12)]
- [InlineData (0, 1, 2)]
- [InlineData (1, 1, 3)]
- [InlineData (-1, 1, 1)]
- [InlineData (11, 1, 13)]
- [InlineData (0, -1, 0)]
- [InlineData (1, -1, 1)]
- [InlineData (-1, -1, -1)]
- [InlineData (11, -1, 11)]
- public void ViewportToScreen_SuperView_WithAdornments (int frameX, int viewportX, int expectedX)
- {
- // We test with only X because Y is equivalent. Height/Width are irrelevant.
- // Arrange
- var frame = new Rectangle (frameX, 0, 10, 10);
- var superView = new View ()
- {
- X = 0,
- Y = 0,
- Height = Dim.Fill (),
- Width = Dim.Fill ()
- };
- superView.BorderStyle = LineStyle.Single;
- var view = new View ();
- view.Frame = frame;
- superView.Add (view);
- superView.LayoutSubviews ();
- // Act
- var screen = view.ViewportToScreen (new Point (viewportX, 0));
- // Assert
- Assert.Equal (expectedX, screen.X);
- }
- [Theory]
- [InlineData (0, 0, 0)]
- [InlineData (1, 0, 1)]
- [InlineData (-1, 0, -1)]
- [InlineData (11, 0, 11)]
- [InlineData (0, 1, 1)]
- [InlineData (1, 1, 2)]
- [InlineData (-1, 1, 0)]
- [InlineData (11, 1, 12)]
- [InlineData (0, -1, -1)]
- [InlineData (1, -1, 0)]
- [InlineData (-1, -1, -2)]
- [InlineData (11, -1, 10)]
- public void ViewportToScreen_NestedSuperView_WithoutAdornments (int frameX, int viewportX, int expectedX)
- {
- // We test with only X because Y is equivalent. Height/Width are irrelevant.
- // Arrange
- var frame = new Rectangle (frameX, 0, 10, 10);
- var superSuperView = new View ()
- {
- X = 0,
- Y = 0,
- Height = Dim.Fill (),
- Width = Dim.Fill ()
- };
- var superView = new View ()
- {
- X = 0,
- Y = 0,
- Height = Dim.Fill (),
- Width = Dim.Fill ()
- };
- superSuperView.Add (superView);
- var view = new View ();
- view.Frame = frame;
- superView.Add (view);
- superView.LayoutSubviews ();
- // Act
- var screen = view.ViewportToScreen (new Point (viewportX, 0));
- // Assert
- Assert.Equal (expectedX, screen.X);
- }
- [Theory]
- [InlineData (0, 0, 2)]
- [InlineData (1, 0, 3)]
- [InlineData (-1, 0, 1)]
- [InlineData (11, 0, 13)]
- [InlineData (0, 1, 3)]
- [InlineData (1, 1, 4)]
- [InlineData (-1, 1, 2)]
- [InlineData (11, 1, 14)]
- [InlineData (0, -1, 1)]
- [InlineData (1, -1, 2)]
- [InlineData (-1, -1, 0)]
- [InlineData (11, -1, 12)]
- public void ViewportToScreen_NestedSuperView_WithAdornments (int frameX, int viewportX, int expectedX)
- {
- // We test with only X because Y is equivalent. Height/Width are irrelevant.
- // Arrange
- var frame = new Rectangle (frameX, 0, 10, 10);
- var superSuperView = new View ()
- {
- X = 0,
- Y = 0,
- Height = Dim.Fill (),
- Width = Dim.Fill ()
- };
- superSuperView.BorderStyle = LineStyle.Single;
- var superView = new View ()
- {
- X = 0,
- Y = 0,
- Height = Dim.Fill (),
- Width = Dim.Fill ()
- };
- superSuperView.Add (superView);
- superView.BorderStyle = LineStyle.Single;
- var view = new View ();
- view.Frame = frame;
- superView.Add (view);
- superView.Layout ();
- // Act
- var screen = view.ViewportToScreen (new Point (viewportX, 0));
- // Assert
- Assert.Equal (expectedX, screen.X);
- }
- [Theory]
- [InlineData (0, 0, 2)]
- [InlineData (1, 0, 3)]
- [InlineData (-1, 0, 1)]
- [InlineData (11, 0, 13)]
- [InlineData (0, 1, 3)]
- [InlineData (1, 1, 4)]
- [InlineData (-1, 1, 2)]
- [InlineData (11, 1, 14)]
- [InlineData (0, -1, 1)]
- [InlineData (1, -1, 2)]
- [InlineData (-1, -1, 0)]
- [InlineData (11, -1, 12)]
- public void ViewportToScreen_Positive_NestedSuperView_WithAdornments (int frameX, int testX, int expectedX)
- {
- // We test with only X because Y is equivalent. Height/Width are irrelevant.
- // Arrange
- var frame = new Rectangle (frameX, 0, 10, 10);
- var superSuperView = new View ()
- {
- X = 0,
- Y = 0,
- Height = Dim.Fill (),
- Width = Dim.Fill ()
- };
- superSuperView.BorderStyle = LineStyle.Single;
- var superView = new View ()
- {
- X = 0,
- Y = 0,
- Height = Dim.Fill (),
- Width = Dim.Fill ()
- };
- superSuperView.Add (superView);
- superView.BorderStyle = LineStyle.Single;
- var view = new View ();
- view.Frame = frame;
- view.SetContentSize (new (11, 11));
- view.Viewport = view.Viewport with { Location = new (1, 1) };
- superView.Add (view);
- superView.LayoutSubviews ();
- // Act
- var screen = view.ViewportToScreen (new Point (testX, 0));
- // Assert
- Assert.Equal (expectedX, screen.X);
- }
- [Fact]
- [AutoInitShutdown]
- public void ScreenToView_ViewToScreen_GetViewsUnderMouse_Full_Top ()
- {
- Application.Top = new ();
- Application.Top.BorderStyle = LineStyle.Single;
- var view = new View
- {
- X = 3,
- Y = 2,
- Width = 10,
- Height = 1,
- Text = "0123456789"
- };
- Application.Top.Add (view);
- var rs = Application.Begin (Application.Top);
- Assert.Equal (new (0, 0, 80, 25), new Rectangle (0, 0, View.Driver.Cols, View.Driver.Rows));
- Assert.Equal (new (0, 0, View.Driver.Cols, View.Driver.Rows), Application.Top.Frame);
- Assert.Equal (new (0, 0, 80, 25), Application.Top.Frame);
- ((FakeDriver)Application.Driver!).SetBufferSize (20, 10);
- Assert.Equal (new (0, 0, View.Driver.Cols, View.Driver.Rows), Application.Top.Frame);
- Assert.Equal (new (0, 0, 20, 10), Application.Top.Frame);
- _ = TestHelpers.AssertDriverContentsWithFrameAre (
- @"
- ┌──────────────────┐
- │ │
- │ │
- │ 0123456789 │
- │ │
- │ │
- │ │
- │ │
- │ │
- └──────────────────┘"
- ,
- _output
- );
- // top
- Assert.Equal (Point.Empty, Application.Top.ScreenToFrame (new (0, 0)));
- Point screen = Application.Top.Margin.ViewportToScreen (new Point (0, 0));
- Assert.Equal (0, screen.X);
- Assert.Equal (0, screen.Y);
- screen = Application.Top.Border.ViewportToScreen (new Point (0, 0));
- Assert.Equal (0, screen.X);
- Assert.Equal (0, screen.Y);
- screen = Application.Top.Padding.ViewportToScreen (new Point (0, 0));
- Assert.Equal (1, screen.X);
- Assert.Equal (1, screen.Y);
- screen = Application.Top.ViewportToScreen (new Point (0, 0));
- Assert.Equal (1, screen.X);
- Assert.Equal (1, screen.Y);
- screen = Application.Top.ViewportToScreen (new Point (-1, -1));
- Assert.Equal (0, screen.X);
- Assert.Equal (0, screen.Y);
- var found = View.GetViewsUnderMouse (new Point(0, 0)).LastOrDefault ();
- Assert.Equal (Application.Top.Border, found);
- Assert.Equal (0, found.Frame.X);
- Assert.Equal (0, found.Frame.Y);
- Assert.Equal (new (3, 2), Application.Top.ScreenToFrame (new (3, 2)));
- screen = Application.Top.ViewportToScreen (new Point (3, 2));
- Assert.Equal (4, screen.X);
- Assert.Equal (3, screen.Y);
- found = View.GetViewsUnderMouse (new Point(screen.X, screen.Y)).LastOrDefault ();
- Assert.Equal (view, found);
- //Assert.Equal (0, found.FrameToScreen ().X);
- //Assert.Equal (0, found.FrameToScreen ().Y);
- found = View.GetViewsUnderMouse (new Point(3, 2)).LastOrDefault ();
- Assert.Equal (Application.Top, found);
- //Assert.Equal (3, found.FrameToScreen ().X);
- //Assert.Equal (2, found.FrameToScreen ().Y);
- Assert.Equal (new (13, 2), Application.Top.ScreenToFrame (new (13, 2)));
- screen = Application.Top.ViewportToScreen (new Point (12, 2));
- Assert.Equal (13, screen.X);
- Assert.Equal (3, screen.Y);
- found = View.GetViewsUnderMouse (new Point(screen.X, screen.Y)).LastOrDefault ();
- Assert.Equal (view, found);
- //Assert.Equal (9, found.FrameToScreen ().X);
- //Assert.Equal (0, found.FrameToScreen ().Y);
- screen = Application.Top.ViewportToScreen (new Point (13, 2));
- Assert.Equal (14, screen.X);
- Assert.Equal (3, screen.Y);
- found = View.GetViewsUnderMouse (new Point(13, 2)).LastOrDefault ();
- Assert.Equal (Application.Top, found);
- //Assert.Equal (13, found.FrameToScreen ().X);
- //Assert.Equal (2, found.FrameToScreen ().Y);
- Assert.Equal (new (14, 3), Application.Top.ScreenToFrame (new (14, 3)));
- screen = Application.Top.ViewportToScreen (new Point (14, 3));
- Assert.Equal (15, screen.X);
- Assert.Equal (4, screen.Y);
- found = View.GetViewsUnderMouse (new Point(14, 3)).LastOrDefault ();
- Assert.Equal (Application.Top, found);
- //Assert.Equal (14, found.FrameToScreen ().X);
- //Assert.Equal (3, found.FrameToScreen ().Y);
- // view
- Assert.Equal (new (-4, -3), view.ScreenToFrame (new (0, 0)));
- screen = view.Margin.ViewportToScreen (new Point (-3, -2));
- Assert.Equal (1, screen.X);
- Assert.Equal (1, screen.Y);
- screen = view.Border.ViewportToScreen (new Point (-3, -2));
- Assert.Equal (1, screen.X);
- Assert.Equal (1, screen.Y);
- screen = view.Padding.ViewportToScreen (new Point (-3, -2));
- Assert.Equal (1, screen.X);
- Assert.Equal (1, screen.Y);
- screen = view.ViewportToScreen (new Point (-3, -2));
- Assert.Equal (1, screen.X);
- Assert.Equal (1, screen.Y);
- screen = view.ViewportToScreen (new Point (-4, -3));
- Assert.Equal (0, screen.X);
- Assert.Equal (0, screen.Y);
- found = View.GetViewsUnderMouse (new Point(0, 0)).LastOrDefault ();
- Assert.Equal (Application.Top.Border, found);
- Assert.Equal (new (-1, -1), view.ScreenToFrame (new (3, 2)));
- screen = view.ViewportToScreen (new Point (0, 0));
- Assert.Equal (4, screen.X);
- Assert.Equal (3, screen.Y);
- found = View.GetViewsUnderMouse (new Point(4, 3)).LastOrDefault ();
- Assert.Equal (view, found);
- Assert.Equal (new (9, -1), view.ScreenToFrame (new (13, 2)));
- screen = view.ViewportToScreen (new Point (10, 0));
- Assert.Equal (14, screen.X);
- Assert.Equal (3, screen.Y);
- found = View.GetViewsUnderMouse (new Point(14, 3)).LastOrDefault ();
- Assert.Equal (Application.Top, found);
- Assert.Equal (new (10, 0), view.ScreenToFrame (new (14, 3)));
- screen = view.ViewportToScreen (new Point (11, 1));
- Assert.Equal (15, screen.X);
- Assert.Equal (4, screen.Y);
- found = View.GetViewsUnderMouse (new Point(15, 4)).LastOrDefault ();
- Assert.Equal (Application.Top, found);
- Application.Top.Dispose ();
- Application.ResetState (ignoreDisposed: true);
- }
- [Fact]
- [AutoInitShutdown]
- public void ScreenToView_ViewToScreen_GetViewsUnderMouse_Smaller_Top ()
- {
- Application.Top = new ()
- {
- X = 3,
- Y = 2,
- Width = 20,
- Height = 10,
- BorderStyle = LineStyle.Single
- };
- var view = new View
- {
- X = 3,
- Y = 2,
- Width = 10,
- Height = 1,
- Text = "0123456789"
- };
- Application.Top.Add (view);
- Application.Begin (Application.Top);
- Assert.Equal (new (0, 0, 80, 25), new Rectangle (0, 0, View.Driver.Cols, View.Driver.Rows));
- Assert.NotEqual (new (0, 0, View.Driver.Cols, View.Driver.Rows), Application.Top.Frame);
- Assert.Equal (new (3, 2, 20, 10), Application.Top.Frame);
- ((FakeDriver)Application.Driver!).SetBufferSize (30, 20);
- Assert.Equal (new (0, 0, 30, 20), new Rectangle (0, 0, View.Driver.Cols, View.Driver.Rows));
- Assert.NotEqual (new (0, 0, View.Driver.Cols, View.Driver.Rows), Application.Top.Frame);
- Assert.Equal (new (3, 2, 20, 10), Application.Top.Frame);
- Rectangle frame = TestHelpers.AssertDriverContentsWithFrameAre (
- @"
- ┌──────────────────┐
- │ │
- │ │
- │ 0123456789 │
- │ │
- │ │
- │ │
- │ │
- │ │
- └──────────────────┘"
- ,
- _output
- );
- // mean the output started at col 3 and line 2
- // which result with a width of 23 and a height of 10 on the output
- Assert.Equal (new (3, 2, 23, 10), frame);
- // top
- Assert.Equal (new (-3, -2), Application.Top.ScreenToFrame (new (0, 0)));
- Point screen = Application.Top.Margin.ViewportToScreen (new Point (-3, -2));
- Assert.Equal (0, screen.X);
- Assert.Equal (0, screen.Y);
- screen = Application.Top.Border.ViewportToScreen (new Point (-3, -2));
- Assert.Equal (0, screen.X);
- Assert.Equal (0, screen.Y);
- screen = Application.Top.Padding.ViewportToScreen (new Point (-3, -2));
- Assert.Equal (1, screen.X);
- Assert.Equal (1, screen.Y);
- screen = Application.Top.ViewportToScreen (new Point (-3, -2));
- Assert.Equal (1, screen.X);
- Assert.Equal (1, screen.Y);
- screen = Application.Top.ViewportToScreen (new Point (-4, -3));
- Assert.Equal (0, screen.X);
- Assert.Equal (0, screen.Y);
- var found = View.GetViewsUnderMouse (new Point(-4, -3)).LastOrDefault ();
- Assert.Null (found);
- Assert.Equal (Point.Empty, Application.Top.ScreenToFrame (new (3, 2)));
- screen = Application.Top.ViewportToScreen (new Point (0, 0));
- Assert.Equal (4, screen.X);
- Assert.Equal (3, screen.Y);
- Assert.Equal (Application.Top.Border, View.GetViewsUnderMouse (new Point(3, 2)).LastOrDefault ());
- //Assert.Equal (0, found.FrameToScreen ().X);
- //Assert.Equal (0, found.FrameToScreen ().Y);
- Assert.Equal (new (10, 0), Application.Top.ScreenToFrame (new (13, 2)));
- screen = Application.Top.ViewportToScreen (new Point (10, 0));
- Assert.Equal (14, screen.X);
- Assert.Equal (3, screen.Y);
- Assert.Equal (Application.Top.Border, View.GetViewsUnderMouse (new Point(13, 2)).LastOrDefault ());
- //Assert.Equal (10, found.FrameToScreen ().X);
- //Assert.Equal (0, found.FrameToScreen ().Y);
- Assert.Equal (new (11, 1), Application.Top.ScreenToFrame (new (14, 3)));
- screen = Application.Top.ViewportToScreen (new Point (11, 1));
- Assert.Equal (15, screen.X);
- Assert.Equal (4, screen.Y);
- Assert.Equal (Application.Top, View.GetViewsUnderMouse (new Point(14, 3)).LastOrDefault ());
- // view
- Assert.Equal (new (-7, -5), view.ScreenToFrame (new (0, 0)));
- screen = view.Margin.ViewportToScreen (new Point (-6, -4));
- Assert.Equal (1, screen.X);
- Assert.Equal (1, screen.Y);
- screen = view.Border.ViewportToScreen (new Point (-6, -4));
- Assert.Equal (1, screen.X);
- Assert.Equal (1, screen.Y);
- screen = view.Padding.ViewportToScreen (new Point (-6, -4));
- Assert.Equal (1, screen.X);
- Assert.Equal (1, screen.Y);
- screen = view.ViewportToScreen (new Point (-6, -4));
- Assert.Equal (1, screen.X);
- Assert.Equal (1, screen.Y);
- Assert.Null (View.GetViewsUnderMouse (new Point(1, 1)).LastOrDefault ());
- Assert.Equal (new (-4, -3), view.ScreenToFrame (new (3, 2)));
- screen = view.ViewportToScreen (new Point (-3, -2));
- Assert.Equal (4, screen.X);
- Assert.Equal (3, screen.Y);
- Assert.Equal (Application.Top, View.GetViewsUnderMouse (new Point(4, 3)).LastOrDefault ());
- Assert.Equal (new (-1, -1), view.ScreenToFrame (new (6, 4)));
- screen = view.ViewportToScreen (new Point (0, 0));
- Assert.Equal (7, screen.X);
- Assert.Equal (5, screen.Y);
- Assert.Equal (view, View.GetViewsUnderMouse (new Point(7, 5)).LastOrDefault ());
- Assert.Equal (new (6, -1), view.ScreenToFrame (new (13, 4)));
- screen = view.ViewportToScreen (new Point (7, 0));
- Assert.Equal (14, screen.X);
- Assert.Equal (5, screen.Y);
- Assert.Equal (view, View.GetViewsUnderMouse (new Point(14, 5)).LastOrDefault ());
- Assert.Equal (new (7, -2), view.ScreenToFrame (new (14, 3)));
- screen = view.ViewportToScreen (new Point (8, -1));
- Assert.Equal (15, screen.X);
- Assert.Equal (4, screen.Y);
- Assert.Equal (Application.Top, View.GetViewsUnderMouse (new Point(15, 4)).LastOrDefault ());
- Assert.Equal (new (16, -2), view.ScreenToFrame (new (23, 3)));
- screen = view.ViewportToScreen (new Point (17, -1));
- Assert.Equal (24, screen.X);
- Assert.Equal (4, screen.Y);
- Assert.Null (View.GetViewsUnderMouse (new Point(24, 4)).LastOrDefault ());
- Application.Top.Dispose ();
- }
- }
|