TileViewTests.cs 75 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406
  1. using UnitTests;
  2. using Xunit.Abstractions;
  3. namespace Terminal.Gui.ViewsTests;
  4. public class TileViewTests (ITestOutputHelper output)
  5. {
  6. [Fact]
  7. [AutoInitShutdown]
  8. public void Test_SplitTop_WholeBottom ()
  9. {
  10. var tileView = new TileView (2)
  11. {
  12. Width = 20, Height = 10, Orientation = Orientation.Horizontal, LineStyle = LineStyle.Single
  13. };
  14. Assert.True (tileView.TrySplitTile (0, 2, out TileView top));
  15. top.Tiles.ElementAt (0).ContentView!.Add (new Label { Text = "bleh" });
  16. top.Tiles.ElementAt (1).ContentView!.Add (new Label { Text = "blah" });
  17. top.Layout ();
  18. tileView.Tiles.ElementAt (1).ContentView!.Add (new Label { Text = "Hello" });
  19. tileView.SetScheme (new ());
  20. top.SetScheme (new ());
  21. top.Layout ();
  22. tileView.Layout ();
  23. tileView.Draw ();
  24. var looksLike =
  25. @"
  26. ┌─────────┬────────┐
  27. │bleh │blah │
  28. │ │ │
  29. │ │ │
  30. │ │ │
  31. ├─────────┴────────┤
  32. │Hello │
  33. │ │
  34. │ │
  35. └──────────────────┘";
  36. DriverAssert.AssertDriverContentsAre (looksLike, output);
  37. }
  38. [Fact]
  39. [AutoInitShutdown]
  40. public void Test5Panel_MinSizes_VerticalSplitters_ResizeSplitter1 ()
  41. {
  42. TileView tv = Get5x1TilesView ();
  43. tv.Tiles.ElementAt (0).MinSize = int.MaxValue;
  44. AutoInitShutdownAttribute.RunIteration ();
  45. var looksLike =
  46. @"
  47. ┌────┬────┬────┬────┬───┐
  48. │1111│2222│3333│4444│555│
  49. │ │ │ │ │ │
  50. └────┴────┴────┴────┴───┘
  51. ";
  52. DriverAssert.AssertDriverContentsAre (looksLike, output);
  53. for (var x = 0; x <= 5; x++)
  54. {
  55. // All these values would result in tile 0 getting smaller
  56. // so are not allowed (tile[0] has a min size of Int.Max)
  57. Assert.False (tv.SetSplitterPos (0, x), $"Assert failed for x={x}");
  58. }
  59. for (var x = 6; x < 10; x++)
  60. {
  61. // All these values would result in tile 0 getting bigger
  62. // so are allowed
  63. Assert.True (tv.SetSplitterPos (0, x), $"Assert failed for x={x}");
  64. }
  65. for (var x = 10; x < 100; x++)
  66. {
  67. // These values would result in the first splitter moving past
  68. // the second splitter so are not allowed
  69. Assert.False (tv.SetSplitterPos (0, x), $"Assert failed for x={x}");
  70. }
  71. AutoInitShutdownAttribute.RunIteration ();
  72. looksLike =
  73. @"
  74. ┌────────┬┬────┬────┬───┐
  75. │11111111││3333│4444│555│
  76. │ ││ │ │ │
  77. └────────┴┴────┴────┴───┘
  78. ";
  79. DriverAssert.AssertDriverContentsAre (looksLike, output);
  80. }
  81. [Fact]
  82. [AutoInitShutdown]
  83. public void Test5Panel_MinSizes_VerticalSplitters_ResizeSplitter1_NoBorder ()
  84. {
  85. TileView tv = Get5x1TilesView (false);
  86. tv.Tiles.ElementAt (0).MinSize = int.MaxValue;
  87. AutoInitShutdownAttribute.RunIteration ();
  88. var looksLike =
  89. @"
  90. 11111│2222│3333│4444│5555
  91. │ │ │ │
  92. │ │ │ │
  93. │ │ │ │
  94. ";
  95. DriverAssert.AssertDriverContentsAre (looksLike, output);
  96. for (var x = 0; x <= 5; x++)
  97. {
  98. // All these values would result in tile 0 getting smaller
  99. // so are not allowed (tile[0] has a min size of Int.Max)
  100. Assert.False (tv.SetSplitterPos (0, x), $"Assert failed for x={x}");
  101. }
  102. for (var x = 6; x < 10; x++)
  103. {
  104. // All these values would result in tile 0 getting bigger
  105. // so are allowed
  106. Assert.True (tv.SetSplitterPos (0, x), $"Assert failed for x={x}");
  107. }
  108. for (var x = 10; x < 100; x++)
  109. {
  110. // These values would result in the first splitter moving past
  111. // the second splitter so are not allowed
  112. Assert.False (tv.SetSplitterPos (0, x), $"Assert failed for x={x}");
  113. }
  114. AutoInitShutdownAttribute.RunIteration ();
  115. looksLike =
  116. @"
  117. 111111111││3333│4444│5555
  118. ││ │ │
  119. ││ │ │
  120. ││ │ │
  121. ";
  122. DriverAssert.AssertDriverContentsAre (looksLike, output);
  123. }
  124. [Fact]
  125. [AutoInitShutdown]
  126. public void Test5Panel_MinSizes_VerticalSplitters_ResizeSplitter2 ()
  127. {
  128. TileView tv = Get5x1TilesView ();
  129. tv.Tiles.ElementAt (1).MinSize = 2;
  130. tv.Tiles.ElementAt (2).MinSize = 3;
  131. AutoInitShutdownAttribute.RunIteration ();
  132. var looksLike =
  133. @"
  134. ┌────┬────┬────┬────┬───┐
  135. │1111│2222│3333│4444│555│
  136. │ │ │ │ │ │
  137. └────┴────┴────┴────┴───┘
  138. ";
  139. DriverAssert.AssertDriverContentsAre (looksLike, output);
  140. for (var x = 10; x > 7; x--)
  141. {
  142. Assert.True (tv.SetSplitterPos (1, x), $"Assert failed for x={x}");
  143. }
  144. for (var x = 7; x > 0; x--)
  145. {
  146. Assert.False (tv.SetSplitterPos (1, x), $"Assert failed for x={x}");
  147. }
  148. AutoInitShutdownAttribute.RunIteration ();
  149. looksLike =
  150. @"
  151. ┌────┬──┬──────┬────┬───┐
  152. │1111│22│333333│4444│555│
  153. │ │ │ │ │ │
  154. └────┴──┴──────┴────┴───┘
  155. ";
  156. DriverAssert.AssertDriverContentsAre (looksLike, output);
  157. for (var x = 10; x < 12; x++)
  158. {
  159. Assert.True (tv.SetSplitterPos (1, x), $"Assert failed for x={x}");
  160. }
  161. for (var x = 12; x < 25; x++)
  162. {
  163. Assert.False (tv.SetSplitterPos (1, x), $"Assert failed for x={x}");
  164. }
  165. Application.Top!.Layout ();
  166. tv.Draw ();
  167. looksLike =
  168. @"
  169. ┌────┬─────┬───┬────┬───┐
  170. │1111│22222│333│4444│555│
  171. │ │ │ │ │ │
  172. └────┴─────┴───┴────┴───┘
  173. ";
  174. DriverAssert.AssertDriverContentsAre (looksLike, output);
  175. }
  176. [Fact]
  177. [AutoInitShutdown]
  178. public void Test5Panel_MinSizes_VerticalSplitters_ResizeSplitter2_NoBorder ()
  179. {
  180. TileView tv = Get5x1TilesView (false);
  181. tv.Tiles.ElementAt (1).MinSize = 2;
  182. tv.Tiles.ElementAt (2).MinSize = 3;
  183. AutoInitShutdownAttribute.RunIteration ();
  184. var looksLike =
  185. @"
  186. 11111│2222│3333│4444│5555
  187. │ │ │ │
  188. │ │ │ │
  189. │ │ │ │
  190. ";
  191. DriverAssert.AssertDriverContentsAre (looksLike, output);
  192. for (var x = 10; x > 7; x--)
  193. {
  194. Assert.True (tv.SetSplitterPos (1, x), $"Assert failed for x={x}");
  195. }
  196. for (var x = 7; x > 0; x--)
  197. {
  198. Assert.False (tv.SetSplitterPos (1, x), $"Assert failed for x={x}");
  199. }
  200. AutoInitShutdownAttribute.RunIteration ();
  201. looksLike =
  202. @"
  203. 11111│22│333333│4444│5555
  204. │ │ │ │
  205. │ │ │ │
  206. │ │ │ │
  207. ";
  208. DriverAssert.AssertDriverContentsAre (looksLike, output);
  209. for (var x = 10; x < 12; x++)
  210. {
  211. Assert.True (tv.SetSplitterPos (1, x), $"Assert failed for x={x}");
  212. }
  213. for (var x = 12; x < 25; x++)
  214. {
  215. Assert.False (tv.SetSplitterPos (1, x), $"Assert failed for x={x}");
  216. }
  217. AutoInitShutdownAttribute.RunIteration ();
  218. looksLike =
  219. @"
  220. 11111│22222│333│4444│5555
  221. │ │ │ │
  222. │ │ │ │
  223. │ │ │ │
  224. ";
  225. DriverAssert.AssertDriverContentsAre (looksLike, output);
  226. }
  227. [Fact]
  228. [AutoInitShutdown]
  229. public void Test5Panel_MinSizes_VerticalSplitters_ResizeSplitter4 ()
  230. {
  231. TileView tv = Get5x1TilesView ();
  232. tv.Tiles.ElementAt (3).MinSize = 2;
  233. tv.Tiles.ElementAt (4).MinSize = 1;
  234. AutoInitShutdownAttribute.RunIteration ();
  235. var looksLike =
  236. @"
  237. ┌────┬────┬────┬────┬───┐
  238. │1111│2222│3333│4444│555│
  239. │ │ │ │ │ │
  240. └────┴────┴────┴────┴───┘
  241. ";
  242. DriverAssert.AssertDriverContentsAre (looksLike, output);
  243. for (var x = 20; x > 17; x--)
  244. {
  245. Assert.True (tv.SetSplitterPos (3, x), $"Assert failed for x={x}");
  246. }
  247. for (var x = 17; x > 0; x--)
  248. {
  249. Assert.False (tv.SetSplitterPos (3, x), $"Assert failed for x={x}");
  250. }
  251. AutoInitShutdownAttribute.RunIteration ();
  252. looksLike =
  253. @"
  254. ┌────┬────┬────┬──┬─────┐
  255. │1111│2222│3333│44│55555│
  256. │ │ │ │ │ │
  257. └────┴────┴────┴──┴─────┘
  258. ";
  259. DriverAssert.AssertDriverContentsAre (looksLike, output);
  260. for (var x = 20; x < 23; x++)
  261. {
  262. Assert.True (tv.SetSplitterPos (3, x), $"Assert failed for x={x}");
  263. }
  264. for (var x = 23; x < 100; x++)
  265. {
  266. Assert.False (tv.SetSplitterPos (3, x), $"Assert failed for x={x}");
  267. }
  268. AutoInitShutdownAttribute.RunIteration ();
  269. looksLike =
  270. @"
  271. ┌────┬────┬────┬──────┬─┐
  272. │1111│2222│3333│444444│5│
  273. │ │ │ │ │ │
  274. └────┴────┴────┴──────┴─┘
  275. ";
  276. DriverAssert.AssertDriverContentsAre (looksLike, output);
  277. }
  278. [Fact]
  279. [AutoInitShutdown]
  280. public void Test5Panel_MinSizes_VerticalSplitters_ResizeSplitter4_NoBorder ()
  281. {
  282. TileView tv = Get5x1TilesView (false);
  283. tv.Tiles.ElementAt (3).MinSize = 2;
  284. tv.Tiles.ElementAt (4).MinSize = 1;
  285. AutoInitShutdownAttribute.RunIteration ();
  286. var looksLike =
  287. @"
  288. 11111│2222│3333│4444│5555
  289. │ │ │ │
  290. │ │ │ │
  291. │ │ │ │
  292. ";
  293. DriverAssert.AssertDriverContentsAre (looksLike, output);
  294. for (var x = 20; x > 17; x--)
  295. {
  296. Assert.True (tv.SetSplitterPos (3, x), $"Assert failed for x={x}");
  297. }
  298. for (var x = 17; x > 0; x--)
  299. {
  300. Assert.False (tv.SetSplitterPos (3, x), $"Assert failed for x={x}");
  301. }
  302. AutoInitShutdownAttribute.RunIteration ();
  303. looksLike =
  304. @"
  305. 11111│2222│3333│44│555555
  306. │ │ │ │
  307. │ │ │ │
  308. │ │ │ │
  309. ";
  310. DriverAssert.AssertDriverContentsAre (looksLike, output);
  311. for (var x = 20; x < 24; x++)
  312. {
  313. Assert.True (tv.SetSplitterPos (3, x), $"Assert failed for x={x}");
  314. }
  315. for (var x = 24; x < 100; x++)
  316. {
  317. Assert.False (tv.SetSplitterPos (3, x), $"Assert failed for x={x}");
  318. }
  319. AutoInitShutdownAttribute.RunIteration ();
  320. looksLike =
  321. @"
  322. 11111│2222│3333│4444444│5
  323. │ │ │ │
  324. │ │ │ │
  325. │ │ │ │
  326. ";
  327. DriverAssert.AssertDriverContentsAre (looksLike, output);
  328. }
  329. [Fact]
  330. [AutoInitShutdown]
  331. public void Test5Panel_NoMinSizes_VerticalSplitters_ResizeSplitter1_CannotCrossBorder ()
  332. {
  333. TileView tv = Get5x1TilesView ();
  334. AutoInitShutdownAttribute.RunIteration ();
  335. var looksLike =
  336. @"
  337. ┌────┬────┬────┬────┬───┐
  338. │1111│2222│3333│4444│555│
  339. │ │ │ │ │ │
  340. └────┴────┴────┴────┴───┘
  341. ";
  342. DriverAssert.AssertDriverContentsAre (looksLike, output);
  343. for (var x = 5; x > 0; x--)
  344. {
  345. Assert.True (tv.SetSplitterPos (0, x), $"Assert failed for x={x}");
  346. }
  347. Assert.False (tv.SetSplitterPos (0, 0));
  348. AutoInitShutdownAttribute.RunIteration ();
  349. looksLike =
  350. @"
  351. ┌┬────────┬────┬────┬───┐
  352. ││22222222│3333│4444│555│
  353. ││ │ │ │ │
  354. └┴────────┴────┴────┴───┘
  355. ";
  356. DriverAssert.AssertDriverContentsAre (looksLike, output);
  357. for (var x = 6; x < 10; x++)
  358. {
  359. Assert.True (tv.SetSplitterPos (0, x), $"Assert failed for x={x}");
  360. }
  361. for (var x = 10; x < 100; x++)
  362. {
  363. // These values would result in the first splitter moving past
  364. // the second splitter so are not allowed
  365. Assert.False (tv.SetSplitterPos (0, x), $"Assert failed for x={x}");
  366. }
  367. AutoInitShutdownAttribute.RunIteration ();
  368. looksLike =
  369. @"
  370. ┌────────┬┬────┬────┬───┐
  371. │11111111││3333│4444│555│
  372. │ ││ │ │ │
  373. └────────┴┴────┴────┴───┘
  374. ";
  375. DriverAssert.AssertDriverContentsAre (looksLike, output);
  376. }
  377. [Fact]
  378. [AutoInitShutdown]
  379. public void Test5Panel_NoMinSizes_VerticalSplitters_ResizeSplitter1_CannotCrossBorder_NoBorder ()
  380. {
  381. TileView tv = Get5x1TilesView (false);
  382. AutoInitShutdownAttribute.RunIteration ();
  383. var looksLike =
  384. @"
  385. 11111│2222│3333│4444│5555
  386. │ │ │ │
  387. │ │ │ │
  388. │ │ │ │
  389. ";
  390. DriverAssert.AssertDriverContentsAre (looksLike, output);
  391. for (var x = 5; x >= 0; x--)
  392. {
  393. Assert.True (tv.SetSplitterPos (0, x), $"Assert failed for x={x}");
  394. }
  395. AutoInitShutdownAttribute.RunIteration ();
  396. looksLike =
  397. @"
  398. │222222222│3333│4444│5555
  399. │ │ │ │
  400. │ │ │ │
  401. │ │ │ │
  402. ";
  403. DriverAssert.AssertDriverContentsAre (looksLike, output);
  404. for (var x = 6; x < 10; x++)
  405. {
  406. Assert.True (tv.SetSplitterPos (0, x), $"Assert failed for x={x}");
  407. }
  408. for (var x = 10; x < 100; x++)
  409. {
  410. // These values would result in the first splitter moving past
  411. // the second splitter so are not allowed
  412. Assert.False (tv.SetSplitterPos (0, x), $"Assert failed for x={x}");
  413. }
  414. AutoInitShutdownAttribute.RunIteration ();
  415. looksLike =
  416. @"
  417. 111111111││3333│4444│5555
  418. ││ │ │
  419. ││ │ │
  420. ││ │ │
  421. ";
  422. DriverAssert.AssertDriverContentsAre (looksLike, output);
  423. }
  424. [Fact]
  425. [AutoInitShutdown]
  426. public void Test5Panel_NoMinSizes_VerticalSplitters_ResizeSplitter2_CannotMoveOverNeighbours ()
  427. {
  428. TileView tv = Get5x1TilesView ();
  429. AutoInitShutdownAttribute.RunIteration ();
  430. var looksLike =
  431. @"
  432. ┌────┬────┬────┬────┬───┐
  433. │1111│2222│3333│4444│555│
  434. │ │ │ │ │ │
  435. └────┴────┴────┴────┴───┘
  436. ";
  437. DriverAssert.AssertDriverContentsAre (looksLike, output);
  438. for (var x = 10; x > 5; x--)
  439. {
  440. Assert.True (tv.SetSplitterPos (1, x), $"Assert failed for x={x}");
  441. }
  442. for (var x = 5; x > 0; x--)
  443. {
  444. Assert.False (tv.SetSplitterPos (1, x), $"Assert failed for x={x}");
  445. }
  446. AutoInitShutdownAttribute.RunIteration ();
  447. looksLike =
  448. @"
  449. ┌────┬┬────────┬────┬───┐
  450. │1111││33333333│4444│555│
  451. │ ││ │ │ │
  452. └────┴┴────────┴────┴───┘
  453. ";
  454. DriverAssert.AssertDriverContentsAre (looksLike, output);
  455. for (var x = 10; x < 15; x++)
  456. {
  457. Assert.True (tv.SetSplitterPos (1, x), $"Assert failed for x={x}");
  458. }
  459. for (var x = 15; x < 25; x++)
  460. {
  461. Assert.False (tv.SetSplitterPos (1, x), $"Assert failed for x={x}");
  462. }
  463. AutoInitShutdownAttribute.RunIteration ();
  464. looksLike =
  465. @"
  466. ┌────┬────────┬┬────┬───┐
  467. │1111│22222222││4444│555│
  468. │ │ ││ │ │
  469. └────┴────────┴┴────┴───┘
  470. ";
  471. DriverAssert.AssertDriverContentsAre (looksLike, output);
  472. }
  473. [Fact]
  474. [AutoInitShutdown]
  475. public void Test5Panel_NoMinSizes_VerticalSplitters_ResizeSplitter2_CannotMoveOverNeighbours_NoBorder ()
  476. {
  477. TileView tv = Get5x1TilesView (false);
  478. AutoInitShutdownAttribute.RunIteration ();
  479. var looksLike =
  480. @"
  481. 11111│2222│3333│4444│5555
  482. │ │ │ │
  483. │ │ │ │
  484. │ │ │ │
  485. ";
  486. DriverAssert.AssertDriverContentsAre (looksLike, output);
  487. for (var x = 10; x > 5; x--)
  488. {
  489. Assert.True (tv.SetSplitterPos (1, x), $"Assert failed for x={x}");
  490. }
  491. for (var x = 5; x > 0; x--)
  492. {
  493. Assert.False (tv.SetSplitterPos (1, x), $"Assert failed for x={x}");
  494. }
  495. AutoInitShutdownAttribute.RunIteration ();
  496. looksLike =
  497. @"
  498. 11111││33333333│4444│5555
  499. ││ │ │
  500. ││ │ │
  501. ││ │ │
  502. ";
  503. DriverAssert.AssertDriverContentsAre (looksLike, output);
  504. for (var x = 10; x < 15; x++)
  505. {
  506. Assert.True (tv.SetSplitterPos (1, x), $"Assert failed for x={x}");
  507. }
  508. for (var x = 15; x < 25; x++)
  509. {
  510. Assert.False (tv.SetSplitterPos (1, x), $"Assert failed for x={x}");
  511. }
  512. AutoInitShutdownAttribute.RunIteration ();
  513. looksLike =
  514. @"
  515. 11111│22222222││4444│5555
  516. │ ││ │
  517. │ ││ │
  518. │ ││ │
  519. ";
  520. DriverAssert.AssertDriverContentsAre (looksLike, output);
  521. }
  522. [Fact]
  523. [AutoInitShutdown]
  524. public void Test5Panel_NoMinSizes_VerticalSplitters_ResizeSplitter4_CannotMoveOverNeighbours ()
  525. {
  526. TileView tv = Get5x1TilesView ();
  527. AutoInitShutdownAttribute.RunIteration ();
  528. var looksLike =
  529. @"
  530. ┌────┬────┬────┬────┬───┐
  531. │1111│2222│3333│4444│555│
  532. │ │ │ │ │ │
  533. └────┴────┴────┴────┴───┘
  534. ";
  535. DriverAssert.AssertDriverContentsAre (looksLike, output);
  536. for (var x = 20; x > 15; x--)
  537. {
  538. Assert.True (tv.SetSplitterPos (3, x), $"Assert failed for x={x}");
  539. }
  540. for (var x = 15; x > 0; x--)
  541. {
  542. Assert.False (tv.SetSplitterPos (3, x), $"Assert failed for x={x}");
  543. }
  544. AutoInitShutdownAttribute.RunIteration ();
  545. looksLike =
  546. @"
  547. ┌────┬────┬────┬┬───────┐
  548. │1111│2222│3333││5555555│
  549. │ │ │ ││ │
  550. └────┴────┴────┴┴───────┘
  551. ";
  552. DriverAssert.AssertDriverContentsAre (looksLike, output);
  553. for (var x = 20; x < 24; x++)
  554. {
  555. Assert.True (tv.SetSplitterPos (3, x), $"Assert failed for x={x}");
  556. }
  557. for (var x = 24; x < 100; x++)
  558. {
  559. Assert.False (tv.SetSplitterPos (3, x), $"Assert failed for x={x}");
  560. }
  561. AutoInitShutdownAttribute.RunIteration ();
  562. looksLike =
  563. @"
  564. ┌────┬────┬────┬───────┬┐
  565. │1111│2222│3333│4444444││
  566. │ │ │ │ ││
  567. └────┴────┴────┴───────┴┘
  568. ";
  569. DriverAssert.AssertDriverContentsAre (looksLike, output);
  570. }
  571. [Fact]
  572. [AutoInitShutdown]
  573. public void Test5Panel_NoMinSizes_VerticalSplitters_ResizeSplitter4_CannotMoveOverNeighbours_NoBorder ()
  574. {
  575. TileView tv = Get5x1TilesView (false);
  576. AutoInitShutdownAttribute.RunIteration ();
  577. var looksLike =
  578. @"
  579. 11111│2222│3333│4444│5555
  580. │ │ │ │
  581. │ │ │ │
  582. │ │ │ │
  583. ";
  584. DriverAssert.AssertDriverContentsAre (looksLike, output);
  585. for (var x = 20; x > 15; x--)
  586. {
  587. Assert.True (tv.SetSplitterPos (3, x), $"Assert failed for x={x}");
  588. }
  589. for (var x = 15; x > 0; x--)
  590. {
  591. Assert.False (tv.SetSplitterPos (3, x), $"Assert failed for x={x}");
  592. }
  593. AutoInitShutdownAttribute.RunIteration ();
  594. looksLike =
  595. @"
  596. 11111│2222│3333││55555555
  597. │ │ ││
  598. │ │ ││
  599. │ │ ││
  600. ";
  601. DriverAssert.AssertDriverContentsAre (looksLike, output);
  602. for (var x = 20; x < 25; x++)
  603. {
  604. Assert.True (tv.SetSplitterPos (3, x), $"Assert failed for x={x}");
  605. }
  606. for (var x = 25; x < 100; x++)
  607. {
  608. Assert.False (tv.SetSplitterPos (3, x), $"Assert failed for x={x}");
  609. }
  610. AutoInitShutdownAttribute.RunIteration ();
  611. looksLike =
  612. @"
  613. 11111│2222│3333│44444444│
  614. │ │ │ │
  615. │ │ │ │
  616. │ │ │ │
  617. ";
  618. DriverAssert.AssertDriverContentsAre (looksLike, output);
  619. }
  620. [Fact]
  621. public void TestDisposal_NoEarlyDisposalsOfUsersViews_DuringInsertTile ()
  622. {
  623. TileView tv = GetTileView (20, 10);
  624. var myReusableView = new DisposeCounter ();
  625. // I want my view in the first tile
  626. tv.Tiles.ElementAt (0).ContentView.Add (myReusableView);
  627. Assert.Equal (0, myReusableView.DisposalCount);
  628. // I've changed my mind, I want 3 tiles now
  629. tv.InsertTile (0);
  630. tv.InsertTile (2);
  631. // but I still want my view in the first tile
  632. // BUGBUG: Adding a view twice is not legit
  633. tv.Tiles.ElementAt (0).ContentView.Add (myReusableView);
  634. Assert.Multiple (
  635. () => Assert.Equal (0, myReusableView.DisposalCount),
  636. () =>
  637. {
  638. tv.Dispose ();
  639. Assert.True (myReusableView.DisposalCount >= 1);
  640. }
  641. );
  642. }
  643. [Fact]
  644. public void TestDisposal_NoEarlyDisposalsOfUsersViews_DuringRebuildForTileCount ()
  645. {
  646. TileView tv = GetTileView (20, 10);
  647. var myReusableView = new DisposeCounter ();
  648. // I want my view in the first tile
  649. tv.Tiles.ElementAt (0).ContentView.Add (myReusableView);
  650. Assert.Equal (0, myReusableView.DisposalCount);
  651. // I've changed my mind, I want 3 tiles now
  652. tv.RebuildForTileCount (3);
  653. // but I still want my view in the first tile
  654. // BUGBUG: Adding a view twice is not legit
  655. tv.Tiles.ElementAt (0).ContentView.Add (myReusableView);
  656. Assert.Multiple (
  657. () => Assert.Equal (0, myReusableView.DisposalCount),
  658. () =>
  659. {
  660. tv.Dispose ();
  661. Assert.Equal (1, myReusableView.DisposalCount);
  662. }
  663. );
  664. Assert.NotNull (Application.Top);
  665. Application.Top.Dispose ();
  666. Application.Shutdown ();
  667. }
  668. [Theory]
  669. [InlineData (0)]
  670. [InlineData (1)]
  671. public void TestDisposal_NoEarlyDisposalsOfUsersViews_DuringRemoveTile (int idx)
  672. {
  673. TileView tv = GetTileView (20, 10);
  674. var myReusableView = new DisposeCounter ();
  675. // I want my view in the first tile
  676. tv.Tiles.ElementAt (0).ContentView.Add (myReusableView);
  677. Assert.Equal (0, myReusableView.DisposalCount);
  678. tv.RemoveTile (idx);
  679. // but I still want my view in the first tile
  680. // BUGBUG: Adding a view twice is not legit
  681. tv.Tiles.ElementAt (0).ContentView.Add (myReusableView);
  682. Assert.Multiple (
  683. () => Assert.Equal (0, myReusableView.DisposalCount),
  684. () =>
  685. {
  686. tv.Dispose ();
  687. Assert.True (myReusableView.DisposalCount >= 1);
  688. }
  689. );
  690. Assert.NotNull (Application.Top);
  691. Application.Top.Dispose ();
  692. Application.Shutdown ();
  693. }
  694. [Fact]
  695. [AutoInitShutdown]
  696. public void TestNestedContainer2LeftAnd1Right_RendersNicely ()
  697. {
  698. TileView tileView = GetNestedContainer2Left1Right (false);
  699. Assert.Equal (20, tileView.Frame.Width);
  700. Assert.Equal (10, tileView.Tiles.ElementAt (0).ContentView.Frame.Width);
  701. Assert.Equal (9, tileView.Tiles.ElementAt (1).ContentView.Frame.Width);
  702. Assert.IsType<TileView> (tileView.Tiles.ElementAt (0).ContentView);
  703. var left = (TileView)tileView.Tiles.ElementAt (0).ContentView;
  704. Assert.Same (left.SuperView, tileView);
  705. Assert.Equal (2, left.Tiles.ElementAt (0).ContentView.SubViews.Count);
  706. Assert.IsType<Label> (left.Tiles.ElementAt (0).ContentView.SubViews.ElementAt (0));
  707. Assert.IsType<Label> (left.Tiles.ElementAt (0).ContentView.SubViews.ElementAt (1));
  708. var onesTop = (Label)left.Tiles.ElementAt (0).ContentView.SubViews.ElementAt (0);
  709. var onesBottom = (Label)left.Tiles.ElementAt (0).ContentView.SubViews.ElementAt (1);
  710. Assert.Same (left.Tiles.ElementAt (0).ContentView, onesTop.SuperView);
  711. Assert.Same (left.Tiles.ElementAt (0).ContentView, onesBottom.SuperView);
  712. Assert.Equal (10, onesTop.Frame.Width);
  713. Assert.Equal (10, onesBottom.Frame.Width);
  714. tileView.Draw ();
  715. var looksLike =
  716. @"
  717. 1111111111│222222222
  718. 1111111111│222222222
  719. ──────────┤
  720. │";
  721. DriverAssert.AssertDriverContentsAre (looksLike, output);
  722. }
  723. [Fact]
  724. [AutoInitShutdown]
  725. public void TestNestedContainer3RightAnd1Down_RendersNicely ()
  726. {
  727. TileView tileView = GetNestedContainer3Right1Down (false);
  728. tileView.Draw ();
  729. var looksLike =
  730. @"
  731. 111111│222222│333333
  732. 111111│222222│333333
  733. 111111│222222│333333
  734. 111111│222222│333333
  735. 111111│222222│333333
  736. 111111│222222├──────
  737. 111111│222222│444444
  738. 111111│222222│444444
  739. 111111│222222│444444
  740. 111111│222222│444444
  741. ";
  742. DriverAssert.AssertDriverContentsAre (looksLike, output);
  743. // It looks good but lets double check the measurements incase
  744. // anything is sticking out but drawn over
  745. // 3 panels + 2 splitters
  746. Assert.Equal (5, tileView.SubViews.Count);
  747. // Check X and Widths of Tiles
  748. Assert.Equal (0, tileView.Tiles.ElementAt (0).ContentView.Frame.X);
  749. Assert.Equal (6, tileView.Tiles.ElementAt (0).ContentView.Frame.Width);
  750. Assert.Equal (7, tileView.Tiles.ElementAt (1).ContentView.Frame.X);
  751. Assert.Equal (6, tileView.Tiles.ElementAt (1).ContentView.Frame.Width);
  752. Assert.Equal (14, tileView.Tiles.ElementAt (2).ContentView.Frame.X);
  753. Assert.Equal (6, tileView.Tiles.ElementAt (2).ContentView.Frame.Width);
  754. // Check Y and Heights of Tiles
  755. Assert.Equal (0, tileView.Tiles.ElementAt (0).ContentView.Frame.Y);
  756. Assert.Equal (10, tileView.Tiles.ElementAt (0).ContentView.Frame.Height);
  757. Assert.Equal (0, tileView.Tiles.ElementAt (1).ContentView.Frame.Y);
  758. Assert.Equal (10, tileView.Tiles.ElementAt (1).ContentView.Frame.Height);
  759. Assert.Equal (0, tileView.Tiles.ElementAt (2).ContentView.Frame.Y);
  760. Assert.Equal (10, tileView.Tiles.ElementAt (2).ContentView.Frame.Height);
  761. // Check Sub containers in last panel
  762. var subSplit = (TileView)tileView.Tiles.ElementAt (2).ContentView;
  763. Assert.Equal (0, subSplit.Tiles.ElementAt (0).ContentView.Frame.X);
  764. Assert.Equal (6, subSplit.Tiles.ElementAt (0).ContentView.Frame.Width);
  765. Assert.Equal (0, subSplit.Tiles.ElementAt (0).ContentView.Frame.Y);
  766. Assert.Equal (5, subSplit.Tiles.ElementAt (0).ContentView.Frame.Height);
  767. //Assert.IsType<TextView> (subSplit.Tiles.ElementAt (0).ContentView.SubViews.Single ());
  768. Assert.Equal (0, subSplit.Tiles.ElementAt (1).ContentView.Frame.X);
  769. Assert.Equal (6, subSplit.Tiles.ElementAt (1).ContentView.Frame.Width);
  770. Assert.Equal (6, subSplit.Tiles.ElementAt (1).ContentView.Frame.Y);
  771. Assert.Equal (4, subSplit.Tiles.ElementAt (1).ContentView.Frame.Height);
  772. //Assert.IsType<TextView> (subSplit.Tiles.ElementAt (1).ContentView.SubViews.Single ());
  773. }
  774. [Fact]
  775. [AutoInitShutdown]
  776. public void TestNestedContainer3RightAnd1Down_TileVisibility_WithBorder ()
  777. {
  778. TileView tileView = GetNestedContainer3Right1Down (true);
  779. AutoInitShutdownAttribute.RunIteration ();
  780. var looksLike =
  781. @"
  782. ┌─────┬──────┬─────┐
  783. │11111│222222│33333│
  784. │11111│222222│33333│
  785. │11111│222222│33333│
  786. │11111│222222│33333│
  787. │11111│222222├─────┤
  788. │11111│222222│44444│
  789. │11111│222222│44444│
  790. │11111│222222│44444│
  791. └─────┴──────┴─────┘";
  792. DriverAssert.AssertDriverContentsAre (looksLike, output);
  793. tileView.Tiles.ElementAt (0).ContentView.Visible = false;
  794. tileView.Tiles.ElementAt (1).ContentView.Visible = true;
  795. tileView.Tiles.ElementAt (2).ContentView.Visible = true;
  796. AutoInitShutdownAttribute.RunIteration ();
  797. looksLike =
  798. @"
  799. ┌────────────┬─────┐
  800. │222222222222│33333│
  801. │222222222222│33333│
  802. │222222222222│33333│
  803. │222222222222│33333│
  804. │222222222222├─────┤
  805. │222222222222│44444│
  806. │222222222222│44444│
  807. │222222222222│44444│
  808. └────────────┴─────┘";
  809. DriverAssert.AssertDriverContentsAre (looksLike, output);
  810. tileView.Tiles.ElementAt (0).ContentView.Visible = true;
  811. tileView.Tiles.ElementAt (1).ContentView.Visible = false;
  812. AutoInitShutdownAttribute.RunIteration ();
  813. looksLike =
  814. @"
  815. ┌────────────┬─────┐
  816. │111111111111│33333│
  817. │111111111111│33333│
  818. │111111111111│33333│
  819. │111111111111│33333│
  820. │111111111111├─────┤
  821. │111111111111│44444│
  822. │111111111111│44444│
  823. │111111111111│44444│
  824. └────────────┴─────┘";
  825. DriverAssert.AssertDriverContentsAre (looksLike, output);
  826. tileView.Tiles.ElementAt (0).ContentView.Visible = true;
  827. tileView.Tiles.ElementAt (1).ContentView.Visible = true;
  828. tileView.Tiles.ElementAt (2).ContentView.Visible = false;
  829. AutoInitShutdownAttribute.RunIteration ();
  830. looksLike =
  831. @"
  832. ┌─────┬────────────┐
  833. │11111│222222222222│
  834. │11111│222222222222│
  835. │11111│222222222222│
  836. │11111│222222222222│
  837. │11111│222222222222│
  838. │11111│222222222222│
  839. │11111│222222222222│
  840. │11111│222222222222│
  841. └─────┴────────────┘";
  842. DriverAssert.AssertDriverContentsAre (looksLike, output);
  843. tileView.Tiles.ElementAt (0).ContentView.Visible = true;
  844. tileView.Tiles.ElementAt (1).ContentView.Visible = false;
  845. tileView.Tiles.ElementAt (2).ContentView.Visible = false;
  846. AutoInitShutdownAttribute.RunIteration ();
  847. looksLike =
  848. @"
  849. ┌──────────────────┐
  850. │111111111111111111│
  851. │111111111111111111│
  852. │111111111111111111│
  853. │111111111111111111│
  854. │111111111111111111│
  855. │111111111111111111│
  856. │111111111111111111│
  857. │111111111111111111│
  858. └──────────────────┘";
  859. DriverAssert.AssertDriverContentsAre (looksLike, output);
  860. tileView.Tiles.ElementAt (0).ContentView.Visible = false;
  861. tileView.Tiles.ElementAt (1).ContentView.Visible = true;
  862. tileView.Tiles.ElementAt (2).ContentView.Visible = false;
  863. AutoInitShutdownAttribute.RunIteration ();
  864. looksLike =
  865. @"
  866. ┌──────────────────┐
  867. │222222222222222222│
  868. │222222222222222222│
  869. │222222222222222222│
  870. │222222222222222222│
  871. │222222222222222222│
  872. │222222222222222222│
  873. │222222222222222222│
  874. │222222222222222222│
  875. └──────────────────┘";
  876. DriverAssert.AssertDriverContentsAre (looksLike, output);
  877. tileView.Tiles.ElementAt (0).ContentView.Visible = false;
  878. tileView.Tiles.ElementAt (1).ContentView.Visible = false;
  879. tileView.Tiles.ElementAt (2).ContentView.Visible = true;
  880. AutoInitShutdownAttribute.RunIteration ();
  881. looksLike =
  882. @"
  883. ┌──────────────────┐
  884. │333333333333333333│
  885. │333333333333333333│
  886. │333333333333333333│
  887. │333333333333333333│
  888. ├──────────────────┤
  889. │444444444444444444│
  890. │444444444444444444│
  891. │444444444444444444│
  892. └──────────────────┘";
  893. DriverAssert.AssertDriverContentsAre (looksLike, output);
  894. DriverAssert.AssertDriverContentsAre (looksLike, output);
  895. tileView.Tiles.ElementAt (0).ContentView.Visible = false;
  896. tileView.Tiles.ElementAt (1).ContentView.Visible = false;
  897. tileView.Tiles.ElementAt (2).ContentView.Visible = false;
  898. AutoInitShutdownAttribute.RunIteration ();
  899. looksLike =
  900. @"
  901. ┌──────────────────┐
  902. │ │
  903. │ │
  904. │ │
  905. │ │
  906. │ │
  907. │ │
  908. │ │
  909. │ │
  910. └──────────────────┘";
  911. DriverAssert.AssertDriverContentsAre (looksLike, output);
  912. }
  913. [Fact]
  914. [AutoInitShutdown]
  915. public void TestNestedContainer3RightAnd1Down_TileVisibility_WithoutBorder ()
  916. {
  917. TileView tileView = GetNestedContainer3Right1Down (false);
  918. AutoInitShutdownAttribute.RunIteration ();
  919. var looksLike =
  920. @"
  921. 111111│222222│333333
  922. 111111│222222│333333
  923. 111111│222222│333333
  924. 111111│222222│333333
  925. 111111│222222│333333
  926. 111111│222222├──────
  927. 111111│222222│444444
  928. 111111│222222│444444
  929. 111111│222222│444444
  930. 111111│222222│444444";
  931. DriverAssert.AssertDriverContentsAre (looksLike, output);
  932. tileView.Tiles.ElementAt (0).ContentView.Visible = false;
  933. tileView.Tiles.ElementAt (1).ContentView.Visible = true;
  934. tileView.Tiles.ElementAt (2).ContentView.Visible = true;
  935. AutoInitShutdownAttribute.RunIteration ();
  936. looksLike =
  937. @"
  938. 2222222222222│333333
  939. 2222222222222│333333
  940. 2222222222222│333333
  941. 2222222222222│333333
  942. 2222222222222│333333
  943. 2222222222222├──────
  944. 2222222222222│444444
  945. 2222222222222│444444
  946. 2222222222222│444444
  947. 2222222222222│444444";
  948. DriverAssert.AssertDriverContentsAre (looksLike, output);
  949. tileView.Tiles.ElementAt (0).ContentView.Visible = true;
  950. tileView.Tiles.ElementAt (1).ContentView.Visible = false;
  951. tileView.Tiles.ElementAt (2).ContentView.Visible = true;
  952. AutoInitShutdownAttribute.RunIteration ();
  953. looksLike =
  954. @"
  955. 1111111111111│333333
  956. 1111111111111│333333
  957. 1111111111111│333333
  958. 1111111111111│333333
  959. 1111111111111│333333
  960. 1111111111111├──────
  961. 1111111111111│444444
  962. 1111111111111│444444
  963. 1111111111111│444444
  964. 1111111111111│444444";
  965. DriverAssert.AssertDriverContentsAre (looksLike, output);
  966. tileView.Tiles.ElementAt (0).ContentView.Visible = true;
  967. tileView.Tiles.ElementAt (1).ContentView.Visible = true;
  968. tileView.Tiles.ElementAt (2).ContentView.Visible = false;
  969. AutoInitShutdownAttribute.RunIteration ();
  970. looksLike =
  971. @"
  972. 111111│2222222222222
  973. 111111│2222222222222
  974. 111111│2222222222222
  975. 111111│2222222222222
  976. 111111│2222222222222
  977. 111111│2222222222222
  978. 111111│2222222222222
  979. 111111│2222222222222
  980. 111111│2222222222222
  981. 111111│2222222222222";
  982. DriverAssert.AssertDriverContentsAre (looksLike, output);
  983. tileView.Tiles.ElementAt (0).ContentView.Visible = true;
  984. tileView.Tiles.ElementAt (1).ContentView.Visible = false;
  985. tileView.Tiles.ElementAt (2).ContentView.Visible = false;
  986. AutoInitShutdownAttribute.RunIteration ();
  987. looksLike =
  988. @"
  989. 11111111111111111111
  990. 11111111111111111111
  991. 11111111111111111111
  992. 11111111111111111111
  993. 11111111111111111111
  994. 11111111111111111111
  995. 11111111111111111111
  996. 11111111111111111111
  997. 11111111111111111111
  998. 11111111111111111111";
  999. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1000. tileView.Tiles.ElementAt (0).ContentView.Visible = false;
  1001. tileView.Tiles.ElementAt (1).ContentView.Visible = true;
  1002. tileView.Tiles.ElementAt (2).ContentView.Visible = false;
  1003. AutoInitShutdownAttribute.RunIteration ();
  1004. looksLike =
  1005. @"
  1006. 22222222222222222222
  1007. 22222222222222222222
  1008. 22222222222222222222
  1009. 22222222222222222222
  1010. 22222222222222222222
  1011. 22222222222222222222
  1012. 22222222222222222222
  1013. 22222222222222222222
  1014. 22222222222222222222
  1015. 22222222222222222222";
  1016. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1017. tileView.Tiles.ElementAt (0).ContentView.Visible = false;
  1018. tileView.Tiles.ElementAt (1).ContentView.Visible = false;
  1019. tileView.Tiles.ElementAt (2).ContentView.Visible = true;
  1020. AutoInitShutdownAttribute.RunIteration ();
  1021. looksLike =
  1022. @"
  1023. 33333333333333333333
  1024. 33333333333333333333
  1025. 33333333333333333333
  1026. 33333333333333333333
  1027. 33333333333333333333
  1028. ────────────────────
  1029. 44444444444444444444
  1030. 44444444444444444444
  1031. 44444444444444444444
  1032. 44444444444444444444";
  1033. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1034. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1035. tileView.Tiles.ElementAt (0).ContentView.Visible = false;
  1036. tileView.Tiles.ElementAt (1).ContentView.Visible = false;
  1037. tileView.Tiles.ElementAt (2).ContentView.Visible = false;
  1038. AutoInitShutdownAttribute.RunIteration ();
  1039. looksLike =
  1040. @"
  1041. ";
  1042. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1043. }
  1044. [Fact]
  1045. [AutoInitShutdown]
  1046. public void TestNestedContainer3RightAnd1Down_TitleDoesNotOverspill ()
  1047. {
  1048. TileView tileView = GetNestedContainer3Right1Down (true, true, 1);
  1049. AutoInitShutdownAttribute.RunIteration ();
  1050. var looksLike =
  1051. @"
  1052. ┌ T1 ─┬ T3 ──┬ T2 ─┐
  1053. │11111│333333│22222│
  1054. │11111│333333│22222│
  1055. │11111│333333│22222│
  1056. │11111│333333│22222│
  1057. │11111├ T4 ──┤22222│
  1058. │11111│444444│22222│
  1059. │11111│444444│22222│
  1060. │11111│444444│22222│
  1061. └─────┴──────┴─────┘";
  1062. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1063. }
  1064. [Fact]
  1065. [AutoInitShutdown]
  1066. public void TestNestedContainer3RightAnd1Down_TitleTriesToOverspill ()
  1067. {
  1068. TileView tileView = GetNestedContainer3Right1Down (true, true, 1);
  1069. tileView.Tiles.ElementAt (0).Title = new ('x', 100);
  1070. ((TileView)tileView.Tiles.ElementAt (1).ContentView)
  1071. .Tiles.ElementAt (1)
  1072. .Title = new ('y', 100);
  1073. AutoInitShutdownAttribute.RunIteration ();
  1074. var looksLike =
  1075. @"
  1076. ┌ xxxx┬ T3 ──┬ T2 ─┐
  1077. │11111│333333│22222│
  1078. │11111│333333│22222│
  1079. │11111│333333│22222│
  1080. │11111│333333│22222│
  1081. │11111├ yyyyy┤22222│
  1082. │11111│444444│22222│
  1083. │11111│444444│22222│
  1084. │11111│444444│22222│
  1085. └─────┴──────┴─────┘";
  1086. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1087. }
  1088. [Fact]
  1089. [AutoInitShutdown]
  1090. public void TestNestedContainer3RightAnd1Down_WithBorder_RemovingTiles ()
  1091. {
  1092. TileView tileView = GetNestedContainer3Right1Down (true);
  1093. AutoInitShutdownAttribute.RunIteration ();
  1094. var looksLike =
  1095. @"
  1096. ┌─────┬──────┬─────┐
  1097. │11111│222222│33333│
  1098. │11111│222222│33333│
  1099. │11111│222222│33333│
  1100. │11111│222222│33333│
  1101. │11111│222222├─────┤
  1102. │11111│222222│44444│
  1103. │11111│222222│44444│
  1104. │11111│222222│44444│
  1105. └─────┴──────┴─────┘";
  1106. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1107. Tile toRemove = tileView.Tiles.ElementAt (1);
  1108. Tile removed = tileView.RemoveTile (1);
  1109. Assert.Same (toRemove, removed);
  1110. Assert.DoesNotContain (removed, tileView.Tiles);
  1111. AutoInitShutdownAttribute.RunIteration ();
  1112. looksLike =
  1113. @"
  1114. ┌─────────┬────────┐
  1115. │111111111│33333333│
  1116. │111111111│33333333│
  1117. │111111111│33333333│
  1118. │111111111│33333333│
  1119. │111111111├────────┤
  1120. │111111111│44444444│
  1121. │111111111│44444444│
  1122. │111111111│44444444│
  1123. └─────────┴────────┘";
  1124. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1125. // cannot remove at this index because there is only one horizontal tile left
  1126. Assert.Null (tileView.RemoveTile (2));
  1127. tileView.RemoveTile (0);
  1128. AutoInitShutdownAttribute.RunIteration ();
  1129. looksLike =
  1130. @"
  1131. ┌──────────────────┐
  1132. │333333333333333333│
  1133. │333333333333333333│
  1134. │333333333333333333│
  1135. │333333333333333333│
  1136. ├──────────────────┤
  1137. │444444444444444444│
  1138. │444444444444444444│
  1139. │444444444444444444│
  1140. └──────────────────┘";
  1141. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1142. Assert.NotNull (tileView.RemoveTile (0));
  1143. AutoInitShutdownAttribute.RunIteration ();
  1144. looksLike =
  1145. @"
  1146. ┌──────────────────┐
  1147. │ │
  1148. │ │
  1149. │ │
  1150. │ │
  1151. │ │
  1152. │ │
  1153. │ │
  1154. │ │
  1155. └──────────────────┘";
  1156. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1157. // cannot remove
  1158. Assert.Null (tileView.RemoveTile (0));
  1159. }
  1160. [Fact]
  1161. [AutoInitShutdown]
  1162. public void TestNestedContainer3RightAnd1Down_WithBorder_RendersNicely ()
  1163. {
  1164. TileView tileView = GetNestedContainer3Right1Down (true);
  1165. AutoInitShutdownAttribute.RunIteration ();
  1166. var looksLike =
  1167. @"
  1168. ┌─────┬──────┬─────┐
  1169. │11111│222222│33333│
  1170. │11111│222222│33333│
  1171. │11111│222222│33333│
  1172. │11111│222222│33333│
  1173. │11111│222222├─────┤
  1174. │11111│222222│44444│
  1175. │11111│222222│44444│
  1176. │11111│222222│44444│
  1177. └─────┴──────┴─────┘";
  1178. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1179. // It looks good but lets double check the measurements incase
  1180. // anything is sticking out but drawn over
  1181. // 3 panels + 2 splitters
  1182. Assert.Equal (5, tileView.SubViews.Count);
  1183. // Check X and Widths of Tiles
  1184. Assert.Equal (1, tileView.Tiles.ElementAt (0).ContentView.Frame.X);
  1185. Assert.Equal (5, tileView.Tiles.ElementAt (0).ContentView.Frame.Width);
  1186. Assert.Equal (7, tileView.Tiles.ElementAt (1).ContentView.Frame.X);
  1187. Assert.Equal (6, tileView.Tiles.ElementAt (1).ContentView.Frame.Width);
  1188. Assert.Equal (14, tileView.Tiles.ElementAt (2).ContentView.Frame.X);
  1189. Assert.Equal (5, tileView.Tiles.ElementAt (2).ContentView.Frame.Width);
  1190. // Check Y and Heights of Tiles
  1191. Assert.Equal (1, tileView.Tiles.ElementAt (0).ContentView.Frame.Y);
  1192. Assert.Equal (8, tileView.Tiles.ElementAt (0).ContentView.Frame.Height);
  1193. Assert.Equal (1, tileView.Tiles.ElementAt (1).ContentView.Frame.Y);
  1194. Assert.Equal (8, tileView.Tiles.ElementAt (1).ContentView.Frame.Height);
  1195. Assert.Equal (1, tileView.Tiles.ElementAt (2).ContentView.Frame.Y);
  1196. Assert.Equal (8, tileView.Tiles.ElementAt (2).ContentView.Frame.Height);
  1197. // Check Sub containers in last panel
  1198. var subSplit = (TileView)tileView.Tiles.ElementAt (2).ContentView;
  1199. Assert.Equal (0, subSplit.Tiles.ElementAt (0).ContentView.Frame.X);
  1200. Assert.Equal (5, subSplit.Tiles.ElementAt (0).ContentView.Frame.Width);
  1201. Assert.Equal (0, subSplit.Tiles.ElementAt (0).ContentView.Frame.Y);
  1202. Assert.Equal (4, subSplit.Tiles.ElementAt (0).ContentView.Frame.Height);
  1203. //Assert.IsType<TextView> (subSplit.Tiles.ElementAt (0).ContentView.SubViews.Single ());
  1204. Assert.Equal (0, subSplit.Tiles.ElementAt (1).ContentView.Frame.X);
  1205. Assert.Equal (5, subSplit.Tiles.ElementAt (1).ContentView.Frame.Width);
  1206. Assert.Equal (5, subSplit.Tiles.ElementAt (1).ContentView.Frame.Y);
  1207. Assert.Equal (3, subSplit.Tiles.ElementAt (1).ContentView.Frame.Height);
  1208. //Assert.IsType<TextView> (subSplit.Tiles.ElementAt (1).ContentView.SubViews.Single ());
  1209. }
  1210. [Fact]
  1211. [AutoInitShutdown]
  1212. public void TestNestedContainer3RightAnd1Down_WithTitledBorder_RendersNicely ()
  1213. {
  1214. TileView tileView = GetNestedContainer3Right1Down (true, true);
  1215. tileView.Draw ();
  1216. var looksLike =
  1217. @"
  1218. ┌ T1 ─┬ T2 ──┬ T3 ─┐
  1219. │11111│222222│33333│
  1220. │11111│222222│33333│
  1221. │11111│222222│33333│
  1222. │11111│222222│33333│
  1223. │11111│222222├ T4 ─┤
  1224. │11111│222222│44444│
  1225. │11111│222222│44444│
  1226. │11111│222222│44444│
  1227. └─────┴──────┴─────┘";
  1228. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1229. }
  1230. [Fact]
  1231. [AutoInitShutdown]
  1232. public void TestNestedNonRoots_OnlyOneRoot_OnlyRootCanHaveBorders ()
  1233. {
  1234. var tv = new TileView
  1235. {
  1236. Width = 10, Height = 5, LineStyle = LineStyle.Single
  1237. };
  1238. tv.TrySplitTile (1, 2, out TileView tv2);
  1239. // tv2.Scheme = new ();
  1240. tv2.LineStyle = LineStyle.Single;
  1241. tv2.Orientation = Orientation.Horizontal;
  1242. Assert.True (tv.IsRootTileView ());
  1243. var top = new Toplevel ();
  1244. top.Add (tv);
  1245. tv.BeginInit ();
  1246. tv.EndInit ();
  1247. tv.LayoutSubViews ();
  1248. tv.LayoutSubViews ();
  1249. tv.Tiles.ElementAt (1).ContentView.LayoutSubViews ();
  1250. tv2.LayoutSubViews ();
  1251. // tv2 is not considered a root because
  1252. // it was created via TrySplitTile so it
  1253. // will have its lines joined to
  1254. // parent and cannot have its own border
  1255. Assert.False (tv2.IsRootTileView ());
  1256. tv.Draw ();
  1257. var looksLike =
  1258. @"
  1259. ┌────┬───┐
  1260. │ │ │
  1261. │ ├───┤
  1262. │ │ │
  1263. └────┴───┘
  1264. ";
  1265. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1266. }
  1267. [Fact]
  1268. [AutoInitShutdown]
  1269. public void TestNestedRoots_BothRoots_BothCanHaveBorders ()
  1270. {
  1271. var tv = new TileView
  1272. {
  1273. Width = 10, Height = 5, LineStyle = LineStyle.Single
  1274. };
  1275. var tv2 = new TileView
  1276. {
  1277. Width = Dim.Fill (),
  1278. Height = Dim.Fill (),
  1279. LineStyle = LineStyle.Single,
  1280. Orientation = Orientation.Horizontal
  1281. };
  1282. Assert.True (tv.IsRootTileView ());
  1283. tv.Tiles.ElementAt (1).ContentView.Add (tv2);
  1284. var top = new Toplevel ();
  1285. top.Add (tv);
  1286. tv.BeginInit ();
  1287. tv.EndInit ();
  1288. tv.LayoutSubViews ();
  1289. tv.LayoutSubViews ();
  1290. tv.Tiles.ElementAt (1).ContentView.LayoutSubViews ();
  1291. tv2.LayoutSubViews ();
  1292. // tv2 is still considered a root because
  1293. // it was manually created by API user. That
  1294. // means it will not have its lines joined to
  1295. // parents and it is permitted to have a border
  1296. Assert.True (tv2.IsRootTileView ());
  1297. tv.Draw ();
  1298. var looksLike =
  1299. @"
  1300. ┌────┬───┐
  1301. │ │┌─┐│
  1302. │ │├─┤│
  1303. │ │└─┘│
  1304. └────┴───┘
  1305. ";
  1306. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1307. }
  1308. [Fact]
  1309. [AutoInitShutdown]
  1310. public void TestTileView_CannotSetSplitterPosToFuncEtc ()
  1311. {
  1312. TileView tileView = Get11By3TileView ();
  1313. var ex = Assert.Throws<ArgumentException> (() => tileView.SetSplitterPos (0, Pos.Right (tileView)));
  1314. Assert.Equal ("Only Percent and Absolute values are supported. Passed value was PosView", ex.Message);
  1315. ex = Assert.Throws<ArgumentException> (() => tileView.SetSplitterPos (0, Pos.Func (_ => 1)));
  1316. Assert.Equal ("Only Percent and Absolute values are supported. Passed value was PosFunc", ex.Message);
  1317. // Also not allowed because this results in a PosCombine
  1318. ex = Assert.Throws<ArgumentException> (() => tileView.SetSplitterPos (0, Pos.Percent (50) - 1));
  1319. Assert.Equal (
  1320. "Only Percent and Absolute values are supported. Passed value was PosCombine",
  1321. ex.Message
  1322. );
  1323. }
  1324. [Fact]
  1325. [AutoInitShutdown]
  1326. public void TestTileView_Horizontal ()
  1327. {
  1328. TileView tileView = Get11By3TileView (out Line line);
  1329. tileView.Orientation = Orientation.Horizontal;
  1330. tileView.Layout ();
  1331. tileView.Draw ();
  1332. var looksLike =
  1333. @"
  1334. 11111111111
  1335. ───────────
  1336. 22222222222";
  1337. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1338. // Keyboard movement on splitter should have no effect if it is not focused
  1339. bool handled = tileView.NewKeyDownEvent (Key.CursorDown);
  1340. Assert.False (handled);
  1341. tileView.SetNeedsDraw ();
  1342. tileView.Draw ();
  1343. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1344. }
  1345. [Fact]
  1346. [AutoInitShutdown]
  1347. public void TestTileView_Horizontal_Focused ()
  1348. {
  1349. TileView tileView = Get11By3TileView (out Line line);
  1350. tileView.Orientation = Orientation.Horizontal;
  1351. tileView.NewKeyDownEvent (new (tileView.ToggleResizable));
  1352. Assert.True (line.HasFocus);
  1353. AutoInitShutdownAttribute.RunIteration ();
  1354. var looksLike =
  1355. @"
  1356. 11111111111
  1357. ─────◊─────
  1358. 22222222222";
  1359. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1360. // Now move splitter line down
  1361. tileView.NewKeyDownEvent (Key.CursorDown);
  1362. AutoInitShutdownAttribute.RunIteration ();
  1363. looksLike =
  1364. @"
  1365. 11111111111
  1366. 11111111111
  1367. ─────◊─────";
  1368. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1369. // And 2 up
  1370. line.NewKeyDownEvent (Key.CursorUp);
  1371. AutoInitShutdownAttribute.RunIteration ();
  1372. line.NewKeyDownEvent (Key.CursorUp);
  1373. AutoInitShutdownAttribute.RunIteration ();
  1374. looksLike =
  1375. @"
  1376. ─────◊─────
  1377. 22222222222
  1378. 22222222222";
  1379. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1380. }
  1381. [Fact]
  1382. [AutoInitShutdown]
  1383. public void TestTileView_Horizontal_View1MinSize_Absolute ()
  1384. {
  1385. TileView tileView = Get11By3TileView (out Line line);
  1386. tileView.NewKeyDownEvent (new (tileView.ToggleResizable));
  1387. tileView.Orientation = Orientation.Horizontal;
  1388. tileView.Tiles.ElementAt (0).MinSize = 1;
  1389. // 0 should not be allowed because it brings us below minimum size of View1
  1390. Assert.False (tileView.SetSplitterPos (0, 0));
  1391. // position should remain where it was, at 50%
  1392. Assert.Equal (Pos.Percent (50), tileView.SplitterDistances.ElementAt (0));
  1393. AutoInitShutdownAttribute.RunIteration ();
  1394. var looksLike =
  1395. @"
  1396. 11111111111
  1397. ─────◊─────
  1398. 22222222222";
  1399. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1400. // Now move splitter line down (allowed
  1401. line.NewKeyDownEvent (Key.CursorDown);
  1402. AutoInitShutdownAttribute.RunIteration ();
  1403. looksLike =
  1404. @"
  1405. 11111111111
  1406. 11111111111
  1407. ─────◊─────";
  1408. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1409. // And up 2 (only 1 is allowed because of minimum size of 1 on view1)
  1410. line.NewKeyDownEvent (Key.CursorUp);
  1411. line.NewKeyDownEvent (Key.CursorUp);
  1412. tileView.SetNeedsDraw ();
  1413. AutoInitShutdownAttribute.RunIteration ();
  1414. looksLike =
  1415. @"
  1416. 11111111111
  1417. ─────◊─────
  1418. 22222222222";
  1419. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1420. }
  1421. [Theory]
  1422. [AutoInitShutdown]
  1423. [InlineData (true)]
  1424. [InlineData (false)]
  1425. public void TestTileView_IndexOf (bool recursive)
  1426. {
  1427. var tv = new TileView ();
  1428. var lbl1 = new Label ();
  1429. var lbl2 = new Label ();
  1430. var frame = new FrameView ();
  1431. var sub = new Label ();
  1432. frame.Add (sub);
  1433. // IndexOf returns -1 when view not found
  1434. Assert.Equal (-1, tv.IndexOf (lbl1, recursive));
  1435. Assert.Equal (-1, tv.IndexOf (lbl2, recursive));
  1436. // IndexOf supports looking for Tile.View
  1437. Assert.Equal (0, tv.IndexOf (tv.Tiles.ElementAt (0).ContentView, recursive));
  1438. Assert.Equal (1, tv.IndexOf (tv.Tiles.ElementAt (1).ContentView, recursive));
  1439. // IndexOf supports looking for Tile.View.SubViews
  1440. tv.Tiles.ElementAt (0).ContentView.Add (lbl1);
  1441. Assert.Equal (0, tv.IndexOf (lbl1, recursive));
  1442. tv.Tiles.ElementAt (1).ContentView.Add (lbl2);
  1443. Assert.Equal (1, tv.IndexOf (lbl2, recursive));
  1444. // IndexOf supports looking deep into subviews only when
  1445. // the recursive true value is passed
  1446. tv.Tiles.ElementAt (1).ContentView.Add (frame);
  1447. if (recursive)
  1448. {
  1449. Assert.Equal (1, tv.IndexOf (sub, recursive));
  1450. }
  1451. else
  1452. {
  1453. Assert.Equal (-1, tv.IndexOf (sub, recursive));
  1454. }
  1455. }
  1456. [Fact]
  1457. [AutoInitShutdown]
  1458. public void TestTileView_InsertPanelAtEnd ()
  1459. {
  1460. TileView tileView = Get11By3TileView (out Line line, true);
  1461. tileView.InsertTile (2);
  1462. tileView.Layout ();
  1463. tileView.Draw ();
  1464. // so should ignore the 2 distance and stick to 6
  1465. var looksLike =
  1466. @"
  1467. ┌──┬───┬──┐
  1468. │11│222│ │
  1469. └──┴───┴──┘";
  1470. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1471. }
  1472. [Fact]
  1473. [AutoInitShutdown]
  1474. public void TestTileView_InsertPanelAtStart ()
  1475. {
  1476. TileView tileView = Get11By3TileView (out Line line, true);
  1477. tileView.InsertTile (0);
  1478. tileView.Layout ();
  1479. tileView.Draw ();
  1480. // so should ignore the 2 distance and stick to 6
  1481. var looksLike =
  1482. @"
  1483. ┌──┬───┬──┐
  1484. │ │111│22│
  1485. └──┴───┴──┘";
  1486. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1487. }
  1488. [Fact]
  1489. [AutoInitShutdown]
  1490. public void TestTileView_InsertPanelMiddle ()
  1491. {
  1492. TileView tileView = Get11By3TileView (out Line line, true);
  1493. tileView.InsertTile (1);
  1494. tileView.Layout ();
  1495. tileView.Draw ();
  1496. // so should ignore the 2 distance and stick to 6
  1497. var looksLike =
  1498. @"
  1499. ┌──┬───┬──┐
  1500. │11│ │22│
  1501. └──┴───┴──┘";
  1502. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1503. }
  1504. [Fact]
  1505. [AutoInitShutdown]
  1506. public void TestTileView_Vertical ()
  1507. {
  1508. TileView tileView = Get11By3TileView (out Line line);
  1509. tileView.Layout ();
  1510. tileView.Draw ();
  1511. var looksLike =
  1512. @"
  1513. 11111│22222
  1514. 11111│22222
  1515. │ ";
  1516. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1517. // Keyboard movement on splitter should have no effect if it is not focused
  1518. tileView.NewKeyDownEvent (Key.CursorRight);
  1519. tileView.SetNeedsDraw ();
  1520. tileView.Draw ();
  1521. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1522. }
  1523. [Fact]
  1524. [AutoInitShutdown]
  1525. public void TestTileView_Vertical_Focused ()
  1526. {
  1527. TileView tileView = Get11By3TileView (out Line line);
  1528. tileView.NewKeyDownEvent (new (tileView.ToggleResizable));
  1529. AutoInitShutdownAttribute.RunIteration ();
  1530. var looksLike =
  1531. @"
  1532. 11111│22222
  1533. 11111◊22222
  1534. │ ";
  1535. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1536. // Now while focused move the splitter 1 unit right
  1537. line.NewKeyDownEvent (Key.CursorRight);
  1538. AutoInitShutdownAttribute.RunIteration ();
  1539. looksLike =
  1540. @"
  1541. 111111│2222
  1542. 111111◊2222
  1543. │ ";
  1544. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1545. // and 2 to the left
  1546. line.NewKeyDownEvent (Key.CursorLeft);
  1547. tileView.Layout ();
  1548. line.NewKeyDownEvent (Key.CursorLeft);
  1549. AutoInitShutdownAttribute.RunIteration ();
  1550. looksLike =
  1551. @"
  1552. 1111│222222
  1553. 1111◊222222
  1554. │ ";
  1555. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1556. }
  1557. [Fact]
  1558. [AutoInitShutdown]
  1559. public void TestTileView_Vertical_Focused_50PercentSplit ()
  1560. {
  1561. TileView tileView = Get11By3TileView (out Line line);
  1562. tileView.SetSplitterPos (0, Pos.Percent (50));
  1563. Assert.IsType<PosPercent> (tileView.SplitterDistances.ElementAt (0));
  1564. tileView.NewKeyDownEvent (new (tileView.ToggleResizable));
  1565. AutoInitShutdownAttribute.RunIteration ();
  1566. var looksLike =
  1567. @"
  1568. 11111│22222
  1569. 11111◊22222
  1570. │ ";
  1571. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1572. // Now while focused move the splitter 1 unit right
  1573. line.NewKeyDownEvent (Key.CursorRight);
  1574. AutoInitShutdownAttribute.RunIteration ();
  1575. looksLike =
  1576. @"
  1577. 111111│2222
  1578. 111111◊2222
  1579. │ ";
  1580. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1581. // Even when moving the splitter location it should stay a Percentage based one
  1582. Assert.IsType<PosPercent> (tileView.SplitterDistances.ElementAt (0));
  1583. // and 2 to the left
  1584. line.NewKeyDownEvent (Key.CursorLeft);
  1585. tileView.Layout ();
  1586. line.NewKeyDownEvent (Key.CursorLeft);
  1587. AutoInitShutdownAttribute.RunIteration ();
  1588. looksLike =
  1589. @"
  1590. 1111│222222
  1591. 1111◊222222
  1592. │ ";
  1593. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1594. // Even when moving the splitter location it should stay a Percentage based one
  1595. Assert.IsType<PosPercent> (tileView.SplitterDistances.ElementAt (0));
  1596. }
  1597. [Fact]
  1598. [AutoInitShutdown]
  1599. public void TestTileView_Vertical_Focused_WithBorder ()
  1600. {
  1601. TileView tileView = Get11By3TileView (out Line line, true);
  1602. tileView.NewKeyDownEvent (new (tileView.ToggleResizable));
  1603. AutoInitShutdownAttribute.RunIteration ();
  1604. var looksLike =
  1605. @"
  1606. ┌────┬────┐
  1607. │1111◊2222│
  1608. └────┴────┘";
  1609. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1610. // Now while focused move the splitter 1 unit right
  1611. line.NewKeyDownEvent (Key.CursorRight);
  1612. AutoInitShutdownAttribute.RunIteration ();
  1613. looksLike =
  1614. @"
  1615. ┌─────┬───┐
  1616. │11111◊222│
  1617. └─────┴───┘";
  1618. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1619. // and 2 to the left
  1620. line.NewKeyDownEvent (Key.CursorLeft);
  1621. tileView.Layout ();
  1622. line.NewKeyDownEvent (Key.CursorLeft);
  1623. AutoInitShutdownAttribute.RunIteration ();
  1624. looksLike =
  1625. @"
  1626. ┌───┬─────┐
  1627. │111◊22222│
  1628. └───┴─────┘";
  1629. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1630. }
  1631. [Fact]
  1632. [AutoInitShutdown]
  1633. public void TestTileView_Vertical_View1MinSize_Absolute ()
  1634. {
  1635. TileView tileView = Get11By3TileView (out Line line);
  1636. tileView.NewKeyDownEvent (new (tileView.ToggleResizable));
  1637. tileView.Tiles.ElementAt (0).MinSize = 6;
  1638. // distance is too small (below 6)
  1639. Assert.False (tileView.SetSplitterPos (0, 2));
  1640. // Should stay where it was originally at (50%)
  1641. Assert.Equal (Pos.Percent (50), tileView.SplitterDistances.ElementAt (0));
  1642. AutoInitShutdownAttribute.RunIteration ();
  1643. // so should ignore the 2 distance and stick to 6
  1644. var looksLike =
  1645. @"
  1646. 11111│22222
  1647. 11111◊22222
  1648. │ ";
  1649. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1650. // Keyboard movement on splitter should have no effect because it
  1651. // would take us below the minimum splitter size
  1652. line.NewKeyDownEvent (Key.CursorLeft);
  1653. AutoInitShutdownAttribute.RunIteration ();
  1654. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1655. // but we can continue to move the splitter right if we want
  1656. line.NewKeyDownEvent (Key.CursorRight);
  1657. AutoInitShutdownAttribute.RunIteration ();
  1658. looksLike =
  1659. @"
  1660. 111111│2222
  1661. 111111◊2222
  1662. │ ";
  1663. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1664. }
  1665. [Fact]
  1666. [AutoInitShutdown]
  1667. public void TestTileView_Vertical_View1MinSize_Absolute_WithBorder ()
  1668. {
  1669. TileView tileView = Get11By3TileView (out Line line, true);
  1670. tileView.NewKeyDownEvent (new (tileView.ToggleResizable));
  1671. tileView.Tiles.ElementAt (0).MinSize = 5;
  1672. // distance is too small (below 5)
  1673. Assert.False (tileView.SetSplitterPos (0, 2));
  1674. // Should stay where it was originally at (50%)
  1675. Assert.Equal (Pos.Percent (50), tileView.SplitterDistances.ElementAt (0));
  1676. AutoInitShutdownAttribute.RunIteration ();
  1677. // so should ignore the 2 distance and stick to 5
  1678. var looksLike =
  1679. @"
  1680. ┌────┬────┐
  1681. │1111◊2222│
  1682. └────┴────┘";
  1683. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1684. // Keyboard movement on splitter should have no effect because it
  1685. // would take us below the minimum splitter size
  1686. line.NewKeyDownEvent (Key.CursorLeft);
  1687. AutoInitShutdownAttribute.RunIteration ();
  1688. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1689. // but we can continue to move the splitter right if we want
  1690. line.NewKeyDownEvent (Key.CursorRight);
  1691. AutoInitShutdownAttribute.RunIteration ();
  1692. looksLike =
  1693. @"
  1694. ┌─────┬───┐
  1695. │11111◊222│
  1696. └─────┴───┘";
  1697. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1698. }
  1699. [Fact]
  1700. [AutoInitShutdown]
  1701. public void TestTileView_Vertical_View2MinSize_Absolute ()
  1702. {
  1703. TileView tileView = Get11By3TileView (out Line line);
  1704. tileView.NewKeyDownEvent (new (tileView.ToggleResizable));
  1705. tileView.Tiles.ElementAt (1).MinSize = 6;
  1706. AutoInitShutdownAttribute.RunIteration ();
  1707. // distance leaves too little space for view2 (less than 6 would remain)
  1708. Assert.False (tileView.SetSplitterPos (0, 8));
  1709. // Should stay where it was originally at (50%)
  1710. Assert.Equal (Pos.Percent (50), tileView.SplitterDistances.ElementAt (0));
  1711. AutoInitShutdownAttribute.RunIteration ();
  1712. // so should ignore the 2 distance and stick to 6
  1713. var looksLike =
  1714. @"
  1715. 11111│22222
  1716. 11111◊22222
  1717. │ ";
  1718. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1719. // Keyboard movement on splitter should have no effect because it
  1720. // would take us below the minimum splitter size
  1721. line.NewKeyDownEvent (Key.CursorRight);
  1722. AutoInitShutdownAttribute.RunIteration ();
  1723. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1724. // but we can continue to move the splitter left if we want
  1725. line.NewKeyDownEvent (Key.CursorLeft);
  1726. AutoInitShutdownAttribute.RunIteration ();
  1727. looksLike =
  1728. @"
  1729. 1111│222222
  1730. 1111◊222222
  1731. │ ";
  1732. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1733. }
  1734. [Fact]
  1735. [AutoInitShutdown]
  1736. public void TestTileView_Vertical_View2MinSize_Absolute_WithBorder ()
  1737. {
  1738. TileView tileView = Get11By3TileView (out Line line, true);
  1739. tileView.NewKeyDownEvent (new (tileView.ToggleResizable));
  1740. tileView.Tiles.ElementAt (1).MinSize = 5;
  1741. // distance leaves too little space for view2 (less than 5 would remain)
  1742. Assert.False (tileView.SetSplitterPos (0, 8));
  1743. AutoInitShutdownAttribute.RunIteration ();
  1744. // Should stay where it was originally at (50%)
  1745. Assert.Equal (Pos.Percent (50), tileView.SplitterDistances.ElementAt (0));
  1746. AutoInitShutdownAttribute.RunIteration ();
  1747. // so should ignore the 2 distance and stick to 6
  1748. var looksLike =
  1749. @"
  1750. ┌────┬────┐
  1751. │1111◊2222│
  1752. └────┴────┘";
  1753. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1754. // Keyboard movement on splitter should have no effect because it
  1755. // would take us below the minimum splitter size
  1756. line.NewKeyDownEvent (Key.CursorRight);
  1757. AutoInitShutdownAttribute.RunIteration ();
  1758. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1759. // but we can continue to move the splitter left if we want
  1760. line.NewKeyDownEvent (Key.CursorLeft);
  1761. AutoInitShutdownAttribute.RunIteration ();
  1762. looksLike =
  1763. @"
  1764. ┌───┬─────┐
  1765. │111◊22222│
  1766. └───┴─────┘";
  1767. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1768. }
  1769. [Fact]
  1770. [AutoInitShutdown]
  1771. public void TestTileView_Vertical_WithBorder ()
  1772. {
  1773. TileView tileView = Get11By3TileView (out Line line, true);
  1774. AutoInitShutdownAttribute.RunIteration ();
  1775. var looksLike =
  1776. @"
  1777. ┌────┬────┐
  1778. │1111│2222│
  1779. └────┴────┘";
  1780. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1781. // Keyboard movement on splitter should have no effect if it is not focused
  1782. tileView.NewKeyDownEvent (Key.CursorRight);
  1783. AutoInitShutdownAttribute.RunIteration ();
  1784. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1785. }
  1786. [Fact]
  1787. [AutoInitShutdown]
  1788. public void TestTrySplit_ShouldRetainTitle ()
  1789. {
  1790. var tv = new TileView ();
  1791. tv.Tiles.ElementAt (0).Title = "flibble";
  1792. tv.TrySplitTile (0, 2, out TileView subTileView);
  1793. // We moved the content so the title should also have been moved
  1794. Assert.Equal ("flibble", subTileView.Tiles.ElementAt (0).Title);
  1795. // Secondly we should have cleared the old title (it should have been moved not copied)
  1796. Assert.Empty (tv.Tiles.ElementAt (0).Title);
  1797. }
  1798. private TileView Get11By3TileView (out Line line, bool withBorder = false)
  1799. {
  1800. TileView split = Get11By3TileView (withBorder);
  1801. line = GetLine (split);
  1802. return split;
  1803. }
  1804. private TileView Get11By3TileView (bool withBorder = false) { return GetTileView (11, 3, withBorder); }
  1805. private TileView Get5x1TilesView (bool border = true)
  1806. {
  1807. var tv = new TileView (5)
  1808. {
  1809. Width = 25, Height = 4, LineStyle = LineStyle.Single
  1810. };
  1811. if (!border)
  1812. {
  1813. tv.LineStyle = LineStyle.None;
  1814. }
  1815. tv.Tiles.ElementAt (0)
  1816. .ContentView.Add (
  1817. new Label { Width = Dim.Fill (), Height = 1, Text = new ('1', 100) }
  1818. );
  1819. tv.Tiles.ElementAt (1)
  1820. .ContentView.Add (
  1821. new Label { Width = Dim.Fill (), Height = 1, Text = new ('2', 100) }
  1822. );
  1823. tv.Tiles.ElementAt (2)
  1824. .ContentView.Add (
  1825. new Label { Width = Dim.Fill (), Height = 1, Text = new ('3', 100) }
  1826. );
  1827. tv.Tiles.ElementAt (3)
  1828. .ContentView.Add (
  1829. new Label { Width = Dim.Fill (), Height = 1, Text = new ('4', 100) }
  1830. );
  1831. tv.Tiles.ElementAt (4)
  1832. .ContentView.Add (
  1833. new Label { Width = Dim.Fill (), Height = 1, Text = new ('5', 100) }
  1834. );
  1835. Application.Top = new ();
  1836. Application.Top.Add (tv);
  1837. Application.Begin (Application.Top);
  1838. Application.Top.SetNeedsDraw();
  1839. return tv;
  1840. }
  1841. private Line GetLine (TileView tileView) { return tileView.SubViews.OfType<Line> ().Single (); }
  1842. /// <summary>Creates a vertical orientation root container with left pane split into two (with horizontal splitter line).</summary>
  1843. /// <param name="withBorder"></param>
  1844. /// <returns></returns>
  1845. private TileView GetNestedContainer2Left1Right (bool withBorder)
  1846. {
  1847. TileView container = GetTileView (20, 10, withBorder);
  1848. Assert.True (container.TrySplitTile (0, 2, out TileView newContainer));
  1849. newContainer.Orientation = Orientation.Horizontal;
  1850. container.LayoutSubViews ();
  1851. return container;
  1852. }
  1853. /// <summary>Creates a vertical orientation root container with 3 tiles. The rightmost is split horizontally</summary>
  1854. /// <param name="withBorder"></param>
  1855. /// <returns></returns>
  1856. private TileView GetNestedContainer3Right1Down (bool withBorder, bool withTitles = false, int split = 2)
  1857. {
  1858. Application.Top = new ();
  1859. var container = new TileView (3) { Width = 20, Height = 10 };
  1860. container.LineStyle = withBorder ? LineStyle.Single : LineStyle.None;
  1861. Assert.True (container.TrySplitTile (split, 2, out TileView newContainer));
  1862. newContainer.Orientation = Orientation.Horizontal;
  1863. var i = 0;
  1864. foreach (Tile tile in container.Tiles.Union (newContainer.Tiles))
  1865. {
  1866. if (tile.ContentView is TileView)
  1867. {
  1868. continue;
  1869. }
  1870. i++;
  1871. if (withTitles)
  1872. {
  1873. tile.Title = "T" + i;
  1874. }
  1875. tile.ContentView.Add (
  1876. new TextView
  1877. {
  1878. Width = Dim.Fill (),
  1879. Height = Dim.Fill (),
  1880. Text =
  1881. string.Join (
  1882. '\n',
  1883. Enumerable.Repeat (
  1884. new string (i.ToString () [0], 100),
  1885. 10
  1886. )
  1887. .ToArray ()
  1888. ),
  1889. WordWrap = false
  1890. }
  1891. );
  1892. }
  1893. Application.Top.Add (container);
  1894. Application.Begin (Application.Top);
  1895. return container;
  1896. }
  1897. private TileView GetTileView (int width, int height, bool withBorder = false)
  1898. {
  1899. var container = new TileView
  1900. {
  1901. Id = "container",
  1902. Width = width, Height = height
  1903. };
  1904. container.LineStyle = withBorder ? LineStyle.Single : LineStyle.None;
  1905. container.Tiles.ElementAt (0)
  1906. .ContentView.Add (
  1907. new Label { Id = "label1", Width = Dim.Fill (), Height = 1, Text = new ('1', 100) }
  1908. );
  1909. container.Tiles.ElementAt (0)
  1910. .ContentView.Add (
  1911. new Label
  1912. {
  1913. Id = "label2",
  1914. Width = Dim.Fill (),
  1915. Height = 1,
  1916. Y = 1,
  1917. Text = new ('1', 100)
  1918. }
  1919. );
  1920. container.Tiles.ElementAt (1)
  1921. .ContentView.Add (
  1922. new Label { Id = "label3", Width = Dim.Fill (), Height = 1, Text = new ('2', 100) }
  1923. );
  1924. container.Tiles.ElementAt (1)
  1925. .ContentView.Add (
  1926. new Label
  1927. {
  1928. Id = "label4",
  1929. Width = Dim.Fill (),
  1930. Height = 1,
  1931. Y = 1,
  1932. Text = new ('2', 100)
  1933. }
  1934. );
  1935. container.Tiles.ElementAt (0).MinSize = 0;
  1936. container.Tiles.ElementAt (1).MinSize = 0;
  1937. Application.Top = new ();
  1938. Application.Top.Add (container);
  1939. Application.Begin (Application.Top);
  1940. return container;
  1941. }
  1942. private class DisposeCounter : View
  1943. {
  1944. public int DisposalCount;
  1945. protected override void Dispose (bool disposing)
  1946. {
  1947. DisposalCount++;
  1948. base.Dispose (disposing);
  1949. }
  1950. }
  1951. }