LayoutTests.cs 57 KB

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