Dim.AutoTests.cs 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312
  1. using System.Globalization;
  2. using System.Text;
  3. using Xunit.Abstractions;
  4. using static Terminal.Gui.Dim;
  5. namespace Terminal.Gui.PosDimTests;
  6. public class DimAutoTests (ITestOutputHelper output)
  7. {
  8. private readonly ITestOutputHelper _output = output;
  9. private class DimAutoTestView : View
  10. {
  11. public DimAutoTestView ()
  12. {
  13. ValidatePosDim = true;
  14. Width = Dim.Auto ();
  15. Height = Dim.Auto ();
  16. }
  17. public DimAutoTestView (Dim width, Dim height)
  18. {
  19. ValidatePosDim = true;
  20. Width = width;
  21. Height = height;
  22. }
  23. public DimAutoTestView (string text, Dim width, Dim height)
  24. {
  25. ValidatePosDim = true;
  26. Text = text;
  27. Width = width;
  28. Height = height;
  29. }
  30. }
  31. // Test min - ensure that if min is specified in the DimAuto constructor it is honored
  32. [Fact]
  33. public void Min_Is_Honored ()
  34. {
  35. var superView = new View
  36. {
  37. X = 0,
  38. Y = 0,
  39. Width = Dim.Auto (minimumContentDim: 10),
  40. Height = Dim.Auto (minimumContentDim: 10),
  41. ValidatePosDim = true
  42. };
  43. var subView = new View
  44. {
  45. X = 0,
  46. Y = 0,
  47. Width = 5,
  48. Height = 5
  49. };
  50. superView.Add (subView);
  51. superView.BeginInit ();
  52. superView.EndInit ();
  53. superView.SetRelativeLayout (new (10, 10));
  54. superView.LayoutSubviews (); // no throw
  55. Assert.Equal (10, superView.Frame.Width);
  56. Assert.Equal (10, superView.Frame.Height);
  57. }
  58. [Theory]
  59. [InlineData (0, 2, 4)]
  60. [InlineData (1, 2, 4)]
  61. [InlineData (2, 2, 4)]
  62. [InlineData (3, 2, 5)]
  63. [InlineData (1, 0, 3)]
  64. public void Min_Absolute_Is_Content_Relative (int contentSize, int minAbsolute, int expected)
  65. {
  66. var view = new View
  67. {
  68. X = 0,
  69. Y = 0,
  70. Width = Dim.Auto (minimumContentDim: minAbsolute),
  71. BorderStyle = LineStyle.Single, // a 1 thick adornment
  72. ValidatePosDim = true
  73. };
  74. view.SetContentSize (new (contentSize, 0));
  75. Assert.Equal (expected, view.Frame.Width);
  76. }
  77. [Theory]
  78. [InlineData (1, 100, 100)]
  79. [InlineData (1, 50, 50)]
  80. public void Min_Percent (int contentSize, int minPercent, int expected)
  81. {
  82. var view = new View
  83. {
  84. X = 0,
  85. Y = 0,
  86. Width = Dim.Auto (minimumContentDim: Dim.Percent (minPercent)),
  87. ValidatePosDim = true
  88. };
  89. view.SetContentSize (new (contentSize, 0));
  90. view.SetRelativeLayout (new (100, 100));
  91. Assert.Equal (expected, view.Frame.Width);
  92. }
  93. [Theory]
  94. [InlineData (1, 100, 100)]
  95. [InlineData (1, 50, 50)]
  96. public void Min_Percent_Is_Content_Relative (int contentSize, int minPercent, int expected)
  97. {
  98. var view = new View
  99. {
  100. X = 0,
  101. Y = 0,
  102. Width = Dim.Auto (minimumContentDim: Dim.Percent (minPercent)),
  103. BorderStyle = LineStyle.Single, // a 1 thick adornment
  104. ValidatePosDim = true
  105. };
  106. view.SetContentSize (new (contentSize, 0));
  107. view.SetRelativeLayout (new (100, 100));
  108. Assert.Equal (expected, view.Frame.Width);
  109. }
  110. // what happens if DimAuto (min: 10) and the subview moves to a negative coord?
  111. [Fact]
  112. public void Min_Resets_If_Subview_Moves_Negative ()
  113. {
  114. var superView = new View
  115. {
  116. X = 0,
  117. Y = 0,
  118. Width = Dim.Auto (minimumContentDim: 10),
  119. Height = Dim.Auto (minimumContentDim: 10),
  120. ValidatePosDim = true
  121. };
  122. var subView = new View
  123. {
  124. X = 0,
  125. Y = 0,
  126. Width = 5,
  127. Height = 5
  128. };
  129. superView.Add (subView);
  130. superView.BeginInit ();
  131. superView.EndInit ();
  132. superView.SetRelativeLayout (new (10, 10));
  133. superView.LayoutSubviews (); // no throw
  134. Assert.Equal (10, superView.Frame.Width);
  135. Assert.Equal (10, superView.Frame.Height);
  136. subView.X = -1;
  137. subView.Y = -1;
  138. superView.SetRelativeLayout (new (10, 10));
  139. superView.LayoutSubviews (); // no throw
  140. Assert.Equal (5, subView.Frame.Width);
  141. Assert.Equal (5, subView.Frame.Height);
  142. Assert.Equal (10, superView.Frame.Width);
  143. Assert.Equal (10, superView.Frame.Height);
  144. }
  145. [Fact]
  146. public void Min_Resets_If_Subview_Shrinks ()
  147. {
  148. var superView = new View
  149. {
  150. X = 0,
  151. Y = 0,
  152. Width = Dim.Auto (minimumContentDim: 10),
  153. Height = Dim.Auto (minimumContentDim: 10),
  154. ValidatePosDim = true
  155. };
  156. var subView = new View
  157. {
  158. X = 0,
  159. Y = 0,
  160. Width = 5,
  161. Height = 5
  162. };
  163. superView.Add (subView);
  164. superView.BeginInit ();
  165. superView.EndInit ();
  166. superView.SetRelativeLayout (new (10, 10));
  167. superView.LayoutSubviews (); // no throw
  168. Assert.Equal (10, superView.Frame.Width);
  169. Assert.Equal (10, superView.Frame.Height);
  170. subView.Width = 3;
  171. subView.Height = 3;
  172. superView.SetRelativeLayout (new (10, 10));
  173. superView.LayoutSubviews (); // no throw
  174. Assert.Equal (3, subView.Frame.Width);
  175. Assert.Equal (3, subView.Frame.Height);
  176. Assert.Equal (10, superView.Frame.Width);
  177. Assert.Equal (10, superView.Frame.Height);
  178. }
  179. [Theory]
  180. [InlineData (0, 0, 0, 0, 0)]
  181. [InlineData (0, 0, 5, 0, 0)]
  182. [InlineData (0, 0, 0, 5, 5)]
  183. [InlineData (0, 0, 5, 5, 5)]
  184. [InlineData (1, 0, 5, 0, 0)]
  185. [InlineData (1, 0, 0, 5, 5)]
  186. [InlineData (1, 0, 5, 5, 5)]
  187. [InlineData (1, 1, 5, 5, 6)]
  188. [InlineData (-1, 0, 5, 0, 0)]
  189. [InlineData (-1, 0, 0, 5, 5)]
  190. [InlineData (-1, 0, 5, 5, 5)]
  191. [InlineData (-1, -1, 5, 5, 4)]
  192. public void Height_Auto_Width_Absolute_NotChanged (int subX, int subY, int subWidth, int subHeight, int expectedHeight)
  193. {
  194. var superView = new View
  195. {
  196. X = 0,
  197. Y = 0,
  198. Width = 10,
  199. Height = Dim.Auto (),
  200. ValidatePosDim = true
  201. };
  202. var subView = new View
  203. {
  204. X = subX,
  205. Y = subY,
  206. Width = subWidth,
  207. Height = subHeight,
  208. ValidatePosDim = true
  209. };
  210. superView.Add (subView);
  211. superView.BeginInit ();
  212. superView.EndInit ();
  213. superView.SetRelativeLayout (new (10, 10));
  214. Assert.Equal (new Rectangle (0, 0, 10, expectedHeight), superView.Frame);
  215. }
  216. [Fact]
  217. public void NoSubViews_Does_Nothing ()
  218. {
  219. var superView = new View
  220. {
  221. X = 0,
  222. Y = 0,
  223. Width = Dim.Auto (),
  224. Height = Dim.Auto (),
  225. ValidatePosDim = true
  226. };
  227. superView.BeginInit ();
  228. superView.EndInit ();
  229. superView.SetRelativeLayout (new (10, 10));
  230. Assert.Equal (new Rectangle (0, 0, 0, 0), superView.Frame);
  231. superView.SetRelativeLayout (new (10, 10));
  232. Assert.Equal (new Rectangle (0, 0, 0, 0), superView.Frame);
  233. }
  234. [Fact]
  235. public void NoSubViews_Does_Nothing_Vertical ()
  236. {
  237. var superView = new View
  238. {
  239. X = 0,
  240. Y = 0,
  241. Width = Dim.Auto (),
  242. Height = Dim.Auto (),
  243. TextDirection = TextDirection.TopBottom_LeftRight,
  244. ValidatePosDim = true
  245. };
  246. superView.BeginInit ();
  247. superView.EndInit ();
  248. superView.SetRelativeLayout (new (10, 10));
  249. Assert.Equal (new Rectangle (0, 0, 0, 0), superView.Frame);
  250. superView.SetRelativeLayout (new (10, 10));
  251. Assert.Equal (new Rectangle (0, 0, 0, 0), superView.Frame);
  252. }
  253. [Theory]
  254. [InlineData (0, 0, 0, 0, 0, 0)]
  255. [InlineData (0, 0, 5, 0, 5, 0)]
  256. [InlineData (0, 0, 0, 5, 0, 5)]
  257. [InlineData (0, 0, 5, 5, 5, 5)]
  258. [InlineData (1, 0, 5, 0, 6, 0)]
  259. [InlineData (1, 0, 0, 5, 1, 5)]
  260. [InlineData (1, 0, 5, 5, 6, 5)]
  261. [InlineData (1, 1, 5, 5, 6, 6)]
  262. [InlineData (-1, 0, 5, 0, 4, 0)]
  263. [InlineData (-1, 0, 0, 5, 0, 5)]
  264. [InlineData (-1, 0, 5, 5, 4, 5)]
  265. [InlineData (-1, -1, 5, 5, 4, 4)]
  266. public void SubView_Changes_SuperView_Size (int subX, int subY, int subWidth, int subHeight, int expectedWidth, int expectedHeight)
  267. {
  268. var superView = new View
  269. {
  270. X = 0,
  271. Y = 0,
  272. Width = Dim.Auto (),
  273. Height = Dim.Auto (),
  274. ValidatePosDim = true
  275. };
  276. var subView = new View
  277. {
  278. X = subX,
  279. Y = subY,
  280. Width = subWidth,
  281. Height = subHeight,
  282. ValidatePosDim = true
  283. };
  284. superView.Add (subView);
  285. superView.BeginInit ();
  286. superView.EndInit ();
  287. superView.SetRelativeLayout (new (10, 10));
  288. Assert.Equal (new Rectangle (0, 0, expectedWidth, expectedHeight), superView.Frame);
  289. }
  290. // Test validation
  291. [Fact]
  292. public void ValidatePosDim_True_Throws_When_SubView_Uses_SuperView_Dims ()
  293. {
  294. var superView = new View
  295. {
  296. X = 0,
  297. Y = 0,
  298. Width = Dim.Auto (),
  299. Height = Dim.Auto (),
  300. ValidatePosDim = true
  301. };
  302. var subView = new View
  303. {
  304. X = 0,
  305. Y = 0,
  306. Width = Dim.Fill (),
  307. Height = 10,
  308. ValidatePosDim = true
  309. };
  310. superView.BeginInit ();
  311. superView.EndInit ();
  312. Assert.Throws<InvalidOperationException> (() => superView.Add (subView));
  313. subView.Width = 10;
  314. superView.Add (subView);
  315. superView.SetRelativeLayout (new (10, 10));
  316. superView.LayoutSubviews (); // no throw
  317. subView.Width = Dim.Fill ();
  318. Assert.Throws<InvalidOperationException> (() => superView.SetRelativeLayout (new (0, 0)));
  319. subView.Width = 10;
  320. subView.Height = Dim.Fill ();
  321. Assert.Throws<InvalidOperationException> (() => superView.SetRelativeLayout (new (0, 0)));
  322. subView.Height = 10;
  323. subView.Height = Dim.Percent (50);
  324. Assert.Throws<InvalidOperationException> (() => superView.SetRelativeLayout (new (0, 0)));
  325. subView.Height = 10;
  326. subView.X = Pos.Center ();
  327. Assert.Throws<InvalidOperationException> (() => superView.SetRelativeLayout (new (0, 0)));
  328. subView.X = 0;
  329. subView.Y = Pos.Center ();
  330. Assert.Throws<InvalidOperationException> (() => superView.SetRelativeLayout (new (0, 0)));
  331. subView.Y = 0;
  332. subView.Width = 10;
  333. subView.Height = 10;
  334. subView.X = 0;
  335. subView.Y = 0;
  336. superView.SetRelativeLayout (new (0, 0));
  337. superView.LayoutSubviews ();
  338. }
  339. // Test validation
  340. [Fact]
  341. public void ValidatePosDim_True_Throws_When_SubView_Uses_SuperView_Dims_Combine ()
  342. {
  343. var superView = new View
  344. {
  345. X = 0,
  346. Y = 0,
  347. Width = Dim.Auto (),
  348. Height = Dim.Auto (),
  349. ValidatePosDim = true
  350. };
  351. var subView = new View
  352. {
  353. X = 0,
  354. Y = 0,
  355. Width = 10,
  356. Height = 10
  357. };
  358. var subView2 = new View
  359. {
  360. X = 0,
  361. Y = 0,
  362. Width = 10,
  363. Height = 10
  364. };
  365. superView.Add (subView, subView2);
  366. superView.BeginInit ();
  367. superView.EndInit ();
  368. superView.SetRelativeLayout (new (0, 0));
  369. superView.LayoutSubviews (); // no throw
  370. subView.Height = Dim.Fill () + 3;
  371. Assert.Throws<InvalidOperationException> (() => superView.SetRelativeLayout (new (0, 0)));
  372. subView.Height = 0;
  373. subView.Height = 3 + Dim.Fill ();
  374. Assert.Throws<InvalidOperationException> (() => superView.SetRelativeLayout (new (0, 0)));
  375. subView.Height = 0;
  376. subView.Height = 3 + 5 + Dim.Fill ();
  377. Assert.Throws<InvalidOperationException> (() => superView.SetRelativeLayout (new (0, 0)));
  378. subView.Height = 0;
  379. subView.Height = 3 + 5 + Dim.Percent (10);
  380. Assert.Throws<InvalidOperationException> (() => superView.SetRelativeLayout (new (0, 0)));
  381. subView.Height = 0;
  382. // Tests nested Combine
  383. subView.Height = 5 + new Dim.DimCombine (true, 3, new Dim.DimCombine (true, Dim.Percent (10), 9));
  384. Assert.Throws<InvalidOperationException> (() => superView.SetRelativeLayout (new (0, 0)));
  385. }
  386. [Fact]
  387. public void ValidatePosDim_True_Throws_When_SubView_Uses_SuperView_Pos_Combine ()
  388. {
  389. var superView = new View
  390. {
  391. X = 0,
  392. Y = 0,
  393. Width = Dim.Auto (),
  394. Height = Dim.Auto (),
  395. ValidatePosDim = true
  396. };
  397. var subView = new View
  398. {
  399. X = 0,
  400. Y = 0,
  401. Width = 10,
  402. Height = 10
  403. };
  404. var subView2 = new View
  405. {
  406. X = 0,
  407. Y = 0,
  408. Width = 10,
  409. Height = 10
  410. };
  411. superView.Add (subView, subView2);
  412. superView.BeginInit ();
  413. superView.EndInit ();
  414. superView.SetRelativeLayout (new (0, 0));
  415. superView.LayoutSubviews (); // no throw
  416. subView.X = Pos.Right (subView2);
  417. superView.SetRelativeLayout (new (0, 0));
  418. superView.LayoutSubviews (); // no throw
  419. subView.X = Pos.Right (subView2) + 3;
  420. superView.SetRelativeLayout (new (0, 0)); // no throw
  421. superView.LayoutSubviews (); // no throw
  422. subView.X = new Pos.PosCombine (true, Pos.Right (subView2), new Pos.PosCombine (true, 7, 9));
  423. superView.SetRelativeLayout (new (0, 0)); // no throw
  424. subView.X = Pos.Center () + 3;
  425. Assert.Throws<InvalidOperationException> (() => superView.SetRelativeLayout (new (0, 0)));
  426. subView.X = 0;
  427. subView.X = 3 + Pos.Center ();
  428. Assert.Throws<InvalidOperationException> (() => superView.SetRelativeLayout (new (0, 0)));
  429. subView.X = 0;
  430. subView.X = 3 + 5 + Pos.Center ();
  431. Assert.Throws<InvalidOperationException> (() => superView.SetRelativeLayout (new (0, 0)));
  432. subView.X = 0;
  433. subView.X = 3 + 5 + Pos.Percent (10);
  434. Assert.Throws<InvalidOperationException> (() => superView.SetRelativeLayout (new (0, 0)));
  435. subView.X = 0;
  436. subView.X = Pos.Percent (10) + Pos.Center ();
  437. Assert.Throws<InvalidOperationException> (() => superView.SetRelativeLayout (new (0, 0)));
  438. subView.X = 0;
  439. // Tests nested Combine
  440. subView.X = 5 + new Pos.PosCombine (true, Pos.Right (subView2), new Pos.PosCombine (true, Pos.Center (), 9));
  441. Assert.Throws<InvalidOperationException> (() => superView.SetRelativeLayout (new (0, 0)));
  442. subView.X = 0;
  443. }
  444. [Theory]
  445. [InlineData (0, 0, 0, 0, 0)]
  446. [InlineData (0, 0, 5, 0, 5)]
  447. [InlineData (0, 0, 0, 5, 0)]
  448. [InlineData (0, 0, 5, 5, 5)]
  449. [InlineData (1, 0, 5, 0, 6)]
  450. [InlineData (1, 0, 0, 5, 1)]
  451. [InlineData (1, 0, 5, 5, 6)]
  452. [InlineData (1, 1, 5, 5, 6)]
  453. [InlineData (-1, 0, 5, 0, 4)]
  454. [InlineData (-1, 0, 0, 5, 0)]
  455. [InlineData (-1, 0, 5, 5, 4)]
  456. [InlineData (-1, -1, 5, 5, 4)]
  457. public void Width_Auto_Height_Absolute_NotChanged (int subX, int subY, int subWidth, int subHeight, int expectedWidth)
  458. {
  459. var superView = new View
  460. {
  461. X = 0,
  462. Y = 0,
  463. Width = Dim.Auto (),
  464. Height = 10,
  465. ValidatePosDim = true
  466. };
  467. var subView = new View
  468. {
  469. X = subX,
  470. Y = subY,
  471. Width = subWidth,
  472. Height = subHeight,
  473. ValidatePosDim = true
  474. };
  475. superView.Add (subView);
  476. superView.BeginInit ();
  477. superView.EndInit ();
  478. superView.SetRelativeLayout (new (10, 10));
  479. Assert.Equal (new Rectangle (0, 0, expectedWidth, 10), superView.Frame);
  480. }
  481. // Test that when a view has Width set to DimAuto (min: x)
  482. // the width is never < x even if SetRelativeLayout is called with smaller bounds
  483. [Theory]
  484. [InlineData (0, 0)]
  485. [InlineData (1, 1)]
  486. [InlineData (3, 3)]
  487. [InlineData (4, 4)]
  488. [InlineData (5, 4)] // This is clearly invalid, but we choose to not throw but log a debug message
  489. public void Width_Auto_Min_Honored (int min, int expectedWidth)
  490. {
  491. var superView = new View
  492. {
  493. X = 0,
  494. Y = 0,
  495. Width = Dim.Auto (minimumContentDim: min),
  496. Height = 1,
  497. ValidatePosDim = true
  498. };
  499. superView.BeginInit ();
  500. superView.EndInit ();
  501. superView.SetRelativeLayout (new (4, 1));
  502. Assert.Equal (expectedWidth, superView.Frame.Width);
  503. }
  504. // Test Dim.Fill - Fill should not impact width of the DimAuto superview
  505. [Theory]
  506. [InlineData (0, 0, 0, 10, 10)]
  507. [InlineData (0, 1, 0, 10, 10)]
  508. [InlineData (0, 11, 0, 10, 10)]
  509. [InlineData (0, 10, 0, 10, 10)]
  510. [InlineData (0, 5, 0, 10, 10)]
  511. [InlineData (1, 5, 0, 10, 9)]
  512. [InlineData (1, 10, 0, 10, 9)]
  513. [InlineData (0, 0, 1, 10, 9)]
  514. [InlineData (0, 10, 1, 10, 9)]
  515. [InlineData (0, 5, 1, 10, 9)]
  516. [InlineData (1, 5, 1, 10, 8)]
  517. [InlineData (1, 10, 1, 10, 8)]
  518. public void Width_Fill_Fills (int subX, int superMinWidth, int fill, int expectedSuperWidth, int expectedSubWidth)
  519. {
  520. var superView = new View
  521. {
  522. X = 0,
  523. Y = 0,
  524. Width = Dim.Auto (minimumContentDim: superMinWidth),
  525. Height = 1,
  526. ValidatePosDim = true
  527. };
  528. var subView = new View
  529. {
  530. X = subX,
  531. Y = 0,
  532. Width = Dim.Fill (fill),
  533. Height = 1,
  534. ValidatePosDim = true
  535. };
  536. superView.Add (subView);
  537. superView.BeginInit ();
  538. superView.EndInit ();
  539. superView.SetRelativeLayout (new (10, 1));
  540. Assert.Equal (expectedSuperWidth, superView.Frame.Width);
  541. superView.LayoutSubviews ();
  542. Assert.Equal (expectedSubWidth, subView.Frame.Width);
  543. Assert.Equal (expectedSuperWidth, superView.Frame.Width);
  544. }
  545. [Theory]
  546. [InlineData (0, 1, 1)]
  547. [InlineData (1, 1, 1)]
  548. [InlineData (9, 1, 1)]
  549. [InlineData (10, 1, 1)]
  550. [InlineData (0, 10, 10)]
  551. [InlineData (1, 10, 10)]
  552. [InlineData (9, 10, 10)]
  553. [InlineData (10, 10, 10)]
  554. public void Width_Auto_Text_Does_Not_Constrain_To_SuperView (int subX, int textLen, int expectedSubWidth)
  555. {
  556. var superView = new View
  557. {
  558. X = 0,
  559. Y = 0,
  560. Width = 10,
  561. Height = 1,
  562. ValidatePosDim = true
  563. };
  564. var subView = new View
  565. {
  566. Text = new string ('*', textLen),
  567. X = subX,
  568. Y = 0,
  569. Width = Dim.Auto (Dim.DimAutoStyle.Text),
  570. Height = 1,
  571. ValidatePosDim = true
  572. };
  573. superView.Add (subView);
  574. superView.BeginInit ();
  575. superView.EndInit ();
  576. superView.SetRelativeLayout (superView.ContentSize);
  577. superView.LayoutSubviews ();
  578. Assert.Equal (expectedSubWidth, subView.Frame.Width);
  579. }
  580. [Theory]
  581. [InlineData (0, 1, 1)]
  582. [InlineData (1, 1, 1)]
  583. [InlineData (9, 1, 1)]
  584. [InlineData (10, 1, 1)]
  585. [InlineData (0, 10, 10)]
  586. [InlineData (1, 10, 10)]
  587. [InlineData (9, 10, 10)]
  588. [InlineData (10, 10, 10)]
  589. public void Width_Auto_Subviews_Does_Not_Constrain_To_SuperView (int subX, int subSubViewWidth, int expectedSubWidth)
  590. {
  591. var superView = new View
  592. {
  593. X = 0,
  594. Y = 0,
  595. Width = 10,
  596. Height = 1,
  597. ValidatePosDim = true
  598. };
  599. var subView = new View
  600. {
  601. X = subX,
  602. Y = 0,
  603. Width = Dim.Auto (Dim.DimAutoStyle.Content),
  604. Height = 1,
  605. ValidatePosDim = true
  606. };
  607. var subSubView = new View
  608. {
  609. X = 0,
  610. Y = 0,
  611. Width = subSubViewWidth,
  612. Height = 1,
  613. ValidatePosDim = true
  614. };
  615. subView.Add (subSubView);
  616. superView.Add (subView);
  617. superView.BeginInit ();
  618. superView.EndInit ();
  619. superView.SetRelativeLayout (superView.ContentSize);
  620. superView.LayoutSubviews ();
  621. Assert.Equal (expectedSubWidth, subView.Frame.Width);
  622. }
  623. [Fact]
  624. public void DimAutoStyle_Text_Viewport_Stays_Set ()
  625. {
  626. var super = new View ()
  627. {
  628. Width = Dim.Fill (),
  629. Height = Dim.Fill ()
  630. };
  631. var view = new View ()
  632. {
  633. Text = "01234567",
  634. Width = Auto (DimAutoStyle.Text),
  635. Height = Auto (DimAutoStyle.Text),
  636. };
  637. super.Add (view);
  638. Rectangle expectedViewport = new (0, 0, 8, 1);
  639. Assert.Equal (expectedViewport.Size, view.ContentSize);
  640. Assert.Equal (expectedViewport, view.Frame);
  641. Assert.Equal (expectedViewport, view.Viewport);
  642. super.LayoutSubviews ();
  643. Assert.Equal (expectedViewport, view.Viewport);
  644. super.Dispose ();
  645. }
  646. // TextFormatter.Size normally tracks ContentSize, but with DimAuto, tracks the text size
  647. [Theory]
  648. [InlineData ("", 0, 0)]
  649. [InlineData (" ", 1, 1)]
  650. [InlineData ("01234", 5, 1)]
  651. public void DimAutoStyle_Text_TextFormatter_Size_Ignores_ContentSize (string text, int expectedW, int expectedH)
  652. {
  653. var view = new View ();
  654. view.Width = Auto (DimAutoStyle.Text);
  655. view.Height = Auto (DimAutoStyle.Text);
  656. view.SetContentSize (new (1, 1));
  657. view.Text = text;
  658. Assert.Equal (new (expectedW, expectedH), view.TextFormatter.Size);
  659. }
  660. // Test that changing TextFormatter does not impact View dimensions if Dim.Auto is not in play
  661. [Fact]
  662. public void Not_Used_TextFormatter_Does_Not_Change_View_Size ()
  663. {
  664. View view = new ()
  665. {
  666. Text = "_1234"
  667. };
  668. Assert.False (view.TextFormatter.AutoSize);
  669. Assert.Equal (Size.Empty, view.Frame.Size);
  670. view.TextFormatter.Text = "ABC";
  671. Assert.False (view.TextFormatter.AutoSize);
  672. Assert.Equal (Size.Empty, view.Frame.Size);
  673. view.TextFormatter.Alignment = TextAlignment.Justified;
  674. Assert.False (view.TextFormatter.AutoSize);
  675. Assert.Equal (Size.Empty, view.Frame.Size);
  676. view.TextFormatter.VerticalAlignment = VerticalTextAlignment.Middle;
  677. Assert.False (view.TextFormatter.AutoSize);
  678. Assert.Equal (Size.Empty, view.Frame.Size);
  679. view.TextFormatter.HotKeySpecifier = (Rune)'*';
  680. Assert.False (view.TextFormatter.AutoSize);
  681. Assert.Equal (Size.Empty, view.Frame.Size);
  682. view.TextFormatter.Text = "*ABC";
  683. Assert.False (view.TextFormatter.AutoSize);
  684. Assert.Equal (Size.Empty, view.Frame.Size);
  685. }
  686. [Fact]
  687. public void Not_Used_TextSettings_Do_Not_Change_View_Size ()
  688. {
  689. View view = new ()
  690. {
  691. Text = "_1234"
  692. };
  693. Assert.False (view.TextFormatter.AutoSize);
  694. Assert.Equal (Size.Empty, view.Frame.Size);
  695. view.TextAlignment = TextAlignment.Justified;
  696. Assert.False (view.TextFormatter.AutoSize);
  697. Assert.Equal (Size.Empty, view.Frame.Size);
  698. view.VerticalTextAlignment = VerticalTextAlignment.Middle;
  699. Assert.False (view.TextFormatter.AutoSize);
  700. Assert.Equal (Size.Empty, view.Frame.Size);
  701. view.HotKeySpecifier = (Rune)'*';
  702. Assert.False (view.TextFormatter.AutoSize);
  703. Assert.Equal (Size.Empty, view.Frame.Size);
  704. view.Text = "*ABC";
  705. Assert.False (view.TextFormatter.AutoSize);
  706. Assert.Equal (Size.Empty, view.Frame.Size);
  707. }
  708. [Fact]
  709. public void TextFormatter_Settings_Change_View_Size ()
  710. {
  711. View view = new ()
  712. {
  713. Text = "_1234",
  714. Width = Dim.Auto ()
  715. };
  716. Assert.False (view.TextFormatter.AutoSize);
  717. Assert.NotEqual (Size.Empty, view.Frame.Size);
  718. view.TextAlignment = TextAlignment.Justified;
  719. Assert.False (view.TextFormatter.AutoSize);
  720. Assert.NotEqual (Size.Empty, view.Frame.Size);
  721. view = new ()
  722. {
  723. Text = "_1234",
  724. Width = Dim.Auto ()
  725. };
  726. view.VerticalTextAlignment = VerticalTextAlignment.Middle;
  727. Assert.False (view.TextFormatter.AutoSize);
  728. Assert.NotEqual (Size.Empty, view.Frame.Size);
  729. view = new ()
  730. {
  731. Text = "_1234",
  732. Width = Dim.Auto ()
  733. };
  734. view.HotKeySpecifier = (Rune)'*';
  735. Assert.False (view.TextFormatter.AutoSize);
  736. Assert.NotEqual (Size.Empty, view.Frame.Size);
  737. view = new ()
  738. {
  739. Text = "_1234",
  740. Width = Dim.Auto ()
  741. };
  742. view.Text = "*ABC";
  743. Assert.False (view.TextFormatter.AutoSize);
  744. Assert.NotEqual (Size.Empty, view.Frame.Size);
  745. }
  746. // Ensure TextFormatter.AutoSize is never used for View.Text
  747. [Fact]
  748. public void TextFormatter_Is_Not_Auto ()
  749. {
  750. View view = new ();
  751. Assert.False (view.TextFormatter.AutoSize);
  752. view.Width = Dim.Auto ();
  753. Assert.False (view.TextFormatter.AutoSize);
  754. view = new ();
  755. Assert.False (view.TextFormatter.AutoSize);
  756. view.Height = Dim.Auto ();
  757. Assert.False (view.TextFormatter.AutoSize);
  758. }
  759. [Theory]
  760. [InlineData ("1234", 4)]
  761. [InlineData ("_1234", 4)]
  762. public void Width_Auto_HotKey_TextFormatter_Size_Correct (string text, int expected)
  763. {
  764. View view = new ()
  765. {
  766. Text = text,
  767. Height = 1,
  768. Width = Dim.Auto ()
  769. };
  770. Assert.Equal (new (expected, 1), view.TextFormatter.Size);
  771. }
  772. [Theory]
  773. [InlineData ("1234", 4)]
  774. [InlineData ("_1234", 4)]
  775. public void Height_Auto_HotKey_TextFormatter_Size_Correct (string text, int expected)
  776. {
  777. View view = new ()
  778. {
  779. HotKeySpecifier = (Rune)'_',
  780. Text = text,
  781. Width = Auto (),
  782. Height = 1,
  783. };
  784. Assert.Equal (new (expected, 1), view.TextFormatter.Size);
  785. view = new ()
  786. {
  787. HotKeySpecifier = (Rune)'_',
  788. TextDirection = TextDirection.TopBottom_LeftRight,
  789. Text = text,
  790. Width = 1,
  791. Height = Auto (),
  792. };
  793. Assert.Equal (new (1, expected), view.TextFormatter.Size);
  794. }
  795. [SetupFakeDriver]
  796. [Fact]
  797. public void Change_To_Non_Auto_Resets_ContentSize ()
  798. {
  799. View view = new ()
  800. {
  801. Width = Auto (),
  802. Height = Auto (),
  803. Text = "01234"
  804. };
  805. Assert.Equal (new Rectangle (0, 0, 5, 1), view.Frame);
  806. Assert.Equal (new Size (5, 1), view.ContentSize);
  807. // Change text to a longer string
  808. view.Text = "0123456789";
  809. Assert.Equal (new Rectangle (0, 0, 10, 1), view.Frame);
  810. Assert.Equal (new Size (10, 1), view.ContentSize);
  811. // If ContentSize was reset, these should cause it to update
  812. view.Width = 5;
  813. view.Height = 1;
  814. Assert.Equal (new Size (5, 1), view.ContentSize);
  815. }
  816. // DimAutoStyle.Content tests
  817. [Fact]
  818. public void DimAutoStyle_Content_UsesContentSize_WhenSet ()
  819. {
  820. var view = new View ();
  821. view.SetContentSize (new (10, 5));
  822. var dim = Dim.Auto (Dim.DimAutoStyle.Content);
  823. int calculatedWidth = dim.Calculate (0, 100, view, Dim.Dimension.Width);
  824. Assert.Equal (10, calculatedWidth);
  825. }
  826. [Fact]
  827. public void DimAutoStyle_Content_IgnoresText_WhenContentSizeNotSet ()
  828. {
  829. var view = new View () { Text = "This is a test" };
  830. var dim = Dim.Auto (Dim.DimAutoStyle.Content);
  831. int calculatedWidth = dim.Calculate (0, 100, view, Dim.Dimension.Width);
  832. Assert.Equal (0, calculatedWidth); // Assuming 0 is the default when no ContentSize or Subviews are set
  833. }
  834. [Fact]
  835. public void DimAutoStyle_Content_UsesLargestSubview_WhenContentSizeNotSet ()
  836. {
  837. var view = new View ();
  838. view.Add (new View () { Frame = new Rectangle (0, 0, 5, 5) }); // Smaller subview
  839. view.Add (new View () { Frame = new Rectangle (0, 0, 10, 10) }); // Larger subview
  840. var dim = Dim.Auto (Dim.DimAutoStyle.Content);
  841. int calculatedWidth = dim.Calculate (0, 100, view, Dim.Dimension.Width);
  842. Assert.Equal (10, calculatedWidth); // Expecting the size of the largest subview
  843. }
  844. // All the Dim types
  845. [Theory]
  846. [InlineData (0, 15, 15)]
  847. [InlineData (1, 15, 16)]
  848. [InlineData (0, 15, 15)]
  849. [InlineData (-1, 15, 14)]
  850. public void With_Subview_Using_DimAbsolute (int subViewOffset, int dimAbsoluteSize, int expectedSize)
  851. {
  852. var view = new View ();
  853. var subview = new View ()
  854. {
  855. X = subViewOffset,
  856. Y = subViewOffset,
  857. Width = Dim.Sized (dimAbsoluteSize),
  858. Height = Dim.Sized (dimAbsoluteSize)
  859. };
  860. view.Add (subview);
  861. var dim = Dim.Auto (Dim.DimAutoStyle.Content);
  862. int calculatedWidth = dim.Calculate (0, 100, view, Dim.Dimension.Width);
  863. int calculatedHeight = dim.Calculate (0, 100, view, Dim.Dimension.Height);
  864. Assert.Equal (expectedSize, calculatedWidth);
  865. Assert.Equal (expectedSize, calculatedHeight);
  866. }
  867. [Theory]
  868. [InlineData (0, 50, 50)]
  869. [InlineData (1, 50, 51)]
  870. [InlineData (0, 25, 25)]
  871. [InlineData (-1, 50, 49)]
  872. public void With_Subview_Using_DimFactor (int subViewOffset, int dimFactor, int expectedSize)
  873. {
  874. var view = new View () { Width = 100, Height = 100 };
  875. var subview = new View ()
  876. {
  877. X = subViewOffset,
  878. Y = subViewOffset,
  879. Width = Dim.Percent (dimFactor),
  880. Height = Dim.Percent (dimFactor)
  881. };
  882. view.Add (subview);
  883. subview.SetRelativeLayout (new (100, 100));
  884. var dim = Dim.Auto (Dim.DimAutoStyle.Content);
  885. int calculatedWidth = dim.Calculate (0, 100, view, Dim.Dimension.Width);
  886. int calculatedHeight = dim.Calculate (0, 100, view, Dim.Dimension.Height);
  887. Assert.Equal (expectedSize, calculatedWidth);
  888. Assert.Equal (expectedSize, calculatedHeight);
  889. }
  890. [Theory]
  891. [InlineData (0, 0, 100)]
  892. [InlineData (1, 0, 100)]
  893. [InlineData (0, 1, 99)]
  894. [InlineData (1, 1, 99)]
  895. public void With_Subview_Using_DimFill (int subViewOffset, int dimFillMargin, int expectedSize)
  896. {
  897. var view = new View ();
  898. var subview = new View ()
  899. {
  900. X = subViewOffset,
  901. Y = subViewOffset,
  902. Width = Dim.Fill (dimFillMargin),
  903. Height = Dim.Fill (dimFillMargin)
  904. };
  905. view.Add (subview);
  906. subview.SetRelativeLayout (new (100, 100));
  907. var dim = Dim.Auto (Dim.DimAutoStyle.Content);
  908. // Assuming the view's size is 100x100 for calculation purposes
  909. int calculatedWidth = dim.Calculate (0, 100, view, Dim.Dimension.Width);
  910. int calculatedHeight = dim.Calculate (0, 100, view, Dim.Dimension.Height);
  911. Assert.Equal (expectedSize, calculatedWidth);
  912. Assert.Equal (expectedSize, calculatedHeight);
  913. }
  914. [Fact]
  915. public void With_Subview_Using_DimFunc ()
  916. {
  917. var view = new View ();
  918. var subview = new View () { Width = Dim.Function (() => 20), Height = Dim.Function (() => 25) };
  919. view.Add (subview);
  920. subview.SetRelativeLayout (new (100, 100));
  921. var dim = Dim.Auto (Dim.DimAutoStyle.Content);
  922. int calculatedWidth = dim.Calculate (0, 100, view, Dim.Dimension.Width);
  923. int calculatedHeight = dim.Calculate (0, 100, view, Dim.Dimension.Height);
  924. Assert.Equal (20, calculatedWidth);
  925. Assert.Equal (25, calculatedHeight);
  926. }
  927. [Fact]
  928. public void With_Subview_Using_DimView ()
  929. {
  930. var view = new View ();
  931. var subview = new View () { Width = 30, Height = 40 };
  932. var subSubview = new View () { Width = Dim.Width (subview), Height = Dim.Height (subview) };
  933. view.Add (subview);
  934. view.Add (subSubview);
  935. subview.SetRelativeLayout (new (100, 100));
  936. var dim = Dim.Auto (Dim.DimAutoStyle.Content);
  937. int calculatedWidth = dim.Calculate (0, 100, view, Dim.Dimension.Width);
  938. int calculatedHeight = dim.Calculate (0, 100, view, Dim.Dimension.Height);
  939. // Expecting the size to match the subview, which is the largest
  940. Assert.Equal (30, calculatedWidth);
  941. Assert.Equal (40, calculatedHeight);
  942. }
  943. // Testing all Pos combinations
  944. [Fact]
  945. public void With_Subview_At_PosAt ()
  946. {
  947. var view = new View ();
  948. var subview = new View () { X = Pos.At (10), Y = Pos.At (5), Width = 20, Height = 10 };
  949. view.Add (subview);
  950. var dimWidth = Dim.Auto ();
  951. var dimHeight = Dim.Auto ();
  952. int calculatedWidth = dimWidth.Calculate (0, 100, view, Dim.Dimension.Width);
  953. int calculatedHeight = dimHeight.Calculate (0, 100, view, Dim.Dimension.Height);
  954. // Expecting the size to include the subview's position and size
  955. Assert.Equal (30, calculatedWidth); // 10 (X position) + 20 (Width)
  956. Assert.Equal (15, calculatedHeight); // 5 (Y position) + 10 (Height)
  957. }
  958. [Fact (Skip = "TextOnly")]
  959. public void With_Subview_At_PosPercent ()
  960. {
  961. var view = new View () { Width = 100, Height = 100 };
  962. var subview = new View () { X = Pos.Percent (50), Y = Pos.Percent (50), Width = 20, Height = 10 };
  963. view.Add (subview);
  964. var dimWidth = Dim.Auto ();
  965. var dimHeight = Dim.Auto ();
  966. // Assuming the calculation is done after layout
  967. int calculatedWidth = dimWidth.Calculate (0, 100, view, Dim.Dimension.Width);
  968. int calculatedHeight = dimHeight.Calculate (0, 100, view, Dim.Dimension.Height);
  969. // Expecting the size to include the subview's position as a percentage of the parent view's size plus the subview's size
  970. Assert.Equal (70, calculatedWidth); // 50% of 100 (Width) + 20
  971. Assert.Equal (60, calculatedHeight); // 50% of 100 (Height) + 10
  972. }
  973. [Fact (Skip = "TextOnly")]
  974. public void With_Subview_At_PosCenter ()
  975. {
  976. var view = new View () { Width = 100, Height = 100 };
  977. var subview = new View () { X = Pos.Center (), Y = Pos.Center (), Width = 20, Height = 10 };
  978. view.Add (subview);
  979. var dimWidth = Dim.Auto ();
  980. var dimHeight = Dim.Auto ();
  981. // Assuming the calculation is done after layout
  982. int calculatedWidth = dimWidth.Calculate (0, 100, view, Dim.Dimension.Width);
  983. int calculatedHeight = dimHeight.Calculate (0, 100, view, Dim.Dimension.Height);
  984. // Expecting the size to include the subview's position at the center of the parent view plus the subview's size
  985. Assert.Equal (70, calculatedWidth); // Centered in 100 (Width) + 20
  986. Assert.Equal (60, calculatedHeight); // Centered in 100 (Height) + 10
  987. }
  988. [Fact (Skip = "TextOnly")]
  989. public void With_Subview_At_PosAnchorEnd ()
  990. {
  991. var dimWidth = Dim.Auto (minimumContentDim: 50);
  992. var dimHeight = Dim.Auto (minimumContentDim: 50);
  993. var view = new View ()
  994. {
  995. Width = dimWidth,
  996. Height = dimHeight
  997. };
  998. var subview = new View ()
  999. {
  1000. X = Pos.AnchorEnd (),
  1001. Y = Pos.AnchorEnd (),
  1002. Width = 20,
  1003. Height = 10
  1004. };
  1005. view.Add (subview);
  1006. // Assuming the calculation is done after layout
  1007. int calculatedWidth = dimWidth.Calculate (0, 100, view, Dim.Dimension.Width);
  1008. int calculatedHeight = dimHeight.Calculate (0, 100, view, Dim.Dimension.Height);
  1009. // Expecting the size to include the subview's position at the end of the parent view minus the offset plus the subview's size
  1010. Assert.Equal (100, calculatedWidth);
  1011. Assert.Equal (100, calculatedHeight);
  1012. }
  1013. [Fact]
  1014. public void DimAutoStyle_Text_Pos_AnchorEnd_Locates_Correctly ()
  1015. {
  1016. DimAutoTestView view = new ("01234", Auto (DimAutoStyle.Text), Auto (DimAutoStyle.Text));
  1017. view.SetRelativeLayout (new (10, 10));
  1018. Assert.Equal (new (5, 1), view.Frame.Size);
  1019. Assert.Equal (new (0, 0), view.Frame.Location);
  1020. view.X = 0;
  1021. view.Y = Pos.AnchorEnd (1);
  1022. view.SetRelativeLayout (new (10, 10));
  1023. Assert.Equal (new (5, 1), view.Frame.Size);
  1024. Assert.Equal (new (0, 9), view.Frame.Location);
  1025. view.Y = Pos.AnchorEnd ();
  1026. view.SetRelativeLayout (new (10, 10));
  1027. Assert.Equal (new (5, 1), view.Frame.Size);
  1028. Assert.Equal (new (0, 9), view.Frame.Location);
  1029. view.Y = Pos.AnchorEnd () - 1;
  1030. view.SetRelativeLayout (new (10, 10));
  1031. Assert.Equal (new (5, 1), view.Frame.Size);
  1032. Assert.Equal (new (0, 8), view.Frame.Location);
  1033. }
  1034. [Fact]
  1035. public void DimAutoStyle_Content_Pos_AnchorEnd_Locates_Correctly ()
  1036. {
  1037. DimAutoTestView view = new (Auto (DimAutoStyle.Content), Auto (DimAutoStyle.Content));
  1038. View subView = new ()
  1039. {
  1040. Width = 5,
  1041. Height = 1
  1042. };
  1043. view.Add (subView);
  1044. view.SetRelativeLayout (new (10, 10));
  1045. Assert.Equal (new (5, 1), view.Frame.Size);
  1046. Assert.Equal (new (0, 0), view.Frame.Location);
  1047. view.X = 0;
  1048. view.Y = Pos.AnchorEnd (1);
  1049. view.SetRelativeLayout (new (10, 10));
  1050. Assert.Equal (new (5, 1), view.Frame.Size);
  1051. Assert.Equal (new (0, 9), view.Frame.Location);
  1052. view.Y = Pos.AnchorEnd ();
  1053. view.SetRelativeLayout (new (10, 10));
  1054. Assert.Equal (new (5, 1), view.Frame.Size);
  1055. Assert.Equal (new (0, 9), view.Frame.Location);
  1056. view.Y = Pos.AnchorEnd () - 1;
  1057. view.SetRelativeLayout (new (10, 10));
  1058. Assert.Equal (new (5, 1), view.Frame.Size);
  1059. Assert.Equal (new (0, 8), view.Frame.Location);
  1060. }
  1061. [Theory]
  1062. [InlineData ("01234", 5, 5)]
  1063. [InlineData ("01234", 6, 6)]
  1064. [InlineData ("01234", 4, 5)]
  1065. [InlineData ("01234", 0, 5)]
  1066. [InlineData ("", 5, 5)]
  1067. [InlineData ("", 0, 0)]
  1068. public void DimAutoStyle_Auto_Larger_Wins (string text, int dimension, int expected)
  1069. {
  1070. View view = new ()
  1071. {
  1072. Width = Auto (),
  1073. Text = text
  1074. };
  1075. View subView = new ()
  1076. {
  1077. Width = dimension,
  1078. };
  1079. view.Add (subView);
  1080. view.SetRelativeLayout (new (10, 10));
  1081. Assert.Equal (expected, view.Frame.Width);
  1082. }
  1083. [Fact]
  1084. public void DimAutoStyle_Content_UsesContentSize_If_No_Subviews ()
  1085. {
  1086. DimAutoTestView view = new (Auto (DimAutoStyle.Content), Auto (DimAutoStyle.Content));
  1087. view.SetContentSize (new (5, 5));
  1088. view.SetRelativeLayout (new (10, 10));
  1089. Assert.Equal (new (5, 5), view.Frame.Size);
  1090. }
  1091. // Test variations of Frame
  1092. }