ClipRegionTests.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. using System.Text;
  2. using Xunit.Abstractions;
  3. // Alias Console to MockConsole so we don't accidentally use Console
  4. namespace Terminal.Gui.DriverTests;
  5. public class ClipRegionTests
  6. {
  7. private readonly ITestOutputHelper _output;
  8. public ClipRegionTests (ITestOutputHelper output)
  9. {
  10. ConsoleDriver.RunningUnitTests = true;
  11. this._output = output;
  12. }
  13. [Theory]
  14. [InlineData (typeof (FakeDriver))]
  15. [InlineData (typeof (NetDriver))]
  16. //[InlineData (typeof (ANSIDriver))]
  17. [InlineData (typeof (WindowsDriver))]
  18. [InlineData (typeof (CursesDriver))]
  19. public void AddRune_Is_Clipped (Type driverType)
  20. {
  21. var driver = (IConsoleDriver)Activator.CreateInstance (driverType);
  22. Application.Init (driver);
  23. Application.Driver!.Rows = 25;
  24. Application.Driver!.Cols = 80;
  25. driver.Move (0, 0);
  26. driver.AddRune ('x');
  27. Assert.Equal ((Rune)'x', driver.Contents [0, 0].Rune);
  28. driver.Move (5, 5);
  29. driver.AddRune ('x');
  30. Assert.Equal ((Rune)'x', driver.Contents [5, 5].Rune);
  31. // Clear the contents
  32. driver.FillRect (new Rectangle (0, 0, driver.Rows, driver.Cols), ' ');
  33. Assert.Equal ((Rune)' ', driver.Contents [0, 0].Rune);
  34. // Setup the region with a single rectangle, fill screen with 'x'
  35. driver.Clip = new (new Rectangle (5, 5, 5, 5));
  36. driver.FillRect (new Rectangle (0, 0, driver.Rows, driver.Cols), 'x');
  37. Assert.Equal ((Rune)' ', driver.Contents [0, 0].Rune);
  38. Assert.Equal ((Rune)' ', driver.Contents [4, 9].Rune);
  39. Assert.Equal ((Rune)'x', driver.Contents [5, 5].Rune);
  40. Assert.Equal ((Rune)'x', driver.Contents [9, 9].Rune);
  41. Assert.Equal ((Rune)' ', driver.Contents [10, 10].Rune);
  42. Application.Shutdown ();
  43. }
  44. [Theory]
  45. [InlineData (typeof (FakeDriver))]
  46. [InlineData (typeof (NetDriver))]
  47. //[InlineData (typeof (ANSIDriver))]
  48. [InlineData (typeof (WindowsDriver))]
  49. [InlineData (typeof (CursesDriver))]
  50. public void Clip_Set_To_Empty_AllInvalid (Type driverType)
  51. {
  52. var driver = (IConsoleDriver)Activator.CreateInstance (driverType);
  53. Application.Init (driver);
  54. // Define a clip rectangle
  55. driver.Clip = new (Rectangle.Empty);
  56. // negative
  57. Assert.False (driver.IsValidLocation (default, 4, 5));
  58. Assert.False (driver.IsValidLocation (default, 5, 4));
  59. Assert.False (driver.IsValidLocation (default, 10, 9));
  60. Assert.False (driver.IsValidLocation (default, 9, 10));
  61. Assert.False (driver.IsValidLocation (default, -1, 0));
  62. Assert.False (driver.IsValidLocation (default, 0, -1));
  63. Assert.False (driver.IsValidLocation (default, -1, -1));
  64. Assert.False (driver.IsValidLocation (default, driver.Cols, driver.Rows - 1));
  65. Assert.False (driver.IsValidLocation (default, driver.Cols, driver.Rows - 1));
  66. Assert.False (driver.IsValidLocation (default, driver.Cols, driver.Rows));
  67. Application.Shutdown ();
  68. }
  69. [Theory]
  70. [InlineData (typeof (FakeDriver))]
  71. [InlineData (typeof (NetDriver))]
  72. //[InlineData (typeof (ANSIDriver))]
  73. [InlineData (typeof (WindowsDriver))]
  74. [InlineData (typeof (CursesDriver))]
  75. public void IsValidLocation (Type driverType)
  76. {
  77. var driver = (IConsoleDriver)Activator.CreateInstance (driverType);
  78. Application.Init (driver);
  79. Application.Driver!.Rows = 10;
  80. Application.Driver!.Cols = 10;
  81. // positive
  82. Assert.True (driver.IsValidLocation (default, 0, 0));
  83. Assert.True (driver.IsValidLocation (default, 1, 1));
  84. Assert.True (driver.IsValidLocation (default, driver.Cols - 1, driver.Rows - 1));
  85. // negative
  86. Assert.False (driver.IsValidLocation (default, -1, 0));
  87. Assert.False (driver.IsValidLocation (default, 0, -1));
  88. Assert.False (driver.IsValidLocation (default, -1, -1));
  89. Assert.False (driver.IsValidLocation (default, driver.Cols, driver.Rows - 1));
  90. Assert.False (driver.IsValidLocation (default, driver.Cols, driver.Rows - 1));
  91. Assert.False (driver.IsValidLocation (default, driver.Cols, driver.Rows));
  92. // Define a clip rectangle
  93. driver.Clip = new(new Rectangle(5, 5, 5, 5));
  94. // positive
  95. Assert.True (driver.IsValidLocation (default, 5, 5));
  96. Assert.True (driver.IsValidLocation (default, 9, 9));
  97. // negative
  98. Assert.False (driver.IsValidLocation (default, 4, 5));
  99. Assert.False (driver.IsValidLocation (default, 5, 4));
  100. Assert.False (driver.IsValidLocation (default, 10, 9));
  101. Assert.False (driver.IsValidLocation (default, 9, 10));
  102. Assert.False (driver.IsValidLocation (default, -1, 0));
  103. Assert.False (driver.IsValidLocation (default, 0, -1));
  104. Assert.False (driver.IsValidLocation (default, -1, -1));
  105. Assert.False (driver.IsValidLocation (default, driver.Cols, driver.Rows - 1));
  106. Assert.False (driver.IsValidLocation (default, driver.Cols, driver.Rows - 1));
  107. Assert.False (driver.IsValidLocation (default, driver.Cols, driver.Rows));
  108. Application.Shutdown ();
  109. }
  110. }