1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066 |
- using System;
- using Xunit;
- using Xunit.Abstractions;
- using GraphViewTests = Terminal.Gui.Views.GraphViewTests;
- // Alias Console to MockConsole so we don't accidentally use Console
- using Console = Terminal.Gui.FakeConsole;
- namespace Terminal.Gui.Core {
- public class ViewTests {
- readonly ITestOutputHelper output;
- public ViewTests (ITestOutputHelper output)
- {
- this.output = output;
- }
- [Fact]
- public void New_Initializes ()
- {
- // Parameterless
- var r = new View ();
- Assert.NotNull (r);
- Assert.Equal (LayoutStyle.Computed, r.LayoutStyle);
- Assert.Equal ("View()({X=0,Y=0,Width=0,Height=0})", r.ToString ());
- Assert.False (r.CanFocus);
- Assert.False (r.HasFocus);
- Assert.Equal (new Rect (0, 0, 0, 0), r.Bounds);
- Assert.Equal (new Rect (0, 0, 0, 0), r.Frame);
- Assert.Null (r.Focused);
- Assert.Null (r.ColorScheme);
- Assert.Null (r.Width);
- Assert.Null (r.Height);
- Assert.Null (r.X);
- Assert.Null (r.Y);
- Assert.False (r.IsCurrentTop);
- Assert.Empty (r.Id);
- Assert.Empty (r.Subviews);
- Assert.False (r.WantContinuousButtonPressed);
- Assert.False (r.WantMousePositionReports);
- Assert.Null (r.SuperView);
- Assert.Null (r.MostFocused);
- Assert.Equal (TextDirection.LeftRight_TopBottom, r.TextDirection);
- // Empty Rect
- r = new View (Rect.Empty);
- Assert.NotNull (r);
- Assert.Equal (LayoutStyle.Absolute, r.LayoutStyle);
- Assert.Equal ("View()({X=0,Y=0,Width=0,Height=0})", r.ToString ());
- Assert.False (r.CanFocus);
- Assert.False (r.HasFocus);
- Assert.Equal (new Rect (0, 0, 0, 0), r.Bounds);
- Assert.Equal (new Rect (0, 0, 0, 0), r.Frame);
- Assert.Null (r.Focused);
- Assert.Null (r.ColorScheme);
- Assert.Null (r.Width); // All view Dim are initialized now in the IsAdded setter,
- Assert.Null (r.Height); // avoiding Dim errors.
- Assert.Null (r.X); // All view Pos are initialized now in the IsAdded setter,
- Assert.Null (r.Y); // avoiding Pos errors.
- Assert.False (r.IsCurrentTop);
- Assert.Empty (r.Id);
- Assert.Empty (r.Subviews);
- Assert.False (r.WantContinuousButtonPressed);
- Assert.False (r.WantMousePositionReports);
- Assert.Null (r.SuperView);
- Assert.Null (r.MostFocused);
- Assert.Equal (TextDirection.LeftRight_TopBottom, r.TextDirection);
- // Rect with values
- r = new View (new Rect (1, 2, 3, 4));
- Assert.NotNull (r);
- Assert.Equal (LayoutStyle.Absolute, r.LayoutStyle);
- Assert.Equal ("View()({X=1,Y=2,Width=3,Height=4})", r.ToString ());
- Assert.False (r.CanFocus);
- Assert.False (r.HasFocus);
- Assert.Equal (new Rect (0, 0, 3, 4), r.Bounds);
- Assert.Equal (new Rect (1, 2, 3, 4), r.Frame);
- Assert.Null (r.Focused);
- Assert.Null (r.ColorScheme);
- Assert.Null (r.Width);
- Assert.Null (r.Height);
- Assert.Null (r.X);
- Assert.Null (r.Y);
- Assert.False (r.IsCurrentTop);
- Assert.Empty (r.Id);
- Assert.Empty (r.Subviews);
- Assert.False (r.WantContinuousButtonPressed);
- Assert.False (r.WantMousePositionReports);
- Assert.Null (r.SuperView);
- Assert.Null (r.MostFocused);
- Assert.Equal (TextDirection.LeftRight_TopBottom, r.TextDirection);
- // Initializes a view with a vertical direction
- r = new View ("Vertical View", TextDirection.TopBottom_LeftRight);
- Assert.NotNull (r);
- Assert.Equal (LayoutStyle.Computed, r.LayoutStyle);
- Assert.Equal ("View()({X=0,Y=0,Width=1,Height=13})", r.ToString ());
- Assert.False (r.CanFocus);
- Assert.False (r.HasFocus);
- Assert.Equal (new Rect (0, 0, 1, 13), r.Bounds);
- Assert.Equal (new Rect (0, 0, 1, 13), r.Frame);
- Assert.Null (r.Focused);
- Assert.Null (r.ColorScheme);
- Assert.Null (r.Width); // All view Dim are initialized now in the IsAdded setter,
- Assert.Null (r.Height); // avoiding Dim errors.
- Assert.Null (r.X); // All view Pos are initialized now in the IsAdded setter,
- Assert.Null (r.Y); // avoiding Pos errors.
- Assert.False (r.IsCurrentTop);
- Assert.Empty (r.Id);
- Assert.Empty (r.Subviews);
- Assert.False (r.WantContinuousButtonPressed);
- Assert.False (r.WantMousePositionReports);
- Assert.Null (r.SuperView);
- Assert.Null (r.MostFocused);
- Assert.Equal (TextDirection.TopBottom_LeftRight, r.TextDirection);
- }
- [Fact]
- public void New_Methods_Return_False ()
- {
- var r = new View ();
- Assert.False (r.ProcessKey (new KeyEvent () { Key = Key.Unknown }));
- Assert.False (r.ProcessHotKey (new KeyEvent () { Key = Key.Unknown }));
- Assert.False (r.ProcessColdKey (new KeyEvent () { Key = Key.Unknown }));
- Assert.False (r.OnKeyDown (new KeyEvent () { Key = Key.Unknown }));
- Assert.False (r.OnKeyUp (new KeyEvent () { Key = Key.Unknown }));
- Assert.False (r.MouseEvent (new MouseEvent () { Flags = MouseFlags.AllEvents }));
- Assert.False (r.OnMouseEnter (new MouseEvent () { Flags = MouseFlags.AllEvents }));
- Assert.False (r.OnMouseLeave (new MouseEvent () { Flags = MouseFlags.AllEvents }));
- Assert.False (r.OnEnter (new View ()));
- Assert.False (r.OnLeave (new View ()));
- // TODO: Add more
- }
- [Fact]
- public void TopologicalSort_Missing_Add ()
- {
- var root = new View ();
- var sub1 = new View ();
- root.Add (sub1);
- var sub2 = new View ();
- sub1.Width = Dim.Width (sub2);
- Assert.Throws<InvalidOperationException> (() => root.LayoutSubviews ());
- sub2.Width = Dim.Width (sub1);
- Assert.Throws<InvalidOperationException> (() => root.LayoutSubviews ());
- }
- [Fact]
- public void TopologicalSort_Recursive_Ref ()
- {
- var root = new View ();
- var sub1 = new View ();
- root.Add (sub1);
- var sub2 = new View ();
- root.Add (sub2);
- sub2.Width = Dim.Width (sub2);
- Assert.Throws<InvalidOperationException> (() => root.LayoutSubviews ());
- }
- [Fact]
- public void Added_Removed ()
- {
- var v = new View (new Rect (0, 0, 10, 24));
- var t = new View ();
- v.Added += (View e) => {
- Assert.True (v.SuperView == e);
- };
- v.Removed += (View e) => {
- Assert.True (v.SuperView == null);
- };
- t.Add (v);
- Assert.True (t.Subviews.Count == 1);
- t.Remove (v);
- Assert.True (t.Subviews.Count == 0);
- }
- [Fact]
- public void Subviews_TabIndexes_AreEqual ()
- {
- var r = new View ();
- var v1 = new View () { CanFocus = true };
- var v2 = new View () { CanFocus = true };
- var v3 = new View () { CanFocus = true };
- r.Add (v1, v2, v3);
- Assert.True (r.Subviews.IndexOf (v1) == 0);
- Assert.True (r.Subviews.IndexOf (v2) == 1);
- Assert.True (r.Subviews.IndexOf (v3) == 2);
- Assert.True (r.TabIndexes.IndexOf (v1) == 0);
- Assert.True (r.TabIndexes.IndexOf (v2) == 1);
- Assert.True (r.TabIndexes.IndexOf (v3) == 2);
- Assert.Equal (r.Subviews.IndexOf (v1), r.TabIndexes.IndexOf (v1));
- Assert.Equal (r.Subviews.IndexOf (v2), r.TabIndexes.IndexOf (v2));
- Assert.Equal (r.Subviews.IndexOf (v3), r.TabIndexes.IndexOf (v3));
- }
- [Fact]
- public void BringSubviewToFront_Subviews_vs_TabIndexes ()
- {
- var r = new View ();
- var v1 = new View () { CanFocus = true };
- var v2 = new View () { CanFocus = true };
- var v3 = new View () { CanFocus = true };
- r.Add (v1, v2, v3);
- r.BringSubviewToFront (v1);
- Assert.True (r.Subviews.IndexOf (v1) == 2);
- Assert.True (r.Subviews.IndexOf (v2) == 0);
- Assert.True (r.Subviews.IndexOf (v3) == 1);
- Assert.True (r.TabIndexes.IndexOf (v1) == 0);
- Assert.True (r.TabIndexes.IndexOf (v2) == 1);
- Assert.True (r.TabIndexes.IndexOf (v3) == 2);
- }
- [Fact]
- public void BringSubviewForward_Subviews_vs_TabIndexes ()
- {
- var r = new View ();
- var v1 = new View () { CanFocus = true };
- var v2 = new View () { CanFocus = true };
- var v3 = new View () { CanFocus = true };
- r.Add (v1, v2, v3);
- r.BringSubviewForward (v1);
- Assert.True (r.Subviews.IndexOf (v1) == 1);
- Assert.True (r.Subviews.IndexOf (v2) == 0);
- Assert.True (r.Subviews.IndexOf (v3) == 2);
- Assert.True (r.TabIndexes.IndexOf (v1) == 0);
- Assert.True (r.TabIndexes.IndexOf (v2) == 1);
- Assert.True (r.TabIndexes.IndexOf (v3) == 2);
- }
- [Fact]
- public void SendSubviewToBack_Subviews_vs_TabIndexes ()
- {
- var r = new View ();
- var v1 = new View () { CanFocus = true };
- var v2 = new View () { CanFocus = true };
- var v3 = new View () { CanFocus = true };
- r.Add (v1, v2, v3);
- r.SendSubviewToBack (v3);
- Assert.True (r.Subviews.IndexOf (v1) == 1);
- Assert.True (r.Subviews.IndexOf (v2) == 2);
- Assert.True (r.Subviews.IndexOf (v3) == 0);
- Assert.True (r.TabIndexes.IndexOf (v1) == 0);
- Assert.True (r.TabIndexes.IndexOf (v2) == 1);
- Assert.True (r.TabIndexes.IndexOf (v3) == 2);
- }
- [Fact]
- public void SendSubviewBackwards_Subviews_vs_TabIndexes ()
- {
- var r = new View ();
- var v1 = new View () { CanFocus = true };
- var v2 = new View () { CanFocus = true };
- var v3 = new View () { CanFocus = true };
- r.Add (v1, v2, v3);
- r.SendSubviewBackwards (v3);
- Assert.True (r.Subviews.IndexOf (v1) == 0);
- Assert.True (r.Subviews.IndexOf (v2) == 2);
- Assert.True (r.Subviews.IndexOf (v3) == 1);
- Assert.True (r.TabIndexes.IndexOf (v1) == 0);
- Assert.True (r.TabIndexes.IndexOf (v2) == 1);
- Assert.True (r.TabIndexes.IndexOf (v3) == 2);
- }
- [Fact]
- public void TabIndex_Set_CanFocus_ValidValues ()
- {
- var r = new View ();
- var v1 = new View () { CanFocus = true };
- var v2 = new View () { CanFocus = true };
- var v3 = new View () { CanFocus = true };
- r.Add (v1, v2, v3);
- v1.TabIndex = 1;
- Assert.True (r.Subviews.IndexOf (v1) == 0);
- Assert.True (r.TabIndexes.IndexOf (v1) == 1);
- v1.TabIndex = 2;
- Assert.True (r.Subviews.IndexOf (v1) == 0);
- Assert.True (r.TabIndexes.IndexOf (v1) == 2);
- }
- [Fact]
- public void TabIndex_Set_CanFocus_HigherValues ()
- {
- var r = new View ();
- var v1 = new View () { CanFocus = true };
- var v2 = new View () { CanFocus = true };
- var v3 = new View () { CanFocus = true };
- r.Add (v1, v2, v3);
- v1.TabIndex = 3;
- Assert.True (r.Subviews.IndexOf (v1) == 0);
- Assert.True (r.TabIndexes.IndexOf (v1) == 2);
- }
- [Fact]
- public void TabIndex_Set_CanFocus_LowerValues ()
- {
- var r = new View ();
- var v1 = new View () { CanFocus = true };
- var v2 = new View () { CanFocus = true };
- var v3 = new View () { CanFocus = true };
- r.Add (v1, v2, v3);
- v1.TabIndex = -1;
- Assert.True (r.Subviews.IndexOf (v1) == 0);
- Assert.True (r.TabIndexes.IndexOf (v1) == 0);
- }
- [Fact]
- public void TabIndex_Set_CanFocus_False ()
- {
- var r = new View ();
- var v1 = new View () { CanFocus = true };
- var v2 = new View () { CanFocus = true };
- var v3 = new View () { CanFocus = true };
- r.Add (v1, v2, v3);
- v1.CanFocus = false;
- v1.TabIndex = 0;
- Assert.True (r.Subviews.IndexOf (v1) == 0);
- Assert.True (r.TabIndexes.IndexOf (v1) == 0);
- Assert.Equal (-1, v1.TabIndex);
- }
- [Fact]
- public void TabIndex_Set_CanFocus_False_To_True ()
- {
- var r = new View ();
- var v1 = new View ();
- var v2 = new View () { CanFocus = true };
- var v3 = new View () { CanFocus = true };
- r.Add (v1, v2, v3);
- v1.CanFocus = true;
- v1.TabIndex = 1;
- Assert.True (r.Subviews.IndexOf (v1) == 0);
- Assert.True (r.TabIndexes.IndexOf (v1) == 1);
- }
- [Fact]
- public void TabStop_And_CanFocus_Are_All_True ()
- {
- var r = new View ();
- var v1 = new View () { CanFocus = true };
- var v2 = new View () { CanFocus = true };
- var v3 = new View () { CanFocus = true };
- r.Add (v1, v2, v3);
- r.FocusNext ();
- Assert.True (v1.HasFocus);
- Assert.False (v2.HasFocus);
- Assert.False (v3.HasFocus);
- r.FocusNext ();
- Assert.False (v1.HasFocus);
- Assert.True (v2.HasFocus);
- Assert.False (v3.HasFocus);
- r.FocusNext ();
- Assert.False (v1.HasFocus);
- Assert.False (v2.HasFocus);
- Assert.True (v3.HasFocus);
- }
- [Fact]
- public void TabStop_Are_All_True_And_CanFocus_Are_All_False ()
- {
- var r = new View ();
- var v1 = new View ();
- var v2 = new View ();
- var v3 = new View ();
- r.Add (v1, v2, v3);
- r.FocusNext ();
- Assert.False (v1.HasFocus);
- Assert.False (v2.HasFocus);
- Assert.False (v3.HasFocus);
- r.FocusNext ();
- Assert.False (v1.HasFocus);
- Assert.False (v2.HasFocus);
- Assert.False (v3.HasFocus);
- r.FocusNext ();
- Assert.False (v1.HasFocus);
- Assert.False (v2.HasFocus);
- Assert.False (v3.HasFocus);
- }
- [Fact]
- public void TabStop_Are_All_False_And_CanFocus_Are_All_True ()
- {
- var r = new View ();
- var v1 = new View () { CanFocus = true, TabStop = false };
- var v2 = new View () { CanFocus = true, TabStop = false };
- var v3 = new View () { CanFocus = true, TabStop = false };
- r.Add (v1, v2, v3);
- r.FocusNext ();
- Assert.False (v1.HasFocus);
- Assert.False (v2.HasFocus);
- Assert.False (v3.HasFocus);
- r.FocusNext ();
- Assert.False (v1.HasFocus);
- Assert.False (v2.HasFocus);
- Assert.False (v3.HasFocus);
- r.FocusNext ();
- Assert.False (v1.HasFocus);
- Assert.False (v2.HasFocus);
- Assert.False (v3.HasFocus);
- }
- [Fact]
- public void TabStop_And_CanFocus_Mixed_And_BothFalse ()
- {
- var r = new View ();
- var v1 = new View () { CanFocus = true, TabStop = false };
- var v2 = new View () { CanFocus = false, TabStop = true };
- var v3 = new View () { CanFocus = false, TabStop = false };
- r.Add (v1, v2, v3);
- r.FocusNext ();
- Assert.False (v1.HasFocus);
- Assert.False (v2.HasFocus);
- Assert.False (v3.HasFocus);
- r.FocusNext ();
- Assert.False (v1.HasFocus);
- Assert.False (v2.HasFocus);
- Assert.False (v3.HasFocus);
- r.FocusNext ();
- Assert.False (v1.HasFocus);
- Assert.False (v2.HasFocus);
- Assert.False (v3.HasFocus);
- }
- [Fact]
- public void TabStop_All_True_And_Changing_CanFocus_Later ()
- {
- var r = new View ();
- var v1 = new View ();
- var v2 = new View ();
- var v3 = new View ();
- r.Add (v1, v2, v3);
- r.FocusNext ();
- Assert.False (v1.HasFocus);
- Assert.False (v2.HasFocus);
- Assert.False (v3.HasFocus);
- v1.CanFocus = true;
- r.FocusNext ();
- Assert.True (v1.HasFocus);
- Assert.False (v2.HasFocus);
- Assert.False (v3.HasFocus);
- v2.CanFocus = true;
- r.FocusNext ();
- Assert.False (v1.HasFocus);
- Assert.True (v2.HasFocus);
- Assert.False (v3.HasFocus);
- v3.CanFocus = true;
- r.FocusNext ();
- Assert.False (v1.HasFocus);
- Assert.False (v2.HasFocus);
- Assert.True (v3.HasFocus);
- }
- [Fact]
- public void TabStop_All_False_And_All_True_And_Changing_TabStop_Later ()
- {
- var r = new View ();
- var v1 = new View () { CanFocus = true, TabStop = false };
- var v2 = new View () { CanFocus = true, TabStop = false };
- var v3 = new View () { CanFocus = true, TabStop = false };
- r.Add (v1, v2, v3);
- r.FocusNext ();
- Assert.False (v1.HasFocus);
- Assert.False (v2.HasFocus);
- Assert.False (v3.HasFocus);
- v1.TabStop = true;
- r.FocusNext ();
- Assert.True (v1.HasFocus);
- Assert.False (v2.HasFocus);
- Assert.False (v3.HasFocus);
- v2.TabStop = true;
- r.FocusNext ();
- Assert.False (v1.HasFocus);
- Assert.True (v2.HasFocus);
- Assert.False (v3.HasFocus);
- v3.TabStop = true;
- r.FocusNext ();
- Assert.False (v1.HasFocus);
- Assert.False (v2.HasFocus);
- Assert.True (v3.HasFocus);
- }
- [Fact]
- public void CanFocus_Set_Changes_TabIndex_And_TabStop ()
- {
- var r = new View ();
- var v1 = new View ("1");
- var v2 = new View ("2");
- var v3 = new View ("3");
- r.Add (v1, v2, v3);
- v2.CanFocus = true;
- Assert.Equal (r.TabIndexes.IndexOf (v2), v2.TabIndex);
- Assert.Equal (0, v2.TabIndex);
- Assert.True (v2.TabStop);
- v1.CanFocus = true;
- Assert.Equal (r.TabIndexes.IndexOf (v1), v1.TabIndex);
- Assert.Equal (1, v1.TabIndex);
- Assert.True (v1.TabStop);
- v1.TabIndex = 2;
- Assert.Equal (r.TabIndexes.IndexOf (v1), v1.TabIndex);
- Assert.Equal (1, v1.TabIndex);
- v3.CanFocus = true;
- Assert.Equal (r.TabIndexes.IndexOf (v1), v1.TabIndex);
- Assert.Equal (1, v1.TabIndex);
- Assert.Equal (r.TabIndexes.IndexOf (v3), v3.TabIndex);
- Assert.Equal (2, v3.TabIndex);
- Assert.True (v3.TabStop);
- v2.CanFocus = false;
- Assert.Equal (r.TabIndexes.IndexOf (v1), v1.TabIndex);
- Assert.Equal (1, v1.TabIndex);
- Assert.True (v1.TabStop);
- Assert.NotEqual (r.TabIndexes.IndexOf (v2), v2.TabIndex);
- Assert.Equal (-1, v2.TabIndex);
- Assert.False (v2.TabStop);
- Assert.Equal (r.TabIndexes.IndexOf (v3), v3.TabIndex);
- Assert.Equal (2, v3.TabIndex);
- Assert.True (v3.TabStop);
- }
- [Fact]
- public void Initialized_Event_Comparing_With_Added_Event ()
- {
- Application.Init (new FakeDriver (), new FakeMainLoop (() => FakeConsole.ReadKey (true)));
- var t = new Toplevel () { Id = "0", };
- var w = new Window () { Id = "t", Width = Dim.Fill (), Height = Dim.Fill () };
- var v1 = new View () { Id = "v1", Width = Dim.Fill (), Height = Dim.Fill () };
- var v2 = new View () { Id = "v2", Width = Dim.Fill (), Height = Dim.Fill () };
- var sv1 = new View () { Id = "sv1", Width = Dim.Fill (), Height = Dim.Fill () };
- int tc = 0, wc = 0, v1c = 0, v2c = 0, sv1c = 0;
- w.Added += (e) => {
- Assert.Equal (e.Frame.Width, w.Frame.Width);
- Assert.Equal (e.Frame.Height, w.Frame.Height);
- };
- v1.Added += (e) => {
- Assert.Equal (e.Frame.Width, v1.Frame.Width);
- Assert.Equal (e.Frame.Height, v1.Frame.Height);
- };
- v2.Added += (e) => {
- Assert.Equal (e.Frame.Width, v2.Frame.Width);
- Assert.Equal (e.Frame.Height, v2.Frame.Height);
- };
- sv1.Added += (e) => {
- Assert.Equal (e.Frame.Width, sv1.Frame.Width);
- Assert.Equal (e.Frame.Height, sv1.Frame.Height);
- };
- t.Initialized += (s, e) => {
- tc++;
- Assert.Equal (1, tc);
- Assert.Equal (1, wc);
- Assert.Equal (1, v1c);
- Assert.Equal (1, v2c);
- Assert.Equal (1, sv1c);
- Assert.True (t.CanFocus);
- Assert.True (w.CanFocus);
- Assert.False (v1.CanFocus);
- Assert.False (v2.CanFocus);
- Assert.False (sv1.CanFocus);
- Application.Refresh ();
- };
- w.Initialized += (s, e) => {
- wc++;
- Assert.Equal (t.Frame.Width, w.Frame.Width);
- Assert.Equal (t.Frame.Height, w.Frame.Height);
- };
- v1.Initialized += (s, e) => {
- v1c++;
- Assert.Equal (t.Frame.Width, v1.Frame.Width);
- Assert.Equal (t.Frame.Height, v1.Frame.Height);
- };
- v2.Initialized += (s, e) => {
- v2c++;
- Assert.Equal (t.Frame.Width, v2.Frame.Width);
- Assert.Equal (t.Frame.Height, v2.Frame.Height);
- };
- sv1.Initialized += (s, e) => {
- sv1c++;
- Assert.Equal (t.Frame.Width, sv1.Frame.Width);
- Assert.Equal (t.Frame.Height, sv1.Frame.Height);
- Assert.False (sv1.CanFocus);
- Assert.Throws<InvalidOperationException> (() => sv1.CanFocus = true);
- Assert.False (sv1.CanFocus);
- };
- v1.Add (sv1);
- w.Add (v1, v2);
- t.Add (w);
- Application.Iteration = () => {
- Application.Refresh ();
- t.Running = false;
- };
- Application.Run (t);
- Application.Shutdown ();
- Assert.Equal (1, tc);
- Assert.Equal (1, wc);
- Assert.Equal (1, v1c);
- Assert.Equal (1, v2c);
- Assert.Equal (1, sv1c);
- Assert.True (t.CanFocus);
- Assert.True (w.CanFocus);
- Assert.False (v1.CanFocus);
- Assert.False (v2.CanFocus);
- Assert.False (sv1.CanFocus);
- v1.CanFocus = true;
- Assert.False (sv1.CanFocus); // False because sv1 was disposed and it isn't a subview of v1.
- }
- [Fact]
- public void Initialized_Event_Will_Be_Invoked_When_Added_Dynamically ()
- {
- Application.Init (new FakeDriver (), new FakeMainLoop (() => FakeConsole.ReadKey (true)));
- var t = new Toplevel () { Id = "0", };
- var w = new Window () { Id = "t", Width = Dim.Fill (), Height = Dim.Fill () };
- var v1 = new View () { Id = "v1", Width = Dim.Fill (), Height = Dim.Fill () };
- var v2 = new View () { Id = "v2", Width = Dim.Fill (), Height = Dim.Fill () };
- int tc = 0, wc = 0, v1c = 0, v2c = 0, sv1c = 0;
- t.Initialized += (s, e) => {
- tc++;
- Assert.Equal (1, tc);
- Assert.Equal (1, wc);
- Assert.Equal (1, v1c);
- Assert.Equal (1, v2c);
- Assert.Equal (0, sv1c); // Added after t in the Application.Iteration.
- Assert.True (t.CanFocus);
- Assert.True (w.CanFocus);
- Assert.False (v1.CanFocus);
- Assert.False (v2.CanFocus);
- Application.Refresh ();
- };
- w.Initialized += (s, e) => {
- wc++;
- Assert.Equal (t.Frame.Width, w.Frame.Width);
- Assert.Equal (t.Frame.Height, w.Frame.Height);
- };
- v1.Initialized += (s, e) => {
- v1c++;
- Assert.Equal (t.Frame.Width, v1.Frame.Width);
- Assert.Equal (t.Frame.Height, v1.Frame.Height);
- };
- v2.Initialized += (s, e) => {
- v2c++;
- Assert.Equal (t.Frame.Width, v2.Frame.Width);
- Assert.Equal (t.Frame.Height, v2.Frame.Height);
- };
- w.Add (v1, v2);
- t.Add (w);
- Application.Iteration = () => {
- var sv1 = new View () { Id = "sv1", Width = Dim.Fill (), Height = Dim.Fill () };
- sv1.Initialized += (s, e) => {
- sv1c++;
- Assert.NotEqual (t.Frame.Width, sv1.Frame.Width);
- Assert.NotEqual (t.Frame.Height, sv1.Frame.Height);
- Assert.False (sv1.CanFocus);
- Assert.Throws<InvalidOperationException> (() => sv1.CanFocus = true);
- Assert.False (sv1.CanFocus);
- };
- v1.Add (sv1);
- Application.Refresh ();
- t.Running = false;
- };
- Application.Run (t);
- Application.Shutdown ();
- Assert.Equal (1, tc);
- Assert.Equal (1, wc);
- Assert.Equal (1, v1c);
- Assert.Equal (1, v2c);
- Assert.Equal (1, sv1c);
- Assert.True (t.CanFocus);
- Assert.True (w.CanFocus);
- Assert.False (v1.CanFocus);
- Assert.False (v2.CanFocus);
- }
- [Fact]
- [AutoInitShutdown]
- public void CanFocus_Faced_With_Container ()
- {
- var t = new Toplevel ();
- var w = new Window ();
- var f = new FrameView ();
- var v = new View () { CanFocus = true };
- f.Add (v);
- w.Add (f);
- t.Add (w);
- Assert.True (t.CanFocus);
- Assert.True (w.CanFocus);
- Assert.True (f.CanFocus);
- Assert.True (v.CanFocus);
- f.CanFocus = false;
- Assert.False (f.CanFocus);
- Assert.True (v.CanFocus);
- v.CanFocus = false;
- Assert.False (f.CanFocus);
- Assert.False (v.CanFocus);
- v.CanFocus = true;
- Assert.False (f.CanFocus);
- Assert.True (v.CanFocus);
- }
- [Fact]
- public void CanFocus_Faced_With_Container_Before_Run ()
- {
- Application.Init (new FakeDriver (), new FakeMainLoop (() => FakeConsole.ReadKey (true)));
- var t = Application.Top;
- var w = new Window ("w");
- var f = new FrameView ("f");
- var v = new View ("v") { CanFocus = true };
- f.Add (v);
- w.Add (f);
- t.Add (w);
- Assert.True (t.CanFocus);
- Assert.True (w.CanFocus);
- Assert.True (f.CanFocus);
- Assert.True (v.CanFocus);
- f.CanFocus = false;
- Assert.False (f.CanFocus);
- Assert.True (v.CanFocus);
- v.CanFocus = false;
- Assert.False (f.CanFocus);
- Assert.False (v.CanFocus);
- v.CanFocus = true;
- Assert.False (f.CanFocus);
- Assert.True (v.CanFocus);
- Application.Iteration += () => Application.RequestStop ();
- Application.Run ();
- Application.Shutdown ();
- }
- [Fact]
- public void CanFocus_Faced_With_Container_After_Run ()
- {
- Application.Init (new FakeDriver (), new FakeMainLoop (() => FakeConsole.ReadKey (true)));
- var t = Application.Top;
- var w = new Window ("w");
- var f = new FrameView ("f");
- var v = new View ("v") { CanFocus = true };
- f.Add (v);
- w.Add (f);
- t.Add (w);
- t.Ready += () => {
- Assert.True (t.CanFocus);
- Assert.True (w.CanFocus);
- Assert.True (f.CanFocus);
- Assert.True (v.CanFocus);
- f.CanFocus = false;
- Assert.False (f.CanFocus);
- Assert.False (v.CanFocus);
- v.CanFocus = false;
- Assert.False (f.CanFocus);
- Assert.False (v.CanFocus);
- Assert.Throws<InvalidOperationException> (() => v.CanFocus = true);
- Assert.False (f.CanFocus);
- Assert.False (v.CanFocus);
- f.CanFocus = true;
- Assert.True (f.CanFocus);
- Assert.True (v.CanFocus);
- };
- Application.Iteration += () => Application.RequestStop ();
- Application.Run ();
- Application.Shutdown ();
- }
- [Fact]
- public void CanFocus_Container_ToFalse_Turns_All_Subviews_ToFalse_Too ()
- {
- Application.Init (new FakeDriver (), new FakeMainLoop (() => FakeConsole.ReadKey (true)));
- var t = Application.Top;
- var w = new Window ("w");
- var f = new FrameView ("f");
- var v1 = new View ("v1") { CanFocus = true };
- var v2 = new View ("v2") { CanFocus = true };
- f.Add (v1, v2);
- w.Add (f);
- t.Add (w);
- t.Ready += () => {
- Assert.True (t.CanFocus);
- Assert.True (w.CanFocus);
- Assert.True (f.CanFocus);
- Assert.True (v1.CanFocus);
- Assert.True (v2.CanFocus);
- w.CanFocus = false;
- Assert.False (w.CanFocus);
- Assert.False (f.CanFocus);
- Assert.False (v1.CanFocus);
- Assert.False (v2.CanFocus);
- };
- Application.Iteration += () => Application.RequestStop ();
- Application.Run ();
- Application.Shutdown ();
- }
- [Fact]
- public void CanFocus_Container_Toggling_All_Subviews_To_Old_Value_When_Is_True ()
- {
- Application.Init (new FakeDriver (), new FakeMainLoop (() => FakeConsole.ReadKey (true)));
- var t = Application.Top;
- var w = new Window ("w");
- var f = new FrameView ("f");
- var v1 = new View ("v1");
- var v2 = new View ("v2") { CanFocus = true };
- f.Add (v1, v2);
- w.Add (f);
- t.Add (w);
- t.Ready += () => {
- Assert.True (t.CanFocus);
- Assert.True (w.CanFocus);
- Assert.True (f.CanFocus);
- Assert.False (v1.CanFocus);
- Assert.True (v2.CanFocus);
- w.CanFocus = false;
- Assert.False (w.CanFocus);
- Assert.False (f.CanFocus);
- Assert.False (v1.CanFocus);
- Assert.False (v2.CanFocus);
- w.CanFocus = true;
- Assert.True (w.CanFocus);
- Assert.True (f.CanFocus);
- Assert.False (v1.CanFocus);
- Assert.True (v2.CanFocus);
- };
- Application.Iteration += () => Application.RequestStop ();
- Application.Run ();
- Application.Shutdown ();
- }
- [Fact]
- public void Navigation_With_Null_Focused_View ()
- {
- // Non-regression test for #882 (NullReferenceException during keyboard navigation when Focused is null)
- Application.Init (new FakeDriver (), new FakeMainLoop (() => FakeConsole.ReadKey (true)));
- Application.Top.Ready += () => {
- Assert.Null (Application.Top.Focused);
- };
- // Keyboard navigation with tab
- Console.MockKeyPresses.Push (new ConsoleKeyInfo ('\t', ConsoleKey.Tab, false, false, false));
- Application.Iteration += () => Application.RequestStop ();
- Application.Run ();
- Application.Shutdown ();
- }
- [Fact]
- public void Multi_Thread_Toplevels ()
- {
- Application.Init (new FakeDriver (), new FakeMainLoop (() => FakeConsole.ReadKey (true)));
- var t = Application.Top;
- var w = new Window ();
- t.Add (w);
- int count = 0, count1 = 0, count2 = 0;
- bool log = false, log1 = false, log2 = false;
- bool fromTopStillKnowFirstIsRunning = false;
- bool fromTopStillKnowSecondIsRunning = false;
- bool fromFirstStillKnowSecondIsRunning = false;
- Application.MainLoop.AddTimeout (TimeSpan.FromMilliseconds (100), (_) => {
- count++;
- if (count1 == 5) {
- log1 = true;
- }
- if (count1 == 14 && count2 == 10 && count == 15) { // count2 is already stopped
- fromTopStillKnowFirstIsRunning = true;
- }
- if (count1 == 7 && count2 == 7 && count == 8) {
- fromTopStillKnowSecondIsRunning = true;
- }
- if (count == 30) {
- Assert.Equal (30, count);
- Assert.Equal (20, count1);
- Assert.Equal (10, count2);
- Assert.True (log);
- Assert.True (log1);
- Assert.True (log2);
- Assert.True (fromTopStillKnowFirstIsRunning);
- Assert.True (fromTopStillKnowSecondIsRunning);
- Assert.True (fromFirstStillKnowSecondIsRunning);
- Application.RequestStop ();
- return false;
- }
- return true;
- });
- t.Ready += FirstDialogToplevel;
- void FirstDialogToplevel ()
- {
- var od = new OpenDialog ();
- od.Ready += SecoundDialogToplevel;
- Application.MainLoop.AddTimeout (TimeSpan.FromMilliseconds (100), (_) => {
- count1++;
- if (count2 == 5) {
- log2 = true;
- }
- if (count2 == 4 && count1 == 5 && count == 5) {
- fromFirstStillKnowSecondIsRunning = true;
- }
- if (count1 == 20) {
- Assert.Equal (20, count1);
- Application.RequestStop ();
- return false;
- }
- return true;
- });
- Application.Run (od);
- }
- void SecoundDialogToplevel ()
- {
- var d = new Dialog ();
- Application.MainLoop.AddTimeout (TimeSpan.FromMilliseconds (100), (_) => {
- count2++;
- if (count < 30) {
- log = true;
- }
- if (count2 == 10) {
- Assert.Equal (10, count2);
- Application.RequestStop ();
- return false;
- }
- return true;
- });
- Application.Run (d);
- }
- Application.Run ();
- Application.Shutdown ();
- }
- [Fact]
- public void View_With_No_Difference_Between_An_Object_Initializer_And_A_Constructor ()
- {
- // Object Initializer
- var view = new View () {
- X = 1,
- Y = 2,
- Width = 3,
- Height = 4
- };
- Assert.Equal (1, view.X);
- Assert.Equal (2, view.Y);
- Assert.Equal (3, view.Width);
- Assert.Equal (4, view.Height);
- Assert.False (view.Frame.IsEmpty);
- Assert.Equal (new Rect (1, 2, 3, 4), view.Frame);
- Assert.False (view.Bounds.IsEmpty);
- Assert.Equal (new Rect (0, 0, 3, 4), view.Bounds);
- view.LayoutSubviews ();
- Assert.Equal (1, view.X);
- Assert.Equal (2, view.Y);
- Assert.Equal (3, view.Width);
- Assert.Equal (4, view.Height);
- Assert.False (view.Frame.IsEmpty);
- Assert.False (view.Bounds.IsEmpty);
- // Default Constructor
- view = new View ();
- Assert.Null (view.X);
- Assert.Null (view.Y);
- Assert.Null (view.Width);
- Assert.Null (view.Height);
- Assert.True (view.Frame.IsEmpty);
- Assert.True (view.Bounds.IsEmpty);
- // Constructor
- view = new View (1, 2, "");
- Assert.Null (view.X);
- Assert.Null (view.Y);
- Assert.Null (view.Width);
- Assert.Null (view.Height);
- Assert.False (view.Frame.IsEmpty);
- Assert.True (view.Bounds.IsEmpty);
- // Default Constructor and post assignment equivalent to Object Initializer
- view = new View ();
- view.X = 1;
- view.Y = 2;
- view.Width = 3;
- view.Height = 4;
- Assert.Equal (1, view.X);
- Assert.Equal (2, view.Y);
- Assert.Equal (3, view.Width);
- Assert.Equal (4, view.Height);
- Assert.False (view.Frame.IsEmpty);
- Assert.Equal (new Rect (1, 2, 3, 4), view.Frame);
- Assert.False (view.Bounds.IsEmpty);
- Assert.Equal (new Rect (0, 0, 3, 4), view.Bounds);
- }
- [Fact]
- public void FocusNearestView_Ensure_Focus_Ordered ()
- {
- var top = new Toplevel ();
- var win = new Window ();
- var winSubview = new View ("WindowSubview") {
- CanFocus = true
- };
- win.Add (winSubview);
- top.Add (win);
- var frm = new FrameView ();
- var frmSubview = new View ("FrameSubview") {
- CanFocus = true
- };
- frm.Add (frmSubview);
- top.Add (frm);
- top.ProcessKey (new KeyEvent (Key.Tab, new KeyModifiers ()));
- Assert.Equal ($"WindowSubview", top.MostFocused.Text);
- top.ProcessKey (new KeyEvent (Key.Tab, new KeyModifiers ()));
- Assert.Equal ("FrameSubview", top.MostFocused.Text);
- top.ProcessKey (new KeyEvent (Key.Tab, new KeyModifiers ()));
- Assert.Equal ($"WindowSubview", top.MostFocused.Text);
- top.ProcessKey (new KeyEvent (Key.BackTab | Key.ShiftMask, new KeyModifiers ()));
- Assert.Equal ("FrameSubview", top.MostFocused.Text);
- top.ProcessKey (new KeyEvent (Key.BackTab | Key.ShiftMask, new KeyModifiers ()));
- Assert.Equal ($"WindowSubview", top.MostFocused.Text);
- }
- [Fact]
- public void KeyPress_Handled_To_True_Prevents_Changes ()
- {
- Application.Init (new FakeDriver (), new FakeMainLoop (() => FakeConsole.ReadKey (true)));
- Console.MockKeyPresses.Push (new ConsoleKeyInfo ('N', ConsoleKey.N, false, false, false));
- var top = Application.Top;
- var text = new TextField ("");
- text.KeyPress += (e) => {
- e.Handled = true;
- Assert.True (e.Handled);
- Assert.Equal (Key.N, e.KeyEvent.Key);
- };
- top.Add (text);
- Application.Iteration += () => {
- Console.MockKeyPresses.Push (new ConsoleKeyInfo ('N', ConsoleKey.N, false, false, false));
- Assert.Equal ("", text.Text);
- Application.RequestStop ();
- };
- Application.Run ();
- // Shutdown must be called to safely clean up Application if Init has been called
- Application.Shutdown ();
- }
- [Fact, AutoInitShutdown]
- public void SetWidth_CanSetWidth_ForceValidatePosDim ()
- {
- var top = new View () {
- X = 0,
- Y = 0,
- Width = 80,
- };
- var v = new View () {
- Width = Dim.Fill (),
- ForceValidatePosDim = true
- };
- top.Add (v);
- Assert.False (v.SetWidth (70, out int rWidth));
- Assert.Equal (70, rWidth);
- v.Width = Dim.Fill (1);
- Assert.False (v.SetWidth (70, out rWidth));
- Assert.Equal (69, rWidth);
- v.Width = null;
- Assert.True (v.SetWidth (70, out rWidth));
- Assert.Equal (70, rWidth);
- Assert.False (v.IsInitialized);
- Application.Top.Add (top);
- Application.Begin (Application.Top);
- Assert.True (v.IsInitialized);
- v.Width = Dim.Fill (1);
- Assert.Throws<ArgumentException> (() => v.Width = 75);
- v.LayoutStyle = LayoutStyle.Absolute;
- v.Width = 75;
- Assert.True (v.SetWidth (60, out rWidth));
- Assert.Equal (60, rWidth);
- }
- [Fact, AutoInitShutdown]
- public void SetHeight_CanSetHeight_ForceValidatePosDim ()
- {
- var top = new View () {
- X = 0,
- Y = 0,
- Height = 20
- };
- var v = new View () {
- Height = Dim.Fill (),
- ForceValidatePosDim = true
- };
- top.Add (v);
- Assert.False (v.SetHeight (10, out int rHeight));
- Assert.Equal (10, rHeight);
- v.Height = Dim.Fill (1);
- Assert.False (v.SetHeight (10, out rHeight));
- Assert.Equal (9, rHeight);
- v.Height = null;
- Assert.True (v.SetHeight (10, out rHeight));
- Assert.Equal (10, rHeight);
- Assert.False (v.IsInitialized);
- Application.Top.Add (top);
- Application.Begin (Application.Top);
- Assert.True (v.IsInitialized);
- v.Height = Dim.Fill (1);
- Assert.Throws<ArgumentException> (() => v.Height = 15);
- v.LayoutStyle = LayoutStyle.Absolute;
- v.Height = 15;
- Assert.True (v.SetHeight (5, out rHeight));
- Assert.Equal (5, rHeight);
- }
- [Fact]
- public void GetCurrentWidth_CanSetWidth ()
- {
- var top = new View () {
- X = 0,
- Y = 0,
- Width = 80,
- };
- var v = new View () {
- Width = Dim.Fill ()
- };
- top.Add (v);
- Assert.False (v.AutoSize);
- Assert.True (v.GetCurrentWidth (out int cWidth));
- Assert.Equal (80, cWidth);
- v.Width = Dim.Fill (1);
- Assert.True (v.GetCurrentWidth (out cWidth));
- Assert.Equal (79, cWidth);
- v.AutoSize = true;
- Assert.True (v.GetCurrentWidth (out cWidth));
- Assert.Equal (79, cWidth);
- }
- [Fact]
- public void GetCurrentHeight_CanSetHeight ()
- {
- var top = new View () {
- X = 0,
- Y = 0,
- Height = 20
- };
- var v = new View () {
- Height = Dim.Fill ()
- };
- top.Add (v);
- Assert.False (v.AutoSize);
- Assert.True (v.GetCurrentHeight (out int cHeight));
- Assert.Equal (20, cHeight);
- v.Height = Dim.Fill (1);
- Assert.True (v.GetCurrentHeight (out cHeight));
- Assert.Equal (19, cHeight);
- v.AutoSize = true;
- Assert.True (v.GetCurrentHeight (out cHeight));
- Assert.Equal (19, cHeight);
- }
- [Fact]
- public void AutoSize_False_If_Text_Emmpty ()
- {
- var view1 = new View ();
- var view2 = new View ("");
- var view3 = new View () { Text = "" };
- Assert.False (view1.AutoSize);
- Assert.False (view2.AutoSize);
- Assert.False (view3.AutoSize);
- }
- [Fact]
- public void AutoSize_False_If_Text_Is_Not_Emmpty ()
- {
- var view1 = new View ();
- view1.Text = "Hello World";
- var view2 = new View ("Hello World");
- var view3 = new View () { Text = "Hello World" };
- Assert.False (view1.AutoSize);
- Assert.False (view2.AutoSize);
- Assert.False (view3.AutoSize);
- }
- [Fact]
- public void AutoSize_True_Label_If_Text_Emmpty ()
- {
- var label1 = new Label ();
- var label2 = new Label ("");
- var label3 = new Label () { Text = "" };
- Assert.True (label1.AutoSize);
- Assert.True (label2.AutoSize);
- Assert.True (label3.AutoSize);
- }
- [Fact]
- public void AutoSize_True_Label_If_Text_Is_Not_Emmpty ()
- {
- var label1 = new Label ();
- label1.Text = "Hello World";
- var label2 = new Label ("Hello World");
- var label3 = new Label () { Text = "Hello World" };
- Assert.True (label1.AutoSize);
- Assert.True (label2.AutoSize);
- Assert.True (label3.AutoSize);
- }
- [Fact]
- public void AutoSize_False_ResizeView_Is_Always_False ()
- {
- var label = new Label () { AutoSize = false };
- label.Text = "New text";
- Assert.False (label.AutoSize);
- Assert.Equal ("{X=0,Y=0,Width=0,Height=1}", label.Bounds.ToString ());
- }
- [Fact]
- public void AutoSize_True_ResizeView_With_Dim_Absolute ()
- {
- var label = new Label ();
- label.Text = "New text";
- Assert.True (label.AutoSize);
- Assert.Equal ("{X=0,Y=0,Width=8,Height=1}", label.Bounds.ToString ());
- }
- [Fact, AutoInitShutdown]
- public void AutoSize_False_ResizeView_With_Dim_Fill_After_IsInitialized ()
- {
- var win = new Window (new Rect (0, 0, 30, 80), "");
- var label = new Label () { AutoSize = false, Width = Dim.Fill (), Height = Dim.Fill () };
- win.Add (label);
- Application.Top.Add (win);
- // Text is empty so height=0
- Assert.False (label.AutoSize);
- Assert.Equal ("{X=0,Y=0,Width=0,Height=0}", label.Bounds.ToString ());
- label.Text = "New text\nNew line";
- Application.Top.LayoutSubviews ();
- Assert.False (label.AutoSize);
- Assert.Equal ("{X=0,Y=0,Width=28,Height=78}", label.Bounds.ToString ());
- Assert.False (label.IsInitialized);
- Application.Begin (Application.Top);
- Assert.True (label.IsInitialized);
- Assert.False (label.AutoSize);
- Assert.Equal ("{X=0,Y=0,Width=28,Height=78}", label.Bounds.ToString ());
- }
- [Fact, AutoInitShutdown]
- public void AutoSize_False_SetWidthHeight_With_Dim_Fill_And_Dim_Absolute_After_IsAdded_And_IsInitialized ()
- {
- var win = new Window (new Rect (0, 0, 30, 80), "");
- var label = new Label () { Width = Dim.Fill () };
- win.Add (label);
- Application.Top.Add (win);
- Assert.True (label.IsAdded);
- // Text is empty so height=0
- Assert.True (label.AutoSize);
- Assert.Equal ("{X=0,Y=0,Width=0,Height=0}", label.Bounds.ToString ());
- label.Text = "First line\nSecond line";
- Application.Top.LayoutSubviews ();
- Assert.True (label.AutoSize);
- Assert.Equal ("{X=0,Y=0,Width=28,Height=2}", label.Bounds.ToString ());
- Assert.False (label.IsInitialized);
- Application.Begin (Application.Top);
- Assert.True (label.AutoSize);
- Assert.Equal ("{X=0,Y=0,Width=28,Height=2}", label.Bounds.ToString ());
- Assert.True (label.IsInitialized);
- label.AutoSize = false;
- Application.Refresh ();
- Assert.False (label.AutoSize);
- Assert.Equal ("{X=0,Y=0,Width=28,Height=1}", label.Bounds.ToString ());
- }
- [Fact, AutoInitShutdown]
- public void AutoSize_False_SetWidthHeight_With_Dim_Fill_And_Dim_Absolute_With_Initialization ()
- {
- var win = new Window (new Rect (0, 0, 30, 80), "");
- var label = new Label () { Width = Dim.Fill () };
- win.Add (label);
- Application.Top.Add (win);
- // Text is empty so height=0
- Assert.True (label.AutoSize);
- Assert.Equal ("{X=0,Y=0,Width=0,Height=0}", label.Bounds.ToString ());
- Application.Begin (Application.Top);
- Assert.True (label.AutoSize);
- Assert.Equal ("{X=0,Y=0,Width=28,Height=0}", label.Bounds.ToString ());
- label.Text = "First line\nSecond line";
- Application.Refresh ();
- // Here the AutoSize ensuring the right size
- Assert.True (label.AutoSize);
- Assert.Equal ("{X=0,Y=0,Width=28,Height=2}", label.Bounds.ToString ());
- label.AutoSize = false;
- Application.Refresh ();
- // Here the SetMinWidthHeight ensuring the minimum height
- Assert.False (label.AutoSize);
- Assert.Equal ("{X=0,Y=0,Width=28,Height=1}", label.Bounds.ToString ());
- label.Text = "First changed line\nSecond changed line\nNew line";
- Application.Refresh ();
- Assert.False (label.AutoSize);
- Assert.Equal ("{X=0,Y=0,Width=28,Height=1}", label.Bounds.ToString ());
- label.AutoSize = true;
- Application.Refresh ();
- Assert.True (label.AutoSize);
- Assert.Equal ("{X=0,Y=0,Width=28,Height=3}", label.Bounds.ToString ());
- }
- [Fact, AutoInitShutdown]
- public void AutoSize_True_Setting_With_Height_Horizontal ()
- {
- var label = new Label ("Hello") { Width = 10, Height = 2 };
- var viewX = new View ("X") { X = Pos.Right (label) };
- var viewY = new View ("Y") { Y = Pos.Bottom (label) };
- Application.Top.Add (label, viewX, viewY);
- Application.Begin (Application.Top);
- Assert.True (label.AutoSize);
- Assert.Equal (new Rect (0, 0, 10, 2), label.Frame);
- var expected = @"
- Hello X
-
- Y
- ";
- var pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
- Assert.Equal (new Rect (0, 0, 11, 3), pos);
- label.AutoSize = false;
- Application.Refresh ();
- Assert.False (label.AutoSize);
- Assert.Equal (new Rect (0, 0, 10, 2), label.Frame);
- expected = @"
- Hello X
-
- Y
- ";
- pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
- Assert.Equal (new Rect (0, 0, 11, 3), pos);
- }
- [Fact, AutoInitShutdown]
- public void AutoSize_True_Setting_With_Height_Vertical ()
- {
- var label = new Label ("Hello") { Width = 2, Height = 10, TextDirection = TextDirection.TopBottom_LeftRight };
- var viewX = new View ("X") { X = Pos.Right (label) };
- var viewY = new View ("Y") { Y = Pos.Bottom (label) };
- Application.Top.Add (label, viewX, viewY);
- Application.Begin (Application.Top);
- Assert.True (label.AutoSize);
- Assert.Equal (new Rect (0, 0, 2, 10), label.Frame);
- var expected = @"
- H X
- e
- l
- l
- o
-
-
-
-
-
- Y
- ";
- var pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
- Assert.Equal (new Rect (0, 0, 3, 11), pos);
- label.AutoSize = false;
- Application.Refresh ();
- Assert.False (label.AutoSize);
- Assert.Equal (new Rect (0, 0, 2, 10), label.Frame);
- expected = @"
- H X
- e
- l
- l
- o
-
-
-
-
-
- Y
- ";
- pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
- Assert.Equal (new Rect (0, 0, 3, 11), pos);
- }
- [Theory]
- [InlineData (1)]
- [InlineData (2)]
- [InlineData (3)]
- public void LabelChangeText_RendersCorrectly_Constructors (int choice)
- {
- var driver = new FakeDriver ();
- Application.Init (driver, new FakeMainLoop (() => FakeConsole.ReadKey (true)));
- try {
- // Create a label with a short text
- Label lbl;
- var text = "test";
- if (choice == 1) {
- // An object initializer should call the default constructor.
- lbl = new Label { Text = text };
- } else if (choice == 2) {
- // Calling the default constructor followed by the object initializer.
- lbl = new Label () { Text = text };
- } else {
- // Calling the Text constructor.
- lbl = new Label (text);
- }
- lbl.ColorScheme = new ColorScheme ();
- lbl.Redraw (lbl.Bounds);
- // should have the initial text
- Assert.Equal ('t', driver.Contents [0, 0, 0]);
- Assert.Equal ('e', driver.Contents [0, 1, 0]);
- Assert.Equal ('s', driver.Contents [0, 2, 0]);
- Assert.Equal ('t', driver.Contents [0, 3, 0]);
- Assert.Equal (' ', driver.Contents [0, 4, 0]);
- } finally {
- Application.Shutdown ();
- }
- }
- [Fact]
- [AutoInitShutdown]
- public void Internal_Tests ()
- {
- Assert.Equal (new [] { View.Direction.Forward, View.Direction.Backward },
- Enum.GetValues (typeof (View.Direction)));
- var rect = new Rect (1, 1, 10, 1);
- var view = new View (rect);
- var top = Application.Top;
- top.Add (view);
- Assert.Equal (View.Direction.Forward, view.FocusDirection);
- view.FocusDirection = View.Direction.Backward;
- Assert.Equal (View.Direction.Backward, view.FocusDirection);
- Assert.Empty (view.InternalSubviews);
- Assert.Equal (new Rect (new Point (0, 0), rect.Size), view.NeedDisplay);
- Assert.True (view.LayoutNeeded);
- Assert.False (view.ChildNeedsDisplay);
- Assert.False (view.addingView);
- view.addingView = true;
- Assert.True (view.addingView);
- view.ViewToScreen (0, 0, out int rcol, out int rrow);
- Assert.Equal (1, rcol);
- Assert.Equal (1, rrow);
- Assert.Equal (rect, view.ViewToScreen (view.Bounds));
- Assert.Equal (top.Bounds, view.ScreenClip (top.Bounds));
- view.Width = Dim.Fill ();
- view.Height = Dim.Fill ();
- Assert.Equal (10, view.Bounds.Width);
- Assert.Equal (1, view.Bounds.Height);
- view.SetRelativeLayout (top.Bounds);
- Assert.Equal (79, view.Bounds.Width);
- Assert.Equal (24, view.Bounds.Height);
- view.X = 0;
- view.Y = 0;
- view.SetRelativeLayout (top.Bounds);
- Assert.Equal (80, view.Bounds.Width);
- Assert.Equal (25, view.Bounds.Height);
- bool layoutStarted = false;
- view.LayoutStarted += (_) => layoutStarted = true;
- view.OnLayoutStarted (null);
- Assert.True (layoutStarted);
- view.LayoutComplete += (_) => layoutStarted = false;
- view.OnLayoutComplete (null);
- Assert.False (layoutStarted);
- view.X = Pos.Center () - 41;
- view.Y = Pos.Center () - 13;
- view.SetRelativeLayout (top.Bounds);
- view.ViewToScreen (0, 0, out rcol, out rrow);
- Assert.Equal (-1, rcol);
- Assert.Equal (-1, rrow);
- }
- [Fact]
- [AutoInitShutdown]
- public void Enabled_False_Sets_HasFocus_To_False ()
- {
- var wasClicked = false;
- var view = new Button ("Click Me");
- view.Clicked += () => wasClicked = !wasClicked;
- Application.Top.Add (view);
- view.ProcessKey (new KeyEvent (Key.Enter, null));
- Assert.True (wasClicked);
- view.MouseEvent (new MouseEvent () { Flags = MouseFlags.Button1Clicked });
- Assert.False (wasClicked);
- Assert.True (view.Enabled);
- Assert.True (view.CanFocus);
- Assert.True (view.HasFocus);
- view.Enabled = false;
- view.ProcessKey (new KeyEvent (Key.Enter, null));
- Assert.False (wasClicked);
- view.MouseEvent (new MouseEvent () { Flags = MouseFlags.Button1Clicked });
- Assert.False (wasClicked);
- Assert.False (view.Enabled);
- Assert.True (view.CanFocus);
- Assert.False (view.HasFocus);
- view.SetFocus ();
- Assert.False (view.HasFocus);
- }
- [Fact]
- [AutoInitShutdown]
- public void Enabled_Sets_Also_Sets_Subviews ()
- {
- var wasClicked = false;
- var button = new Button ("Click Me");
- button.Clicked += () => wasClicked = !wasClicked;
- var win = new Window () { Width = Dim.Fill (), Height = Dim.Fill () };
- win.Add (button);
- Application.Top.Add (win);
- var iterations = 0;
- Application.Iteration += () => {
- iterations++;
- button.ProcessKey (new KeyEvent (Key.Enter, null));
- Assert.True (wasClicked);
- button.MouseEvent (new MouseEvent () { Flags = MouseFlags.Button1Clicked });
- Assert.False (wasClicked);
- Assert.True (button.Enabled);
- Assert.True (button.CanFocus);
- Assert.True (button.HasFocus);
- Assert.True (win.Enabled);
- Assert.True (win.CanFocus);
- Assert.True (win.HasFocus);
- win.Enabled = false;
- button.ProcessKey (new KeyEvent (Key.Enter, null));
- Assert.False (wasClicked);
- button.MouseEvent (new MouseEvent () { Flags = MouseFlags.Button1Clicked });
- Assert.False (wasClicked);
- Assert.False (button.Enabled);
- Assert.True (button.CanFocus);
- Assert.False (button.HasFocus);
- Assert.False (win.Enabled);
- Assert.True (win.CanFocus);
- Assert.False (win.HasFocus);
- button.SetFocus ();
- Assert.False (button.HasFocus);
- Assert.False (win.HasFocus);
- win.SetFocus ();
- Assert.False (button.HasFocus);
- Assert.False (win.HasFocus);
- win.Enabled = true;
- win.FocusFirst ();
- Assert.True (button.HasFocus);
- Assert.True (win.HasFocus);
- Application.RequestStop ();
- };
- Application.Run ();
- Assert.Equal (1, iterations);
- }
- [Fact]
- [AutoInitShutdown]
- public void Visible_Sets_Also_Sets_Subviews ()
- {
- var button = new Button ("Click Me");
- var win = new Window () { Width = Dim.Fill (), Height = Dim.Fill () };
- win.Add (button);
- var top = Application.Top;
- top.Add (win);
- var iterations = 0;
- Application.Iteration += () => {
- iterations++;
- Assert.True (button.Visible);
- Assert.True (button.CanFocus);
- Assert.True (button.HasFocus);
- Assert.True (win.Visible);
- Assert.True (win.CanFocus);
- Assert.True (win.HasFocus);
- Assert.True (RunesCount () > 0);
- win.Visible = false;
- Assert.True (button.Visible);
- Assert.True (button.CanFocus);
- Assert.False (button.HasFocus);
- Assert.False (win.Visible);
- Assert.True (win.CanFocus);
- Assert.False (win.HasFocus);
- button.SetFocus ();
- Assert.False (button.HasFocus);
- Assert.False (win.HasFocus);
- win.SetFocus ();
- Assert.False (button.HasFocus);
- Assert.False (win.HasFocus);
- top.Redraw (top.Bounds);
- Assert.True (RunesCount () == 0);
- win.Visible = true;
- win.FocusFirst ();
- Assert.True (button.HasFocus);
- Assert.True (win.HasFocus);
- top.Redraw (top.Bounds);
- Assert.True (RunesCount () > 0);
- Application.RequestStop ();
- };
- Application.Run ();
- Assert.Equal (1, iterations);
- int RunesCount ()
- {
- var contents = ((FakeDriver)Application.Driver).Contents;
- var runesCount = 0;
- for (int i = 0; i < Application.Driver.Rows; i++) {
- for (int j = 0; j < Application.Driver.Cols; j++) {
- if (contents [i, j, 0] != ' ') {
- runesCount++;
- }
- }
- }
- return runesCount;
- }
- }
- [Fact]
- [AutoInitShutdown]
- public void GetTopSuperView_Test ()
- {
- var v1 = new View ();
- var fv1 = new FrameView ();
- fv1.Add (v1);
- var tf1 = new TextField ();
- var w1 = new Window ();
- w1.Add (fv1, tf1);
- var top1 = new Toplevel ();
- top1.Add (w1);
- var v2 = new View ();
- var fv2 = new FrameView ();
- fv2.Add (v2);
- var tf2 = new TextField ();
- var w2 = new Window ();
- w2.Add (fv2, tf2);
- var top2 = new Toplevel ();
- top2.Add (w2);
- Assert.Equal (top1, v1.GetTopSuperView ());
- Assert.Equal (top2, v2.GetTopSuperView ());
- }
- [Fact]
- [AutoInitShutdown]
- public void Excess_Text_Is_Erased_When_The_Width_Is_Reduced ()
- {
- var lbl = new Label ("123");
- Application.Top.Add (lbl);
- Application.Begin (Application.Top);
- Assert.True (lbl.AutoSize);
- Assert.Equal ("123 ", GetContents ());
- lbl.Text = "12";
- lbl.SuperView.Redraw (lbl.SuperView.NeedDisplay);
- Assert.Equal ("12 ", GetContents ());
- string GetContents ()
- {
- var text = "";
- for (int i = 0; i < 4; i++) {
- text += (char)Application.Driver.Contents [0, i, 0];
- }
- return text;
- }
- }
- [Fact]
- [AutoInitShutdown]
- public void CanFocus_Sets_To_False_Does_Not_Sets_HasFocus_To_True ()
- {
- var view = new View () { CanFocus = true };
- var win = new Window () { Width = Dim.Fill (), Height = Dim.Fill () };
- win.Add (view);
- Application.Top.Add (win);
- Application.Begin (Application.Top);
- Assert.True (view.CanFocus);
- Assert.True (view.HasFocus);
- view.CanFocus = false;
- Assert.False (view.CanFocus);
- Assert.False (view.HasFocus);
- Assert.Null (Application.Current.Focused);
- Assert.Null (Application.Current.MostFocused);
- }
- [Fact]
- [AutoInitShutdown]
- public void CanFocus_Sets_To_False_On_Single_View_Focus_View_On_Another_Toplevel ()
- {
- var view1 = new View () { Width = 10, Height = 1, CanFocus = true };
- var win1 = new Window () { Width = Dim.Percent (50), Height = Dim.Fill () };
- win1.Add (view1);
- var view2 = new View () { Width = 20, Height = 2, CanFocus = true };
- var win2 = new Window () { X = Pos.Right (win1), Width = Dim.Fill (), Height = Dim.Fill () };
- win2.Add (view2);
- Application.Top.Add (win1, win2);
- Application.Begin (Application.Top);
- Assert.True (view1.CanFocus);
- Assert.True (view1.HasFocus);
- Assert.True (view2.CanFocus);
- Assert.True (view2.HasFocus);
- view1.CanFocus = false;
- Assert.False (view1.CanFocus);
- Assert.False (view1.HasFocus);
- Assert.Equal (win2, Application.Current.Focused);
- Assert.Equal (view2, Application.Current.MostFocused);
- }
- [Fact]
- [AutoInitShutdown]
- public void CanFocus_Sets_To_False_With_Two_Views_Focus_Another_View_On_The_Same_Toplevel ()
- {
- var view1 = new View () { Width = 10, Height = 1, CanFocus = true };
- var view12 = new View () { Y = 5, Width = 10, Height = 1, CanFocus = true };
- var win1 = new Window () { Width = Dim.Percent (50), Height = Dim.Fill () };
- win1.Add (view1, view12);
- var view2 = new View () { Width = 20, Height = 2, CanFocus = true };
- var win2 = new Window () { X = Pos.Right (win1), Width = Dim.Fill (), Height = Dim.Fill () };
- win2.Add (view2);
- Application.Top.Add (win1, win2);
- Application.Begin (Application.Top);
- Assert.True (view1.CanFocus);
- Assert.True (view1.HasFocus);
- Assert.True (view2.CanFocus);
- Assert.True (view2.HasFocus);
- view1.CanFocus = false;
- Assert.False (view1.CanFocus);
- Assert.False (view1.HasFocus);
- Assert.Equal (win1, Application.Current.Focused);
- Assert.Equal (view12, Application.Current.MostFocused);
- }
- [Fact]
- [AutoInitShutdown]
- public void CanFocus_Sets_To_False_On_Toplevel_Focus_View_On_Another_Toplevel ()
- {
- var view1 = new View () { Width = 10, Height = 1, CanFocus = true };
- var win1 = new Window () { Width = Dim.Percent (50), Height = Dim.Fill () };
- win1.Add (view1);
- var view2 = new View () { Width = 20, Height = 2, CanFocus = true };
- var win2 = new Window () { X = Pos.Right (win1), Width = Dim.Fill (), Height = Dim.Fill () };
- win2.Add (view2);
- Application.Top.Add (win1, win2);
- Application.Begin (Application.Top);
- Assert.True (view1.CanFocus);
- Assert.True (view1.HasFocus);
- Assert.True (view2.CanFocus);
- Assert.True (view2.HasFocus);
- win1.CanFocus = false;
- Assert.False (view1.CanFocus);
- Assert.False (view1.HasFocus);
- Assert.False (win1.CanFocus);
- Assert.False (win1.HasFocus);
- Assert.Equal (win2, Application.Current.Focused);
- Assert.Equal (view2, Application.Current.MostFocused);
- }
- [Fact]
- [AutoInitShutdown]
- public void ProcessHotKey_Will_Invoke_ProcessKey_Only_For_The_MostFocused_With_Top_KeyPress_Event ()
- {
- var sbQuiting = false;
- var tfQuiting = false;
- var topQuiting = false;
- var sb = new StatusBar (new StatusItem [] {
- new StatusItem(Key.CtrlMask | Key.Q, "~^Q~ Quit", () => sbQuiting = true )
- });
- var tf = new TextField ();
- tf.KeyPress += Tf_KeyPress;
- void Tf_KeyPress (View.KeyEventEventArgs obj)
- {
- if (obj.KeyEvent.Key == (Key.Q | Key.CtrlMask)) {
- obj.Handled = tfQuiting = true;
- }
- }
- var win = new Window ();
- win.Add (sb, tf);
- var top = Application.Top;
- top.KeyPress += Top_KeyPress;
- void Top_KeyPress (View.KeyEventEventArgs obj)
- {
- if (obj.KeyEvent.Key == (Key.Q | Key.CtrlMask)) {
- obj.Handled = topQuiting = true;
- }
- }
- top.Add (win);
- Application.Begin (top);
- Assert.False (sbQuiting);
- Assert.False (tfQuiting);
- Assert.False (topQuiting);
- Application.Driver.SendKeys ('q', ConsoleKey.Q, false, false, true);
- Assert.False (sbQuiting);
- Assert.True (tfQuiting);
- Assert.False (topQuiting);
- tf.KeyPress -= Tf_KeyPress;
- tfQuiting = false;
- Application.Driver.SendKeys ('q', ConsoleKey.Q, false, false, true);
- Application.MainLoop.MainIteration ();
- Assert.True (sbQuiting);
- Assert.False (tfQuiting);
- Assert.False (topQuiting);
- sb.RemoveItem (0);
- sbQuiting = false;
- Application.Driver.SendKeys ('q', ConsoleKey.Q, false, false, true);
- Application.MainLoop.MainIteration ();
- Assert.False (sbQuiting);
- Assert.False (tfQuiting);
- Assert.True (topQuiting);
- }
- [Fact]
- [AutoInitShutdown]
- public void ProcessHotKey_Will_Invoke_ProcessKey_Only_For_The_MostFocused_Without_Top_KeyPress_Event ()
- {
- var sbQuiting = false;
- var tfQuiting = false;
- var sb = new StatusBar (new StatusItem [] {
- new StatusItem(Key.CtrlMask | Key.Q, "~^Q~ Quit", () => sbQuiting = true )
- });
- var tf = new TextField ();
- tf.KeyPress += Tf_KeyPress;
- void Tf_KeyPress (View.KeyEventEventArgs obj)
- {
- if (obj.KeyEvent.Key == (Key.Q | Key.CtrlMask)) {
- obj.Handled = tfQuiting = true;
- }
- }
- var win = new Window ();
- win.Add (sb, tf);
- var top = Application.Top;
- top.Add (win);
- Application.Begin (top);
- Assert.False (sbQuiting);
- Assert.False (tfQuiting);
- Application.Driver.SendKeys ('q', ConsoleKey.Q, false, false, true);
- Assert.False (sbQuiting);
- Assert.True (tfQuiting);
- tf.KeyPress -= Tf_KeyPress;
- tfQuiting = false;
- Application.Driver.SendKeys ('q', ConsoleKey.Q, false, false, true);
- Application.MainLoop.MainIteration ();
- Assert.True (sbQuiting);
- Assert.False (tfQuiting);
- }
- [Fact]
- [AutoInitShutdown]
- public void WindowDispose_CanFocusProblem ()
- {
- // Arrange
- Application.Init ();
- using var top = Toplevel.Create ();
- using var view = new View (
- x: 0,
- y: 1,
- text: nameof (WindowDispose_CanFocusProblem));
- using var window = new Window ();
- top.Add (window);
- window.Add (view);
- // Act
- Application.Begin (top);
- Application.Shutdown ();
- // Assert does Not throw NullReferenceException
- top.SetFocus ();
- }
- [Fact, AutoInitShutdown]
- public void DrawFrame_With_Positive_Positions ()
- {
- var view = new View (new Rect (0, 0, 8, 4));
- view.DrawContent += (_) => view.DrawFrame (view.Bounds, 0, true);
- Assert.Equal (Point.Empty, new Point (view.Frame.X, view.Frame.Y));
- Assert.Equal (new Size (8, 4), new Size (view.Frame.Width, view.Frame.Height));
- Application.Top.Add (view);
- Application.Begin (Application.Top);
- var expected = @"
- ┌──────┐
- │ │
- │ │
- └──────┘
- ";
- var pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
- Assert.Equal (new Rect (0, 0, 8, 4), pos);
- }
- [Fact, AutoInitShutdown]
- public void DrawFrame_With_Minimum_Size ()
- {
- var view = new View (new Rect (0, 0, 2, 2));
- view.DrawContent += (_) => view.DrawFrame (view.Bounds, 0, true);
- Assert.Equal (Point.Empty, new Point (view.Frame.X, view.Frame.Y));
- Assert.Equal (new Size (2, 2), new Size (view.Frame.Width, view.Frame.Height));
- Application.Top.Add (view);
- Application.Begin (Application.Top);
- var expected = @"
- ┌┐
- └┘
- ";
- var pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
- Assert.Equal (new Rect (0, 0, 2, 2), pos);
- }
- [Fact, AutoInitShutdown]
- public void DrawFrame_With_Negative_Positions ()
- {
- var view = new View (new Rect (-1, 0, 8, 4));
- view.DrawContent += (_) => view.DrawFrame (view.Bounds, 0, true);
- Assert.Equal (new Point (-1, 0), new Point (view.Frame.X, view.Frame.Y));
- Assert.Equal (new Size (8, 4), new Size (view.Frame.Width, view.Frame.Height));
- Application.Top.Add (view);
- Application.Begin (Application.Top);
- var expected = @"
- ──────┐
- │
- │
- ──────┘
- ";
- var pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
- Assert.Equal (new Rect (0, 0, 7, 4), pos);
- view.Frame = new Rect (-1, -1, 8, 4);
- Application.Refresh ();
- expected = @"
- │
- │
- ──────┘
- ";
- pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
- Assert.Equal (new Rect (6, 0, 7, 3), pos);
- view.Frame = new Rect (0, 0, 8, 4);
- ((FakeDriver)Application.Driver).SetBufferSize (7, 4);
- expected = @"
- ┌──────
- │
- │
- └──────
- ";
- pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
- Assert.Equal (new Rect (0, 0, 7, 4), pos);
- view.Frame = new Rect (0, 0, 8, 4);
- ((FakeDriver)Application.Driver).SetBufferSize (7, 3);
- }
- [Fact, AutoInitShutdown]
- public void DrawTextFormatter_Respects_The_Clip_Bounds ()
- {
- var view = new View (new Rect (0, 0, 20, 20));
- view.Add (new Label ("0123456789abcdefghij"));
- view.Add (new Label (0, 1, "1\n2\n3\n4\n5\n6\n7\n8\n9\n0"));
- view.Add (new Button (1, 1, "Press me!"));
- var scrollView = new ScrollView (new Rect (1, 1, 15, 10)) {
- ContentSize = new Size (40, 40),
- ShowHorizontalScrollIndicator = true,
- ShowVerticalScrollIndicator = true
- };
- scrollView.Add (view);
- var win = new Window (new Rect (1, 1, 20, 14), "Test");
- win.Add (scrollView);
- Application.Top.Add (win);
- Application.Begin (Application.Top);
- var expected = @"
- ┌ Test ────────────┐
- │ │
- │ 0123456789abcd▲ │
- │ 1[ Press me! ]┬ │
- │ 2 │ │
- │ 3 ┴ │
- │ 4 ░ │
- │ 5 ░ │
- │ 6 ░ │
- │ 7 ░ │
- │ 8 ▼ │
- │ ◄├───┤░░░░░░░► │
- │ │
- └──────────────────┘
- ";
- var pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
- Assert.Equal (new Rect (1, 1, 21, 14), pos);
- Assert.True (scrollView.ProcessKey (new KeyEvent (Key.CursorRight, new KeyModifiers ())));
- Application.Top.Redraw (Application.Top.Bounds);
- expected = @"
- ┌ Test ────────────┐
- │ │
- │ 123456789abcde▲ │
- │ [ Press me! ] ┬ │
- │ │ │
- │ ┴ │
- │ ░ │
- │ ░ │
- │ ░ │
- │ ░ │
- │ ▼ │
- │ ◄├───┤░░░░░░░► │
- │ │
- └──────────────────┘
- ";
- pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
- Assert.Equal (new Rect (1, 1, 21, 14), pos);
- Assert.True (scrollView.ProcessKey (new KeyEvent (Key.CursorRight, new KeyModifiers ())));
- Application.Top.Redraw (Application.Top.Bounds);
- expected = @"
- ┌ Test ────────────┐
- │ │
- │ 23456789abcdef▲ │
- │ Press me! ] ┬ │
- │ │ │
- │ ┴ │
- │ ░ │
- │ ░ │
- │ ░ │
- │ ░ │
- │ ▼ │
- │ ◄├────┤░░░░░░► │
- │ │
- └──────────────────┘
- ";
- pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
- Assert.Equal (new Rect (1, 1, 21, 14), pos);
- Assert.True (scrollView.ProcessKey (new KeyEvent (Key.CursorRight, new KeyModifiers ())));
- Application.Top.Redraw (Application.Top.Bounds);
- expected = @"
- ┌ Test ────────────┐
- │ │
- │ 3456789abcdefg▲ │
- │ Press me! ] ┬ │
- │ │ │
- │ ┴ │
- │ ░ │
- │ ░ │
- │ ░ │
- │ ░ │
- │ ▼ │
- │ ◄├────┤░░░░░░► │
- │ │
- └──────────────────┘
- ";
- pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
- Assert.Equal (new Rect (1, 1, 21, 14), pos);
- Assert.True (scrollView.ProcessKey (new KeyEvent (Key.CursorRight, new KeyModifiers ())));
- Application.Top.Redraw (Application.Top.Bounds);
- expected = @"
- ┌ Test ────────────┐
- │ │
- │ 456789abcdefgh▲ │
- │ ress me! ] ┬ │
- │ │ │
- │ ┴ │
- │ ░ │
- │ ░ │
- │ ░ │
- │ ░ │
- │ ▼ │
- │ ◄░├───┤░░░░░░► │
- │ │
- └──────────────────┘
- ";
- pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
- Assert.Equal (new Rect (1, 1, 21, 14), pos);
- Assert.True (scrollView.ProcessKey (new KeyEvent (Key.CursorRight, new KeyModifiers ())));
- Application.Top.Redraw (Application.Top.Bounds);
- expected = @"
- ┌ Test ────────────┐
- │ │
- │ 56789abcdefghi▲ │
- │ ess me! ] ┬ │
- │ │ │
- │ ┴ │
- │ ░ │
- │ ░ │
- │ ░ │
- │ ░ │
- │ ▼ │
- │ ◄░├────┤░░░░░► │
- │ │
- └──────────────────┘
- ";
- pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
- Assert.Equal (new Rect (1, 1, 21, 14), pos);
- Assert.True (scrollView.ProcessKey (new KeyEvent (Key.CursorRight, new KeyModifiers ())));
- Application.Top.Redraw (Application.Top.Bounds);
- expected = @"
- ┌ Test ────────────┐
- │ │
- │ 6789abcdefghij▲ │
- │ ss me! ] ┬ │
- │ │ │
- │ ┴ │
- │ ░ │
- │ ░ │
- │ ░ │
- │ ░ │
- │ ▼ │
- │ ◄░├────┤░░░░░► │
- │ │
- └──────────────────┘
- ";
- pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
- Assert.Equal (new Rect (1, 1, 21, 14), pos);
- Assert.True (scrollView.ProcessKey (new KeyEvent (Key.CursorRight, new KeyModifiers ())));
- Application.Top.Redraw (Application.Top.Bounds);
- expected = @"
- ┌ Test ────────────┐
- │ │
- │ 789abcdefghij ▲ │
- │ s me! ] ┬ │
- │ │ │
- │ ┴ │
- │ ░ │
- │ ░ │
- │ ░ │
- │ ░ │
- │ ▼ │
- │ ◄░░├───┤░░░░░► │
- │ │
- └──────────────────┘
- ";
- pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
- Assert.Equal (new Rect (1, 1, 21, 14), pos);
- Assert.True (scrollView.ProcessKey (new KeyEvent (Key.CtrlMask | Key.Home, new KeyModifiers ())));
- Assert.True (scrollView.ProcessKey (new KeyEvent (Key.CursorDown, new KeyModifiers ())));
- Application.Top.Redraw (Application.Top.Bounds);
- expected = @"
- ┌ Test ────────────┐
- │ │
- │ 1[ Press me! ]▲ │
- │ 2 ┬ │
- │ 3 │ │
- │ 4 ┴ │
- │ 5 ░ │
- │ 6 ░ │
- │ 7 ░ │
- │ 8 ░ │
- │ 9 ▼ │
- │ ◄├───┤░░░░░░░► │
- │ │
- └──────────────────┘
- ";
- pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
- Assert.Equal (new Rect (1, 1, 21, 14), pos);
- Assert.True (scrollView.ProcessKey (new KeyEvent (Key.CursorDown, new KeyModifiers ())));
- Application.Top.Redraw (Application.Top.Bounds);
- expected = @"
- ┌ Test ────────────┐
- │ │
- │ 2 ▲ │
- │ 3 ┬ │
- │ 4 │ │
- │ 5 ┴ │
- │ 6 ░ │
- │ 7 ░ │
- │ 8 ░ │
- │ 9 ░ │
- │ 0 ▼ │
- │ ◄├───┤░░░░░░░► │
- │ │
- └──────────────────┘
- ";
- pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
- Assert.Equal (new Rect (1, 1, 21, 14), pos);
- Assert.True (scrollView.ProcessKey (new KeyEvent (Key.CursorDown, new KeyModifiers ())));
- Application.Top.Redraw (Application.Top.Bounds);
- expected = @"
- ┌ Test ────────────┐
- │ │
- │ 3 ▲ │
- │ 4 ┬ │
- │ 5 │ │
- │ 6 ┴ │
- │ 7 ░ │
- │ 8 ░ │
- │ 9 ░ │
- │ 0 ░ │
- │ ▼ │
- │ ◄├───┤░░░░░░░► │
- │ │
- └──────────────────┘
- ";
- pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
- Assert.Equal (new Rect (1, 1, 21, 14), pos);
- }
- [Fact, AutoInitShutdown]
- public void Clear_Can_Use_Driver_AddRune_Or_AddStr_Methods ()
- {
- var view = new View () {
- Width = Dim.Fill (),
- Height = Dim.Fill ()
- };
- view.DrawContent += e => {
- view.DrawFrame (view.Bounds);
- var savedClip = Application.Driver.Clip;
- Application.Driver.Clip = new Rect (1, 1, view.Bounds.Width - 2, view.Bounds.Height - 2);
- for (int row = 0; row < view.Bounds.Height - 2; row++) {
- Application.Driver.Move (1, row + 1);
- for (int col = 0; col < view.Bounds.Width - 2; col++) {
- Application.Driver.AddStr ($"{col}");
- }
- }
- Application.Driver.Clip = savedClip;
- };
- Application.Top.Add (view);
- Application.Begin (Application.Top);
- ((FakeDriver)Application.Driver).SetBufferSize (20, 10);
- var expected = @"
- ┌──────────────────┐
- │012345678910111213│
- │012345678910111213│
- │012345678910111213│
- │012345678910111213│
- │012345678910111213│
- │012345678910111213│
- │012345678910111213│
- │012345678910111213│
- └──────────────────┘
- ";
- var pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
- Assert.Equal (new Rect (0, 0, 20, 10), pos);
- view.Clear ();
- expected = @"
- ";
- pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
- Assert.Equal (Rect.Empty, pos);
- }
- [Fact, AutoInitShutdown]
- public void Clear_Bounds_Can_Use_Driver_AddRune_Or_AddStr_Methods ()
- {
- var view = new View () {
- Width = Dim.Fill (),
- Height = Dim.Fill ()
- };
- view.DrawContent += e => {
- view.DrawFrame (view.Bounds);
- var savedClip = Application.Driver.Clip;
- Application.Driver.Clip = new Rect (1, 1, view.Bounds.Width - 2, view.Bounds.Height - 2);
- for (int row = 0; row < view.Bounds.Height - 2; row++) {
- Application.Driver.Move (1, row + 1);
- for (int col = 0; col < view.Bounds.Width - 2; col++) {
- Application.Driver.AddStr ($"{col}");
- }
- }
- Application.Driver.Clip = savedClip;
- };
- Application.Top.Add (view);
- Application.Begin (Application.Top);
- ((FakeDriver)Application.Driver).SetBufferSize (20, 10);
- var expected = @"
- ┌──────────────────┐
- │012345678910111213│
- │012345678910111213│
- │012345678910111213│
- │012345678910111213│
- │012345678910111213│
- │012345678910111213│
- │012345678910111213│
- │012345678910111213│
- └──────────────────┘
- ";
- var pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
- Assert.Equal (new Rect (0, 0, 20, 10), pos);
- view.Clear (view.Bounds);
- expected = @"
- ";
- pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
- Assert.Equal (Rect.Empty, pos);
- }
- [Fact, AutoInitShutdown]
- public void Width_Height_SetMinWidthHeight_Narrow_Wide_Runes ()
- {
- var text = $"First line{Environment.NewLine}Second line";
- var horizontalView = new View () {
- Width = 20,
- Text = text
- };
- var verticalView = new View () {
- Y = 3,
- Height = 20,
- Text = text,
- TextDirection = TextDirection.TopBottom_LeftRight
- };
- var win = new Window () {
- Width = Dim.Fill (),
- Height = Dim.Fill (),
- Text = "Window"
- };
- win.Add (horizontalView, verticalView);
- Application.Top.Add (win);
- Application.Begin (Application.Top);
- ((FakeDriver)Application.Driver).SetBufferSize (32, 32);
- Assert.False (horizontalView.AutoSize);
- Assert.False (verticalView.AutoSize);
- Assert.Equal (new Rect (0, 0, 20, 1), horizontalView.Frame);
- Assert.Equal (new Rect (0, 3, 1, 20), verticalView.Frame);
- var expected = @"
- ┌──────────────────────────────┐
- │First line Second li │
- │ │
- │ │
- │F │
- │i │
- │r │
- │s │
- │t │
- │ │
- │l │
- │i │
- │n │
- │e │
- │ │
- │S │
- │e │
- │c │
- │o │
- │n │
- │d │
- │ │
- │l │
- │i │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- └──────────────────────────────┘
- ";
- var pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
- Assert.Equal (new Rect (0, 0, 32, 32), pos);
- verticalView.Text = $"最初の行{Environment.NewLine}二行目";
- Application.Top.Redraw (Application.Top.Bounds);
- Assert.Equal (new Rect (0, 3, 2, 20), verticalView.Frame);
- expected = @"
- ┌──────────────────────────────┐
- │First line Second li │
- │ │
- │ │
- │最 │
- │初 │
- │の │
- │行 │
- │ │
- │二 │
- │行 │
- │目 │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- └──────────────────────────────┘
- ";
- pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
- Assert.Equal (new Rect (0, 0, 32, 32), pos);
- }
- [Fact, AutoInitShutdown]
- public void TextDirection_Toggle ()
- {
- var view = new View ();
- var win = new Window () { Width = Dim.Fill (), Height = Dim.Fill () };
- win.Add (view);
- Application.Top.Add (win);
- Application.Begin (Application.Top);
- ((FakeDriver)Application.Driver).SetBufferSize (22, 22);
- Assert.False (view.AutoSize);
- Assert.Equal (TextDirection.LeftRight_TopBottom, view.TextDirection);
- Assert.Equal (Rect.Empty, view.Frame);
- Assert.Equal ("Pos.Absolute(0)", view.X.ToString ());
- Assert.Equal ("Pos.Absolute(0)", view.Y.ToString ());
- Assert.Equal ("Dim.Absolute(0)", view.Width.ToString ());
- Assert.Equal ("Dim.Absolute(0)", view.Height.ToString ());
- var expected = @"
- ┌────────────────────┐
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- └────────────────────┘
- ";
- var pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
- Assert.Equal (new Rect (0, 0, 22, 22), pos);
- view.Text = "Hello World";
- view.Width = 11;
- Application.Refresh ();
- Assert.Equal (new Rect (0, 0, 11, 1), view.Frame);
- Assert.Equal ("Pos.Absolute(0)", view.X.ToString ());
- Assert.Equal ("Pos.Absolute(0)", view.Y.ToString ());
- Assert.Equal ("Dim.Absolute(11)", view.Width.ToString ());
- Assert.Equal ("Dim.Absolute(0)", view.Height.ToString ());
- expected = @"
- ┌────────────────────┐
- │Hello World │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- └────────────────────┘
- ";
- pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
- Assert.Equal (new Rect (0, 0, 22, 22), pos);
- view.AutoSize = true;
- view.Text = "Hello Worlds";
- Application.Refresh ();
- Assert.Equal (new Rect (0, 0, 12, 1), view.Frame);
- Assert.Equal ("Pos.Absolute(0)", view.X.ToString ());
- Assert.Equal ("Pos.Absolute(0)", view.Y.ToString ());
- Assert.Equal ("Dim.Absolute(11)", view.Width.ToString ());
- Assert.Equal ("Dim.Absolute(0)", view.Height.ToString ());
- expected = @"
- ┌────────────────────┐
- │Hello Worlds │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- └────────────────────┘
- ";
- pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
- Assert.Equal (new Rect (0, 0, 22, 22), pos);
- view.TextDirection = TextDirection.TopBottom_LeftRight;
- Application.Refresh ();
- Assert.Equal (new Rect (0, 0, 11, 12), view.Frame);
- Assert.Equal ("Pos.Absolute(0)", view.X.ToString ());
- Assert.Equal ("Pos.Absolute(0)", view.Y.ToString ());
- Assert.Equal ("Dim.Absolute(11)", view.Width.ToString ());
- Assert.Equal ("Dim.Absolute(0)", view.Height.ToString ());
- expected = @"
- ┌────────────────────┐
- │H │
- │e │
- │l │
- │l │
- │o │
- │ │
- │W │
- │o │
- │r │
- │l │
- │d │
- │s │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- └────────────────────┘
- ";
- pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
- Assert.Equal (new Rect (0, 0, 22, 22), pos);
- view.AutoSize = false;
- view.Height = 1;
- Application.Refresh ();
- Assert.Equal (new Rect (0, 0, 11, 1), view.Frame);
- Assert.Equal ("Pos.Absolute(0)", view.X.ToString ());
- Assert.Equal ("Pos.Absolute(0)", view.Y.ToString ());
- Assert.Equal ("Dim.Absolute(11)", view.Width.ToString ());
- Assert.Equal ("Dim.Absolute(1)", view.Height.ToString ());
- expected = @"
- ┌────────────────────┐
- │HelloWorlds │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- └────────────────────┘
- ";
- pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
- Assert.Equal (new Rect (0, 0, 22, 22), pos);
- view.PreserveTrailingSpaces = true;
- Application.Refresh ();
- Assert.Equal (new Rect (0, 0, 11, 1), view.Frame);
- Assert.Equal ("Pos.Absolute(0)", view.X.ToString ());
- Assert.Equal ("Pos.Absolute(0)", view.Y.ToString ());
- Assert.Equal ("Dim.Absolute(11)", view.Width.ToString ());
- Assert.Equal ("Dim.Absolute(1)", view.Height.ToString ());
- expected = @"
- ┌────────────────────┐
- │Hello World │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- └────────────────────┘
- ";
- pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
- Assert.Equal (new Rect (0, 0, 22, 22), pos);
- view.PreserveTrailingSpaces = false;
- var f = view.Frame;
- view.Width = f.Height;
- view.Height = f.Width;
- view.TextDirection = TextDirection.TopBottom_LeftRight;
- Application.Refresh ();
- Assert.Equal (new Rect (0, 0, 1, 11), view.Frame);
- Assert.Equal ("Pos.Absolute(0)", view.X.ToString ());
- Assert.Equal ("Pos.Absolute(0)", view.Y.ToString ());
- Assert.Equal ("Dim.Absolute(1)", view.Width.ToString ());
- Assert.Equal ("Dim.Absolute(11)", view.Height.ToString ());
- expected = @"
- ┌────────────────────┐
- │H │
- │e │
- │l │
- │l │
- │o │
- │ │
- │W │
- │o │
- │r │
- │l │
- │d │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- └────────────────────┘
- ";
- pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
- Assert.Equal (new Rect (0, 0, 22, 22), pos);
- view.AutoSize = true;
- Application.Refresh ();
- Assert.Equal (new Rect (0, 0, 1, 12), view.Frame);
- Assert.Equal ("Pos.Absolute(0)", view.X.ToString ());
- Assert.Equal ("Pos.Absolute(0)", view.Y.ToString ());
- Assert.Equal ("Dim.Absolute(1)", view.Width.ToString ());
- Assert.Equal ("Dim.Absolute(11)", view.Height.ToString ());
- expected = @"
- ┌────────────────────┐
- │H │
- │e │
- │l │
- │l │
- │o │
- │ │
- │W │
- │o │
- │r │
- │l │
- │d │
- │s │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- └────────────────────┘
- ";
- pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
- Assert.Equal (new Rect (0, 0, 22, 22), pos);
- }
- [Fact, AutoInitShutdown]
- public void Width_Height_AutoSize_True_Stay_True_If_TextFormatter_Size_Fit ()
- {
- var text = $"Fi_nish 終";
- var horizontalView = new View () {
- AutoSize = true,
- HotKeySpecifier = '_',
- Text = text
- };
- var verticalView = new View () {
- Y = 3,
- AutoSize = true,
- HotKeySpecifier = '_',
- Text = text,
- TextDirection = TextDirection.TopBottom_LeftRight
- };
- var win = new Window () {
- Width = Dim.Fill (),
- Height = Dim.Fill (),
- Text = "Window"
- };
- win.Add (horizontalView, verticalView);
- Application.Top.Add (win);
- Application.Begin (Application.Top);
- ((FakeDriver)Application.Driver).SetBufferSize (22, 22);
- Assert.True (horizontalView.AutoSize);
- Assert.True (verticalView.AutoSize);
- Assert.Equal (new Size (10, 1), horizontalView.TextFormatter.Size);
- Assert.Equal (new Size (2, 9), verticalView.TextFormatter.Size);
- Assert.Equal (new Rect (0, 0, 9, 1), horizontalView.Frame);
- Assert.Equal ("Pos.Absolute(0)", horizontalView.X.ToString ());
- Assert.Equal ("Pos.Absolute(0)", horizontalView.Y.ToString ());
- Assert.Equal ("Dim.Absolute(9)", horizontalView.Width.ToString ());
- Assert.Equal ("Dim.Absolute(1)", horizontalView.Height.ToString ());
- Assert.Equal (new Rect (0, 3, 2, 8), verticalView.Frame);
- Assert.Equal ("Pos.Absolute(0)", verticalView.X.ToString ());
- Assert.Equal ("Pos.Absolute(3)", verticalView.Y.ToString ());
- Assert.Equal ("Dim.Absolute(2)", verticalView.Width.ToString ());
- Assert.Equal ("Dim.Absolute(8)", verticalView.Height.ToString ());
- var expected = @"
- ┌────────────────────┐
- │Finish 終 │
- │ │
- │ │
- │F │
- │i │
- │n │
- │i │
- │s │
- │h │
- │ │
- │終 │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- └────────────────────┘
- ";
- var pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
- Assert.Equal (new Rect (0, 0, 22, 22), pos);
- verticalView.Text = $"最初_の行二行目";
- Application.Top.Redraw (Application.Top.Bounds);
- Assert.True (horizontalView.AutoSize);
- Assert.True (verticalView.AutoSize);
- // height was initialized with 8 and is kept as minimum
- Assert.Equal (new Rect (0, 3, 2, 8), verticalView.Frame);
- Assert.Equal ("Pos.Absolute(0)", verticalView.X.ToString ());
- Assert.Equal ("Pos.Absolute(3)", verticalView.Y.ToString ());
- Assert.Equal ("Dim.Absolute(2)", verticalView.Width.ToString ());
- Assert.Equal ("Dim.Absolute(8)", verticalView.Height.ToString ());
- expected = @"
- ┌────────────────────┐
- │Finish 終 │
- │ │
- │ │
- │最 │
- │初 │
- │の │
- │行 │
- │二 │
- │行 │
- │目 │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- └────────────────────┘
- ";
- pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
- Assert.Equal (new Rect (0, 0, 22, 22), pos);
- }
- [Fact, AutoInitShutdown]
- public void AutoSize_Stays_True_Center_HotKeySpecifier ()
- {
- var btn = new Button () {
- X = Pos.Center (),
- Y = Pos.Center (),
- Text = "Say He_llo 你"
- };
- var win = new Window () {
- Width = Dim.Fill (),
- Height = Dim.Fill (),
- Title = "Test Demo 你"
- };
- win.Add (btn);
- Application.Top.Add (win);
- Assert.True (btn.AutoSize);
- Application.Begin (Application.Top);
- ((FakeDriver)Application.Driver).SetBufferSize (30, 5);
- var expected = @"
- ┌ Test Demo 你 ──────────────┐
- │ │
- │ [ Say Hello 你 ] │
- │ │
- └────────────────────────────┘
- ";
- GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
- Assert.True (btn.AutoSize);
- btn.Text = "Say He_llo 你 changed";
- Assert.True (btn.AutoSize);
- Application.Refresh ();
- expected = @"
- ┌ Test Demo 你 ──────────────┐
- │ │
- │ [ Say Hello 你 changed ] │
- │ │
- └────────────────────────────┘
- ";
- GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
- }
- [Fact]
- public void GetTextFormatterBoundsSize_GetBoundsTextFormatterSize_HotKeySpecifier ()
- {
- var text = "Say Hello 你";
- var horizontalView = new View () { Text = text, AutoSize = true, HotKeySpecifier = '_' };
- var verticalView = new View () {
- Text = text,
- AutoSize = true,
- HotKeySpecifier = '_',
- TextDirection = TextDirection.TopBottom_LeftRight
- };
- Assert.True (horizontalView.AutoSize);
- Assert.Equal (new Rect (0, 0, 12, 1), horizontalView.Frame);
- Assert.Equal (new Size (12, 1), horizontalView.GetTextFormatterBoundsSize ());
- Assert.Equal (new Size (12, 1), horizontalView.GetBoundsTextFormatterSize ());
- Assert.Equal (horizontalView.TextFormatter.Size, horizontalView.GetBoundsTextFormatterSize ());
- Assert.Equal (horizontalView.Frame.Size, horizontalView.GetTextFormatterBoundsSize ());
- Assert.True (verticalView.AutoSize);
- Assert.Equal (new Rect (0, 0, 2, 11), verticalView.Frame);
- Assert.Equal (new Size (2, 11), verticalView.GetTextFormatterBoundsSize ());
- Assert.Equal (new Size (2, 11), verticalView.GetBoundsTextFormatterSize ());
- Assert.Equal (verticalView.TextFormatter.Size, verticalView.GetBoundsTextFormatterSize ());
- Assert.Equal (verticalView.Frame.Size, verticalView.GetTextFormatterBoundsSize ());
- text = "Say He_llo 你";
- horizontalView.Text = text;
- verticalView.Text = text;
- Assert.True (horizontalView.AutoSize);
- Assert.Equal (new Rect (0, 0, 12, 1), horizontalView.Frame);
- Assert.Equal (new Size (12, 1), horizontalView.GetTextFormatterBoundsSize ());
- Assert.Equal (new Size (13, 1), horizontalView.GetBoundsTextFormatterSize ());
- Assert.Equal (horizontalView.TextFormatter.Size, horizontalView.GetBoundsTextFormatterSize ());
- Assert.Equal (horizontalView.Frame.Size, horizontalView.GetTextFormatterBoundsSize ());
- Assert.True (verticalView.AutoSize);
- Assert.Equal (new Rect (0, 0, 2, 11), verticalView.Frame);
- Assert.Equal (new Size (2, 11), verticalView.GetTextFormatterBoundsSize ());
- Assert.Equal (new Size (2, 12), verticalView.GetBoundsTextFormatterSize ());
- Assert.Equal (verticalView.TextFormatter.Size, verticalView.GetBoundsTextFormatterSize ());
- Assert.Equal (verticalView.Frame.Size, verticalView.GetTextFormatterBoundsSize ());
- }
- [Fact, AutoInitShutdown]
- public void AutoSize_False_Equal_Before_And_After_IsInitialized_With_Differents_Orders ()
- {
- var view1 = new View () { Text = "Say Hello view1 你", AutoSize = false, Width = 10, Height = 5 };
- var view2 = new View () { Text = "Say Hello view2 你", Width = 10, Height = 5, AutoSize = false };
- var view3 = new View () { AutoSize = false, Width = 10, Height = 5, Text = "Say Hello view3 你" };
- var view4 = new View () {
- Text = "Say Hello view4 你",
- AutoSize = false,
- Width = 10,
- Height = 5,
- TextDirection = TextDirection.TopBottom_LeftRight
- };
- var view5 = new View () {
- Text = "Say Hello view5 你",
- Width = 10,
- Height = 5,
- AutoSize = false,
- TextDirection = TextDirection.TopBottom_LeftRight
- };
- var view6 = new View () {
- AutoSize = false,
- Width = 10,
- Height = 5,
- TextDirection = TextDirection.TopBottom_LeftRight,
- Text = "Say Hello view6 你",
- };
- Application.Top.Add (view1, view2, view3, view4, view5, view6);
- Assert.False (view1.IsInitialized);
- Assert.False (view2.IsInitialized);
- Assert.False (view3.IsInitialized);
- Assert.False (view4.IsInitialized);
- Assert.False (view5.IsInitialized);
- Assert.False (view1.AutoSize);
- Assert.Equal (new Rect (0, 0, 10, 5), view1.Frame);
- Assert.Equal ("Dim.Absolute(10)", view1.Width.ToString ());
- Assert.Equal ("Dim.Absolute(5)", view1.Height.ToString ());
- Assert.False (view2.AutoSize);
- Assert.Equal (new Rect (0, 0, 10, 5), view2.Frame);
- Assert.Equal ("Dim.Absolute(10)", view2.Width.ToString ());
- Assert.Equal ("Dim.Absolute(5)", view2.Height.ToString ());
- Assert.False (view3.AutoSize);
- Assert.Equal (new Rect (0, 0, 10, 5), view3.Frame);
- Assert.Equal ("Dim.Absolute(10)", view3.Width.ToString ());
- Assert.Equal ("Dim.Absolute(5)", view3.Height.ToString ());
- Assert.False (view4.AutoSize);
- Assert.Equal (new Rect (0, 0, 10, 5), view4.Frame);
- Assert.Equal ("Dim.Absolute(10)", view4.Width.ToString ());
- Assert.Equal ("Dim.Absolute(5)", view4.Height.ToString ());
- Assert.False (view5.AutoSize);
- Assert.Equal (new Rect (0, 0, 10, 5), view5.Frame);
- Assert.Equal ("Dim.Absolute(10)", view5.Width.ToString ());
- Assert.Equal ("Dim.Absolute(5)", view5.Height.ToString ());
- Assert.False (view6.AutoSize);
- Assert.Equal (new Rect (0, 0, 10, 5), view6.Frame);
- Assert.Equal ("Dim.Absolute(10)", view6.Width.ToString ());
- Assert.Equal ("Dim.Absolute(5)", view6.Height.ToString ());
- Application.Begin (Application.Top);
- Assert.True (view1.IsInitialized);
- Assert.True (view2.IsInitialized);
- Assert.True (view3.IsInitialized);
- Assert.True (view4.IsInitialized);
- Assert.True (view5.IsInitialized);
- Assert.False (view1.AutoSize);
- Assert.Equal (new Rect (0, 0, 10, 5), view1.Frame);
- Assert.Equal ("Dim.Absolute(10)", view1.Width.ToString ());
- Assert.Equal ("Dim.Absolute(5)", view1.Height.ToString ());
- Assert.False (view2.AutoSize);
- Assert.Equal (new Rect (0, 0, 10, 5), view2.Frame);
- Assert.Equal ("Dim.Absolute(10)", view2.Width.ToString ());
- Assert.Equal ("Dim.Absolute(5)", view2.Height.ToString ());
- Assert.False (view3.AutoSize);
- Assert.Equal (new Rect (0, 0, 10, 5), view3.Frame);
- Assert.Equal ("Dim.Absolute(10)", view3.Width.ToString ());
- Assert.Equal ("Dim.Absolute(5)", view3.Height.ToString ());
- Assert.False (view4.AutoSize);
- Assert.Equal (new Rect (0, 0, 10, 5), view4.Frame);
- Assert.Equal ("Dim.Absolute(10)", view4.Width.ToString ());
- Assert.Equal ("Dim.Absolute(5)", view4.Height.ToString ());
- Assert.False (view5.AutoSize);
- Assert.Equal (new Rect (0, 0, 10, 5), view5.Frame);
- Assert.Equal ("Dim.Absolute(10)", view5.Width.ToString ());
- Assert.Equal ("Dim.Absolute(5)", view5.Height.ToString ());
- Assert.False (view6.AutoSize);
- Assert.Equal (new Rect (0, 0, 10, 5), view6.Frame);
- Assert.Equal ("Dim.Absolute(10)", view6.Width.ToString ());
- Assert.Equal ("Dim.Absolute(5)", view6.Height.ToString ());
- }
- [Fact, AutoInitShutdown]
- public void AutoSize_True_Equal_Before_And_After_IsInitialized_With_Differents_Orders ()
- {
- var view1 = new View () { Text = "Say Hello view1 你", AutoSize = true, Width = 10, Height = 5 };
- var view2 = new View () { Text = "Say Hello view2 你", Width = 10, Height = 5, AutoSize = true };
- var view3 = new View () { AutoSize = true, Width = 10, Height = 5, Text = "Say Hello view3 你" };
- var view4 = new View () {
- Text = "Say Hello view4 你",
- AutoSize = true,
- Width = 10,
- Height = 5,
- TextDirection = TextDirection.TopBottom_LeftRight
- };
- var view5 = new View () {
- Text = "Say Hello view5 你",
- Width = 10,
- Height = 5,
- AutoSize = true,
- TextDirection = TextDirection.TopBottom_LeftRight
- };
- var view6 = new View () {
- AutoSize = true,
- Width = 10,
- Height = 5,
- TextDirection = TextDirection.TopBottom_LeftRight,
- Text = "Say Hello view6 你",
- };
- Application.Top.Add (view1, view2, view3, view4, view5, view6);
- Assert.False (view1.IsInitialized);
- Assert.False (view2.IsInitialized);
- Assert.False (view3.IsInitialized);
- Assert.False (view4.IsInitialized);
- Assert.False (view5.IsInitialized);
- Assert.True (view1.AutoSize);
- Assert.Equal (new Rect (0, 0, 18, 5), view1.Frame);
- Assert.Equal ("Dim.Absolute(10)", view1.Width.ToString ());
- Assert.Equal ("Dim.Absolute(5)", view1.Height.ToString ());
- Assert.True (view2.AutoSize);
- Assert.Equal (new Rect (0, 0, 18, 5), view2.Frame);
- Assert.Equal ("Dim.Absolute(10)", view2.Width.ToString ());
- Assert.Equal ("Dim.Absolute(5)", view2.Height.ToString ());
- Assert.True (view3.AutoSize);
- Assert.Equal (new Rect (0, 0, 18, 5), view3.Frame);
- Assert.Equal ("Dim.Absolute(10)", view3.Width.ToString ());
- Assert.Equal ("Dim.Absolute(5)", view3.Height.ToString ());
- Assert.True (view4.AutoSize);
- Assert.Equal (new Rect (0, 0, 10, 17), view4.Frame);
- Assert.Equal ("Dim.Absolute(10)", view4.Width.ToString ());
- Assert.Equal ("Dim.Absolute(5)", view4.Height.ToString ());
- Assert.True (view5.AutoSize);
- Assert.Equal (new Rect (0, 0, 10, 17), view5.Frame);
- Assert.Equal ("Dim.Absolute(10)", view5.Width.ToString ());
- Assert.Equal ("Dim.Absolute(5)", view5.Height.ToString ());
- Assert.True (view6.AutoSize);
- Assert.Equal (new Rect (0, 0, 10, 17), view6.Frame);
- Assert.Equal ("Dim.Absolute(10)", view6.Width.ToString ());
- Assert.Equal ("Dim.Absolute(5)", view6.Height.ToString ());
- Application.Begin (Application.Top);
- Assert.True (view1.IsInitialized);
- Assert.True (view2.IsInitialized);
- Assert.True (view3.IsInitialized);
- Assert.True (view4.IsInitialized);
- Assert.True (view5.IsInitialized);
- Assert.True (view1.AutoSize);
- Assert.Equal (new Rect (0, 0, 18, 5), view1.Frame);
- Assert.Equal ("Dim.Absolute(10)", view1.Width.ToString ());
- Assert.Equal ("Dim.Absolute(5)", view1.Height.ToString ());
- Assert.True (view2.AutoSize);
- Assert.Equal (new Rect (0, 0, 18, 5), view2.Frame);
- Assert.Equal ("Dim.Absolute(10)", view2.Width.ToString ());
- Assert.Equal ("Dim.Absolute(5)", view2.Height.ToString ());
- Assert.True (view3.AutoSize);
- Assert.Equal (new Rect (0, 0, 18, 5), view3.Frame);
- Assert.Equal ("Dim.Absolute(10)", view3.Width.ToString ());
- Assert.Equal ("Dim.Absolute(5)", view3.Height.ToString ());
- Assert.True (view4.AutoSize);
- Assert.Equal (new Rect (0, 0, 10, 17), view4.Frame);
- Assert.Equal ("Dim.Absolute(10)", view4.Width.ToString ());
- Assert.Equal ("Dim.Absolute(5)", view4.Height.ToString ());
- Assert.True (view5.AutoSize);
- Assert.Equal (new Rect (0, 0, 10, 17), view5.Frame);
- Assert.Equal ("Dim.Absolute(10)", view5.Width.ToString ());
- Assert.Equal ("Dim.Absolute(5)", view5.Height.ToString ());
- Assert.True (view6.AutoSize);
- Assert.Equal (new Rect (0, 0, 10, 17), view6.Frame);
- Assert.Equal ("Dim.Absolute(10)", view6.Width.ToString ());
- Assert.Equal ("Dim.Absolute(5)", view6.Height.ToString ());
- }
- [Fact, AutoInitShutdown]
- public void Setting_Frame_Dont_Respect_AutoSize_True_On_Layout_Absolute ()
- {
- var view1 = new View (new Rect (0, 0, 10, 0)) { Text = "Say Hello view1 你", AutoSize = true };
- var view2 = new View (new Rect (0, 0, 0, 10)) {
- Text = "Say Hello view2 你",
- AutoSize = true,
- TextDirection = TextDirection.TopBottom_LeftRight
- };
- Application.Top.Add (view1, view2);
- var rs = Application.Begin (Application.Top);
- Assert.True (view1.AutoSize);
- Assert.Equal (LayoutStyle.Absolute, view1.LayoutStyle);
- Assert.Equal (new Rect (0, 0, 18, 1), view1.Frame);
- Assert.Equal ("Pos.Absolute(0)", view1.X.ToString ());
- Assert.Equal ("Pos.Absolute(0)", view1.Y.ToString ());
- Assert.Equal ("Dim.Absolute(18)", view1.Width.ToString ());
- Assert.Equal ("Dim.Absolute(1)", view1.Height.ToString ());
- Assert.True (view2.AutoSize);
- Assert.Equal (LayoutStyle.Absolute, view2.LayoutStyle);
- Assert.Equal (new Rect (0, 0, 2, 17), view2.Frame);
- Assert.Equal ("Pos.Absolute(0)", view2.X.ToString ());
- Assert.Equal ("Pos.Absolute(0)", view2.Y.ToString ());
- Assert.Equal ("Dim.Absolute(2)", view2.Width.ToString ());
- Assert.Equal ("Dim.Absolute(17)", view2.Height.ToString ());
- view1.Frame = new Rect (0, 0, 25, 4);
- bool firstIteration = false;
- Application.RunMainLoopIteration (ref rs, true, ref firstIteration);
- Assert.True (view1.AutoSize);
- Assert.Equal (LayoutStyle.Absolute, view1.LayoutStyle);
- Assert.Equal (new Rect (0, 0, 25, 4), view1.Frame);
- Assert.Equal ("Pos.Absolute(0)", view1.X.ToString ());
- Assert.Equal ("Pos.Absolute(0)", view1.Y.ToString ());
- Assert.Equal ("Dim.Absolute(18)", view1.Width.ToString ());
- Assert.Equal ("Dim.Absolute(1)", view1.Height.ToString ());
- view2.Frame = new Rect (0, 0, 1, 25);
- Application.RunMainLoopIteration (ref rs, true, ref firstIteration);
- Assert.True (view2.AutoSize);
- Assert.Equal (LayoutStyle.Absolute, view2.LayoutStyle);
- Assert.Equal (new Rect (0, 0, 1, 25), view2.Frame);
- Assert.Equal ("Pos.Absolute(0)", view2.X.ToString ());
- Assert.Equal ("Pos.Absolute(0)", view2.Y.ToString ());
- Assert.Equal ("Dim.Absolute(2)", view2.Width.ToString ());
- Assert.Equal ("Dim.Absolute(17)", view2.Height.ToString ());
- }
- [Fact, AutoInitShutdown]
- public void Pos_Dim_Are_Null_If_Not_Initialized_On_Constructor_IsAdded_False ()
- {
- var top = Application.Top;
- var view1 = new View ();
- Assert.False (view1.IsAdded);
- Assert.Null (view1.X);
- Assert.Null (view1.Y);
- Assert.Null (view1.Width);
- Assert.Null (view1.Height);
- top.Add (view1);
- Assert.True (view1.IsAdded);
- Assert.Equal ("Pos.Absolute(0)", view1.X.ToString ());
- Assert.Equal ("Pos.Absolute(0)", view1.Y.ToString ());
- Assert.Equal ("Dim.Absolute(0)", view1.Width.ToString ());
- Assert.Equal ("Dim.Absolute(0)", view1.Height.ToString ());
- var view2 = new View () {
- X = Pos.Center (),
- Y = Pos.Center (),
- Width = Dim.Fill (),
- Height = Dim.Fill ()
- };
- Assert.False (view2.IsAdded);
- Assert.Equal ("Pos.Center", view2.X.ToString ());
- Assert.Equal ("Pos.Center", view2.Y.ToString ());
- Assert.Equal ("Dim.Fill(margin=0)", view2.Width.ToString ());
- Assert.Equal ("Dim.Fill(margin=0)", view2.Height.ToString ());
- top.Add (view2);
- Assert.True (view2.IsAdded);
- Assert.Equal ("Pos.Center", view2.X.ToString ());
- Assert.Equal ("Pos.Center", view2.Y.ToString ());
- Assert.Equal ("Dim.Fill(margin=0)", view2.Width.ToString ());
- Assert.Equal ("Dim.Fill(margin=0)", view2.Height.ToString ());
- }
- [Fact]
- public void IsAdded_Added_Removed ()
- {
- var top = new Toplevel ();
- var view = new View ();
- Assert.False (view.IsAdded);
- top.Add (view);
- Assert.True (view.IsAdded);
- top.Remove (view);
- Assert.False (view.IsAdded);
- }
- [Fact]
- public void AutoSize_Layout_Absolute_Without_Add_Horizontal_Narrow ()
- {
- var view = new View (new Rect (0, 0, 10, 1)) {
- Text = "Test"
- };
- Assert.False (view.IsAdded);
- Assert.False (view.AutoSize);
- Assert.Equal (new Rect (0, 0, 10, 1), view.Frame);
- Assert.Equal ("Test", view.TextFormatter.Text);
- view.Text = "First line\nSecond line";
- Assert.False (view.AutoSize);
- Assert.Equal (new Rect (0, 0, 10, 1), view.Frame);
- Assert.Equal ("First line\nSecond line", view.TextFormatter.Text);
- view.AutoSize = true;
- Assert.True (view.AutoSize);
- Assert.Equal (new Rect (0, 0, 11, 2), view.Frame);
- Assert.Equal ("First line\nSecond line", view.TextFormatter.Text);
- view.AutoSize = false;
- Assert.False (view.AutoSize);
- Assert.Equal (new Rect (0, 0, 11, 2), view.Frame);
- Assert.Equal ("First line\nSecond line", view.TextFormatter.Text);
- }
- [Fact, AutoInitShutdown]
- public void AutoSize_Layout_Absolute_With_Add_Horizontal_Narrow ()
- {
- var view = new View (new Rect (0, 0, 10, 1)) {
- Text = "Test"
- };
- Application.Top.Add (view);
- Application.Begin (Application.Top);
- Assert.True (view.IsAdded);
- Assert.False (view.AutoSize);
- Assert.Equal (new Rect (0, 0, 10, 1), view.Frame);
- Assert.Equal ("Test", view.TextFormatter.Text);
- GraphViewTests.AssertDriverContentsWithFrameAre (@"
- Test
- ", output);
- view.Text = "First line\nSecond line";
- Assert.False (view.AutoSize);
- Assert.Equal (new Rect (0, 0, 10, 1), view.Frame);
- Assert.Equal ("First line\nSecond line", view.TextFormatter.Text);
- Application.Refresh ();
- GraphViewTests.AssertDriverContentsWithFrameAre (@"
- First line
- ", output);
- view.AutoSize = true;
- Assert.True (view.AutoSize);
- Assert.Equal (new Rect (0, 0, 11, 2), view.Frame);
- Assert.Equal ("First line\nSecond line", view.TextFormatter.Text);
- Application.Refresh ();
- GraphViewTests.AssertDriverContentsWithFrameAre (@"
- First line
- Second line
- ", output);
- view.AutoSize = false;
- Assert.False (view.AutoSize);
- Assert.Equal (new Rect (0, 0, 10, 1), view.Frame);
- Assert.Equal ("First line\nSecond line", view.TextFormatter.Text);
- Application.Refresh ();
- GraphViewTests.AssertDriverContentsWithFrameAre (@"
- First line
- ", output);
- }
- [Fact]
- public void AutoSize_Layout_Absolute_Without_Add_Vertical_Narrow ()
- {
- var view = new View (new Rect (0, 0, 1, 10)) {
- Text = "Test",
- TextDirection = TextDirection.TopBottom_LeftRight
- };
- Assert.False (view.IsAdded);
- Assert.False (view.AutoSize);
- Assert.Equal (new Rect (0, 0, 1, 10), view.Frame);
- Assert.Equal ("Test", view.TextFormatter.Text);
- view.Text = "First line\nSecond line";
- Assert.False (view.AutoSize);
- Assert.Equal (new Rect (0, 0, 1, 10), view.Frame);
- Assert.Equal ("First line\nSecond line", view.TextFormatter.Text);
- view.AutoSize = true;
- Assert.True (view.AutoSize);
- Assert.Equal (new Rect (0, 0, 2, 11), view.Frame);
- Assert.Equal ("First line\nSecond line", view.TextFormatter.Text);
- view.AutoSize = false;
- Assert.False (view.AutoSize);
- Assert.Equal (new Rect (0, 0, 2, 11), view.Frame);
- Assert.Equal ("First line\nSecond line", view.TextFormatter.Text);
- }
- [Fact, AutoInitShutdown]
- public void AutoSize_Layout_Absolute_With_Add_Vertical_Narrow ()
- {
- var view = new View (new Rect (0, 0, 1, 10)) {
- Text = "Test",
- TextDirection = TextDirection.TopBottom_LeftRight
- };
- Application.Top.Add (view);
- Application.Begin (Application.Top);
- Assert.True (view.IsAdded);
- Assert.False (view.AutoSize);
- Assert.Equal (new Rect (0, 0, 1, 10), view.Frame);
- Assert.Equal ("Test", view.TextFormatter.Text);
- GraphViewTests.AssertDriverContentsWithFrameAre (@"
- T
- e
- s
- t
- ", output);
- view.Text = "First line\nSecond line";
- Assert.False (view.AutoSize);
- Assert.Equal (new Rect (0, 0, 1, 10), view.Frame);
- Assert.Equal ("First line\nSecond line", view.TextFormatter.Text);
- Application.Refresh ();
- GraphViewTests.AssertDriverContentsWithFrameAre (@"
- F
- i
- r
- s
- t
-
- l
- i
- n
- e
- ", output);
- view.AutoSize = true;
- Assert.True (view.AutoSize);
- Assert.Equal (new Rect (0, 0, 2, 11), view.Frame);
- Assert.Equal ("First line\nSecond line", view.TextFormatter.Text);
- Application.Refresh ();
- GraphViewTests.AssertDriverContentsWithFrameAre (@"
- FS
- ie
- rc
- so
- tn
- d
- l
- il
- ni
- en
- e
- ", output);
- view.AutoSize = false;
- Assert.False (view.AutoSize);
- Assert.Equal (new Rect (0, 0, 1, 10), view.Frame);
- Assert.Equal ("First line\nSecond line", view.TextFormatter.Text);
- Application.Refresh ();
- GraphViewTests.AssertDriverContentsWithFrameAre (@"
- F
- i
- r
- s
- t
-
- l
- i
- n
- e
- ", output);
- }
- [Fact]
- public void AutoSize_Layout_Absolute_Without_Add_Horizontal_Wide ()
- {
- var view = new View (new Rect (0, 0, 10, 1)) {
- Text = "Test 你"
- };
- Assert.False (view.IsAdded);
- Assert.False (view.AutoSize);
- Assert.Equal (new Rect (0, 0, 10, 1), view.Frame);
- Assert.Equal ("Test 你", view.TextFormatter.Text);
- view.Text = "First line 你\nSecond line 你";
- Assert.False (view.AutoSize);
- Assert.Equal (new Rect (0, 0, 10, 1), view.Frame);
- Assert.Equal ("First line 你\nSecond line 你", view.TextFormatter.Text);
- view.AutoSize = true;
- Assert.True (view.AutoSize);
- Assert.Equal (new Rect (0, 0, 14, 2), view.Frame);
- Assert.Equal ("First line 你\nSecond line 你", view.TextFormatter.Text);
- view.AutoSize = false;
- Assert.False (view.AutoSize);
- Assert.Equal (new Rect (0, 0, 14, 2), view.Frame);
- Assert.Equal ("First line 你\nSecond line 你", view.TextFormatter.Text);
- }
- [Fact, AutoInitShutdown]
- public void AutoSize_Layout_Absolute_With_Add_Horizontal_Wide ()
- {
- var view = new View (new Rect (0, 0, 10, 1)) {
- Text = "Test 你"
- };
- Application.Top.Add (view);
- Application.Begin (Application.Top);
- Assert.True (view.IsAdded);
- Assert.False (view.AutoSize);
- Assert.Equal (new Rect (0, 0, 10, 1), view.Frame);
- Assert.Equal ("Test 你", view.TextFormatter.Text);
- GraphViewTests.AssertDriverContentsWithFrameAre (@"
- Test 你
- ", output);
- view.Text = "First line 你\nSecond line 你";
- Assert.False (view.AutoSize);
- Assert.Equal (new Rect (0, 0, 10, 1), view.Frame);
- Assert.Equal ("First line 你\nSecond line 你", view.TextFormatter.Text);
- Application.Refresh ();
- GraphViewTests.AssertDriverContentsWithFrameAre (@"
- First line
- ", output);
- view.AutoSize = true;
- Assert.True (view.AutoSize);
- Assert.Equal (new Rect (0, 0, 14, 2), view.Frame);
- Assert.Equal ("First line 你\nSecond line 你", view.TextFormatter.Text);
- Application.Refresh ();
- GraphViewTests.AssertDriverContentsWithFrameAre (@"
- First line 你
- Second line 你
- ", output);
- view.AutoSize = false;
- Assert.False (view.AutoSize);
- Assert.Equal (new Rect (0, 0, 10, 1), view.Frame);
- Assert.Equal ("First line 你\nSecond line 你", view.TextFormatter.Text);
- Application.Refresh ();
- GraphViewTests.AssertDriverContentsWithFrameAre (@"
- First line
- ", output);
- }
- [Fact]
- public void AutoSize_Layout_Absolute_Without_Add_Vertical_Wide ()
- {
- var view = new View (new Rect (0, 0, 1, 10)) {
- Text = "Test 你",
- TextDirection = TextDirection.TopBottom_LeftRight
- };
- Assert.False (view.IsAdded);
- Assert.False (view.AutoSize);
- // SetMinWidthHeight ensuring the minimum width for the wide char
- Assert.Equal (new Rect (0, 0, 2, 10), view.Frame);
- Assert.Equal ("Test 你", view.TextFormatter.Text);
- view.Text = "First line 你\nSecond line 你";
- Assert.False (view.AutoSize);
- Assert.Equal (new Rect (0, 0, 2, 10), view.Frame);
- Assert.Equal ("First line 你\nSecond line 你", view.TextFormatter.Text);
- view.AutoSize = true;
- Assert.True (view.AutoSize);
- Assert.Equal (new Rect (0, 0, 4, 13), view.Frame);
- Assert.Equal ("First line 你\nSecond line 你", view.TextFormatter.Text);
- view.AutoSize = false;
- Assert.False (view.AutoSize);
- Assert.Equal (new Rect (0, 0, 4, 13), view.Frame);
- Assert.Equal ("First line 你\nSecond line 你", view.TextFormatter.Text);
- }
- [Fact, AutoInitShutdown]
- public void AutoSize_Layout_Absolute_With_Add_Vertical_Wide ()
- {
- var view = new View (new Rect (0, 0, 1, 10)) {
- Text = "Test 你",
- TextDirection = TextDirection.TopBottom_LeftRight
- };
- Application.Top.Add (view);
- Application.Begin (Application.Top);
- Assert.True (view.IsAdded);
- Assert.False (view.AutoSize);
- // SetMinWidthHeight ensuring the minimum width for the wide char
- Assert.Equal (new Rect (0, 0, 2, 10), view.Frame);
- Assert.Equal ("Test 你", view.TextFormatter.Text);
- GraphViewTests.AssertDriverContentsWithFrameAre (@"
- T
- e
- s
- t
-
- 你
- ", output);
- view.Text = "First line 你\nSecond line 你";
- Assert.False (view.AutoSize);
- Assert.Equal (new Rect (0, 0, 2, 10), view.Frame);
- Assert.Equal ("First line 你\nSecond line 你", view.TextFormatter.Text);
- Application.Refresh ();
- GraphViewTests.AssertDriverContentsWithFrameAre (@"
- F
- i
- r
- s
- t
-
- l
- i
- n
- e
- ", output);
- view.AutoSize = true;
- Assert.True (view.AutoSize);
- Assert.Equal (new Rect (0, 0, 4, 13), view.Frame);
- Assert.Equal ("First line 你\nSecond line 你", view.TextFormatter.Text);
- Application.Refresh ();
- GraphViewTests.AssertDriverContentsWithFrameAre (@"
- F S
- i e
- r c
- s o
- t n
- d
- l
- i l
- n i
- e n
- e
- 你
- 你
- ", output);
- view.AutoSize = false;
- Assert.False (view.AutoSize);
- Assert.Equal (new Rect (0, 0, 2, 10), view.Frame);
- Assert.Equal ("First line 你\nSecond line 你", view.TextFormatter.Text);
- Application.Refresh ();
- GraphViewTests.AssertDriverContentsWithFrameAre (@"
- F
- i
- r
- s
- t
-
- l
- i
- n
- e
- ", output);
- }
- [Fact, AutoInitShutdown]
- public void Visible_Clear_The_View_Output ()
- {
- var label = new Label ("Testing visibility.");
- var win = new Window ();
- win.Add (label);
- var top = Application.Top;
- top.Add (win);
- Application.Begin (top);
- Assert.True (label.Visible);
- ((FakeDriver)Application.Driver).SetBufferSize (30, 5);
- GraphViewTests.AssertDriverContentsWithFrameAre (@"
- ┌────────────────────────────┐
- │Testing visibility. │
- │ │
- │ │
- └────────────────────────────┘
- ", output);
- label.Visible = false;
- GraphViewTests.AssertDriverContentsWithFrameAre (@"
- ┌────────────────────────────┐
- │ │
- │ │
- │ │
- └────────────────────────────┘
- ", output);
- }
- [Fact, AutoInitShutdown]
- public void ClearOnVisibleFalse_Gets_Sets ()
- {
- var text = "This is a test\nThis is a test\nThis is a test\nThis is a test\nThis is a test\nThis is a test";
- var label = new Label (text);
- Application.Top.Add (label);
- var sbv = new ScrollBarView (label, true, false) {
- Size = 100,
- ClearOnVisibleFalse = false
- };
- Application.Begin (Application.Top);
- Assert.True (sbv.Visible);
- GraphViewTests.AssertDriverContentsWithFrameAre (@"
- This is a tes▲
- This is a tes┬
- This is a tes┴
- This is a tes░
- This is a tes░
- This is a tes▼
- ", output);
- sbv.Visible = false;
- Assert.False (sbv.Visible);
- Application.Top.Redraw (Application.Top.Bounds);
- GraphViewTests.AssertDriverContentsWithFrameAre (@"
- This is a test
- This is a test
- This is a test
- This is a test
- This is a test
- This is a test
- ", output);
- sbv.Visible = true;
- Assert.True (sbv.Visible);
- Application.Top.Redraw (Application.Top.Bounds);
- GraphViewTests.AssertDriverContentsWithFrameAre (@"
- This is a tes▲
- This is a tes┬
- This is a tes┴
- This is a tes░
- This is a tes░
- This is a tes▼
- ", output);
- sbv.ClearOnVisibleFalse = true;
- sbv.Visible = false;
- Assert.False (sbv.Visible);
- GraphViewTests.AssertDriverContentsWithFrameAre (@"
- This is a tes
- This is a tes
- This is a tes
- This is a tes
- This is a tes
- This is a tes
- ", output);
- }
- [Fact, AutoInitShutdown]
- public void DrawContentComplete_Event_Is_Always_Called ()
- {
- var viewCalled = false;
- var tvCalled = false;
- var view = new View ("View") { Width = 10, Height = 10 };
- view.DrawContentComplete += (e) => viewCalled = true;
- var tv = new TextView () { Y = 11, Width = 10, Height = 10 };
- tv.DrawContentComplete += (e) => tvCalled = true;
- Application.Top.Add (view, tv);
- Application.Begin (Application.Top);
- Assert.True (viewCalled);
- Assert.True (tvCalled);
- }
- [Fact, AutoInitShutdown]
- public void KeyDown_And_KeyUp_Events_Must_Called_Before_OnKeyDown_And_OnKeyUp ()
- {
- var keyDown = false;
- var keyPress = false;
- var keyUp = false;
- var view = new DerivedView ();
- view.KeyDown += (e) => {
- Assert.Equal (Key.a, e.KeyEvent.Key);
- Assert.False (keyDown);
- Assert.False (view.IsKeyDown);
- e.Handled = true;
- keyDown = true;
- };
- view.KeyPress += (e) => {
- Assert.Equal (Key.a, e.KeyEvent.Key);
- Assert.False (keyPress);
- Assert.False (view.IsKeyPress);
- e.Handled = true;
- keyPress = true;
- };
- view.KeyUp += (e) => {
- Assert.Equal (Key.a, e.KeyEvent.Key);
- Assert.False (keyUp);
- Assert.False (view.IsKeyUp);
- e.Handled = true;
- keyUp = true;
- };
- Application.Top.Add (view);
- Console.MockKeyPresses.Push (new ConsoleKeyInfo ('a', ConsoleKey.A, false, false, false));
- Application.Iteration += () => Application.RequestStop ();
- Assert.True (view.CanFocus);
- Application.Run ();
- Application.Shutdown ();
- Assert.True (keyDown);
- Assert.True (keyPress);
- Assert.True (keyUp);
- Assert.False (view.IsKeyDown);
- Assert.False (view.IsKeyPress);
- Assert.False (view.IsKeyUp);
- }
- public class DerivedView : View {
- public DerivedView ()
- {
- CanFocus = true;
- }
- public bool IsKeyDown { get; set; }
- public bool IsKeyPress { get; set; }
- public bool IsKeyUp { get; set; }
- public override bool OnKeyDown (KeyEvent keyEvent)
- {
- IsKeyDown = true;
- return true;
- }
- public override bool ProcessKey (KeyEvent keyEvent)
- {
- IsKeyPress = true;
- return true;
- }
- public override bool OnKeyUp (KeyEvent keyEvent)
- {
- IsKeyUp = true;
- return true;
- }
- }
- [Theory, AutoInitShutdown]
- [InlineData (true, false, false)]
- [InlineData (true, true, false)]
- [InlineData (true, true, true)]
- public void KeyDown_And_KeyUp_Events_With_Only_Key_Modifiers (bool shift, bool alt, bool control)
- {
- var keyDown = false;
- var keyPress = false;
- var keyUp = false;
- var view = new DerivedView ();
- view.KeyDown += (e) => {
- Assert.Equal (-1, e.KeyEvent.KeyValue);
- Assert.Equal (shift, e.KeyEvent.IsShift);
- Assert.Equal (alt, e.KeyEvent.IsAlt);
- Assert.Equal (control, e.KeyEvent.IsCtrl);
- Assert.False (keyDown);
- Assert.False (view.IsKeyDown);
- keyDown = true;
- };
- view.KeyPress += (e) => {
- keyPress = true;
- };
- view.KeyUp += (e) => {
- Assert.Equal (-1, e.KeyEvent.KeyValue);
- Assert.Equal (shift, e.KeyEvent.IsShift);
- Assert.Equal (alt, e.KeyEvent.IsAlt);
- Assert.Equal (control, e.KeyEvent.IsCtrl);
- Assert.False (keyUp);
- Assert.False (view.IsKeyUp);
- keyUp = true;
- };
- Application.Top.Add (view);
- Console.MockKeyPresses.Push (new ConsoleKeyInfo ('\0', (ConsoleKey)'\0', shift, alt, control));
- Application.Iteration += () => Application.RequestStop ();
- Assert.True (view.CanFocus);
- Application.Run ();
- Application.Shutdown ();
- Assert.True (keyDown);
- Assert.False (keyPress);
- Assert.True (keyUp);
- Assert.True (view.IsKeyDown);
- Assert.False (view.IsKeyPress);
- Assert.True (view.IsKeyUp);
- }
- }
- }
|