FrameTests.cs 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. using NStack;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Xml.Linq;
  5. using Xunit;
  6. using Xunit.Abstractions;
  7. //using GraphViewTests = Terminal.Gui.Views.GraphViewTests;
  8. // Alias Console to MockConsole so we don't accidentally use Console
  9. using Console = Terminal.Gui.FakeConsole;
  10. namespace Terminal.Gui.ViewTests {
  11. public class FrameTests {
  12. readonly ITestOutputHelper output;
  13. public FrameTests (ITestOutputHelper output)
  14. {
  15. this.output = output;
  16. }
  17. [Fact]
  18. public void GetFramesThickness ()
  19. {
  20. var view = new View ();
  21. Assert.Equal (Thickness.Empty, view.GetFramesThickness ());
  22. view.Margin.Thickness = new Thickness (1);
  23. Assert.Equal (new Thickness (1), view.GetFramesThickness ());
  24. view.Border.Thickness = new Thickness (1);
  25. Assert.Equal (new Thickness (2), view.GetFramesThickness ());
  26. view.Padding.Thickness = new Thickness (1);
  27. Assert.Equal (new Thickness (3), view.GetFramesThickness ());
  28. view.Padding.Thickness = new Thickness (2);
  29. Assert.Equal (new Thickness (4), view.GetFramesThickness ());
  30. view.Padding.Thickness = new Thickness (1, 2, 3, 4);
  31. Assert.Equal (new Thickness (3, 4, 5, 6), view.GetFramesThickness ());
  32. view.Margin.Thickness = new Thickness (1, 2, 3, 4);
  33. Assert.Equal (new Thickness (3, 5, 7, 9), view.GetFramesThickness ());
  34. }
  35. [Theory, AutoInitShutdown]
  36. [InlineData (0)]
  37. [InlineData (1)]
  38. [InlineData (2)]
  39. [InlineData (3)]
  40. public void Border_With_Title_Size_Height (int height)
  41. {
  42. var win = new Window () {
  43. Title = "1234",
  44. Width = Dim.Fill (),
  45. Height = Dim.Fill ()
  46. };
  47. var rs = Application.Begin (win);
  48. bool firstIteration = false;
  49. ((FakeDriver)Application.Driver).SetBufferSize (20, height);
  50. Application.RunMainLoopIteration (ref rs, true, ref firstIteration);
  51. var expected = string.Empty;
  52. switch (height) {
  53. case 0:
  54. //Assert.Equal (new Rect (0, 0, 17, 0), subview.Frame);
  55. expected = @"
  56. ";
  57. break;
  58. case 1:
  59. //Assert.Equal (new Rect (0, 0, 17, 0), subview.Frame);
  60. expected = @"
  61. ────────────────────";
  62. break;
  63. case 2:
  64. //Assert.Equal (new Rect (0, 0, 17, 1), subview.Frame);
  65. expected = @"
  66. ┌┤1234├────────────┐
  67. └──────────────────┘
  68. ";
  69. break;
  70. case 3:
  71. //Assert.Equal (new Rect (0, 0, 17, 2), subview.Frame);
  72. expected = @"
  73. ┌┤1234├────────────┐
  74. │ │
  75. └──────────────────┘
  76. ";
  77. break;
  78. }
  79. _ = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  80. }
  81. [Theory, AutoInitShutdown]
  82. [InlineData (0)]
  83. [InlineData (1)]
  84. [InlineData (2)]
  85. [InlineData (3)]
  86. [InlineData (4)]
  87. [InlineData (5)]
  88. [InlineData (6)]
  89. [InlineData (7)]
  90. [InlineData (8)]
  91. [InlineData (9)]
  92. [InlineData (10)]
  93. public void Border_With_Title_Size_Width (int width)
  94. {
  95. var win = new Window () {
  96. Title = "1234",
  97. Width = Dim.Fill (),
  98. Height = Dim.Fill ()
  99. };
  100. var rs = Application.Begin (win);
  101. bool firstIteration = false;
  102. ((FakeDriver)Application.Driver).SetBufferSize (width, 3);
  103. Application.RunMainLoopIteration (ref rs, true, ref firstIteration);
  104. var expected = string.Empty;
  105. switch (width) {
  106. case 1:
  107. //Assert.Equal (new Rect (0, 0, 17, 0), subview.Frame);
  108. expected = @"
  109. │";
  110. break;
  111. case 2:
  112. //Assert.Equal (new Rect (0, 0, 17, 1), subview.Frame);
  113. expected = @"
  114. ┌┐
  115. ││
  116. └┘";
  117. break;
  118. case 3:
  119. //Assert.Equal (new Rect (0, 0, 17, 2), subview.Frame);
  120. expected = @"
  121. ┌─┐
  122. │ │
  123. └─┘
  124. ";
  125. break;
  126. case 4:
  127. //Assert.Equal (new Rect (0, 0, 17, 3), subview.Frame);
  128. expected = @"
  129. ┌┤├┐
  130. │ │
  131. └──┘";
  132. break;
  133. case 5:
  134. //Assert.Equal (new Rect (0, 0, 17, 3), subview.Frame);
  135. expected = @"
  136. ┌┤1├┐
  137. │ │
  138. └───┘";
  139. break;
  140. case 6:
  141. //Assert.Equal (new Rect (0, 0, 17, 3), subview.Frame);
  142. expected = @"
  143. ┌┤12├┐
  144. │ │
  145. └────┘";
  146. break;
  147. case 7:
  148. //Assert.Equal (new Rect (0, 0, 17, 3), subview.Frame);
  149. expected = @"
  150. ┌┤123├┐
  151. │ │
  152. └─────┘";
  153. break;
  154. case 8:
  155. //Assert.Equal (new Rect (0, 0, 17, 3), subview.Frame);
  156. expected = @"
  157. ┌┤1234├┐
  158. │ │
  159. └──────┘";
  160. break;
  161. case 9:
  162. //Assert.Equal (new Rect (0, 0, 17, 3), subview.Frame);
  163. expected = @"
  164. ┌┤1234├─┐
  165. │ │
  166. └───────┘";
  167. break;
  168. case 10:
  169. //Assert.Equal (new Rect (0, 0, 17, 3), subview.Frame);
  170. expected = @"
  171. ┌┤1234├──┐
  172. │ │
  173. └────────┘";
  174. break;
  175. }
  176. _ = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  177. }
  178. [Fact, AutoInitShutdown]
  179. public void NoSuperView ()
  180. {
  181. var win = new Window () {
  182. Width = Dim.Fill (),
  183. Height = Dim.Fill ()
  184. };
  185. var rs = Application.Begin (win);
  186. bool firstIteration = false;
  187. ((FakeDriver)Application.Driver).SetBufferSize (3, 3);
  188. Application.RunMainLoopIteration (ref rs, true, ref firstIteration);
  189. var expected = @"
  190. ┌─┐
  191. │ │
  192. └─┘";
  193. _ = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  194. }
  195. [Fact, AutoInitShutdown]
  196. public void HasSuperView ()
  197. {
  198. Application.Top.BorderStyle = LineStyle.Double;
  199. var frame = new FrameView () {
  200. Width = Dim.Fill (),
  201. Height = Dim.Fill ()
  202. };
  203. Application.Top.Add (frame);
  204. var rs = Application.Begin (Application.Top);
  205. bool firstIteration = false;
  206. ((FakeDriver)Application.Driver).SetBufferSize (5, 5);
  207. Application.RunMainLoopIteration (ref rs, true, ref firstIteration);
  208. var expected = @"
  209. ╔═══╗
  210. ║┌─┐║
  211. ║│ │║
  212. ║└─┘║
  213. ╚═══╝";
  214. _ = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  215. }
  216. [Fact, AutoInitShutdown]
  217. public void HasSuperView_Title ()
  218. {
  219. Application.Top.BorderStyle = LineStyle.Double;
  220. var frame = new FrameView () {
  221. Title = "1234",
  222. Width = Dim.Fill (),
  223. Height = Dim.Fill ()
  224. };
  225. Application.Top.Add (frame);
  226. var rs = Application.Begin (Application.Top);
  227. bool firstIteration = false;
  228. ((FakeDriver)Application.Driver).SetBufferSize (10, 4);
  229. Application.RunMainLoopIteration (ref rs, true, ref firstIteration);
  230. var expected = @"
  231. ╔════════╗
  232. ║┌┤1234├┐║
  233. ║└──────┘║
  234. ╚════════╝";
  235. _ = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  236. }
  237. }
  238. }