Dim.AutoTests.cs 38 KB

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