LayoutTests.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795
  1. using System;
  2. using System.Text;
  3. using Xunit;
  4. using Xunit.Abstractions;
  5. // Alias Console to MockConsole so we don't accidentally use Console
  6. using Console = Terminal.Gui.FakeConsole;
  7. namespace Terminal.Gui.ViewTests;
  8. public class LayoutTests {
  9. readonly ITestOutputHelper _output;
  10. public LayoutTests (ITestOutputHelper output) => _output = output;
  11. [Fact]
  12. public void TopologicalSort_Missing_Add ()
  13. {
  14. var root = new View ();
  15. var sub1 = new View ();
  16. root.Add (sub1);
  17. var sub2 = new View ();
  18. sub1.Width = Dim.Width (sub2);
  19. Assert.Throws<InvalidOperationException> (() => root.LayoutSubviews ());
  20. sub2.Width = Dim.Width (sub1);
  21. Assert.Throws<InvalidOperationException> (() => root.LayoutSubviews ());
  22. root.Dispose ();
  23. sub1.Dispose ();
  24. sub2.Dispose ();
  25. }
  26. [Fact]
  27. public void TopologicalSort_Recursive_Ref ()
  28. {
  29. var root = new View ();
  30. var sub1 = new View ();
  31. root.Add (sub1);
  32. var sub2 = new View ();
  33. root.Add (sub2);
  34. sub2.Width = Dim.Width (sub2);
  35. var exception = Record.Exception (root.LayoutSubviews);
  36. Assert.Null (exception);
  37. root.Dispose ();
  38. sub1.Dispose ();
  39. sub2.Dispose ();
  40. }
  41. [Fact]
  42. public void LayoutSubviews_No_SuperView ()
  43. {
  44. var root = new View ();
  45. var first = new View () { Id = "first", X = 1, Y = 2, Height = 3, Width = 4 };
  46. root.Add (first);
  47. var second = new View () { Id = "second" };
  48. root.Add (second);
  49. second.X = Pos.Right (first) + 1;
  50. root.LayoutSubviews ();
  51. Assert.Equal (6, second.Frame.X);
  52. root.Dispose ();
  53. first.Dispose ();
  54. second.Dispose ();
  55. }
  56. [Fact]
  57. public void LayoutSubviews_RootHas_SuperView ()
  58. {
  59. var top = new View ();
  60. var root = new View ();
  61. top.Add (root);
  62. var first = new View () { Id = "first", X = 1, Y = 2, Height = 3, Width = 4 };
  63. root.Add (first);
  64. var second = new View () { Id = "second" };
  65. root.Add (second);
  66. second.X = Pos.Right (first) + 1;
  67. root.LayoutSubviews ();
  68. Assert.Equal (6, second.Frame.X);
  69. root.Dispose ();
  70. top.Dispose ();
  71. first.Dispose ();
  72. second.Dispose ();
  73. }
  74. [Fact]
  75. public void LayoutSubviews_ViewThatRefsSubView_Throws ()
  76. {
  77. var root = new View ();
  78. var super = new View ();
  79. root.Add (super);
  80. var sub = new View ();
  81. super.Add (sub);
  82. super.Width = Dim.Width (sub);
  83. Assert.Throws<InvalidOperationException> (() => root.LayoutSubviews ());
  84. root.Dispose ();
  85. super.Dispose ();
  86. }
  87. [Fact] [AutoInitShutdown]
  88. public void TrySetWidth_ForceValidatePosDim ()
  89. {
  90. var top = new View () {
  91. X = 0,
  92. Y = 0,
  93. Width = 80
  94. };
  95. var v = new View () {
  96. Width = Dim.Fill (),
  97. ValidatePosDim = true
  98. };
  99. top.Add (v);
  100. Assert.False (v.TrySetWidth (70, out int rWidth));
  101. Assert.Equal (70, rWidth);
  102. v.Width = Dim.Fill (1);
  103. Assert.False (v.TrySetWidth (70, out rWidth));
  104. Assert.Equal (69, rWidth);
  105. v.Width = 0;
  106. Assert.True (v.TrySetWidth (70, out rWidth));
  107. Assert.Equal (70, rWidth);
  108. Assert.False (v.IsInitialized);
  109. Application.Top.Add (top);
  110. Application.Begin (Application.Top);
  111. Assert.True (v.IsInitialized);
  112. v.Width = 75;
  113. Assert.True (v.TrySetWidth (60, out rWidth));
  114. Assert.Equal (60, rWidth);
  115. }
  116. [Fact] [AutoInitShutdown]
  117. public void TrySetHeight_ForceValidatePosDim ()
  118. {
  119. var top = new View () {
  120. X = 0,
  121. Y = 0,
  122. Height = 20
  123. };
  124. var v = new View () {
  125. Height = Dim.Fill (),
  126. ValidatePosDim = true
  127. };
  128. top.Add (v);
  129. Assert.False (v.TrySetHeight (10, out int rHeight));
  130. Assert.Equal (10, rHeight);
  131. v.Height = Dim.Fill (1);
  132. Assert.False (v.TrySetHeight (10, out rHeight));
  133. Assert.Equal (9, rHeight);
  134. v.Height = 0;
  135. Assert.True (v.TrySetHeight (10, out rHeight));
  136. Assert.Equal (10, rHeight);
  137. Assert.False (v.IsInitialized);
  138. Application.Top.Add (top);
  139. Application.Begin (Application.Top);
  140. Assert.True (v.IsInitialized);
  141. v.Height = 15;
  142. Assert.True (v.TrySetHeight (5, out rHeight));
  143. Assert.Equal (5, rHeight);
  144. }
  145. [Fact] [TestRespondersDisposed]
  146. public void GetCurrentWidth_TrySetWidth ()
  147. {
  148. var top = new View () {
  149. X = 0,
  150. Y = 0,
  151. Width = 80
  152. };
  153. var v = new View () {
  154. Width = Dim.Fill ()
  155. };
  156. top.Add (v);
  157. top.BeginInit ();
  158. top.EndInit ();
  159. top.LayoutSubviews ();
  160. Assert.False (v.AutoSize);
  161. Assert.True (v.TrySetWidth (0, out _));
  162. Assert.Equal (80, v.Frame.Width);
  163. v.Width = Dim.Fill (1);
  164. top.LayoutSubviews ();
  165. Assert.True (v.TrySetWidth (0, out _));
  166. Assert.Equal (79, v.Frame.Width);
  167. v.AutoSize = true;
  168. top.LayoutSubviews ();
  169. Assert.True (v.TrySetWidth (0, out _));
  170. top.Dispose ();
  171. }
  172. [Fact]
  173. public void GetCurrentHeight_TrySetHeight ()
  174. {
  175. var top = new View () {
  176. X = 0,
  177. Y = 0,
  178. Height = 20
  179. };
  180. var v = new View () {
  181. Height = Dim.Fill ()
  182. };
  183. top.Add (v);
  184. top.BeginInit ();
  185. top.EndInit ();
  186. top.LayoutSubviews ();
  187. Assert.False (v.AutoSize);
  188. Assert.True (v.TrySetHeight (0, out _));
  189. Assert.Equal (20, v.Frame.Height);
  190. v.Height = Dim.Fill (1);
  191. top.LayoutSubviews ();
  192. Assert.True (v.TrySetHeight (0, out _));
  193. Assert.Equal (19, v.Frame.Height);
  194. v.AutoSize = true;
  195. top.LayoutSubviews ();
  196. Assert.True (v.TrySetHeight (0, out _));
  197. top.Dispose ();
  198. }
  199. [Fact] [AutoInitShutdown]
  200. public void Width_Height_SetMinWidthHeight_Narrow_Wide_Runes ()
  201. {
  202. string text = $"First line{Environment.NewLine}Second line";
  203. var horizontalView = new View () {
  204. Width = 20,
  205. Height = 1,
  206. Text = text
  207. };
  208. var verticalView = new View () {
  209. Y = 3,
  210. Height = 20,
  211. Width = 1,
  212. Text = text,
  213. TextDirection = TextDirection.TopBottom_LeftRight
  214. };
  215. var win = new Window () {
  216. Width = Dim.Fill (),
  217. Height = Dim.Fill (),
  218. Text = "Window"
  219. };
  220. win.Add (horizontalView, verticalView);
  221. Application.Top.Add (win);
  222. var rs = Application.Begin (Application.Top);
  223. ((FakeDriver)Application.Driver).SetBufferSize (32, 32);
  224. Assert.False (horizontalView.AutoSize);
  225. Assert.False (verticalView.AutoSize);
  226. Assert.Equal (new Rect (0, 0, 20, 1), horizontalView.Frame);
  227. Assert.Equal (new Rect (0, 3, 1, 20), verticalView.Frame);
  228. string expected = @"
  229. ┌──────────────────────────────┐
  230. │First line Second li │
  231. │ │
  232. │ │
  233. │F │
  234. │i │
  235. │r │
  236. │s │
  237. │t │
  238. │ │
  239. │l │
  240. │i │
  241. │n │
  242. │e │
  243. │ │
  244. │S │
  245. │e │
  246. │c │
  247. │o │
  248. │n │
  249. │d │
  250. │ │
  251. │l │
  252. │i │
  253. │ │
  254. │ │
  255. │ │
  256. │ │
  257. │ │
  258. │ │
  259. │ │
  260. └──────────────────────────────┘
  261. ";
  262. var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
  263. Assert.Equal (new Rect (0, 0, 32, 32), pos);
  264. verticalView.Text = $"最初の行{Environment.NewLine}二行目";
  265. Application.Top.Draw ();
  266. Assert.Equal (new Rect (0, 3, 2, 20), verticalView.Frame);
  267. expected = @"
  268. ┌──────────────────────────────┐
  269. │First line Second li │
  270. │ │
  271. │ │
  272. │最 │
  273. │初 │
  274. │の │
  275. │行 │
  276. │ │
  277. │二 │
  278. │行 │
  279. │目 │
  280. │ │
  281. │ │
  282. │ │
  283. │ │
  284. │ │
  285. │ │
  286. │ │
  287. │ │
  288. │ │
  289. │ │
  290. │ │
  291. │ │
  292. │ │
  293. │ │
  294. │ │
  295. │ │
  296. │ │
  297. │ │
  298. │ │
  299. └──────────────────────────────┘
  300. ";
  301. pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
  302. Assert.Equal (new Rect (0, 0, 32, 32), pos);
  303. Application.End (rs);
  304. }
  305. // Tested in AbsoluteLayoutTests.cs
  306. // public void Pos_Dim_Are_Null_If_Not_Initialized_On_Constructor_IsAdded_False ()
  307. [Theory] [AutoInitShutdown]
  308. [InlineData (1)]
  309. [InlineData (2)]
  310. [InlineData (3)]
  311. [InlineData (4)]
  312. [InlineData (5)]
  313. [InlineData (6)]
  314. [InlineData (7)]
  315. [InlineData (8)]
  316. [InlineData (9)]
  317. [InlineData (10)]
  318. public void Dim_CenteredSubView_85_Percent_Height (int height)
  319. {
  320. var win = new Window () {
  321. Width = Dim.Fill (),
  322. Height = Dim.Fill ()
  323. };
  324. var subview = new Window () {
  325. X = Pos.Center (),
  326. Y = Pos.Center (),
  327. Width = Dim.Percent (85),
  328. Height = Dim.Percent (85)
  329. };
  330. win.Add (subview);
  331. var rs = Application.Begin (win);
  332. bool firstIteration = false;
  333. ((FakeDriver)Application.Driver).SetBufferSize (20, height);
  334. Application.RunIteration (ref rs, ref firstIteration);
  335. string expected = string.Empty;
  336. switch (height) {
  337. case 1:
  338. //Assert.Equal (new Rect (0, 0, 17, 0), subview.Frame);
  339. expected = @"
  340. ────────────────────";
  341. break;
  342. case 2:
  343. //Assert.Equal (new Rect (0, 0, 17, 1), subview.Frame);
  344. expected = @"
  345. ┌──────────────────┐
  346. └──────────────────┘
  347. ";
  348. break;
  349. case 3:
  350. //Assert.Equal (new Rect (0, 0, 17, 2), subview.Frame);
  351. expected = @"
  352. ┌──────────────────┐
  353. │ │
  354. └──────────────────┘
  355. ";
  356. break;
  357. case 4:
  358. //Assert.Equal (new Rect (0, 0, 17, 3), subview.Frame);
  359. expected = @"
  360. ┌──────────────────┐
  361. │ ─────────────── │
  362. │ │
  363. └──────────────────┘";
  364. break;
  365. case 5:
  366. //Assert.Equal (new Rect (0, 0, 17, 3), subview.Frame);
  367. expected = @"
  368. ┌──────────────────┐
  369. │ ┌─────────────┐ │
  370. │ └─────────────┘ │
  371. │ │
  372. └──────────────────┘";
  373. break;
  374. case 6:
  375. //Assert.Equal (new Rect (0, 0, 17, 3), subview.Frame);
  376. expected = @"
  377. ┌──────────────────┐
  378. │ ┌─────────────┐ │
  379. │ │ │ │
  380. │ └─────────────┘ │
  381. │ │
  382. └──────────────────┘";
  383. break;
  384. case 7:
  385. //Assert.Equal (new Rect (0, 0, 17, 3), subview.Frame);
  386. expected = @"
  387. ┌──────────────────┐
  388. │ ┌─────────────┐ │
  389. │ │ │ │
  390. │ │ │ │
  391. │ └─────────────┘ │
  392. │ │
  393. └──────────────────┘";
  394. break;
  395. case 8:
  396. //Assert.Equal (new Rect (0, 0, 17, 3), subview.Frame);
  397. expected = @"
  398. ┌──────────────────┐
  399. │ ┌─────────────┐ │
  400. │ │ │ │
  401. │ │ │ │
  402. │ │ │ │
  403. │ └─────────────┘ │
  404. │ │
  405. └──────────────────┘";
  406. break;
  407. case 9:
  408. //Assert.Equal (new Rect (0, 0, 17, 3), subview.Frame);
  409. expected = @"
  410. ┌──────────────────┐
  411. │ │
  412. │ ┌─────────────┐ │
  413. │ │ │ │
  414. │ │ │ │
  415. │ │ │ │
  416. │ └─────────────┘ │
  417. │ │
  418. └──────────────────┘";
  419. break;
  420. case 10:
  421. //Assert.Equal (new Rect (0, 0, 17, 3), subview.Frame);
  422. expected = @"
  423. ┌──────────────────┐
  424. │ │
  425. │ ┌─────────────┐ │
  426. │ │ │ │
  427. │ │ │ │
  428. │ │ │ │
  429. │ │ │ │
  430. │ └─────────────┘ │
  431. │ │
  432. └──────────────────┘";
  433. break;
  434. }
  435. _ = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
  436. Application.End (rs);
  437. }
  438. [Theory] [AutoInitShutdown]
  439. [InlineData (1)]
  440. [InlineData (2)]
  441. [InlineData (3)]
  442. [InlineData (4)]
  443. [InlineData (5)]
  444. [InlineData (6)]
  445. [InlineData (7)]
  446. [InlineData (8)]
  447. [InlineData (9)]
  448. [InlineData (10)]
  449. public void Dim_CenteredSubView_85_Percent_Width (int width)
  450. {
  451. var win = new Window () {
  452. Width = Dim.Fill (),
  453. Height = Dim.Fill ()
  454. };
  455. var subview = new Window () {
  456. X = Pos.Center (),
  457. Y = Pos.Center (),
  458. Width = Dim.Percent (85),
  459. Height = Dim.Percent (85)
  460. };
  461. win.Add (subview);
  462. var rs = Application.Begin (win);
  463. bool firstIteration = false;
  464. ((FakeDriver)Application.Driver).SetBufferSize (width, 7);
  465. Application.RunIteration (ref rs, ref firstIteration);
  466. string expected = string.Empty;
  467. switch (width) {
  468. case 1:
  469. Assert.Equal (new Rect (0, 0, 0, 4), subview.Frame);
  470. expected = @"
  471. │";
  472. break;
  473. case 2:
  474. Assert.Equal (new Rect (0, 0, 0, 4), subview.Frame);
  475. expected = @"
  476. ┌┐
  477. ││
  478. ││
  479. ││
  480. ││
  481. ││
  482. └┘";
  483. break;
  484. case 3:
  485. Assert.Equal (new Rect (0, 0, 0, 4), subview.Frame);
  486. expected = @"
  487. ┌─┐
  488. │ │
  489. │ │
  490. │ │
  491. │ │
  492. │ │
  493. └─┘";
  494. break;
  495. case 4:
  496. Assert.Equal (new Rect (0, 0, 1, 4), subview.Frame);
  497. expected = @"
  498. ┌──┐
  499. ││ │
  500. ││ │
  501. ││ │
  502. ││ │
  503. │ │
  504. └──┘";
  505. break;
  506. case 5:
  507. Assert.Equal (new Rect (0, 0, 2, 4), subview.Frame);
  508. expected = @"
  509. ┌───┐
  510. │┌┐ │
  511. │││ │
  512. │││ │
  513. │└┘ │
  514. │ │
  515. └───┘";
  516. break;
  517. case 6:
  518. Assert.Equal (new Rect (0, 0, 3, 4), subview.Frame);
  519. expected = @"
  520. ┌────┐
  521. │┌─┐ │
  522. ││ │ │
  523. ││ │ │
  524. │└─┘ │
  525. │ │
  526. └────┘";
  527. break;
  528. case 7:
  529. Assert.Equal (new Rect (0, 0, 4, 4), subview.Frame);
  530. expected = @"
  531. ┌─────┐
  532. │┌──┐ │
  533. ││ │ │
  534. ││ │ │
  535. │└──┘ │
  536. │ │
  537. └─────┘";
  538. break;
  539. case 8:
  540. Assert.Equal (new Rect (0, 0, 5, 4), subview.Frame);
  541. expected = @"
  542. ┌──────┐
  543. │┌───┐ │
  544. ││ │ │
  545. ││ │ │
  546. │└───┘ │
  547. │ │
  548. └──────┘";
  549. break;
  550. case 9:
  551. Assert.Equal (new Rect (1, 0, 5, 4), subview.Frame);
  552. expected = @"
  553. ┌───────┐
  554. │ ┌───┐ │
  555. │ │ │ │
  556. │ │ │ │
  557. │ └───┘ │
  558. │ │
  559. └───────┘";
  560. break;
  561. case 10:
  562. Assert.Equal (new Rect (1, 0, 6, 4), subview.Frame);
  563. expected = @"
  564. ┌────────┐
  565. │ ┌────┐ │
  566. │ │ │ │
  567. │ │ │ │
  568. │ └────┘ │
  569. │ │
  570. └────────┘";
  571. break;
  572. }
  573. _ = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
  574. Application.End (rs);
  575. }
  576. [Fact] [AutoInitShutdown]
  577. public void PosCombine_DimCombine_View_With_SubViews ()
  578. {
  579. bool clicked = false;
  580. var top = Application.Top;
  581. var win1 = new Window () { Id = "win1", Width = 20, Height = 10 };
  582. var view1 = new View ("view1");
  583. var win2 = new Window () { Id = "win2", Y = Pos.Bottom (view1) + 1, Width = 10, Height = 3 };
  584. var view2 = new View () { Id = "view2", Width = Dim.Fill (), Height = 1, CanFocus = true };
  585. view2.MouseClick += (sender, e) => clicked = true;
  586. var view3 = new View () { Id = "view3", Width = Dim.Fill (1), Height = 1, CanFocus = true };
  587. view2.Add (view3);
  588. win2.Add (view2);
  589. win1.Add (view1, win2);
  590. top.Add (win1);
  591. var rs = Application.Begin (top);
  592. TestHelpers.AssertDriverContentsWithFrameAre (@"
  593. ┌──────────────────┐
  594. │view1 │
  595. │ │
  596. │┌────────┐ │
  597. ││ │ │
  598. │└────────┘ │
  599. │ │
  600. │ │
  601. │ │
  602. └──────────────────┘", _output);
  603. Assert.Equal (new Rect (0, 0, 80, 25), top.Frame);
  604. Assert.Equal (new Rect (0, 0, 5, 1), view1.Frame);
  605. Assert.Equal (new Rect (0, 0, 20, 10), win1.Frame);
  606. Assert.Equal (new Rect (0, 2, 10, 3), win2.Frame);
  607. Assert.Equal (new Rect (0, 0, 8, 1), view2.Frame);
  608. Assert.Equal (new Rect (0, 0, 7, 1), view3.Frame);
  609. var foundView = View.FindDeepestView (top, 9, 4, out int rx, out int ry);
  610. Assert.Equal (foundView, view2);
  611. Application.OnMouseEvent (new MouseEventEventArgs (new MouseEvent () {
  612. X = 9,
  613. Y = 4,
  614. Flags = MouseFlags.Button1Clicked
  615. }));
  616. Assert.True (clicked);
  617. Application.End (rs);
  618. }
  619. [Fact] [TestRespondersDisposed]
  620. public void Draw_Vertical_Throws_IndexOutOfRangeException_With_Negative_Bounds ()
  621. {
  622. Application.Init (new FakeDriver ());
  623. var top = Application.Top;
  624. var view = new View ("view") {
  625. Y = -2,
  626. Height = 10,
  627. TextDirection = TextDirection.TopBottom_LeftRight
  628. };
  629. top.Add (view);
  630. Application.Iteration += (s, a) => {
  631. Assert.Equal (-2, view.Y);
  632. Application.RequestStop ();
  633. };
  634. try {
  635. Application.Run ();
  636. } catch (IndexOutOfRangeException ex) {
  637. // After the fix this exception will not be caught.
  638. Assert.IsType<IndexOutOfRangeException> (ex);
  639. }
  640. // Shutdown must be called to safely clean up Application if Init has been called
  641. Application.Shutdown ();
  642. }
  643. [Fact] [TestRespondersDisposed]
  644. public void Draw_Throws_IndexOutOfRangeException_With_Negative_Bounds ()
  645. {
  646. Application.Init (new FakeDriver ());
  647. var top = Application.Top;
  648. var view = new View ("view") { X = -2 };
  649. top.Add (view);
  650. Application.Iteration += (s, a) => {
  651. Assert.Equal (-2, view.X);
  652. Application.RequestStop ();
  653. };
  654. try {
  655. Application.Run ();
  656. } catch (IndexOutOfRangeException ex) {
  657. // After the fix this exception will not be caught.
  658. Assert.IsType<IndexOutOfRangeException> (ex);
  659. }
  660. // Shutdown must be called to safely clean up Application if Init has been called
  661. Application.Shutdown ();
  662. }
  663. // Was named AutoSize_Pos_Validation_Do_Not_Throws_If_NewValue_Is_PosAbsolute_And_OldValue_Is_Another_Type_After_Sets_To_LayoutStyle_Absolute ()
  664. // but doesn't actually have anything to do with AutoSize.
  665. [Fact]
  666. public void AutoSize_Pos_Validation_Do_Not_Throws_If_NewValue_Is_PosAbsolute_And_OldValue_Is_Another_Type_After_Sets_To_LayoutStyle_Absolute ()
  667. {
  668. Application.Init (new FakeDriver ());
  669. var t = Application.Top;
  670. var w = new Window () {
  671. X = Pos.Left (t) + 2,
  672. Y = Pos.At (2)
  673. };
  674. var v = new View () {
  675. X = Pos.Center (),
  676. Y = Pos.Percent (10)
  677. };
  678. w.Add (v);
  679. t.Add (w);
  680. t.Ready += (s, e) => {
  681. v.LayoutStyle = LayoutStyle.Absolute;
  682. Assert.Equal (2, v.X = 2);
  683. Assert.Equal (2, v.Y = 2);
  684. };
  685. Application.Iteration += (s, a) => Application.RequestStop ();
  686. Application.Run ();
  687. Application.Shutdown ();
  688. }
  689. }