ClipRegionTests.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. driver.Init ();
  23. driver.SetScreenSize (80, 25);
  24. Application.Init (driver);
  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 (DotNetDriver))]
  47. //[InlineData (typeof (ANSIDriver))]
  48. //[InlineData (typeof (WindowsDriver))]
  49. //[InlineData (typeof (UnixDriver))]
  50. public void Clip_Set_To_Empty_AllInvalid (Type driverType)
  51. {
  52. var driver = (IConsoleDriver)Activator.CreateInstance (driverType);
  53. driver.Init ();
  54. Application.Init (driver);
  55. // Define a clip rectangle
  56. driver.Clip = new (Rectangle.Empty);
  57. // negative
  58. Assert.False (driver.IsValidLocation (default, 4, 5));
  59. Assert.False (driver.IsValidLocation (default, 5, 4));
  60. Assert.False (driver.IsValidLocation (default, 10, 9));
  61. Assert.False (driver.IsValidLocation (default, 9, 10));
  62. Assert.False (driver.IsValidLocation (default, -1, 0));
  63. Assert.False (driver.IsValidLocation (default, 0, -1));
  64. Assert.False (driver.IsValidLocation (default, -1, -1));
  65. Assert.False (driver.IsValidLocation (default, driver.Cols, driver.Rows - 1));
  66. Assert.False (driver.IsValidLocation (default, driver.Cols, driver.Rows - 1));
  67. Assert.False (driver.IsValidLocation (default, driver.Cols, driver.Rows));
  68. Application.Shutdown ();
  69. }
  70. [Theory]
  71. [InlineData (typeof (FakeDriver))]
  72. //[InlineData (typeof (DotNetDriver))]
  73. //[InlineData (typeof (ANSIDriver))]
  74. //[InlineData (typeof (WindowsDriver))]
  75. //[InlineData (typeof (UnixDriver))]
  76. public void IsValidLocation (Type driverType)
  77. {
  78. var driver = (IConsoleDriver)Activator.CreateInstance (driverType);
  79. driver.Init ();
  80. driver.SetScreenSize (10, 10);
  81. Application.Init (driver);
  82. // positive
  83. Assert.True (driver.IsValidLocation (default, 0, 0));
  84. Assert.True (driver.IsValidLocation (default, 1, 1));
  85. Assert.True (driver.IsValidLocation (default, driver.Cols - 1, driver.Rows - 1));
  86. // negative
  87. Assert.False (driver.IsValidLocation (default, -1, 0));
  88. Assert.False (driver.IsValidLocation (default, 0, -1));
  89. Assert.False (driver.IsValidLocation (default, -1, -1));
  90. Assert.False (driver.IsValidLocation (default, driver.Cols, driver.Rows - 1));
  91. Assert.False (driver.IsValidLocation (default, driver.Cols, driver.Rows - 1));
  92. Assert.False (driver.IsValidLocation (default, driver.Cols, driver.Rows));
  93. // Define a clip rectangle
  94. driver.Clip = new(new Rectangle(5, 5, 5, 5));
  95. // positive
  96. Assert.True (driver.IsValidLocation (default, 5, 5));
  97. Assert.True (driver.IsValidLocation (default, 9, 9));
  98. // negative
  99. Assert.False (driver.IsValidLocation (default, 4, 5));
  100. Assert.False (driver.IsValidLocation (default, 5, 4));
  101. Assert.False (driver.IsValidLocation (default, 10, 9));
  102. Assert.False (driver.IsValidLocation (default, 9, 10));
  103. Assert.False (driver.IsValidLocation (default, -1, 0));
  104. Assert.False (driver.IsValidLocation (default, 0, -1));
  105. Assert.False (driver.IsValidLocation (default, -1, -1));
  106. Assert.False (driver.IsValidLocation (default, driver.Cols, driver.Rows - 1));
  107. Assert.False (driver.IsValidLocation (default, driver.Cols, driver.Rows - 1));
  108. Assert.False (driver.IsValidLocation (default, driver.Cols, driver.Rows));
  109. Application.Shutdown ();
  110. }
  111. }