|
@@ -497,325 +497,6 @@ public class PosTests (ITestOutputHelper output)
|
|
|
}
|
|
|
|
|
|
|
|
|
- // TODO: Test Left, Top, Right bottom Equal
|
|
|
-
|
|
|
- /// <summary>Tests Pos.Left, Pos.X, Pos.Top, Pos.Y, Pos.Right, and Pos.Bottom set operations</summary>
|
|
|
- [Fact]
|
|
|
- [TestRespondersDisposed]
|
|
|
- public void PosView_Side_SetsValue ()
|
|
|
- {
|
|
|
- string side; // used in format string
|
|
|
- var testRect = Rectangle.Empty;
|
|
|
- var testInt = 0;
|
|
|
- Pos pos;
|
|
|
-
|
|
|
- // Pos.Left
|
|
|
- side = "left";
|
|
|
- testInt = 0;
|
|
|
- testRect = Rectangle.Empty;
|
|
|
- pos = Pos.Left (new ());
|
|
|
- Assert.Equal ($"View(side={side},target=View(){testRect})", pos.ToString ());
|
|
|
-
|
|
|
- pos = Pos.Left (new() { Frame = testRect });
|
|
|
- Assert.Equal ($"View(side={side},target=View(){testRect})", pos.ToString ());
|
|
|
-
|
|
|
- testRect = new (1, 2, 3, 4);
|
|
|
- pos = Pos.Left (new() { Frame = testRect });
|
|
|
- Assert.Equal ($"View(side={side},target=View(){testRect})", pos.ToString ());
|
|
|
-
|
|
|
- // Pos.Left(win) + 0
|
|
|
- pos = Pos.Left (new() { Frame = testRect }) + testInt;
|
|
|
-
|
|
|
- Assert.Equal (
|
|
|
- $"Combine(View(side={side},target=View(){testRect}){(testInt < 0 ? '-' : '+')}Absolute({testInt}))",
|
|
|
- pos.ToString ()
|
|
|
- );
|
|
|
-
|
|
|
- testInt = 1;
|
|
|
-
|
|
|
- // Pos.Left(win) +1
|
|
|
- pos = Pos.Left (new() { Frame = testRect }) + testInt;
|
|
|
-
|
|
|
- Assert.Equal (
|
|
|
- $"Combine(View(side={side},target=View(){testRect}){(testInt < 0 ? '-' : '+')}Absolute({testInt}))",
|
|
|
- pos.ToString ()
|
|
|
- );
|
|
|
-
|
|
|
- testInt = -1;
|
|
|
-
|
|
|
- // Pos.Left(win) -1
|
|
|
- pos = Pos.Left (new() { Frame = testRect }) - testInt;
|
|
|
-
|
|
|
- Assert.Equal (
|
|
|
- $"Combine(View(side={side},target=View(){testRect}){(testInt < 0 ? '-' : '+')}Absolute({testInt}))",
|
|
|
- pos.ToString ()
|
|
|
- );
|
|
|
-
|
|
|
- // Pos.X
|
|
|
- side = "left";
|
|
|
- testInt = 0;
|
|
|
- testRect = Rectangle.Empty;
|
|
|
- pos = Pos.X (new ());
|
|
|
- Assert.Equal ($"View(side={side},target=View(){testRect})", pos.ToString ());
|
|
|
-
|
|
|
- pos = Pos.X (new() { Frame = testRect });
|
|
|
- Assert.Equal ($"View(side={side},target=View(){testRect})", pos.ToString ());
|
|
|
-
|
|
|
- testRect = new (1, 2, 3, 4);
|
|
|
- pos = Pos.X (new() { Frame = testRect });
|
|
|
- Assert.Equal ($"View(side={side},target=View(){testRect})", pos.ToString ());
|
|
|
-
|
|
|
- // Pos.X(win) + 0
|
|
|
- pos = Pos.X (new() { Frame = testRect }) + testInt;
|
|
|
-
|
|
|
- Assert.Equal (
|
|
|
- $"Combine(View(side={side},target=View(){testRect}){(testInt < 0 ? '-' : '+')}Absolute({testInt}))",
|
|
|
- pos.ToString ()
|
|
|
- );
|
|
|
-
|
|
|
- testInt = 1;
|
|
|
-
|
|
|
- // Pos.X(win) +1
|
|
|
- pos = Pos.X (new() { Frame = testRect }) + testInt;
|
|
|
-
|
|
|
- Assert.Equal (
|
|
|
- $"Combine(View(side={side},target=View(){testRect}){(testInt < 0 ? '-' : '+')}Absolute({testInt}))",
|
|
|
- pos.ToString ()
|
|
|
- );
|
|
|
-
|
|
|
- testInt = -1;
|
|
|
-
|
|
|
- // Pos.X(win) -1
|
|
|
- pos = Pos.X (new() { Frame = testRect }) - testInt;
|
|
|
-
|
|
|
- Assert.Equal (
|
|
|
- $"Combine(View(side={side},target=View(){testRect}){(testInt < 0 ? '-' : '+')}Absolute({testInt}))",
|
|
|
- pos.ToString ()
|
|
|
- );
|
|
|
-
|
|
|
- // Pos.Top
|
|
|
- side = "top";
|
|
|
- testInt = 0;
|
|
|
- testRect = Rectangle.Empty;
|
|
|
- pos = Pos.Top (new ());
|
|
|
- Assert.Equal ($"View(side={side},target=View(){testRect})", pos.ToString ());
|
|
|
-
|
|
|
- pos = Pos.Top (new() { Frame = testRect });
|
|
|
- Assert.Equal ($"View(side={side},target=View(){testRect})", pos.ToString ());
|
|
|
-
|
|
|
- testRect = new (1, 2, 3, 4);
|
|
|
- pos = Pos.Top (new() { Frame = testRect });
|
|
|
- Assert.Equal ($"View(side={side},target=View(){testRect})", pos.ToString ());
|
|
|
-
|
|
|
- // Pos.Top(win) + 0
|
|
|
- pos = Pos.Top (new() { Frame = testRect }) + testInt;
|
|
|
-
|
|
|
- Assert.Equal (
|
|
|
- $"Combine(View(side={side},target=View(){testRect}){(testInt < 0 ? '-' : '+')}Absolute({testInt}))",
|
|
|
- pos.ToString ()
|
|
|
- );
|
|
|
-
|
|
|
- testInt = 1;
|
|
|
-
|
|
|
- // Pos.Top(win) +1
|
|
|
- pos = Pos.Top (new() { Frame = testRect }) + testInt;
|
|
|
-
|
|
|
- Assert.Equal (
|
|
|
- $"Combine(View(side={side},target=View(){testRect}){(testInt < 0 ? '-' : '+')}Absolute({testInt}))",
|
|
|
- pos.ToString ()
|
|
|
- );
|
|
|
-
|
|
|
- testInt = -1;
|
|
|
-
|
|
|
- // Pos.Top(win) -1
|
|
|
- pos = Pos.Top (new() { Frame = testRect }) - testInt;
|
|
|
-
|
|
|
- Assert.Equal (
|
|
|
- $"Combine(View(side={side},target=View(){testRect}){(testInt < 0 ? '-' : '+')}Absolute({testInt}))",
|
|
|
- pos.ToString ()
|
|
|
- );
|
|
|
-
|
|
|
- // Pos.Y
|
|
|
- side = "top";
|
|
|
- testInt = 0;
|
|
|
- testRect = Rectangle.Empty;
|
|
|
- pos = Pos.Y (new ());
|
|
|
- Assert.Equal ($"View(side={side},target=View(){testRect})", pos.ToString ());
|
|
|
-
|
|
|
- pos = Pos.Y (new() { Frame = testRect });
|
|
|
- Assert.Equal ($"View(side={side},target=View(){testRect})", pos.ToString ());
|
|
|
-
|
|
|
- testRect = new (1, 2, 3, 4);
|
|
|
- pos = Pos.Y (new() { Frame = testRect });
|
|
|
- Assert.Equal ($"View(side={side},target=View(){testRect})", pos.ToString ());
|
|
|
-
|
|
|
- // Pos.Y(win) + 0
|
|
|
- pos = Pos.Y (new() { Frame = testRect }) + testInt;
|
|
|
-
|
|
|
- Assert.Equal (
|
|
|
- $"Combine(View(side={side},target=View(){testRect}){(testInt < 0 ? '-' : '+')}Absolute({testInt}))",
|
|
|
- pos.ToString ()
|
|
|
- );
|
|
|
-
|
|
|
- testInt = 1;
|
|
|
-
|
|
|
- // Pos.Y(win) +1
|
|
|
- pos = Pos.Y (new() { Frame = testRect }) + testInt;
|
|
|
-
|
|
|
- Assert.Equal (
|
|
|
- $"Combine(View(side={side},target=View(){testRect}){(testInt < 0 ? '-' : '+')}Absolute({testInt}))",
|
|
|
- pos.ToString ()
|
|
|
- );
|
|
|
-
|
|
|
- testInt = -1;
|
|
|
-
|
|
|
- // Pos.Y(win) -1
|
|
|
- pos = Pos.Y (new() { Frame = testRect }) - testInt;
|
|
|
-
|
|
|
- Assert.Equal (
|
|
|
- $"Combine(View(side={side},target=View(){testRect}){(testInt < 0 ? '-' : '+')}Absolute({testInt}))",
|
|
|
- pos.ToString ()
|
|
|
- );
|
|
|
-
|
|
|
- // Pos.Bottom
|
|
|
- side = "bottom";
|
|
|
- testRect = Rectangle.Empty;
|
|
|
- testInt = 0;
|
|
|
- pos = Pos.Bottom (new ());
|
|
|
- Assert.Equal ($"View(side={side},target=View(){testRect})", pos.ToString ());
|
|
|
-
|
|
|
- pos = Pos.Bottom (new() { Frame = testRect });
|
|
|
- Assert.Equal ($"View(side={side},target=View(){testRect})", pos.ToString ());
|
|
|
-
|
|
|
- testRect = new (1, 2, 3, 4);
|
|
|
- pos = Pos.Bottom (new() { Frame = testRect });
|
|
|
- Assert.Equal ($"View(side={side},target=View(){testRect})", pos.ToString ());
|
|
|
-
|
|
|
- // Pos.Bottom(win) + 0
|
|
|
- pos = Pos.Bottom (new() { Frame = testRect }) + testInt;
|
|
|
-
|
|
|
- Assert.Equal (
|
|
|
- $"Combine(View(side={side},target=View(){testRect}){(testInt < 0 ? '-' : '+')}Absolute({testInt}))",
|
|
|
- pos.ToString ()
|
|
|
- );
|
|
|
-
|
|
|
- testInt = 1;
|
|
|
-
|
|
|
- // Pos.Bottom(win) +1
|
|
|
- pos = Pos.Bottom (new() { Frame = testRect }) + testInt;
|
|
|
-
|
|
|
- Assert.Equal (
|
|
|
- $"Combine(View(side={side},target=View(){testRect}){(testInt < 0 ? '-' : '+')}Absolute({testInt}))",
|
|
|
- pos.ToString ()
|
|
|
- );
|
|
|
-
|
|
|
- testInt = -1;
|
|
|
-
|
|
|
- // Pos.Bottom(win) -1
|
|
|
- pos = Pos.Bottom (new() { Frame = testRect }) - testInt;
|
|
|
-
|
|
|
- Assert.Equal (
|
|
|
- $"Combine(View(side={side},target=View(){testRect}){(testInt < 0 ? '-' : '+')}Absolute({testInt}))",
|
|
|
- pos.ToString ()
|
|
|
- );
|
|
|
-
|
|
|
-#if DEBUG_IDISPOSABLE
|
|
|
-
|
|
|
- // HACK: Force clean up of Responders to avoid having to Dispose all the Views created above.
|
|
|
- Responder.Instances.Clear ();
|
|
|
-#endif
|
|
|
- }
|
|
|
-
|
|
|
- [Fact]
|
|
|
- public void PosView_Side_SetToNull_Throws ()
|
|
|
- {
|
|
|
- Pos pos = Pos.Left (null);
|
|
|
- Assert.Throws<NullReferenceException> (() => pos.ToString ());
|
|
|
-
|
|
|
- pos = Pos.X (null);
|
|
|
- Assert.Throws<NullReferenceException> (() => pos.ToString ());
|
|
|
-
|
|
|
- pos = Pos.Top (null);
|
|
|
- Assert.Throws<NullReferenceException> (() => pos.ToString ());
|
|
|
-
|
|
|
- pos = Pos.Y (null);
|
|
|
- Assert.Throws<NullReferenceException> (() => pos.ToString ());
|
|
|
-
|
|
|
- pos = Pos.Bottom (null);
|
|
|
- Assert.Throws<NullReferenceException> (() => pos.ToString ());
|
|
|
-
|
|
|
- pos = Pos.Right (null);
|
|
|
- Assert.Throws<NullReferenceException> (() => pos.ToString ());
|
|
|
- }
|
|
|
-
|
|
|
- // TODO: This actually a SetRelativeLayout/LayoutSubViews test and should be moved
|
|
|
- // TODO: A new test that calls SetRelativeLayout directly is needed.
|
|
|
- [Fact]
|
|
|
- [TestRespondersDisposed]
|
|
|
- public void Subtract_Operator ()
|
|
|
- {
|
|
|
- Application.Init (new FakeDriver ());
|
|
|
-
|
|
|
- Toplevel top = new Toplevel ();
|
|
|
-
|
|
|
- var view = new View { X = 0, Y = 0, Width = 20, Height = 20 };
|
|
|
- var field = new TextField { X = 0, Y = 0, Width = 20 };
|
|
|
- var count = 20;
|
|
|
- List<View> listViews = new ();
|
|
|
-
|
|
|
- for (var i = 0; i < count; i++)
|
|
|
- {
|
|
|
- field.Text = $"View {i}";
|
|
|
- var view2 = new View { X = 0, Y = field.Y, Width = 20, Text = field.Text };
|
|
|
- view.Add (view2);
|
|
|
- Assert.Equal ($"View {i}", view2.Text);
|
|
|
- Assert.Equal ($"Absolute({i})", field.Y.ToString ());
|
|
|
- listViews.Add (view2);
|
|
|
-
|
|
|
- Assert.Equal ($"Absolute({i})", field.Y.ToString ());
|
|
|
- field.Y += 1;
|
|
|
- Assert.Equal ($"Absolute({i + 1})", field.Y.ToString ());
|
|
|
- }
|
|
|
-
|
|
|
- field.KeyDown += (s, k) =>
|
|
|
- {
|
|
|
- if (k.KeyCode == KeyCode.Enter)
|
|
|
- {
|
|
|
- Assert.Equal ($"View {count - 1}", listViews [count - 1].Text);
|
|
|
- view.Remove (listViews [count - 1]);
|
|
|
- listViews [count - 1].Dispose ();
|
|
|
-
|
|
|
- Assert.Equal ($"Absolute({count})", field.Y.ToString ());
|
|
|
- field.Y -= 1;
|
|
|
- count--;
|
|
|
- Assert.Equal ($"Absolute({count})", field.Y.ToString ());
|
|
|
- }
|
|
|
- };
|
|
|
-
|
|
|
- Application.Iteration += (s, a) =>
|
|
|
- {
|
|
|
- while (count > 0)
|
|
|
- {
|
|
|
- field.NewKeyDownEvent (new Key (KeyCode.Enter));
|
|
|
- }
|
|
|
-
|
|
|
- Application.RequestStop ();
|
|
|
- };
|
|
|
-
|
|
|
- var win = new Window ();
|
|
|
- win.Add (view);
|
|
|
- win.Add (field);
|
|
|
-
|
|
|
- top.Add (win);
|
|
|
-
|
|
|
- Application.Run (top);
|
|
|
- top.Dispose ();
|
|
|
- Assert.Equal (0, count);
|
|
|
-
|
|
|
- // Shutdown must be called to safely clean up Application if Init has been called
|
|
|
- Application.Shutdown ();
|
|
|
- }
|
|
|
-
|
|
|
// TODO: This actually a SetRelativeLayout/LayoutSubViews test and should be moved
|
|
|
// TODO: A new test that calls SetRelativeLayout directly is needed.
|
|
|
[Fact]
|
|
@@ -840,82 +521,4 @@ public class PosTests (ITestOutputHelper output)
|
|
|
t.Dispose ();
|
|
|
Application.Shutdown ();
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
- [Fact]
|
|
|
- [SetupFakeDriver]
|
|
|
- public void PosCombine_DimCombine_View_With_SubViews ()
|
|
|
- {
|
|
|
- var clicked = false;
|
|
|
- Toplevel top = new Toplevel () { Width = 80, Height = 25 };
|
|
|
- var win1 = new Window { Id = "win1", Width = 20, Height = 10 };
|
|
|
- var view1 = new View
|
|
|
- {
|
|
|
- Text = "view1",
|
|
|
- Width = Auto (DimAutoStyle.Text),
|
|
|
- Height = Auto (DimAutoStyle.Text)
|
|
|
-
|
|
|
- };
|
|
|
- var win2 = new Window { Id = "win2", Y = Pos.Bottom (view1) + 1, Width = 10, Height = 3 };
|
|
|
- var view2 = new View { Id = "view2", Width = Dim.Fill (), Height = 1, CanFocus = true };
|
|
|
- view2.MouseClick += (sender, e) => clicked = true;
|
|
|
- var view3 = new View { Id = "view3", Width = Dim.Fill (1), Height = 1, CanFocus = true };
|
|
|
-
|
|
|
- view2.Add (view3);
|
|
|
- win2.Add (view2);
|
|
|
- win1.Add (view1, win2);
|
|
|
- top.Add (win1);
|
|
|
- top.BeginInit ();
|
|
|
- top.EndInit ();
|
|
|
-
|
|
|
- Assert.Equal (new Rectangle (0, 0, 80, 25), top.Frame);
|
|
|
- Assert.Equal (new Rectangle (0, 0, 5, 1), view1.Frame);
|
|
|
- Assert.Equal (new Rectangle (0, 0, 20, 10), win1.Frame);
|
|
|
- Assert.Equal (new Rectangle (0, 2, 10, 3), win2.Frame);
|
|
|
- Assert.Equal (new Rectangle (0, 0, 8, 1), view2.Frame);
|
|
|
- Assert.Equal (new Rectangle (0, 0, 7, 1), view3.Frame);
|
|
|
- var foundView = View.FindDeepestView (top, new (9, 4));
|
|
|
- Assert.Equal (foundView, view2);
|
|
|
- }
|
|
|
-
|
|
|
- [Fact]
|
|
|
- public void PosCombine_Refs_SuperView_Throws ()
|
|
|
- {
|
|
|
- Application.Init (new FakeDriver ());
|
|
|
-
|
|
|
- var top = new Toplevel ();
|
|
|
- var w = new Window { X = Pos.Left (top) + 2, Y = Pos.Top (top) + 2 };
|
|
|
- var f = new FrameView ();
|
|
|
- var v1 = new View { X = Pos.Left (w) + 2, Y = Pos.Top (w) + 2 };
|
|
|
- var v2 = new View { X = Pos.Left (v1) + 2, Y = Pos.Top (v1) + 2 };
|
|
|
-
|
|
|
- f.Add (v1, v2);
|
|
|
- w.Add (f);
|
|
|
- top.Add (w);
|
|
|
- Application.Begin (top);
|
|
|
-
|
|
|
- f.X = Pos.X (Application.Top) + Pos.X (v2) - Pos.X (v1);
|
|
|
- f.Y = Pos.Y (Application.Top) + Pos.Y (v2) - Pos.Y (v1);
|
|
|
-
|
|
|
- Application.Top.LayoutComplete += (s, e) =>
|
|
|
- {
|
|
|
- Assert.Equal (0, Application.Top.Frame.X);
|
|
|
- Assert.Equal (0, Application.Top.Frame.Y);
|
|
|
- Assert.Equal (2, w.Frame.X);
|
|
|
- Assert.Equal (2, w.Frame.Y);
|
|
|
- Assert.Equal (2, f.Frame.X);
|
|
|
- Assert.Equal (2, f.Frame.Y);
|
|
|
- Assert.Equal (4, v1.Frame.X);
|
|
|
- Assert.Equal (4, v1.Frame.Y);
|
|
|
- Assert.Equal (6, v2.Frame.X);
|
|
|
- Assert.Equal (6, v2.Frame.Y);
|
|
|
- };
|
|
|
-
|
|
|
- Application.Iteration += (s, a) => Application.RequestStop ();
|
|
|
-
|
|
|
- Assert.Throws<InvalidOperationException> (() => Application.Run ());
|
|
|
- top.Dispose ();
|
|
|
- Application.Shutdown ();
|
|
|
- }
|
|
|
-
|
|
|
}
|