DriverTests.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #nullable enable
  2. using UnitTests;
  3. using Xunit.Abstractions;
  4. namespace DriverTests;
  5. public class DriverTests (ITestOutputHelper output) : FakeDriverBase
  6. {
  7. [Theory]
  8. [InlineData ("", true)]
  9. [InlineData ("a", true)]
  10. [InlineData ("👩‍❤️‍💋‍👨", false)]
  11. public void IsValidLocation (string text, bool positive)
  12. {
  13. IDriver driver = CreateFakeDriver ();
  14. driver.SetScreenSize (10, 10);
  15. // positive
  16. Assert.True (driver.IsValidLocation (text, 0, 0));
  17. Assert.True (driver.IsValidLocation (text, 1, 1));
  18. Assert.Equal (positive, driver.IsValidLocation (text, driver.Cols - 1, driver.Rows - 1));
  19. // negative
  20. Assert.False (driver.IsValidLocation (text, -1, 0));
  21. Assert.False (driver.IsValidLocation (text, 0, -1));
  22. Assert.False (driver.IsValidLocation (text, -1, -1));
  23. Assert.False (driver.IsValidLocation (text, driver.Cols, driver.Rows - 1));
  24. Assert.False (driver.IsValidLocation (text, driver.Cols, driver.Rows - 1));
  25. Assert.False (driver.IsValidLocation (text, driver.Cols, driver.Rows));
  26. // Define a clip rectangle
  27. driver.Clip = new (new Rectangle (5, 5, 5, 5));
  28. // positive
  29. Assert.True (driver.IsValidLocation (text, 5, 5));
  30. Assert.Equal (positive, driver.IsValidLocation (text, 9, 9));
  31. // negative
  32. Assert.False (driver.IsValidLocation (text, 4, 5));
  33. Assert.False (driver.IsValidLocation (text, 5, 4));
  34. Assert.False (driver.IsValidLocation (text, 10, 9));
  35. Assert.False (driver.IsValidLocation (text, 9, 10));
  36. Assert.False (driver.IsValidLocation (text, -1, 0));
  37. Assert.False (driver.IsValidLocation (text, 0, -1));
  38. Assert.False (driver.IsValidLocation (text, -1, -1));
  39. Assert.False (driver.IsValidLocation (text, driver.Cols, driver.Rows - 1));
  40. Assert.False (driver.IsValidLocation (text, driver.Cols, driver.Rows - 1));
  41. Assert.False (driver.IsValidLocation (text, driver.Cols, driver.Rows));
  42. driver.Dispose ();
  43. }
  44. [Theory]
  45. [InlineData ("fake")]
  46. [InlineData ("windows")]
  47. [InlineData ("dotnet")]
  48. [InlineData ("unix")]
  49. public void All_Drivers_Init_Dispose_Cross_Platform (string driverName)
  50. {
  51. IApplication? app = Application.Create ();
  52. app.Init (driverName);
  53. app.Dispose ();
  54. }
  55. [Theory]
  56. [InlineData ("fake")]
  57. [InlineData ("windows")]
  58. [InlineData ("dotnet")]
  59. [InlineData ("unix")]
  60. public void All_Drivers_Run_Cross_Platform (string driverName)
  61. {
  62. IApplication? app = Application.Create ();
  63. app.Init (driverName);
  64. app.StopAfterFirstIteration = true;
  65. app.Run<Runnable<bool>> ();
  66. app.Dispose ();
  67. }
  68. [Theory]
  69. [InlineData ("fake")]
  70. [InlineData ("windows")]
  71. [InlineData ("dotnet")]
  72. [InlineData ("unix")]
  73. public void All_Drivers_LayoutAndDraw_Cross_Platform (string driverName)
  74. {
  75. IApplication? app = Application.Create ();
  76. app.Init (driverName);
  77. app.StopAfterFirstIteration = true;
  78. app.Run<TestTop> ();
  79. DriverAssert.AssertDriverContentsWithFrameAre (driverName!, output, app.Driver);
  80. app.Dispose ();
  81. }
  82. }
  83. public class TestTop : Runnable
  84. {
  85. /// <inheritdoc/>
  86. public override void BeginInit ()
  87. {
  88. Text = Driver!.GetName ()!;
  89. BorderStyle = LineStyle.None;
  90. base.BeginInit ();
  91. }
  92. }