TransparentTests.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #nullable enable
  2. using UnitTests;
  3. using Xunit.Abstractions;
  4. namespace UnitTests.ViewBaseTests;
  5. [Trait ("Category", "Output")]
  6. public class TransparentTests (ITestOutputHelper output)
  7. {
  8. [Fact]
  9. [SetupFakeApplication]
  10. public void Transparent_Text_Occludes ()
  11. {
  12. var super = new View
  13. {
  14. App = ApplicationImpl.Instance,
  15. Id = "super",
  16. Width = 20,
  17. Height = 5,
  18. };
  19. super.DrawingContent += (sender, args) =>
  20. {
  21. var s = sender as View;
  22. s!.FillRect(s!.Viewport, Glyphs.Stipple);
  23. args.Cancel = true;
  24. };
  25. var sub = new View
  26. {
  27. X = 1,
  28. Y = 1,
  29. Width = 15,
  30. Height = 3,
  31. Id = "sub",
  32. Text = "Sub",
  33. ViewportSettings = ViewportSettingsFlags.Transparent,
  34. BorderStyle = LineStyle.Single
  35. };
  36. super.Add (sub);
  37. super.Layout ();
  38. super.Draw ();
  39. _ = DriverAssert.AssertDriverContentsWithFrameAre (
  40. @"
  41. ░░░░░░░░░░░░░░░░░░░░
  42. ░┌─────────────┐░░░░
  43. ░│Sub░░░░░░░░░░│░░░░
  44. ░└─────────────┘░░░░
  45. ░░░░░░░░░░░░░░░░░░░░", output);
  46. }
  47. [Fact]
  48. [SetupFakeApplication]
  49. public void Transparent_SubView_Occludes ()
  50. {
  51. var super = new View
  52. {
  53. App = ApplicationImpl.Instance,
  54. Id = "super",
  55. Width = 20,
  56. Height = 5,
  57. };
  58. super.DrawingContent += (sender, args) =>
  59. {
  60. var s = sender as View;
  61. s!.FillRect (s!.Viewport, Glyphs.Stipple);
  62. args.Cancel = true;
  63. };
  64. var sub = new View
  65. {
  66. X = 1,
  67. Y = 1,
  68. Width = 15,
  69. Height = 3,
  70. Id = "sub",
  71. ViewportSettings = ViewportSettingsFlags.Transparent,
  72. BorderStyle = LineStyle.Single
  73. };
  74. var subSub = new View
  75. {
  76. X = Pos.Center(),
  77. Y = Pos.Center(),
  78. Width = Dim.Auto(),
  79. Height = Dim.Auto(),
  80. Id = "subSub",
  81. Text = "subSub",
  82. };
  83. sub.Add (subSub);
  84. super.Add (sub);
  85. super.Layout ();
  86. super.Draw ();
  87. _ = DriverAssert.AssertDriverContentsWithFrameAre (
  88. @"
  89. ░░░░░░░░░░░░░░░░░░░░
  90. ░┌─────────────┐░░░░
  91. ░│░░░subSub░░░░│░░░░
  92. ░└─────────────┘░░░░
  93. ░░░░░░░░░░░░░░░░░░░░", output);
  94. }
  95. }