mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-27 16:27:55 +01:00
* Removes CheckAbsoulte and updates unit tests to match
* Fixed code that was dependent on ToString behavior vs. direct test for null
* Dim/Pos != null WIP
* Moved AutoSize specific tests out of Pos/Dim tests
* Broke out AutoSize = false tests to new file
* Commented test TODOs
* New test
* Removed unused API and cleaned up code
* Removed unused API and cleaned up code
* Cleaned up code
* Cleaned up code
* reorg'd Toplevel tests
* Fixed Create and related unit tests
* Added test from #3136
* Removed TopLevel.Create
* Fixed SetCurrentOverlappedAsTop
* Updated pull request template
* Updated pull request template
* Revert "Updated pull request template"
This reverts commit d807190dd9.
* reverting
* re-reverting
* Fixed every thing but autosize scenarios??
* Fixed hexview
* Fixed contextmenu
* Fixed more minor issues in tests
* Fixed more minor issues in tests
* Debugging Dialog test failure
* Fixed bad Dialog test. Was cleary invalid
* Fixed OnResizeNeeded bug
* Fixed OnResizeNeeded bug
* Fixed UICatalog to not eat exceptions
* Fixed TextView
* Removed Frame overrides
* Made Frame non-virtual
* Fixed radioGroup
* Fixed TabView
* Hcked ScrolLBarView unit tests to pass
* All AutoSize tests pass!
* All tests pass!!!!!!!
* Updated API docs. Cleaned up code.
* Fixed ColorPicker
* Added 'Bounds =' unit tests
* Refactored TextFormatter.Size setting logic
* Cleaned up OnResizeNeeded (api docs and usages)
* Merges in #3019 changes. Makes OnResizeNeeded non-virtual. If we find a use-case where someone wants to override it we can change this back.
* Fixed FileDialog bounds warning
* Removed resharper settings from editorconfig
* Added Pos.Center test to AllViewsTests.cs.
Modernized RadioGroup.
Fixed ProgressBar.
* Reverted formatting
* Reverted formatting
* Reverted formatting
* Reverted formatting
* Reverted formatting
* Reverted formatting
* Reverted formatting
* Code cleanup
* Code cleanup
* Code cleanup
* Code cleanup
* Code cleanup
* Code cleanup
* Code cleanup
* Code cleanup
* Reverted formatting
255 lines
7.8 KiB
C#
255 lines
7.8 KiB
C#
using Xunit;
|
|
using Xunit.Abstractions;
|
|
|
|
namespace Terminal.Gui.ViewTests;
|
|
|
|
/// <summary>
|
|
/// Tests for view coordinate mapping (e.g. <see cref="View.ScreenToFrame"/> etc...).
|
|
/// </summary>
|
|
public class CoordinateTests {
|
|
readonly ITestOutputHelper _output;
|
|
|
|
public CoordinateTests (ITestOutputHelper output) => _output = output;
|
|
|
|
/// <summary>
|
|
/// Tests that screen to view mapping works correctly when the view has no superview and there are no Frames on the view.
|
|
/// </summary>
|
|
[Theory]
|
|
[InlineData (0, 0, 0, 0, 0, 0)]
|
|
[InlineData (0, 0, 1, 1, 1, 1)]
|
|
[InlineData (0, 0, 9, 9, 9, 9)]
|
|
[InlineData (0, 0, 11, 11, 11, 11)] // it's ok for the view to return coordinates outside of its bounds
|
|
[InlineData (1, 1, 0, 0, -1, -1)]
|
|
[InlineData (1, 1, 1, 1, 0, 0)]
|
|
[InlineData (1, 1, 9, 9, 8, 8)]
|
|
[InlineData (1, 1, 11, 11, 10, 10)] // it's ok for the view to return coordinates outside of its bounds
|
|
public void ScreenToView_NoSuper_NoFrames (int viewX, int viewY, int x, int y, int expectedX, int expectedY)
|
|
{
|
|
var view = new View {
|
|
X = viewX,
|
|
Y = viewY,
|
|
Width = 10,
|
|
Height = 10
|
|
};
|
|
|
|
var actual = view.ScreenToFrame (x, y);
|
|
Assert.Equal (expectedX, actual.X);
|
|
Assert.Equal (expectedY, actual.Y);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tests that screen to view mapping works correctly when the view has no superview and there ARE Frames on the view.
|
|
/// </summary>
|
|
[Theory]
|
|
[InlineData (0, 0, 0, 0, 0, 0)]
|
|
[InlineData (0, 0, 1, 1, 1, 1)]
|
|
[InlineData (0, 0, 9, 9, 9, 9)]
|
|
[InlineData (0, 0, 11, 11, 11, 11)] // it's ok for the view to return coordinates outside of its bounds
|
|
[InlineData (1, 1, 0, 0, -1, -1)]
|
|
[InlineData (1, 1, 1, 1, 0, 0)]
|
|
[InlineData (1, 1, 9, 9, 8, 8)]
|
|
[InlineData (1, 1, 11, 11, 10, 10)] // it's ok for the view to return coordinates outside of its bounds
|
|
public void ScreenToView_NoSuper_HasFrames (int viewX, int viewY, int x, int y, int expectedX, int expectedY)
|
|
{
|
|
var view = new View {
|
|
X = viewX,
|
|
Y = viewY,
|
|
Width = 10,
|
|
Height = 10,
|
|
BorderStyle = LineStyle.Single
|
|
};
|
|
|
|
var actual = view.ScreenToFrame (x, y);
|
|
Assert.Equal (expectedX, actual.X);
|
|
Assert.Equal (expectedY, actual.Y);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tests that screen to view mapping works correctly when the view has as superview it does not have Frames
|
|
/// </summary>
|
|
[Theory]
|
|
[InlineData (0, 0, 0, 0, 0, 0)]
|
|
[InlineData (0, 0, 1, 1, 1, 1)]
|
|
[InlineData (0, 0, 9, 9, 9, 9)]
|
|
[InlineData (0, 0, 11, 11, 11, 11)] // it's ok for the view to return coordinates outside of its bounds
|
|
[InlineData (1, 1, 0, 0, -1, -1)]
|
|
[InlineData (1, 1, 1, 1, 0, 0)]
|
|
[InlineData (1, 1, 9, 9, 8, 8)]
|
|
[InlineData (1, 1, 11, 11, 10, 10)] // it's ok for the view to return coordinates outside of its bounds
|
|
public void ScreenToView_SuperHasNoFrames (int viewX, int viewY, int x, int y, int expectedX, int expectedY)
|
|
{
|
|
var super = new View {
|
|
X = 0,
|
|
Y = 0,
|
|
Width = 10,
|
|
Height = 10
|
|
};
|
|
var view = new View {
|
|
X = viewX,
|
|
Y = viewY,
|
|
Width = 5,
|
|
Height = 5
|
|
};
|
|
super.Add (view);
|
|
|
|
var actual = view.ScreenToFrame (x, y);
|
|
Assert.Equal (expectedX, actual.X);
|
|
Assert.Equal (expectedY, actual.Y);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tests that screen to view mapping works correctly when the view has as superview it DOES have Frames
|
|
/// </summary>
|
|
[Theory]
|
|
[InlineData (0, 0, 0, 0, -1, -1)] // it's ok for the view to return coordinates outside of its bounds
|
|
[InlineData (0, 0, 1, 1, 0, 0)]
|
|
[InlineData (0, 0, 9, 9, 8, 8)]
|
|
[InlineData (0, 0, 11, 11, 10, 10)] // it's ok for the view to return coordinates outside of its bounds
|
|
[InlineData (1, 1, 0, 0, -2, -2)]
|
|
[InlineData (1, 1, 1, 1, -1, -1)]
|
|
[InlineData (1, 1, 9, 9, 7, 7)]
|
|
[InlineData (1, 1, 11, 11, 9, 9)] // it's ok for the view to return coordinates outside of its bounds
|
|
public void ScreenToView_SuperHasFrames (int viewX, int viewY, int x, int y, int expectedX, int expectedY)
|
|
{
|
|
var super = new View {
|
|
X = 0,
|
|
Y = 0,
|
|
Width = 10,
|
|
Height = 10,
|
|
BorderStyle = LineStyle.Single
|
|
};
|
|
var view = new View {
|
|
X = viewX,
|
|
Y = viewY,
|
|
Width = 5,
|
|
Height = 5
|
|
};
|
|
super.Add (view);
|
|
|
|
var actual = view.ScreenToFrame (x, y);
|
|
Assert.Equal (expectedX, actual.X);
|
|
Assert.Equal (expectedY, actual.Y);
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// Tests that screen to bounds mapping works correctly when the view has no superview and there are no Frames on the view.
|
|
/// </summary>
|
|
[Theory]
|
|
[InlineData (0, 0, 0, 0, 0, 0)]
|
|
[InlineData (0, 0, 1, 1, 1, 1)]
|
|
[InlineData (0, 0, 9, 9, 9, 9)]
|
|
[InlineData (0, 0, 11, 11, 11, 11)] // it's ok for the view to return coordinates outside of its bounds
|
|
[InlineData (1, 1, 0, 0, -1, -1)]
|
|
[InlineData (1, 1, 1, 1, 0, 0)]
|
|
[InlineData (1, 1, 9, 9, 8, 8)]
|
|
[InlineData (1, 1, 11, 11, 10, 10)] // it's ok for the view to return coordinates outside of its bounds
|
|
public void ScreenToBounds_NoSuper_NoFrames (int viewX, int viewY, int x, int y, int expectedX, int expectedY)
|
|
{
|
|
var view = new View {
|
|
X = viewX,
|
|
Y = viewY,
|
|
Width = 10,
|
|
Height = 10
|
|
};
|
|
|
|
var actual = view.ScreenToBounds (x, y);
|
|
Assert.Equal (expectedX, actual.X);
|
|
Assert.Equal (expectedY, actual.Y);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tests that screen to bounds mapping works correctly when the view has no superview and there ARE Frames on the view.
|
|
/// </summary>
|
|
[Theory]
|
|
[InlineData (0, 0, 0, 0, -1, -1)]
|
|
[InlineData (0, 0, 1, 1, 0, 0)]
|
|
[InlineData (0, 0, 9, 9, 8, 8)]
|
|
[InlineData (0, 0, 11, 11, 10, 10)]
|
|
[InlineData (1, 1, 0, 0, -2, -2)]
|
|
[InlineData (1, 1, 1, 1, -1, -1)]
|
|
[InlineData (1, 1, 9, 9, 7, 7)]
|
|
[InlineData (1, 1, 11, 11, 9, 9)]
|
|
public void ScreenToBounds_NoSuper_HasFrames (int viewX, int viewY, int x, int y, int expectedX, int expectedY)
|
|
{
|
|
var view = new View {
|
|
X = viewX,
|
|
Y = viewY,
|
|
Width = 10,
|
|
Height = 10,
|
|
BorderStyle = LineStyle.Single
|
|
};
|
|
|
|
var actual = view.ScreenToBounds (x, y);
|
|
Assert.Equal (expectedX, actual.X);
|
|
Assert.Equal (expectedY, actual.Y);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tests that screen to bounds mapping works correctly when the view has as superview it does not have Frames
|
|
/// </summary>
|
|
[Theory]
|
|
[InlineData (0, 0, 0, 0, 0, 0)]
|
|
[InlineData (0, 0, 1, 1, 1, 1)]
|
|
[InlineData (0, 0, 9, 9, 9, 9)]
|
|
[InlineData (0, 0, 11, 11, 11, 11)] // it's ok for the view to return coordinates outside of its bounds
|
|
[InlineData (1, 1, 0, 0, -1, -1)]
|
|
[InlineData (1, 1, 1, 1, 0, 0)]
|
|
[InlineData (1, 1, 9, 9, 8, 8)]
|
|
[InlineData (1, 1, 11, 11, 10, 10)] // it's ok for the view to return coordinates outside of its bounds
|
|
public void ScreenToBounds_SuperHasNoFrames (int viewX, int viewY, int x, int y, int expectedX, int expectedY)
|
|
{
|
|
var super = new View {
|
|
X = 0,
|
|
Y = 0,
|
|
Width = 10,
|
|
Height = 10
|
|
};
|
|
var view = new View {
|
|
X = viewX,
|
|
Y = viewY,
|
|
Width = 5,
|
|
Height = 5
|
|
};
|
|
super.Add (view);
|
|
|
|
var actual = view.ScreenToBounds (x, y);
|
|
Assert.Equal (expectedX, actual.X);
|
|
Assert.Equal (expectedY, actual.Y);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tests that screen to bounds mapping works correctly when the view has as superview it DOES have Frames
|
|
/// </summary>
|
|
[Theory]
|
|
[InlineData (0, 0, 0, 0, -1, -1)] // it's ok for the view to return coordinates outside of its bounds
|
|
[InlineData (0, 0, 1, 1, 0, 0)]
|
|
[InlineData (0, 0, 9, 9, 8, 8)]
|
|
[InlineData (0, 0, 11, 11, 10, 10)] // it's ok for the view to return coordinates outside of its bounds
|
|
[InlineData (1, 1, 0, 0, -2, -2)]
|
|
[InlineData (1, 1, 1, 1, -1, -1)]
|
|
[InlineData (1, 1, 9, 9, 7, 7)]
|
|
[InlineData (1, 1, 11, 11, 9, 9)] // it's ok for the view to return coordinates outside of its bounds
|
|
public void ScreenToBounds_SuperHasFrames (int viewX, int viewY, int x, int y, int expectedX, int expectedY)
|
|
{
|
|
var super = new View {
|
|
X = 0,
|
|
Y = 0,
|
|
Width = 10,
|
|
Height = 10,
|
|
BorderStyle = LineStyle.Single
|
|
};
|
|
var view = new View {
|
|
X = viewX,
|
|
Y = viewY,
|
|
Width = 5,
|
|
Height = 5
|
|
};
|
|
super.Add (view);
|
|
|
|
var actual = view.ScreenToFrame (x, y);
|
|
Assert.Equal (expectedX, actual.X);
|
|
Assert.Equal (expectedY, actual.Y);
|
|
}
|
|
} |