DimTests.cs 37 KB

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