ShadowStyleTests.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. using UnitTests;
  2. using Xunit.Abstractions;
  3. namespace UnitTests.ViewTests;
  4. public class ShadowStyleTests (ITestOutputHelper output)
  5. {
  6. [Theory]
  7. [InlineData (
  8. ShadowStyle.None,
  9. """
  10. 011
  11. 111
  12. 111
  13. """)]
  14. [InlineData (
  15. ShadowStyle.Transparent,
  16. """
  17. 031
  18. 131
  19. 111
  20. """)]
  21. [InlineData (
  22. ShadowStyle.Opaque,
  23. """
  24. 021
  25. 221
  26. 111
  27. """)]
  28. [SetupFakeApplication]
  29. public void ShadowView_Colors (ShadowStyle style, string expectedAttrs)
  30. {
  31. Application.Driver!.SetScreenSize (5, 5);
  32. Color fg = Color.Red;
  33. Color bg = Color.Green;
  34. // 0 - View
  35. // 1 - SuperView
  36. // 2 - Opaque - fg is Black, bg is SuperView.Bg
  37. // 3 - Transparent - fg is darker fg, bg is darker bg
  38. Attribute [] attributes =
  39. {
  40. Attribute.Default,
  41. new (fg, bg),
  42. new (Color.Black, bg),
  43. new (fg.GetDimColor (), bg.GetDimColor ())
  44. };
  45. var superView = new Toplevel
  46. {
  47. Driver = ApplicationImpl.Instance.Driver,
  48. Height = 3,
  49. Width = 3,
  50. Text = "012ABC!@#",
  51. };
  52. superView.SetScheme (new (new Attribute (fg, bg)));
  53. superView.TextFormatter.WordWrap = true;
  54. View view = new ()
  55. {
  56. Width = Dim.Auto (),
  57. Height = Dim.Auto (),
  58. Text = "*",
  59. ShadowStyle = style,
  60. };
  61. view.SetScheme (new (Attribute.Default));
  62. superView.Add (view);
  63. Application.SessionStack.Push (superView);
  64. Application.LayoutAndDraw (true);
  65. DriverAssert.AssertDriverAttributesAre (expectedAttrs, output, Application.Driver, attributes);
  66. Application.ResetState (true);
  67. }
  68. // Visual tests
  69. [Theory]
  70. [InlineData (
  71. ShadowStyle.None,
  72. """
  73. 01#$
  74. AB#$
  75. !@#$
  76. !@#$
  77. """)]
  78. [InlineData (
  79. ShadowStyle.Opaque,
  80. """
  81. 01▖$
  82. AB▌$
  83. ▝▀▘$
  84. !@#$
  85. """)]
  86. [InlineData (
  87. ShadowStyle.Transparent,
  88. """
  89. 01#$
  90. AB#$
  91. !@#$
  92. !@#$
  93. """)]
  94. [SetupFakeApplication]
  95. public void Visual_Test (ShadowStyle style, string expected)
  96. {
  97. Application.Driver!.SetScreenSize (5, 5);
  98. var superView = new Toplevel
  99. {
  100. Driver = ApplicationImpl.Instance.Driver,
  101. Width = 4,
  102. Height = 4,
  103. Text = "!@#$".Repeat (4)!
  104. };
  105. superView.TextFormatter.WordWrap = true;
  106. var view = new View
  107. {
  108. Text = "01\nAB",
  109. Width = Dim.Auto (),
  110. Height = Dim.Auto ()
  111. };
  112. view.ShadowStyle = style;
  113. superView.Add (view);
  114. Application.SessionStack.Push (superView);
  115. Application.LayoutAndDraw (true);
  116. DriverAssert.AssertDriverContentsWithFrameAre (expected, output);
  117. view.Dispose ();
  118. Application.ResetState (true);
  119. }
  120. [Theory]
  121. [InlineData (ShadowStyle.None, 0, 0, 0, 0)]
  122. [InlineData (ShadowStyle.Opaque, 1, 0, 0, 1)]
  123. [InlineData (ShadowStyle.Transparent, 1, 0, 0, 1)]
  124. [AutoInitShutdown]
  125. public void ShadowStyle_Button1Pressed_Causes_Movement (ShadowStyle style, int expectedLeft, int expectedTop, int expectedRight, int expectedBottom)
  126. {
  127. var superView = new View
  128. {
  129. Height = 10, Width = 10,
  130. App = ApplicationImpl.Instance
  131. };
  132. View view = new ()
  133. {
  134. Width = Dim.Auto (),
  135. Height = Dim.Auto (),
  136. Text = "0123",
  137. HighlightStates = MouseState.Pressed,
  138. ShadowStyle = style,
  139. CanFocus = true
  140. };
  141. superView.Add (view);
  142. superView.BeginInit ();
  143. superView.EndInit ();
  144. Thickness origThickness = view.Margin!.Thickness;
  145. view.NewMouseEvent (new () { Flags = MouseFlags.Button1Pressed, Position = new (0, 0) });
  146. Assert.Equal (new (expectedLeft, expectedTop, expectedRight, expectedBottom), view.Margin.Thickness);
  147. view.NewMouseEvent (new () { Flags = MouseFlags.Button1Released, Position = new (0, 0) });
  148. Assert.Equal (origThickness, view.Margin.Thickness);
  149. // Button1Pressed, Button1Released cause Application.Mouse.MouseGrabView to be set
  150. Application.ResetState (true);
  151. }
  152. }