LayoutTests.cs 57 KB

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