ShadowStyleTests.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. using UnitTests;
  2. using Xunit.Abstractions;
  3. namespace UnitTests.ViewBaseTests;
  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 Runnable
  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.Begin (superView);
  64. Application.LayoutAndDraw (true);
  65. DriverAssert.AssertDriverAttributesAre (expectedAttrs, output, Application.Driver, attributes);
  66. superView.Dispose ();
  67. Application.ResetState (true);
  68. }
  69. // Visual tests
  70. [Theory]
  71. [InlineData (
  72. ShadowStyle.None,
  73. """
  74. 01#$
  75. AB#$
  76. !@#$
  77. !@#$
  78. """)]
  79. [InlineData (
  80. ShadowStyle.Opaque,
  81. """
  82. 01▖$
  83. AB▌$
  84. ▝▀▘$
  85. !@#$
  86. """)]
  87. [InlineData (
  88. ShadowStyle.Transparent,
  89. """
  90. 01#$
  91. AB#$
  92. !@#$
  93. !@#$
  94. """)]
  95. [SetupFakeApplication]
  96. public void Visual_Test (ShadowStyle style, string expected)
  97. {
  98. Application.Driver!.SetScreenSize (5, 5);
  99. var superView = new Runnable
  100. {
  101. Driver = ApplicationImpl.Instance.Driver,
  102. Width = 4,
  103. Height = 4,
  104. Text = "!@#$".Repeat (4)!
  105. };
  106. superView.TextFormatter.WordWrap = true;
  107. var view = new View
  108. {
  109. Text = "01\nAB",
  110. Width = Dim.Auto (),
  111. Height = Dim.Auto ()
  112. };
  113. view.ShadowStyle = style;
  114. superView.Add (view);
  115. Application.Begin (superView);
  116. Application.LayoutAndDraw (true);
  117. DriverAssert.AssertDriverContentsWithFrameAre (expected, output);
  118. superView.Dispose ();
  119. Application.ResetState (true);
  120. }
  121. [Theory]
  122. [InlineData (ShadowStyle.None, 0, 0, 0, 0)]
  123. [InlineData (ShadowStyle.Opaque, 1, 0, 0, 1)]
  124. [InlineData (ShadowStyle.Transparent, 1, 0, 0, 1)]
  125. [AutoInitShutdown]
  126. public void ShadowStyle_Button1Pressed_Causes_Movement (ShadowStyle style, int expectedLeft, int expectedTop, int expectedRight, int expectedBottom)
  127. {
  128. var superView = new View
  129. {
  130. Height = 10, Width = 10,
  131. App = ApplicationImpl.Instance
  132. };
  133. View view = new ()
  134. {
  135. Width = Dim.Auto (),
  136. Height = Dim.Auto (),
  137. Text = "0123",
  138. HighlightStates = MouseState.Pressed,
  139. ShadowStyle = style,
  140. CanFocus = true
  141. };
  142. superView.Add (view);
  143. superView.BeginInit ();
  144. superView.EndInit ();
  145. Thickness origThickness = view.Margin!.Thickness;
  146. view.NewMouseEvent (new () { Flags = MouseFlags.Button1Pressed, Position = new (0, 0) });
  147. Assert.Equal (new (expectedLeft, expectedTop, expectedRight, expectedBottom), view.Margin.Thickness);
  148. view.NewMouseEvent (new () { Flags = MouseFlags.Button1Released, Position = new (0, 0) });
  149. Assert.Equal (origThickness, view.Margin.Thickness);
  150. // Button1Pressed, Button1Released cause Application.Mouse.MouseGrabView to be set
  151. Application.ResetState (true);
  152. }
  153. }