ColorTests.cs 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 ColorTests {
  7. [Theory]
  8. [InlineData (typeof (FakeDriver))]
  9. //[InlineData (typeof (NetDriver))]
  10. //[InlineData (typeof (CursesDriver))]
  11. //[InlineData (typeof (WindowsDriver))]
  12. public void SetColors_Changes_Colors (Type driverType)
  13. {
  14. var driver = (ConsoleDriver)Activator.CreateInstance (driverType);
  15. Application.Init (driver);
  16. driver.Init (() => { });
  17. Assert.Equal (ConsoleColor.Gray, Console.ForegroundColor);
  18. Assert.Equal (ConsoleColor.Black, Console.BackgroundColor);
  19. Console.ForegroundColor = ConsoleColor.Red;
  20. Assert.Equal (ConsoleColor.Red, Console.ForegroundColor);
  21. Console.BackgroundColor = ConsoleColor.Green;
  22. Assert.Equal (ConsoleColor.Green, Console.BackgroundColor);
  23. Console.ResetColor ();
  24. Assert.Equal (ConsoleColor.Gray, Console.ForegroundColor);
  25. Assert.Equal (ConsoleColor.Black, Console.BackgroundColor);
  26. driver.End ();
  27. // Shutdown must be called to safely clean up Application if Init has been called
  28. Application.Shutdown ();
  29. }
  30. [Fact, AutoInitShutdown]
  31. public void ColorScheme_New ()
  32. {
  33. var scheme = new ColorScheme ();
  34. var lbl = new Label ();
  35. lbl.ColorScheme = scheme;
  36. lbl.Redraw (lbl.Bounds);
  37. }
  38. [Fact]
  39. public void TestAllColors ()
  40. {
  41. var colors = System.Enum.GetValues (typeof (Color));
  42. Attribute [] attrs = new Attribute [colors.Length];
  43. int idx = 0;
  44. foreach (Color bg in colors) {
  45. attrs [idx] = new Attribute (bg, colors.Length - 1 - bg);
  46. idx++;
  47. }
  48. Assert.Equal (16, attrs.Length);
  49. Assert.Equal (new Attribute (Color.Black, Color.White), attrs [0]);
  50. Assert.Equal (new Attribute (Color.Blue, Color.BrightYellow), attrs [1]);
  51. Assert.Equal (new Attribute (Color.Green, Color.BrightMagenta), attrs [2]);
  52. Assert.Equal (new Attribute (Color.Cyan, Color.BrightRed), attrs [3]);
  53. Assert.Equal (new Attribute (Color.Red, Color.BrightCyan), attrs [4]);
  54. Assert.Equal (new Attribute (Color.Magenta, Color.BrightGreen), attrs [5]);
  55. Assert.Equal (new Attribute (Color.Brown, Color.BrightBlue), attrs [6]);
  56. Assert.Equal (new Attribute (Color.Gray, Color.DarkGray), attrs [7]);
  57. Assert.Equal (new Attribute (Color.DarkGray, Color.Gray), attrs [8]);
  58. Assert.Equal (new Attribute (Color.BrightBlue, Color.Brown), attrs [9]);
  59. Assert.Equal (new Attribute (Color.BrightGreen, Color.Magenta), attrs [10]);
  60. Assert.Equal (new Attribute (Color.BrightCyan, Color.Red), attrs [11]);
  61. Assert.Equal (new Attribute (Color.BrightRed, Color.Cyan), attrs [12]);
  62. Assert.Equal (new Attribute (Color.BrightMagenta, Color.Green), attrs [13]);
  63. Assert.Equal (new Attribute (Color.BrightYellow, Color.Blue), attrs [14]);
  64. Assert.Equal (new Attribute (Color.White, Color.Black), attrs [^1]);
  65. }
  66. }
  67. }