DriverColorTests.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. driver.Init ();
  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. driver.End ();
  30. }
  31. [Theory]
  32. [InlineData (typeof (FakeDriver), false)]
  33. [InlineData (typeof (NetDriver), true)]
  34. [InlineData (typeof (CursesDriver), false)]
  35. [InlineData (typeof (WindowsDriver), true)] // Because we're not Windows Terminal
  36. public void SupportsTrueColor_Defaults (Type driverType, bool expectedSetting)
  37. {
  38. var driver = (ConsoleDriver)Activator.CreateInstance (driverType);
  39. driver.Init ();
  40. Assert.Equal (expectedSetting, driver.SupportsTrueColor);
  41. driver.End ();
  42. }
  43. [Theory]
  44. [InlineData (typeof (FakeDriver))]
  45. [InlineData (typeof (NetDriver))]
  46. [InlineData (typeof (CursesDriver))]
  47. [InlineData (typeof (WindowsDriver))]
  48. public void Force16Colors_Sets (Type driverType)
  49. {
  50. var driver = (ConsoleDriver)Activator.CreateInstance (driverType);
  51. driver.Init ();
  52. driver.Force16Colors = true;
  53. Assert.True (driver.Force16Colors);
  54. driver.End ();
  55. }
  56. }
  57. }