LayoutTests.cs 18 KB

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