LayoutTests.cs 58 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964
  1. using System;
  2. using System.Text;
  3. using Xunit;
  4. using Xunit.Abstractions;
  5. // Alias Console to MockConsole so we don't accidentally use Console
  6. using Console = Terminal.Gui.FakeConsole;
  7. namespace Terminal.Gui.ViewTests {
  8. public class LayoutTests {
  9. readonly ITestOutputHelper output;
  10. public LayoutTests (ITestOutputHelper output)
  11. {
  12. this.output = output;
  13. }
  14. [Fact]
  15. public void TopologicalSort_Missing_Add ()
  16. {
  17. var root = new View ();
  18. var sub1 = new View ();
  19. root.Add (sub1);
  20. var sub2 = new View ();
  21. sub1.Width = Dim.Width (sub2);
  22. Assert.Throws<InvalidOperationException> (() => root.LayoutSubviews ());
  23. sub2.Width = Dim.Width (sub1);
  24. Assert.Throws<InvalidOperationException> (() => root.LayoutSubviews ());
  25. root.Dispose ();
  26. sub1.Dispose ();
  27. sub2.Dispose ();
  28. }
  29. [Fact]
  30. public void TopologicalSort_Recursive_Ref ()
  31. {
  32. var root = new View ();
  33. var sub1 = new View ();
  34. root.Add (sub1);
  35. var sub2 = new View ();
  36. root.Add (sub2);
  37. sub2.Width = Dim.Width (sub2);
  38. var exception = Record.Exception (root.LayoutSubviews);
  39. Assert.Null (exception);
  40. root.Dispose ();
  41. sub1.Dispose ();
  42. sub2.Dispose ();
  43. }
  44. [Fact]
  45. public void LayoutSubviews_No_SuperView ()
  46. {
  47. var root = new View ();
  48. var first = new View () { Id = "first", X = 1, Y = 2, Height = 3, Width = 4 };
  49. root.Add (first);
  50. var second = new View () { Id = "second" };
  51. root.Add (second);
  52. second.X = Pos.Right (first) + 1;
  53. root.LayoutSubviews ();
  54. Assert.Equal (6, second.Frame.X);
  55. root.Dispose ();
  56. first.Dispose ();
  57. second.Dispose ();
  58. }
  59. [Fact]
  60. public void LayoutSubviews_RootHas_SuperView ()
  61. {
  62. var top = new View ();
  63. var root = new View ();
  64. top.Add (root);
  65. var first = new View () { Id = "first", X = 1, Y = 2, Height = 3, Width = 4 };
  66. root.Add (first);
  67. var second = new View () { Id = "second" };
  68. root.Add (second);
  69. second.X = Pos.Right (first) + 1;
  70. root.LayoutSubviews ();
  71. Assert.Equal (6, second.Frame.X);
  72. root.Dispose ();
  73. top.Dispose ();
  74. first.Dispose ();
  75. second.Dispose ();
  76. }
  77. [Fact]
  78. public void LayoutSubviews_ViewThatRefsSubView_Throws ()
  79. {
  80. var root = new View ();
  81. var super = new View ();
  82. root.Add (super);
  83. var sub = new View ();
  84. super.Add (sub);
  85. super.Width = Dim.Width (sub);
  86. Assert.Throws<InvalidOperationException> (() => root.LayoutSubviews ());
  87. root.Dispose ();
  88. super.Dispose ();
  89. }
  90. [Fact, AutoInitShutdown]
  91. public void TrySetWidth_ForceValidatePosDim ()
  92. {
  93. var top = new View () {
  94. X = 0,
  95. Y = 0,
  96. Width = 80,
  97. };
  98. var v = new View () {
  99. Width = Dim.Fill (),
  100. ForceValidatePosDim = true
  101. };
  102. top.Add (v);
  103. Assert.False (v.TrySetWidth (70, out int rWidth));
  104. Assert.Equal (70, rWidth);
  105. v.Width = Dim.Fill (1);
  106. Assert.False (v.TrySetWidth (70, out rWidth));
  107. Assert.Equal (69, rWidth);
  108. v.Width = null;
  109. Assert.True (v.TrySetWidth (70, out rWidth));
  110. Assert.Equal (70, rWidth);
  111. Assert.False (v.IsInitialized);
  112. Application.Top.Add (top);
  113. Application.Begin (Application.Top);
  114. Assert.True (v.IsInitialized);
  115. v.Width = Dim.Fill (1);
  116. Assert.Throws<ArgumentException> (() => v.Width = 75);
  117. v.LayoutStyle = LayoutStyle.Absolute;
  118. v.Width = 75;
  119. Assert.True (v.TrySetWidth (60, out rWidth));
  120. Assert.Equal (60, rWidth);
  121. }
  122. [Fact, AutoInitShutdown]
  123. public void TrySetHeight_ForceValidatePosDim ()
  124. {
  125. var top = new View () {
  126. X = 0,
  127. Y = 0,
  128. Height = 20
  129. };
  130. var v = new View () {
  131. Height = Dim.Fill (),
  132. ForceValidatePosDim = true
  133. };
  134. top.Add (v);
  135. Assert.False (v.TrySetHeight (10, out int rHeight));
  136. Assert.Equal (10, rHeight);
  137. v.Height = Dim.Fill (1);
  138. Assert.False (v.TrySetHeight (10, out rHeight));
  139. Assert.Equal (9, rHeight);
  140. v.Height = null;
  141. Assert.True (v.TrySetHeight (10, out rHeight));
  142. Assert.Equal (10, rHeight);
  143. Assert.False (v.IsInitialized);
  144. Application.Top.Add (top);
  145. Application.Begin (Application.Top);
  146. Assert.True (v.IsInitialized);
  147. v.Height = Dim.Fill (1);
  148. Assert.Throws<ArgumentException> (() => v.Height = 15);
  149. v.LayoutStyle = LayoutStyle.Absolute;
  150. v.Height = 15;
  151. Assert.True (v.TrySetHeight (5, out rHeight));
  152. Assert.Equal (5, rHeight);
  153. }
  154. [Fact, TestRespondersDisposed]
  155. public void GetCurrentWidth_TrySetWidth ()
  156. {
  157. var top = new View () {
  158. X = 0,
  159. Y = 0,
  160. Width = 80,
  161. };
  162. var v = new View () {
  163. Width = Dim.Fill ()
  164. };
  165. top.Add (v);
  166. top.BeginInit ();
  167. top.EndInit ();
  168. top.LayoutSubviews ();
  169. Assert.False (v.AutoSize);
  170. Assert.True (v.TrySetWidth (0, out _));
  171. Assert.Equal (80, v.Frame.Width);
  172. v.Width = Dim.Fill (1);
  173. top.LayoutSubviews ();
  174. Assert.True (v.TrySetWidth (0, out _));
  175. Assert.Equal (79, v.Frame.Width);
  176. v.AutoSize = true;
  177. top.LayoutSubviews ();
  178. Assert.True (v.TrySetWidth (0, out _));
  179. top.Dispose ();
  180. }
  181. [Fact]
  182. public void GetCurrentHeight_TrySetHeight ()
  183. {
  184. var top = new View () {
  185. X = 0,
  186. Y = 0,
  187. Height = 20
  188. };
  189. var v = new View () {
  190. Height = Dim.Fill ()
  191. };
  192. top.Add (v);
  193. top.BeginInit ();
  194. top.EndInit ();
  195. top.LayoutSubviews ();
  196. Assert.False (v.AutoSize);
  197. Assert.True (v.TrySetHeight (0, out _));
  198. Assert.Equal (20, v.Frame.Height);
  199. v.Height = Dim.Fill (1);
  200. top.LayoutSubviews ();
  201. Assert.True (v.TrySetHeight (0, out _));
  202. Assert.Equal (19, v.Frame.Height);
  203. v.AutoSize = true;
  204. top.LayoutSubviews ();
  205. Assert.True (v.TrySetHeight (0, out _));
  206. top.Dispose ();
  207. }
  208. [Fact]
  209. public void AutoSize_False_If_Text_Emmpty ()
  210. {
  211. var view1 = new View ();
  212. var view2 = new View ("");
  213. var view3 = new View () { Text = "" };
  214. Assert.False (view1.AutoSize);
  215. Assert.False (view2.AutoSize);
  216. Assert.False (view3.AutoSize);
  217. view1.Dispose ();
  218. view2.Dispose ();
  219. view3.Dispose ();
  220. }
  221. [Fact]
  222. public void AutoSize_False_If_Text_Is_Not_Emmpty ()
  223. {
  224. var view1 = new View ();
  225. view1.Text = "Hello World";
  226. var view2 = new View ("Hello World");
  227. var view3 = new View () { Text = "Hello World" };
  228. Assert.False (view1.AutoSize);
  229. Assert.False (view2.AutoSize);
  230. Assert.False (view3.AutoSize);
  231. view1.Dispose ();
  232. view2.Dispose ();
  233. view3.Dispose ();
  234. }
  235. [Fact]
  236. public void AutoSize_True_Label_If_Text_Emmpty ()
  237. {
  238. var label1 = new Label ();
  239. var label2 = new Label ("");
  240. var label3 = new Label () { Text = "" };
  241. Assert.True (label1.AutoSize);
  242. Assert.True (label2.AutoSize);
  243. Assert.True (label3.AutoSize);
  244. label1.Dispose ();
  245. label2.Dispose ();
  246. label3.Dispose ();
  247. }
  248. [Fact]
  249. public void AutoSize_True_Label_If_Text_Is_Not_Emmpty ()
  250. {
  251. var label1 = new Label ();
  252. label1.Text = "Hello World";
  253. var label2 = new Label ("Hello World");
  254. var label3 = new Label () { Text = "Hello World" };
  255. Assert.True (label1.AutoSize);
  256. Assert.True (label2.AutoSize);
  257. Assert.True (label3.AutoSize);
  258. label1.Dispose ();
  259. label2.Dispose ();
  260. label3.Dispose ();
  261. }
  262. [Fact]
  263. public void AutoSize_False_ResizeView_Is_Always_False ()
  264. {
  265. var super = new View ();
  266. var label = new Label () { AutoSize = false };
  267. super.Add (label);
  268. label.Text = "New text";
  269. super.LayoutSubviews ();
  270. Assert.False (label.AutoSize);
  271. Assert.Equal ("(0,0,0,1)", label.Bounds.ToString ());
  272. super.Dispose ();
  273. }
  274. [Fact]
  275. public void AutoSize_True_ResizeView_With_Dim_Absolute ()
  276. {
  277. var super = new View ();
  278. var label = new Label ();
  279. label.Text = "New text";
  280. // BUGBUG: v2 - label was never added to super, so it was never laid out.
  281. super.Add (label);
  282. super.LayoutSubviews ();
  283. Assert.True (label.AutoSize);
  284. Assert.Equal ("(0,0,8,1)", label.Bounds.ToString ());
  285. super.Dispose ();
  286. }
  287. [Fact, AutoInitShutdown]
  288. public void AutoSize_False_ResizeView_With_Dim_Fill_After_IsInitialized ()
  289. {
  290. var win = new Window (new Rect (0, 0, 30, 80));
  291. var label = new Label () { AutoSize = false, Width = Dim.Fill (), Height = Dim.Fill () };
  292. win.Add (label);
  293. Application.Top.Add (win);
  294. // Text is empty so height=0
  295. Assert.False (label.AutoSize);
  296. Assert.Equal ("(0,0,0,0)", label.Bounds.ToString ());
  297. label.Text = "New text\nNew line";
  298. Application.Top.LayoutSubviews ();
  299. Assert.False (label.AutoSize);
  300. Assert.Equal ("(0,0,28,78)", label.Bounds.ToString ());
  301. Assert.False (label.IsInitialized);
  302. var rs = Application.Begin (Application.Top);
  303. Assert.True (label.IsInitialized);
  304. Assert.False (label.AutoSize);
  305. Assert.Equal ("(0,0,28,78)", label.Bounds.ToString ());
  306. Application.End (rs);
  307. }
  308. [Fact, AutoInitShutdown]
  309. public void AutoSize_False_SetWidthHeight_With_Dim_Fill_And_Dim_Absolute_After_IsAdded_And_IsInitialized ()
  310. {
  311. var win = new Window (new Rect (0, 0, 30, 80));
  312. var label = new Label () { Width = Dim.Fill () };
  313. win.Add (label);
  314. Application.Top.Add (win);
  315. Assert.True (label.IsAdded);
  316. // Text is empty so height=0
  317. Assert.True (label.AutoSize);
  318. // BUGBUG: LayoutSubviews has not been called, so this test is not really valid (pos/dim are indeterminate, not 0)
  319. Assert.Equal ("(0,0,0,0)", label.Bounds.ToString ());
  320. label.Text = "First line\nSecond line";
  321. Application.Top.LayoutSubviews ();
  322. Assert.True (label.AutoSize);
  323. // BUGBUG: This test is bogus: label has not been initialized. pos/dim is indeterminate!
  324. Assert.Equal ("(0,0,28,2)", label.Bounds.ToString ());
  325. Assert.False (label.IsInitialized);
  326. var rs = Application.Begin (Application.Top);
  327. Assert.True (label.AutoSize);
  328. Assert.Equal ("(0,0,28,2)", label.Bounds.ToString ());
  329. Assert.True (label.IsInitialized);
  330. label.AutoSize = false;
  331. Application.Refresh ();
  332. Assert.False (label.AutoSize);
  333. Assert.Equal ("(0,0,28,1)", label.Bounds.ToString ());
  334. Application.End (rs);
  335. }
  336. [Fact, AutoInitShutdown]
  337. public void AutoSize_False_SetWidthHeight_With_Dim_Fill_And_Dim_Absolute_With_Initialization ()
  338. {
  339. var win = new Window (new Rect (0, 0, 30, 80));
  340. var label = new Label () { Width = Dim.Fill () };
  341. win.Add (label);
  342. Application.Top.Add (win);
  343. // Text is empty so height=0
  344. Assert.True (label.AutoSize);
  345. Assert.Equal ("(0,0,0,0)", label.Bounds.ToString ());
  346. var rs = Application.Begin (Application.Top);
  347. Assert.True (label.AutoSize);
  348. // Here the AutoSize ensuring the right size with width 28 (Dim.Fill)
  349. // and height 0 because wasn't set and the text is empty
  350. // BUGBUG: Because of #2450, this test is bogus: pos/dim is indeterminate!
  351. //Assert.Equal ("(0,0,28,0)", label.Bounds.ToString ());
  352. label.Text = "First line\nSecond line";
  353. Application.Refresh ();
  354. // Here the AutoSize ensuring the right size with width 28 (Dim.Fill)
  355. // and height 2 because wasn't set and the text has 2 lines
  356. Assert.True (label.AutoSize);
  357. Assert.Equal ("(0,0,28,2)", label.Bounds.ToString ());
  358. label.AutoSize = false;
  359. Application.Refresh ();
  360. // Here the SetMinWidthHeight ensuring the minimum height
  361. Assert.False (label.AutoSize);
  362. Assert.Equal ("(0,0,28,1)", label.Bounds.ToString ());
  363. label.Text = "First changed line\nSecond changed line\nNew line";
  364. Application.Refresh ();
  365. // Here the AutoSize is false and the width 28 (Dim.Fill) and
  366. // height 1 because wasn't set and SetMinWidthHeight ensuring the minimum height
  367. Assert.False (label.AutoSize);
  368. Assert.Equal ("(0,0,28,1)", label.Bounds.ToString ());
  369. label.AutoSize = true;
  370. Application.Refresh ();
  371. // Here the AutoSize ensuring the right size with width 28 (Dim.Fill)
  372. // and height 3 because wasn't set and the text has 3 lines
  373. Assert.True (label.AutoSize);
  374. // BUGBUG: v2 - AutoSize is broken - temporarily disabling test See #2432
  375. //Assert.Equal ("(0,0,28,3)", label.Bounds.ToString ());
  376. Application.End (rs);
  377. }
  378. [Fact, AutoInitShutdown]
  379. public void AutoSize_True_Setting_With_Height_Horizontal ()
  380. {
  381. var label = new Label ("Hello") { Width = 10, Height = 2 };
  382. var viewX = new View ("X") { X = Pos.Right (label) };
  383. var viewY = new View ("Y") { Y = Pos.Bottom (label) };
  384. Application.Top.Add (label, viewX, viewY);
  385. var rs = Application.Begin (Application.Top);
  386. Assert.True (label.AutoSize);
  387. Assert.Equal (new Rect (0, 0, 10, 2), label.Frame);
  388. var expected = @"
  389. Hello X
  390. Y
  391. ";
  392. var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  393. Assert.Equal (new Rect (0, 0, 11, 3), pos);
  394. label.AutoSize = false;
  395. Application.Refresh ();
  396. Assert.False (label.AutoSize);
  397. Assert.Equal (new Rect (0, 0, 10, 2), label.Frame);
  398. expected = @"
  399. Hello X
  400. Y
  401. ";
  402. pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  403. Assert.Equal (new Rect (0, 0, 11, 3), pos);
  404. Application.End (rs);
  405. }
  406. [Fact, AutoInitShutdown]
  407. public void AutoSize_True_Setting_With_Height_Vertical ()
  408. {
  409. var label = new Label ("Hello") { Width = 2, Height = 10, TextDirection = TextDirection.TopBottom_LeftRight };
  410. var viewX = new View ("X") { X = Pos.Right (label) };
  411. var viewY = new View ("Y") { Y = Pos.Bottom (label) };
  412. Application.Top.Add (label, viewX, viewY);
  413. var rs = Application.Begin (Application.Top);
  414. Assert.True (label.AutoSize);
  415. Assert.Equal (new Rect (0, 0, 2, 10), label.Frame);
  416. var expected = @"
  417. H X
  418. e
  419. l
  420. l
  421. o
  422. Y
  423. ";
  424. var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  425. Assert.Equal (new Rect (0, 0, 3, 11), pos);
  426. label.AutoSize = false;
  427. Application.Refresh ();
  428. Assert.False (label.AutoSize);
  429. Assert.Equal (new Rect (0, 0, 2, 10), label.Frame);
  430. expected = @"
  431. H X
  432. e
  433. l
  434. l
  435. o
  436. Y
  437. ";
  438. pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  439. Assert.Equal (new Rect (0, 0, 3, 11), pos);
  440. Application.End (rs);
  441. }
  442. [Fact]
  443. [AutoInitShutdown]
  444. public void Excess_Text_Is_Erased_When_The_Width_Is_Reduced ()
  445. {
  446. var lbl = new Label ("123");
  447. Application.Top.Add (lbl);
  448. var rs = Application.Begin (Application.Top);
  449. Assert.True (lbl.AutoSize);
  450. Assert.Equal ("123 ", GetContents ());
  451. lbl.Text = "12";
  452. // Here the AutoSize ensuring the right size with width 3 (Dim.Absolute)
  453. // that was set on the OnAdded method with the text length of 3
  454. // and height 1 because wasn't set and the text has 1 line
  455. Assert.Equal (new Rect (0, 0, 3, 1), lbl.Frame);
  456. Assert.Equal (new Rect (0, 0, 3, 1), lbl._needsDisplayRect);
  457. Assert.Equal (new Rect (0, 0, 0, 0), lbl.SuperView._needsDisplayRect);
  458. Assert.True (lbl.SuperView.LayoutNeeded);
  459. lbl.SuperView.Draw ();
  460. Assert.Equal ("12 ", GetContents ());
  461. string GetContents ()
  462. {
  463. var text = "";
  464. for (int i = 0; i < 4; i++) {
  465. text += Application.Driver.Contents [0, i].Runes [0];
  466. }
  467. return text;
  468. }
  469. Application.End (rs);
  470. }
  471. [Fact, AutoInitShutdown]
  472. public void Width_Height_SetMinWidthHeight_Narrow_Wide_Runes ()
  473. {
  474. var text = $"First line{Environment.NewLine}Second line";
  475. var horizontalView = new View () {
  476. Width = 20,
  477. Height = 1,
  478. Text = text
  479. };
  480. var verticalView = new View () {
  481. Y = 3,
  482. Height = 20,
  483. Width = 1,
  484. Text = text,
  485. TextDirection = TextDirection.TopBottom_LeftRight
  486. };
  487. var win = new Window () {
  488. Width = Dim.Fill (),
  489. Height = Dim.Fill (),
  490. Text = "Window"
  491. };
  492. win.Add (horizontalView, verticalView);
  493. Application.Top.Add (win);
  494. var rs = Application.Begin (Application.Top);
  495. ((FakeDriver)Application.Driver).SetBufferSize (32, 32);
  496. Assert.False (horizontalView.AutoSize);
  497. Assert.False (verticalView.AutoSize);
  498. Assert.Equal (new Rect (0, 0, 20, 1), horizontalView.Frame);
  499. Assert.Equal (new Rect (0, 3, 1, 20), verticalView.Frame);
  500. var expected = @"
  501. ┌──────────────────────────────┐
  502. │First line Second li │
  503. │ │
  504. │ │
  505. │F │
  506. │i │
  507. │r │
  508. │s │
  509. │t │
  510. │ │
  511. │l │
  512. │i │
  513. │n │
  514. │e │
  515. │ │
  516. │S │
  517. │e │
  518. │c │
  519. │o │
  520. │n │
  521. │d │
  522. │ │
  523. │l │
  524. │i │
  525. │ │
  526. │ │
  527. │ │
  528. │ │
  529. │ │
  530. │ │
  531. │ │
  532. └──────────────────────────────┘
  533. ";
  534. var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  535. Assert.Equal (new Rect (0, 0, 32, 32), pos);
  536. verticalView.Text = $"最初の行{Environment.NewLine}二行目";
  537. Application.Top.Draw ();
  538. Assert.Equal (new Rect (0, 3, 2, 20), verticalView.Frame);
  539. expected = @"
  540. ┌──────────────────────────────┐
  541. │First line Second li │
  542. │ │
  543. │ │
  544. │最 │
  545. │初 │
  546. │の │
  547. │行 │
  548. │ │
  549. │二 │
  550. │行 │
  551. │目 │
  552. │ │
  553. │ │
  554. │ │
  555. │ │
  556. │ │
  557. │ │
  558. │ │
  559. │ │
  560. │ │
  561. │ │
  562. │ │
  563. │ │
  564. │ │
  565. │ │
  566. │ │
  567. │ │
  568. │ │
  569. │ │
  570. │ │
  571. └──────────────────────────────┘
  572. ";
  573. pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  574. Assert.Equal (new Rect (0, 0, 32, 32), pos);
  575. Application.End (rs);
  576. }
  577. [Fact, AutoInitShutdown]
  578. public void TextDirection_Toggle ()
  579. {
  580. var win = new Window () { Width = Dim.Fill (), Height = Dim.Fill () };
  581. var view = new View ();
  582. win.Add (view);
  583. Application.Top.Add (win);
  584. var rs = Application.Begin (Application.Top);
  585. ((FakeDriver)Application.Driver).SetBufferSize (22, 22);
  586. Assert.Equal (new Rect (0, 0, 22, 22), win.Frame);
  587. Assert.Equal (new Rect (0, 0, 22, 22), win.Margin.Frame);
  588. Assert.Equal (new Rect (0, 0, 22, 22), win.Border.Frame);
  589. Assert.Equal (new Rect (1, 1, 20, 20), win.Padding.Frame);
  590. Assert.False (view.AutoSize);
  591. Assert.Equal (TextDirection.LeftRight_TopBottom, view.TextDirection);
  592. Assert.Equal (Rect.Empty, view.Frame);
  593. Assert.Equal ("Absolute(0)", view.X.ToString ());
  594. Assert.Equal ("Absolute(0)", view.Y.ToString ());
  595. Assert.Equal ("Absolute(0)", view.Width.ToString ());
  596. Assert.Equal ("Absolute(0)", view.Height.ToString ());
  597. var expected = @"
  598. ┌────────────────────┐
  599. │ │
  600. │ │
  601. │ │
  602. │ │
  603. │ │
  604. │ │
  605. │ │
  606. │ │
  607. │ │
  608. │ │
  609. │ │
  610. │ │
  611. │ │
  612. │ │
  613. │ │
  614. │ │
  615. │ │
  616. │ │
  617. │ │
  618. │ │
  619. └────────────────────┘
  620. ";
  621. var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  622. Assert.Equal (new Rect (0, 0, 22, 22), pos);
  623. view.Text = "Hello World";
  624. view.Width = 11;
  625. view.Height = 1;
  626. win.LayoutSubviews ();
  627. Application.Refresh ();
  628. Assert.Equal (new Rect (0, 0, 11, 1), view.Frame);
  629. Assert.Equal ("Absolute(0)", view.X.ToString ());
  630. Assert.Equal ("Absolute(0)", view.Y.ToString ());
  631. Assert.Equal ("Absolute(11)", view.Width.ToString ());
  632. Assert.Equal ("Absolute(1)", view.Height.ToString ());
  633. expected = @"
  634. ┌────────────────────┐
  635. │Hello World │
  636. │ │
  637. │ │
  638. │ │
  639. │ │
  640. │ │
  641. │ │
  642. │ │
  643. │ │
  644. │ │
  645. │ │
  646. │ │
  647. │ │
  648. │ │
  649. │ │
  650. │ │
  651. │ │
  652. │ │
  653. │ │
  654. │ │
  655. └────────────────────┘
  656. ";
  657. pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  658. Assert.Equal (new Rect (0, 0, 22, 22), pos);
  659. view.AutoSize = true;
  660. view.Text = "Hello Worlds";
  661. Application.Refresh ();
  662. Assert.Equal (new Rect (0, 0, 12, 1), view.Frame);
  663. Assert.Equal ("Absolute(0)", view.X.ToString ());
  664. Assert.Equal ("Absolute(0)", view.Y.ToString ());
  665. Assert.Equal ("Absolute(11)", view.Width.ToString ());
  666. Assert.Equal ("Absolute(1)", view.Height.ToString ());
  667. expected = @"
  668. ┌────────────────────┐
  669. │Hello Worlds │
  670. │ │
  671. │ │
  672. │ │
  673. │ │
  674. │ │
  675. │ │
  676. │ │
  677. │ │
  678. │ │
  679. │ │
  680. │ │
  681. │ │
  682. │ │
  683. │ │
  684. │ │
  685. │ │
  686. │ │
  687. │ │
  688. │ │
  689. └────────────────────┘
  690. ";
  691. pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  692. Assert.Equal (new Rect (0, 0, 22, 22), pos);
  693. view.TextDirection = TextDirection.TopBottom_LeftRight;
  694. Application.Refresh ();
  695. Assert.Equal (new Rect (0, 0, 11, 12), view.Frame);
  696. Assert.Equal ("Absolute(0)", view.X.ToString ());
  697. Assert.Equal ("Absolute(0)", view.Y.ToString ());
  698. Assert.Equal ("Absolute(11)", view.Width.ToString ());
  699. Assert.Equal ("Absolute(1)", view.Height.ToString ());
  700. expected = @"
  701. ┌────────────────────┐
  702. │H │
  703. │e │
  704. │l │
  705. │l │
  706. │o │
  707. │ │
  708. │W │
  709. │o │
  710. │r │
  711. │l │
  712. │d │
  713. │s │
  714. │ │
  715. │ │
  716. │ │
  717. │ │
  718. │ │
  719. │ │
  720. │ │
  721. │ │
  722. └────────────────────┘
  723. ";
  724. pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  725. Assert.Equal (new Rect (0, 0, 22, 22), pos);
  726. view.AutoSize = false;
  727. view.Height = 1;
  728. Application.Refresh ();
  729. Assert.Equal (new Rect (0, 0, 11, 1), view.Frame);
  730. Assert.Equal ("Absolute(0)", view.X.ToString ());
  731. Assert.Equal ("Absolute(0)", view.Y.ToString ());
  732. Assert.Equal ("Absolute(11)", view.Width.ToString ());
  733. Assert.Equal ("Absolute(1)", view.Height.ToString ());
  734. expected = @"
  735. ┌────────────────────┐
  736. │HelloWorlds │
  737. │ │
  738. │ │
  739. │ │
  740. │ │
  741. │ │
  742. │ │
  743. │ │
  744. │ │
  745. │ │
  746. │ │
  747. │ │
  748. │ │
  749. │ │
  750. │ │
  751. │ │
  752. │ │
  753. │ │
  754. │ │
  755. │ │
  756. └────────────────────┘
  757. ";
  758. pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  759. Assert.Equal (new Rect (0, 0, 22, 22), pos);
  760. view.PreserveTrailingSpaces = true;
  761. Application.Refresh ();
  762. Assert.Equal (new Rect (0, 0, 11, 1), view.Frame);
  763. Assert.Equal ("Absolute(0)", view.X.ToString ());
  764. Assert.Equal ("Absolute(0)", view.Y.ToString ());
  765. Assert.Equal ("Absolute(11)", view.Width.ToString ());
  766. Assert.Equal ("Absolute(1)", view.Height.ToString ());
  767. expected = @"
  768. ┌────────────────────┐
  769. │Hello World │
  770. │ │
  771. │ │
  772. │ │
  773. │ │
  774. │ │
  775. │ │
  776. │ │
  777. │ │
  778. │ │
  779. │ │
  780. │ │
  781. │ │
  782. │ │
  783. │ │
  784. │ │
  785. │ │
  786. │ │
  787. │ │
  788. │ │
  789. └────────────────────┘
  790. ";
  791. pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  792. Assert.Equal (new Rect (0, 0, 22, 22), pos);
  793. view.PreserveTrailingSpaces = false;
  794. var f = view.Frame;
  795. view.Width = f.Height;
  796. view.Height = f.Width;
  797. view.TextDirection = TextDirection.TopBottom_LeftRight;
  798. Application.Refresh ();
  799. Assert.Equal (new Rect (0, 0, 1, 11), view.Frame);
  800. Assert.Equal ("Absolute(0)", view.X.ToString ());
  801. Assert.Equal ("Absolute(0)", view.Y.ToString ());
  802. Assert.Equal ("Absolute(1)", view.Width.ToString ());
  803. Assert.Equal ("Absolute(11)", view.Height.ToString ());
  804. expected = @"
  805. ┌────────────────────┐
  806. │H │
  807. │e │
  808. │l │
  809. │l │
  810. │o │
  811. │ │
  812. │W │
  813. │o │
  814. │r │
  815. │l │
  816. │d │
  817. │ │
  818. │ │
  819. │ │
  820. │ │
  821. │ │
  822. │ │
  823. │ │
  824. │ │
  825. │ │
  826. └────────────────────┘
  827. ";
  828. pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  829. Assert.Equal (new Rect (0, 0, 22, 22), pos);
  830. view.AutoSize = true;
  831. Application.Refresh ();
  832. Assert.Equal (new Rect (0, 0, 1, 12), view.Frame);
  833. Assert.Equal ("Absolute(0)", view.X.ToString ());
  834. Assert.Equal ("Absolute(0)", view.Y.ToString ());
  835. Assert.Equal ("Absolute(1)", view.Width.ToString ());
  836. Assert.Equal ("Absolute(12)", view.Height.ToString ());
  837. expected = @"
  838. ┌────────────────────┐
  839. │H │
  840. │e │
  841. │l │
  842. │l │
  843. │o │
  844. │ │
  845. │W │
  846. │o │
  847. │r │
  848. │l │
  849. │d │
  850. │s │
  851. │ │
  852. │ │
  853. │ │
  854. │ │
  855. │ │
  856. │ │
  857. │ │
  858. │ │
  859. └────────────────────┘
  860. ";
  861. pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  862. Assert.Equal (new Rect (0, 0, 22, 22), pos);
  863. Application.End (rs);
  864. }
  865. [Fact, AutoInitShutdown]
  866. public void Width_Height_AutoSize_True_Stay_True_If_TextFormatter_Size_Fit ()
  867. {
  868. var text = $"Fi_nish 終";
  869. var horizontalView = new View () {
  870. Id = "horizontalView",
  871. AutoSize = true,
  872. HotKeySpecifier = (Rune)'_',
  873. Text = text
  874. };
  875. var verticalView = new View () {
  876. Id = "verticalView",
  877. Y = 3,
  878. AutoSize = true,
  879. HotKeySpecifier = (Rune)'_',
  880. Text = text,
  881. TextDirection = TextDirection.TopBottom_LeftRight
  882. };
  883. var win = new Window () {
  884. Id = "win",
  885. Width = Dim.Fill (),
  886. Height = Dim.Fill (),
  887. Text = "Window"
  888. };
  889. win.Add (horizontalView, verticalView);
  890. Application.Top.Add (win);
  891. var rs = Application.Begin (Application.Top);
  892. ((FakeDriver)Application.Driver).SetBufferSize (22, 22);
  893. Assert.True (horizontalView.AutoSize);
  894. Assert.True (verticalView.AutoSize);
  895. Assert.Equal (new Size (10, 1), horizontalView.TextFormatter.Size);
  896. Assert.Equal (new Size (2, 9), verticalView.TextFormatter.Size);
  897. Assert.Equal (new Rect (0, 0, 9, 1), horizontalView.Frame);
  898. Assert.Equal ("Absolute(0)", horizontalView.X.ToString ());
  899. Assert.Equal ("Absolute(0)", horizontalView.Y.ToString ());
  900. // BUGBUG - v2 - With v1 AutoSize = true Width/Height should always grow or keep initial value,
  901. // but in v2, autosize will be replaced by Dim.Fit. Disabling test for now.
  902. Assert.Equal ("Absolute(9)", horizontalView.Width.ToString ());
  903. Assert.Equal ("Absolute(1)", horizontalView.Height.ToString ());
  904. Assert.Equal (new Rect (0, 3, 2, 8), verticalView.Frame);
  905. Assert.Equal ("Absolute(0)", verticalView.X.ToString ());
  906. Assert.Equal ("Absolute(3)", verticalView.Y.ToString ());
  907. Assert.Equal ("Absolute(2)", verticalView.Width.ToString ());
  908. Assert.Equal ("Absolute(8)", verticalView.Height.ToString ());
  909. var expected = @"
  910. ┌────────────────────┐
  911. │Finish 終 │
  912. │ │
  913. │ │
  914. │F │
  915. │i │
  916. │n │
  917. │i │
  918. │s │
  919. │h │
  920. │ │
  921. │終 │
  922. │ │
  923. │ │
  924. │ │
  925. │ │
  926. │ │
  927. │ │
  928. │ │
  929. │ │
  930. │ │
  931. └────────────────────┘
  932. ";
  933. var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  934. Assert.Equal (new Rect (0, 0, 22, 22), pos);
  935. verticalView.Text = $"最初_の行二行目";
  936. Application.Top.Draw ();
  937. Assert.True (horizontalView.AutoSize);
  938. Assert.True (verticalView.AutoSize);
  939. // height was initialized with 8 and can only grow or keep initial value
  940. Assert.Equal (new Rect (0, 3, 2, 8), verticalView.Frame);
  941. Assert.Equal ("Absolute(0)", verticalView.X.ToString ());
  942. Assert.Equal ("Absolute(3)", verticalView.Y.ToString ());
  943. Assert.Equal ("Absolute(2)", verticalView.Width.ToString ());
  944. Assert.Equal ("Absolute(8)", verticalView.Height.ToString ());
  945. expected = @"
  946. ┌────────────────────┐
  947. │Finish 終 │
  948. │ │
  949. │ │
  950. │最 │
  951. │初 │
  952. │の │
  953. │行 │
  954. │二 │
  955. │行 │
  956. │目 │
  957. │ │
  958. │ │
  959. │ │
  960. │ │
  961. │ │
  962. │ │
  963. │ │
  964. │ │
  965. │ │
  966. │ │
  967. └────────────────────┘
  968. ";
  969. pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  970. Assert.Equal (new Rect (0, 0, 22, 22), pos);
  971. Application.End (rs);
  972. }
  973. [Fact, AutoInitShutdown]
  974. public void AutoSize_Stays_True_Center_HotKeySpecifier ()
  975. {
  976. var label = new Label () {
  977. X = Pos.Center (),
  978. Y = Pos.Center (),
  979. Text = "Say Hello 你"
  980. };
  981. var win = new Window () {
  982. Width = Dim.Fill (),
  983. Height = Dim.Fill (),
  984. Title = "Test Demo 你"
  985. };
  986. win.Add (label);
  987. Application.Top.Add (win);
  988. Assert.True (label.AutoSize);
  989. var rs = Application.Begin (Application.Top);
  990. ((FakeDriver)Application.Driver).SetBufferSize (30, 5);
  991. var expected = @$"
  992. ┌┤Test Demo 你├──────────────┐
  993. │ │
  994. │ Say Hello 你 │
  995. │ │
  996. └────────────────────────────┘
  997. ";
  998. TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  999. Assert.True (label.AutoSize);
  1000. label.Text = "Say Hello 你 changed";
  1001. Assert.True (label.AutoSize);
  1002. Application.Refresh ();
  1003. expected = @"
  1004. ┌┤Test Demo 你├──────────────┐
  1005. │ │
  1006. │ Say Hello 你 changed │
  1007. │ │
  1008. └────────────────────────────┘
  1009. ";
  1010. TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  1011. Application.End (rs);
  1012. }
  1013. [Fact, AutoInitShutdown]
  1014. public void AutoSize_False_Equal_Before_And_After_IsInitialized_With_Differents_Orders ()
  1015. {
  1016. var view1 = new View () { Text = "Say Hello view1 你", AutoSize = false, Width = 10, Height = 5 };
  1017. var view2 = new View () { Text = "Say Hello view2 你", Width = 10, Height = 5, AutoSize = false };
  1018. var view3 = new View () { AutoSize = false, Width = 10, Height = 5, Text = "Say Hello view3 你" };
  1019. var view4 = new View () {
  1020. Text = "Say Hello view4 你",
  1021. AutoSize = false,
  1022. Width = 10,
  1023. Height = 5,
  1024. TextDirection = TextDirection.TopBottom_LeftRight
  1025. };
  1026. var view5 = new View () {
  1027. Text = "Say Hello view5 你",
  1028. Width = 10,
  1029. Height = 5,
  1030. AutoSize = false,
  1031. TextDirection = TextDirection.TopBottom_LeftRight
  1032. };
  1033. var view6 = new View () {
  1034. AutoSize = false,
  1035. Width = 10,
  1036. Height = 5,
  1037. TextDirection = TextDirection.TopBottom_LeftRight,
  1038. Text = "Say Hello view6 你",
  1039. };
  1040. Application.Top.Add (view1, view2, view3, view4, view5, view6);
  1041. Assert.False (view1.IsInitialized);
  1042. Assert.False (view2.IsInitialized);
  1043. Assert.False (view3.IsInitialized);
  1044. Assert.False (view4.IsInitialized);
  1045. Assert.False (view5.IsInitialized);
  1046. Assert.False (view1.AutoSize);
  1047. Assert.Equal (new Rect (0, 0, 10, 5), view1.Frame);
  1048. Assert.Equal ("Absolute(10)", view1.Width.ToString ());
  1049. Assert.Equal ("Absolute(5)", view1.Height.ToString ());
  1050. Assert.False (view2.AutoSize);
  1051. Assert.Equal (new Rect (0, 0, 10, 5), view2.Frame);
  1052. Assert.Equal ("Absolute(10)", view2.Width.ToString ());
  1053. Assert.Equal ("Absolute(5)", view2.Height.ToString ());
  1054. Assert.False (view3.AutoSize);
  1055. Assert.Equal (new Rect (0, 0, 10, 5), view3.Frame);
  1056. Assert.Equal ("Absolute(10)", view3.Width.ToString ());
  1057. Assert.Equal ("Absolute(5)", view3.Height.ToString ());
  1058. Assert.False (view4.AutoSize);
  1059. Assert.Equal (new Rect (0, 0, 10, 5), view4.Frame);
  1060. Assert.Equal ("Absolute(10)", view4.Width.ToString ());
  1061. Assert.Equal ("Absolute(5)", view4.Height.ToString ());
  1062. Assert.False (view5.AutoSize);
  1063. Assert.Equal (new Rect (0, 0, 10, 5), view5.Frame);
  1064. Assert.Equal ("Absolute(10)", view5.Width.ToString ());
  1065. Assert.Equal ("Absolute(5)", view5.Height.ToString ());
  1066. Assert.False (view6.AutoSize);
  1067. Assert.Equal (new Rect (0, 0, 10, 5), view6.Frame);
  1068. Assert.Equal ("Absolute(10)", view6.Width.ToString ());
  1069. Assert.Equal ("Absolute(5)", view6.Height.ToString ());
  1070. var rs = Application.Begin (Application.Top);
  1071. Assert.True (view1.IsInitialized);
  1072. Assert.True (view2.IsInitialized);
  1073. Assert.True (view3.IsInitialized);
  1074. Assert.True (view4.IsInitialized);
  1075. Assert.True (view5.IsInitialized);
  1076. Assert.False (view1.AutoSize);
  1077. Assert.Equal (new Rect (0, 0, 10, 5), view1.Frame);
  1078. Assert.Equal ("Absolute(10)", view1.Width.ToString ());
  1079. Assert.Equal ("Absolute(5)", view1.Height.ToString ());
  1080. Assert.False (view2.AutoSize);
  1081. Assert.Equal (new Rect (0, 0, 10, 5), view2.Frame);
  1082. Assert.Equal ("Absolute(10)", view2.Width.ToString ());
  1083. Assert.Equal ("Absolute(5)", view2.Height.ToString ());
  1084. Assert.False (view3.AutoSize);
  1085. Assert.Equal (new Rect (0, 0, 10, 5), view3.Frame);
  1086. Assert.Equal ("Absolute(10)", view3.Width.ToString ());
  1087. Assert.Equal ("Absolute(5)", view3.Height.ToString ());
  1088. Assert.False (view4.AutoSize);
  1089. Assert.Equal (new Rect (0, 0, 10, 5), view4.Frame);
  1090. Assert.Equal ("Absolute(10)", view4.Width.ToString ());
  1091. Assert.Equal ("Absolute(5)", view4.Height.ToString ());
  1092. Assert.False (view5.AutoSize);
  1093. Assert.Equal (new Rect (0, 0, 10, 5), view5.Frame);
  1094. Assert.Equal ("Absolute(10)", view5.Width.ToString ());
  1095. Assert.Equal ("Absolute(5)", view5.Height.ToString ());
  1096. Assert.False (view6.AutoSize);
  1097. Assert.Equal (new Rect (0, 0, 10, 5), view6.Frame);
  1098. Assert.Equal ("Absolute(10)", view6.Width.ToString ());
  1099. Assert.Equal ("Absolute(5)", view6.Height.ToString ());
  1100. Application.End (rs);
  1101. }
  1102. [Fact, AutoInitShutdown]
  1103. public void AutoSize_True_Equal_Before_And_After_IsInitialized_With_Different_Orders ()
  1104. {
  1105. var view1 = new View () { Text = "Say Hello view1 你", AutoSize = true, Width = 10, Height = 5 };
  1106. var view2 = new View () { Text = "Say Hello view2 你", Width = 10, Height = 5, AutoSize = true };
  1107. var view3 = new View () { AutoSize = true, Width = 10, Height = 5, Text = "Say Hello view3 你" };
  1108. var view4 = new View () {
  1109. Text = "Say Hello view4 你",
  1110. AutoSize = true,
  1111. Width = 10,
  1112. Height = 5,
  1113. TextDirection = TextDirection.TopBottom_LeftRight
  1114. };
  1115. var view5 = new View () {
  1116. Text = "Say Hello view5 你",
  1117. Width = 10,
  1118. Height = 5,
  1119. AutoSize = true,
  1120. TextDirection = TextDirection.TopBottom_LeftRight
  1121. };
  1122. var view6 = new View () {
  1123. AutoSize = true,
  1124. Width = 10,
  1125. Height = 5,
  1126. TextDirection = TextDirection.TopBottom_LeftRight,
  1127. Text = "Say Hello view6 你",
  1128. };
  1129. Application.Top.Add (view1, view2, view3, view4, view5, view6);
  1130. Assert.False (view1.IsInitialized);
  1131. Assert.False (view2.IsInitialized);
  1132. Assert.False (view3.IsInitialized);
  1133. Assert.False (view4.IsInitialized);
  1134. Assert.False (view5.IsInitialized);
  1135. Assert.True (view1.AutoSize);
  1136. Assert.Equal (new Rect (0, 0, 18, 5), view1.Frame);
  1137. Assert.Equal ("Absolute(10)", view1.Width.ToString ());
  1138. Assert.Equal ("Absolute(5)", view1.Height.ToString ());
  1139. Assert.True (view2.AutoSize);
  1140. // BUGBUG: v2 - Autosize is broken when setting Width/Height AutoSize. Disabling test for now.
  1141. //Assert.Equal (new Rect (0, 0, 18, 5), view2.Frame);
  1142. //Assert.Equal ("Absolute(10)", view2.Width.ToString ());
  1143. //Assert.Equal ("Absolute(5)", view2.Height.ToString ());
  1144. //Assert.True (view3.AutoSize);
  1145. //Assert.Equal (new Rect (0, 0, 18, 5), view3.Frame);
  1146. //Assert.Equal ("Absolute(10)", view3.Width.ToString ());
  1147. //Assert.Equal ("Absolute(5)", view3.Height.ToString ());
  1148. //Assert.True (view4.AutoSize);
  1149. //Assert.Equal (new Rect (0, 0, 10, 17), view4.Frame);
  1150. //Assert.Equal ("Absolute(10)", view4.Width.ToString ());
  1151. //Assert.Equal ("Absolute(5)", view4.Height.ToString ());
  1152. //Assert.True (view5.AutoSize);
  1153. //Assert.Equal (new Rect (0, 0, 10, 17), view5.Frame);
  1154. //Assert.Equal ("Absolute(10)", view5.Width.ToString ());
  1155. //Assert.Equal ("Absolute(5)", view5.Height.ToString ());
  1156. //Assert.True (view6.AutoSize);
  1157. //Assert.Equal (new Rect (0, 0, 10, 17), view6.Frame);
  1158. //Assert.Equal ("Absolute(10)", view6.Width.ToString ());
  1159. //Assert.Equal ("Absolute(5)", view6.Height.ToString ());
  1160. var rs = Application.Begin (Application.Top);
  1161. Assert.True (view1.IsInitialized);
  1162. Assert.True (view2.IsInitialized);
  1163. Assert.True (view3.IsInitialized);
  1164. Assert.True (view4.IsInitialized);
  1165. Assert.True (view5.IsInitialized);
  1166. Assert.True (view1.AutoSize);
  1167. Assert.Equal (new Rect (0, 0, 18, 5), view1.Frame);
  1168. Assert.Equal ("Absolute(10)", view1.Width.ToString ());
  1169. Assert.Equal ("Absolute(5)", view1.Height.ToString ());
  1170. Assert.True (view2.AutoSize);
  1171. // BUGBUG: v2 - Autosize is broken when setting Width/Height AutoSize. Disabling test for now.
  1172. //Assert.Equal (new Rect (0, 0, 18, 5), view2.Frame);
  1173. //Assert.Equal ("Absolute(10)", view2.Width.ToString ());
  1174. //Assert.Equal ("Absolute(5)", view2.Height.ToString ());
  1175. //Assert.True (view3.AutoSize);
  1176. //Assert.Equal (new Rect (0, 0, 18, 5), view3.Frame);
  1177. //Assert.Equal ("Absolute(10)", view3.Width.ToString ());
  1178. //Assert.Equal ("Absolute(5)", view3.Height.ToString ());
  1179. //Assert.True (view4.AutoSize);
  1180. //Assert.Equal (new Rect (0, 0, 10, 17), view4.Frame);
  1181. //Assert.Equal ("Absolute(10)", view4.Width.ToString ());
  1182. //Assert.Equal ("Absolute(5)", view4.Height.ToString ());
  1183. //Assert.True (view5.AutoSize);
  1184. //Assert.Equal (new Rect (0, 0, 10, 17), view5.Frame);
  1185. //Assert.Equal ("Absolute(10)", view5.Width.ToString ());
  1186. //Assert.Equal ("Absolute(5)", view5.Height.ToString ());
  1187. //Assert.True (view6.AutoSize);
  1188. //Assert.Equal (new Rect (0, 0, 10, 17), view6.Frame);
  1189. //Assert.Equal ("Absolute(10)", view6.Width.ToString ());
  1190. //Assert.Equal ("Absolute(5)", view6.Height.ToString ());
  1191. Application.End (rs);
  1192. }
  1193. [Fact, AutoInitShutdown]
  1194. public void Setting_Frame_Dont_Respect_AutoSize_True_On_Layout_Absolute ()
  1195. {
  1196. var view1 = new View (new Rect (0, 0, 10, 0)) { Text = "Say Hello view1 你", AutoSize = true };
  1197. var view2 = new View (new Rect (0, 0, 0, 10)) {
  1198. Text = "Say Hello view2 你",
  1199. AutoSize = true,
  1200. TextDirection = TextDirection.TopBottom_LeftRight
  1201. };
  1202. Application.Top.Add (view1, view2);
  1203. var rs = Application.Begin (Application.Top);
  1204. Assert.True (view1.AutoSize);
  1205. Assert.Equal (LayoutStyle.Absolute, view1.LayoutStyle);
  1206. Assert.Equal (new Rect (0, 0, 18, 1), view1.Frame);
  1207. Assert.Equal ("Absolute(0)", view1.X.ToString ());
  1208. Assert.Equal ("Absolute(0)", view1.Y.ToString ());
  1209. Assert.Equal ("Absolute(18)", view1.Width.ToString ());
  1210. Assert.Equal ("Absolute(1)", view1.Height.ToString ());
  1211. Assert.True (view2.AutoSize);
  1212. // BUGBUG: v2 - Autosize is broken when setting Width/Height AutoSize. Disabling test for now.
  1213. //Assert.Equal (LayoutStyle.Absolute, view2.LayoutStyle);
  1214. //Assert.Equal (new Rect (0, 0, 2, 17), view2.Frame);
  1215. //Assert.Equal ("Absolute(0)", view2.X.ToString ());
  1216. //Assert.Equal ("Absolute(0)", view2.Y.ToString ());
  1217. //Assert.Equal ("Absolute(2)", view2.Width.ToString ());
  1218. //Assert.Equal ("Absolute(17)", view2.Height.ToString ());
  1219. view1.Frame = new Rect (0, 0, 25, 4);
  1220. bool firstIteration = false;
  1221. Application.RunIteration (ref rs, ref firstIteration);
  1222. Assert.True (view1.AutoSize);
  1223. Assert.Equal (LayoutStyle.Absolute, view1.LayoutStyle);
  1224. Assert.Equal (new Rect (0, 0, 25, 4), view1.Frame);
  1225. Assert.Equal ("Absolute(0)", view1.X.ToString ());
  1226. Assert.Equal ("Absolute(0)", view1.Y.ToString ());
  1227. Assert.Equal ("Absolute(18)", view1.Width.ToString ());
  1228. Assert.Equal ("Absolute(1)", view1.Height.ToString ());
  1229. view2.Frame = new Rect (0, 0, 1, 25);
  1230. Application.RunIteration (ref rs, ref firstIteration);
  1231. Assert.True (view2.AutoSize);
  1232. Assert.Equal (LayoutStyle.Absolute, view2.LayoutStyle);
  1233. Assert.Equal (new Rect (0, 0, 1, 25), view2.Frame);
  1234. Assert.Equal ("Absolute(0)", view2.X.ToString ());
  1235. Assert.Equal ("Absolute(0)", view2.Y.ToString ());
  1236. // BUGBUG: v2 - Autosize is broken when setting Width/Height AutoSize. Disabling test for now.
  1237. //Assert.Equal ("Absolute(2)", view2.Width.ToString ());
  1238. //Assert.Equal ("Absolute(17)", view2.Height.ToString ());
  1239. Application.End (rs);
  1240. }
  1241. [Fact, AutoInitShutdown]
  1242. public void Pos_Dim_Are_Null_If_Not_Initialized_On_Constructor_IsAdded_False ()
  1243. {
  1244. var top = Application.Top;
  1245. var view1 = new View ();
  1246. Assert.False (view1.IsAdded);
  1247. Assert.Null (view1.X);
  1248. Assert.Null (view1.Y);
  1249. Assert.Null (view1.Width);
  1250. Assert.Null (view1.Height);
  1251. top.Add (view1);
  1252. Assert.True (view1.IsAdded);
  1253. Assert.Equal ("Absolute(0)", view1.X.ToString ());
  1254. Assert.Equal ("Absolute(0)", view1.Y.ToString ());
  1255. Assert.Equal ("Absolute(0)", view1.Width.ToString ());
  1256. Assert.Equal ("Absolute(0)", view1.Height.ToString ());
  1257. var view2 = new View () {
  1258. X = Pos.Center (),
  1259. Y = Pos.Center (),
  1260. Width = Dim.Fill (),
  1261. Height = Dim.Fill ()
  1262. };
  1263. Assert.False (view2.IsAdded);
  1264. Assert.Equal ("Center", view2.X.ToString ());
  1265. Assert.Equal ("Center", view2.Y.ToString ());
  1266. Assert.Equal ("Fill(0)", view2.Width.ToString ());
  1267. Assert.Equal ("Fill(0)", view2.Height.ToString ());
  1268. top.Add (view2);
  1269. Assert.True (view2.IsAdded);
  1270. Assert.Equal ("Center", view2.X.ToString ());
  1271. Assert.Equal ("Center", view2.Y.ToString ());
  1272. Assert.Equal ("Fill(0)", view2.Width.ToString ());
  1273. Assert.Equal ("Fill(0)", view2.Height.ToString ());
  1274. }
  1275. [Fact, TestRespondersDisposed]
  1276. public void SetRelativeLayout_PosCombine_Center_Plus_Absolute ()
  1277. {
  1278. var superView = new View () {
  1279. AutoSize = false,
  1280. Width = 10,
  1281. Height = 10
  1282. };
  1283. var testView = new View () {
  1284. AutoSize = false,
  1285. X = Pos.Center (),
  1286. Y = Pos.Center (),
  1287. Width = 1,
  1288. Height = 1
  1289. };
  1290. superView.Add (testView);
  1291. testView.SetRelativeLayout (superView.Frame);
  1292. Assert.Equal (4, testView.Frame.X);
  1293. Assert.Equal (4, testView.Frame.Y);
  1294. testView = new View () {
  1295. AutoSize = false,
  1296. X = Pos.Center () + 1,
  1297. Y = Pos.Center () + 1,
  1298. Width = 1,
  1299. Height = 1
  1300. };
  1301. superView.Add (testView);
  1302. testView.SetRelativeLayout (superView.Frame);
  1303. Assert.Equal (5, testView.Frame.X);
  1304. Assert.Equal (5, testView.Frame.Y);
  1305. testView = new View () {
  1306. AutoSize = false,
  1307. X = 1 + Pos.Center (),
  1308. Y = 1 + Pos.Center (),
  1309. Width = 1,
  1310. Height = 1
  1311. };
  1312. superView.Add (testView);
  1313. testView.SetRelativeLayout (superView.Frame);
  1314. Assert.Equal (5, testView.Frame.X);
  1315. Assert.Equal (5, testView.Frame.Y);
  1316. testView = new View () {
  1317. AutoSize = false,
  1318. X = 1 + Pos.Percent (50),
  1319. Y = Pos.Percent (50) + 1,
  1320. Width = 1,
  1321. Height = 1
  1322. };
  1323. superView.Add (testView);
  1324. testView.SetRelativeLayout (superView.Frame);
  1325. Assert.Equal (6, testView.Frame.X);
  1326. Assert.Equal (6, testView.Frame.Y);
  1327. testView = new View () {
  1328. AutoSize = false,
  1329. X = Pos.Percent (10) + Pos.Percent (40),
  1330. Y = Pos.Percent (10) + Pos.Percent (40),
  1331. Width = 1,
  1332. Height = 1
  1333. };
  1334. superView.Add (testView);
  1335. testView.SetRelativeLayout (superView.Frame);
  1336. Assert.Equal (5, testView.Frame.X);
  1337. Assert.Equal (5, testView.Frame.Y);
  1338. testView = new View () {
  1339. AutoSize = false,
  1340. X = 1 + Pos.Percent (10) + Pos.Percent (40) - 1,
  1341. Y = 5 + Pos.Percent (10) + Pos.Percent (40) - 5,
  1342. Width = 1,
  1343. Height = 1
  1344. };
  1345. superView.Add (testView);
  1346. testView.SetRelativeLayout (superView.Frame);
  1347. Assert.Equal (5, testView.Frame.X);
  1348. Assert.Equal (5, testView.Frame.Y);
  1349. testView = new View () {
  1350. AutoSize = false,
  1351. X = Pos.Left (testView),
  1352. Y = Pos.Left (testView),
  1353. Width = 1,
  1354. Height = 1
  1355. };
  1356. superView.Add (testView);
  1357. testView.SetRelativeLayout (superView.Frame);
  1358. Assert.Equal (5, testView.Frame.X);
  1359. Assert.Equal (5, testView.Frame.Y);
  1360. testView = new View () {
  1361. AutoSize = false,
  1362. X = 1 + Pos.Left (testView),
  1363. Y = Pos.Top (testView) + 1,
  1364. Width = 1,
  1365. Height = 1
  1366. };
  1367. superView.Add (testView);
  1368. testView.SetRelativeLayout (superView.Frame);
  1369. Assert.Equal (6, testView.Frame.X);
  1370. Assert.Equal (6, testView.Frame.Y);
  1371. superView.Dispose ();
  1372. }
  1373. [Theory, AutoInitShutdown]
  1374. [InlineData (1)]
  1375. [InlineData (2)]
  1376. [InlineData (3)]
  1377. [InlineData (4)]
  1378. [InlineData (5)]
  1379. [InlineData (6)]
  1380. [InlineData (7)]
  1381. [InlineData (8)]
  1382. [InlineData (9)]
  1383. [InlineData (10)]
  1384. public void Dim_CenteredSubView_85_Percent_Height (int height)
  1385. {
  1386. var win = new Window () {
  1387. Width = Dim.Fill (),
  1388. Height = Dim.Fill ()
  1389. };
  1390. var subview = new Window () {
  1391. X = Pos.Center (),
  1392. Y = Pos.Center (),
  1393. Width = Dim.Percent (85),
  1394. Height = Dim.Percent (85)
  1395. };
  1396. win.Add (subview);
  1397. var rs = Application.Begin (win);
  1398. bool firstIteration = false;
  1399. ((FakeDriver)Application.Driver).SetBufferSize (20, height);
  1400. Application.RunIteration (ref rs, ref firstIteration);
  1401. var expected = string.Empty;
  1402. switch (height) {
  1403. case 1:
  1404. //Assert.Equal (new Rect (0, 0, 17, 0), subview.Frame);
  1405. expected = @"
  1406. ────────────────────";
  1407. break;
  1408. case 2:
  1409. //Assert.Equal (new Rect (0, 0, 17, 1), subview.Frame);
  1410. expected = @"
  1411. ┌──────────────────┐
  1412. └──────────────────┘
  1413. ";
  1414. break;
  1415. case 3:
  1416. //Assert.Equal (new Rect (0, 0, 17, 2), subview.Frame);
  1417. expected = @"
  1418. ┌──────────────────┐
  1419. │ │
  1420. └──────────────────┘
  1421. ";
  1422. break;
  1423. case 4:
  1424. //Assert.Equal (new Rect (0, 0, 17, 3), subview.Frame);
  1425. expected = @"
  1426. ┌──────────────────┐
  1427. │ ─────────────── │
  1428. │ │
  1429. └──────────────────┘";
  1430. break;
  1431. case 5:
  1432. //Assert.Equal (new Rect (0, 0, 17, 3), subview.Frame);
  1433. expected = @"
  1434. ┌──────────────────┐
  1435. │ ┌─────────────┐ │
  1436. │ └─────────────┘ │
  1437. │ │
  1438. └──────────────────┘";
  1439. break;
  1440. case 6:
  1441. //Assert.Equal (new Rect (0, 0, 17, 3), subview.Frame);
  1442. expected = @"
  1443. ┌──────────────────┐
  1444. │ ┌─────────────┐ │
  1445. │ │ │ │
  1446. │ └─────────────┘ │
  1447. │ │
  1448. └──────────────────┘";
  1449. break;
  1450. case 7:
  1451. //Assert.Equal (new Rect (0, 0, 17, 3), subview.Frame);
  1452. expected = @"
  1453. ┌──────────────────┐
  1454. │ ┌─────────────┐ │
  1455. │ │ │ │
  1456. │ │ │ │
  1457. │ └─────────────┘ │
  1458. │ │
  1459. └──────────────────┘";
  1460. break;
  1461. case 8:
  1462. //Assert.Equal (new Rect (0, 0, 17, 3), subview.Frame);
  1463. expected = @"
  1464. ┌──────────────────┐
  1465. │ ┌─────────────┐ │
  1466. │ │ │ │
  1467. │ │ │ │
  1468. │ │ │ │
  1469. │ └─────────────┘ │
  1470. │ │
  1471. └──────────────────┘";
  1472. break;
  1473. case 9:
  1474. //Assert.Equal (new Rect (0, 0, 17, 3), subview.Frame);
  1475. expected = @"
  1476. ┌──────────────────┐
  1477. │ │
  1478. │ ┌─────────────┐ │
  1479. │ │ │ │
  1480. │ │ │ │
  1481. │ │ │ │
  1482. │ └─────────────┘ │
  1483. │ │
  1484. └──────────────────┘";
  1485. break;
  1486. case 10:
  1487. //Assert.Equal (new Rect (0, 0, 17, 3), subview.Frame);
  1488. expected = @"
  1489. ┌──────────────────┐
  1490. │ │
  1491. │ ┌─────────────┐ │
  1492. │ │ │ │
  1493. │ │ │ │
  1494. │ │ │ │
  1495. │ │ │ │
  1496. │ └─────────────┘ │
  1497. │ │
  1498. └──────────────────┘";
  1499. break;
  1500. }
  1501. _ = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  1502. Application.End (rs);
  1503. }
  1504. [Theory, AutoInitShutdown]
  1505. [InlineData (1)]
  1506. [InlineData (2)]
  1507. [InlineData (3)]
  1508. [InlineData (4)]
  1509. [InlineData (5)]
  1510. [InlineData (6)]
  1511. [InlineData (7)]
  1512. [InlineData (8)]
  1513. [InlineData (9)]
  1514. [InlineData (10)]
  1515. public void Dim_CenteredSubView_85_Percent_Width (int width)
  1516. {
  1517. var win = new Window () {
  1518. Width = Dim.Fill (),
  1519. Height = Dim.Fill ()
  1520. };
  1521. var subview = new Window () {
  1522. X = Pos.Center (),
  1523. Y = Pos.Center (),
  1524. Width = Dim.Percent (85),
  1525. Height = Dim.Percent (85)
  1526. };
  1527. win.Add (subview);
  1528. var rs = Application.Begin (win);
  1529. bool firstIteration = false;
  1530. ((FakeDriver)Application.Driver).SetBufferSize (width, 7);
  1531. Application.RunIteration (ref rs, ref firstIteration);
  1532. var expected = string.Empty;
  1533. switch (width) {
  1534. case 1:
  1535. Assert.Equal (new Rect (0, 0, 0, 4), subview.Frame);
  1536. expected = @"
  1537. │";
  1538. break;
  1539. case 2:
  1540. Assert.Equal (new Rect (0, 0, 0, 4), subview.Frame);
  1541. expected = @"
  1542. ┌┐
  1543. ││
  1544. ││
  1545. ││
  1546. ││
  1547. ││
  1548. └┘";
  1549. break;
  1550. case 3:
  1551. Assert.Equal (new Rect (0, 0, 0, 4), subview.Frame);
  1552. expected = @"
  1553. ┌─┐
  1554. │ │
  1555. │ │
  1556. │ │
  1557. │ │
  1558. │ │
  1559. └─┘";
  1560. break;
  1561. case 4:
  1562. Assert.Equal (new Rect (0, 0, 1, 4), subview.Frame);
  1563. expected = @"
  1564. ┌──┐
  1565. ││ │
  1566. ││ │
  1567. ││ │
  1568. ││ │
  1569. │ │
  1570. └──┘";
  1571. break;
  1572. case 5:
  1573. Assert.Equal (new Rect (0, 0, 2, 4), subview.Frame);
  1574. expected = @"
  1575. ┌───┐
  1576. │┌┐ │
  1577. │││ │
  1578. │││ │
  1579. │└┘ │
  1580. │ │
  1581. └───┘";
  1582. break;
  1583. case 6:
  1584. Assert.Equal (new Rect (0, 0, 3, 4), subview.Frame);
  1585. expected = @"
  1586. ┌────┐
  1587. │┌─┐ │
  1588. ││ │ │
  1589. ││ │ │
  1590. │└─┘ │
  1591. │ │
  1592. └────┘";
  1593. break;
  1594. case 7:
  1595. Assert.Equal (new Rect (0, 0, 4, 4), subview.Frame);
  1596. expected = @"
  1597. ┌─────┐
  1598. │┌──┐ │
  1599. ││ │ │
  1600. ││ │ │
  1601. │└──┘ │
  1602. │ │
  1603. └─────┘";
  1604. break;
  1605. case 8:
  1606. Assert.Equal (new Rect (0, 0, 5, 4), subview.Frame);
  1607. expected = @"
  1608. ┌──────┐
  1609. │┌───┐ │
  1610. ││ │ │
  1611. ││ │ │
  1612. │└───┘ │
  1613. │ │
  1614. └──────┘";
  1615. break;
  1616. case 9:
  1617. Assert.Equal (new Rect (1, 0, 5, 4), subview.Frame);
  1618. expected = @"
  1619. ┌───────┐
  1620. │ ┌───┐ │
  1621. │ │ │ │
  1622. │ │ │ │
  1623. │ └───┘ │
  1624. │ │
  1625. └───────┘";
  1626. break;
  1627. case 10:
  1628. Assert.Equal (new Rect (1, 0, 6, 4), subview.Frame);
  1629. expected = @"
  1630. ┌────────┐
  1631. │ ┌────┐ │
  1632. │ │ │ │
  1633. │ │ │ │
  1634. │ └────┘ │
  1635. │ │
  1636. └────────┘";
  1637. break;
  1638. }
  1639. _ = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  1640. Application.End (rs);
  1641. }
  1642. [Fact, AutoInitShutdown]
  1643. public void PosCombine_DimCombine_View_With_SubViews ()
  1644. {
  1645. var clicked = false;
  1646. var top = Application.Top;
  1647. var win1 = new Window () { Id = "win1", Width = 20, Height = 10 };
  1648. var label = new Label ("[ ok ]");
  1649. var win2 = new Window () { Id = "win2", Y = Pos.Bottom (label) + 1, Width = 10, Height = 3 };
  1650. var view1 = new View () { Id = "view1", Width = Dim.Fill (), Height = 1, CanFocus = true };
  1651. view1.MouseClick += (sender, e) => clicked = true;
  1652. var view2 = new View () { Id = "view2", Width = Dim.Fill (1), Height = 1, CanFocus = true };
  1653. view1.Add (view2);
  1654. win2.Add (view1);
  1655. win1.Add (label, win2);
  1656. top.Add (win1);
  1657. var rs = Application.Begin (top);
  1658. TestHelpers.AssertDriverContentsWithFrameAre (@"
  1659. ┌──────────────────┐
  1660. │[ ok ] │
  1661. │ │
  1662. │┌────────┐ │
  1663. ││ │ │
  1664. │└────────┘ │
  1665. │ │
  1666. │ │
  1667. │ │
  1668. └──────────────────┘", output);
  1669. Assert.Equal (new Rect (0, 0, 80, 25), top.Frame);
  1670. Assert.Equal (new Rect (0, 0, 6, 1), label.Frame);
  1671. Assert.Equal (new Rect (0, 0, 20, 10), win1.Frame);
  1672. Assert.Equal (new Rect (0, 2, 10, 3), win2.Frame);
  1673. Assert.Equal (new Rect (0, 0, 8, 1), view1.Frame);
  1674. Assert.Equal (new Rect (0, 0, 7, 1), view2.Frame);
  1675. var foundView = View.FindDeepestView (top, 9, 4, out int rx, out int ry);
  1676. Assert.Equal (foundView, view1);
  1677. Application.OnMouseEvent (new MouseEventEventArgs (new MouseEvent () {
  1678. X = 9,
  1679. Y = 4,
  1680. Flags = MouseFlags.Button1Clicked
  1681. }));
  1682. Assert.True (clicked);
  1683. Application.End (rs);
  1684. }
  1685. [Fact, TestRespondersDisposed]
  1686. public void Draw_Vertical_Throws_IndexOutOfRangeException_With_Negative_Bounds ()
  1687. {
  1688. Application.Init (new FakeDriver ());
  1689. var top = Application.Top;
  1690. var view = new View ("view") {
  1691. Y = -2,
  1692. Height = 10,
  1693. TextDirection = TextDirection.TopBottom_LeftRight
  1694. };
  1695. top.Add (view);
  1696. Application.Iteration += (s, a) => {
  1697. Assert.Equal (-2, view.Y);
  1698. Application.RequestStop ();
  1699. };
  1700. try {
  1701. Application.Run ();
  1702. } catch (IndexOutOfRangeException ex) {
  1703. // After the fix this exception will not be caught.
  1704. Assert.IsType<IndexOutOfRangeException> (ex);
  1705. }
  1706. // Shutdown must be called to safely clean up Application if Init has been called
  1707. Application.Shutdown ();
  1708. }
  1709. [Fact, TestRespondersDisposed]
  1710. public void Draw_Throws_IndexOutOfRangeException_With_Negative_Bounds ()
  1711. {
  1712. Application.Init (new FakeDriver ());
  1713. var top = Application.Top;
  1714. var view = new View ("view") { X = -2 };
  1715. top.Add (view);
  1716. Application.Iteration += (s, a) => {
  1717. Assert.Equal (-2, view.X);
  1718. Application.RequestStop ();
  1719. };
  1720. try {
  1721. Application.Run ();
  1722. } catch (IndexOutOfRangeException ex) {
  1723. // After the fix this exception will not be caught.
  1724. Assert.IsType<IndexOutOfRangeException> (ex);
  1725. }
  1726. // Shutdown must be called to safely clean up Application if Init has been called
  1727. Application.Shutdown ();
  1728. }
  1729. }
  1730. }