ClipRegionTests.cs 5.1 KB

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