DimTests.cs 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Globalization;
  5. using System.IO;
  6. using System.Linq;
  7. using System.Threading;
  8. using Terminal.Gui;
  9. using Xunit;
  10. using Xunit.Abstractions;
  11. // Alias Console to MockConsole so we don't accidentally use Console
  12. using Console = Terminal.Gui.FakeConsole;
  13. namespace Terminal.Gui.TypeTests {
  14. public class DimTests {
  15. readonly ITestOutputHelper output;
  16. public DimTests (ITestOutputHelper output)
  17. {
  18. this.output = output;
  19. Console.OutputEncoding = System.Text.Encoding.Default;
  20. // Change current culture
  21. var culture = CultureInfo.CreateSpecificCulture ("en-US");
  22. Thread.CurrentThread.CurrentCulture = culture;
  23. Thread.CurrentThread.CurrentUICulture = culture;
  24. }
  25. [Fact]
  26. public void New_Works ()
  27. {
  28. var dim = new Dim ();
  29. Assert.Equal ("Terminal.Gui.Dim", dim.ToString ());
  30. }
  31. [Fact]
  32. public void Sized_SetsValue ()
  33. {
  34. var dim = Dim.Sized (0);
  35. Assert.Equal ("Dim.Absolute(0)", dim.ToString ());
  36. int testVal = 5;
  37. dim = Dim.Sized (testVal);
  38. Assert.Equal ($"Dim.Absolute({testVal})", dim.ToString ());
  39. testVal = -1;
  40. dim = Dim.Sized (testVal);
  41. Assert.Equal ($"Dim.Absolute({testVal})", dim.ToString ());
  42. }
  43. [Fact]
  44. public void Sized_Equals ()
  45. {
  46. int n1 = 0;
  47. int n2 = 0;
  48. var dim1 = Dim.Sized (n1);
  49. var dim2 = Dim.Sized (n2);
  50. Assert.Equal (dim1, dim2);
  51. n1 = n2 = 1;
  52. dim1 = Dim.Sized (n1);
  53. dim2 = Dim.Sized (n2);
  54. Assert.Equal (dim1, dim2);
  55. n1 = n2 = -1;
  56. dim1 = Dim.Sized (n1);
  57. dim2 = Dim.Sized (n2);
  58. Assert.Equal (dim1, dim2);
  59. n1 = 0;
  60. n2 = 1;
  61. dim1 = Dim.Sized (n1);
  62. dim2 = Dim.Sized (n2);
  63. Assert.NotEqual (dim1, dim2);
  64. }
  65. [Fact]
  66. public void Width_SetsValue ()
  67. {
  68. var dim = Dim.Width (null);
  69. Assert.Throws<NullReferenceException> (() => dim.ToString ());
  70. var testVal = Rect.Empty;
  71. testVal = Rect.Empty;
  72. dim = Dim.Width (new View (testVal));
  73. Assert.Equal ($"DimView(side=Width, target=View()({{X={testVal.X},Y={testVal.Y},Width={testVal.Width},Height={testVal.Height}}}))", dim.ToString ());
  74. testVal = new Rect (1, 2, 3, 4);
  75. dim = Dim.Width (new View (testVal));
  76. Assert.Equal ($"DimView(side=Width, target=View()({{X={testVal.X},Y={testVal.Y},Width={testVal.Width},Height={testVal.Height}}}))", dim.ToString ());
  77. }
  78. [Fact]
  79. public void Width_Equals ()
  80. {
  81. var testRect1 = Rect.Empty;
  82. var view1 = new View (testRect1);
  83. var testRect2 = Rect.Empty;
  84. var view2 = new View (testRect2);
  85. var dim1 = Dim.Width (view1);
  86. var dim2 = Dim.Width (view1);
  87. // FIXED: Dim.Width should support Equals() and this should change to Equal.
  88. Assert.Equal (dim1, dim2);
  89. dim2 = Dim.Width (view2);
  90. Assert.NotEqual (dim1, dim2);
  91. testRect1 = new Rect (0, 1, 2, 3);
  92. view1 = new View (testRect1);
  93. testRect2 = new Rect (0, 1, 2, 3);
  94. dim1 = Dim.Width (view1);
  95. dim2 = Dim.Width (view1);
  96. // FIXED: Dim.Width should support Equals() and this should change to Equal.
  97. Assert.Equal (dim1, dim2);
  98. Assert.Throws<ArgumentException> (() => new Rect (0, -1, -2, -3));
  99. testRect1 = new Rect (0, -1, 2, 3);
  100. view1 = new View (testRect1);
  101. testRect2 = new Rect (0, -1, 2, 3);
  102. dim1 = Dim.Width (view1);
  103. dim2 = Dim.Width (view1);
  104. // FIXED: Dim.Width should support Equals() and this should change to Equal.
  105. Assert.Equal (dim1, dim2);
  106. testRect1 = new Rect (0, -1, 2, 3);
  107. view1 = new View (testRect1);
  108. testRect2 = Rect.Empty;
  109. view2 = new View (testRect2);
  110. dim1 = Dim.Width (view1);
  111. dim2 = Dim.Width (view2);
  112. Assert.NotEqual (dim1, dim2);
  113. }
  114. [Fact]
  115. public void Height_SetsValue ()
  116. {
  117. var dim = Dim.Height (null);
  118. Assert.Throws<NullReferenceException> (() => dim.ToString ());
  119. var testVal = Rect.Empty;
  120. testVal = Rect.Empty;
  121. dim = Dim.Height (new View (testVal));
  122. Assert.Equal ($"DimView(side=Height, target=View()({{X={testVal.X},Y={testVal.Y},Width={testVal.Width},Height={testVal.Height}}}))", dim.ToString ());
  123. testVal = new Rect (1, 2, 3, 4);
  124. dim = Dim.Height (new View (testVal));
  125. Assert.Equal ($"DimView(side=Height, target=View()({{X={testVal.X},Y={testVal.Y},Width={testVal.Width},Height={testVal.Height}}}))", dim.ToString ());
  126. }
  127. // TODO: Other Dim.Height tests (e.g. Equal?)
  128. [Fact]
  129. public void Fill_SetsValue ()
  130. {
  131. var testMargin = 0;
  132. var dim = Dim.Fill ();
  133. Assert.Equal ($"Dim.Fill(margin={testMargin})", dim.ToString ());
  134. testMargin = 0;
  135. dim = Dim.Fill (testMargin);
  136. Assert.Equal ($"Dim.Fill(margin={testMargin})", dim.ToString ());
  137. testMargin = 5;
  138. dim = Dim.Fill (testMargin);
  139. Assert.Equal ($"Dim.Fill(margin={testMargin})", dim.ToString ());
  140. }
  141. [Fact]
  142. public void Fill_Equal ()
  143. {
  144. var margin1 = 0;
  145. var margin2 = 0;
  146. var dim1 = Dim.Fill (margin1);
  147. var dim2 = Dim.Fill (margin2);
  148. Assert.Equal (dim1, dim2);
  149. }
  150. [Fact]
  151. public void Percent_SetsValue ()
  152. {
  153. float f = 0;
  154. var dim = Dim.Percent (f);
  155. Assert.Equal ($"Dim.Factor(factor={f / 100:0.###}, remaining={false})", dim.ToString ());
  156. f = 0.5F;
  157. dim = Dim.Percent (f);
  158. Assert.Equal ($"Dim.Factor(factor={f / 100:0.###}, remaining={false})", dim.ToString ());
  159. f = 100;
  160. dim = Dim.Percent (f);
  161. Assert.Equal ($"Dim.Factor(factor={f / 100:0.###}, remaining={false})", dim.ToString ());
  162. }
  163. [Fact]
  164. public void Percent_Equals ()
  165. {
  166. float n1 = 0;
  167. float n2 = 0;
  168. var dim1 = Dim.Percent (n1);
  169. var dim2 = Dim.Percent (n2);
  170. Assert.Equal (dim1, dim2);
  171. n1 = n2 = 1;
  172. dim1 = Dim.Percent (n1);
  173. dim2 = Dim.Percent (n2);
  174. Assert.Equal (dim1, dim2);
  175. n1 = n2 = 0.5f;
  176. dim1 = Dim.Percent (n1);
  177. dim2 = Dim.Percent (n2);
  178. Assert.Equal (dim1, dim2);
  179. n1 = n2 = 100f;
  180. dim1 = Dim.Percent (n1);
  181. dim2 = Dim.Percent (n2);
  182. Assert.Equal (dim1, dim2);
  183. n1 = n2 = 0.3f;
  184. dim1 = Dim.Percent (n1, true);
  185. dim2 = Dim.Percent (n2, true);
  186. Assert.Equal (dim1, dim2);
  187. n1 = n2 = 0.3f;
  188. dim1 = Dim.Percent (n1);
  189. dim2 = Dim.Percent (n2, true);
  190. Assert.NotEqual (dim1, dim2);
  191. n1 = 0;
  192. n2 = 1;
  193. dim1 = Dim.Percent (n1);
  194. dim2 = Dim.Percent (n2);
  195. Assert.NotEqual (dim1, dim2);
  196. n1 = 0.5f;
  197. n2 = 1.5f;
  198. dim1 = Dim.Percent (n1);
  199. dim2 = Dim.Percent (n2);
  200. Assert.NotEqual (dim1, dim2);
  201. }
  202. [Fact]
  203. public void Percent_ThrowsOnIvalid ()
  204. {
  205. var dim = Dim.Percent (0);
  206. Assert.Throws<ArgumentException> (() => dim = Dim.Percent (-1));
  207. Assert.Throws<ArgumentException> (() => dim = Dim.Percent (101));
  208. Assert.Throws<ArgumentException> (() => dim = Dim.Percent (100.0001F));
  209. Assert.Throws<ArgumentException> (() => dim = Dim.Percent (1000001));
  210. }
  211. [Fact]
  212. public void ForceValidatePosDim_True_Dim_Validation_Throws_If_NewValue_Is_DimAbsolute_And_OldValue_Is_Another_Type ()
  213. {
  214. Application.Init (new FakeDriver ());
  215. var t = Application.Top;
  216. var w = new Window ("w") {
  217. Width = Dim.Fill (0),
  218. Height = Dim.Sized (10)
  219. };
  220. var v = new View ("v") {
  221. Width = Dim.Width (w) - 2,
  222. Height = Dim.Percent (10),
  223. ForceValidatePosDim = true
  224. };
  225. w.Add (v);
  226. t.Add (w);
  227. t.Ready += () => {
  228. Assert.Equal (2, w.Width = 2);
  229. Assert.Equal (2, w.Height = 2);
  230. Assert.Throws<ArgumentException> (() => v.Width = 2);
  231. Assert.Throws<ArgumentException> (() => v.Height = 2);
  232. v.ForceValidatePosDim = false;
  233. var exception = Record.Exception (() => v.Width = 2);
  234. Assert.Null (exception);
  235. Assert.Equal (2, v.Width);
  236. exception = Record.Exception (() => v.Height = 2);
  237. Assert.Null (exception);
  238. Assert.Equal (2, v.Height);
  239. };
  240. Application.Iteration += () => Application.RequestStop ();
  241. Application.Run ();
  242. Application.Shutdown ();
  243. }
  244. [Fact]
  245. public void Dim_Validation_Do_Not_Throws_If_NewValue_Is_DimAbsolute_And_OldValue_Is_Null ()
  246. {
  247. Application.Init (new FakeDriver ());
  248. var t = Application.Top;
  249. var w = new Window (new Rect (1, 2, 4, 5), "w");
  250. t.Add (w);
  251. t.Ready += () => {
  252. Assert.Equal (3, w.Width = 3);
  253. Assert.Equal (4, w.Height = 4);
  254. };
  255. Application.Iteration += () => Application.RequestStop ();
  256. Application.Run ();
  257. Application.Shutdown ();
  258. }
  259. [Fact]
  260. public void Dim_Validation_Do_Not_Throws_If_NewValue_Is_DimAbsolute_And_OldValue_Is_Another_Type_After_Sets_To_LayoutStyle_Absolute ()
  261. {
  262. Application.Init (new FakeDriver ());
  263. var t = Application.Top;
  264. var w = new Window ("w") {
  265. Width = Dim.Fill (0),
  266. Height = Dim.Sized (10)
  267. };
  268. var v = new View ("v") {
  269. Width = Dim.Width (w) - 2,
  270. Height = Dim.Percent (10)
  271. };
  272. w.Add (v);
  273. t.Add (w);
  274. t.Ready += () => {
  275. v.LayoutStyle = LayoutStyle.Absolute;
  276. Assert.Equal (2, v.Width = 2);
  277. Assert.Equal (2, v.Height = 2);
  278. };
  279. Application.Iteration += () => Application.RequestStop ();
  280. Application.Run ();
  281. Application.Shutdown ();
  282. }
  283. [Fact]
  284. public void Only_DimAbsolute_And_DimFactor_As_A_Different_Procedure_For_Assigning_Value_To_Width_Or_Height ()
  285. {
  286. // Testing with the Button because it properly handles the Dim class.
  287. Application.Init (new FakeDriver ());
  288. var t = Application.Top;
  289. var w = new Window ("w") {
  290. Width = 100,
  291. Height = 100
  292. };
  293. var f1 = new FrameView ("f1") {
  294. X = 0,
  295. Y = 0,
  296. Width = Dim.Percent (50),
  297. Height = 5
  298. };
  299. var f2 = new FrameView ("f2") {
  300. X = Pos.Right (f1),
  301. Y = 0,
  302. Width = Dim.Fill (),
  303. Height = 5
  304. };
  305. var v1 = new Button ("v1") {
  306. AutoSize = false,
  307. X = Pos.X (f1) + 2,
  308. Y = Pos.Bottom (f1) + 2,
  309. Width = Dim.Width (f1) - 2,
  310. Height = Dim.Fill () - 2,
  311. ForceValidatePosDim = true
  312. };
  313. var v2 = new Button ("v2") {
  314. AutoSize = false,
  315. X = Pos.X (f2) + 2,
  316. Y = Pos.Bottom (f2) + 2,
  317. Width = Dim.Width (f2) - 2,
  318. Height = Dim.Fill () - 2,
  319. ForceValidatePosDim = true
  320. };
  321. var v3 = new Button ("v3") {
  322. AutoSize = false,
  323. Width = Dim.Percent (10),
  324. Height = Dim.Percent (10),
  325. ForceValidatePosDim = true
  326. };
  327. var v4 = new Button ("v4") {
  328. AutoSize = false,
  329. Width = Dim.Sized (50),
  330. Height = Dim.Sized (50),
  331. ForceValidatePosDim = true
  332. };
  333. var v5 = new Button ("v5") {
  334. AutoSize = false,
  335. Width = Dim.Width (v1) - Dim.Width (v3),
  336. Height = Dim.Height (v1) - Dim.Height (v3),
  337. ForceValidatePosDim = true
  338. };
  339. var v6 = new Button ("v6") {
  340. AutoSize = false,
  341. X = Pos.X (f2),
  342. Y = Pos.Bottom (f2) + 2,
  343. Width = Dim.Percent (20, true),
  344. Height = Dim.Percent (20, true),
  345. ForceValidatePosDim = true
  346. };
  347. w.Add (f1, f2, v1, v2, v3, v4, v5, v6);
  348. t.Add (w);
  349. t.Ready += () => {
  350. Assert.Equal ("Dim.Absolute(100)", w.Width.ToString ());
  351. Assert.Equal ("Dim.Absolute(100)", w.Height.ToString ());
  352. Assert.Equal (100, w.Frame.Width);
  353. Assert.Equal (100, w.Frame.Height);
  354. Assert.Equal ("Dim.Factor(factor=0.5, remaining=False)", f1.Width.ToString ());
  355. Assert.Equal ("Dim.Absolute(5)", f1.Height.ToString ());
  356. Assert.Equal (49, f1.Frame.Width); // 50-1=49
  357. Assert.Equal (5, f1.Frame.Height);
  358. Assert.Equal ("Dim.Fill(margin=0)", f2.Width.ToString ());
  359. Assert.Equal ("Dim.Absolute(5)", f2.Height.ToString ());
  360. Assert.Equal (49, f2.Frame.Width); // 50-1=49
  361. Assert.Equal (5, f2.Frame.Height);
  362. Assert.Equal ("Dim.Combine(DimView(side=Width, target=FrameView()({X=0,Y=0,Width=49,Height=5}))-Dim.Absolute(2))", v1.Width.ToString ());
  363. Assert.Equal ("Dim.Combine(Dim.Fill(margin=0)-Dim.Absolute(2))", v1.Height.ToString ());
  364. Assert.Equal (47, v1.Frame.Width); // 49-2=47
  365. Assert.Equal (89, v1.Frame.Height); // 98-5-2-2=89
  366. Assert.Equal ("Dim.Combine(DimView(side=Width, target=FrameView()({X=49,Y=0,Width=49,Height=5}))-Dim.Absolute(2))", v2.Width.ToString ());
  367. Assert.Equal ("Dim.Combine(Dim.Fill(margin=0)-Dim.Absolute(2))", v2.Height.ToString ());
  368. Assert.Equal (47, v2.Frame.Width); // 49-2=47
  369. Assert.Equal (89, v2.Frame.Height); // 98-5-2-2=89
  370. Assert.Equal ("Dim.Factor(factor=0.1, remaining=False)", v3.Width.ToString ());
  371. Assert.Equal ("Dim.Factor(factor=0.1, remaining=False)", v3.Height.ToString ());
  372. Assert.Equal (9, v3.Frame.Width); // 98*10%=9
  373. Assert.Equal (9, v3.Frame.Height); // 98*10%=9
  374. Assert.Equal ("Dim.Absolute(50)", v4.Width.ToString ());
  375. Assert.Equal ("Dim.Absolute(50)", v4.Height.ToString ());
  376. Assert.Equal (50, v4.Frame.Width);
  377. Assert.Equal (50, v4.Frame.Height);
  378. Assert.Equal ("Dim.Combine(DimView(side=Width, target=Button()({X=2,Y=7,Width=47,Height=89}))-DimView(side=Width, target=Button()({X=0,Y=0,Width=9,Height=9})))", v5.Width.ToString ());
  379. Assert.Equal ("Dim.Combine(DimView(side=Height, target=Button()({X=2,Y=7,Width=47,Height=89}))-DimView(side=Height, target=Button()({X=0,Y=0,Width=9,Height=9})))", v5.Height.ToString ());
  380. Assert.Equal (38, v5.Frame.Width); // 47-9=38
  381. Assert.Equal (80, v5.Frame.Height); // 89-9=80
  382. Assert.Equal ("Dim.Factor(factor=0.2, remaining=True)", v6.Width.ToString ());
  383. Assert.Equal ("Dim.Factor(factor=0.2, remaining=True)", v6.Height.ToString ());
  384. Assert.Equal (9, v6.Frame.Width); // 47*20%=9
  385. Assert.Equal (18, v6.Frame.Height); // 89*20%=18
  386. w.Width = 200;
  387. w.Height = 200;
  388. t.LayoutSubviews ();
  389. Assert.Equal ("Dim.Absolute(200)", w.Width.ToString ());
  390. Assert.Equal ("Dim.Absolute(200)", w.Height.ToString ());
  391. Assert.Equal (200, w.Frame.Width);
  392. Assert.Equal (200, w.Frame.Height);
  393. f1.Text = "Frame1";
  394. Assert.Equal ("Dim.Factor(factor=0.5, remaining=False)", f1.Width.ToString ());
  395. Assert.Equal ("Dim.Absolute(5)", f1.Height.ToString ());
  396. Assert.Equal (99, f1.Frame.Width); // 100-1=99
  397. Assert.Equal (5, f1.Frame.Height);
  398. f2.Text = "Frame2";
  399. Assert.Equal ("Dim.Fill(margin=0)", f2.Width.ToString ());
  400. Assert.Equal ("Dim.Absolute(5)", f2.Height.ToString ());
  401. Assert.Equal (99, f2.Frame.Width); // 100-1=99
  402. Assert.Equal (5, f2.Frame.Height);
  403. v1.Text = "Button1";
  404. Assert.Equal ("Dim.Combine(DimView(side=Width, target=FrameView()({X=0,Y=0,Width=99,Height=5}))-Dim.Absolute(2))", v1.Width.ToString ());
  405. Assert.Equal ("Dim.Combine(Dim.Fill(margin=0)-Dim.Absolute(2))", v1.Height.ToString ());
  406. Assert.Equal (97, v1.Frame.Width); // 99-2=97
  407. Assert.Equal (189, v1.Frame.Height); // 198-2-7=189
  408. v2.Text = "Button2";
  409. Assert.Equal ("Dim.Combine(DimView(side=Width, target=FrameView()({X=99,Y=0,Width=99,Height=5}))-Dim.Absolute(2))", v2.Width.ToString ());
  410. Assert.Equal ("Dim.Combine(Dim.Fill(margin=0)-Dim.Absolute(2))", v2.Height.ToString ());
  411. Assert.Equal (97, v2.Frame.Width); // 99-2=97
  412. Assert.Equal (189, v2.Frame.Height); // 198-2-7=189
  413. v3.Text = "Button3";
  414. Assert.Equal ("Dim.Factor(factor=0.1, remaining=False)", v3.Width.ToString ());
  415. Assert.Equal ("Dim.Factor(factor=0.1, remaining=False)", v3.Height.ToString ());
  416. Assert.Equal (19, v3.Frame.Width); // 198*10%=19 * Percent is related to the super-view if it isn't null otherwise the view width
  417. Assert.Equal (19, v3.Frame.Height); // 199*10%=19
  418. v4.Text = "Button4";
  419. v4.AutoSize = false;
  420. Assert.Equal ("Dim.Absolute(50)", v4.Width.ToString ());
  421. Assert.Equal ("Dim.Absolute(50)", v4.Height.ToString ());
  422. Assert.Equal (50, v4.Frame.Width);
  423. Assert.Equal (50, v4.Frame.Height);
  424. v4.AutoSize = true;
  425. Assert.Equal ("Dim.Absolute(11)", v4.Width.ToString ());
  426. Assert.Equal ("Dim.Absolute(1)", v4.Height.ToString ());
  427. Assert.Equal (11, v4.Frame.Width); // 11 is the text length and because is Dim.DimAbsolute
  428. Assert.Equal (1, v4.Frame.Height); // 1 because is Dim.DimAbsolute
  429. v5.Text = "Button5";
  430. Assert.Equal ("Dim.Combine(DimView(side=Width, target=Button()({X=2,Y=7,Width=97,Height=189}))-DimView(side=Width, target=Button()({X=0,Y=0,Width=19,Height=19})))", v5.Width.ToString ());
  431. Assert.Equal ("Dim.Combine(DimView(side=Height, target=Button()({X=2,Y=7,Width=97,Height=189}))-DimView(side=Height, target=Button()({X=0,Y=0,Width=19,Height=19})))", v5.Height.ToString ());
  432. Assert.Equal (78, v5.Frame.Width); // 97-19=78
  433. Assert.Equal (170, v5.Frame.Height); // 189-19=170
  434. v6.Text = "Button6";
  435. Assert.Equal ("Dim.Factor(factor=0.2, remaining=True)", v6.Width.ToString ());
  436. Assert.Equal ("Dim.Factor(factor=0.2, remaining=True)", v6.Height.ToString ());
  437. Assert.Equal (19, v6.Frame.Width); // 99*20%=19
  438. Assert.Equal (38, v6.Frame.Height); // 198-7*20=38
  439. };
  440. Application.Iteration += () => Application.RequestStop ();
  441. Application.Run ();
  442. Application.Shutdown ();
  443. }
  444. // DONE: Test operators
  445. [Fact]
  446. public void DimCombine_Do_Not_Throws ()
  447. {
  448. Application.Init (new FakeDriver ());
  449. var t = Application.Top;
  450. var w = new Window ("w") {
  451. Width = Dim.Width (t) - 2,
  452. Height = Dim.Height (t) - 2
  453. };
  454. var f = new FrameView ("f");
  455. var v1 = new View ("v1") {
  456. Width = Dim.Width (w) - 2,
  457. Height = Dim.Height (w) - 2
  458. };
  459. var v2 = new View ("v2") {
  460. Width = Dim.Width (v1) - 2,
  461. Height = Dim.Height (v1) - 2
  462. };
  463. f.Add (v1, v2);
  464. w.Add (f);
  465. t.Add (w);
  466. f.Width = Dim.Width (t) - Dim.Width (v2);
  467. f.Height = Dim.Height (t) - Dim.Height (v2);
  468. t.Ready += () => {
  469. Assert.Equal (80, t.Frame.Width);
  470. Assert.Equal (25, t.Frame.Height);
  471. Assert.Equal (78, w.Frame.Width);
  472. Assert.Equal (23, w.Frame.Height);
  473. Assert.Equal (6, f.Frame.Width);
  474. Assert.Equal (6, f.Frame.Height);
  475. Assert.Equal (76, v1.Frame.Width);
  476. Assert.Equal (21, v1.Frame.Height);
  477. Assert.Equal (74, v2.Frame.Width);
  478. Assert.Equal (19, v2.Frame.Height);
  479. };
  480. Application.Iteration += () => Application.RequestStop ();
  481. Application.Run ();
  482. Application.Shutdown ();
  483. }
  484. [Fact]
  485. public void PosCombine_Will_Throws ()
  486. {
  487. Application.Init (new FakeDriver ());
  488. var t = Application.Top;
  489. var w = new Window ("w") {
  490. Width = Dim.Width (t) - 2,
  491. Height = Dim.Height (t) - 2
  492. };
  493. var f = new FrameView ("f");
  494. var v1 = new View ("v1") {
  495. Width = Dim.Width (w) - 2,
  496. Height = Dim.Height (w) - 2
  497. };
  498. var v2 = new View ("v2") {
  499. Width = Dim.Width (v1) - 2,
  500. Height = Dim.Height (v1) - 2
  501. };
  502. f.Add (v1); // v2 not added
  503. w.Add (f);
  504. t.Add (w);
  505. f.Width = Dim.Width (t) - Dim.Width (v2);
  506. f.Height = Dim.Height (t) - Dim.Height (v2);
  507. Assert.Throws<InvalidOperationException> (() => Application.Run ());
  508. Application.Shutdown ();
  509. }
  510. [Fact]
  511. public void Dim_Add_Operator ()
  512. {
  513. Application.Init (new FakeDriver ());
  514. var top = Application.Top;
  515. var view = new View () { X = 0, Y = 0, Width = 20, Height = 0 };
  516. var field = new TextField () { X = 0, Y = Pos.Bottom (view), Width = 20 };
  517. var count = 0;
  518. field.KeyDown += (k) => {
  519. if (k.KeyEvent.Key == Key.Enter) {
  520. field.Text = $"Label {count}";
  521. var label = new Label (field.Text) { X = 0, Y = view.Bounds.Height, Width = 20 };
  522. view.Add (label);
  523. Assert.Equal ($"Label {count}", label.Text);
  524. Assert.Equal ($"Pos.Absolute({count})", label.Y.ToString ());
  525. Assert.Equal ($"Dim.Absolute({count})", view.Height.ToString ());
  526. view.Height += 1;
  527. count++;
  528. Assert.Equal ($"Dim.Absolute({count})", view.Height.ToString ());
  529. }
  530. };
  531. Application.Iteration += () => {
  532. while (count < 20) field.OnKeyDown (new KeyEvent (Key.Enter, new KeyModifiers ()));
  533. Application.RequestStop ();
  534. };
  535. var win = new Window ();
  536. win.Add (view);
  537. win.Add (field);
  538. top.Add (win);
  539. Application.Run (top);
  540. Assert.Equal (20, count);
  541. // Shutdown must be called to safely clean up Application if Init has been called
  542. Application.Shutdown ();
  543. }
  544. private string [] expecteds = new string [21] {
  545. @"
  546. ┌────────────────────┐
  547. │View with long text │
  548. │ │
  549. └────────────────────┘",
  550. @"
  551. ┌────────────────────┐
  552. │View with long text │
  553. │Label 0 │
  554. │Label 0 │
  555. └────────────────────┘",
  556. @"
  557. ┌────────────────────┐
  558. │View with long text │
  559. │Label 0 │
  560. │Label 1 │
  561. │Label 1 │
  562. └────────────────────┘",
  563. @"
  564. ┌────────────────────┐
  565. │View with long text │
  566. │Label 0 │
  567. │Label 1 │
  568. │Label 2 │
  569. │Label 2 │
  570. └────────────────────┘",
  571. @"
  572. ┌────────────────────┐
  573. │View with long text │
  574. │Label 0 │
  575. │Label 1 │
  576. │Label 2 │
  577. │Label 3 │
  578. │Label 3 │
  579. └────────────────────┘",
  580. @"
  581. ┌────────────────────┐
  582. │View with long text │
  583. │Label 0 │
  584. │Label 1 │
  585. │Label 2 │
  586. │Label 3 │
  587. │Label 4 │
  588. │Label 4 │
  589. └────────────────────┘",
  590. @"
  591. ┌────────────────────┐
  592. │View with long text │
  593. │Label 0 │
  594. │Label 1 │
  595. │Label 2 │
  596. │Label 3 │
  597. │Label 4 │
  598. │Label 5 │
  599. │Label 5 │
  600. └────────────────────┘",
  601. @"
  602. ┌────────────────────┐
  603. │View with long text │
  604. │Label 0 │
  605. │Label 1 │
  606. │Label 2 │
  607. │Label 3 │
  608. │Label 4 │
  609. │Label 5 │
  610. │Label 6 │
  611. │Label 6 │
  612. └────────────────────┘",
  613. @"
  614. ┌────────────────────┐
  615. │View with long text │
  616. │Label 0 │
  617. │Label 1 │
  618. │Label 2 │
  619. │Label 3 │
  620. │Label 4 │
  621. │Label 5 │
  622. │Label 6 │
  623. │Label 7 │
  624. │Label 7 │
  625. └────────────────────┘",
  626. @"
  627. ┌────────────────────┐
  628. │View with long text │
  629. │Label 0 │
  630. │Label 1 │
  631. │Label 2 │
  632. │Label 3 │
  633. │Label 4 │
  634. │Label 5 │
  635. │Label 6 │
  636. │Label 7 │
  637. │Label 8 │
  638. │Label 8 │
  639. └────────────────────┘",
  640. @"
  641. ┌────────────────────┐
  642. │View with long text │
  643. │Label 0 │
  644. │Label 1 │
  645. │Label 2 │
  646. │Label 3 │
  647. │Label 4 │
  648. │Label 5 │
  649. │Label 6 │
  650. │Label 7 │
  651. │Label 8 │
  652. │Label 9 │
  653. │Label 9 │
  654. └────────────────────┘",
  655. @"
  656. ┌────────────────────┐
  657. │View with long text │
  658. │Label 0 │
  659. │Label 1 │
  660. │Label 2 │
  661. │Label 3 │
  662. │Label 4 │
  663. │Label 5 │
  664. │Label 6 │
  665. │Label 7 │
  666. │Label 8 │
  667. │Label 9 │
  668. │Label 10 │
  669. │Label 10 │
  670. └────────────────────┘",
  671. @"
  672. ┌────────────────────┐
  673. │View with long text │
  674. │Label 0 │
  675. │Label 1 │
  676. │Label 2 │
  677. │Label 3 │
  678. │Label 4 │
  679. │Label 5 │
  680. │Label 6 │
  681. │Label 7 │
  682. │Label 8 │
  683. │Label 9 │
  684. │Label 10 │
  685. │Label 11 │
  686. │Label 11 │
  687. └────────────────────┘",
  688. @"
  689. ┌────────────────────┐
  690. │View with long text │
  691. │Label 0 │
  692. │Label 1 │
  693. │Label 2 │
  694. │Label 3 │
  695. │Label 4 │
  696. │Label 5 │
  697. │Label 6 │
  698. │Label 7 │
  699. │Label 8 │
  700. │Label 9 │
  701. │Label 10 │
  702. │Label 11 │
  703. │Label 12 │
  704. │Label 12 │
  705. └────────────────────┘",
  706. @"
  707. ┌────────────────────┐
  708. │View with long text │
  709. │Label 0 │
  710. │Label 1 │
  711. │Label 2 │
  712. │Label 3 │
  713. │Label 4 │
  714. │Label 5 │
  715. │Label 6 │
  716. │Label 7 │
  717. │Label 8 │
  718. │Label 9 │
  719. │Label 10 │
  720. │Label 11 │
  721. │Label 12 │
  722. │Label 13 │
  723. │Label 13 │
  724. └────────────────────┘",
  725. @"
  726. ┌────────────────────┐
  727. │View with long text │
  728. │Label 0 │
  729. │Label 1 │
  730. │Label 2 │
  731. │Label 3 │
  732. │Label 4 │
  733. │Label 5 │
  734. │Label 6 │
  735. │Label 7 │
  736. │Label 8 │
  737. │Label 9 │
  738. │Label 10 │
  739. │Label 11 │
  740. │Label 12 │
  741. │Label 13 │
  742. │Label 14 │
  743. │Label 14 │
  744. └────────────────────┘",
  745. @"
  746. ┌────────────────────┐
  747. │View with long text │
  748. │Label 0 │
  749. │Label 1 │
  750. │Label 2 │
  751. │Label 3 │
  752. │Label 4 │
  753. │Label 5 │
  754. │Label 6 │
  755. │Label 7 │
  756. │Label 8 │
  757. │Label 9 │
  758. │Label 10 │
  759. │Label 11 │
  760. │Label 12 │
  761. │Label 13 │
  762. │Label 14 │
  763. │Label 15 │
  764. │Label 15 │
  765. └────────────────────┘",
  766. @"
  767. ┌────────────────────┐
  768. │View with long text │
  769. │Label 0 │
  770. │Label 1 │
  771. │Label 2 │
  772. │Label 3 │
  773. │Label 4 │
  774. │Label 5 │
  775. │Label 6 │
  776. │Label 7 │
  777. │Label 8 │
  778. │Label 9 │
  779. │Label 10 │
  780. │Label 11 │
  781. │Label 12 │
  782. │Label 13 │
  783. │Label 14 │
  784. │Label 15 │
  785. │Label 16 │
  786. │Label 16 │
  787. └────────────────────┘",
  788. @"
  789. ┌────────────────────┐
  790. │View with long text │
  791. │Label 0 │
  792. │Label 1 │
  793. │Label 2 │
  794. │Label 3 │
  795. │Label 4 │
  796. │Label 5 │
  797. │Label 6 │
  798. │Label 7 │
  799. │Label 8 │
  800. │Label 9 │
  801. │Label 10 │
  802. │Label 11 │
  803. │Label 12 │
  804. │Label 13 │
  805. │Label 14 │
  806. │Label 15 │
  807. │Label 16 │
  808. │Label 17 │
  809. │Label 17 │
  810. └────────────────────┘",
  811. @"
  812. ┌────────────────────┐
  813. │View with long text │
  814. │Label 0 │
  815. │Label 1 │
  816. │Label 2 │
  817. │Label 3 │
  818. │Label 4 │
  819. │Label 5 │
  820. │Label 6 │
  821. │Label 7 │
  822. │Label 8 │
  823. │Label 9 │
  824. │Label 10 │
  825. │Label 11 │
  826. │Label 12 │
  827. │Label 13 │
  828. │Label 14 │
  829. │Label 15 │
  830. │Label 16 │
  831. │Label 17 │
  832. │Label 18 │
  833. │Label 18 │
  834. └────────────────────┘",
  835. @"
  836. ┌────────────────────┐
  837. │View with long text │
  838. │Label 0 │
  839. │Label 1 │
  840. │Label 2 │
  841. │Label 3 │
  842. │Label 4 │
  843. │Label 5 │
  844. │Label 6 │
  845. │Label 7 │
  846. │Label 8 │
  847. │Label 9 │
  848. │Label 10 │
  849. │Label 11 │
  850. │Label 12 │
  851. │Label 13 │
  852. │Label 14 │
  853. │Label 15 │
  854. │Label 16 │
  855. │Label 17 │
  856. │Label 18 │
  857. │Label 19 │
  858. │Label 19 │
  859. └────────────────────┘",
  860. };
  861. [Fact]
  862. public void Dim_Add_Operator_With_Text ()
  863. {
  864. Application.Init (new FakeDriver ());
  865. var top = Application.Top;
  866. // Although view height is zero the text it's draw due the SetMinWidthHeight method
  867. var view = new View ("View with long text") { X = 0, Y = 0, Width = 20, Height = 0 };
  868. var field = new TextField () { X = 0, Y = Pos.Bottom (view), Width = 20 };
  869. var count = 0;
  870. var listLabels = new List<Label> ();
  871. field.KeyDown += (k) => {
  872. if (k.KeyEvent.Key == Key.Enter) {
  873. ((FakeDriver)Application.Driver).SetBufferSize (22, count + 4);
  874. var pos = TestHelpers.AssertDriverContentsWithFrameAre (expecteds [count], output);
  875. Assert.Equal (new Rect (0, 0, 22, count + 4), pos);
  876. if (count < 20) {
  877. field.Text = $"Label {count}";
  878. var label = new Label (field.Text) { X = 0, Y = view.Bounds.Height, Width = 10 };
  879. view.Add (label);
  880. Assert.Equal ($"Label {count}", label.Text);
  881. Assert.Equal ($"Pos.Absolute({count + 1})", label.Y.ToString ());
  882. listLabels.Add (label);
  883. if (count == 0) {
  884. Assert.Equal ($"Dim.Absolute({count})", view.Height.ToString ());
  885. view.Height += 2;
  886. } else {
  887. Assert.Equal ($"Dim.Absolute({count + 1})", view.Height.ToString ());
  888. view.Height += 1;
  889. }
  890. count++;
  891. }
  892. Assert.Equal ($"Dim.Absolute({count + 1})", view.Height.ToString ());
  893. }
  894. };
  895. Application.Iteration += () => {
  896. while (count < 21) {
  897. field.OnKeyDown (new KeyEvent (Key.Enter, new KeyModifiers ()));
  898. if (count == 20) {
  899. field.OnKeyDown (new KeyEvent (Key.Enter, new KeyModifiers ()));
  900. break;
  901. }
  902. }
  903. Application.RequestStop ();
  904. };
  905. var win = new Window ();
  906. win.Add (view);
  907. win.Add (field);
  908. top.Add (win);
  909. Application.Run (top);
  910. Assert.Equal (20, count);
  911. Assert.Equal (count, listLabels.Count);
  912. // Shutdown must be called to safely clean up Application if Init has been called
  913. Application.Shutdown ();
  914. }
  915. [Fact]
  916. public void Dim_Subtract_Operator ()
  917. {
  918. Application.Init (new FakeDriver ());
  919. var top = Application.Top;
  920. var view = new View () { X = 0, Y = 0, Width = 20, Height = 0 };
  921. var field = new TextField () { X = 0, Y = Pos.Bottom (view), Width = 20 };
  922. var count = 20;
  923. var listLabels = new List<Label> ();
  924. for (int i = 0; i < count; i++) {
  925. field.Text = $"Label {i}";
  926. var label = new Label (field.Text) { X = 0, Y = view.Bounds.Height, Width = 20 };
  927. view.Add (label);
  928. Assert.Equal ($"Label {i}", label.Text);
  929. Assert.Equal ($"Pos.Absolute({i})", label.Y.ToString ());
  930. listLabels.Add (label);
  931. Assert.Equal ($"Dim.Absolute({i})", view.Height.ToString ());
  932. view.Height += 1;
  933. Assert.Equal ($"Dim.Absolute({i + 1})", view.Height.ToString ());
  934. }
  935. field.KeyDown += (k) => {
  936. if (k.KeyEvent.Key == Key.Enter) {
  937. Assert.Equal ($"Label {count - 1}", listLabels [count - 1].Text);
  938. view.Remove (listLabels [count - 1]);
  939. Assert.Equal ($"Dim.Absolute({count})", view.Height.ToString ());
  940. view.Height -= 1;
  941. count--;
  942. Assert.Equal ($"Dim.Absolute({count})", view.Height.ToString ());
  943. }
  944. };
  945. Application.Iteration += () => {
  946. while (count > 0) field.OnKeyDown (new KeyEvent (Key.Enter, new KeyModifiers ()));
  947. Application.RequestStop ();
  948. };
  949. var win = new Window ();
  950. win.Add (view);
  951. win.Add (field);
  952. top.Add (win);
  953. Application.Run (top);
  954. Assert.Equal (0, count);
  955. // Shutdown must be called to safely clean up Application if Init has been called
  956. Application.Shutdown ();
  957. }
  958. [Fact]
  959. public void Dim_Subtract_Operator_With_Text ()
  960. {
  961. Application.Init (new FakeDriver ());
  962. var top = Application.Top;
  963. // Although view height is zero the text it's draw due the SetMinWidthHeight method
  964. var view = new View ("View with long text") { X = 0, Y = 0, Width = 20, Height = 0 };
  965. var field = new TextField () { X = 0, Y = Pos.Bottom (view), Width = 20 };
  966. var count = 20;
  967. var listLabels = new List<Label> ();
  968. for (int i = 0; i < count; i++) {
  969. field.Text = $"Label {i}";
  970. var label = new Label (field.Text) { X = 0, Y = view.Bounds.Height, Width = 10 };
  971. view.Add (label);
  972. Assert.Equal ($"Label {i}", label.Text);
  973. Assert.Equal ($"Pos.Absolute({i + 1})", label.Y.ToString ());
  974. listLabels.Add (label);
  975. if (i == 0) {
  976. Assert.Equal ($"Dim.Absolute({i})", view.Height.ToString ());
  977. view.Height += 2;
  978. Assert.Equal ($"Dim.Absolute({i + 2})", view.Height.ToString ());
  979. } else {
  980. Assert.Equal ($"Dim.Absolute({i + 1})", view.Height.ToString ());
  981. view.Height += 1;
  982. Assert.Equal ($"Dim.Absolute({i + 2})", view.Height.ToString ());
  983. }
  984. }
  985. field.KeyDown += (k) => {
  986. if (k.KeyEvent.Key == Key.Enter) {
  987. ((FakeDriver)Application.Driver).SetBufferSize (22, count + 4);
  988. var pos = TestHelpers.AssertDriverContentsWithFrameAre (expecteds [count], output);
  989. Assert.Equal (new Rect (0, 0, 22, count + 4), pos);
  990. if (count > 0) {
  991. Assert.Equal ($"Label {count - 1}", listLabels [count - 1].Text);
  992. view.Remove (listLabels [count - 1]);
  993. listLabels.RemoveAt (count - 1);
  994. Assert.Equal ($"Dim.Absolute({count + 1})", view.Height.ToString ());
  995. view.Height -= 1;
  996. count--;
  997. if (listLabels.Count > 0)
  998. field.Text = listLabels [count - 1].Text;
  999. else
  1000. field.Text = NStack.ustring.Empty;
  1001. }
  1002. Assert.Equal ($"Dim.Absolute({count + 1})", view.Height.ToString ());
  1003. }
  1004. };
  1005. Application.Iteration += () => {
  1006. while (count > -1) {
  1007. field.OnKeyDown (new KeyEvent (Key.Enter, new KeyModifiers ()));
  1008. if (count == 0) {
  1009. field.OnKeyDown (new KeyEvent (Key.Enter, new KeyModifiers ()));
  1010. break;
  1011. }
  1012. }
  1013. Application.RequestStop ();
  1014. };
  1015. var win = new Window ();
  1016. win.Add (view);
  1017. win.Add (field);
  1018. top.Add (win);
  1019. Application.Run (top);
  1020. Assert.Equal (0, count);
  1021. Assert.Equal (count, listLabels.Count);
  1022. // Shutdown must be called to safely clean up Application if Init has been called
  1023. Application.Shutdown ();
  1024. }
  1025. [Fact]
  1026. public void Internal_Tests ()
  1027. {
  1028. var dimFactor = new Dim.DimFactor (0.10F);
  1029. Assert.Equal (10, dimFactor.Anchor (100));
  1030. var dimAbsolute = new Dim.DimAbsolute (10);
  1031. Assert.Equal (10, dimAbsolute.Anchor (0));
  1032. var dimFill = new Dim.DimFill (1);
  1033. Assert.Equal (99, dimFill.Anchor (100));
  1034. var dimCombine = new Dim.DimCombine (true, dimFactor, dimAbsolute);
  1035. Assert.Equal (dimCombine.left, dimFactor);
  1036. Assert.Equal (dimCombine.right, dimAbsolute);
  1037. Assert.Equal (20, dimCombine.Anchor (100));
  1038. var view = new View (new Rect (20, 10, 20, 1));
  1039. var dimViewHeight = new Dim.DimView (view, 0);
  1040. Assert.Equal (1, dimViewHeight.Anchor (0));
  1041. var dimViewWidth = new Dim.DimView (view, 1);
  1042. Assert.Equal (20, dimViewWidth.Anchor (0));
  1043. }
  1044. [Fact]
  1045. public void Function_SetsValue ()
  1046. {
  1047. var text = "Test";
  1048. var dim = Dim.Function (() => text.Length);
  1049. Assert.Equal ("Dim.DimFunc(4)", dim.ToString ());
  1050. text = "New Test";
  1051. Assert.Equal ("Dim.DimFunc(8)", dim.ToString ());
  1052. text = "";
  1053. Assert.Equal ("Dim.DimFunc(0)", dim.ToString ());
  1054. }
  1055. [Fact]
  1056. public void Function_Equal ()
  1057. {
  1058. var f1 = () => 0;
  1059. var f2 = () => 0;
  1060. var dim1 = Dim.Function (f1);
  1061. var dim2 = Dim.Function (f2);
  1062. Assert.Equal (dim1, dim2);
  1063. f2 = () => 1;
  1064. dim2 = Dim.Function (f2);
  1065. Assert.NotEqual (dim1, dim2);
  1066. }
  1067. [Theory, AutoInitShutdown]
  1068. [InlineData (0, true)]
  1069. [InlineData (0, false)]
  1070. [InlineData (50, true)]
  1071. [InlineData (50, false)]
  1072. public void DimPercentPlusOne (int startingDistance, bool testHorizontal)
  1073. {
  1074. var container = new View {
  1075. Width = 100,
  1076. Height = 100,
  1077. };
  1078. var label = new Label {
  1079. X = testHorizontal ? startingDistance : 0,
  1080. Y = testHorizontal ? 0 : startingDistance,
  1081. Width = testHorizontal ? Dim.Percent (50) + 1 : 1,
  1082. Height = testHorizontal ? 1 : Dim.Percent (50) + 1,
  1083. };
  1084. container.Add (label);
  1085. Application.Top.Add (container);
  1086. Application.Top.LayoutSubviews ();
  1087. Assert.Equal (100, container.Frame.Width);
  1088. Assert.Equal (100, container.Frame.Height);
  1089. if (testHorizontal) {
  1090. Assert.Equal (51, label.Frame.Width);
  1091. Assert.Equal (1, label.Frame.Height);
  1092. } else {
  1093. Assert.Equal (1, label.Frame.Width);
  1094. Assert.Equal (51, label.Frame.Height);
  1095. }
  1096. }
  1097. }
  1098. }