LayoutTests.cs 57 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918
  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 ("{X=0,Y=0,Width=0,Height=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 ("{X=0,Y=0,Width=8,Height=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 ("{X=0,Y=0,Width=0,Height=0}", label.Bounds.ToString ());
  265. label.Text = "New text\nNew line";
  266. Application.Top.LayoutSubviews ();
  267. Assert.False (label.AutoSize);
  268. Assert.Equal ("{X=0,Y=0,Width=28,Height=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 ("{X=0,Y=0,Width=28,Height=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 ("{X=0,Y=0,Width=0,Height=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 ("{X=0,Y=0,Width=28,Height=2}", label.Bounds.ToString ());
  292. Assert.False (label.IsInitialized);
  293. Application.Begin (Application.Top);
  294. Assert.True (label.AutoSize);
  295. Assert.Equal ("{X=0,Y=0,Width=28,Height=2}", label.Bounds.ToString ());
  296. Assert.True (label.IsInitialized);
  297. label.AutoSize = false;
  298. Application.Refresh ();
  299. Assert.False (label.AutoSize);
  300. Assert.Equal ("{X=0,Y=0,Width=28,Height=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 ("{X=0,Y=0,Width=0,Height=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 ("{X=0,Y=0,Width=28,Height=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 ("{X=0,Y=0,Width=28,Height=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 ("{X=0,Y=0,Width=28,Height=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 ("{X=0,Y=0,Width=28,Height=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 ("{X=0,Y=0,Width=28,Height=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.False (view.AutoSize);
  548. Assert.Equal (TextDirection.LeftRight_TopBottom, view.TextDirection);
  549. Assert.Equal (Rect.Empty, view.Frame);
  550. Assert.Equal ("Absolute(0)", view.X.ToString ());
  551. Assert.Equal ("Absolute(0)", view.Y.ToString ());
  552. Assert.Equal ("Absolute(0)", view.Width.ToString ());
  553. Assert.Equal ("Absolute(0)", view.Height.ToString ());
  554. var expected = @"
  555. ┌────────────────────┐
  556. │ │
  557. │ │
  558. │ │
  559. │ │
  560. │ │
  561. │ │
  562. │ │
  563. │ │
  564. │ │
  565. │ │
  566. │ │
  567. │ │
  568. │ │
  569. │ │
  570. │ │
  571. │ │
  572. │ │
  573. │ │
  574. │ │
  575. │ │
  576. └────────────────────┘
  577. ";
  578. var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  579. Assert.Equal (new Rect (0, 0, 22, 22), pos);
  580. view.Text = "Hello World";
  581. view.Width = 11;
  582. view.Height = 1;
  583. win.LayoutSubviews ();
  584. Application.Refresh ();
  585. Assert.Equal (new Rect (0, 0, 11, 1), view.Frame);
  586. Assert.Equal ("Absolute(0)", view.X.ToString ());
  587. Assert.Equal ("Absolute(0)", view.Y.ToString ());
  588. Assert.Equal ("Absolute(11)", view.Width.ToString ());
  589. Assert.Equal ("Absolute(1)", view.Height.ToString ());
  590. expected = @"
  591. ┌────────────────────┐
  592. │Hello World │
  593. │ │
  594. │ │
  595. │ │
  596. │ │
  597. │ │
  598. │ │
  599. │ │
  600. │ │
  601. │ │
  602. │ │
  603. │ │
  604. │ │
  605. │ │
  606. │ │
  607. │ │
  608. │ │
  609. │ │
  610. │ │
  611. │ │
  612. └────────────────────┘
  613. ";
  614. pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  615. Assert.Equal (new Rect (0, 0, 22, 22), pos);
  616. view.AutoSize = true;
  617. view.Text = "Hello Worlds";
  618. Application.Refresh ();
  619. Assert.Equal (new Rect (0, 0, 12, 1), view.Frame);
  620. Assert.Equal ("Absolute(0)", view.X.ToString ());
  621. Assert.Equal ("Absolute(0)", view.Y.ToString ());
  622. Assert.Equal ("Absolute(11)", view.Width.ToString ());
  623. Assert.Equal ("Absolute(1)", view.Height.ToString ());
  624. expected = @"
  625. ┌────────────────────┐
  626. │Hello Worlds │
  627. │ │
  628. │ │
  629. │ │
  630. │ │
  631. │ │
  632. │ │
  633. │ │
  634. │ │
  635. │ │
  636. │ │
  637. │ │
  638. │ │
  639. │ │
  640. │ │
  641. │ │
  642. │ │
  643. │ │
  644. │ │
  645. │ │
  646. └────────────────────┘
  647. ";
  648. pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  649. Assert.Equal (new Rect (0, 0, 22, 22), pos);
  650. view.TextDirection = TextDirection.TopBottom_LeftRight;
  651. Application.Refresh ();
  652. Assert.Equal (new Rect (0, 0, 11, 12), view.Frame);
  653. Assert.Equal ("Absolute(0)", view.X.ToString ());
  654. Assert.Equal ("Absolute(0)", view.Y.ToString ());
  655. Assert.Equal ("Absolute(11)", view.Width.ToString ());
  656. Assert.Equal ("Absolute(1)", view.Height.ToString ());
  657. expected = @"
  658. ┌────────────────────┐
  659. │H │
  660. │e │
  661. │l │
  662. │l │
  663. │o │
  664. │ │
  665. │W │
  666. │o │
  667. │r │
  668. │l │
  669. │d │
  670. │s │
  671. │ │
  672. │ │
  673. │ │
  674. │ │
  675. │ │
  676. │ │
  677. │ │
  678. │ │
  679. └────────────────────┘
  680. ";
  681. pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  682. Assert.Equal (new Rect (0, 0, 22, 22), pos);
  683. view.AutoSize = false;
  684. view.Height = 1;
  685. Application.Refresh ();
  686. Assert.Equal (new Rect (0, 0, 11, 1), view.Frame);
  687. Assert.Equal ("Absolute(0)", view.X.ToString ());
  688. Assert.Equal ("Absolute(0)", view.Y.ToString ());
  689. Assert.Equal ("Absolute(11)", view.Width.ToString ());
  690. Assert.Equal ("Absolute(1)", view.Height.ToString ());
  691. expected = @"
  692. ┌────────────────────┐
  693. │HelloWorlds │
  694. │ │
  695. │ │
  696. │ │
  697. │ │
  698. │ │
  699. │ │
  700. │ │
  701. │ │
  702. │ │
  703. │ │
  704. │ │
  705. │ │
  706. │ │
  707. │ │
  708. │ │
  709. │ │
  710. │ │
  711. │ │
  712. │ │
  713. └────────────────────┘
  714. ";
  715. pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  716. Assert.Equal (new Rect (0, 0, 22, 22), pos);
  717. view.PreserveTrailingSpaces = true;
  718. Application.Refresh ();
  719. Assert.Equal (new Rect (0, 0, 11, 1), view.Frame);
  720. Assert.Equal ("Absolute(0)", view.X.ToString ());
  721. Assert.Equal ("Absolute(0)", view.Y.ToString ());
  722. Assert.Equal ("Absolute(11)", view.Width.ToString ());
  723. Assert.Equal ("Absolute(1)", view.Height.ToString ());
  724. expected = @"
  725. ┌────────────────────┐
  726. │Hello World │
  727. │ │
  728. │ │
  729. │ │
  730. │ │
  731. │ │
  732. │ │
  733. │ │
  734. │ │
  735. │ │
  736. │ │
  737. │ │
  738. │ │
  739. │ │
  740. │ │
  741. │ │
  742. │ │
  743. │ │
  744. │ │
  745. │ │
  746. └────────────────────┘
  747. ";
  748. pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  749. Assert.Equal (new Rect (0, 0, 22, 22), pos);
  750. view.PreserveTrailingSpaces = false;
  751. var f = view.Frame;
  752. view.Width = f.Height;
  753. view.Height = f.Width;
  754. view.TextDirection = TextDirection.TopBottom_LeftRight;
  755. Application.Refresh ();
  756. Assert.Equal (new Rect (0, 0, 1, 11), view.Frame);
  757. Assert.Equal ("Absolute(0)", view.X.ToString ());
  758. Assert.Equal ("Absolute(0)", view.Y.ToString ());
  759. Assert.Equal ("Absolute(1)", view.Width.ToString ());
  760. Assert.Equal ("Absolute(11)", view.Height.ToString ());
  761. expected = @"
  762. ┌────────────────────┐
  763. │H │
  764. │e │
  765. │l │
  766. │l │
  767. │o │
  768. │ │
  769. │W │
  770. │o │
  771. │r │
  772. │l │
  773. │d │
  774. │ │
  775. │ │
  776. │ │
  777. │ │
  778. │ │
  779. │ │
  780. │ │
  781. │ │
  782. │ │
  783. └────────────────────┘
  784. ";
  785. pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  786. Assert.Equal (new Rect (0, 0, 22, 22), pos);
  787. view.AutoSize = true;
  788. Application.Refresh ();
  789. Assert.Equal (new Rect (0, 0, 1, 12), view.Frame);
  790. Assert.Equal ("Absolute(0)", view.X.ToString ());
  791. Assert.Equal ("Absolute(0)", view.Y.ToString ());
  792. Assert.Equal ("Absolute(1)", view.Width.ToString ());
  793. Assert.Equal ("Absolute(12)", view.Height.ToString ());
  794. expected = @"
  795. ┌────────────────────┐
  796. │H │
  797. │e │
  798. │l │
  799. │l │
  800. │o │
  801. │ │
  802. │W │
  803. │o │
  804. │r │
  805. │l │
  806. │d │
  807. │s │
  808. │ │
  809. │ │
  810. │ │
  811. │ │
  812. │ │
  813. │ │
  814. │ │
  815. │ │
  816. └────────────────────┘
  817. ";
  818. pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  819. Assert.Equal (new Rect (0, 0, 22, 22), pos);
  820. }
  821. [Fact, AutoInitShutdown]
  822. public void Width_Height_AutoSize_True_Stay_True_If_TextFormatter_Size_Fit ()
  823. {
  824. var text = $"Fi_nish 終";
  825. var horizontalView = new View () {
  826. Id = "horizontalView",
  827. AutoSize = true,
  828. HotKeySpecifier = '_',
  829. Text = text
  830. };
  831. var verticalView = new View () {
  832. Id = "verticalView",
  833. Y = 3,
  834. AutoSize = true,
  835. HotKeySpecifier = '_',
  836. Text = text,
  837. TextDirection = TextDirection.TopBottom_LeftRight
  838. };
  839. var win = new Window () {
  840. Id = "win",
  841. Width = Dim.Fill (),
  842. Height = Dim.Fill (),
  843. Text = "Window"
  844. };
  845. win.Add (horizontalView, verticalView);
  846. Application.Top.Add (win);
  847. Application.Begin (Application.Top);
  848. ((FakeDriver)Application.Driver).SetBufferSize (22, 22);
  849. Assert.True (horizontalView.AutoSize);
  850. Assert.True (verticalView.AutoSize);
  851. Assert.Equal (new Size (10, 1), horizontalView.TextFormatter.Size);
  852. Assert.Equal (new Size (2, 9), verticalView.TextFormatter.Size);
  853. Assert.Equal (new Rect (0, 0, 9, 1), horizontalView.Frame);
  854. Assert.Equal ("Absolute(0)", horizontalView.X.ToString ());
  855. Assert.Equal ("Absolute(0)", horizontalView.Y.ToString ());
  856. // BUGBUG - v2 - With v1 AutoSize = true Width/Height should always match Frame.Width/Height,
  857. // but in v2, autosize will be replaced by Dim.Fit. Disabling test for now.
  858. //Assert.Equal ("Absolute(9)", horizontalView.Width.ToString ());
  859. //Assert.Equal ("Absolute(1)", horizontalView.Height.ToString ());
  860. //Assert.Equal (new Rect (0, 3, 2, 8), verticalView.Frame);
  861. Assert.Equal ("Absolute(0)", verticalView.X.ToString ());
  862. Assert.Equal ("Absolute(3)", verticalView.Y.ToString ());
  863. //Assert.Equal ("Absolute(2)", verticalView.Width.ToString ());
  864. //Assert.Equal ("Absolute(8)", verticalView.Height.ToString ());
  865. var expected = @"
  866. ┌────────────────────┐
  867. │Finish 終 │
  868. │ │
  869. │ │
  870. │F │
  871. │i │
  872. │n │
  873. │i │
  874. │s │
  875. │h │
  876. │ │
  877. │終 │
  878. │ │
  879. │ │
  880. │ │
  881. │ │
  882. │ │
  883. │ │
  884. │ │
  885. │ │
  886. │ │
  887. └────────────────────┘
  888. ";
  889. var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  890. Assert.Equal (new Rect (0, 0, 22, 22), pos);
  891. verticalView.Text = $"最初_の行二行目";
  892. Application.Top.Redraw (Application.Top.Bounds);
  893. Assert.True (horizontalView.AutoSize);
  894. Assert.True (verticalView.AutoSize);
  895. // height was initialized with 8 and is kept as minimum
  896. Assert.Equal (new Rect (0, 3, 2, 7), verticalView.Frame);
  897. Assert.Equal ("Absolute(0)", verticalView.X.ToString ());
  898. Assert.Equal ("Absolute(3)", verticalView.Y.ToString ());
  899. //Assert.Equal ("Absolute(2)", verticalView.Width.ToString ());
  900. //Assert.Equal ("Absolute(8)", verticalView.Height.ToString ());
  901. expected = @"
  902. ┌────────────────────┐
  903. │Finish 終 │
  904. │ │
  905. │ │
  906. │最 │
  907. │初 │
  908. │の │
  909. │行 │
  910. │二 │
  911. │行 │
  912. │目 │
  913. │ │
  914. │ │
  915. │ │
  916. │ │
  917. │ │
  918. │ │
  919. │ │
  920. │ │
  921. │ │
  922. │ │
  923. └────────────────────┘
  924. ";
  925. pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  926. Assert.Equal (new Rect (0, 0, 22, 22), pos);
  927. }
  928. [Fact, AutoInitShutdown]
  929. public void AutoSize_Stays_True_Center_HotKeySpecifier ()
  930. {
  931. var btn = new Button () {
  932. X = Pos.Center (),
  933. Y = Pos.Center (),
  934. Text = "Say He_llo 你"
  935. };
  936. var win = new Window () {
  937. Width = Dim.Fill (),
  938. Height = Dim.Fill (),
  939. Title = "Test Demo 你"
  940. };
  941. win.Add (btn);
  942. Application.Top.Add (win);
  943. Assert.True (btn.AutoSize);
  944. Application.Begin (Application.Top);
  945. ((FakeDriver)Application.Driver).SetBufferSize (30, 5);
  946. var expected = @"
  947. ┌┤Test Demo 你├──────────────┐
  948. │ │
  949. │ [ Say Hello 你 ] │
  950. │ │
  951. └────────────────────────────┘
  952. ";
  953. TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  954. Assert.True (btn.AutoSize);
  955. btn.Text = "Say He_llo 你 changed";
  956. Assert.True (btn.AutoSize);
  957. Application.Refresh ();
  958. expected = @"
  959. ┌┤Test Demo 你├──────────────┐
  960. │ │
  961. │ [ Say Hello 你 changed ] │
  962. │ │
  963. └────────────────────────────┘
  964. ";
  965. TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  966. }
  967. [Fact, AutoInitShutdown]
  968. public void AutoSize_False_Equal_Before_And_After_IsInitialized_With_Differents_Orders ()
  969. {
  970. var view1 = new View () { Text = "Say Hello view1 你", AutoSize = false, Width = 10, Height = 5 };
  971. var view2 = new View () { Text = "Say Hello view2 你", Width = 10, Height = 5, AutoSize = false };
  972. var view3 = new View () { AutoSize = false, Width = 10, Height = 5, Text = "Say Hello view3 你" };
  973. var view4 = new View () {
  974. Text = "Say Hello view4 你",
  975. AutoSize = false,
  976. Width = 10,
  977. Height = 5,
  978. TextDirection = TextDirection.TopBottom_LeftRight
  979. };
  980. var view5 = new View () {
  981. Text = "Say Hello view5 你",
  982. Width = 10,
  983. Height = 5,
  984. AutoSize = false,
  985. TextDirection = TextDirection.TopBottom_LeftRight
  986. };
  987. var view6 = new View () {
  988. AutoSize = false,
  989. Width = 10,
  990. Height = 5,
  991. TextDirection = TextDirection.TopBottom_LeftRight,
  992. Text = "Say Hello view6 你",
  993. };
  994. Application.Top.Add (view1, view2, view3, view4, view5, view6);
  995. Assert.False (view1.IsInitialized);
  996. Assert.False (view2.IsInitialized);
  997. Assert.False (view3.IsInitialized);
  998. Assert.False (view4.IsInitialized);
  999. Assert.False (view5.IsInitialized);
  1000. Assert.False (view1.AutoSize);
  1001. Assert.Equal (new Rect (0, 0, 10, 5), view1.Frame);
  1002. Assert.Equal ("Absolute(10)", view1.Width.ToString ());
  1003. Assert.Equal ("Absolute(5)", view1.Height.ToString ());
  1004. Assert.False (view2.AutoSize);
  1005. Assert.Equal (new Rect (0, 0, 10, 5), view2.Frame);
  1006. Assert.Equal ("Absolute(10)", view2.Width.ToString ());
  1007. Assert.Equal ("Absolute(5)", view2.Height.ToString ());
  1008. Assert.False (view3.AutoSize);
  1009. Assert.Equal (new Rect (0, 0, 10, 5), view3.Frame);
  1010. Assert.Equal ("Absolute(10)", view3.Width.ToString ());
  1011. Assert.Equal ("Absolute(5)", view3.Height.ToString ());
  1012. Assert.False (view4.AutoSize);
  1013. Assert.Equal (new Rect (0, 0, 10, 5), view4.Frame);
  1014. Assert.Equal ("Absolute(10)", view4.Width.ToString ());
  1015. Assert.Equal ("Absolute(5)", view4.Height.ToString ());
  1016. Assert.False (view5.AutoSize);
  1017. Assert.Equal (new Rect (0, 0, 10, 5), view5.Frame);
  1018. Assert.Equal ("Absolute(10)", view5.Width.ToString ());
  1019. Assert.Equal ("Absolute(5)", view5.Height.ToString ());
  1020. Assert.False (view6.AutoSize);
  1021. Assert.Equal (new Rect (0, 0, 10, 5), view6.Frame);
  1022. Assert.Equal ("Absolute(10)", view6.Width.ToString ());
  1023. Assert.Equal ("Absolute(5)", view6.Height.ToString ());
  1024. Application.Begin (Application.Top);
  1025. Assert.True (view1.IsInitialized);
  1026. Assert.True (view2.IsInitialized);
  1027. Assert.True (view3.IsInitialized);
  1028. Assert.True (view4.IsInitialized);
  1029. Assert.True (view5.IsInitialized);
  1030. Assert.False (view1.AutoSize);
  1031. Assert.Equal (new Rect (0, 0, 10, 5), view1.Frame);
  1032. Assert.Equal ("Absolute(10)", view1.Width.ToString ());
  1033. Assert.Equal ("Absolute(5)", view1.Height.ToString ());
  1034. Assert.False (view2.AutoSize);
  1035. Assert.Equal (new Rect (0, 0, 10, 5), view2.Frame);
  1036. Assert.Equal ("Absolute(10)", view2.Width.ToString ());
  1037. Assert.Equal ("Absolute(5)", view2.Height.ToString ());
  1038. Assert.False (view3.AutoSize);
  1039. Assert.Equal (new Rect (0, 0, 10, 5), view3.Frame);
  1040. Assert.Equal ("Absolute(10)", view3.Width.ToString ());
  1041. Assert.Equal ("Absolute(5)", view3.Height.ToString ());
  1042. Assert.False (view4.AutoSize);
  1043. Assert.Equal (new Rect (0, 0, 10, 5), view4.Frame);
  1044. Assert.Equal ("Absolute(10)", view4.Width.ToString ());
  1045. Assert.Equal ("Absolute(5)", view4.Height.ToString ());
  1046. Assert.False (view5.AutoSize);
  1047. Assert.Equal (new Rect (0, 0, 10, 5), view5.Frame);
  1048. Assert.Equal ("Absolute(10)", view5.Width.ToString ());
  1049. Assert.Equal ("Absolute(5)", view5.Height.ToString ());
  1050. Assert.False (view6.AutoSize);
  1051. Assert.Equal (new Rect (0, 0, 10, 5), view6.Frame);
  1052. Assert.Equal ("Absolute(10)", view6.Width.ToString ());
  1053. Assert.Equal ("Absolute(5)", view6.Height.ToString ());
  1054. }
  1055. [Fact, AutoInitShutdown]
  1056. public void AutoSize_True_Equal_Before_And_After_IsInitialized_With_Different_Orders ()
  1057. {
  1058. var view1 = new View () { Text = "Say Hello view1 你", AutoSize = true, Width = 10, Height = 5 };
  1059. var view2 = new View () { Text = "Say Hello view2 你", Width = 10, Height = 5, AutoSize = true };
  1060. var view3 = new View () { AutoSize = true, Width = 10, Height = 5, Text = "Say Hello view3 你" };
  1061. var view4 = new View () {
  1062. Text = "Say Hello view4 你",
  1063. AutoSize = true,
  1064. Width = 10,
  1065. Height = 5,
  1066. TextDirection = TextDirection.TopBottom_LeftRight
  1067. };
  1068. var view5 = new View () {
  1069. Text = "Say Hello view5 你",
  1070. Width = 10,
  1071. Height = 5,
  1072. AutoSize = true,
  1073. TextDirection = TextDirection.TopBottom_LeftRight
  1074. };
  1075. var view6 = new View () {
  1076. AutoSize = true,
  1077. Width = 10,
  1078. Height = 5,
  1079. TextDirection = TextDirection.TopBottom_LeftRight,
  1080. Text = "Say Hello view6 你",
  1081. };
  1082. Application.Top.Add (view1, view2, view3, view4, view5, view6);
  1083. Assert.False (view1.IsInitialized);
  1084. Assert.False (view2.IsInitialized);
  1085. Assert.False (view3.IsInitialized);
  1086. Assert.False (view4.IsInitialized);
  1087. Assert.False (view5.IsInitialized);
  1088. Assert.True (view1.AutoSize);
  1089. Assert.Equal (new Rect (0, 0, 18, 5), view1.Frame);
  1090. Assert.Equal ("Absolute(10)", view1.Width.ToString ());
  1091. Assert.Equal ("Absolute(5)", view1.Height.ToString ());
  1092. Assert.True (view2.AutoSize);
  1093. // BUGBUG: v2 - Autosize is broken when setting Width/Height AutoSize. Disabling test for now.
  1094. //Assert.Equal (new Rect (0, 0, 18, 5), view2.Frame);
  1095. //Assert.Equal ("Absolute(10)", view2.Width.ToString ());
  1096. //Assert.Equal ("Absolute(5)", view2.Height.ToString ());
  1097. //Assert.True (view3.AutoSize);
  1098. //Assert.Equal (new Rect (0, 0, 18, 5), view3.Frame);
  1099. //Assert.Equal ("Absolute(10)", view3.Width.ToString ());
  1100. //Assert.Equal ("Absolute(5)", view3.Height.ToString ());
  1101. //Assert.True (view4.AutoSize);
  1102. //Assert.Equal (new Rect (0, 0, 10, 17), view4.Frame);
  1103. //Assert.Equal ("Absolute(10)", view4.Width.ToString ());
  1104. //Assert.Equal ("Absolute(5)", view4.Height.ToString ());
  1105. //Assert.True (view5.AutoSize);
  1106. //Assert.Equal (new Rect (0, 0, 10, 17), view5.Frame);
  1107. //Assert.Equal ("Absolute(10)", view5.Width.ToString ());
  1108. //Assert.Equal ("Absolute(5)", view5.Height.ToString ());
  1109. //Assert.True (view6.AutoSize);
  1110. //Assert.Equal (new Rect (0, 0, 10, 17), view6.Frame);
  1111. //Assert.Equal ("Absolute(10)", view6.Width.ToString ());
  1112. //Assert.Equal ("Absolute(5)", view6.Height.ToString ());
  1113. Application.Begin (Application.Top);
  1114. Assert.True (view1.IsInitialized);
  1115. Assert.True (view2.IsInitialized);
  1116. Assert.True (view3.IsInitialized);
  1117. Assert.True (view4.IsInitialized);
  1118. Assert.True (view5.IsInitialized);
  1119. Assert.True (view1.AutoSize);
  1120. Assert.Equal (new Rect (0, 0, 18, 5), view1.Frame);
  1121. Assert.Equal ("Absolute(10)", view1.Width.ToString ());
  1122. Assert.Equal ("Absolute(5)", view1.Height.ToString ());
  1123. Assert.True (view2.AutoSize);
  1124. // BUGBUG: v2 - Autosize is broken when setting Width/Height AutoSize. Disabling test for now.
  1125. //Assert.Equal (new Rect (0, 0, 18, 5), view2.Frame);
  1126. //Assert.Equal ("Absolute(10)", view2.Width.ToString ());
  1127. //Assert.Equal ("Absolute(5)", view2.Height.ToString ());
  1128. //Assert.True (view3.AutoSize);
  1129. //Assert.Equal (new Rect (0, 0, 18, 5), view3.Frame);
  1130. //Assert.Equal ("Absolute(10)", view3.Width.ToString ());
  1131. //Assert.Equal ("Absolute(5)", view3.Height.ToString ());
  1132. //Assert.True (view4.AutoSize);
  1133. //Assert.Equal (new Rect (0, 0, 10, 17), view4.Frame);
  1134. //Assert.Equal ("Absolute(10)", view4.Width.ToString ());
  1135. //Assert.Equal ("Absolute(5)", view4.Height.ToString ());
  1136. //Assert.True (view5.AutoSize);
  1137. //Assert.Equal (new Rect (0, 0, 10, 17), view5.Frame);
  1138. //Assert.Equal ("Absolute(10)", view5.Width.ToString ());
  1139. //Assert.Equal ("Absolute(5)", view5.Height.ToString ());
  1140. //Assert.True (view6.AutoSize);
  1141. //Assert.Equal (new Rect (0, 0, 10, 17), view6.Frame);
  1142. //Assert.Equal ("Absolute(10)", view6.Width.ToString ());
  1143. //Assert.Equal ("Absolute(5)", view6.Height.ToString ());
  1144. }
  1145. [Fact, AutoInitShutdown]
  1146. public void Setting_Frame_Dont_Respect_AutoSize_True_On_Layout_Absolute ()
  1147. {
  1148. var view1 = new View (new Rect (0, 0, 10, 0)) { Text = "Say Hello view1 你", AutoSize = true };
  1149. var view2 = new View (new Rect (0, 0, 0, 10)) {
  1150. Text = "Say Hello view2 你",
  1151. AutoSize = true,
  1152. TextDirection = TextDirection.TopBottom_LeftRight
  1153. };
  1154. Application.Top.Add (view1, view2);
  1155. var rs = Application.Begin (Application.Top);
  1156. Assert.True (view1.AutoSize);
  1157. Assert.Equal (LayoutStyle.Absolute, view1.LayoutStyle);
  1158. Assert.Equal (new Rect (0, 0, 18, 1), view1.Frame);
  1159. Assert.Equal ("Absolute(0)", view1.X.ToString ());
  1160. Assert.Equal ("Absolute(0)", view1.Y.ToString ());
  1161. Assert.Equal ("Absolute(18)", view1.Width.ToString ());
  1162. Assert.Equal ("Absolute(1)", view1.Height.ToString ());
  1163. Assert.True (view2.AutoSize);
  1164. // BUGBUG: v2 - Autosize is broken when setting Width/Height AutoSize. Disabling test for now.
  1165. //Assert.Equal (LayoutStyle.Absolute, view2.LayoutStyle);
  1166. //Assert.Equal (new Rect (0, 0, 2, 17), view2.Frame);
  1167. //Assert.Equal ("Absolute(0)", view2.X.ToString ());
  1168. //Assert.Equal ("Absolute(0)", view2.Y.ToString ());
  1169. //Assert.Equal ("Absolute(2)", view2.Width.ToString ());
  1170. //Assert.Equal ("Absolute(17)", view2.Height.ToString ());
  1171. view1.Frame = new Rect (0, 0, 25, 4);
  1172. bool firstIteration = false;
  1173. Application.RunMainLoopIteration (ref rs, true, ref firstIteration);
  1174. Assert.True (view1.AutoSize);
  1175. Assert.Equal (LayoutStyle.Absolute, view1.LayoutStyle);
  1176. Assert.Equal (new Rect (0, 0, 25, 4), view1.Frame);
  1177. Assert.Equal ("Absolute(0)", view1.X.ToString ());
  1178. Assert.Equal ("Absolute(0)", view1.Y.ToString ());
  1179. Assert.Equal ("Absolute(18)", view1.Width.ToString ());
  1180. Assert.Equal ("Absolute(1)", view1.Height.ToString ());
  1181. view2.Frame = new Rect (0, 0, 1, 25);
  1182. Application.RunMainLoopIteration (ref rs, true, ref firstIteration);
  1183. Assert.True (view2.AutoSize);
  1184. Assert.Equal (LayoutStyle.Absolute, view2.LayoutStyle);
  1185. Assert.Equal (new Rect (0, 0, 1, 25), view2.Frame);
  1186. Assert.Equal ("Absolute(0)", view2.X.ToString ());
  1187. Assert.Equal ("Absolute(0)", view2.Y.ToString ());
  1188. // BUGBUG: v2 - Autosize is broken when setting Width/Height AutoSize. Disabling test for now.
  1189. //Assert.Equal ("Absolute(2)", view2.Width.ToString ());
  1190. //Assert.Equal ("Absolute(17)", view2.Height.ToString ());
  1191. }
  1192. [Fact, AutoInitShutdown]
  1193. public void Pos_Dim_Are_Null_If_Not_Initialized_On_Constructor_IsAdded_False ()
  1194. {
  1195. var top = Application.Top;
  1196. var view1 = new View ();
  1197. Assert.False (view1.IsAdded);
  1198. Assert.Null (view1.X);
  1199. Assert.Null (view1.Y);
  1200. Assert.Null (view1.Width);
  1201. Assert.Null (view1.Height);
  1202. top.Add (view1);
  1203. Assert.True (view1.IsAdded);
  1204. Assert.Equal ("Absolute(0)", view1.X.ToString ());
  1205. Assert.Equal ("Absolute(0)", view1.Y.ToString ());
  1206. Assert.Equal ("Absolute(0)", view1.Width.ToString ());
  1207. Assert.Equal ("Absolute(0)", view1.Height.ToString ());
  1208. var view2 = new View () {
  1209. X = Pos.Center (),
  1210. Y = Pos.Center (),
  1211. Width = Dim.Fill (),
  1212. Height = Dim.Fill ()
  1213. };
  1214. Assert.False (view2.IsAdded);
  1215. Assert.Equal ("Center", view2.X.ToString ());
  1216. Assert.Equal ("Center", view2.Y.ToString ());
  1217. Assert.Equal ("Fill(0)", view2.Width.ToString ());
  1218. Assert.Equal ("Fill(0)", view2.Height.ToString ());
  1219. top.Add (view2);
  1220. Assert.True (view2.IsAdded);
  1221. Assert.Equal ("Center", view2.X.ToString ());
  1222. Assert.Equal ("Center", view2.Y.ToString ());
  1223. Assert.Equal ("Fill(0)", view2.Width.ToString ());
  1224. Assert.Equal ("Fill(0)", view2.Height.ToString ());
  1225. }
  1226. [Fact]
  1227. public void SetRelativeLayout_PosCombine_Center_Plus_Absolute ()
  1228. {
  1229. var superView = new View () {
  1230. AutoSize = false,
  1231. Width = 10,
  1232. Height = 10
  1233. };
  1234. var testView = new View () {
  1235. AutoSize = false,
  1236. X = Pos.Center (),
  1237. Y = Pos.Center (),
  1238. Width = 1,
  1239. Height = 1
  1240. };
  1241. superView.Add (testView);
  1242. testView.SetRelativeLayout (superView.Frame);
  1243. Assert.Equal (4, testView.Frame.X);
  1244. Assert.Equal (4, testView.Frame.Y);
  1245. testView = new View () {
  1246. AutoSize = false,
  1247. X = Pos.Center () + 1,
  1248. Y = Pos.Center () + 1,
  1249. Width = 1,
  1250. Height = 1
  1251. };
  1252. superView.Add (testView);
  1253. testView.SetRelativeLayout (superView.Frame);
  1254. Assert.Equal (5, testView.Frame.X);
  1255. Assert.Equal (5, testView.Frame.Y);
  1256. testView = new View () {
  1257. AutoSize = false,
  1258. X = 1 + Pos.Center (),
  1259. Y = 1 + Pos.Center (),
  1260. Width = 1,
  1261. Height = 1
  1262. };
  1263. superView.Add (testView);
  1264. testView.SetRelativeLayout (superView.Frame);
  1265. Assert.Equal (5, testView.Frame.X);
  1266. Assert.Equal (5, testView.Frame.Y);
  1267. testView = new View () {
  1268. AutoSize = false,
  1269. X = 1 + Pos.Percent (50),
  1270. Y = Pos.Percent (50) + 1,
  1271. Width = 1,
  1272. Height = 1
  1273. };
  1274. superView.Add (testView);
  1275. testView.SetRelativeLayout (superView.Frame);
  1276. Assert.Equal (6, testView.Frame.X);
  1277. Assert.Equal (6, testView.Frame.Y);
  1278. testView = new View () {
  1279. AutoSize = false,
  1280. X = Pos.Percent (10) + Pos.Percent (40),
  1281. Y = Pos.Percent (10) + Pos.Percent (40),
  1282. Width = 1,
  1283. Height = 1
  1284. };
  1285. superView.Add (testView);
  1286. testView.SetRelativeLayout (superView.Frame);
  1287. Assert.Equal (5, testView.Frame.X);
  1288. Assert.Equal (5, testView.Frame.Y);
  1289. testView = new View () {
  1290. AutoSize = false,
  1291. X = 1 + Pos.Percent (10) + Pos.Percent (40) - 1,
  1292. Y = 5 + Pos.Percent (10) + Pos.Percent (40) - 5,
  1293. Width = 1,
  1294. Height = 1
  1295. };
  1296. superView.Add (testView);
  1297. testView.SetRelativeLayout (superView.Frame);
  1298. Assert.Equal (5, testView.Frame.X);
  1299. Assert.Equal (5, testView.Frame.Y);
  1300. testView = new View () {
  1301. AutoSize = false,
  1302. X = Pos.Left (testView),
  1303. Y = Pos.Left (testView),
  1304. Width = 1,
  1305. Height = 1
  1306. };
  1307. superView.Add (testView);
  1308. testView.SetRelativeLayout (superView.Frame);
  1309. Assert.Equal (5, testView.Frame.X);
  1310. Assert.Equal (5, testView.Frame.Y);
  1311. testView = new View () {
  1312. AutoSize = false,
  1313. X = 1 + Pos.Left (testView),
  1314. Y = Pos.Top (testView) + 1,
  1315. Width = 1,
  1316. Height = 1
  1317. };
  1318. superView.Add (testView);
  1319. testView.SetRelativeLayout (superView.Frame);
  1320. Assert.Equal (6, testView.Frame.X);
  1321. Assert.Equal (6, testView.Frame.Y);
  1322. }
  1323. [Theory, AutoInitShutdown]
  1324. [InlineData (1)]
  1325. [InlineData (2)]
  1326. [InlineData (3)]
  1327. [InlineData (4)]
  1328. [InlineData (5)]
  1329. [InlineData (6)]
  1330. [InlineData (7)]
  1331. [InlineData (8)]
  1332. [InlineData (9)]
  1333. [InlineData (10)]
  1334. public void Dim_CenteredSubView_85_Percent_Height (int height)
  1335. {
  1336. var win = new Window () {
  1337. Width = Dim.Fill (),
  1338. Height = Dim.Fill ()
  1339. };
  1340. var subview = new Window () {
  1341. X = Pos.Center (),
  1342. Y = Pos.Center (),
  1343. Width = Dim.Percent (85),
  1344. Height = Dim.Percent (85)
  1345. };
  1346. win.Add (subview);
  1347. var rs = Application.Begin (win);
  1348. bool firstIteration = false;
  1349. ((FakeDriver)Application.Driver).SetBufferSize (20, height);
  1350. Application.RunMainLoopIteration (ref rs, true, ref firstIteration);
  1351. var expected = string.Empty;
  1352. switch (height) {
  1353. case 1:
  1354. //Assert.Equal (new Rect (0, 0, 17, 0), subview.Frame);
  1355. expected = @"
  1356. ────────────────────";
  1357. break;
  1358. case 2:
  1359. //Assert.Equal (new Rect (0, 0, 17, 1), subview.Frame);
  1360. expected = @"
  1361. ┌──────────────────┐
  1362. └──────────────────┘
  1363. ";
  1364. break;
  1365. case 3:
  1366. //Assert.Equal (new Rect (0, 0, 17, 2), subview.Frame);
  1367. expected = @"
  1368. ┌──────────────────┐
  1369. │ │
  1370. └──────────────────┘
  1371. ";
  1372. break;
  1373. case 4:
  1374. //Assert.Equal (new Rect (0, 0, 17, 3), subview.Frame);
  1375. expected = @"
  1376. ┌──────────────────┐
  1377. │ ─────────────── │
  1378. │ │
  1379. └──────────────────┘";
  1380. break;
  1381. case 5:
  1382. //Assert.Equal (new Rect (0, 0, 17, 3), subview.Frame);
  1383. expected = @"
  1384. ┌──────────────────┐
  1385. │ ┌─────────────┐ │
  1386. │ └─────────────┘ │
  1387. │ │
  1388. └──────────────────┘";
  1389. break;
  1390. case 6:
  1391. //Assert.Equal (new Rect (0, 0, 17, 3), subview.Frame);
  1392. expected = @"
  1393. ┌──────────────────┐
  1394. │ ┌─────────────┐ │
  1395. │ │ │ │
  1396. │ └─────────────┘ │
  1397. │ │
  1398. └──────────────────┘";
  1399. break;
  1400. case 7:
  1401. //Assert.Equal (new Rect (0, 0, 17, 3), subview.Frame);
  1402. expected = @"
  1403. ┌──────────────────┐
  1404. │ ┌─────────────┐ │
  1405. │ │ │ │
  1406. │ │ │ │
  1407. │ └─────────────┘ │
  1408. │ │
  1409. └──────────────────┘";
  1410. break;
  1411. case 8:
  1412. //Assert.Equal (new Rect (0, 0, 17, 3), subview.Frame);
  1413. expected = @"
  1414. ┌──────────────────┐
  1415. │ ┌─────────────┐ │
  1416. │ │ │ │
  1417. │ │ │ │
  1418. │ │ │ │
  1419. │ └─────────────┘ │
  1420. │ │
  1421. └──────────────────┘";
  1422. break;
  1423. case 9:
  1424. //Assert.Equal (new Rect (0, 0, 17, 3), subview.Frame);
  1425. expected = @"
  1426. ┌──────────────────┐
  1427. │ │
  1428. │ ┌─────────────┐ │
  1429. │ │ │ │
  1430. │ │ │ │
  1431. │ │ │ │
  1432. │ └─────────────┘ │
  1433. │ │
  1434. └──────────────────┘";
  1435. break;
  1436. case 10:
  1437. //Assert.Equal (new Rect (0, 0, 17, 3), subview.Frame);
  1438. expected = @"
  1439. ┌──────────────────┐
  1440. │ │
  1441. │ ┌─────────────┐ │
  1442. │ │ │ │
  1443. │ │ │ │
  1444. │ │ │ │
  1445. │ │ │ │
  1446. │ └─────────────┘ │
  1447. │ │
  1448. └──────────────────┘";
  1449. break;
  1450. }
  1451. _ = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  1452. }
  1453. [Theory, AutoInitShutdown]
  1454. [InlineData (1)]
  1455. [InlineData (2)]
  1456. [InlineData (3)]
  1457. [InlineData (4)]
  1458. [InlineData (5)]
  1459. [InlineData (6)]
  1460. [InlineData (7)]
  1461. [InlineData (8)]
  1462. [InlineData (9)]
  1463. [InlineData (10)]
  1464. public void Dim_CenteredSubView_85_Percent_Width (int width)
  1465. {
  1466. var win = new Window () {
  1467. Width = Dim.Fill (),
  1468. Height = Dim.Fill ()
  1469. };
  1470. var subview = new Window () {
  1471. X = Pos.Center (),
  1472. Y = Pos.Center (),
  1473. Width = Dim.Percent (85),
  1474. Height = Dim.Percent (85)
  1475. };
  1476. win.Add (subview);
  1477. var rs = Application.Begin (win);
  1478. bool firstIteration = false;
  1479. ((FakeDriver)Application.Driver).SetBufferSize (width, 7);
  1480. Application.RunMainLoopIteration (ref rs, true, ref firstIteration);
  1481. var expected = string.Empty;
  1482. switch (width) {
  1483. case 1:
  1484. Assert.Equal (new Rect (0, 0, 0, 4), subview.Frame);
  1485. expected = @"
  1486. │";
  1487. break;
  1488. case 2:
  1489. Assert.Equal (new Rect (0, 0, 0, 4), subview.Frame);
  1490. expected = @"
  1491. ┌┐
  1492. ││
  1493. ││
  1494. ││
  1495. ││
  1496. ││
  1497. └┘";
  1498. break;
  1499. case 3:
  1500. Assert.Equal (new Rect (0, 0, 0, 4), subview.Frame);
  1501. expected = @"
  1502. ┌─┐
  1503. │ │
  1504. │ │
  1505. │ │
  1506. │ │
  1507. │ │
  1508. └─┘
  1509. ";
  1510. break;
  1511. case 4:
  1512. Assert.Equal (new Rect (0, 0, 1, 4), subview.Frame);
  1513. expected = @"
  1514. ┌──┐
  1515. ││ │
  1516. ││ │
  1517. ││ │
  1518. ││ │
  1519. │ │
  1520. └──┘";
  1521. break;
  1522. case 5:
  1523. Assert.Equal (new Rect (0, 0, 2, 4), subview.Frame);
  1524. expected = @"
  1525. ┌───┐
  1526. │┌┐ │
  1527. │││ │
  1528. │││ │
  1529. │└┘ │
  1530. │ │
  1531. └───┘";
  1532. break;
  1533. case 6:
  1534. Assert.Equal (new Rect (0, 0, 3, 4), subview.Frame);
  1535. expected = @"
  1536. ┌────┐
  1537. │┌─┐ │
  1538. ││ │ │
  1539. ││ │ │
  1540. │└─┘ │
  1541. │ │
  1542. └────┘";
  1543. break;
  1544. case 7:
  1545. Assert.Equal (new Rect (0, 0, 4, 4), subview.Frame);
  1546. expected = @"
  1547. ┌─────┐
  1548. │┌──┐ │
  1549. ││ │ │
  1550. ││ │ │
  1551. │└──┘ │
  1552. │ │
  1553. └─────┘";
  1554. break;
  1555. case 8:
  1556. Assert.Equal (new Rect (0, 0, 5, 4), subview.Frame);
  1557. expected = @"
  1558. ┌──────┐
  1559. │┌───┐ │
  1560. ││ │ │
  1561. ││ │ │
  1562. │└───┘ │
  1563. │ │
  1564. └──────┘";
  1565. break;
  1566. case 9:
  1567. Assert.Equal (new Rect (1, 0, 5, 4), subview.Frame);
  1568. expected = @"
  1569. ┌───────┐
  1570. │ ┌───┐ │
  1571. │ │ │ │
  1572. │ │ │ │
  1573. │ └───┘ │
  1574. │ │
  1575. └───────┘";
  1576. break;
  1577. case 10:
  1578. Assert.Equal (new Rect (1, 0, 6, 4), subview.Frame);
  1579. expected = @"
  1580. ┌────────┐
  1581. │ ┌────┐ │
  1582. │ │ │ │
  1583. │ │ │ │
  1584. │ └────┘ │
  1585. │ │
  1586. └────────┘";
  1587. break;
  1588. }
  1589. _ = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  1590. }
  1591. [Fact, AutoInitShutdown]
  1592. public void PosCombine_DimCombine_View_With_SubViews ()
  1593. {
  1594. var clicked = false;
  1595. var top = Application.Top;
  1596. var win1 = new Window () { Id = "win1", Width = 20, Height = 10 };
  1597. var btn = new Button ("ok");
  1598. var win2 = new Window () { Id = "win2", Y = Pos.Bottom (btn) + 1, Width = 10, Height = 3 };
  1599. var view1 = new View () { Id = "view1", Width = Dim.Fill (), Height = 1, CanFocus = true };
  1600. view1.MouseClick += (sender, e) => clicked = true;
  1601. var view2 = new View () { Id = "view2", Width = Dim.Fill (1), Height = 1, CanFocus = true };
  1602. view1.Add (view2);
  1603. win2.Add (view1);
  1604. win1.Add (btn, win2);
  1605. top.Add (win1);
  1606. var rs = Application.Begin (top);
  1607. TestHelpers.AssertDriverContentsWithFrameAre (@"
  1608. ┌──────────────────┐
  1609. │[ ok ] │
  1610. │ │
  1611. │┌────────┐ │
  1612. ││ │ │
  1613. │└────────┘ │
  1614. │ │
  1615. │ │
  1616. │ │
  1617. └──────────────────┘", output);
  1618. Assert.Equal (new Rect (0, 0, 80, 25), top.Frame);
  1619. Assert.Equal (new Rect (0, 0, 6, 1), btn.Frame);
  1620. Assert.Equal (new Rect (0, 0, 20, 10), win1.Frame);
  1621. Assert.Equal (new Rect (0, 2, 10, 3), win2.Frame);
  1622. Assert.Equal (new Rect (0, 0, 8, 1), view1.Frame);
  1623. Assert.Equal (new Rect (0, 0, 7, 1), view2.Frame);
  1624. var foundView = View.FindDeepestView (top, 9, 4, out int rx, out int ry);
  1625. Assert.Equal (foundView, view1);
  1626. ReflectionTools.InvokePrivate (
  1627. typeof (Application),
  1628. "ProcessMouseEvent",
  1629. new MouseEvent () {
  1630. X = 9,
  1631. Y = 4,
  1632. Flags = MouseFlags.Button1Clicked
  1633. });
  1634. Assert.True (clicked);
  1635. Application.End (rs);
  1636. }
  1637. [Fact]
  1638. public void Draw_Vertical_Throws_IndexOutOfRangeException_With_Negative_Bounds ()
  1639. {
  1640. Application.Init (new FakeDriver ());
  1641. var top = Application.Top;
  1642. var view = new View ("view") {
  1643. Y = -2,
  1644. Height = 10,
  1645. TextDirection = TextDirection.TopBottom_LeftRight
  1646. };
  1647. top.Add (view);
  1648. Application.Iteration += () => {
  1649. Assert.Equal (-2, view.Y);
  1650. Application.RequestStop ();
  1651. };
  1652. try {
  1653. Application.Run ();
  1654. } catch (IndexOutOfRangeException ex) {
  1655. // After the fix this exception will not be caught.
  1656. Assert.IsType<IndexOutOfRangeException> (ex);
  1657. }
  1658. // Shutdown must be called to safely clean up Application if Init has been called
  1659. Application.Shutdown ();
  1660. }
  1661. [Fact]
  1662. public void Draw_Throws_IndexOutOfRangeException_With_Negative_Bounds ()
  1663. {
  1664. Application.Init (new FakeDriver ());
  1665. var top = Application.Top;
  1666. var view = new View ("view") { X = -2 };
  1667. top.Add (view);
  1668. Application.Iteration += () => {
  1669. Assert.Equal (-2, view.X);
  1670. Application.RequestStop ();
  1671. };
  1672. try {
  1673. Application.Run ();
  1674. } catch (IndexOutOfRangeException ex) {
  1675. // After the fix this exception will not be caught.
  1676. Assert.IsType<IndexOutOfRangeException> (ex);
  1677. }
  1678. // Shutdown must be called to safely clean up Application if Init has been called
  1679. Application.Shutdown ();
  1680. }
  1681. }
  1682. }