mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2026-01-01 16:59:35 +01:00
Code cleanup on just touched files
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
using Xunit;
|
||||
using Xunit.Abstractions;
|
||||
using Xunit.Abstractions;
|
||||
|
||||
//using GraphViewTests = Terminal.Gui.Views.GraphViewTests;
|
||||
|
||||
@@ -7,383 +6,392 @@ using Xunit.Abstractions;
|
||||
|
||||
namespace Terminal.Gui.ViewTests;
|
||||
|
||||
public class AbsoluteLayoutTests {
|
||||
readonly ITestOutputHelper _output;
|
||||
public class AbsoluteLayoutTests
|
||||
{
|
||||
private readonly ITestOutputHelper _output;
|
||||
|
||||
public AbsoluteLayoutTests (ITestOutputHelper output) => _output = output;
|
||||
public AbsoluteLayoutTests (ITestOutputHelper output) { _output = output; }
|
||||
|
||||
[Fact]
|
||||
[TestRespondersDisposed]
|
||||
public void AbsoluteLayout_Constructor ()
|
||||
{
|
||||
var v = new View ();
|
||||
Assert.True (v.LayoutStyle == LayoutStyle.Absolute);
|
||||
v.Dispose ();
|
||||
[Fact]
|
||||
[TestRespondersDisposed]
|
||||
public void AbsoluteLayout_Change_Frame ()
|
||||
{
|
||||
var frame = new Rect (1, 2, 3, 4);
|
||||
var newFrame = new Rect (1, 2, 30, 40);
|
||||
|
||||
var frame = Rect.Empty;
|
||||
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.Equal (Pos.At (0), v.X);
|
||||
Assert.Equal (Pos.At (0), v.Y);
|
||||
Assert.Equal (Dim.Sized (0), v.Width);
|
||||
Assert.Equal (Dim.Sized (0), v.Height);
|
||||
v.Dispose ();
|
||||
var v = new View ();
|
||||
Assert.True (v.LayoutStyle == LayoutStyle.Absolute);
|
||||
v.Dispose ();
|
||||
|
||||
frame = new Rect (1, 2, 3, 4);
|
||||
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.Equal (Pos.At (1), v.X);
|
||||
Assert.Equal (Pos.At (2), v.Y);
|
||||
Assert.Equal (Dim.Sized (3), v.Width);
|
||||
Assert.Equal (Dim.Sized (4), v.Height);
|
||||
v.Dispose ();
|
||||
v = new View (frame);
|
||||
Assert.True (v.LayoutStyle == LayoutStyle.Absolute);
|
||||
|
||||
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.Equal (Pos.At (1), v.X);
|
||||
Assert.Equal (Pos.At (2), v.Y);
|
||||
Assert.Equal (Dim.Sized (3), v.Width);
|
||||
Assert.Equal (Dim.Sized (4), v.Height);
|
||||
v.Dispose ();
|
||||
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.Equal (Pos.At (1), v.X);
|
||||
Assert.Equal (Pos.At (2), v.Y);
|
||||
Assert.Equal (Dim.Sized (30), v.Width);
|
||||
Assert.Equal (Dim.Sized (40), v.Height);
|
||||
v.Dispose ();
|
||||
|
||||
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 not 1,1
|
||||
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.Equal (Pos.At (1), v.X);
|
||||
Assert.Equal (Pos.At (2), v.Y);
|
||||
Assert.Equal (Dim.Sized (1), v.Width);
|
||||
Assert.Equal (Dim.Sized (1), v.Height);
|
||||
v.Dispose ();
|
||||
v = new View (frame.X, frame.Y, "v");
|
||||
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.Equal (Pos.At (1), v.X);
|
||||
Assert.Equal (Pos.At (2), v.Y);
|
||||
Assert.Equal (Dim.Sized (30), v.Width);
|
||||
Assert.Equal (Dim.Sized (40), v.Height);
|
||||
v.Dispose ();
|
||||
|
||||
v = new View ();
|
||||
Assert.True (v.LayoutStyle == LayoutStyle.Absolute);
|
||||
Assert.Equal (new Rect (0, 0, 0, 0), v.Frame);
|
||||
Assert.Equal (new Rect (0, 0, 0, 0), v.Bounds); // With Absolute Bounds *is* deterministic before Layout
|
||||
Assert.Equal (Pos.At (0), v.X);
|
||||
Assert.Equal (Pos.At (0), v.Y);
|
||||
Assert.Equal (Dim.Sized (0), v.Width);
|
||||
Assert.Equal (Dim.Sized (0), v.Height);
|
||||
v.Dispose ();
|
||||
newFrame = new Rect (10, 20, 30, 40);
|
||||
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.Equal (Pos.At (10), v.X);
|
||||
Assert.Equal (Pos.At (20), v.Y);
|
||||
Assert.Equal (Dim.Sized (30), v.Width);
|
||||
Assert.Equal (Dim.Sized (40), v.Height);
|
||||
v.Dispose ();
|
||||
|
||||
v = new View {
|
||||
X = frame.X,
|
||||
Y = frame.Y,
|
||||
Width = frame.Width,
|
||||
Height = frame.Height
|
||||
};
|
||||
Assert.True (v.LayoutStyle == LayoutStyle.Absolute);
|
||||
Assert.Equal (new Rect (frame.X, frame.Y, 3, 4), v.Frame);
|
||||
Assert.Equal (new Rect (0, 0, 3, 4), v.Bounds); // With Absolute Bounds *is* deterministic before Layout
|
||||
Assert.Equal (Pos.At (1), v.X);
|
||||
Assert.Equal (Pos.At (2), v.Y);
|
||||
Assert.Equal (Dim.Sized (3), v.Width);
|
||||
Assert.Equal (Dim.Sized (4), v.Height);
|
||||
v.Dispose ();
|
||||
}
|
||||
v = new View (frame.X, frame.Y, "v");
|
||||
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.Equal (Pos.At (10), v.X);
|
||||
Assert.Equal (Pos.At (20), v.Y);
|
||||
Assert.Equal (Dim.Sized (30), v.Width);
|
||||
Assert.Equal (Dim.Sized (40), v.Height);
|
||||
v.Dispose ();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[TestRespondersDisposed]
|
||||
public void AbsoluteLayout_Change_Frame ()
|
||||
{
|
||||
var frame = new Rect (1, 2, 3, 4);
|
||||
var newFrame = new Rect (1, 2, 30, 40);
|
||||
[Fact]
|
||||
[TestRespondersDisposed]
|
||||
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 ();
|
||||
Assert.True (v.LayoutStyle == LayoutStyle.Absolute);
|
||||
v.Dispose ();
|
||||
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.Equal (Pos.At (1), v.X);
|
||||
Assert.Equal (Pos.At (2), v.Y);
|
||||
Assert.Equal ($"Absolute({newFrame.Height})", v.Height.ToString ());
|
||||
Assert.Equal ($"Absolute({newFrame.Width})", v.Width.ToString ());
|
||||
v.Dispose ();
|
||||
}
|
||||
|
||||
v = new View (frame);
|
||||
Assert.True (v.LayoutStyle == LayoutStyle.Absolute);
|
||||
[Fact]
|
||||
[TestRespondersDisposed]
|
||||
public void AbsoluteLayout_Change_Height_or_Width_MakesComputed ()
|
||||
{
|
||||
var v = new View (Rect.Empty);
|
||||
v.Height = Dim.Fill ();
|
||||
v.Width = Dim.Fill ();
|
||||
Assert.True (v.LayoutStyle == LayoutStyle.Computed);
|
||||
v.Dispose ();
|
||||
}
|
||||
|
||||
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.Equal (Pos.At (1), v.X);
|
||||
Assert.Equal (Pos.At (2), v.Y);
|
||||
Assert.Equal (Dim.Sized (30), v.Width);
|
||||
Assert.Equal (Dim.Sized (40), v.Height);
|
||||
v.Dispose ();
|
||||
[Fact]
|
||||
[TestRespondersDisposed]
|
||||
public void AbsoluteLayout_Change_X_or_Y_Absolute ()
|
||||
{
|
||||
var frame = new Rect (1, 2, 3, 4);
|
||||
var newFrame = new Rect (10, 20, 3, 4);
|
||||
|
||||
v = new View (frame.X, frame.Y, "v");
|
||||
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.Equal (Pos.At (1), v.X);
|
||||
Assert.Equal (Pos.At (2), v.Y);
|
||||
Assert.Equal (Dim.Sized (30), v.Width);
|
||||
Assert.Equal (Dim.Sized (40), v.Height);
|
||||
v.Dispose ();
|
||||
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.Equal (Dim.Sized (3), v.Width);
|
||||
Assert.Equal (Dim.Sized (4), v.Height);
|
||||
v.Dispose ();
|
||||
}
|
||||
|
||||
newFrame = new Rect (10, 20, 30, 40);
|
||||
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.Equal (Pos.At (10), v.X);
|
||||
Assert.Equal (Pos.At (20), v.Y);
|
||||
Assert.Equal (Dim.Sized (30), v.Width);
|
||||
Assert.Equal (Dim.Sized (40), v.Height);
|
||||
v.Dispose ();
|
||||
[Fact]
|
||||
[TestRespondersDisposed]
|
||||
public void AbsoluteLayout_Change_X_or_Y_MakesComputed ()
|
||||
{
|
||||
var v = new View (Rect.Empty);
|
||||
v.X = Pos.Center ();
|
||||
v.Y = Pos.Center ();
|
||||
Assert.True (v.LayoutStyle == LayoutStyle.Computed);
|
||||
v.Dispose ();
|
||||
}
|
||||
|
||||
v = new View (frame.X, frame.Y, "v");
|
||||
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.Equal (Pos.At (10), v.X);
|
||||
Assert.Equal (Pos.At (20), v.Y);
|
||||
Assert.Equal (Dim.Sized (30), v.Width);
|
||||
Assert.Equal (Dim.Sized (40), v.Height);
|
||||
v.Dispose ();
|
||||
}
|
||||
[Fact]
|
||||
[TestRespondersDisposed]
|
||||
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.Dispose ();
|
||||
|
||||
[Fact]
|
||||
[TestRespondersDisposed]
|
||||
public void AbsoluteLayout_Change_Height_or_Width_Absolute ()
|
||||
{
|
||||
var frame = new Rect (1, 2, 3, 4);
|
||||
var newFrame = new Rect (1, 2, 30, 40);
|
||||
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.Computed);
|
||||
v.Dispose ();
|
||||
|
||||
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.Equal (Pos.At (1), v.X);
|
||||
Assert.Equal (Pos.At (2), v.Y);
|
||||
Assert.Equal ($"Absolute({newFrame.Height})", v.Height.ToString ());
|
||||
Assert.Equal ($"Absolute({newFrame.Width})", v.Width.ToString ());
|
||||
v.Dispose ();
|
||||
}
|
||||
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.Computed);
|
||||
|
||||
[Fact]
|
||||
[TestRespondersDisposed]
|
||||
public void AbsoluteLayout_Change_Height_or_Width_MakesComputed ()
|
||||
{
|
||||
var v = new View (Rect.Empty);
|
||||
v.Height = Dim.Fill ();
|
||||
v.Width = Dim.Fill ();
|
||||
Assert.True (v.LayoutStyle == LayoutStyle.Computed);
|
||||
v.Dispose ();
|
||||
}
|
||||
v.X = 1;
|
||||
Assert.True (v.LayoutStyle == LayoutStyle.Computed);
|
||||
v.Dispose ();
|
||||
|
||||
[Fact]
|
||||
[TestRespondersDisposed]
|
||||
public void AbsoluteLayout_Change_X_or_Y_Absolute ()
|
||||
{
|
||||
var frame = new Rect (1, 2, 3, 4);
|
||||
var newFrame = new Rect (10, 20, 3, 4);
|
||||
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.Computed);
|
||||
|
||||
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.Equal (Dim.Sized (3), v.Width);
|
||||
Assert.Equal (Dim.Sized (4), v.Height);
|
||||
v.Dispose ();
|
||||
}
|
||||
v.Y = 2;
|
||||
Assert.True (v.LayoutStyle == LayoutStyle.Computed);
|
||||
v.Dispose ();
|
||||
|
||||
[Fact]
|
||||
[TestRespondersDisposed]
|
||||
public void AbsoluteLayout_Change_X_or_Y_MakesComputed ()
|
||||
{
|
||||
var v = new View (Rect.Empty);
|
||||
v.X = Pos.Center ();
|
||||
v.Y = Pos.Center ();
|
||||
Assert.True (v.LayoutStyle == LayoutStyle.Computed);
|
||||
v.Dispose ();
|
||||
}
|
||||
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.Computed);
|
||||
|
||||
[Fact]
|
||||
[TestRespondersDisposed]
|
||||
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.Dispose ();
|
||||
v.Width = 3;
|
||||
Assert.True (v.LayoutStyle == LayoutStyle.Computed);
|
||||
v.Dispose ();
|
||||
|
||||
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.Computed);
|
||||
v.Dispose ();
|
||||
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.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.Computed);
|
||||
v.Height = 3;
|
||||
Assert.True (v.LayoutStyle == LayoutStyle.Computed);
|
||||
v.Dispose ();
|
||||
|
||||
v.X = 1;
|
||||
Assert.True (v.LayoutStyle == LayoutStyle.Computed);
|
||||
v.Dispose ();
|
||||
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.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.Computed);
|
||||
v.X = 1;
|
||||
v.Y = 2;
|
||||
v.Height = 3;
|
||||
v.Width = 4;
|
||||
Assert.True (v.LayoutStyle == LayoutStyle.Absolute);
|
||||
v.Dispose ();
|
||||
}
|
||||
|
||||
v.Y = 2;
|
||||
Assert.True (v.LayoutStyle == LayoutStyle.Computed);
|
||||
v.Dispose ();
|
||||
[Fact]
|
||||
[TestRespondersDisposed]
|
||||
public void AbsoluteLayout_Constructor ()
|
||||
{
|
||||
var v = new View ();
|
||||
Assert.True (v.LayoutStyle == LayoutStyle.Absolute);
|
||||
v.Dispose ();
|
||||
|
||||
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.Computed);
|
||||
var frame = Rect.Empty;
|
||||
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.Equal (Pos.At (0), v.X);
|
||||
Assert.Equal (Pos.At (0), v.Y);
|
||||
Assert.Equal (Dim.Sized (0), v.Width);
|
||||
Assert.Equal (Dim.Sized (0), v.Height);
|
||||
v.Dispose ();
|
||||
|
||||
v.Width = 3;
|
||||
Assert.True (v.LayoutStyle == LayoutStyle.Computed);
|
||||
v.Dispose ();
|
||||
frame = new Rect (1, 2, 3, 4);
|
||||
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.Equal (Pos.At (1), v.X);
|
||||
Assert.Equal (Pos.At (2), v.Y);
|
||||
Assert.Equal (Dim.Sized (3), v.Width);
|
||||
Assert.Equal (Dim.Sized (4), v.Height);
|
||||
v.Dispose ();
|
||||
|
||||
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.Computed);
|
||||
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.Equal (Pos.At (1), v.X);
|
||||
Assert.Equal (Pos.At (2), v.Y);
|
||||
Assert.Equal (Dim.Sized (3), v.Width);
|
||||
Assert.Equal (Dim.Sized (4), v.Height);
|
||||
v.Dispose ();
|
||||
|
||||
v.Height = 3;
|
||||
Assert.True (v.LayoutStyle == LayoutStyle.Computed);
|
||||
v.Dispose ();
|
||||
v = new View (frame.X, frame.Y, "v");
|
||||
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.Computed);
|
||||
// BUGBUG: v2 - I think the default size should be 0,0 not 1,1
|
||||
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.Equal (Pos.At (1), v.X);
|
||||
Assert.Equal (Pos.At (2), v.Y);
|
||||
Assert.Equal (Dim.Sized (1), v.Width);
|
||||
Assert.Equal (Dim.Sized (1), v.Height);
|
||||
v.Dispose ();
|
||||
|
||||
v.X = 1;
|
||||
v.Y = 2;
|
||||
v.Height = 3;
|
||||
v.Width = 4;
|
||||
Assert.True (v.LayoutStyle == LayoutStyle.Absolute);
|
||||
v.Dispose ();
|
||||
}
|
||||
v = new View ();
|
||||
Assert.True (v.LayoutStyle == LayoutStyle.Absolute);
|
||||
Assert.Equal (new Rect (0, 0, 0, 0), v.Frame);
|
||||
Assert.Equal (new Rect (0, 0, 0, 0), v.Bounds); // With Absolute Bounds *is* deterministic before Layout
|
||||
Assert.Equal (Pos.At (0), v.X);
|
||||
Assert.Equal (Pos.At (0), v.Y);
|
||||
Assert.Equal (Dim.Sized (0), v.Width);
|
||||
Assert.Equal (Dim.Sized (0), v.Height);
|
||||
v.Dispose ();
|
||||
|
||||
[Fact]
|
||||
[TestRespondersDisposed]
|
||||
public void AbsoluteLayout_LayoutSubviews ()
|
||||
{
|
||||
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
|
||||
};
|
||||
Assert.True (v1.LayoutStyle == LayoutStyle.Absolute);
|
||||
v = new View
|
||||
{
|
||||
X = frame.X,
|
||||
Y = frame.Y,
|
||||
Width = frame.Width,
|
||||
Height = frame.Height
|
||||
};
|
||||
Assert.True (v.LayoutStyle == LayoutStyle.Absolute);
|
||||
Assert.Equal (new Rect (frame.X, frame.Y, 3, 4), v.Frame);
|
||||
Assert.Equal (new Rect (0, 0, 3, 4), v.Bounds); // With Absolute Bounds *is* deterministic before Layout
|
||||
Assert.Equal (Pos.At (1), v.X);
|
||||
Assert.Equal (Pos.At (2), v.Y);
|
||||
Assert.Equal (Dim.Sized (3), v.Width);
|
||||
Assert.Equal (Dim.Sized (4), v.Height);
|
||||
v.Dispose ();
|
||||
}
|
||||
|
||||
var v2 = new View {
|
||||
X = 10,
|
||||
Y = 10,
|
||||
Width = 10,
|
||||
Height = 10
|
||||
};
|
||||
Assert.True (v2.LayoutStyle == LayoutStyle.Absolute);
|
||||
[Fact]
|
||||
[TestRespondersDisposed]
|
||||
public void AbsoluteLayout_LayoutSubviews ()
|
||||
{
|
||||
var superRect = new Rect (0, 0, 100, 100);
|
||||
var super = new View (superRect, "super");
|
||||
Assert.True (super.LayoutStyle == LayoutStyle.Absolute);
|
||||
|
||||
super.Add (v1, v2);
|
||||
Assert.True (v1.LayoutStyle == LayoutStyle.Absolute);
|
||||
Assert.True (v2.LayoutStyle == LayoutStyle.Absolute);
|
||||
var v1 = new View
|
||||
{
|
||||
X = 0,
|
||||
Y = 0,
|
||||
Width = 10,
|
||||
Height = 10
|
||||
};
|
||||
Assert.True (v1.LayoutStyle == LayoutStyle.Absolute);
|
||||
|
||||
super.LayoutSubviews ();
|
||||
Assert.Equal (new Rect (0, 0, 10, 10), v1.Frame);
|
||||
Assert.Equal (new Rect (10, 10, 10, 10), v2.Frame);
|
||||
super.Dispose ();
|
||||
}
|
||||
var v2 = new View
|
||||
{
|
||||
X = 10,
|
||||
Y = 10,
|
||||
Width = 10,
|
||||
Height = 10
|
||||
};
|
||||
Assert.True (v2.LayoutStyle == LayoutStyle.Absolute);
|
||||
|
||||
[Fact]
|
||||
public void AbsoluteLayout_Setting_Bounds_Location_NotEmpty ()
|
||||
{
|
||||
// TODO: Should we enforce Bounds.X/Y == 0? The code currently ignores value.X/Y which is
|
||||
// TODO: correct behavior, but is silent. Perhaps an exception?
|
||||
var frame = new Rect (1, 2, 3, 4);
|
||||
var newBounds = new Rect (10, 20, 30, 40);
|
||||
var view = new View (frame);
|
||||
view.Bounds = newBounds;
|
||||
Assert.Equal (new Rect (0, 0, 30, 40), view.Bounds);
|
||||
Assert.Equal (new Rect (1, 2, 30, 40), view.Frame);
|
||||
}
|
||||
super.Add (v1, v2);
|
||||
Assert.True (v1.LayoutStyle == LayoutStyle.Absolute);
|
||||
Assert.True (v2.LayoutStyle == LayoutStyle.Absolute);
|
||||
|
||||
[Fact]
|
||||
public void AbsoluteLayout_Setting_Bounds_Sets_Frame ()
|
||||
{
|
||||
var frame = new Rect (1, 2, 3, 4);
|
||||
var newBounds = new Rect (0, 0, 30, 40);
|
||||
super.LayoutSubviews ();
|
||||
Assert.Equal (new Rect (0, 0, 10, 10), v1.Frame);
|
||||
Assert.Equal (new Rect (10, 10, 10, 10), v2.Frame);
|
||||
super.Dispose ();
|
||||
}
|
||||
|
||||
var v = new View (frame);
|
||||
Assert.True (v.LayoutStyle == LayoutStyle.Absolute);
|
||||
[Fact]
|
||||
public void AbsoluteLayout_Setting_Bounds_Location_NotEmpty ()
|
||||
{
|
||||
// TODO: Should we enforce Bounds.X/Y == 0? The code currently ignores value.X/Y which is
|
||||
// TODO: correct behavior, but is silent. Perhaps an exception?
|
||||
var frame = new Rect (1, 2, 3, 4);
|
||||
var newBounds = new Rect (10, 20, 30, 40);
|
||||
var view = new View (frame);
|
||||
view.Bounds = newBounds;
|
||||
Assert.Equal (new Rect (0, 0, 30, 40), view.Bounds);
|
||||
Assert.Equal (new Rect (1, 2, 30, 40), view.Frame);
|
||||
}
|
||||
|
||||
v.Bounds = newBounds;
|
||||
Assert.True (v.LayoutStyle == LayoutStyle.Absolute);
|
||||
Assert.Equal (newBounds, v.Bounds);
|
||||
Assert.Equal (new Rect (1, 2, newBounds.Width, newBounds.Height), v.Frame);
|
||||
Assert.Equal (new Rect (0, 0, newBounds.Width, newBounds.Height), v.Bounds);
|
||||
Assert.Equal (Pos.At (1), v.X);
|
||||
Assert.Equal (Pos.At (2), v.Y);
|
||||
Assert.Equal (Dim.Sized (30), v.Width);
|
||||
Assert.Equal (Dim.Sized (40), v.Height);
|
||||
[Fact]
|
||||
public void AbsoluteLayout_Setting_Bounds_Sets_Frame ()
|
||||
{
|
||||
var frame = new Rect (1, 2, 3, 4);
|
||||
var newBounds = new Rect (0, 0, 30, 40);
|
||||
|
||||
newBounds = new Rect (0, 0, 3, 4);
|
||||
v.Bounds = newBounds;
|
||||
Assert.Equal (newBounds, v.Bounds);
|
||||
Assert.Equal (new Rect (1, 2, newBounds.Width, newBounds.Height), v.Frame);
|
||||
Assert.Equal (new Rect (0, 0, newBounds.Width, newBounds.Height), v.Bounds);
|
||||
Assert.Equal (Pos.At (1), v.X);
|
||||
Assert.Equal (Pos.At (2), v.Y);
|
||||
Assert.Equal (Dim.Sized (3), v.Width);
|
||||
Assert.Equal (Dim.Sized (4), v.Height);
|
||||
var v = new View (frame);
|
||||
Assert.True (v.LayoutStyle == LayoutStyle.Absolute);
|
||||
|
||||
v.BorderStyle = LineStyle.Single;
|
||||
// Bounds should shrink
|
||||
Assert.Equal (new Rect (0, 0, 1, 2), v.Bounds);
|
||||
// Frame should not change
|
||||
Assert.Equal (new Rect (1, 2, 3, 4), v.Frame);
|
||||
Assert.Equal (Pos.At (1), v.X);
|
||||
Assert.Equal (Pos.At (2), v.Y);
|
||||
Assert.Equal (Dim.Sized (3), v.Width);
|
||||
Assert.Equal (Dim.Sized (4), v.Height);
|
||||
v.Bounds = newBounds;
|
||||
Assert.True (v.LayoutStyle == LayoutStyle.Absolute);
|
||||
Assert.Equal (newBounds, v.Bounds);
|
||||
Assert.Equal (new Rect (1, 2, newBounds.Width, newBounds.Height), v.Frame);
|
||||
Assert.Equal (new Rect (0, 0, newBounds.Width, newBounds.Height), v.Bounds);
|
||||
Assert.Equal (Pos.At (1), v.X);
|
||||
Assert.Equal (Pos.At (2), v.Y);
|
||||
Assert.Equal (Dim.Sized (30), v.Width);
|
||||
Assert.Equal (Dim.Sized (40), v.Height);
|
||||
|
||||
// Now set bounds bigger as before
|
||||
newBounds = new Rect (0, 0, 3, 4);
|
||||
v.Bounds = newBounds;
|
||||
Assert.Equal (newBounds, v.Bounds);
|
||||
// Frame grows because there's now a border
|
||||
Assert.Equal (new Rect (1, 2, 5, 6), v.Frame);
|
||||
Assert.Equal (new Rect (0, 0, newBounds.Width, newBounds.Height), v.Bounds);
|
||||
Assert.Equal (Pos.At (1), v.X);
|
||||
Assert.Equal (Pos.At (2), v.Y);
|
||||
Assert.Equal (Dim.Sized (5), v.Width);
|
||||
Assert.Equal (Dim.Sized (6), v.Height);
|
||||
}
|
||||
}
|
||||
newBounds = new Rect (0, 0, 3, 4);
|
||||
v.Bounds = newBounds;
|
||||
Assert.Equal (newBounds, v.Bounds);
|
||||
Assert.Equal (new Rect (1, 2, newBounds.Width, newBounds.Height), v.Frame);
|
||||
Assert.Equal (new Rect (0, 0, newBounds.Width, newBounds.Height), v.Bounds);
|
||||
Assert.Equal (Pos.At (1), v.X);
|
||||
Assert.Equal (Pos.At (2), v.Y);
|
||||
Assert.Equal (Dim.Sized (3), v.Width);
|
||||
Assert.Equal (Dim.Sized (4), v.Height);
|
||||
|
||||
v.BorderStyle = LineStyle.Single;
|
||||
|
||||
// Bounds should shrink
|
||||
Assert.Equal (new Rect (0, 0, 1, 2), v.Bounds);
|
||||
|
||||
// Frame should not change
|
||||
Assert.Equal (new Rect (1, 2, 3, 4), v.Frame);
|
||||
Assert.Equal (Pos.At (1), v.X);
|
||||
Assert.Equal (Pos.At (2), v.Y);
|
||||
Assert.Equal (Dim.Sized (3), v.Width);
|
||||
Assert.Equal (Dim.Sized (4), v.Height);
|
||||
|
||||
// Now set bounds bigger as before
|
||||
newBounds = new Rect (0, 0, 3, 4);
|
||||
v.Bounds = newBounds;
|
||||
Assert.Equal (newBounds, v.Bounds);
|
||||
|
||||
// Frame grows because there's now a border
|
||||
Assert.Equal (new Rect (1, 2, 5, 6), v.Frame);
|
||||
Assert.Equal (new Rect (0, 0, newBounds.Width, newBounds.Height), v.Bounds);
|
||||
Assert.Equal (Pos.At (1), v.X);
|
||||
Assert.Equal (Pos.At (2), v.Y);
|
||||
Assert.Equal (Dim.Sized (5), v.Width);
|
||||
Assert.Equal (Dim.Sized (6), v.Height);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Threading;
|
||||
using Xunit;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
using Xunit.Abstractions;
|
||||
|
||||
// Alias Console to MockConsole so we don't accidentally use Console
|
||||
@@ -9,458 +7,473 @@ using Console = Terminal.Gui.FakeConsole;
|
||||
|
||||
namespace Terminal.Gui.ViewTests;
|
||||
|
||||
public class DimAutoTests {
|
||||
readonly ITestOutputHelper _output;
|
||||
|
||||
public DimAutoTests (ITestOutputHelper output)
|
||||
{
|
||||
_output = output;
|
||||
Console.OutputEncoding = System.Text.Encoding.Default;
|
||||
// Change current culture
|
||||
var culture = CultureInfo.CreateSpecificCulture ("en-US");
|
||||
Thread.CurrentThread.CurrentCulture = culture;
|
||||
Thread.CurrentThread.CurrentUICulture = culture;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void NoSubViews_Does_Nothing ()
|
||||
{
|
||||
var superView = new View () {
|
||||
X = 0,
|
||||
Y = 0,
|
||||
Width = Dim.Auto (),
|
||||
Height = Dim.Auto (),
|
||||
ValidatePosDim = true,
|
||||
};
|
||||
|
||||
superView.BeginInit ();
|
||||
superView.EndInit ();
|
||||
superView.SetRelativeLayout (new Rect (0, 0, 0, 0));
|
||||
Assert.Equal (new Rect (0, 0, 0, 0), superView.Frame);
|
||||
|
||||
superView.SetRelativeLayout (new Rect (0, 0, 10, 10));
|
||||
Assert.Equal (new Rect (0, 0, 0, 0), superView.Frame);
|
||||
|
||||
superView.SetRelativeLayout (new Rect (10, 10, 10, 10));
|
||||
Assert.Equal (new Rect (0, 0, 0, 0), superView.Frame);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData (0, 0, 0, 0, 0, 0)]
|
||||
[InlineData (0, 0, 5, 0, 5, 0)]
|
||||
[InlineData (0, 0, 0, 5, 0, 5)]
|
||||
[InlineData (0, 0, 5, 5, 5, 5)]
|
||||
|
||||
[InlineData (1, 0, 5, 0, 6, 0)]
|
||||
[InlineData (1, 0, 0, 5, 1, 5)]
|
||||
[InlineData (1, 0, 5, 5, 6, 5)]
|
||||
[InlineData (1, 1, 5, 5, 6, 6)]
|
||||
|
||||
[InlineData (-1, 0, 5, 0, 4, 0)]
|
||||
[InlineData (-1, 0, 0, 5, 0, 5)]
|
||||
[InlineData (-1, 0, 5, 5, 4, 5)]
|
||||
[InlineData (-1, -1, 5, 5, 4, 4)]
|
||||
public void SubView_ChangesSuperViewSize (int subX, int subY, int subWidth, int subHeight, int expectedWidth, int expectedHeight)
|
||||
{
|
||||
var superView = new View () {
|
||||
X = 0,
|
||||
Y = 0,
|
||||
Width = Dim.Auto (),
|
||||
Height = Dim.Auto (),
|
||||
ValidatePosDim = true,
|
||||
};
|
||||
|
||||
var subView = new View () {
|
||||
X = subX,
|
||||
Y = subY,
|
||||
Width = subWidth,
|
||||
Height = subHeight,
|
||||
ValidatePosDim = true,
|
||||
};
|
||||
|
||||
superView.Add (subView);
|
||||
|
||||
superView.BeginInit ();
|
||||
superView.EndInit ();
|
||||
superView.SetRelativeLayout (new Rect (0, 0, 0, 0));
|
||||
Assert.Equal (new Rect (0, 0, expectedWidth, expectedHeight), superView.Frame);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData (0, 0, 0, 0, 0)]
|
||||
[InlineData (0, 0, 5, 0, 5)]
|
||||
[InlineData (0, 0, 0, 5, 0)]
|
||||
[InlineData (0, 0, 5, 5, 5)]
|
||||
|
||||
[InlineData (1, 0, 5, 0, 6)]
|
||||
[InlineData (1, 0, 0, 5, 1)]
|
||||
[InlineData (1, 0, 5, 5, 6)]
|
||||
[InlineData (1, 1, 5, 5, 6)]
|
||||
|
||||
[InlineData (-1, 0, 5, 0, 4)]
|
||||
[InlineData (-1, 0, 0, 5, 0)]
|
||||
[InlineData (-1, 0, 5, 5, 4)]
|
||||
[InlineData (-1, -1, 5, 5, 4)]
|
||||
public void Width_Auto_Height_NotChanged (int subX, int subY, int subWidth, int subHeight, int expectedWidth)
|
||||
{
|
||||
var superView = new View () {
|
||||
X = 0,
|
||||
Y = 0,
|
||||
Width = Dim.Auto (),
|
||||
Height = 10,
|
||||
ValidatePosDim = true,
|
||||
};
|
||||
|
||||
var subView = new View () {
|
||||
X = subX,
|
||||
Y = subY,
|
||||
Width = subWidth,
|
||||
Height = subHeight,
|
||||
ValidatePosDim = true,
|
||||
};
|
||||
|
||||
superView.Add (subView);
|
||||
|
||||
superView.BeginInit ();
|
||||
superView.EndInit ();
|
||||
superView.SetRelativeLayout (new Rect (0, 0, 0, 0));
|
||||
Assert.Equal (new Rect (0, 0, expectedWidth, 10), superView.Frame);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData (0, 0, 0, 0, 0)]
|
||||
[InlineData (0, 0, 5, 0, 0)]
|
||||
[InlineData (0, 0, 0, 5, 5)]
|
||||
[InlineData (0, 0, 5, 5, 5)]
|
||||
|
||||
[InlineData (1, 0, 5, 0, 0)]
|
||||
[InlineData (1, 0, 0, 5, 5)]
|
||||
[InlineData (1, 0, 5, 5, 5)]
|
||||
[InlineData (1, 1, 5, 5, 6)]
|
||||
|
||||
[InlineData (-1, 0, 5, 0, 0)]
|
||||
[InlineData (-1, 0, 0, 5, 5)]
|
||||
[InlineData (-1, 0, 5, 5, 5)]
|
||||
[InlineData (-1, -1, 5, 5, 4)]
|
||||
public void Height_Auto_Width_NotChanged (int subX, int subY, int subWidth, int subHeight, int expectedHeight)
|
||||
{
|
||||
var superView = new View () {
|
||||
X = 0,
|
||||
Y = 0,
|
||||
Width = 10,
|
||||
Height = Dim.Auto (),
|
||||
ValidatePosDim = true,
|
||||
};
|
||||
|
||||
var subView = new View () {
|
||||
X = subX,
|
||||
Y = subY,
|
||||
Width = subWidth,
|
||||
Height = subHeight,
|
||||
ValidatePosDim = true,
|
||||
};
|
||||
|
||||
superView.Add (subView);
|
||||
|
||||
superView.BeginInit ();
|
||||
superView.EndInit ();
|
||||
superView.SetRelativeLayout (new Rect (0, 0, 0, 0));
|
||||
Assert.Equal (new Rect (0, 0, 10, expectedHeight), superView.Frame);
|
||||
}
|
||||
|
||||
// Test validation
|
||||
[Fact]
|
||||
public void ValidatePosDim_True_Throws_When_SubView_Uses_SuperView_Dims ()
|
||||
{
|
||||
var superView = new View () {
|
||||
X = 0,
|
||||
Y = 0,
|
||||
Width = Dim.Auto (),
|
||||
Height = Dim.Auto (),
|
||||
ValidatePosDim = true,
|
||||
};
|
||||
|
||||
var subView = new View () {
|
||||
X = 0,
|
||||
Y = 0,
|
||||
Width = Dim.Fill (),
|
||||
Height = 10,
|
||||
ValidatePosDim = true,
|
||||
};
|
||||
|
||||
superView.BeginInit ();
|
||||
superView.EndInit ();
|
||||
|
||||
Assert.Throws<InvalidOperationException> (() => superView.Add (subView));
|
||||
|
||||
subView.Width = 10;
|
||||
superView.Add (subView);
|
||||
superView.BeginInit ();
|
||||
superView.EndInit ();
|
||||
superView.SetRelativeLayout (new Rect (0, 0, 0, 0));
|
||||
superView.LayoutSubviews (); // no throw
|
||||
|
||||
subView.Width = Dim.Fill ();
|
||||
Assert.Throws<InvalidOperationException> (() => superView.SetRelativeLayout (new Rect (0, 0, 0, 0)));
|
||||
subView.Width = 10;
|
||||
|
||||
subView.Height = Dim.Fill ();
|
||||
Assert.Throws<InvalidOperationException> (() => superView.SetRelativeLayout (new Rect (0, 0, 0, 0)));
|
||||
subView.Height = 10;
|
||||
|
||||
subView.Height = Dim.Percent (50);
|
||||
Assert.Throws<InvalidOperationException> (() => superView.SetRelativeLayout (new Rect (0, 0, 0, 0)));
|
||||
subView.Height = 10;
|
||||
|
||||
subView.X = Pos.Center ();
|
||||
Assert.Throws<InvalidOperationException> (() => superView.SetRelativeLayout (new Rect (0, 0, 0, 0)));
|
||||
subView.X = 0;
|
||||
|
||||
subView.Y = Pos.Center ();
|
||||
Assert.Throws<InvalidOperationException> (() => superView.SetRelativeLayout (new Rect (0, 0, 0, 0)));
|
||||
subView.Y = 0;
|
||||
|
||||
subView.Width = 10;
|
||||
subView.Height = 10;
|
||||
subView.X = 0;
|
||||
subView.Y = 0;
|
||||
superView.SetRelativeLayout (new Rect (0, 0, 0, 0));
|
||||
superView.LayoutSubviews ();
|
||||
}
|
||||
|
||||
// Test validation
|
||||
[Fact]
|
||||
public void ValidatePosDim_True_Throws_When_SubView_Uses_SuperView_Dims_Combine ()
|
||||
{
|
||||
var superView = new View () {
|
||||
X = 0,
|
||||
Y = 0,
|
||||
Width = Dim.Auto (),
|
||||
Height = Dim.Auto (),
|
||||
ValidatePosDim = true,
|
||||
};
|
||||
|
||||
var subView = new View () {
|
||||
X = 0,
|
||||
Y = 0,
|
||||
Width = 10,
|
||||
Height = 10
|
||||
};
|
||||
|
||||
|
||||
var subView2 = new View () {
|
||||
X = 0,
|
||||
Y = 0,
|
||||
Width = 10,
|
||||
Height = 10
|
||||
};
|
||||
|
||||
superView.Add (subView, subView2);
|
||||
superView.BeginInit ();
|
||||
superView.EndInit ();
|
||||
superView.SetRelativeLayout (new Rect (0, 0, 0, 0));
|
||||
superView.LayoutSubviews (); // no throw
|
||||
|
||||
subView.Height = Dim.Fill () + 3;
|
||||
Assert.Throws<InvalidOperationException> (() => superView.SetRelativeLayout (new Rect (0, 0, 0, 0)));
|
||||
subView.Height = 0;
|
||||
|
||||
subView.Height = 3 + Dim.Fill ();
|
||||
Assert.Throws<InvalidOperationException> (() => superView.SetRelativeLayout (new Rect (0, 0, 0, 0)));
|
||||
subView.Height = 0;
|
||||
|
||||
subView.Height = 3 + 5 + Dim.Fill ();
|
||||
Assert.Throws<InvalidOperationException> (() => superView.SetRelativeLayout (new Rect (0, 0, 0, 0)));
|
||||
subView.Height = 0;
|
||||
|
||||
subView.Height = 3 + 5 + Dim.Percent (10);
|
||||
Assert.Throws<InvalidOperationException> (() => superView.SetRelativeLayout (new Rect (0, 0, 0, 0)));
|
||||
subView.Height = 0;
|
||||
|
||||
// Tests nested Combine
|
||||
subView.Height = 5 + new Dim.DimCombine (true, 3, new Dim.DimCombine (true, Dim.Percent (10), 9));
|
||||
Assert.Throws<InvalidOperationException> (() => superView.SetRelativeLayout (new Rect (0, 0, 0, 0)));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ValidatePosDim_True_Throws_When_SubView_Uses_SuperView_Pos_Combine ()
|
||||
{
|
||||
var superView = new View () {
|
||||
X = 0,
|
||||
Y = 0,
|
||||
Width = Dim.Auto (),
|
||||
Height = Dim.Auto (),
|
||||
ValidatePosDim = true,
|
||||
};
|
||||
|
||||
var subView = new View () {
|
||||
X = 0,
|
||||
Y = 0,
|
||||
Width = 10,
|
||||
Height = 10
|
||||
};
|
||||
|
||||
var subView2 = new View () {
|
||||
X = 0,
|
||||
Y = 0,
|
||||
Width = 10,
|
||||
Height = 10
|
||||
};
|
||||
|
||||
superView.Add (subView, subView2);
|
||||
superView.BeginInit ();
|
||||
superView.EndInit ();
|
||||
superView.SetRelativeLayout (new Rect (0, 0, 0, 0));
|
||||
superView.LayoutSubviews (); // no throw
|
||||
|
||||
subView.X = Pos.Right (subView2);
|
||||
superView.SetRelativeLayout (new Rect (0, 0, 0, 0));
|
||||
superView.LayoutSubviews (); // no throw
|
||||
|
||||
subView.X = Pos.Right (subView2) + 3;
|
||||
superView.SetRelativeLayout (new Rect (0, 0, 0, 0)); // no throw
|
||||
superView.LayoutSubviews (); // no throw
|
||||
|
||||
subView.X = new Pos.PosCombine (true, Pos.Right (subView2), new Pos.PosCombine (true, 7, 9));
|
||||
superView.SetRelativeLayout (new Rect (0, 0, 0, 0)); // no throw
|
||||
|
||||
subView.X = Pos.Center () + 3;
|
||||
Assert.Throws<InvalidOperationException> (() => superView.SetRelativeLayout (new Rect (0, 0, 0, 0)));
|
||||
subView.X = 0;
|
||||
|
||||
subView.X = 3 + Pos.Center ();
|
||||
Assert.Throws<InvalidOperationException> (() => superView.SetRelativeLayout (new Rect (0, 0, 0, 0)));
|
||||
subView.X = 0;
|
||||
|
||||
subView.X = 3 + 5 + Pos.Center ();
|
||||
Assert.Throws<InvalidOperationException> (() => superView.SetRelativeLayout (new Rect (0, 0, 0, 0)));
|
||||
subView.X = 0;
|
||||
|
||||
subView.X = 3 + 5 + Pos.Percent (10);
|
||||
Assert.Throws<InvalidOperationException> (() => superView.SetRelativeLayout (new Rect (0, 0, 0, 0)));
|
||||
subView.X = 0;
|
||||
|
||||
subView.X = Pos.Percent (10) + Pos.Center ();
|
||||
Assert.Throws<InvalidOperationException> (() => superView.SetRelativeLayout (new Rect (0, 0, 0, 0)));
|
||||
subView.X = 0;
|
||||
|
||||
// Tests nested Combine
|
||||
subView.X = 5 + new Pos.PosCombine (true, Pos.Right (subView2), new Pos.PosCombine (true, Pos.Center (), 9));
|
||||
Assert.Throws<InvalidOperationException> (() => superView.SetRelativeLayout (new Rect (0, 0, 0, 0)));
|
||||
subView.X = 0;
|
||||
}
|
||||
|
||||
// Test min - ensure that if min is specified in the DimAuto constructor it is honored
|
||||
[Fact]
|
||||
public void DimAuto_Min ()
|
||||
{
|
||||
var superView = new View () {
|
||||
X = 0,
|
||||
Y = 0,
|
||||
Width = Dim.Auto (min: 10),
|
||||
Height = Dim.Auto (min: 10),
|
||||
ValidatePosDim = true,
|
||||
};
|
||||
|
||||
var subView = new View () {
|
||||
X = 0,
|
||||
Y = 0,
|
||||
Width = 5,
|
||||
Height = 5
|
||||
};
|
||||
|
||||
superView.Add (subView);
|
||||
superView.BeginInit ();
|
||||
superView.EndInit ();
|
||||
|
||||
superView.SetRelativeLayout (new Rect (0, 0, 0, 0));
|
||||
superView.LayoutSubviews (); // no throw
|
||||
|
||||
Assert.Equal (10, superView.Frame.Width);
|
||||
Assert.Equal (10, superView.Frame.Height);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DimAuto_Min_Resets_If_Subview_Shrinks ()
|
||||
{
|
||||
var superView = new View () {
|
||||
X = 0,
|
||||
Y = 0,
|
||||
Width = Dim.Auto (min: 10),
|
||||
Height = Dim.Auto (min: 10),
|
||||
ValidatePosDim = true,
|
||||
};
|
||||
|
||||
var subView = new View () {
|
||||
X = 0,
|
||||
Y = 0,
|
||||
Width = 5,
|
||||
Height = 5
|
||||
};
|
||||
|
||||
superView.Add (subView);
|
||||
superView.BeginInit ();
|
||||
superView.EndInit ();
|
||||
|
||||
superView.SetRelativeLayout (new Rect (0, 0, 0, 0));
|
||||
superView.LayoutSubviews (); // no throw
|
||||
|
||||
Assert.Equal (10, superView.Frame.Width);
|
||||
Assert.Equal (10, superView.Frame.Height);
|
||||
|
||||
subView.Width = 3;
|
||||
subView.Height = 3;
|
||||
superView.SetRelativeLayout (new Rect (0, 0, 0, 0));
|
||||
superView.LayoutSubviews (); // no throw
|
||||
|
||||
Assert.Equal (3, subView.Frame.Width);
|
||||
Assert.Equal (3, subView.Frame.Height);
|
||||
|
||||
Assert.Equal (10, superView.Frame.Width);
|
||||
Assert.Equal (10, superView.Frame.Height);
|
||||
}
|
||||
|
||||
// what happens if DimAuto (min: 10) and the subview moves to a negative coord?
|
||||
[Fact]
|
||||
public void DimAuto_Min_Resets_If_Subview_Moves_Negative ()
|
||||
{
|
||||
var superView = new View () {
|
||||
X = 0,
|
||||
Y = 0,
|
||||
Width = Dim.Auto (min: 10),
|
||||
Height = Dim.Auto (min: 10),
|
||||
ValidatePosDim = true,
|
||||
};
|
||||
|
||||
var subView = new View () {
|
||||
X = 0,
|
||||
Y = 0,
|
||||
Width = 5,
|
||||
Height = 5
|
||||
};
|
||||
|
||||
superView.Add (subView);
|
||||
superView.BeginInit ();
|
||||
superView.EndInit ();
|
||||
|
||||
superView.SetRelativeLayout (new Rect (0, 0, 0, 0));
|
||||
superView.LayoutSubviews (); // no throw
|
||||
|
||||
Assert.Equal (10, superView.Frame.Width);
|
||||
Assert.Equal (10, superView.Frame.Height);
|
||||
|
||||
subView.X = -1;
|
||||
subView.Y = -1;
|
||||
superView.SetRelativeLayout (new Rect (0, 0, 0, 0));
|
||||
superView.LayoutSubviews (); // no throw
|
||||
|
||||
Assert.Equal (5, subView.Frame.Width);
|
||||
Assert.Equal (5, subView.Frame.Height);
|
||||
|
||||
Assert.Equal (10, superView.Frame.Width);
|
||||
Assert.Equal (10, superView.Frame.Height);
|
||||
}
|
||||
|
||||
// Test variations of Frame
|
||||
|
||||
}
|
||||
public class DimAutoTests
|
||||
{
|
||||
private readonly ITestOutputHelper _output;
|
||||
|
||||
public DimAutoTests (ITestOutputHelper output)
|
||||
{
|
||||
_output = output;
|
||||
Console.OutputEncoding = Encoding.Default;
|
||||
|
||||
// Change current culture
|
||||
var culture = CultureInfo.CreateSpecificCulture ("en-US");
|
||||
Thread.CurrentThread.CurrentCulture = culture;
|
||||
Thread.CurrentThread.CurrentUICulture = culture;
|
||||
}
|
||||
|
||||
// Test min - ensure that if min is specified in the DimAuto constructor it is honored
|
||||
[Fact]
|
||||
public void DimAuto_Min ()
|
||||
{
|
||||
var superView = new View
|
||||
{
|
||||
X = 0,
|
||||
Y = 0,
|
||||
Width = Dim.Auto (min: 10),
|
||||
Height = Dim.Auto (min: 10),
|
||||
ValidatePosDim = true
|
||||
};
|
||||
|
||||
var subView = new View
|
||||
{
|
||||
X = 0,
|
||||
Y = 0,
|
||||
Width = 5,
|
||||
Height = 5
|
||||
};
|
||||
|
||||
superView.Add (subView);
|
||||
superView.BeginInit ();
|
||||
superView.EndInit ();
|
||||
|
||||
superView.SetRelativeLayout (new Rect (0, 0, 0, 0));
|
||||
superView.LayoutSubviews (); // no throw
|
||||
|
||||
Assert.Equal (10, superView.Frame.Width);
|
||||
Assert.Equal (10, superView.Frame.Height);
|
||||
}
|
||||
|
||||
// what happens if DimAuto (min: 10) and the subview moves to a negative coord?
|
||||
[Fact]
|
||||
public void DimAuto_Min_Resets_If_Subview_Moves_Negative ()
|
||||
{
|
||||
var superView = new View
|
||||
{
|
||||
X = 0,
|
||||
Y = 0,
|
||||
Width = Dim.Auto (min: 10),
|
||||
Height = Dim.Auto (min: 10),
|
||||
ValidatePosDim = true
|
||||
};
|
||||
|
||||
var subView = new View
|
||||
{
|
||||
X = 0,
|
||||
Y = 0,
|
||||
Width = 5,
|
||||
Height = 5
|
||||
};
|
||||
|
||||
superView.Add (subView);
|
||||
superView.BeginInit ();
|
||||
superView.EndInit ();
|
||||
|
||||
superView.SetRelativeLayout (new Rect (0, 0, 0, 0));
|
||||
superView.LayoutSubviews (); // no throw
|
||||
|
||||
Assert.Equal (10, superView.Frame.Width);
|
||||
Assert.Equal (10, superView.Frame.Height);
|
||||
|
||||
subView.X = -1;
|
||||
subView.Y = -1;
|
||||
superView.SetRelativeLayout (new Rect (0, 0, 0, 0));
|
||||
superView.LayoutSubviews (); // no throw
|
||||
|
||||
Assert.Equal (5, subView.Frame.Width);
|
||||
Assert.Equal (5, subView.Frame.Height);
|
||||
|
||||
Assert.Equal (10, superView.Frame.Width);
|
||||
Assert.Equal (10, superView.Frame.Height);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DimAuto_Min_Resets_If_Subview_Shrinks ()
|
||||
{
|
||||
var superView = new View
|
||||
{
|
||||
X = 0,
|
||||
Y = 0,
|
||||
Width = Dim.Auto (min: 10),
|
||||
Height = Dim.Auto (min: 10),
|
||||
ValidatePosDim = true
|
||||
};
|
||||
|
||||
var subView = new View
|
||||
{
|
||||
X = 0,
|
||||
Y = 0,
|
||||
Width = 5,
|
||||
Height = 5
|
||||
};
|
||||
|
||||
superView.Add (subView);
|
||||
superView.BeginInit ();
|
||||
superView.EndInit ();
|
||||
|
||||
superView.SetRelativeLayout (new Rect (0, 0, 0, 0));
|
||||
superView.LayoutSubviews (); // no throw
|
||||
|
||||
Assert.Equal (10, superView.Frame.Width);
|
||||
Assert.Equal (10, superView.Frame.Height);
|
||||
|
||||
subView.Width = 3;
|
||||
subView.Height = 3;
|
||||
superView.SetRelativeLayout (new Rect (0, 0, 0, 0));
|
||||
superView.LayoutSubviews (); // no throw
|
||||
|
||||
Assert.Equal (3, subView.Frame.Width);
|
||||
Assert.Equal (3, subView.Frame.Height);
|
||||
|
||||
Assert.Equal (10, superView.Frame.Width);
|
||||
Assert.Equal (10, superView.Frame.Height);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData (0, 0, 0, 0, 0)]
|
||||
[InlineData (0, 0, 5, 0, 0)]
|
||||
[InlineData (0, 0, 0, 5, 5)]
|
||||
[InlineData (0, 0, 5, 5, 5)]
|
||||
[InlineData (1, 0, 5, 0, 0)]
|
||||
[InlineData (1, 0, 0, 5, 5)]
|
||||
[InlineData (1, 0, 5, 5, 5)]
|
||||
[InlineData (1, 1, 5, 5, 6)]
|
||||
[InlineData (-1, 0, 5, 0, 0)]
|
||||
[InlineData (-1, 0, 0, 5, 5)]
|
||||
[InlineData (-1, 0, 5, 5, 5)]
|
||||
[InlineData (-1, -1, 5, 5, 4)]
|
||||
public void Height_Auto_Width_NotChanged (int subX, int subY, int subWidth, int subHeight, int expectedHeight)
|
||||
{
|
||||
var superView = new View
|
||||
{
|
||||
X = 0,
|
||||
Y = 0,
|
||||
Width = 10,
|
||||
Height = Dim.Auto (),
|
||||
ValidatePosDim = true
|
||||
};
|
||||
|
||||
var subView = new View
|
||||
{
|
||||
X = subX,
|
||||
Y = subY,
|
||||
Width = subWidth,
|
||||
Height = subHeight,
|
||||
ValidatePosDim = true
|
||||
};
|
||||
|
||||
superView.Add (subView);
|
||||
|
||||
superView.BeginInit ();
|
||||
superView.EndInit ();
|
||||
superView.SetRelativeLayout (new Rect (0, 0, 0, 0));
|
||||
Assert.Equal (new Rect (0, 0, 10, expectedHeight), superView.Frame);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void NoSubViews_Does_Nothing ()
|
||||
{
|
||||
var superView = new View
|
||||
{
|
||||
X = 0,
|
||||
Y = 0,
|
||||
Width = Dim.Auto (),
|
||||
Height = Dim.Auto (),
|
||||
ValidatePosDim = true
|
||||
};
|
||||
|
||||
superView.BeginInit ();
|
||||
superView.EndInit ();
|
||||
superView.SetRelativeLayout (new Rect (0, 0, 0, 0));
|
||||
Assert.Equal (new Rect (0, 0, 0, 0), superView.Frame);
|
||||
|
||||
superView.SetRelativeLayout (new Rect (0, 0, 10, 10));
|
||||
Assert.Equal (new Rect (0, 0, 0, 0), superView.Frame);
|
||||
|
||||
superView.SetRelativeLayout (new Rect (10, 10, 10, 10));
|
||||
Assert.Equal (new Rect (0, 0, 0, 0), superView.Frame);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData (0, 0, 0, 0, 0, 0)]
|
||||
[InlineData (0, 0, 5, 0, 5, 0)]
|
||||
[InlineData (0, 0, 0, 5, 0, 5)]
|
||||
[InlineData (0, 0, 5, 5, 5, 5)]
|
||||
[InlineData (1, 0, 5, 0, 6, 0)]
|
||||
[InlineData (1, 0, 0, 5, 1, 5)]
|
||||
[InlineData (1, 0, 5, 5, 6, 5)]
|
||||
[InlineData (1, 1, 5, 5, 6, 6)]
|
||||
[InlineData (-1, 0, 5, 0, 4, 0)]
|
||||
[InlineData (-1, 0, 0, 5, 0, 5)]
|
||||
[InlineData (-1, 0, 5, 5, 4, 5)]
|
||||
[InlineData (-1, -1, 5, 5, 4, 4)]
|
||||
public void SubView_ChangesSuperViewSize (int subX, int subY, int subWidth, int subHeight, int expectedWidth, int expectedHeight)
|
||||
{
|
||||
var superView = new View
|
||||
{
|
||||
X = 0,
|
||||
Y = 0,
|
||||
Width = Dim.Auto (),
|
||||
Height = Dim.Auto (),
|
||||
ValidatePosDim = true
|
||||
};
|
||||
|
||||
var subView = new View
|
||||
{
|
||||
X = subX,
|
||||
Y = subY,
|
||||
Width = subWidth,
|
||||
Height = subHeight,
|
||||
ValidatePosDim = true
|
||||
};
|
||||
|
||||
superView.Add (subView);
|
||||
|
||||
superView.BeginInit ();
|
||||
superView.EndInit ();
|
||||
superView.SetRelativeLayout (new Rect (0, 0, 0, 0));
|
||||
Assert.Equal (new Rect (0, 0, expectedWidth, expectedHeight), superView.Frame);
|
||||
}
|
||||
|
||||
// Test validation
|
||||
[Fact]
|
||||
public void ValidatePosDim_True_Throws_When_SubView_Uses_SuperView_Dims ()
|
||||
{
|
||||
var superView = new View
|
||||
{
|
||||
X = 0,
|
||||
Y = 0,
|
||||
Width = Dim.Auto (),
|
||||
Height = Dim.Auto (),
|
||||
ValidatePosDim = true
|
||||
};
|
||||
|
||||
var subView = new View
|
||||
{
|
||||
X = 0,
|
||||
Y = 0,
|
||||
Width = Dim.Fill (),
|
||||
Height = 10,
|
||||
ValidatePosDim = true
|
||||
};
|
||||
|
||||
superView.BeginInit ();
|
||||
superView.EndInit ();
|
||||
|
||||
Assert.Throws<InvalidOperationException> (() => superView.Add (subView));
|
||||
|
||||
subView.Width = 10;
|
||||
superView.Add (subView);
|
||||
superView.BeginInit ();
|
||||
superView.EndInit ();
|
||||
superView.SetRelativeLayout (new Rect (0, 0, 0, 0));
|
||||
superView.LayoutSubviews (); // no throw
|
||||
|
||||
subView.Width = Dim.Fill ();
|
||||
Assert.Throws<InvalidOperationException> (() => superView.SetRelativeLayout (new Rect (0, 0, 0, 0)));
|
||||
subView.Width = 10;
|
||||
|
||||
subView.Height = Dim.Fill ();
|
||||
Assert.Throws<InvalidOperationException> (() => superView.SetRelativeLayout (new Rect (0, 0, 0, 0)));
|
||||
subView.Height = 10;
|
||||
|
||||
subView.Height = Dim.Percent (50);
|
||||
Assert.Throws<InvalidOperationException> (() => superView.SetRelativeLayout (new Rect (0, 0, 0, 0)));
|
||||
subView.Height = 10;
|
||||
|
||||
subView.X = Pos.Center ();
|
||||
Assert.Throws<InvalidOperationException> (() => superView.SetRelativeLayout (new Rect (0, 0, 0, 0)));
|
||||
subView.X = 0;
|
||||
|
||||
subView.Y = Pos.Center ();
|
||||
Assert.Throws<InvalidOperationException> (() => superView.SetRelativeLayout (new Rect (0, 0, 0, 0)));
|
||||
subView.Y = 0;
|
||||
|
||||
subView.Width = 10;
|
||||
subView.Height = 10;
|
||||
subView.X = 0;
|
||||
subView.Y = 0;
|
||||
superView.SetRelativeLayout (new Rect (0, 0, 0, 0));
|
||||
superView.LayoutSubviews ();
|
||||
}
|
||||
|
||||
// Test validation
|
||||
[Fact]
|
||||
public void ValidatePosDim_True_Throws_When_SubView_Uses_SuperView_Dims_Combine ()
|
||||
{
|
||||
var superView = new View
|
||||
{
|
||||
X = 0,
|
||||
Y = 0,
|
||||
Width = Dim.Auto (),
|
||||
Height = Dim.Auto (),
|
||||
ValidatePosDim = true
|
||||
};
|
||||
|
||||
var subView = new View
|
||||
{
|
||||
X = 0,
|
||||
Y = 0,
|
||||
Width = 10,
|
||||
Height = 10
|
||||
};
|
||||
|
||||
var subView2 = new View
|
||||
{
|
||||
X = 0,
|
||||
Y = 0,
|
||||
Width = 10,
|
||||
Height = 10
|
||||
};
|
||||
|
||||
superView.Add (subView, subView2);
|
||||
superView.BeginInit ();
|
||||
superView.EndInit ();
|
||||
superView.SetRelativeLayout (new Rect (0, 0, 0, 0));
|
||||
superView.LayoutSubviews (); // no throw
|
||||
|
||||
subView.Height = Dim.Fill () + 3;
|
||||
Assert.Throws<InvalidOperationException> (() => superView.SetRelativeLayout (new Rect (0, 0, 0, 0)));
|
||||
subView.Height = 0;
|
||||
|
||||
subView.Height = 3 + Dim.Fill ();
|
||||
Assert.Throws<InvalidOperationException> (() => superView.SetRelativeLayout (new Rect (0, 0, 0, 0)));
|
||||
subView.Height = 0;
|
||||
|
||||
subView.Height = 3 + 5 + Dim.Fill ();
|
||||
Assert.Throws<InvalidOperationException> (() => superView.SetRelativeLayout (new Rect (0, 0, 0, 0)));
|
||||
subView.Height = 0;
|
||||
|
||||
subView.Height = 3 + 5 + Dim.Percent (10);
|
||||
Assert.Throws<InvalidOperationException> (() => superView.SetRelativeLayout (new Rect (0, 0, 0, 0)));
|
||||
subView.Height = 0;
|
||||
|
||||
// Tests nested Combine
|
||||
subView.Height = 5 + new Dim.DimCombine (true, 3, new Dim.DimCombine (true, Dim.Percent (10), 9));
|
||||
Assert.Throws<InvalidOperationException> (() => superView.SetRelativeLayout (new Rect (0, 0, 0, 0)));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ValidatePosDim_True_Throws_When_SubView_Uses_SuperView_Pos_Combine ()
|
||||
{
|
||||
var superView = new View
|
||||
{
|
||||
X = 0,
|
||||
Y = 0,
|
||||
Width = Dim.Auto (),
|
||||
Height = Dim.Auto (),
|
||||
ValidatePosDim = true
|
||||
};
|
||||
|
||||
var subView = new View
|
||||
{
|
||||
X = 0,
|
||||
Y = 0,
|
||||
Width = 10,
|
||||
Height = 10
|
||||
};
|
||||
|
||||
var subView2 = new View
|
||||
{
|
||||
X = 0,
|
||||
Y = 0,
|
||||
Width = 10,
|
||||
Height = 10
|
||||
};
|
||||
|
||||
superView.Add (subView, subView2);
|
||||
superView.BeginInit ();
|
||||
superView.EndInit ();
|
||||
superView.SetRelativeLayout (new Rect (0, 0, 0, 0));
|
||||
superView.LayoutSubviews (); // no throw
|
||||
|
||||
subView.X = Pos.Right (subView2);
|
||||
superView.SetRelativeLayout (new Rect (0, 0, 0, 0));
|
||||
superView.LayoutSubviews (); // no throw
|
||||
|
||||
subView.X = Pos.Right (subView2) + 3;
|
||||
superView.SetRelativeLayout (new Rect (0, 0, 0, 0)); // no throw
|
||||
superView.LayoutSubviews (); // no throw
|
||||
|
||||
subView.X = new Pos.PosCombine (true, Pos.Right (subView2), new Pos.PosCombine (true, 7, 9));
|
||||
superView.SetRelativeLayout (new Rect (0, 0, 0, 0)); // no throw
|
||||
|
||||
subView.X = Pos.Center () + 3;
|
||||
Assert.Throws<InvalidOperationException> (() => superView.SetRelativeLayout (new Rect (0, 0, 0, 0)));
|
||||
subView.X = 0;
|
||||
|
||||
subView.X = 3 + Pos.Center ();
|
||||
Assert.Throws<InvalidOperationException> (() => superView.SetRelativeLayout (new Rect (0, 0, 0, 0)));
|
||||
subView.X = 0;
|
||||
|
||||
subView.X = 3 + 5 + Pos.Center ();
|
||||
Assert.Throws<InvalidOperationException> (() => superView.SetRelativeLayout (new Rect (0, 0, 0, 0)));
|
||||
subView.X = 0;
|
||||
|
||||
subView.X = 3 + 5 + Pos.Percent (10);
|
||||
Assert.Throws<InvalidOperationException> (() => superView.SetRelativeLayout (new Rect (0, 0, 0, 0)));
|
||||
subView.X = 0;
|
||||
|
||||
subView.X = Pos.Percent (10) + Pos.Center ();
|
||||
Assert.Throws<InvalidOperationException> (() => superView.SetRelativeLayout (new Rect (0, 0, 0, 0)));
|
||||
subView.X = 0;
|
||||
|
||||
// Tests nested Combine
|
||||
subView.X = 5 + new Pos.PosCombine (true, Pos.Right (subView2), new Pos.PosCombine (true, Pos.Center (), 9));
|
||||
Assert.Throws<InvalidOperationException> (() => superView.SetRelativeLayout (new Rect (0, 0, 0, 0)));
|
||||
subView.X = 0;
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData (0, 0, 0, 0, 0)]
|
||||
[InlineData (0, 0, 5, 0, 5)]
|
||||
[InlineData (0, 0, 0, 5, 0)]
|
||||
[InlineData (0, 0, 5, 5, 5)]
|
||||
[InlineData (1, 0, 5, 0, 6)]
|
||||
[InlineData (1, 0, 0, 5, 1)]
|
||||
[InlineData (1, 0, 5, 5, 6)]
|
||||
[InlineData (1, 1, 5, 5, 6)]
|
||||
[InlineData (-1, 0, 5, 0, 4)]
|
||||
[InlineData (-1, 0, 0, 5, 0)]
|
||||
[InlineData (-1, 0, 5, 5, 4)]
|
||||
[InlineData (-1, -1, 5, 5, 4)]
|
||||
public void Width_Auto_Height_NotChanged (int subX, int subY, int subWidth, int subHeight, int expectedWidth)
|
||||
{
|
||||
var superView = new View
|
||||
{
|
||||
X = 0,
|
||||
Y = 0,
|
||||
Width = Dim.Auto (),
|
||||
Height = 10,
|
||||
ValidatePosDim = true
|
||||
};
|
||||
|
||||
var subView = new View
|
||||
{
|
||||
X = subX,
|
||||
Y = subY,
|
||||
Width = subWidth,
|
||||
Height = subHeight,
|
||||
ValidatePosDim = true
|
||||
};
|
||||
|
||||
superView.Add (subView);
|
||||
|
||||
superView.BeginInit ();
|
||||
superView.EndInit ();
|
||||
superView.SetRelativeLayout (new Rect (0, 0, 0, 0));
|
||||
Assert.Equal (new Rect (0, 0, expectedWidth, 10), superView.Frame);
|
||||
}
|
||||
|
||||
// Test variations of Frame
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user