DriverColorTests.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. using System;
  2. using Xunit;
  3. // Alias Console to MockConsole so we don't accidentally use Console
  4. using Console = Terminal.Gui.FakeConsole;
  5. namespace Terminal.Gui.DriverTests {
  6. public class DriverColorTests {
  7. public DriverColorTests ()
  8. {
  9. ConsoleDriver.RunningUnitTests = true;
  10. }
  11. [Theory]
  12. [InlineData (typeof (FakeDriver))]
  13. [InlineData (typeof (NetDriver))]
  14. [InlineData (typeof (CursesDriver))]
  15. [InlineData (typeof (WindowsDriver))]
  16. public void SetColors_Changes_Colors (Type driverType)
  17. {
  18. var driver = (ConsoleDriver)Activator.CreateInstance (driverType);
  19. Application.Init (driver);
  20. Assert.Equal (ConsoleColor.Gray, Console.ForegroundColor);
  21. Assert.Equal (ConsoleColor.Black, Console.BackgroundColor);
  22. Console.ForegroundColor = ConsoleColor.Red;
  23. Assert.Equal (ConsoleColor.Red, Console.ForegroundColor);
  24. Console.BackgroundColor = ConsoleColor.Green;
  25. Assert.Equal (ConsoleColor.Green, Console.BackgroundColor);
  26. Console.ResetColor ();
  27. Assert.Equal (ConsoleColor.Gray, Console.ForegroundColor);
  28. Assert.Equal (ConsoleColor.Black, Console.BackgroundColor);
  29. // Shutdown must be called to safely clean up Application if Init has been called
  30. Application.Shutdown ();
  31. }
  32. [Theory]
  33. [InlineData (typeof (FakeDriver), false)]
  34. [InlineData (typeof (NetDriver), true)]
  35. [InlineData (typeof (CursesDriver), false)]
  36. [InlineData (typeof (WindowsDriver), true)] // Because we're not Windows Terminal
  37. public void SupportsTrueColor_Defaults (Type driverType, bool expectedSetting)
  38. {
  39. var driver = (ConsoleDriver)Activator.CreateInstance (driverType);
  40. driver.Init ();
  41. Assert.Equal (expectedSetting, driver.SupportsTrueColor);
  42. driver.End ();
  43. // Shutdown must be called to safely clean up Application if Init has been called
  44. Application.Shutdown ();
  45. }
  46. [Theory]
  47. [InlineData (typeof (FakeDriver))]
  48. [InlineData (typeof (NetDriver))]
  49. [InlineData (typeof (CursesDriver))]
  50. [InlineData (typeof (WindowsDriver))]
  51. public void Force16Colors_Sets (Type driverType)
  52. {
  53. var driver = (ConsoleDriver)Activator.CreateInstance (driverType);
  54. driver.Init ();
  55. driver.Force16Colors = true;
  56. Assert.True (driver.Force16Colors);
  57. driver.End ();
  58. // Shutdown must be called to safely clean up Application if Init has been called
  59. Application.Shutdown ();
  60. }
  61. }
  62. }