ViewTests.cs 113 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836
  1. ๏ปฟusing System;
  2. using Xunit;
  3. using Xunit.Abstractions;
  4. using GraphViewTests = Terminal.Gui.Views.GraphViewTests;
  5. // Alias Console to MockConsole so we don't accidentally use Console
  6. using Console = Terminal.Gui.FakeConsole;
  7. namespace Terminal.Gui.Core {
  8. public class ViewTests {
  9. readonly ITestOutputHelper output;
  10. public ViewTests (ITestOutputHelper output)
  11. {
  12. this.output = output;
  13. }
  14. [Fact]
  15. public void New_Initializes ()
  16. {
  17. // Parameterless
  18. var r = new View ();
  19. Assert.NotNull (r);
  20. Assert.Equal (LayoutStyle.Computed, r.LayoutStyle);
  21. Assert.Equal ("View()({X=0,Y=0,Width=0,Height=0})", r.ToString ());
  22. Assert.False (r.CanFocus);
  23. Assert.False (r.HasFocus);
  24. Assert.Equal (new Rect (0, 0, 0, 0), r.Bounds);
  25. Assert.Equal (new Rect (0, 0, 0, 0), r.Frame);
  26. Assert.Null (r.Focused);
  27. Assert.Null (r.ColorScheme);
  28. Assert.Null (r.Width);
  29. Assert.Null (r.Height);
  30. Assert.Null (r.X);
  31. Assert.Null (r.Y);
  32. Assert.False (r.IsCurrentTop);
  33. Assert.Empty (r.Id);
  34. Assert.Empty (r.Subviews);
  35. Assert.False (r.WantContinuousButtonPressed);
  36. Assert.False (r.WantMousePositionReports);
  37. Assert.Null (r.SuperView);
  38. Assert.Null (r.MostFocused);
  39. Assert.Equal (TextDirection.LeftRight_TopBottom, r.TextDirection);
  40. // Empty Rect
  41. r = new View (Rect.Empty);
  42. Assert.NotNull (r);
  43. Assert.Equal (LayoutStyle.Absolute, r.LayoutStyle);
  44. Assert.Equal ("View()({X=0,Y=0,Width=0,Height=0})", r.ToString ());
  45. Assert.False (r.CanFocus);
  46. Assert.False (r.HasFocus);
  47. Assert.Equal (new Rect (0, 0, 0, 0), r.Bounds);
  48. Assert.Equal (new Rect (0, 0, 0, 0), r.Frame);
  49. Assert.Null (r.Focused);
  50. Assert.Null (r.ColorScheme);
  51. Assert.Null (r.Width); // All view Dim are initialized now in the IsAdded setter,
  52. Assert.Null (r.Height); // avoiding Dim errors.
  53. Assert.Null (r.X); // All view Pos are initialized now in the IsAdded setter,
  54. Assert.Null (r.Y); // avoiding Pos errors.
  55. Assert.False (r.IsCurrentTop);
  56. Assert.Empty (r.Id);
  57. Assert.Empty (r.Subviews);
  58. Assert.False (r.WantContinuousButtonPressed);
  59. Assert.False (r.WantMousePositionReports);
  60. Assert.Null (r.SuperView);
  61. Assert.Null (r.MostFocused);
  62. Assert.Equal (TextDirection.LeftRight_TopBottom, r.TextDirection);
  63. // Rect with values
  64. r = new View (new Rect (1, 2, 3, 4));
  65. Assert.NotNull (r);
  66. Assert.Equal (LayoutStyle.Absolute, r.LayoutStyle);
  67. Assert.Equal ("View()({X=1,Y=2,Width=3,Height=4})", r.ToString ());
  68. Assert.False (r.CanFocus);
  69. Assert.False (r.HasFocus);
  70. Assert.Equal (new Rect (0, 0, 3, 4), r.Bounds);
  71. Assert.Equal (new Rect (1, 2, 3, 4), r.Frame);
  72. Assert.Null (r.Focused);
  73. Assert.Null (r.ColorScheme);
  74. Assert.Null (r.Width);
  75. Assert.Null (r.Height);
  76. Assert.Null (r.X);
  77. Assert.Null (r.Y);
  78. Assert.False (r.IsCurrentTop);
  79. Assert.Empty (r.Id);
  80. Assert.Empty (r.Subviews);
  81. Assert.False (r.WantContinuousButtonPressed);
  82. Assert.False (r.WantMousePositionReports);
  83. Assert.Null (r.SuperView);
  84. Assert.Null (r.MostFocused);
  85. Assert.Equal (TextDirection.LeftRight_TopBottom, r.TextDirection);
  86. // Initializes a view with a vertical direction
  87. r = new View ("Vertical View", TextDirection.TopBottom_LeftRight);
  88. Assert.NotNull (r);
  89. Assert.Equal (LayoutStyle.Computed, r.LayoutStyle);
  90. Assert.Equal ("View()({X=0,Y=0,Width=1,Height=13})", r.ToString ());
  91. Assert.False (r.CanFocus);
  92. Assert.False (r.HasFocus);
  93. Assert.Equal (new Rect (0, 0, 1, 13), r.Bounds);
  94. Assert.Equal (new Rect (0, 0, 1, 13), r.Frame);
  95. Assert.Null (r.Focused);
  96. Assert.Null (r.ColorScheme);
  97. Assert.Null (r.Width); // All view Dim are initialized now in the IsAdded setter,
  98. Assert.Null (r.Height); // avoiding Dim errors.
  99. Assert.Null (r.X); // All view Pos are initialized now in the IsAdded setter,
  100. Assert.Null (r.Y); // avoiding Pos errors.
  101. Assert.False (r.IsCurrentTop);
  102. Assert.Empty (r.Id);
  103. Assert.Empty (r.Subviews);
  104. Assert.False (r.WantContinuousButtonPressed);
  105. Assert.False (r.WantMousePositionReports);
  106. Assert.Null (r.SuperView);
  107. Assert.Null (r.MostFocused);
  108. Assert.Equal (TextDirection.TopBottom_LeftRight, r.TextDirection);
  109. }
  110. [Fact]
  111. public void New_Methods_Return_False ()
  112. {
  113. var r = new View ();
  114. Assert.False (r.ProcessKey (new KeyEvent () { Key = Key.Unknown }));
  115. Assert.False (r.ProcessHotKey (new KeyEvent () { Key = Key.Unknown }));
  116. Assert.False (r.ProcessColdKey (new KeyEvent () { Key = Key.Unknown }));
  117. Assert.False (r.OnKeyDown (new KeyEvent () { Key = Key.Unknown }));
  118. Assert.False (r.OnKeyUp (new KeyEvent () { Key = Key.Unknown }));
  119. Assert.False (r.MouseEvent (new MouseEvent () { Flags = MouseFlags.AllEvents }));
  120. Assert.False (r.OnMouseEnter (new MouseEvent () { Flags = MouseFlags.AllEvents }));
  121. Assert.False (r.OnMouseLeave (new MouseEvent () { Flags = MouseFlags.AllEvents }));
  122. Assert.False (r.OnEnter (new View ()));
  123. Assert.False (r.OnLeave (new View ()));
  124. // TODO: Add more
  125. }
  126. [Fact]
  127. public void TopologicalSort_Missing_Add ()
  128. {
  129. var root = new View ();
  130. var sub1 = new View ();
  131. root.Add (sub1);
  132. var sub2 = new View ();
  133. sub1.Width = Dim.Width (sub2);
  134. Assert.Throws<InvalidOperationException> (() => root.LayoutSubviews ());
  135. sub2.Width = Dim.Width (sub1);
  136. Assert.Throws<InvalidOperationException> (() => root.LayoutSubviews ());
  137. }
  138. [Fact]
  139. public void TopologicalSort_Recursive_Ref ()
  140. {
  141. var root = new View ();
  142. var sub1 = new View ();
  143. root.Add (sub1);
  144. var sub2 = new View ();
  145. root.Add (sub2);
  146. sub2.Width = Dim.Width (sub2);
  147. Assert.Throws<InvalidOperationException> (() => root.LayoutSubviews ());
  148. }
  149. [Fact]
  150. public void Added_Removed ()
  151. {
  152. var v = new View (new Rect (0, 0, 10, 24));
  153. var t = new View ();
  154. v.Added += (View e) => {
  155. Assert.True (v.SuperView == e);
  156. };
  157. v.Removed += (View e) => {
  158. Assert.True (v.SuperView == null);
  159. };
  160. t.Add (v);
  161. Assert.True (t.Subviews.Count == 1);
  162. t.Remove (v);
  163. Assert.True (t.Subviews.Count == 0);
  164. }
  165. [Fact]
  166. public void Subviews_TabIndexes_AreEqual ()
  167. {
  168. var r = new View ();
  169. var v1 = new View () { CanFocus = true };
  170. var v2 = new View () { CanFocus = true };
  171. var v3 = new View () { CanFocus = true };
  172. r.Add (v1, v2, v3);
  173. Assert.True (r.Subviews.IndexOf (v1) == 0);
  174. Assert.True (r.Subviews.IndexOf (v2) == 1);
  175. Assert.True (r.Subviews.IndexOf (v3) == 2);
  176. Assert.True (r.TabIndexes.IndexOf (v1) == 0);
  177. Assert.True (r.TabIndexes.IndexOf (v2) == 1);
  178. Assert.True (r.TabIndexes.IndexOf (v3) == 2);
  179. Assert.Equal (r.Subviews.IndexOf (v1), r.TabIndexes.IndexOf (v1));
  180. Assert.Equal (r.Subviews.IndexOf (v2), r.TabIndexes.IndexOf (v2));
  181. Assert.Equal (r.Subviews.IndexOf (v3), r.TabIndexes.IndexOf (v3));
  182. }
  183. [Fact]
  184. public void BringSubviewToFront_Subviews_vs_TabIndexes ()
  185. {
  186. var r = new View ();
  187. var v1 = new View () { CanFocus = true };
  188. var v2 = new View () { CanFocus = true };
  189. var v3 = new View () { CanFocus = true };
  190. r.Add (v1, v2, v3);
  191. r.BringSubviewToFront (v1);
  192. Assert.True (r.Subviews.IndexOf (v1) == 2);
  193. Assert.True (r.Subviews.IndexOf (v2) == 0);
  194. Assert.True (r.Subviews.IndexOf (v3) == 1);
  195. Assert.True (r.TabIndexes.IndexOf (v1) == 0);
  196. Assert.True (r.TabIndexes.IndexOf (v2) == 1);
  197. Assert.True (r.TabIndexes.IndexOf (v3) == 2);
  198. }
  199. [Fact]
  200. public void BringSubviewForward_Subviews_vs_TabIndexes ()
  201. {
  202. var r = new View ();
  203. var v1 = new View () { CanFocus = true };
  204. var v2 = new View () { CanFocus = true };
  205. var v3 = new View () { CanFocus = true };
  206. r.Add (v1, v2, v3);
  207. r.BringSubviewForward (v1);
  208. Assert.True (r.Subviews.IndexOf (v1) == 1);
  209. Assert.True (r.Subviews.IndexOf (v2) == 0);
  210. Assert.True (r.Subviews.IndexOf (v3) == 2);
  211. Assert.True (r.TabIndexes.IndexOf (v1) == 0);
  212. Assert.True (r.TabIndexes.IndexOf (v2) == 1);
  213. Assert.True (r.TabIndexes.IndexOf (v3) == 2);
  214. }
  215. [Fact]
  216. public void SendSubviewToBack_Subviews_vs_TabIndexes ()
  217. {
  218. var r = new View ();
  219. var v1 = new View () { CanFocus = true };
  220. var v2 = new View () { CanFocus = true };
  221. var v3 = new View () { CanFocus = true };
  222. r.Add (v1, v2, v3);
  223. r.SendSubviewToBack (v3);
  224. Assert.True (r.Subviews.IndexOf (v1) == 1);
  225. Assert.True (r.Subviews.IndexOf (v2) == 2);
  226. Assert.True (r.Subviews.IndexOf (v3) == 0);
  227. Assert.True (r.TabIndexes.IndexOf (v1) == 0);
  228. Assert.True (r.TabIndexes.IndexOf (v2) == 1);
  229. Assert.True (r.TabIndexes.IndexOf (v3) == 2);
  230. }
  231. [Fact]
  232. public void SendSubviewBackwards_Subviews_vs_TabIndexes ()
  233. {
  234. var r = new View ();
  235. var v1 = new View () { CanFocus = true };
  236. var v2 = new View () { CanFocus = true };
  237. var v3 = new View () { CanFocus = true };
  238. r.Add (v1, v2, v3);
  239. r.SendSubviewBackwards (v3);
  240. Assert.True (r.Subviews.IndexOf (v1) == 0);
  241. Assert.True (r.Subviews.IndexOf (v2) == 2);
  242. Assert.True (r.Subviews.IndexOf (v3) == 1);
  243. Assert.True (r.TabIndexes.IndexOf (v1) == 0);
  244. Assert.True (r.TabIndexes.IndexOf (v2) == 1);
  245. Assert.True (r.TabIndexes.IndexOf (v3) == 2);
  246. }
  247. [Fact]
  248. public void TabIndex_Set_CanFocus_ValidValues ()
  249. {
  250. var r = new View ();
  251. var v1 = new View () { CanFocus = true };
  252. var v2 = new View () { CanFocus = true };
  253. var v3 = new View () { CanFocus = true };
  254. r.Add (v1, v2, v3);
  255. v1.TabIndex = 1;
  256. Assert.True (r.Subviews.IndexOf (v1) == 0);
  257. Assert.True (r.TabIndexes.IndexOf (v1) == 1);
  258. v1.TabIndex = 2;
  259. Assert.True (r.Subviews.IndexOf (v1) == 0);
  260. Assert.True (r.TabIndexes.IndexOf (v1) == 2);
  261. }
  262. [Fact]
  263. public void TabIndex_Set_CanFocus_HigherValues ()
  264. {
  265. var r = new View ();
  266. var v1 = new View () { CanFocus = true };
  267. var v2 = new View () { CanFocus = true };
  268. var v3 = new View () { CanFocus = true };
  269. r.Add (v1, v2, v3);
  270. v1.TabIndex = 3;
  271. Assert.True (r.Subviews.IndexOf (v1) == 0);
  272. Assert.True (r.TabIndexes.IndexOf (v1) == 2);
  273. }
  274. [Fact]
  275. public void TabIndex_Set_CanFocus_LowerValues ()
  276. {
  277. var r = new View ();
  278. var v1 = new View () { CanFocus = true };
  279. var v2 = new View () { CanFocus = true };
  280. var v3 = new View () { CanFocus = true };
  281. r.Add (v1, v2, v3);
  282. v1.TabIndex = -1;
  283. Assert.True (r.Subviews.IndexOf (v1) == 0);
  284. Assert.True (r.TabIndexes.IndexOf (v1) == 0);
  285. }
  286. [Fact]
  287. public void TabIndex_Set_CanFocus_False ()
  288. {
  289. var r = new View ();
  290. var v1 = new View () { CanFocus = true };
  291. var v2 = new View () { CanFocus = true };
  292. var v3 = new View () { CanFocus = true };
  293. r.Add (v1, v2, v3);
  294. v1.CanFocus = false;
  295. v1.TabIndex = 0;
  296. Assert.True (r.Subviews.IndexOf (v1) == 0);
  297. Assert.True (r.TabIndexes.IndexOf (v1) == 0);
  298. Assert.Equal (-1, v1.TabIndex);
  299. }
  300. [Fact]
  301. public void TabIndex_Set_CanFocus_False_To_True ()
  302. {
  303. var r = new View ();
  304. var v1 = new View ();
  305. var v2 = new View () { CanFocus = true };
  306. var v3 = new View () { CanFocus = true };
  307. r.Add (v1, v2, v3);
  308. v1.CanFocus = true;
  309. v1.TabIndex = 1;
  310. Assert.True (r.Subviews.IndexOf (v1) == 0);
  311. Assert.True (r.TabIndexes.IndexOf (v1) == 1);
  312. }
  313. [Fact]
  314. public void TabStop_And_CanFocus_Are_All_True ()
  315. {
  316. var r = new View ();
  317. var v1 = new View () { CanFocus = true };
  318. var v2 = new View () { CanFocus = true };
  319. var v3 = new View () { CanFocus = true };
  320. r.Add (v1, v2, v3);
  321. r.FocusNext ();
  322. Assert.True (v1.HasFocus);
  323. Assert.False (v2.HasFocus);
  324. Assert.False (v3.HasFocus);
  325. r.FocusNext ();
  326. Assert.False (v1.HasFocus);
  327. Assert.True (v2.HasFocus);
  328. Assert.False (v3.HasFocus);
  329. r.FocusNext ();
  330. Assert.False (v1.HasFocus);
  331. Assert.False (v2.HasFocus);
  332. Assert.True (v3.HasFocus);
  333. }
  334. [Fact]
  335. public void TabStop_Are_All_True_And_CanFocus_Are_All_False ()
  336. {
  337. var r = new View ();
  338. var v1 = new View ();
  339. var v2 = new View ();
  340. var v3 = new View ();
  341. r.Add (v1, v2, v3);
  342. r.FocusNext ();
  343. Assert.False (v1.HasFocus);
  344. Assert.False (v2.HasFocus);
  345. Assert.False (v3.HasFocus);
  346. r.FocusNext ();
  347. Assert.False (v1.HasFocus);
  348. Assert.False (v2.HasFocus);
  349. Assert.False (v3.HasFocus);
  350. r.FocusNext ();
  351. Assert.False (v1.HasFocus);
  352. Assert.False (v2.HasFocus);
  353. Assert.False (v3.HasFocus);
  354. }
  355. [Fact]
  356. public void TabStop_Are_All_False_And_CanFocus_Are_All_True ()
  357. {
  358. var r = new View ();
  359. var v1 = new View () { CanFocus = true, TabStop = false };
  360. var v2 = new View () { CanFocus = true, TabStop = false };
  361. var v3 = new View () { CanFocus = true, TabStop = false };
  362. r.Add (v1, v2, v3);
  363. r.FocusNext ();
  364. Assert.False (v1.HasFocus);
  365. Assert.False (v2.HasFocus);
  366. Assert.False (v3.HasFocus);
  367. r.FocusNext ();
  368. Assert.False (v1.HasFocus);
  369. Assert.False (v2.HasFocus);
  370. Assert.False (v3.HasFocus);
  371. r.FocusNext ();
  372. Assert.False (v1.HasFocus);
  373. Assert.False (v2.HasFocus);
  374. Assert.False (v3.HasFocus);
  375. }
  376. [Fact]
  377. public void TabStop_And_CanFocus_Mixed_And_BothFalse ()
  378. {
  379. var r = new View ();
  380. var v1 = new View () { CanFocus = true, TabStop = false };
  381. var v2 = new View () { CanFocus = false, TabStop = true };
  382. var v3 = new View () { CanFocus = false, TabStop = false };
  383. r.Add (v1, v2, v3);
  384. r.FocusNext ();
  385. Assert.False (v1.HasFocus);
  386. Assert.False (v2.HasFocus);
  387. Assert.False (v3.HasFocus);
  388. r.FocusNext ();
  389. Assert.False (v1.HasFocus);
  390. Assert.False (v2.HasFocus);
  391. Assert.False (v3.HasFocus);
  392. r.FocusNext ();
  393. Assert.False (v1.HasFocus);
  394. Assert.False (v2.HasFocus);
  395. Assert.False (v3.HasFocus);
  396. }
  397. [Fact]
  398. public void TabStop_All_True_And_Changing_CanFocus_Later ()
  399. {
  400. var r = new View ();
  401. var v1 = new View ();
  402. var v2 = new View ();
  403. var v3 = new View ();
  404. r.Add (v1, v2, v3);
  405. r.FocusNext ();
  406. Assert.False (v1.HasFocus);
  407. Assert.False (v2.HasFocus);
  408. Assert.False (v3.HasFocus);
  409. v1.CanFocus = true;
  410. r.FocusNext ();
  411. Assert.True (v1.HasFocus);
  412. Assert.False (v2.HasFocus);
  413. Assert.False (v3.HasFocus);
  414. v2.CanFocus = true;
  415. r.FocusNext ();
  416. Assert.False (v1.HasFocus);
  417. Assert.True (v2.HasFocus);
  418. Assert.False (v3.HasFocus);
  419. v3.CanFocus = true;
  420. r.FocusNext ();
  421. Assert.False (v1.HasFocus);
  422. Assert.False (v2.HasFocus);
  423. Assert.True (v3.HasFocus);
  424. }
  425. [Fact]
  426. public void TabStop_All_False_And_All_True_And_Changing_TabStop_Later ()
  427. {
  428. var r = new View ();
  429. var v1 = new View () { CanFocus = true, TabStop = false };
  430. var v2 = new View () { CanFocus = true, TabStop = false };
  431. var v3 = new View () { CanFocus = true, TabStop = false };
  432. r.Add (v1, v2, v3);
  433. r.FocusNext ();
  434. Assert.False (v1.HasFocus);
  435. Assert.False (v2.HasFocus);
  436. Assert.False (v3.HasFocus);
  437. v1.TabStop = true;
  438. r.FocusNext ();
  439. Assert.True (v1.HasFocus);
  440. Assert.False (v2.HasFocus);
  441. Assert.False (v3.HasFocus);
  442. v2.TabStop = true;
  443. r.FocusNext ();
  444. Assert.False (v1.HasFocus);
  445. Assert.True (v2.HasFocus);
  446. Assert.False (v3.HasFocus);
  447. v3.TabStop = true;
  448. r.FocusNext ();
  449. Assert.False (v1.HasFocus);
  450. Assert.False (v2.HasFocus);
  451. Assert.True (v3.HasFocus);
  452. }
  453. [Fact]
  454. public void CanFocus_Set_Changes_TabIndex_And_TabStop ()
  455. {
  456. var r = new View ();
  457. var v1 = new View ("1");
  458. var v2 = new View ("2");
  459. var v3 = new View ("3");
  460. r.Add (v1, v2, v3);
  461. v2.CanFocus = true;
  462. Assert.Equal (r.TabIndexes.IndexOf (v2), v2.TabIndex);
  463. Assert.Equal (0, v2.TabIndex);
  464. Assert.True (v2.TabStop);
  465. v1.CanFocus = true;
  466. Assert.Equal (r.TabIndexes.IndexOf (v1), v1.TabIndex);
  467. Assert.Equal (1, v1.TabIndex);
  468. Assert.True (v1.TabStop);
  469. v1.TabIndex = 2;
  470. Assert.Equal (r.TabIndexes.IndexOf (v1), v1.TabIndex);
  471. Assert.Equal (1, v1.TabIndex);
  472. v3.CanFocus = true;
  473. Assert.Equal (r.TabIndexes.IndexOf (v1), v1.TabIndex);
  474. Assert.Equal (1, v1.TabIndex);
  475. Assert.Equal (r.TabIndexes.IndexOf (v3), v3.TabIndex);
  476. Assert.Equal (2, v3.TabIndex);
  477. Assert.True (v3.TabStop);
  478. v2.CanFocus = false;
  479. Assert.Equal (r.TabIndexes.IndexOf (v1), v1.TabIndex);
  480. Assert.Equal (1, v1.TabIndex);
  481. Assert.True (v1.TabStop);
  482. Assert.NotEqual (r.TabIndexes.IndexOf (v2), v2.TabIndex);
  483. Assert.Equal (-1, v2.TabIndex);
  484. Assert.False (v2.TabStop);
  485. Assert.Equal (r.TabIndexes.IndexOf (v3), v3.TabIndex);
  486. Assert.Equal (2, v3.TabIndex);
  487. Assert.True (v3.TabStop);
  488. }
  489. [Fact]
  490. public void Initialized_Event_Comparing_With_Added_Event ()
  491. {
  492. Application.Init (new FakeDriver (), new FakeMainLoop (() => FakeConsole.ReadKey (true)));
  493. var t = new Toplevel () { Id = "0", };
  494. var w = new Window () { Id = "t", Width = Dim.Fill (), Height = Dim.Fill () };
  495. var v1 = new View () { Id = "v1", Width = Dim.Fill (), Height = Dim.Fill () };
  496. var v2 = new View () { Id = "v2", Width = Dim.Fill (), Height = Dim.Fill () };
  497. var sv1 = new View () { Id = "sv1", Width = Dim.Fill (), Height = Dim.Fill () };
  498. int tc = 0, wc = 0, v1c = 0, v2c = 0, sv1c = 0;
  499. w.Added += (e) => {
  500. Assert.Equal (e.Frame.Width, w.Frame.Width);
  501. Assert.Equal (e.Frame.Height, w.Frame.Height);
  502. };
  503. v1.Added += (e) => {
  504. Assert.Equal (e.Frame.Width, v1.Frame.Width);
  505. Assert.Equal (e.Frame.Height, v1.Frame.Height);
  506. };
  507. v2.Added += (e) => {
  508. Assert.Equal (e.Frame.Width, v2.Frame.Width);
  509. Assert.Equal (e.Frame.Height, v2.Frame.Height);
  510. };
  511. sv1.Added += (e) => {
  512. Assert.Equal (e.Frame.Width, sv1.Frame.Width);
  513. Assert.Equal (e.Frame.Height, sv1.Frame.Height);
  514. };
  515. t.Initialized += (s, e) => {
  516. tc++;
  517. Assert.Equal (1, tc);
  518. Assert.Equal (1, wc);
  519. Assert.Equal (1, v1c);
  520. Assert.Equal (1, v2c);
  521. Assert.Equal (1, sv1c);
  522. Assert.True (t.CanFocus);
  523. Assert.True (w.CanFocus);
  524. Assert.False (v1.CanFocus);
  525. Assert.False (v2.CanFocus);
  526. Assert.False (sv1.CanFocus);
  527. Application.Refresh ();
  528. };
  529. w.Initialized += (s, e) => {
  530. wc++;
  531. Assert.Equal (t.Frame.Width, w.Frame.Width);
  532. Assert.Equal (t.Frame.Height, w.Frame.Height);
  533. };
  534. v1.Initialized += (s, e) => {
  535. v1c++;
  536. Assert.Equal (t.Frame.Width, v1.Frame.Width);
  537. Assert.Equal (t.Frame.Height, v1.Frame.Height);
  538. };
  539. v2.Initialized += (s, e) => {
  540. v2c++;
  541. Assert.Equal (t.Frame.Width, v2.Frame.Width);
  542. Assert.Equal (t.Frame.Height, v2.Frame.Height);
  543. };
  544. sv1.Initialized += (s, e) => {
  545. sv1c++;
  546. Assert.Equal (t.Frame.Width, sv1.Frame.Width);
  547. Assert.Equal (t.Frame.Height, sv1.Frame.Height);
  548. Assert.False (sv1.CanFocus);
  549. Assert.Throws<InvalidOperationException> (() => sv1.CanFocus = true);
  550. Assert.False (sv1.CanFocus);
  551. };
  552. v1.Add (sv1);
  553. w.Add (v1, v2);
  554. t.Add (w);
  555. Application.Iteration = () => {
  556. Application.Refresh ();
  557. t.Running = false;
  558. };
  559. Application.Run (t);
  560. Application.Shutdown ();
  561. Assert.Equal (1, tc);
  562. Assert.Equal (1, wc);
  563. Assert.Equal (1, v1c);
  564. Assert.Equal (1, v2c);
  565. Assert.Equal (1, sv1c);
  566. Assert.True (t.CanFocus);
  567. Assert.True (w.CanFocus);
  568. Assert.False (v1.CanFocus);
  569. Assert.False (v2.CanFocus);
  570. Assert.False (sv1.CanFocus);
  571. v1.CanFocus = true;
  572. Assert.False (sv1.CanFocus); // False because sv1 was disposed and it isn't a subview of v1.
  573. }
  574. [Fact]
  575. public void Initialized_Event_Will_Be_Invoked_When_Added_Dynamically ()
  576. {
  577. Application.Init (new FakeDriver (), new FakeMainLoop (() => FakeConsole.ReadKey (true)));
  578. var t = new Toplevel () { Id = "0", };
  579. var w = new Window () { Id = "t", Width = Dim.Fill (), Height = Dim.Fill () };
  580. var v1 = new View () { Id = "v1", Width = Dim.Fill (), Height = Dim.Fill () };
  581. var v2 = new View () { Id = "v2", Width = Dim.Fill (), Height = Dim.Fill () };
  582. int tc = 0, wc = 0, v1c = 0, v2c = 0, sv1c = 0;
  583. t.Initialized += (s, e) => {
  584. tc++;
  585. Assert.Equal (1, tc);
  586. Assert.Equal (1, wc);
  587. Assert.Equal (1, v1c);
  588. Assert.Equal (1, v2c);
  589. Assert.Equal (0, sv1c); // Added after t in the Application.Iteration.
  590. Assert.True (t.CanFocus);
  591. Assert.True (w.CanFocus);
  592. Assert.False (v1.CanFocus);
  593. Assert.False (v2.CanFocus);
  594. Application.Refresh ();
  595. };
  596. w.Initialized += (s, e) => {
  597. wc++;
  598. Assert.Equal (t.Frame.Width, w.Frame.Width);
  599. Assert.Equal (t.Frame.Height, w.Frame.Height);
  600. };
  601. v1.Initialized += (s, e) => {
  602. v1c++;
  603. Assert.Equal (t.Frame.Width, v1.Frame.Width);
  604. Assert.Equal (t.Frame.Height, v1.Frame.Height);
  605. };
  606. v2.Initialized += (s, e) => {
  607. v2c++;
  608. Assert.Equal (t.Frame.Width, v2.Frame.Width);
  609. Assert.Equal (t.Frame.Height, v2.Frame.Height);
  610. };
  611. w.Add (v1, v2);
  612. t.Add (w);
  613. Application.Iteration = () => {
  614. var sv1 = new View () { Id = "sv1", Width = Dim.Fill (), Height = Dim.Fill () };
  615. sv1.Initialized += (s, e) => {
  616. sv1c++;
  617. Assert.NotEqual (t.Frame.Width, sv1.Frame.Width);
  618. Assert.NotEqual (t.Frame.Height, sv1.Frame.Height);
  619. Assert.False (sv1.CanFocus);
  620. Assert.Throws<InvalidOperationException> (() => sv1.CanFocus = true);
  621. Assert.False (sv1.CanFocus);
  622. };
  623. v1.Add (sv1);
  624. Application.Refresh ();
  625. t.Running = false;
  626. };
  627. Application.Run (t);
  628. Application.Shutdown ();
  629. Assert.Equal (1, tc);
  630. Assert.Equal (1, wc);
  631. Assert.Equal (1, v1c);
  632. Assert.Equal (1, v2c);
  633. Assert.Equal (1, sv1c);
  634. Assert.True (t.CanFocus);
  635. Assert.True (w.CanFocus);
  636. Assert.False (v1.CanFocus);
  637. Assert.False (v2.CanFocus);
  638. }
  639. [Fact]
  640. [AutoInitShutdown]
  641. public void CanFocus_Faced_With_Container ()
  642. {
  643. var t = new Toplevel ();
  644. var w = new Window ();
  645. var f = new FrameView ();
  646. var v = new View () { CanFocus = true };
  647. f.Add (v);
  648. w.Add (f);
  649. t.Add (w);
  650. Assert.True (t.CanFocus);
  651. Assert.True (w.CanFocus);
  652. Assert.True (f.CanFocus);
  653. Assert.True (v.CanFocus);
  654. f.CanFocus = false;
  655. Assert.False (f.CanFocus);
  656. Assert.True (v.CanFocus);
  657. v.CanFocus = false;
  658. Assert.False (f.CanFocus);
  659. Assert.False (v.CanFocus);
  660. v.CanFocus = true;
  661. Assert.False (f.CanFocus);
  662. Assert.True (v.CanFocus);
  663. }
  664. [Fact]
  665. public void CanFocus_Faced_With_Container_Before_Run ()
  666. {
  667. Application.Init (new FakeDriver (), new FakeMainLoop (() => FakeConsole.ReadKey (true)));
  668. var t = Application.Top;
  669. var w = new Window ("w");
  670. var f = new FrameView ("f");
  671. var v = new View ("v") { CanFocus = true };
  672. f.Add (v);
  673. w.Add (f);
  674. t.Add (w);
  675. Assert.True (t.CanFocus);
  676. Assert.True (w.CanFocus);
  677. Assert.True (f.CanFocus);
  678. Assert.True (v.CanFocus);
  679. f.CanFocus = false;
  680. Assert.False (f.CanFocus);
  681. Assert.True (v.CanFocus);
  682. v.CanFocus = false;
  683. Assert.False (f.CanFocus);
  684. Assert.False (v.CanFocus);
  685. v.CanFocus = true;
  686. Assert.False (f.CanFocus);
  687. Assert.True (v.CanFocus);
  688. Application.Iteration += () => Application.RequestStop ();
  689. Application.Run ();
  690. Application.Shutdown ();
  691. }
  692. [Fact]
  693. public void CanFocus_Faced_With_Container_After_Run ()
  694. {
  695. Application.Init (new FakeDriver (), new FakeMainLoop (() => FakeConsole.ReadKey (true)));
  696. var t = Application.Top;
  697. var w = new Window ("w");
  698. var f = new FrameView ("f");
  699. var v = new View ("v") { CanFocus = true };
  700. f.Add (v);
  701. w.Add (f);
  702. t.Add (w);
  703. t.Ready += () => {
  704. Assert.True (t.CanFocus);
  705. Assert.True (w.CanFocus);
  706. Assert.True (f.CanFocus);
  707. Assert.True (v.CanFocus);
  708. f.CanFocus = false;
  709. Assert.False (f.CanFocus);
  710. Assert.False (v.CanFocus);
  711. v.CanFocus = false;
  712. Assert.False (f.CanFocus);
  713. Assert.False (v.CanFocus);
  714. Assert.Throws<InvalidOperationException> (() => v.CanFocus = true);
  715. Assert.False (f.CanFocus);
  716. Assert.False (v.CanFocus);
  717. f.CanFocus = true;
  718. Assert.True (f.CanFocus);
  719. Assert.True (v.CanFocus);
  720. };
  721. Application.Iteration += () => Application.RequestStop ();
  722. Application.Run ();
  723. Application.Shutdown ();
  724. }
  725. [Fact]
  726. public void CanFocus_Container_ToFalse_Turns_All_Subviews_ToFalse_Too ()
  727. {
  728. Application.Init (new FakeDriver (), new FakeMainLoop (() => FakeConsole.ReadKey (true)));
  729. var t = Application.Top;
  730. var w = new Window ("w");
  731. var f = new FrameView ("f");
  732. var v1 = new View ("v1") { CanFocus = true };
  733. var v2 = new View ("v2") { CanFocus = true };
  734. f.Add (v1, v2);
  735. w.Add (f);
  736. t.Add (w);
  737. t.Ready += () => {
  738. Assert.True (t.CanFocus);
  739. Assert.True (w.CanFocus);
  740. Assert.True (f.CanFocus);
  741. Assert.True (v1.CanFocus);
  742. Assert.True (v2.CanFocus);
  743. w.CanFocus = false;
  744. Assert.False (w.CanFocus);
  745. Assert.False (f.CanFocus);
  746. Assert.False (v1.CanFocus);
  747. Assert.False (v2.CanFocus);
  748. };
  749. Application.Iteration += () => Application.RequestStop ();
  750. Application.Run ();
  751. Application.Shutdown ();
  752. }
  753. [Fact]
  754. public void CanFocus_Container_Toggling_All_Subviews_To_Old_Value_When_Is_True ()
  755. {
  756. Application.Init (new FakeDriver (), new FakeMainLoop (() => FakeConsole.ReadKey (true)));
  757. var t = Application.Top;
  758. var w = new Window ("w");
  759. var f = new FrameView ("f");
  760. var v1 = new View ("v1");
  761. var v2 = new View ("v2") { CanFocus = true };
  762. f.Add (v1, v2);
  763. w.Add (f);
  764. t.Add (w);
  765. t.Ready += () => {
  766. Assert.True (t.CanFocus);
  767. Assert.True (w.CanFocus);
  768. Assert.True (f.CanFocus);
  769. Assert.False (v1.CanFocus);
  770. Assert.True (v2.CanFocus);
  771. w.CanFocus = false;
  772. Assert.False (w.CanFocus);
  773. Assert.False (f.CanFocus);
  774. Assert.False (v1.CanFocus);
  775. Assert.False (v2.CanFocus);
  776. w.CanFocus = true;
  777. Assert.True (w.CanFocus);
  778. Assert.True (f.CanFocus);
  779. Assert.False (v1.CanFocus);
  780. Assert.True (v2.CanFocus);
  781. };
  782. Application.Iteration += () => Application.RequestStop ();
  783. Application.Run ();
  784. Application.Shutdown ();
  785. }
  786. [Fact]
  787. public void Navigation_With_Null_Focused_View ()
  788. {
  789. // Non-regression test for #882 (NullReferenceException during keyboard navigation when Focused is null)
  790. Application.Init (new FakeDriver (), new FakeMainLoop (() => FakeConsole.ReadKey (true)));
  791. Application.Top.Ready += () => {
  792. Assert.Null (Application.Top.Focused);
  793. };
  794. // Keyboard navigation with tab
  795. Console.MockKeyPresses.Push (new ConsoleKeyInfo ('\t', ConsoleKey.Tab, false, false, false));
  796. Application.Iteration += () => Application.RequestStop ();
  797. Application.Run ();
  798. Application.Shutdown ();
  799. }
  800. [Fact]
  801. public void Multi_Thread_Toplevels ()
  802. {
  803. Application.Init (new FakeDriver (), new FakeMainLoop (() => FakeConsole.ReadKey (true)));
  804. var t = Application.Top;
  805. var w = new Window ();
  806. t.Add (w);
  807. int count = 0, count1 = 0, count2 = 0;
  808. bool log = false, log1 = false, log2 = false;
  809. bool fromTopStillKnowFirstIsRunning = false;
  810. bool fromTopStillKnowSecondIsRunning = false;
  811. bool fromFirstStillKnowSecondIsRunning = false;
  812. Application.MainLoop.AddTimeout (TimeSpan.FromMilliseconds (100), (_) => {
  813. count++;
  814. if (count1 == 5) {
  815. log1 = true;
  816. }
  817. if (count1 == 14 && count2 == 10 && count == 15) { // count2 is already stopped
  818. fromTopStillKnowFirstIsRunning = true;
  819. }
  820. if (count1 == 7 && count2 == 7 && count == 8) {
  821. fromTopStillKnowSecondIsRunning = true;
  822. }
  823. if (count == 30) {
  824. Assert.Equal (30, count);
  825. Assert.Equal (20, count1);
  826. Assert.Equal (10, count2);
  827. Assert.True (log);
  828. Assert.True (log1);
  829. Assert.True (log2);
  830. Assert.True (fromTopStillKnowFirstIsRunning);
  831. Assert.True (fromTopStillKnowSecondIsRunning);
  832. Assert.True (fromFirstStillKnowSecondIsRunning);
  833. Application.RequestStop ();
  834. return false;
  835. }
  836. return true;
  837. });
  838. t.Ready += FirstDialogToplevel;
  839. void FirstDialogToplevel ()
  840. {
  841. var od = new OpenDialog ();
  842. od.Ready += SecoundDialogToplevel;
  843. Application.MainLoop.AddTimeout (TimeSpan.FromMilliseconds (100), (_) => {
  844. count1++;
  845. if (count2 == 5) {
  846. log2 = true;
  847. }
  848. if (count2 == 4 && count1 == 5 && count == 5) {
  849. fromFirstStillKnowSecondIsRunning = true;
  850. }
  851. if (count1 == 20) {
  852. Assert.Equal (20, count1);
  853. Application.RequestStop ();
  854. return false;
  855. }
  856. return true;
  857. });
  858. Application.Run (od);
  859. }
  860. void SecoundDialogToplevel ()
  861. {
  862. var d = new Dialog ();
  863. Application.MainLoop.AddTimeout (TimeSpan.FromMilliseconds (100), (_) => {
  864. count2++;
  865. if (count < 30) {
  866. log = true;
  867. }
  868. if (count2 == 10) {
  869. Assert.Equal (10, count2);
  870. Application.RequestStop ();
  871. return false;
  872. }
  873. return true;
  874. });
  875. Application.Run (d);
  876. }
  877. Application.Run ();
  878. Application.Shutdown ();
  879. }
  880. [Fact]
  881. public void View_With_No_Difference_Between_An_Object_Initializer_And_A_Constructor ()
  882. {
  883. // Object Initializer
  884. var view = new View () {
  885. X = 1,
  886. Y = 2,
  887. Width = 3,
  888. Height = 4
  889. };
  890. Assert.Equal (1, view.X);
  891. Assert.Equal (2, view.Y);
  892. Assert.Equal (3, view.Width);
  893. Assert.Equal (4, view.Height);
  894. Assert.False (view.Frame.IsEmpty);
  895. Assert.Equal (new Rect (1, 2, 3, 4), view.Frame);
  896. Assert.False (view.Bounds.IsEmpty);
  897. Assert.Equal (new Rect (0, 0, 3, 4), view.Bounds);
  898. view.LayoutSubviews ();
  899. Assert.Equal (1, view.X);
  900. Assert.Equal (2, view.Y);
  901. Assert.Equal (3, view.Width);
  902. Assert.Equal (4, view.Height);
  903. Assert.False (view.Frame.IsEmpty);
  904. Assert.False (view.Bounds.IsEmpty);
  905. // Default Constructor
  906. view = new View ();
  907. Assert.Null (view.X);
  908. Assert.Null (view.Y);
  909. Assert.Null (view.Width);
  910. Assert.Null (view.Height);
  911. Assert.True (view.Frame.IsEmpty);
  912. Assert.True (view.Bounds.IsEmpty);
  913. // Constructor
  914. view = new View (1, 2, "");
  915. Assert.Null (view.X);
  916. Assert.Null (view.Y);
  917. Assert.Null (view.Width);
  918. Assert.Null (view.Height);
  919. Assert.False (view.Frame.IsEmpty);
  920. Assert.True (view.Bounds.IsEmpty);
  921. // Default Constructor and post assignment equivalent to Object Initializer
  922. view = new View ();
  923. view.X = 1;
  924. view.Y = 2;
  925. view.Width = 3;
  926. view.Height = 4;
  927. Assert.Equal (1, view.X);
  928. Assert.Equal (2, view.Y);
  929. Assert.Equal (3, view.Width);
  930. Assert.Equal (4, view.Height);
  931. Assert.False (view.Frame.IsEmpty);
  932. Assert.Equal (new Rect (1, 2, 3, 4), view.Frame);
  933. Assert.False (view.Bounds.IsEmpty);
  934. Assert.Equal (new Rect (0, 0, 3, 4), view.Bounds);
  935. }
  936. [Fact]
  937. public void FocusNearestView_Ensure_Focus_Ordered ()
  938. {
  939. var top = new Toplevel ();
  940. var win = new Window ();
  941. var winSubview = new View ("WindowSubview") {
  942. CanFocus = true
  943. };
  944. win.Add (winSubview);
  945. top.Add (win);
  946. var frm = new FrameView ();
  947. var frmSubview = new View ("FrameSubview") {
  948. CanFocus = true
  949. };
  950. frm.Add (frmSubview);
  951. top.Add (frm);
  952. top.ProcessKey (new KeyEvent (Key.Tab, new KeyModifiers ()));
  953. Assert.Equal ($"WindowSubview", top.MostFocused.Text);
  954. top.ProcessKey (new KeyEvent (Key.Tab, new KeyModifiers ()));
  955. Assert.Equal ("FrameSubview", top.MostFocused.Text);
  956. top.ProcessKey (new KeyEvent (Key.Tab, new KeyModifiers ()));
  957. Assert.Equal ($"WindowSubview", top.MostFocused.Text);
  958. top.ProcessKey (new KeyEvent (Key.BackTab | Key.ShiftMask, new KeyModifiers ()));
  959. Assert.Equal ("FrameSubview", top.MostFocused.Text);
  960. top.ProcessKey (new KeyEvent (Key.BackTab | Key.ShiftMask, new KeyModifiers ()));
  961. Assert.Equal ($"WindowSubview", top.MostFocused.Text);
  962. }
  963. [Fact]
  964. public void KeyPress_Handled_To_True_Prevents_Changes ()
  965. {
  966. Application.Init (new FakeDriver (), new FakeMainLoop (() => FakeConsole.ReadKey (true)));
  967. Console.MockKeyPresses.Push (new ConsoleKeyInfo ('N', ConsoleKey.N, false, false, false));
  968. var top = Application.Top;
  969. var text = new TextField ("");
  970. text.KeyPress += (e) => {
  971. e.Handled = true;
  972. Assert.True (e.Handled);
  973. Assert.Equal (Key.N, e.KeyEvent.Key);
  974. };
  975. top.Add (text);
  976. Application.Iteration += () => {
  977. Console.MockKeyPresses.Push (new ConsoleKeyInfo ('N', ConsoleKey.N, false, false, false));
  978. Assert.Equal ("", text.Text);
  979. Application.RequestStop ();
  980. };
  981. Application.Run ();
  982. // Shutdown must be called to safely clean up Application if Init has been called
  983. Application.Shutdown ();
  984. }
  985. [Fact, AutoInitShutdown]
  986. public void SetWidth_CanSetWidth_ForceValidatePosDim ()
  987. {
  988. var top = new View () {
  989. X = 0,
  990. Y = 0,
  991. Width = 80,
  992. };
  993. var v = new View () {
  994. Width = Dim.Fill (),
  995. ForceValidatePosDim = true
  996. };
  997. top.Add (v);
  998. Assert.False (v.SetWidth (70, out int rWidth));
  999. Assert.Equal (70, rWidth);
  1000. v.Width = Dim.Fill (1);
  1001. Assert.False (v.SetWidth (70, out rWidth));
  1002. Assert.Equal (69, rWidth);
  1003. v.Width = null;
  1004. Assert.True (v.SetWidth (70, out rWidth));
  1005. Assert.Equal (70, rWidth);
  1006. Assert.False (v.IsInitialized);
  1007. Application.Top.Add (top);
  1008. Application.Begin (Application.Top);
  1009. Assert.True (v.IsInitialized);
  1010. v.Width = Dim.Fill (1);
  1011. Assert.Throws<ArgumentException> (() => v.Width = 75);
  1012. v.LayoutStyle = LayoutStyle.Absolute;
  1013. v.Width = 75;
  1014. Assert.True (v.SetWidth (60, out rWidth));
  1015. Assert.Equal (60, rWidth);
  1016. }
  1017. [Fact, AutoInitShutdown]
  1018. public void SetHeight_CanSetHeight_ForceValidatePosDim ()
  1019. {
  1020. var top = new View () {
  1021. X = 0,
  1022. Y = 0,
  1023. Height = 20
  1024. };
  1025. var v = new View () {
  1026. Height = Dim.Fill (),
  1027. ForceValidatePosDim = true
  1028. };
  1029. top.Add (v);
  1030. Assert.False (v.SetHeight (10, out int rHeight));
  1031. Assert.Equal (10, rHeight);
  1032. v.Height = Dim.Fill (1);
  1033. Assert.False (v.SetHeight (10, out rHeight));
  1034. Assert.Equal (9, rHeight);
  1035. v.Height = null;
  1036. Assert.True (v.SetHeight (10, out rHeight));
  1037. Assert.Equal (10, rHeight);
  1038. Assert.False (v.IsInitialized);
  1039. Application.Top.Add (top);
  1040. Application.Begin (Application.Top);
  1041. Assert.True (v.IsInitialized);
  1042. v.Height = Dim.Fill (1);
  1043. Assert.Throws<ArgumentException> (() => v.Height = 15);
  1044. v.LayoutStyle = LayoutStyle.Absolute;
  1045. v.Height = 15;
  1046. Assert.True (v.SetHeight (5, out rHeight));
  1047. Assert.Equal (5, rHeight);
  1048. }
  1049. [Fact]
  1050. public void GetCurrentWidth_CanSetWidth ()
  1051. {
  1052. var top = new View () {
  1053. X = 0,
  1054. Y = 0,
  1055. Width = 80,
  1056. };
  1057. var v = new View () {
  1058. Width = Dim.Fill ()
  1059. };
  1060. top.Add (v);
  1061. Assert.False (v.AutoSize);
  1062. Assert.True (v.GetCurrentWidth (out int cWidth));
  1063. Assert.Equal (80, cWidth);
  1064. v.Width = Dim.Fill (1);
  1065. Assert.True (v.GetCurrentWidth (out cWidth));
  1066. Assert.Equal (79, cWidth);
  1067. v.AutoSize = true;
  1068. Assert.True (v.GetCurrentWidth (out cWidth));
  1069. Assert.Equal (79, cWidth);
  1070. }
  1071. [Fact]
  1072. public void GetCurrentHeight_CanSetHeight ()
  1073. {
  1074. var top = new View () {
  1075. X = 0,
  1076. Y = 0,
  1077. Height = 20
  1078. };
  1079. var v = new View () {
  1080. Height = Dim.Fill ()
  1081. };
  1082. top.Add (v);
  1083. Assert.False (v.AutoSize);
  1084. Assert.True (v.GetCurrentHeight (out int cHeight));
  1085. Assert.Equal (20, cHeight);
  1086. v.Height = Dim.Fill (1);
  1087. Assert.True (v.GetCurrentHeight (out cHeight));
  1088. Assert.Equal (19, cHeight);
  1089. v.AutoSize = true;
  1090. Assert.True (v.GetCurrentHeight (out cHeight));
  1091. Assert.Equal (19, cHeight);
  1092. }
  1093. [Fact]
  1094. public void AutoSize_False_If_Text_Emmpty ()
  1095. {
  1096. var view1 = new View ();
  1097. var view2 = new View ("");
  1098. var view3 = new View () { Text = "" };
  1099. Assert.False (view1.AutoSize);
  1100. Assert.False (view2.AutoSize);
  1101. Assert.False (view3.AutoSize);
  1102. }
  1103. [Fact]
  1104. public void AutoSize_False_If_Text_Is_Not_Emmpty ()
  1105. {
  1106. var view1 = new View ();
  1107. view1.Text = "Hello World";
  1108. var view2 = new View ("Hello World");
  1109. var view3 = new View () { Text = "Hello World" };
  1110. Assert.False (view1.AutoSize);
  1111. Assert.False (view2.AutoSize);
  1112. Assert.False (view3.AutoSize);
  1113. }
  1114. [Fact]
  1115. public void AutoSize_True_Label_If_Text_Emmpty ()
  1116. {
  1117. var label1 = new Label ();
  1118. var label2 = new Label ("");
  1119. var label3 = new Label () { Text = "" };
  1120. Assert.True (label1.AutoSize);
  1121. Assert.True (label2.AutoSize);
  1122. Assert.True (label3.AutoSize);
  1123. }
  1124. [Fact]
  1125. public void AutoSize_True_Label_If_Text_Is_Not_Emmpty ()
  1126. {
  1127. var label1 = new Label ();
  1128. label1.Text = "Hello World";
  1129. var label2 = new Label ("Hello World");
  1130. var label3 = new Label () { Text = "Hello World" };
  1131. Assert.True (label1.AutoSize);
  1132. Assert.True (label2.AutoSize);
  1133. Assert.True (label3.AutoSize);
  1134. }
  1135. [Fact]
  1136. public void AutoSize_False_ResizeView_Is_Always_False ()
  1137. {
  1138. var label = new Label () { AutoSize = false };
  1139. label.Text = "New text";
  1140. Assert.False (label.AutoSize);
  1141. Assert.Equal ("{X=0,Y=0,Width=0,Height=1}", label.Bounds.ToString ());
  1142. }
  1143. [Fact]
  1144. public void AutoSize_True_ResizeView_With_Dim_Absolute ()
  1145. {
  1146. var label = new Label ();
  1147. label.Text = "New text";
  1148. Assert.True (label.AutoSize);
  1149. Assert.Equal ("{X=0,Y=0,Width=8,Height=1}", label.Bounds.ToString ());
  1150. }
  1151. [Fact, AutoInitShutdown]
  1152. public void AutoSize_False_ResizeView_With_Dim_Fill_After_IsInitialized ()
  1153. {
  1154. var win = new Window (new Rect (0, 0, 30, 80), "");
  1155. var label = new Label () { AutoSize = false, Width = Dim.Fill (), Height = Dim.Fill () };
  1156. win.Add (label);
  1157. Application.Top.Add (win);
  1158. // Text is empty so height=0
  1159. Assert.False (label.AutoSize);
  1160. Assert.Equal ("{X=0,Y=0,Width=0,Height=0}", label.Bounds.ToString ());
  1161. label.Text = "New text\nNew line";
  1162. Application.Top.LayoutSubviews ();
  1163. Assert.False (label.AutoSize);
  1164. Assert.Equal ("{X=0,Y=0,Width=28,Height=78}", label.Bounds.ToString ());
  1165. Assert.False (label.IsInitialized);
  1166. Application.Begin (Application.Top);
  1167. Assert.True (label.IsInitialized);
  1168. Assert.False (label.AutoSize);
  1169. Assert.Equal ("{X=0,Y=0,Width=28,Height=78}", label.Bounds.ToString ());
  1170. }
  1171. [Fact, AutoInitShutdown]
  1172. public void AutoSize_False_SetWidthHeight_With_Dim_Fill_And_Dim_Absolute_After_IsAdded_And_IsInitialized ()
  1173. {
  1174. var win = new Window (new Rect (0, 0, 30, 80), "");
  1175. var label = new Label () { Width = Dim.Fill () };
  1176. win.Add (label);
  1177. Application.Top.Add (win);
  1178. Assert.True (label.IsAdded);
  1179. // Text is empty so height=0
  1180. Assert.True (label.AutoSize);
  1181. Assert.Equal ("{X=0,Y=0,Width=0,Height=0}", label.Bounds.ToString ());
  1182. label.Text = "First line\nSecond line";
  1183. Application.Top.LayoutSubviews ();
  1184. Assert.True (label.AutoSize);
  1185. Assert.Equal ("{X=0,Y=0,Width=28,Height=2}", label.Bounds.ToString ());
  1186. Assert.False (label.IsInitialized);
  1187. Application.Begin (Application.Top);
  1188. Assert.True (label.AutoSize);
  1189. Assert.Equal ("{X=0,Y=0,Width=28,Height=2}", label.Bounds.ToString ());
  1190. Assert.True (label.IsInitialized);
  1191. label.AutoSize = false;
  1192. Application.Refresh ();
  1193. Assert.False (label.AutoSize);
  1194. Assert.Equal ("{X=0,Y=0,Width=28,Height=1}", label.Bounds.ToString ());
  1195. }
  1196. [Fact, AutoInitShutdown]
  1197. public void AutoSize_False_SetWidthHeight_With_Dim_Fill_And_Dim_Absolute_With_Initialization ()
  1198. {
  1199. var win = new Window (new Rect (0, 0, 30, 80), "");
  1200. var label = new Label () { Width = Dim.Fill () };
  1201. win.Add (label);
  1202. Application.Top.Add (win);
  1203. // Text is empty so height=0
  1204. Assert.True (label.AutoSize);
  1205. Assert.Equal ("{X=0,Y=0,Width=0,Height=0}", label.Bounds.ToString ());
  1206. Application.Begin (Application.Top);
  1207. Assert.True (label.AutoSize);
  1208. Assert.Equal ("{X=0,Y=0,Width=28,Height=0}", label.Bounds.ToString ());
  1209. label.Text = "First line\nSecond line";
  1210. Application.Refresh ();
  1211. // Here the AutoSize ensuring the right size
  1212. Assert.True (label.AutoSize);
  1213. Assert.Equal ("{X=0,Y=0,Width=28,Height=2}", label.Bounds.ToString ());
  1214. label.AutoSize = false;
  1215. Application.Refresh ();
  1216. // Here the SetMinWidthHeight ensuring the minimum height
  1217. Assert.False (label.AutoSize);
  1218. Assert.Equal ("{X=0,Y=0,Width=28,Height=1}", label.Bounds.ToString ());
  1219. label.Text = "First changed line\nSecond changed line\nNew line";
  1220. Application.Refresh ();
  1221. Assert.False (label.AutoSize);
  1222. Assert.Equal ("{X=0,Y=0,Width=28,Height=1}", label.Bounds.ToString ());
  1223. label.AutoSize = true;
  1224. Application.Refresh ();
  1225. Assert.True (label.AutoSize);
  1226. Assert.Equal ("{X=0,Y=0,Width=28,Height=3}", label.Bounds.ToString ());
  1227. }
  1228. [Fact, AutoInitShutdown]
  1229. public void AutoSize_True_Setting_With_Height_Horizontal ()
  1230. {
  1231. var label = new Label ("Hello") { Width = 10, Height = 2 };
  1232. var viewX = new View ("X") { X = Pos.Right (label) };
  1233. var viewY = new View ("Y") { Y = Pos.Bottom (label) };
  1234. Application.Top.Add (label, viewX, viewY);
  1235. Application.Begin (Application.Top);
  1236. Assert.True (label.AutoSize);
  1237. Assert.Equal (new Rect (0, 0, 10, 2), label.Frame);
  1238. var expected = @"
  1239. Hello X
  1240. Y
  1241. ";
  1242. var pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
  1243. Assert.Equal (new Rect (0, 0, 11, 3), pos);
  1244. label.AutoSize = false;
  1245. Application.Refresh ();
  1246. Assert.False (label.AutoSize);
  1247. Assert.Equal (new Rect (0, 0, 10, 2), label.Frame);
  1248. expected = @"
  1249. Hello X
  1250. Y
  1251. ";
  1252. pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
  1253. Assert.Equal (new Rect (0, 0, 11, 3), pos);
  1254. }
  1255. [Fact, AutoInitShutdown]
  1256. public void AutoSize_True_Setting_With_Height_Vertical ()
  1257. {
  1258. var label = new Label ("Hello") { Width = 2, Height = 10, TextDirection = TextDirection.TopBottom_LeftRight };
  1259. var viewX = new View ("X") { X = Pos.Right (label) };
  1260. var viewY = new View ("Y") { Y = Pos.Bottom (label) };
  1261. Application.Top.Add (label, viewX, viewY);
  1262. Application.Begin (Application.Top);
  1263. Assert.True (label.AutoSize);
  1264. Assert.Equal (new Rect (0, 0, 2, 10), label.Frame);
  1265. var expected = @"
  1266. H X
  1267. e
  1268. l
  1269. l
  1270. o
  1271. Y
  1272. ";
  1273. var pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
  1274. Assert.Equal (new Rect (0, 0, 3, 11), pos);
  1275. label.AutoSize = false;
  1276. Application.Refresh ();
  1277. Assert.False (label.AutoSize);
  1278. Assert.Equal (new Rect (0, 0, 2, 10), label.Frame);
  1279. expected = @"
  1280. H X
  1281. e
  1282. l
  1283. l
  1284. o
  1285. Y
  1286. ";
  1287. pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
  1288. Assert.Equal (new Rect (0, 0, 3, 11), pos);
  1289. }
  1290. [Theory]
  1291. [InlineData (1)]
  1292. [InlineData (2)]
  1293. [InlineData (3)]
  1294. public void LabelChangeText_RendersCorrectly_Constructors (int choice)
  1295. {
  1296. var driver = new FakeDriver ();
  1297. Application.Init (driver, new FakeMainLoop (() => FakeConsole.ReadKey (true)));
  1298. try {
  1299. // Create a label with a short text
  1300. Label lbl;
  1301. var text = "test";
  1302. if (choice == 1) {
  1303. // An object initializer should call the default constructor.
  1304. lbl = new Label { Text = text };
  1305. } else if (choice == 2) {
  1306. // Calling the default constructor followed by the object initializer.
  1307. lbl = new Label () { Text = text };
  1308. } else {
  1309. // Calling the Text constructor.
  1310. lbl = new Label (text);
  1311. }
  1312. lbl.ColorScheme = new ColorScheme ();
  1313. lbl.Redraw (lbl.Bounds);
  1314. // should have the initial text
  1315. Assert.Equal ('t', driver.Contents [0, 0, 0]);
  1316. Assert.Equal ('e', driver.Contents [0, 1, 0]);
  1317. Assert.Equal ('s', driver.Contents [0, 2, 0]);
  1318. Assert.Equal ('t', driver.Contents [0, 3, 0]);
  1319. Assert.Equal (' ', driver.Contents [0, 4, 0]);
  1320. } finally {
  1321. Application.Shutdown ();
  1322. }
  1323. }
  1324. [Fact]
  1325. [AutoInitShutdown]
  1326. public void Internal_Tests ()
  1327. {
  1328. Assert.Equal (new [] { View.Direction.Forward, View.Direction.Backward },
  1329. Enum.GetValues (typeof (View.Direction)));
  1330. var rect = new Rect (1, 1, 10, 1);
  1331. var view = new View (rect);
  1332. var top = Application.Top;
  1333. top.Add (view);
  1334. Assert.Equal (View.Direction.Forward, view.FocusDirection);
  1335. view.FocusDirection = View.Direction.Backward;
  1336. Assert.Equal (View.Direction.Backward, view.FocusDirection);
  1337. Assert.Empty (view.InternalSubviews);
  1338. Assert.Equal (new Rect (new Point (0, 0), rect.Size), view.NeedDisplay);
  1339. Assert.True (view.LayoutNeeded);
  1340. Assert.False (view.ChildNeedsDisplay);
  1341. Assert.False (view.addingView);
  1342. view.addingView = true;
  1343. Assert.True (view.addingView);
  1344. view.ViewToScreen (0, 0, out int rcol, out int rrow);
  1345. Assert.Equal (1, rcol);
  1346. Assert.Equal (1, rrow);
  1347. Assert.Equal (rect, view.ViewToScreen (view.Bounds));
  1348. Assert.Equal (top.Bounds, view.ScreenClip (top.Bounds));
  1349. view.Width = Dim.Fill ();
  1350. view.Height = Dim.Fill ();
  1351. Assert.Equal (10, view.Bounds.Width);
  1352. Assert.Equal (1, view.Bounds.Height);
  1353. view.SetRelativeLayout (top.Bounds);
  1354. Assert.Equal (79, view.Bounds.Width);
  1355. Assert.Equal (24, view.Bounds.Height);
  1356. view.X = 0;
  1357. view.Y = 0;
  1358. view.SetRelativeLayout (top.Bounds);
  1359. Assert.Equal (80, view.Bounds.Width);
  1360. Assert.Equal (25, view.Bounds.Height);
  1361. bool layoutStarted = false;
  1362. view.LayoutStarted += (_) => layoutStarted = true;
  1363. view.OnLayoutStarted (null);
  1364. Assert.True (layoutStarted);
  1365. view.LayoutComplete += (_) => layoutStarted = false;
  1366. view.OnLayoutComplete (null);
  1367. Assert.False (layoutStarted);
  1368. view.X = Pos.Center () - 41;
  1369. view.Y = Pos.Center () - 13;
  1370. view.SetRelativeLayout (top.Bounds);
  1371. view.ViewToScreen (0, 0, out rcol, out rrow);
  1372. Assert.Equal (-1, rcol);
  1373. Assert.Equal (-1, rrow);
  1374. }
  1375. [Fact]
  1376. [AutoInitShutdown]
  1377. public void Enabled_False_Sets_HasFocus_To_False ()
  1378. {
  1379. var wasClicked = false;
  1380. var view = new Button ("Click Me");
  1381. view.Clicked += () => wasClicked = !wasClicked;
  1382. Application.Top.Add (view);
  1383. view.ProcessKey (new KeyEvent (Key.Enter, null));
  1384. Assert.True (wasClicked);
  1385. view.MouseEvent (new MouseEvent () { Flags = MouseFlags.Button1Clicked });
  1386. Assert.False (wasClicked);
  1387. Assert.True (view.Enabled);
  1388. Assert.True (view.CanFocus);
  1389. Assert.True (view.HasFocus);
  1390. view.Enabled = false;
  1391. view.ProcessKey (new KeyEvent (Key.Enter, null));
  1392. Assert.False (wasClicked);
  1393. view.MouseEvent (new MouseEvent () { Flags = MouseFlags.Button1Clicked });
  1394. Assert.False (wasClicked);
  1395. Assert.False (view.Enabled);
  1396. Assert.True (view.CanFocus);
  1397. Assert.False (view.HasFocus);
  1398. view.SetFocus ();
  1399. Assert.False (view.HasFocus);
  1400. }
  1401. [Fact]
  1402. [AutoInitShutdown]
  1403. public void Enabled_Sets_Also_Sets_Subviews ()
  1404. {
  1405. var wasClicked = false;
  1406. var button = new Button ("Click Me");
  1407. button.Clicked += () => wasClicked = !wasClicked;
  1408. var win = new Window () { Width = Dim.Fill (), Height = Dim.Fill () };
  1409. win.Add (button);
  1410. Application.Top.Add (win);
  1411. var iterations = 0;
  1412. Application.Iteration += () => {
  1413. iterations++;
  1414. button.ProcessKey (new KeyEvent (Key.Enter, null));
  1415. Assert.True (wasClicked);
  1416. button.MouseEvent (new MouseEvent () { Flags = MouseFlags.Button1Clicked });
  1417. Assert.False (wasClicked);
  1418. Assert.True (button.Enabled);
  1419. Assert.True (button.CanFocus);
  1420. Assert.True (button.HasFocus);
  1421. Assert.True (win.Enabled);
  1422. Assert.True (win.CanFocus);
  1423. Assert.True (win.HasFocus);
  1424. win.Enabled = false;
  1425. button.ProcessKey (new KeyEvent (Key.Enter, null));
  1426. Assert.False (wasClicked);
  1427. button.MouseEvent (new MouseEvent () { Flags = MouseFlags.Button1Clicked });
  1428. Assert.False (wasClicked);
  1429. Assert.False (button.Enabled);
  1430. Assert.True (button.CanFocus);
  1431. Assert.False (button.HasFocus);
  1432. Assert.False (win.Enabled);
  1433. Assert.True (win.CanFocus);
  1434. Assert.False (win.HasFocus);
  1435. button.SetFocus ();
  1436. Assert.False (button.HasFocus);
  1437. Assert.False (win.HasFocus);
  1438. win.SetFocus ();
  1439. Assert.False (button.HasFocus);
  1440. Assert.False (win.HasFocus);
  1441. win.Enabled = true;
  1442. win.FocusFirst ();
  1443. Assert.True (button.HasFocus);
  1444. Assert.True (win.HasFocus);
  1445. Application.RequestStop ();
  1446. };
  1447. Application.Run ();
  1448. Assert.Equal (1, iterations);
  1449. }
  1450. [Fact]
  1451. [AutoInitShutdown]
  1452. public void Visible_Sets_Also_Sets_Subviews ()
  1453. {
  1454. var button = new Button ("Click Me");
  1455. var win = new Window () { Width = Dim.Fill (), Height = Dim.Fill () };
  1456. win.Add (button);
  1457. var top = Application.Top;
  1458. top.Add (win);
  1459. var iterations = 0;
  1460. Application.Iteration += () => {
  1461. iterations++;
  1462. Assert.True (button.Visible);
  1463. Assert.True (button.CanFocus);
  1464. Assert.True (button.HasFocus);
  1465. Assert.True (win.Visible);
  1466. Assert.True (win.CanFocus);
  1467. Assert.True (win.HasFocus);
  1468. Assert.True (RunesCount () > 0);
  1469. win.Visible = false;
  1470. Assert.True (button.Visible);
  1471. Assert.True (button.CanFocus);
  1472. Assert.False (button.HasFocus);
  1473. Assert.False (win.Visible);
  1474. Assert.True (win.CanFocus);
  1475. Assert.False (win.HasFocus);
  1476. button.SetFocus ();
  1477. Assert.False (button.HasFocus);
  1478. Assert.False (win.HasFocus);
  1479. win.SetFocus ();
  1480. Assert.False (button.HasFocus);
  1481. Assert.False (win.HasFocus);
  1482. top.Redraw (top.Bounds);
  1483. Assert.True (RunesCount () == 0);
  1484. win.Visible = true;
  1485. win.FocusFirst ();
  1486. Assert.True (button.HasFocus);
  1487. Assert.True (win.HasFocus);
  1488. top.Redraw (top.Bounds);
  1489. Assert.True (RunesCount () > 0);
  1490. Application.RequestStop ();
  1491. };
  1492. Application.Run ();
  1493. Assert.Equal (1, iterations);
  1494. int RunesCount ()
  1495. {
  1496. var contents = ((FakeDriver)Application.Driver).Contents;
  1497. var runesCount = 0;
  1498. for (int i = 0; i < Application.Driver.Rows; i++) {
  1499. for (int j = 0; j < Application.Driver.Cols; j++) {
  1500. if (contents [i, j, 0] != ' ') {
  1501. runesCount++;
  1502. }
  1503. }
  1504. }
  1505. return runesCount;
  1506. }
  1507. }
  1508. [Fact]
  1509. [AutoInitShutdown]
  1510. public void GetTopSuperView_Test ()
  1511. {
  1512. var v1 = new View ();
  1513. var fv1 = new FrameView ();
  1514. fv1.Add (v1);
  1515. var tf1 = new TextField ();
  1516. var w1 = new Window ();
  1517. w1.Add (fv1, tf1);
  1518. var top1 = new Toplevel ();
  1519. top1.Add (w1);
  1520. var v2 = new View ();
  1521. var fv2 = new FrameView ();
  1522. fv2.Add (v2);
  1523. var tf2 = new TextField ();
  1524. var w2 = new Window ();
  1525. w2.Add (fv2, tf2);
  1526. var top2 = new Toplevel ();
  1527. top2.Add (w2);
  1528. Assert.Equal (top1, v1.GetTopSuperView ());
  1529. Assert.Equal (top2, v2.GetTopSuperView ());
  1530. }
  1531. [Fact]
  1532. [AutoInitShutdown]
  1533. public void Excess_Text_Is_Erased_When_The_Width_Is_Reduced ()
  1534. {
  1535. var lbl = new Label ("123");
  1536. Application.Top.Add (lbl);
  1537. Application.Begin (Application.Top);
  1538. Assert.True (lbl.AutoSize);
  1539. Assert.Equal ("123 ", GetContents ());
  1540. lbl.Text = "12";
  1541. lbl.SuperView.Redraw (lbl.SuperView.NeedDisplay);
  1542. Assert.Equal ("12 ", GetContents ());
  1543. string GetContents ()
  1544. {
  1545. var text = "";
  1546. for (int i = 0; i < 4; i++) {
  1547. text += (char)Application.Driver.Contents [0, i, 0];
  1548. }
  1549. return text;
  1550. }
  1551. }
  1552. [Fact]
  1553. [AutoInitShutdown]
  1554. public void CanFocus_Sets_To_False_Does_Not_Sets_HasFocus_To_True ()
  1555. {
  1556. var view = new View () { CanFocus = true };
  1557. var win = new Window () { Width = Dim.Fill (), Height = Dim.Fill () };
  1558. win.Add (view);
  1559. Application.Top.Add (win);
  1560. Application.Begin (Application.Top);
  1561. Assert.True (view.CanFocus);
  1562. Assert.True (view.HasFocus);
  1563. view.CanFocus = false;
  1564. Assert.False (view.CanFocus);
  1565. Assert.False (view.HasFocus);
  1566. Assert.Null (Application.Current.Focused);
  1567. Assert.Null (Application.Current.MostFocused);
  1568. }
  1569. [Fact]
  1570. [AutoInitShutdown]
  1571. public void CanFocus_Sets_To_False_On_Single_View_Focus_View_On_Another_Toplevel ()
  1572. {
  1573. var view1 = new View () { Width = 10, Height = 1, CanFocus = true };
  1574. var win1 = new Window () { Width = Dim.Percent (50), Height = Dim.Fill () };
  1575. win1.Add (view1);
  1576. var view2 = new View () { Width = 20, Height = 2, CanFocus = true };
  1577. var win2 = new Window () { X = Pos.Right (win1), Width = Dim.Fill (), Height = Dim.Fill () };
  1578. win2.Add (view2);
  1579. Application.Top.Add (win1, win2);
  1580. Application.Begin (Application.Top);
  1581. Assert.True (view1.CanFocus);
  1582. Assert.True (view1.HasFocus);
  1583. Assert.True (view2.CanFocus);
  1584. Assert.True (view2.HasFocus);
  1585. view1.CanFocus = false;
  1586. Assert.False (view1.CanFocus);
  1587. Assert.False (view1.HasFocus);
  1588. Assert.Equal (win2, Application.Current.Focused);
  1589. Assert.Equal (view2, Application.Current.MostFocused);
  1590. }
  1591. [Fact]
  1592. [AutoInitShutdown]
  1593. public void CanFocus_Sets_To_False_With_Two_Views_Focus_Another_View_On_The_Same_Toplevel ()
  1594. {
  1595. var view1 = new View () { Width = 10, Height = 1, CanFocus = true };
  1596. var view12 = new View () { Y = 5, Width = 10, Height = 1, CanFocus = true };
  1597. var win1 = new Window () { Width = Dim.Percent (50), Height = Dim.Fill () };
  1598. win1.Add (view1, view12);
  1599. var view2 = new View () { Width = 20, Height = 2, CanFocus = true };
  1600. var win2 = new Window () { X = Pos.Right (win1), Width = Dim.Fill (), Height = Dim.Fill () };
  1601. win2.Add (view2);
  1602. Application.Top.Add (win1, win2);
  1603. Application.Begin (Application.Top);
  1604. Assert.True (view1.CanFocus);
  1605. Assert.True (view1.HasFocus);
  1606. Assert.True (view2.CanFocus);
  1607. Assert.True (view2.HasFocus);
  1608. view1.CanFocus = false;
  1609. Assert.False (view1.CanFocus);
  1610. Assert.False (view1.HasFocus);
  1611. Assert.Equal (win1, Application.Current.Focused);
  1612. Assert.Equal (view12, Application.Current.MostFocused);
  1613. }
  1614. [Fact]
  1615. [AutoInitShutdown]
  1616. public void CanFocus_Sets_To_False_On_Toplevel_Focus_View_On_Another_Toplevel ()
  1617. {
  1618. var view1 = new View () { Width = 10, Height = 1, CanFocus = true };
  1619. var win1 = new Window () { Width = Dim.Percent (50), Height = Dim.Fill () };
  1620. win1.Add (view1);
  1621. var view2 = new View () { Width = 20, Height = 2, CanFocus = true };
  1622. var win2 = new Window () { X = Pos.Right (win1), Width = Dim.Fill (), Height = Dim.Fill () };
  1623. win2.Add (view2);
  1624. Application.Top.Add (win1, win2);
  1625. Application.Begin (Application.Top);
  1626. Assert.True (view1.CanFocus);
  1627. Assert.True (view1.HasFocus);
  1628. Assert.True (view2.CanFocus);
  1629. Assert.True (view2.HasFocus);
  1630. win1.CanFocus = false;
  1631. Assert.False (view1.CanFocus);
  1632. Assert.False (view1.HasFocus);
  1633. Assert.False (win1.CanFocus);
  1634. Assert.False (win1.HasFocus);
  1635. Assert.Equal (win2, Application.Current.Focused);
  1636. Assert.Equal (view2, Application.Current.MostFocused);
  1637. }
  1638. [Fact]
  1639. [AutoInitShutdown]
  1640. public void ProcessHotKey_Will_Invoke_ProcessKey_Only_For_The_MostFocused_With_Top_KeyPress_Event ()
  1641. {
  1642. var sbQuiting = false;
  1643. var tfQuiting = false;
  1644. var topQuiting = false;
  1645. var sb = new StatusBar (new StatusItem [] {
  1646. new StatusItem(Key.CtrlMask | Key.Q, "~^Q~ Quit", () => sbQuiting = true )
  1647. });
  1648. var tf = new TextField ();
  1649. tf.KeyPress += Tf_KeyPress;
  1650. void Tf_KeyPress (View.KeyEventEventArgs obj)
  1651. {
  1652. if (obj.KeyEvent.Key == (Key.Q | Key.CtrlMask)) {
  1653. obj.Handled = tfQuiting = true;
  1654. }
  1655. }
  1656. var win = new Window ();
  1657. win.Add (sb, tf);
  1658. var top = Application.Top;
  1659. top.KeyPress += Top_KeyPress;
  1660. void Top_KeyPress (View.KeyEventEventArgs obj)
  1661. {
  1662. if (obj.KeyEvent.Key == (Key.Q | Key.CtrlMask)) {
  1663. obj.Handled = topQuiting = true;
  1664. }
  1665. }
  1666. top.Add (win);
  1667. Application.Begin (top);
  1668. Assert.False (sbQuiting);
  1669. Assert.False (tfQuiting);
  1670. Assert.False (topQuiting);
  1671. Application.Driver.SendKeys ('q', ConsoleKey.Q, false, false, true);
  1672. Assert.False (sbQuiting);
  1673. Assert.True (tfQuiting);
  1674. Assert.False (topQuiting);
  1675. tf.KeyPress -= Tf_KeyPress;
  1676. tfQuiting = false;
  1677. Application.Driver.SendKeys ('q', ConsoleKey.Q, false, false, true);
  1678. Application.MainLoop.MainIteration ();
  1679. Assert.True (sbQuiting);
  1680. Assert.False (tfQuiting);
  1681. Assert.False (topQuiting);
  1682. sb.RemoveItem (0);
  1683. sbQuiting = false;
  1684. Application.Driver.SendKeys ('q', ConsoleKey.Q, false, false, true);
  1685. Application.MainLoop.MainIteration ();
  1686. Assert.False (sbQuiting);
  1687. Assert.False (tfQuiting);
  1688. Assert.True (topQuiting);
  1689. }
  1690. [Fact]
  1691. [AutoInitShutdown]
  1692. public void ProcessHotKey_Will_Invoke_ProcessKey_Only_For_The_MostFocused_Without_Top_KeyPress_Event ()
  1693. {
  1694. var sbQuiting = false;
  1695. var tfQuiting = false;
  1696. var sb = new StatusBar (new StatusItem [] {
  1697. new StatusItem(Key.CtrlMask | Key.Q, "~^Q~ Quit", () => sbQuiting = true )
  1698. });
  1699. var tf = new TextField ();
  1700. tf.KeyPress += Tf_KeyPress;
  1701. void Tf_KeyPress (View.KeyEventEventArgs obj)
  1702. {
  1703. if (obj.KeyEvent.Key == (Key.Q | Key.CtrlMask)) {
  1704. obj.Handled = tfQuiting = true;
  1705. }
  1706. }
  1707. var win = new Window ();
  1708. win.Add (sb, tf);
  1709. var top = Application.Top;
  1710. top.Add (win);
  1711. Application.Begin (top);
  1712. Assert.False (sbQuiting);
  1713. Assert.False (tfQuiting);
  1714. Application.Driver.SendKeys ('q', ConsoleKey.Q, false, false, true);
  1715. Assert.False (sbQuiting);
  1716. Assert.True (tfQuiting);
  1717. tf.KeyPress -= Tf_KeyPress;
  1718. tfQuiting = false;
  1719. Application.Driver.SendKeys ('q', ConsoleKey.Q, false, false, true);
  1720. Application.MainLoop.MainIteration ();
  1721. Assert.True (sbQuiting);
  1722. Assert.False (tfQuiting);
  1723. }
  1724. [Fact]
  1725. [AutoInitShutdown]
  1726. public void WindowDispose_CanFocusProblem ()
  1727. {
  1728. // Arrange
  1729. Application.Init ();
  1730. using var top = Toplevel.Create ();
  1731. using var view = new View (
  1732. x: 0,
  1733. y: 1,
  1734. text: nameof (WindowDispose_CanFocusProblem));
  1735. using var window = new Window ();
  1736. top.Add (window);
  1737. window.Add (view);
  1738. // Act
  1739. Application.Begin (top);
  1740. Application.Shutdown ();
  1741. // Assert does Not throw NullReferenceException
  1742. top.SetFocus ();
  1743. }
  1744. [Fact, AutoInitShutdown]
  1745. public void DrawFrame_With_Positive_Positions ()
  1746. {
  1747. var view = new View (new Rect (0, 0, 8, 4));
  1748. view.DrawContent += (_) => view.DrawFrame (view.Bounds, 0, true);
  1749. Assert.Equal (Point.Empty, new Point (view.Frame.X, view.Frame.Y));
  1750. Assert.Equal (new Size (8, 4), new Size (view.Frame.Width, view.Frame.Height));
  1751. Application.Top.Add (view);
  1752. Application.Begin (Application.Top);
  1753. var expected = @"
  1754. โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”
  1755. โ”‚ โ”‚
  1756. โ”‚ โ”‚
  1757. โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
  1758. ";
  1759. var pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
  1760. Assert.Equal (new Rect (0, 0, 8, 4), pos);
  1761. }
  1762. [Fact, AutoInitShutdown]
  1763. public void DrawFrame_With_Negative_Positions ()
  1764. {
  1765. var view = new View (new Rect (-1, 0, 8, 4));
  1766. view.DrawContent += (_) => view.DrawFrame (view.Bounds, 0, true);
  1767. Assert.Equal (new Point (-1, 0), new Point (view.Frame.X, view.Frame.Y));
  1768. Assert.Equal (new Size (8, 4), new Size (view.Frame.Width, view.Frame.Height));
  1769. Application.Top.Add (view);
  1770. Application.Begin (Application.Top);
  1771. var expected = @"
  1772. โ”€โ”€โ”€โ”€โ”€โ”€โ”
  1773. โ”‚
  1774. โ”‚
  1775. โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
  1776. ";
  1777. var pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
  1778. Assert.Equal (new Rect (0, 0, 7, 4), pos);
  1779. view.Frame = new Rect (-1, -1, 8, 4);
  1780. Application.Refresh ();
  1781. expected = @"
  1782. โ”‚
  1783. โ”‚
  1784. โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
  1785. ";
  1786. pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
  1787. Assert.Equal (new Rect (6, 0, 7, 3), pos);
  1788. view.Frame = new Rect (0, 0, 8, 4);
  1789. ((FakeDriver)Application.Driver).SetBufferSize (7, 4);
  1790. expected = @"
  1791. โ”Œโ”€โ”€โ”€โ”€โ”€โ”€
  1792. โ”‚
  1793. โ”‚
  1794. โ””โ”€โ”€โ”€โ”€โ”€โ”€
  1795. ";
  1796. pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
  1797. Assert.Equal (new Rect (0, 0, 7, 4), pos);
  1798. view.Frame = new Rect (0, 0, 8, 4);
  1799. ((FakeDriver)Application.Driver).SetBufferSize (7, 3);
  1800. }
  1801. [Fact, AutoInitShutdown]
  1802. public void DrawTextFormatter_Respects_The_Clip_Bounds ()
  1803. {
  1804. var view = new View (new Rect (0, 0, 20, 20));
  1805. view.Add (new Label ("0123456789abcdefghij"));
  1806. view.Add (new Label (0, 1, "1\n2\n3\n4\n5\n6\n7\n8\n9\n0"));
  1807. view.Add (new Button (1, 1, "Press me!"));
  1808. var scrollView = new ScrollView (new Rect (1, 1, 15, 10)) {
  1809. ContentSize = new Size (40, 40),
  1810. ShowHorizontalScrollIndicator = true,
  1811. ShowVerticalScrollIndicator = true
  1812. };
  1813. scrollView.Add (view);
  1814. var win = new Window (new Rect (1, 1, 20, 14), "Test");
  1815. win.Add (scrollView);
  1816. Application.Top.Add (win);
  1817. Application.Begin (Application.Top);
  1818. var expected = @"
  1819. โ”Œ Test โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  1820. โ”‚ โ”‚
  1821. โ”‚ 0123456789abcdโ–ฒ โ”‚
  1822. โ”‚ 1[ Press me! ]โ”ฌ โ”‚
  1823. โ”‚ 2 โ”‚ โ”‚
  1824. โ”‚ 3 โ”ด โ”‚
  1825. โ”‚ 4 โ–‘ โ”‚
  1826. โ”‚ 5 โ–‘ โ”‚
  1827. โ”‚ 6 โ–‘ โ”‚
  1828. โ”‚ 7 โ–‘ โ”‚
  1829. โ”‚ 8 โ–ผ โ”‚
  1830. โ”‚ โ—„โ”œโ”€โ”€โ”€โ”คโ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–บ โ”‚
  1831. โ”‚ โ”‚
  1832. โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
  1833. ";
  1834. var pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
  1835. Assert.Equal (new Rect (1, 1, 21, 14), pos);
  1836. Assert.True (scrollView.ProcessKey (new KeyEvent (Key.CursorRight, new KeyModifiers ())));
  1837. Application.Top.Redraw (Application.Top.Bounds);
  1838. expected = @"
  1839. โ”Œ Test โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  1840. โ”‚ โ”‚
  1841. โ”‚ 123456789abcdeโ–ฒ โ”‚
  1842. โ”‚ [ Press me! ] โ”ฌ โ”‚
  1843. โ”‚ โ”‚ โ”‚
  1844. โ”‚ โ”ด โ”‚
  1845. โ”‚ โ–‘ โ”‚
  1846. โ”‚ โ–‘ โ”‚
  1847. โ”‚ โ–‘ โ”‚
  1848. โ”‚ โ–‘ โ”‚
  1849. โ”‚ โ–ผ โ”‚
  1850. โ”‚ โ—„โ”œโ”€โ”€โ”€โ”คโ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–บ โ”‚
  1851. โ”‚ โ”‚
  1852. โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
  1853. ";
  1854. pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
  1855. Assert.Equal (new Rect (1, 1, 21, 14), pos);
  1856. Assert.True (scrollView.ProcessKey (new KeyEvent (Key.CursorRight, new KeyModifiers ())));
  1857. Application.Top.Redraw (Application.Top.Bounds);
  1858. expected = @"
  1859. โ”Œ Test โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  1860. โ”‚ โ”‚
  1861. โ”‚ 23456789abcdefโ–ฒ โ”‚
  1862. โ”‚ Press me! ] โ”ฌ โ”‚
  1863. โ”‚ โ”‚ โ”‚
  1864. โ”‚ โ”ด โ”‚
  1865. โ”‚ โ–‘ โ”‚
  1866. โ”‚ โ–‘ โ”‚
  1867. โ”‚ โ–‘ โ”‚
  1868. โ”‚ โ–‘ โ”‚
  1869. โ”‚ โ–ผ โ”‚
  1870. โ”‚ โ—„โ”œโ”€โ”€โ”€โ”€โ”คโ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–บ โ”‚
  1871. โ”‚ โ”‚
  1872. โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
  1873. ";
  1874. pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
  1875. Assert.Equal (new Rect (1, 1, 21, 14), pos);
  1876. Assert.True (scrollView.ProcessKey (new KeyEvent (Key.CursorRight, new KeyModifiers ())));
  1877. Application.Top.Redraw (Application.Top.Bounds);
  1878. expected = @"
  1879. โ”Œ Test โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  1880. โ”‚ โ”‚
  1881. โ”‚ 3456789abcdefgโ–ฒ โ”‚
  1882. โ”‚ Press me! ] โ”ฌ โ”‚
  1883. โ”‚ โ”‚ โ”‚
  1884. โ”‚ โ”ด โ”‚
  1885. โ”‚ โ–‘ โ”‚
  1886. โ”‚ โ–‘ โ”‚
  1887. โ”‚ โ–‘ โ”‚
  1888. โ”‚ โ–‘ โ”‚
  1889. โ”‚ โ–ผ โ”‚
  1890. โ”‚ โ—„โ”œโ”€โ”€โ”€โ”€โ”คโ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–บ โ”‚
  1891. โ”‚ โ”‚
  1892. โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
  1893. ";
  1894. pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
  1895. Assert.Equal (new Rect (1, 1, 21, 14), pos);
  1896. Assert.True (scrollView.ProcessKey (new KeyEvent (Key.CursorRight, new KeyModifiers ())));
  1897. Application.Top.Redraw (Application.Top.Bounds);
  1898. expected = @"
  1899. โ”Œ Test โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  1900. โ”‚ โ”‚
  1901. โ”‚ 456789abcdefghโ–ฒ โ”‚
  1902. โ”‚ ress me! ] โ”ฌ โ”‚
  1903. โ”‚ โ”‚ โ”‚
  1904. โ”‚ โ”ด โ”‚
  1905. โ”‚ โ–‘ โ”‚
  1906. โ”‚ โ–‘ โ”‚
  1907. โ”‚ โ–‘ โ”‚
  1908. โ”‚ โ–‘ โ”‚
  1909. โ”‚ โ–ผ โ”‚
  1910. โ”‚ โ—„โ–‘โ”œโ”€โ”€โ”€โ”คโ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–บ โ”‚
  1911. โ”‚ โ”‚
  1912. โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
  1913. ";
  1914. pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
  1915. Assert.Equal (new Rect (1, 1, 21, 14), pos);
  1916. Assert.True (scrollView.ProcessKey (new KeyEvent (Key.CursorRight, new KeyModifiers ())));
  1917. Application.Top.Redraw (Application.Top.Bounds);
  1918. expected = @"
  1919. โ”Œ Test โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  1920. โ”‚ โ”‚
  1921. โ”‚ 56789abcdefghiโ–ฒ โ”‚
  1922. โ”‚ ess me! ] โ”ฌ โ”‚
  1923. โ”‚ โ”‚ โ”‚
  1924. โ”‚ โ”ด โ”‚
  1925. โ”‚ โ–‘ โ”‚
  1926. โ”‚ โ–‘ โ”‚
  1927. โ”‚ โ–‘ โ”‚
  1928. โ”‚ โ–‘ โ”‚
  1929. โ”‚ โ–ผ โ”‚
  1930. โ”‚ โ—„โ–‘โ”œโ”€โ”€โ”€โ”€โ”คโ–‘โ–‘โ–‘โ–‘โ–‘โ–บ โ”‚
  1931. โ”‚ โ”‚
  1932. โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
  1933. ";
  1934. pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
  1935. Assert.Equal (new Rect (1, 1, 21, 14), pos);
  1936. Assert.True (scrollView.ProcessKey (new KeyEvent (Key.CursorRight, new KeyModifiers ())));
  1937. Application.Top.Redraw (Application.Top.Bounds);
  1938. expected = @"
  1939. โ”Œ Test โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  1940. โ”‚ โ”‚
  1941. โ”‚ 6789abcdefghijโ–ฒ โ”‚
  1942. โ”‚ ss me! ] โ”ฌ โ”‚
  1943. โ”‚ โ”‚ โ”‚
  1944. โ”‚ โ”ด โ”‚
  1945. โ”‚ โ–‘ โ”‚
  1946. โ”‚ โ–‘ โ”‚
  1947. โ”‚ โ–‘ โ”‚
  1948. โ”‚ โ–‘ โ”‚
  1949. โ”‚ โ–ผ โ”‚
  1950. โ”‚ โ—„โ–‘โ”œโ”€โ”€โ”€โ”€โ”คโ–‘โ–‘โ–‘โ–‘โ–‘โ–บ โ”‚
  1951. โ”‚ โ”‚
  1952. โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
  1953. ";
  1954. pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
  1955. Assert.Equal (new Rect (1, 1, 21, 14), pos);
  1956. Assert.True (scrollView.ProcessKey (new KeyEvent (Key.CursorRight, new KeyModifiers ())));
  1957. Application.Top.Redraw (Application.Top.Bounds);
  1958. expected = @"
  1959. โ”Œ Test โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  1960. โ”‚ โ”‚
  1961. โ”‚ 789abcdefghij โ–ฒ โ”‚
  1962. โ”‚ s me! ] โ”ฌ โ”‚
  1963. โ”‚ โ”‚ โ”‚
  1964. โ”‚ โ”ด โ”‚
  1965. โ”‚ โ–‘ โ”‚
  1966. โ”‚ โ–‘ โ”‚
  1967. โ”‚ โ–‘ โ”‚
  1968. โ”‚ โ–‘ โ”‚
  1969. โ”‚ โ–ผ โ”‚
  1970. โ”‚ โ—„โ–‘โ–‘โ”œโ”€โ”€โ”€โ”คโ–‘โ–‘โ–‘โ–‘โ–‘โ–บ โ”‚
  1971. โ”‚ โ”‚
  1972. โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
  1973. ";
  1974. pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
  1975. Assert.Equal (new Rect (1, 1, 21, 14), pos);
  1976. Assert.True (scrollView.ProcessKey (new KeyEvent (Key.CtrlMask | Key.Home, new KeyModifiers ())));
  1977. Assert.True (scrollView.ProcessKey (new KeyEvent (Key.CursorDown, new KeyModifiers ())));
  1978. Application.Top.Redraw (Application.Top.Bounds);
  1979. expected = @"
  1980. โ”Œ Test โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  1981. โ”‚ โ”‚
  1982. โ”‚ 1[ Press me! ]โ–ฒ โ”‚
  1983. โ”‚ 2 โ”ฌ โ”‚
  1984. โ”‚ 3 โ”‚ โ”‚
  1985. โ”‚ 4 โ”ด โ”‚
  1986. โ”‚ 5 โ–‘ โ”‚
  1987. โ”‚ 6 โ–‘ โ”‚
  1988. โ”‚ 7 โ–‘ โ”‚
  1989. โ”‚ 8 โ–‘ โ”‚
  1990. โ”‚ 9 โ–ผ โ”‚
  1991. โ”‚ โ—„โ”œโ”€โ”€โ”€โ”คโ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–บ โ”‚
  1992. โ”‚ โ”‚
  1993. โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
  1994. ";
  1995. pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
  1996. Assert.Equal (new Rect (1, 1, 21, 14), pos);
  1997. Assert.True (scrollView.ProcessKey (new KeyEvent (Key.CursorDown, new KeyModifiers ())));
  1998. Application.Top.Redraw (Application.Top.Bounds);
  1999. expected = @"
  2000. โ”Œ Test โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  2001. โ”‚ โ”‚
  2002. โ”‚ 2 โ–ฒ โ”‚
  2003. โ”‚ 3 โ”ฌ โ”‚
  2004. โ”‚ 4 โ”‚ โ”‚
  2005. โ”‚ 5 โ”ด โ”‚
  2006. โ”‚ 6 โ–‘ โ”‚
  2007. โ”‚ 7 โ–‘ โ”‚
  2008. โ”‚ 8 โ–‘ โ”‚
  2009. โ”‚ 9 โ–‘ โ”‚
  2010. โ”‚ 0 โ–ผ โ”‚
  2011. โ”‚ โ—„โ”œโ”€โ”€โ”€โ”คโ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–บ โ”‚
  2012. โ”‚ โ”‚
  2013. โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
  2014. ";
  2015. pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
  2016. Assert.Equal (new Rect (1, 1, 21, 14), pos);
  2017. Assert.True (scrollView.ProcessKey (new KeyEvent (Key.CursorDown, new KeyModifiers ())));
  2018. Application.Top.Redraw (Application.Top.Bounds);
  2019. expected = @"
  2020. โ”Œ Test โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  2021. โ”‚ โ”‚
  2022. โ”‚ 3 โ–ฒ โ”‚
  2023. โ”‚ 4 โ”ฌ โ”‚
  2024. โ”‚ 5 โ”‚ โ”‚
  2025. โ”‚ 6 โ”ด โ”‚
  2026. โ”‚ 7 โ–‘ โ”‚
  2027. โ”‚ 8 โ–‘ โ”‚
  2028. โ”‚ 9 โ–‘ โ”‚
  2029. โ”‚ 0 โ–‘ โ”‚
  2030. โ”‚ โ–ผ โ”‚
  2031. โ”‚ โ—„โ”œโ”€โ”€โ”€โ”คโ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–บ โ”‚
  2032. โ”‚ โ”‚
  2033. โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
  2034. ";
  2035. pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
  2036. Assert.Equal (new Rect (1, 1, 21, 14), pos);
  2037. }
  2038. [Fact, AutoInitShutdown]
  2039. public void Clear_Can_Use_Driver_AddRune_Or_AddStr_Methods ()
  2040. {
  2041. var view = new View () {
  2042. Width = Dim.Fill (),
  2043. Height = Dim.Fill ()
  2044. };
  2045. view.LayoutComplete += e => {
  2046. view.DrawFrame (view.Bounds);
  2047. var savedClip = Application.Driver.Clip;
  2048. Application.Driver.Clip = new Rect (1, 1, view.Bounds.Width - 2, view.Bounds.Height - 2);
  2049. for (int row = 0; row < view.Bounds.Height - 2; row++) {
  2050. Application.Driver.Move (1, row + 1);
  2051. for (int col = 0; col < view.Bounds.Width - 2; col++) {
  2052. Application.Driver.AddStr ($"{col}");
  2053. }
  2054. }
  2055. Application.Driver.Clip = savedClip;
  2056. };
  2057. Application.Top.Add (view);
  2058. Application.Begin (Application.Top);
  2059. ((FakeDriver)Application.Driver).SetBufferSize (20, 10);
  2060. var expected = @"
  2061. โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  2062. โ”‚012345678910111213โ”‚
  2063. โ”‚012345678910111213โ”‚
  2064. โ”‚012345678910111213โ”‚
  2065. โ”‚012345678910111213โ”‚
  2066. โ”‚012345678910111213โ”‚
  2067. โ”‚012345678910111213โ”‚
  2068. โ”‚012345678910111213โ”‚
  2069. โ”‚012345678910111213โ”‚
  2070. โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
  2071. ";
  2072. var pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
  2073. Assert.Equal (new Rect (0, 0, 20, 10), pos);
  2074. view.Clear ();
  2075. expected = @"
  2076. ";
  2077. pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
  2078. Assert.Equal (Rect.Empty, pos);
  2079. }
  2080. [Fact, AutoInitShutdown]
  2081. public void Clear_Bounds_Can_Use_Driver_AddRune_Or_AddStr_Methods ()
  2082. {
  2083. var view = new View () {
  2084. Width = Dim.Fill (),
  2085. Height = Dim.Fill ()
  2086. };
  2087. view.LayoutComplete += e => {
  2088. view.DrawFrame (view.Bounds);
  2089. var savedClip = Application.Driver.Clip;
  2090. Application.Driver.Clip = new Rect (1, 1, view.Bounds.Width - 2, view.Bounds.Height - 2);
  2091. for (int row = 0; row < view.Bounds.Height - 2; row++) {
  2092. Application.Driver.Move (1, row + 1);
  2093. for (int col = 0; col < view.Bounds.Width - 2; col++) {
  2094. Application.Driver.AddStr ($"{col}");
  2095. }
  2096. }
  2097. Application.Driver.Clip = savedClip;
  2098. };
  2099. Application.Top.Add (view);
  2100. Application.Begin (Application.Top);
  2101. ((FakeDriver)Application.Driver).SetBufferSize (20, 10);
  2102. var expected = @"
  2103. โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  2104. โ”‚012345678910111213โ”‚
  2105. โ”‚012345678910111213โ”‚
  2106. โ”‚012345678910111213โ”‚
  2107. โ”‚012345678910111213โ”‚
  2108. โ”‚012345678910111213โ”‚
  2109. โ”‚012345678910111213โ”‚
  2110. โ”‚012345678910111213โ”‚
  2111. โ”‚012345678910111213โ”‚
  2112. โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
  2113. ";
  2114. var pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
  2115. Assert.Equal (new Rect (0, 0, 20, 10), pos);
  2116. view.Clear (view.Bounds);
  2117. expected = @"
  2118. ";
  2119. pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
  2120. Assert.Equal (Rect.Empty, pos);
  2121. }
  2122. [Fact, AutoInitShutdown]
  2123. public void Width_Height_SetMinWidthHeight_Narrow_Wide_Runes ()
  2124. {
  2125. var text = $"First line{Environment.NewLine}Second line";
  2126. var horizontalView = new View () {
  2127. Width = 20,
  2128. Text = text
  2129. };
  2130. var verticalView = new View () {
  2131. Y = 3,
  2132. Height = 20,
  2133. Text = text,
  2134. TextDirection = TextDirection.TopBottom_LeftRight
  2135. };
  2136. var win = new Window () {
  2137. Width = Dim.Fill (),
  2138. Height = Dim.Fill (),
  2139. Text = "Window"
  2140. };
  2141. win.Add (horizontalView, verticalView);
  2142. Application.Top.Add (win);
  2143. Application.Begin (Application.Top);
  2144. ((FakeDriver)Application.Driver).SetBufferSize (32, 32);
  2145. Assert.False (horizontalView.AutoSize);
  2146. Assert.False (verticalView.AutoSize);
  2147. Assert.Equal (new Rect (0, 0, 20, 1), horizontalView.Frame);
  2148. Assert.Equal (new Rect (0, 3, 1, 20), verticalView.Frame);
  2149. var expected = @"
  2150. โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  2151. โ”‚First line Second li โ”‚
  2152. โ”‚ โ”‚
  2153. โ”‚ โ”‚
  2154. โ”‚F โ”‚
  2155. โ”‚i โ”‚
  2156. โ”‚r โ”‚
  2157. โ”‚s โ”‚
  2158. โ”‚t โ”‚
  2159. โ”‚ โ”‚
  2160. โ”‚l โ”‚
  2161. โ”‚i โ”‚
  2162. โ”‚n โ”‚
  2163. โ”‚e โ”‚
  2164. โ”‚ โ”‚
  2165. โ”‚S โ”‚
  2166. โ”‚e โ”‚
  2167. โ”‚c โ”‚
  2168. โ”‚o โ”‚
  2169. โ”‚n โ”‚
  2170. โ”‚d โ”‚
  2171. โ”‚ โ”‚
  2172. โ”‚l โ”‚
  2173. โ”‚i โ”‚
  2174. โ”‚ โ”‚
  2175. โ”‚ โ”‚
  2176. โ”‚ โ”‚
  2177. โ”‚ โ”‚
  2178. โ”‚ โ”‚
  2179. โ”‚ โ”‚
  2180. โ”‚ โ”‚
  2181. โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
  2182. ";
  2183. var pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
  2184. Assert.Equal (new Rect (0, 0, 32, 32), pos);
  2185. verticalView.Text = $"ๆœ€ๅˆใฎ่กŒ{Environment.NewLine}ไบŒ่กŒ็›ฎ";
  2186. Application.Top.Redraw (Application.Top.Bounds);
  2187. Assert.Equal (new Rect (0, 3, 2, 20), verticalView.Frame);
  2188. expected = @"
  2189. โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  2190. โ”‚First line Second li โ”‚
  2191. โ”‚ โ”‚
  2192. โ”‚ โ”‚
  2193. โ”‚ๆœ€ โ”‚
  2194. โ”‚ๅˆ โ”‚
  2195. โ”‚ใฎ โ”‚
  2196. โ”‚่กŒ โ”‚
  2197. โ”‚ โ”‚
  2198. โ”‚ไบŒ โ”‚
  2199. โ”‚่กŒ โ”‚
  2200. โ”‚็›ฎ โ”‚
  2201. โ”‚ โ”‚
  2202. โ”‚ โ”‚
  2203. โ”‚ โ”‚
  2204. โ”‚ โ”‚
  2205. โ”‚ โ”‚
  2206. โ”‚ โ”‚
  2207. โ”‚ โ”‚
  2208. โ”‚ โ”‚
  2209. โ”‚ โ”‚
  2210. โ”‚ โ”‚
  2211. โ”‚ โ”‚
  2212. โ”‚ โ”‚
  2213. โ”‚ โ”‚
  2214. โ”‚ โ”‚
  2215. โ”‚ โ”‚
  2216. โ”‚ โ”‚
  2217. โ”‚ โ”‚
  2218. โ”‚ โ”‚
  2219. โ”‚ โ”‚
  2220. โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
  2221. ";
  2222. pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
  2223. Assert.Equal (new Rect (0, 0, 32, 32), pos);
  2224. }
  2225. [Fact, AutoInitShutdown]
  2226. public void TextDirection_Toggle ()
  2227. {
  2228. var view = new View ();
  2229. var win = new Window () { Width = Dim.Fill (), Height = Dim.Fill () };
  2230. win.Add (view);
  2231. Application.Top.Add (win);
  2232. Application.Begin (Application.Top);
  2233. ((FakeDriver)Application.Driver).SetBufferSize (22, 22);
  2234. Assert.False (view.AutoSize);
  2235. Assert.Equal (TextDirection.LeftRight_TopBottom, view.TextDirection);
  2236. Assert.Equal (Rect.Empty, view.Frame);
  2237. Assert.Equal ("Pos.Absolute(0)", view.X.ToString ());
  2238. Assert.Equal ("Pos.Absolute(0)", view.Y.ToString ());
  2239. Assert.Equal ("Dim.Absolute(0)", view.Width.ToString ());
  2240. Assert.Equal ("Dim.Absolute(0)", view.Height.ToString ());
  2241. var expected = @"
  2242. โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  2243. โ”‚ โ”‚
  2244. โ”‚ โ”‚
  2245. โ”‚ โ”‚
  2246. โ”‚ โ”‚
  2247. โ”‚ โ”‚
  2248. โ”‚ โ”‚
  2249. โ”‚ โ”‚
  2250. โ”‚ โ”‚
  2251. โ”‚ โ”‚
  2252. โ”‚ โ”‚
  2253. โ”‚ โ”‚
  2254. โ”‚ โ”‚
  2255. โ”‚ โ”‚
  2256. โ”‚ โ”‚
  2257. โ”‚ โ”‚
  2258. โ”‚ โ”‚
  2259. โ”‚ โ”‚
  2260. โ”‚ โ”‚
  2261. โ”‚ โ”‚
  2262. โ”‚ โ”‚
  2263. โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
  2264. ";
  2265. var pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
  2266. Assert.Equal (new Rect (0, 0, 22, 22), pos);
  2267. view.Text = "Hello World";
  2268. view.Width = 11;
  2269. Application.Refresh ();
  2270. Assert.Equal (new Rect (0, 0, 11, 1), view.Frame);
  2271. Assert.Equal ("Pos.Absolute(0)", view.X.ToString ());
  2272. Assert.Equal ("Pos.Absolute(0)", view.Y.ToString ());
  2273. Assert.Equal ("Dim.Absolute(11)", view.Width.ToString ());
  2274. Assert.Equal ("Dim.Absolute(0)", view.Height.ToString ());
  2275. expected = @"
  2276. โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  2277. โ”‚Hello World โ”‚
  2278. โ”‚ โ”‚
  2279. โ”‚ โ”‚
  2280. โ”‚ โ”‚
  2281. โ”‚ โ”‚
  2282. โ”‚ โ”‚
  2283. โ”‚ โ”‚
  2284. โ”‚ โ”‚
  2285. โ”‚ โ”‚
  2286. โ”‚ โ”‚
  2287. โ”‚ โ”‚
  2288. โ”‚ โ”‚
  2289. โ”‚ โ”‚
  2290. โ”‚ โ”‚
  2291. โ”‚ โ”‚
  2292. โ”‚ โ”‚
  2293. โ”‚ โ”‚
  2294. โ”‚ โ”‚
  2295. โ”‚ โ”‚
  2296. โ”‚ โ”‚
  2297. โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
  2298. ";
  2299. pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
  2300. Assert.Equal (new Rect (0, 0, 22, 22), pos);
  2301. view.AutoSize = true;
  2302. view.Text = "Hello Worlds";
  2303. Application.Refresh ();
  2304. Assert.Equal (new Rect (0, 0, 12, 1), view.Frame);
  2305. Assert.Equal ("Pos.Absolute(0)", view.X.ToString ());
  2306. Assert.Equal ("Pos.Absolute(0)", view.Y.ToString ());
  2307. Assert.Equal ("Dim.Absolute(11)", view.Width.ToString ());
  2308. Assert.Equal ("Dim.Absolute(0)", view.Height.ToString ());
  2309. expected = @"
  2310. โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  2311. โ”‚Hello Worlds โ”‚
  2312. โ”‚ โ”‚
  2313. โ”‚ โ”‚
  2314. โ”‚ โ”‚
  2315. โ”‚ โ”‚
  2316. โ”‚ โ”‚
  2317. โ”‚ โ”‚
  2318. โ”‚ โ”‚
  2319. โ”‚ โ”‚
  2320. โ”‚ โ”‚
  2321. โ”‚ โ”‚
  2322. โ”‚ โ”‚
  2323. โ”‚ โ”‚
  2324. โ”‚ โ”‚
  2325. โ”‚ โ”‚
  2326. โ”‚ โ”‚
  2327. โ”‚ โ”‚
  2328. โ”‚ โ”‚
  2329. โ”‚ โ”‚
  2330. โ”‚ โ”‚
  2331. โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
  2332. ";
  2333. pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
  2334. Assert.Equal (new Rect (0, 0, 22, 22), pos);
  2335. view.TextDirection = TextDirection.TopBottom_LeftRight;
  2336. Application.Refresh ();
  2337. Assert.Equal (new Rect (0, 0, 11, 12), view.Frame);
  2338. Assert.Equal ("Pos.Absolute(0)", view.X.ToString ());
  2339. Assert.Equal ("Pos.Absolute(0)", view.Y.ToString ());
  2340. Assert.Equal ("Dim.Absolute(11)", view.Width.ToString ());
  2341. Assert.Equal ("Dim.Absolute(0)", view.Height.ToString ());
  2342. expected = @"
  2343. โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  2344. โ”‚H โ”‚
  2345. โ”‚e โ”‚
  2346. โ”‚l โ”‚
  2347. โ”‚l โ”‚
  2348. โ”‚o โ”‚
  2349. โ”‚ โ”‚
  2350. โ”‚W โ”‚
  2351. โ”‚o โ”‚
  2352. โ”‚r โ”‚
  2353. โ”‚l โ”‚
  2354. โ”‚d โ”‚
  2355. โ”‚s โ”‚
  2356. โ”‚ โ”‚
  2357. โ”‚ โ”‚
  2358. โ”‚ โ”‚
  2359. โ”‚ โ”‚
  2360. โ”‚ โ”‚
  2361. โ”‚ โ”‚
  2362. โ”‚ โ”‚
  2363. โ”‚ โ”‚
  2364. โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
  2365. ";
  2366. pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
  2367. Assert.Equal (new Rect (0, 0, 22, 22), pos);
  2368. view.AutoSize = false;
  2369. view.Height = 1;
  2370. Application.Refresh ();
  2371. Assert.Equal (new Rect (0, 0, 11, 1), view.Frame);
  2372. Assert.Equal ("Pos.Absolute(0)", view.X.ToString ());
  2373. Assert.Equal ("Pos.Absolute(0)", view.Y.ToString ());
  2374. Assert.Equal ("Dim.Absolute(11)", view.Width.ToString ());
  2375. Assert.Equal ("Dim.Absolute(1)", view.Height.ToString ());
  2376. expected = @"
  2377. โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  2378. โ”‚HelloWorlds โ”‚
  2379. โ”‚ โ”‚
  2380. โ”‚ โ”‚
  2381. โ”‚ โ”‚
  2382. โ”‚ โ”‚
  2383. โ”‚ โ”‚
  2384. โ”‚ โ”‚
  2385. โ”‚ โ”‚
  2386. โ”‚ โ”‚
  2387. โ”‚ โ”‚
  2388. โ”‚ โ”‚
  2389. โ”‚ โ”‚
  2390. โ”‚ โ”‚
  2391. โ”‚ โ”‚
  2392. โ”‚ โ”‚
  2393. โ”‚ โ”‚
  2394. โ”‚ โ”‚
  2395. โ”‚ โ”‚
  2396. โ”‚ โ”‚
  2397. โ”‚ โ”‚
  2398. โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
  2399. ";
  2400. pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
  2401. Assert.Equal (new Rect (0, 0, 22, 22), pos);
  2402. view.PreserveTrailingSpaces = true;
  2403. Application.Refresh ();
  2404. Assert.Equal (new Rect (0, 0, 11, 1), view.Frame);
  2405. Assert.Equal ("Pos.Absolute(0)", view.X.ToString ());
  2406. Assert.Equal ("Pos.Absolute(0)", view.Y.ToString ());
  2407. Assert.Equal ("Dim.Absolute(11)", view.Width.ToString ());
  2408. Assert.Equal ("Dim.Absolute(1)", view.Height.ToString ());
  2409. expected = @"
  2410. โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  2411. โ”‚Hello World โ”‚
  2412. โ”‚ โ”‚
  2413. โ”‚ โ”‚
  2414. โ”‚ โ”‚
  2415. โ”‚ โ”‚
  2416. โ”‚ โ”‚
  2417. โ”‚ โ”‚
  2418. โ”‚ โ”‚
  2419. โ”‚ โ”‚
  2420. โ”‚ โ”‚
  2421. โ”‚ โ”‚
  2422. โ”‚ โ”‚
  2423. โ”‚ โ”‚
  2424. โ”‚ โ”‚
  2425. โ”‚ โ”‚
  2426. โ”‚ โ”‚
  2427. โ”‚ โ”‚
  2428. โ”‚ โ”‚
  2429. โ”‚ โ”‚
  2430. โ”‚ โ”‚
  2431. โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
  2432. ";
  2433. pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
  2434. Assert.Equal (new Rect (0, 0, 22, 22), pos);
  2435. view.PreserveTrailingSpaces = false;
  2436. var f = view.Frame;
  2437. view.Width = f.Height;
  2438. view.Height = f.Width;
  2439. view.TextDirection = TextDirection.TopBottom_LeftRight;
  2440. Application.Refresh ();
  2441. Assert.Equal (new Rect (0, 0, 1, 11), view.Frame);
  2442. Assert.Equal ("Pos.Absolute(0)", view.X.ToString ());
  2443. Assert.Equal ("Pos.Absolute(0)", view.Y.ToString ());
  2444. Assert.Equal ("Dim.Absolute(1)", view.Width.ToString ());
  2445. Assert.Equal ("Dim.Absolute(11)", view.Height.ToString ());
  2446. expected = @"
  2447. โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  2448. โ”‚H โ”‚
  2449. โ”‚e โ”‚
  2450. โ”‚l โ”‚
  2451. โ”‚l โ”‚
  2452. โ”‚o โ”‚
  2453. โ”‚ โ”‚
  2454. โ”‚W โ”‚
  2455. โ”‚o โ”‚
  2456. โ”‚r โ”‚
  2457. โ”‚l โ”‚
  2458. โ”‚d โ”‚
  2459. โ”‚ โ”‚
  2460. โ”‚ โ”‚
  2461. โ”‚ โ”‚
  2462. โ”‚ โ”‚
  2463. โ”‚ โ”‚
  2464. โ”‚ โ”‚
  2465. โ”‚ โ”‚
  2466. โ”‚ โ”‚
  2467. โ”‚ โ”‚
  2468. โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
  2469. ";
  2470. pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
  2471. Assert.Equal (new Rect (0, 0, 22, 22), pos);
  2472. view.AutoSize = true;
  2473. Application.Refresh ();
  2474. Assert.Equal (new Rect (0, 0, 1, 12), view.Frame);
  2475. Assert.Equal ("Pos.Absolute(0)", view.X.ToString ());
  2476. Assert.Equal ("Pos.Absolute(0)", view.Y.ToString ());
  2477. Assert.Equal ("Dim.Absolute(1)", view.Width.ToString ());
  2478. Assert.Equal ("Dim.Absolute(11)", view.Height.ToString ());
  2479. expected = @"
  2480. โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  2481. โ”‚H โ”‚
  2482. โ”‚e โ”‚
  2483. โ”‚l โ”‚
  2484. โ”‚l โ”‚
  2485. โ”‚o โ”‚
  2486. โ”‚ โ”‚
  2487. โ”‚W โ”‚
  2488. โ”‚o โ”‚
  2489. โ”‚r โ”‚
  2490. โ”‚l โ”‚
  2491. โ”‚d โ”‚
  2492. โ”‚s โ”‚
  2493. โ”‚ โ”‚
  2494. โ”‚ โ”‚
  2495. โ”‚ โ”‚
  2496. โ”‚ โ”‚
  2497. โ”‚ โ”‚
  2498. โ”‚ โ”‚
  2499. โ”‚ โ”‚
  2500. โ”‚ โ”‚
  2501. โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
  2502. ";
  2503. pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
  2504. Assert.Equal (new Rect (0, 0, 22, 22), pos);
  2505. }
  2506. [Fact, AutoInitShutdown]
  2507. public void Width_Height_AutoSize_True_Stay_True_If_TextFormatter_Size_Fit ()
  2508. {
  2509. var text = $"Fi_nish ็ต‚";
  2510. var horizontalView = new View () {
  2511. AutoSize = true,
  2512. HotKeySpecifier = '_',
  2513. Text = text
  2514. };
  2515. var verticalView = new View () {
  2516. Y = 3,
  2517. AutoSize = true,
  2518. HotKeySpecifier = '_',
  2519. Text = text,
  2520. TextDirection = TextDirection.TopBottom_LeftRight
  2521. };
  2522. var win = new Window () {
  2523. Width = Dim.Fill (),
  2524. Height = Dim.Fill (),
  2525. Text = "Window"
  2526. };
  2527. win.Add (horizontalView, verticalView);
  2528. Application.Top.Add (win);
  2529. Application.Begin (Application.Top);
  2530. ((FakeDriver)Application.Driver).SetBufferSize (22, 22);
  2531. Assert.True (horizontalView.AutoSize);
  2532. Assert.True (verticalView.AutoSize);
  2533. Assert.Equal (new Size (10, 1), horizontalView.TextFormatter.Size);
  2534. Assert.Equal (new Size (2, 9), verticalView.TextFormatter.Size);
  2535. Assert.Equal (new Rect (0, 0, 9, 1), horizontalView.Frame);
  2536. Assert.Equal ("Pos.Absolute(0)", horizontalView.X.ToString ());
  2537. Assert.Equal ("Pos.Absolute(0)", horizontalView.Y.ToString ());
  2538. Assert.Equal ("Dim.Absolute(9)", horizontalView.Width.ToString ());
  2539. Assert.Equal ("Dim.Absolute(1)", horizontalView.Height.ToString ());
  2540. Assert.Equal (new Rect (0, 3, 2, 8), verticalView.Frame);
  2541. Assert.Equal ("Pos.Absolute(0)", verticalView.X.ToString ());
  2542. Assert.Equal ("Pos.Absolute(3)", verticalView.Y.ToString ());
  2543. Assert.Equal ("Dim.Absolute(2)", verticalView.Width.ToString ());
  2544. Assert.Equal ("Dim.Absolute(8)", verticalView.Height.ToString ());
  2545. var expected = @"
  2546. โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  2547. โ”‚Finish ็ต‚ โ”‚
  2548. โ”‚ โ”‚
  2549. โ”‚ โ”‚
  2550. โ”‚F โ”‚
  2551. โ”‚i โ”‚
  2552. โ”‚n โ”‚
  2553. โ”‚i โ”‚
  2554. โ”‚s โ”‚
  2555. โ”‚h โ”‚
  2556. โ”‚ โ”‚
  2557. โ”‚็ต‚ โ”‚
  2558. โ”‚ โ”‚
  2559. โ”‚ โ”‚
  2560. โ”‚ โ”‚
  2561. โ”‚ โ”‚
  2562. โ”‚ โ”‚
  2563. โ”‚ โ”‚
  2564. โ”‚ โ”‚
  2565. โ”‚ โ”‚
  2566. โ”‚ โ”‚
  2567. โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
  2568. ";
  2569. var pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
  2570. Assert.Equal (new Rect (0, 0, 22, 22), pos);
  2571. verticalView.Text = $"ๆœ€ๅˆ_ใฎ่กŒไบŒ่กŒ็›ฎ";
  2572. Application.Top.Redraw (Application.Top.Bounds);
  2573. Assert.True (horizontalView.AutoSize);
  2574. Assert.True (verticalView.AutoSize);
  2575. // height was initialized with 8 and is kept as minimum
  2576. Assert.Equal (new Rect (0, 3, 2, 8), verticalView.Frame);
  2577. Assert.Equal ("Pos.Absolute(0)", verticalView.X.ToString ());
  2578. Assert.Equal ("Pos.Absolute(3)", verticalView.Y.ToString ());
  2579. Assert.Equal ("Dim.Absolute(2)", verticalView.Width.ToString ());
  2580. Assert.Equal ("Dim.Absolute(8)", verticalView.Height.ToString ());
  2581. expected = @"
  2582. โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  2583. โ”‚Finish ็ต‚ โ”‚
  2584. โ”‚ โ”‚
  2585. โ”‚ โ”‚
  2586. โ”‚ๆœ€ โ”‚
  2587. โ”‚ๅˆ โ”‚
  2588. โ”‚ใฎ โ”‚
  2589. โ”‚่กŒ โ”‚
  2590. โ”‚ไบŒ โ”‚
  2591. โ”‚่กŒ โ”‚
  2592. โ”‚็›ฎ โ”‚
  2593. โ”‚ โ”‚
  2594. โ”‚ โ”‚
  2595. โ”‚ โ”‚
  2596. โ”‚ โ”‚
  2597. โ”‚ โ”‚
  2598. โ”‚ โ”‚
  2599. โ”‚ โ”‚
  2600. โ”‚ โ”‚
  2601. โ”‚ โ”‚
  2602. โ”‚ โ”‚
  2603. โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
  2604. ";
  2605. pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
  2606. Assert.Equal (new Rect (0, 0, 22, 22), pos);
  2607. }
  2608. [Fact, AutoInitShutdown]
  2609. public void AutoSize_Stays_True_Center_HotKeySpecifier ()
  2610. {
  2611. var btn = new Button () {
  2612. X = Pos.Center (),
  2613. Y = Pos.Center (),
  2614. Text = "Say He_llo ไฝ "
  2615. };
  2616. var win = new Window () {
  2617. Width = Dim.Fill (),
  2618. Height = Dim.Fill (),
  2619. Title = "Test Demo ไฝ "
  2620. };
  2621. win.Add (btn);
  2622. Application.Top.Add (win);
  2623. Assert.True (btn.AutoSize);
  2624. Application.Begin (Application.Top);
  2625. ((FakeDriver)Application.Driver).SetBufferSize (30, 5);
  2626. var expected = @"
  2627. โ”Œ Test Demo ไฝ  โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  2628. โ”‚ โ”‚
  2629. โ”‚ [ Say Hello ไฝ  ] โ”‚
  2630. โ”‚ โ”‚
  2631. โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
  2632. ";
  2633. GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
  2634. Assert.True (btn.AutoSize);
  2635. btn.Text = "Say He_llo ไฝ  changed";
  2636. Assert.True (btn.AutoSize);
  2637. Application.Refresh ();
  2638. expected = @"
  2639. โ”Œ Test Demo ไฝ  โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  2640. โ”‚ โ”‚
  2641. โ”‚ [ Say Hello ไฝ  changed ] โ”‚
  2642. โ”‚ โ”‚
  2643. โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
  2644. ";
  2645. GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
  2646. }
  2647. [Fact]
  2648. public void GetTextFormatterBoundsSize_GetBoundsTextFormatterSize_HotKeySpecifier ()
  2649. {
  2650. var text = "Say Hello ไฝ ";
  2651. var horizontalView = new View () { Text = text, AutoSize = true, HotKeySpecifier = '_' };
  2652. var verticalView = new View () {
  2653. Text = text,
  2654. AutoSize = true,
  2655. HotKeySpecifier = '_',
  2656. TextDirection = TextDirection.TopBottom_LeftRight
  2657. };
  2658. Assert.True (horizontalView.AutoSize);
  2659. Assert.Equal (new Rect (0, 0, 12, 1), horizontalView.Frame);
  2660. Assert.Equal (new Size (12, 1), horizontalView.GetTextFormatterBoundsSize ());
  2661. Assert.Equal (new Size (12, 1), horizontalView.GetBoundsTextFormatterSize ());
  2662. Assert.Equal (horizontalView.TextFormatter.Size, horizontalView.GetBoundsTextFormatterSize ());
  2663. Assert.Equal (horizontalView.Frame.Size, horizontalView.GetTextFormatterBoundsSize ());
  2664. Assert.True (verticalView.AutoSize);
  2665. Assert.Equal (new Rect (0, 0, 2, 11), verticalView.Frame);
  2666. Assert.Equal (new Size (2, 11), verticalView.GetTextFormatterBoundsSize ());
  2667. Assert.Equal (new Size (2, 11), verticalView.GetBoundsTextFormatterSize ());
  2668. Assert.Equal (verticalView.TextFormatter.Size, verticalView.GetBoundsTextFormatterSize ());
  2669. Assert.Equal (verticalView.Frame.Size, verticalView.GetTextFormatterBoundsSize ());
  2670. text = "Say He_llo ไฝ ";
  2671. horizontalView.Text = text;
  2672. verticalView.Text = text;
  2673. Assert.True (horizontalView.AutoSize);
  2674. Assert.Equal (new Rect (0, 0, 12, 1), horizontalView.Frame);
  2675. Assert.Equal (new Size (12, 1), horizontalView.GetTextFormatterBoundsSize ());
  2676. Assert.Equal (new Size (13, 1), horizontalView.GetBoundsTextFormatterSize ());
  2677. Assert.Equal (horizontalView.TextFormatter.Size, horizontalView.GetBoundsTextFormatterSize ());
  2678. Assert.Equal (horizontalView.Frame.Size, horizontalView.GetTextFormatterBoundsSize ());
  2679. Assert.True (verticalView.AutoSize);
  2680. Assert.Equal (new Rect (0, 0, 2, 11), verticalView.Frame);
  2681. Assert.Equal (new Size (2, 11), verticalView.GetTextFormatterBoundsSize ());
  2682. Assert.Equal (new Size (2, 12), verticalView.GetBoundsTextFormatterSize ());
  2683. Assert.Equal (verticalView.TextFormatter.Size, verticalView.GetBoundsTextFormatterSize ());
  2684. Assert.Equal (verticalView.Frame.Size, verticalView.GetTextFormatterBoundsSize ());
  2685. }
  2686. [Fact, AutoInitShutdown]
  2687. public void AutoSize_False_Equal_Before_And_After_IsInitialized_With_Differents_Orders ()
  2688. {
  2689. var view1 = new View () { Text = "Say Hello view1 ไฝ ", AutoSize = false, Width = 10, Height = 5 };
  2690. var view2 = new View () { Text = "Say Hello view2 ไฝ ", Width = 10, Height = 5, AutoSize = false };
  2691. var view3 = new View () { AutoSize = false, Width = 10, Height = 5, Text = "Say Hello view3 ไฝ " };
  2692. var view4 = new View () {
  2693. Text = "Say Hello view4 ไฝ ",
  2694. AutoSize = false,
  2695. Width = 10,
  2696. Height = 5,
  2697. TextDirection = TextDirection.TopBottom_LeftRight
  2698. };
  2699. var view5 = new View () {
  2700. Text = "Say Hello view5 ไฝ ",
  2701. Width = 10,
  2702. Height = 5,
  2703. AutoSize = false,
  2704. TextDirection = TextDirection.TopBottom_LeftRight
  2705. };
  2706. var view6 = new View () {
  2707. AutoSize = false,
  2708. Width = 10,
  2709. Height = 5,
  2710. TextDirection = TextDirection.TopBottom_LeftRight,
  2711. Text = "Say Hello view6 ไฝ ",
  2712. };
  2713. Application.Top.Add (view1, view2, view3, view4, view5, view6);
  2714. Assert.False (view1.IsInitialized);
  2715. Assert.False (view2.IsInitialized);
  2716. Assert.False (view3.IsInitialized);
  2717. Assert.False (view4.IsInitialized);
  2718. Assert.False (view5.IsInitialized);
  2719. Assert.False (view1.AutoSize);
  2720. Assert.Equal (new Rect (0, 0, 10, 5), view1.Frame);
  2721. Assert.Equal ("Dim.Absolute(10)", view1.Width.ToString ());
  2722. Assert.Equal ("Dim.Absolute(5)", view1.Height.ToString ());
  2723. Assert.False (view2.AutoSize);
  2724. Assert.Equal (new Rect (0, 0, 10, 5), view2.Frame);
  2725. Assert.Equal ("Dim.Absolute(10)", view2.Width.ToString ());
  2726. Assert.Equal ("Dim.Absolute(5)", view2.Height.ToString ());
  2727. Assert.False (view3.AutoSize);
  2728. Assert.Equal (new Rect (0, 0, 10, 5), view3.Frame);
  2729. Assert.Equal ("Dim.Absolute(10)", view3.Width.ToString ());
  2730. Assert.Equal ("Dim.Absolute(5)", view3.Height.ToString ());
  2731. Assert.False (view4.AutoSize);
  2732. Assert.Equal (new Rect (0, 0, 10, 5), view4.Frame);
  2733. Assert.Equal ("Dim.Absolute(10)", view4.Width.ToString ());
  2734. Assert.Equal ("Dim.Absolute(5)", view4.Height.ToString ());
  2735. Assert.False (view5.AutoSize);
  2736. Assert.Equal (new Rect (0, 0, 10, 5), view5.Frame);
  2737. Assert.Equal ("Dim.Absolute(10)", view5.Width.ToString ());
  2738. Assert.Equal ("Dim.Absolute(5)", view5.Height.ToString ());
  2739. Assert.False (view6.AutoSize);
  2740. Assert.Equal (new Rect (0, 0, 10, 5), view6.Frame);
  2741. Assert.Equal ("Dim.Absolute(10)", view6.Width.ToString ());
  2742. Assert.Equal ("Dim.Absolute(5)", view6.Height.ToString ());
  2743. Application.Begin (Application.Top);
  2744. Assert.True (view1.IsInitialized);
  2745. Assert.True (view2.IsInitialized);
  2746. Assert.True (view3.IsInitialized);
  2747. Assert.True (view4.IsInitialized);
  2748. Assert.True (view5.IsInitialized);
  2749. Assert.False (view1.AutoSize);
  2750. Assert.Equal (new Rect (0, 0, 10, 5), view1.Frame);
  2751. Assert.Equal ("Dim.Absolute(10)", view1.Width.ToString ());
  2752. Assert.Equal ("Dim.Absolute(5)", view1.Height.ToString ());
  2753. Assert.False (view2.AutoSize);
  2754. Assert.Equal (new Rect (0, 0, 10, 5), view2.Frame);
  2755. Assert.Equal ("Dim.Absolute(10)", view2.Width.ToString ());
  2756. Assert.Equal ("Dim.Absolute(5)", view2.Height.ToString ());
  2757. Assert.False (view3.AutoSize);
  2758. Assert.Equal (new Rect (0, 0, 10, 5), view3.Frame);
  2759. Assert.Equal ("Dim.Absolute(10)", view3.Width.ToString ());
  2760. Assert.Equal ("Dim.Absolute(5)", view3.Height.ToString ());
  2761. Assert.False (view4.AutoSize);
  2762. Assert.Equal (new Rect (0, 0, 10, 5), view4.Frame);
  2763. Assert.Equal ("Dim.Absolute(10)", view4.Width.ToString ());
  2764. Assert.Equal ("Dim.Absolute(5)", view4.Height.ToString ());
  2765. Assert.False (view5.AutoSize);
  2766. Assert.Equal (new Rect (0, 0, 10, 5), view5.Frame);
  2767. Assert.Equal ("Dim.Absolute(10)", view5.Width.ToString ());
  2768. Assert.Equal ("Dim.Absolute(5)", view5.Height.ToString ());
  2769. Assert.False (view6.AutoSize);
  2770. Assert.Equal (new Rect (0, 0, 10, 5), view6.Frame);
  2771. Assert.Equal ("Dim.Absolute(10)", view6.Width.ToString ());
  2772. Assert.Equal ("Dim.Absolute(5)", view6.Height.ToString ());
  2773. }
  2774. [Fact, AutoInitShutdown]
  2775. public void AutoSize_True_Equal_Before_And_After_IsInitialized_With_Differents_Orders ()
  2776. {
  2777. var view1 = new View () { Text = "Say Hello view1 ไฝ ", AutoSize = true, Width = 10, Height = 5 };
  2778. var view2 = new View () { Text = "Say Hello view2 ไฝ ", Width = 10, Height = 5, AutoSize = true };
  2779. var view3 = new View () { AutoSize = true, Width = 10, Height = 5, Text = "Say Hello view3 ไฝ " };
  2780. var view4 = new View () {
  2781. Text = "Say Hello view4 ไฝ ",
  2782. AutoSize = true,
  2783. Width = 10,
  2784. Height = 5,
  2785. TextDirection = TextDirection.TopBottom_LeftRight
  2786. };
  2787. var view5 = new View () {
  2788. Text = "Say Hello view5 ไฝ ",
  2789. Width = 10,
  2790. Height = 5,
  2791. AutoSize = true,
  2792. TextDirection = TextDirection.TopBottom_LeftRight
  2793. };
  2794. var view6 = new View () {
  2795. AutoSize = true,
  2796. Width = 10,
  2797. Height = 5,
  2798. TextDirection = TextDirection.TopBottom_LeftRight,
  2799. Text = "Say Hello view6 ไฝ ",
  2800. };
  2801. Application.Top.Add (view1, view2, view3, view4, view5, view6);
  2802. Assert.False (view1.IsInitialized);
  2803. Assert.False (view2.IsInitialized);
  2804. Assert.False (view3.IsInitialized);
  2805. Assert.False (view4.IsInitialized);
  2806. Assert.False (view5.IsInitialized);
  2807. Assert.True (view1.AutoSize);
  2808. Assert.Equal (new Rect (0, 0, 18, 5), view1.Frame);
  2809. Assert.Equal ("Dim.Absolute(10)", view1.Width.ToString ());
  2810. Assert.Equal ("Dim.Absolute(5)", view1.Height.ToString ());
  2811. Assert.True (view2.AutoSize);
  2812. Assert.Equal (new Rect (0, 0, 18, 5), view2.Frame);
  2813. Assert.Equal ("Dim.Absolute(10)", view2.Width.ToString ());
  2814. Assert.Equal ("Dim.Absolute(5)", view2.Height.ToString ());
  2815. Assert.True (view3.AutoSize);
  2816. Assert.Equal (new Rect (0, 0, 18, 5), view3.Frame);
  2817. Assert.Equal ("Dim.Absolute(10)", view3.Width.ToString ());
  2818. Assert.Equal ("Dim.Absolute(5)", view3.Height.ToString ());
  2819. Assert.True (view4.AutoSize);
  2820. Assert.Equal (new Rect (0, 0, 10, 17), view4.Frame);
  2821. Assert.Equal ("Dim.Absolute(10)", view4.Width.ToString ());
  2822. Assert.Equal ("Dim.Absolute(5)", view4.Height.ToString ());
  2823. Assert.True (view5.AutoSize);
  2824. Assert.Equal (new Rect (0, 0, 10, 17), view5.Frame);
  2825. Assert.Equal ("Dim.Absolute(10)", view5.Width.ToString ());
  2826. Assert.Equal ("Dim.Absolute(5)", view5.Height.ToString ());
  2827. Assert.True (view6.AutoSize);
  2828. Assert.Equal (new Rect (0, 0, 10, 17), view6.Frame);
  2829. Assert.Equal ("Dim.Absolute(10)", view6.Width.ToString ());
  2830. Assert.Equal ("Dim.Absolute(5)", view6.Height.ToString ());
  2831. Application.Begin (Application.Top);
  2832. Assert.True (view1.IsInitialized);
  2833. Assert.True (view2.IsInitialized);
  2834. Assert.True (view3.IsInitialized);
  2835. Assert.True (view4.IsInitialized);
  2836. Assert.True (view5.IsInitialized);
  2837. Assert.True (view1.AutoSize);
  2838. Assert.Equal (new Rect (0, 0, 18, 5), view1.Frame);
  2839. Assert.Equal ("Dim.Absolute(10)", view1.Width.ToString ());
  2840. Assert.Equal ("Dim.Absolute(5)", view1.Height.ToString ());
  2841. Assert.True (view2.AutoSize);
  2842. Assert.Equal (new Rect (0, 0, 18, 5), view2.Frame);
  2843. Assert.Equal ("Dim.Absolute(10)", view2.Width.ToString ());
  2844. Assert.Equal ("Dim.Absolute(5)", view2.Height.ToString ());
  2845. Assert.True (view3.AutoSize);
  2846. Assert.Equal (new Rect (0, 0, 18, 5), view3.Frame);
  2847. Assert.Equal ("Dim.Absolute(10)", view3.Width.ToString ());
  2848. Assert.Equal ("Dim.Absolute(5)", view3.Height.ToString ());
  2849. Assert.True (view4.AutoSize);
  2850. Assert.Equal (new Rect (0, 0, 10, 17), view4.Frame);
  2851. Assert.Equal ("Dim.Absolute(10)", view4.Width.ToString ());
  2852. Assert.Equal ("Dim.Absolute(5)", view4.Height.ToString ());
  2853. Assert.True (view5.AutoSize);
  2854. Assert.Equal (new Rect (0, 0, 10, 17), view5.Frame);
  2855. Assert.Equal ("Dim.Absolute(10)", view5.Width.ToString ());
  2856. Assert.Equal ("Dim.Absolute(5)", view5.Height.ToString ());
  2857. Assert.True (view6.AutoSize);
  2858. Assert.Equal (new Rect (0, 0, 10, 17), view6.Frame);
  2859. Assert.Equal ("Dim.Absolute(10)", view6.Width.ToString ());
  2860. Assert.Equal ("Dim.Absolute(5)", view6.Height.ToString ());
  2861. }
  2862. [Fact, AutoInitShutdown]
  2863. public void Setting_Frame_Dont_Respect_AutoSize_True_On_Layout_Absolute ()
  2864. {
  2865. var view1 = new View (new Rect (0, 0, 10, 0)) { Text = "Say Hello view1 ไฝ ", AutoSize = true };
  2866. var view2 = new View (new Rect (0, 0, 0, 10)) {
  2867. Text = "Say Hello view2 ไฝ ",
  2868. AutoSize = true,
  2869. TextDirection = TextDirection.TopBottom_LeftRight
  2870. };
  2871. Application.Top.Add (view1, view2);
  2872. var rs = Application.Begin (Application.Top);
  2873. Assert.True (view1.AutoSize);
  2874. Assert.Equal (LayoutStyle.Absolute, view1.LayoutStyle);
  2875. Assert.Equal (new Rect (0, 0, 18, 1), view1.Frame);
  2876. Assert.Equal ("Pos.Absolute(0)", view1.X.ToString ());
  2877. Assert.Equal ("Pos.Absolute(0)", view1.Y.ToString ());
  2878. Assert.Equal ("Dim.Absolute(18)", view1.Width.ToString ());
  2879. Assert.Equal ("Dim.Absolute(1)", view1.Height.ToString ());
  2880. Assert.True (view2.AutoSize);
  2881. Assert.Equal (LayoutStyle.Absolute, view2.LayoutStyle);
  2882. Assert.Equal (new Rect (0, 0, 2, 17), view2.Frame);
  2883. Assert.Equal ("Pos.Absolute(0)", view2.X.ToString ());
  2884. Assert.Equal ("Pos.Absolute(0)", view2.Y.ToString ());
  2885. Assert.Equal ("Dim.Absolute(2)", view2.Width.ToString ());
  2886. Assert.Equal ("Dim.Absolute(17)", view2.Height.ToString ());
  2887. view1.Frame = new Rect (0, 0, 25, 4);
  2888. bool firstIteration = false;
  2889. Application.RunMainLoopIteration (ref rs, true, ref firstIteration);
  2890. Assert.True (view1.AutoSize);
  2891. Assert.Equal (LayoutStyle.Absolute, view1.LayoutStyle);
  2892. Assert.Equal (new Rect (0, 0, 25, 4), view1.Frame);
  2893. Assert.Equal ("Pos.Absolute(0)", view1.X.ToString ());
  2894. Assert.Equal ("Pos.Absolute(0)", view1.Y.ToString ());
  2895. Assert.Equal ("Dim.Absolute(18)", view1.Width.ToString ());
  2896. Assert.Equal ("Dim.Absolute(1)", view1.Height.ToString ());
  2897. view2.Frame = new Rect (0, 0, 1, 25);
  2898. Application.RunMainLoopIteration (ref rs, true, ref firstIteration);
  2899. Assert.True (view2.AutoSize);
  2900. Assert.Equal (LayoutStyle.Absolute, view2.LayoutStyle);
  2901. Assert.Equal (new Rect (0, 0, 1, 25), view2.Frame);
  2902. Assert.Equal ("Pos.Absolute(0)", view2.X.ToString ());
  2903. Assert.Equal ("Pos.Absolute(0)", view2.Y.ToString ());
  2904. Assert.Equal ("Dim.Absolute(2)", view2.Width.ToString ());
  2905. Assert.Equal ("Dim.Absolute(17)", view2.Height.ToString ());
  2906. }
  2907. [Fact, AutoInitShutdown]
  2908. public void Pos_Dim_Are_Null_If_Not_Initialized_On_Constructor_IsAdded_False ()
  2909. {
  2910. var top = Application.Top;
  2911. var view1 = new View ();
  2912. Assert.False (view1.IsAdded);
  2913. Assert.Null (view1.X);
  2914. Assert.Null (view1.Y);
  2915. Assert.Null (view1.Width);
  2916. Assert.Null (view1.Height);
  2917. top.Add (view1);
  2918. Assert.True (view1.IsAdded);
  2919. Assert.Equal ("Pos.Absolute(0)", view1.X.ToString ());
  2920. Assert.Equal ("Pos.Absolute(0)", view1.Y.ToString ());
  2921. Assert.Equal ("Dim.Absolute(0)", view1.Width.ToString ());
  2922. Assert.Equal ("Dim.Absolute(0)", view1.Height.ToString ());
  2923. var view2 = new View () {
  2924. X = Pos.Center (),
  2925. Y = Pos.Center (),
  2926. Width = Dim.Fill (),
  2927. Height = Dim.Fill ()
  2928. };
  2929. Assert.False (view2.IsAdded);
  2930. Assert.Equal ("Pos.Center", view2.X.ToString ());
  2931. Assert.Equal ("Pos.Center", view2.Y.ToString ());
  2932. Assert.Equal ("Dim.Fill(margin=0)", view2.Width.ToString ());
  2933. Assert.Equal ("Dim.Fill(margin=0)", view2.Height.ToString ());
  2934. top.Add (view2);
  2935. Assert.True (view2.IsAdded);
  2936. Assert.Equal ("Pos.Center", view2.X.ToString ());
  2937. Assert.Equal ("Pos.Center", view2.Y.ToString ());
  2938. Assert.Equal ("Dim.Fill(margin=0)", view2.Width.ToString ());
  2939. Assert.Equal ("Dim.Fill(margin=0)", view2.Height.ToString ());
  2940. }
  2941. [Fact]
  2942. public void IsAdded_Added_Removed ()
  2943. {
  2944. var top = new Toplevel ();
  2945. var view = new View ();
  2946. Assert.False (view.IsAdded);
  2947. top.Add (view);
  2948. Assert.True (view.IsAdded);
  2949. top.Remove (view);
  2950. Assert.False (view.IsAdded);
  2951. }
  2952. [Fact]
  2953. public void AutoSize_Layout_Absolute_Without_Add_Horizontal_Narrow ()
  2954. {
  2955. var view = new View (new Rect (0, 0, 10, 1)) {
  2956. Text = "Test"
  2957. };
  2958. Assert.False (view.IsAdded);
  2959. Assert.False (view.AutoSize);
  2960. Assert.Equal (new Rect (0, 0, 10, 1), view.Frame);
  2961. Assert.Equal ("Test", view.TextFormatter.Text);
  2962. view.Text = "First line\nSecond line";
  2963. Assert.False (view.AutoSize);
  2964. Assert.Equal (new Rect (0, 0, 10, 1), view.Frame);
  2965. Assert.Equal ("First line\nSecond line", view.TextFormatter.Text);
  2966. view.AutoSize = true;
  2967. Assert.True (view.AutoSize);
  2968. Assert.Equal (new Rect (0, 0, 11, 2), view.Frame);
  2969. Assert.Equal ("First line\nSecond line", view.TextFormatter.Text);
  2970. view.AutoSize = false;
  2971. Assert.False (view.AutoSize);
  2972. Assert.Equal (new Rect (0, 0, 11, 2), view.Frame);
  2973. Assert.Equal ("First line\nSecond line", view.TextFormatter.Text);
  2974. }
  2975. [Fact, AutoInitShutdown]
  2976. public void AutoSize_Layout_Absolute_With_Add_Horizontal_Narrow ()
  2977. {
  2978. var view = new View (new Rect (0, 0, 10, 1)) {
  2979. Text = "Test"
  2980. };
  2981. Application.Top.Add (view);
  2982. Application.Begin (Application.Top);
  2983. Assert.True (view.IsAdded);
  2984. Assert.False (view.AutoSize);
  2985. Assert.Equal (new Rect (0, 0, 10, 1), view.Frame);
  2986. Assert.Equal ("Test", view.TextFormatter.Text);
  2987. GraphViewTests.AssertDriverContentsWithFrameAre (@"
  2988. Test
  2989. ", output);
  2990. view.Text = "First line\nSecond line";
  2991. Assert.False (view.AutoSize);
  2992. Assert.Equal (new Rect (0, 0, 10, 1), view.Frame);
  2993. Assert.Equal ("First line\nSecond line", view.TextFormatter.Text);
  2994. Application.Refresh ();
  2995. GraphViewTests.AssertDriverContentsWithFrameAre (@"
  2996. First line
  2997. ", output);
  2998. view.AutoSize = true;
  2999. Assert.True (view.AutoSize);
  3000. Assert.Equal (new Rect (0, 0, 11, 2), view.Frame);
  3001. Assert.Equal ("First line\nSecond line", view.TextFormatter.Text);
  3002. Application.Refresh ();
  3003. GraphViewTests.AssertDriverContentsWithFrameAre (@"
  3004. First line
  3005. Second line
  3006. ", output);
  3007. view.AutoSize = false;
  3008. Assert.False (view.AutoSize);
  3009. Assert.Equal (new Rect (0, 0, 10, 1), view.Frame);
  3010. Assert.Equal ("First line\nSecond line", view.TextFormatter.Text);
  3011. Application.Refresh ();
  3012. GraphViewTests.AssertDriverContentsWithFrameAre (@"
  3013. First line
  3014. ", output);
  3015. }
  3016. [Fact]
  3017. public void AutoSize_Layout_Absolute_Without_Add_Vertical_Narrow ()
  3018. {
  3019. var view = new View (new Rect (0, 0, 1, 10)) {
  3020. Text = "Test",
  3021. TextDirection = TextDirection.TopBottom_LeftRight
  3022. };
  3023. Assert.False (view.IsAdded);
  3024. Assert.False (view.AutoSize);
  3025. Assert.Equal (new Rect (0, 0, 1, 10), view.Frame);
  3026. Assert.Equal ("Test", view.TextFormatter.Text);
  3027. view.Text = "First line\nSecond line";
  3028. Assert.False (view.AutoSize);
  3029. Assert.Equal (new Rect (0, 0, 1, 10), view.Frame);
  3030. Assert.Equal ("First line\nSecond line", view.TextFormatter.Text);
  3031. view.AutoSize = true;
  3032. Assert.True (view.AutoSize);
  3033. Assert.Equal (new Rect (0, 0, 2, 11), view.Frame);
  3034. Assert.Equal ("First line\nSecond line", view.TextFormatter.Text);
  3035. view.AutoSize = false;
  3036. Assert.False (view.AutoSize);
  3037. Assert.Equal (new Rect (0, 0, 2, 11), view.Frame);
  3038. Assert.Equal ("First line\nSecond line", view.TextFormatter.Text);
  3039. }
  3040. [Fact, AutoInitShutdown]
  3041. public void AutoSize_Layout_Absolute_With_Add_Vertical_Narrow ()
  3042. {
  3043. var view = new View (new Rect (0, 0, 1, 10)) {
  3044. Text = "Test",
  3045. TextDirection = TextDirection.TopBottom_LeftRight
  3046. };
  3047. Application.Top.Add (view);
  3048. Application.Begin (Application.Top);
  3049. Assert.True (view.IsAdded);
  3050. Assert.False (view.AutoSize);
  3051. Assert.Equal (new Rect (0, 0, 1, 10), view.Frame);
  3052. Assert.Equal ("Test", view.TextFormatter.Text);
  3053. GraphViewTests.AssertDriverContentsWithFrameAre (@"
  3054. T
  3055. e
  3056. s
  3057. t
  3058. ", output);
  3059. view.Text = "First line\nSecond line";
  3060. Assert.False (view.AutoSize);
  3061. Assert.Equal (new Rect (0, 0, 1, 10), view.Frame);
  3062. Assert.Equal ("First line\nSecond line", view.TextFormatter.Text);
  3063. Application.Refresh ();
  3064. GraphViewTests.AssertDriverContentsWithFrameAre (@"
  3065. F
  3066. i
  3067. r
  3068. s
  3069. t
  3070. l
  3071. i
  3072. n
  3073. e
  3074. ", output);
  3075. view.AutoSize = true;
  3076. Assert.True (view.AutoSize);
  3077. Assert.Equal (new Rect (0, 0, 2, 11), view.Frame);
  3078. Assert.Equal ("First line\nSecond line", view.TextFormatter.Text);
  3079. Application.Refresh ();
  3080. GraphViewTests.AssertDriverContentsWithFrameAre (@"
  3081. FS
  3082. ie
  3083. rc
  3084. so
  3085. tn
  3086. d
  3087. l
  3088. il
  3089. ni
  3090. en
  3091. e
  3092. ", output);
  3093. view.AutoSize = false;
  3094. Assert.False (view.AutoSize);
  3095. Assert.Equal (new Rect (0, 0, 1, 10), view.Frame);
  3096. Assert.Equal ("First line\nSecond line", view.TextFormatter.Text);
  3097. Application.Refresh ();
  3098. GraphViewTests.AssertDriverContentsWithFrameAre (@"
  3099. F
  3100. i
  3101. r
  3102. s
  3103. t
  3104. l
  3105. i
  3106. n
  3107. e
  3108. ", output);
  3109. }
  3110. [Fact]
  3111. public void AutoSize_Layout_Absolute_Without_Add_Horizontal_Wide ()
  3112. {
  3113. var view = new View (new Rect (0, 0, 10, 1)) {
  3114. Text = "Test ไฝ "
  3115. };
  3116. Assert.False (view.IsAdded);
  3117. Assert.False (view.AutoSize);
  3118. Assert.Equal (new Rect (0, 0, 10, 1), view.Frame);
  3119. Assert.Equal ("Test ไฝ ", view.TextFormatter.Text);
  3120. view.Text = "First line ไฝ \nSecond line ไฝ ";
  3121. Assert.False (view.AutoSize);
  3122. Assert.Equal (new Rect (0, 0, 10, 1), view.Frame);
  3123. Assert.Equal ("First line ไฝ \nSecond line ไฝ ", view.TextFormatter.Text);
  3124. view.AutoSize = true;
  3125. Assert.True (view.AutoSize);
  3126. Assert.Equal (new Rect (0, 0, 14, 2), view.Frame);
  3127. Assert.Equal ("First line ไฝ \nSecond line ไฝ ", view.TextFormatter.Text);
  3128. view.AutoSize = false;
  3129. Assert.False (view.AutoSize);
  3130. Assert.Equal (new Rect (0, 0, 14, 2), view.Frame);
  3131. Assert.Equal ("First line ไฝ \nSecond line ไฝ ", view.TextFormatter.Text);
  3132. }
  3133. [Fact, AutoInitShutdown]
  3134. public void AutoSize_Layout_Absolute_With_Add_Horizontal_Wide ()
  3135. {
  3136. var view = new View (new Rect (0, 0, 10, 1)) {
  3137. Text = "Test ไฝ "
  3138. };
  3139. Application.Top.Add (view);
  3140. Application.Begin (Application.Top);
  3141. Assert.True (view.IsAdded);
  3142. Assert.False (view.AutoSize);
  3143. Assert.Equal (new Rect (0, 0, 10, 1), view.Frame);
  3144. Assert.Equal ("Test ไฝ ", view.TextFormatter.Text);
  3145. GraphViewTests.AssertDriverContentsWithFrameAre (@"
  3146. Test ไฝ 
  3147. ", output);
  3148. view.Text = "First line ไฝ \nSecond line ไฝ ";
  3149. Assert.False (view.AutoSize);
  3150. Assert.Equal (new Rect (0, 0, 10, 1), view.Frame);
  3151. Assert.Equal ("First line ไฝ \nSecond line ไฝ ", view.TextFormatter.Text);
  3152. Application.Refresh ();
  3153. GraphViewTests.AssertDriverContentsWithFrameAre (@"
  3154. First line
  3155. ", output);
  3156. view.AutoSize = true;
  3157. Assert.True (view.AutoSize);
  3158. Assert.Equal (new Rect (0, 0, 14, 2), view.Frame);
  3159. Assert.Equal ("First line ไฝ \nSecond line ไฝ ", view.TextFormatter.Text);
  3160. Application.Refresh ();
  3161. GraphViewTests.AssertDriverContentsWithFrameAre (@"
  3162. First line ไฝ 
  3163. Second line ไฝ 
  3164. ", output);
  3165. view.AutoSize = false;
  3166. Assert.False (view.AutoSize);
  3167. Assert.Equal (new Rect (0, 0, 10, 1), view.Frame);
  3168. Assert.Equal ("First line ไฝ \nSecond line ไฝ ", view.TextFormatter.Text);
  3169. Application.Refresh ();
  3170. GraphViewTests.AssertDriverContentsWithFrameAre (@"
  3171. First line
  3172. ", output);
  3173. }
  3174. [Fact]
  3175. public void AutoSize_Layout_Absolute_Without_Add_Vertical_Wide ()
  3176. {
  3177. var view = new View (new Rect (0, 0, 1, 10)) {
  3178. Text = "Test ไฝ ",
  3179. TextDirection = TextDirection.TopBottom_LeftRight
  3180. };
  3181. Assert.False (view.IsAdded);
  3182. Assert.False (view.AutoSize);
  3183. // SetMinWidthHeight ensuring the minimum width for the wide char
  3184. Assert.Equal (new Rect (0, 0, 2, 10), view.Frame);
  3185. Assert.Equal ("Test ไฝ ", view.TextFormatter.Text);
  3186. view.Text = "First line ไฝ \nSecond line ไฝ ";
  3187. Assert.False (view.AutoSize);
  3188. Assert.Equal (new Rect (0, 0, 2, 10), view.Frame);
  3189. Assert.Equal ("First line ไฝ \nSecond line ไฝ ", view.TextFormatter.Text);
  3190. view.AutoSize = true;
  3191. Assert.True (view.AutoSize);
  3192. Assert.Equal (new Rect (0, 0, 4, 13), view.Frame);
  3193. Assert.Equal ("First line ไฝ \nSecond line ไฝ ", view.TextFormatter.Text);
  3194. view.AutoSize = false;
  3195. Assert.False (view.AutoSize);
  3196. Assert.Equal (new Rect (0, 0, 4, 13), view.Frame);
  3197. Assert.Equal ("First line ไฝ \nSecond line ไฝ ", view.TextFormatter.Text);
  3198. }
  3199. [Fact, AutoInitShutdown]
  3200. public void AutoSize_Layout_Absolute_With_Add_Vertical_Wide ()
  3201. {
  3202. var view = new View (new Rect (0, 0, 1, 10)) {
  3203. Text = "Test ไฝ ",
  3204. TextDirection = TextDirection.TopBottom_LeftRight
  3205. };
  3206. Application.Top.Add (view);
  3207. Application.Begin (Application.Top);
  3208. Assert.True (view.IsAdded);
  3209. Assert.False (view.AutoSize);
  3210. // SetMinWidthHeight ensuring the minimum width for the wide char
  3211. Assert.Equal (new Rect (0, 0, 2, 10), view.Frame);
  3212. Assert.Equal ("Test ไฝ ", view.TextFormatter.Text);
  3213. GraphViewTests.AssertDriverContentsWithFrameAre (@"
  3214. T
  3215. e
  3216. s
  3217. t
  3218. ไฝ 
  3219. ", output);
  3220. view.Text = "First line ไฝ \nSecond line ไฝ ";
  3221. Assert.False (view.AutoSize);
  3222. Assert.Equal (new Rect (0, 0, 2, 10), view.Frame);
  3223. Assert.Equal ("First line ไฝ \nSecond line ไฝ ", view.TextFormatter.Text);
  3224. Application.Refresh ();
  3225. GraphViewTests.AssertDriverContentsWithFrameAre (@"
  3226. F
  3227. i
  3228. r
  3229. s
  3230. t
  3231. l
  3232. i
  3233. n
  3234. e
  3235. ", output);
  3236. view.AutoSize = true;
  3237. Assert.True (view.AutoSize);
  3238. Assert.Equal (new Rect (0, 0, 4, 13), view.Frame);
  3239. Assert.Equal ("First line ไฝ \nSecond line ไฝ ", view.TextFormatter.Text);
  3240. Application.Refresh ();
  3241. GraphViewTests.AssertDriverContentsWithFrameAre (@"
  3242. F S
  3243. i e
  3244. r c
  3245. s o
  3246. t n
  3247. d
  3248. l
  3249. i l
  3250. n i
  3251. e n
  3252. e
  3253. ไฝ 
  3254. ไฝ 
  3255. ", output);
  3256. view.AutoSize = false;
  3257. Assert.False (view.AutoSize);
  3258. Assert.Equal (new Rect (0, 0, 2, 10), view.Frame);
  3259. Assert.Equal ("First line ไฝ \nSecond line ไฝ ", view.TextFormatter.Text);
  3260. Application.Refresh ();
  3261. GraphViewTests.AssertDriverContentsWithFrameAre (@"
  3262. F
  3263. i
  3264. r
  3265. s
  3266. t
  3267. l
  3268. i
  3269. n
  3270. e
  3271. ", output);
  3272. }
  3273. [Fact, AutoInitShutdown]
  3274. public void Visible_Clear_The_View_Output ()
  3275. {
  3276. var label = new Label ("Testing visibility.");
  3277. var win = new Window ();
  3278. win.Add (label);
  3279. var top = Application.Top;
  3280. top.Add (win);
  3281. Application.Begin (top);
  3282. Assert.True (label.Visible);
  3283. ((FakeDriver)Application.Driver).SetBufferSize (30, 5);
  3284. GraphViewTests.AssertDriverContentsWithFrameAre (@"
  3285. โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  3286. โ”‚Testing visibility. โ”‚
  3287. โ”‚ โ”‚
  3288. โ”‚ โ”‚
  3289. โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
  3290. ", output);
  3291. label.Visible = false;
  3292. GraphViewTests.AssertDriverContentsWithFrameAre (@"
  3293. โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  3294. โ”‚ โ”‚
  3295. โ”‚ โ”‚
  3296. โ”‚ โ”‚
  3297. โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
  3298. ", output);
  3299. }
  3300. }
  3301. }