ControlTest.cs 96 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325
  1. //
  2. // Copyright (c) 2005 Novell, Inc.
  3. //
  4. // Authors:
  5. // Ritvik Mayank ([email protected])
  6. // Stefan Noack ([email protected])
  7. //
  8. using System;
  9. using System.Collections;
  10. using System.ComponentModel;
  11. using System.Drawing;
  12. using System.Reflection;
  13. using System.Runtime.Remoting;
  14. using System.Threading;
  15. using System.Windows.Forms;
  16. #if NET_2_0
  17. using System.Windows.Forms.Layout;
  18. #endif
  19. using NUnit.Framework;
  20. using CategoryAttribute = NUnit.Framework.CategoryAttribute;
  21. namespace MonoTests.System.Windows.Forms
  22. {
  23. [TestFixture]
  24. public class ControlTest : TestHelper
  25. {
  26. [Test] // .ctor ()
  27. public void Constructor1 ()
  28. {
  29. MockControl c = new MockControl ();
  30. Assert.AreEqual (0, c.OnLocationChangedCount, "OnLocationChangedCount");
  31. Assert.AreEqual (0, c.OnResizeCount, "OnResizeCount");
  32. Assert.AreEqual (0, c.OnSizeChangedCount, "OnSizeChangedCount");
  33. Assert.AreEqual (0, c.Height, "Height");
  34. Assert.AreEqual (0, c.Left, "Left");
  35. Assert.AreEqual (string.Empty, c.Name, "Name");
  36. Assert.IsNull (c.Parent, "Parent");
  37. Assert.AreEqual (string.Empty, c.Text, "#A:Text");
  38. Assert.AreEqual (0, c.Top, "Top");
  39. Assert.AreEqual (0, c.Width, "Width");
  40. }
  41. [Test] // .ctor (String)
  42. public void Constructor2 ()
  43. {
  44. MockControl c = new MockControl ((string) null);
  45. Assert.AreEqual (0, c.OnLocationChangedCount, "#A:OnLocationChangedCount");
  46. Assert.AreEqual (0, c.OnResizeCount, "#A:OnResizeCount");
  47. Assert.AreEqual (0, c.OnSizeChangedCount, "#A:OnSizeChangedCount");
  48. Assert.AreEqual (0, c.Height, "#A:Height");
  49. Assert.AreEqual (0, c.Left, "#A:Left");
  50. Assert.AreEqual (string.Empty, c.Name, "#A:Name");
  51. Assert.IsNull (c.Parent, "#A:Parent");
  52. Assert.AreEqual (string.Empty, c.Text, "#A:Text");
  53. Assert.AreEqual (0, c.Top, "#A:Top");
  54. Assert.AreEqual (0, c.Width, "#A:Width");
  55. c = new MockControl ("child");
  56. Assert.AreEqual (0, c.OnLocationChangedCount, "#B:OnLocationChangedCount");
  57. Assert.AreEqual (0, c.OnResizeCount, "#B:OnResizeCount");
  58. Assert.AreEqual (0, c.OnSizeChangedCount, "#B:OnSizeChangedCount");
  59. Assert.AreEqual (0, c.Height, "#B:Height");
  60. Assert.AreEqual (0, c.Left, "#B:Left");
  61. Assert.AreEqual (string.Empty, c.Name, "#B:Name");
  62. Assert.IsNull (c.Parent, "#B:Parent");
  63. Assert.AreEqual ("child", c.Text, "#B:Text");
  64. Assert.AreEqual (0, c.Top, "#B:Top");
  65. Assert.AreEqual (0, c.Width, "#B:Width");
  66. }
  67. [Test] // .ctor (Control, String)
  68. public void Constructor3 ()
  69. {
  70. Control parent = new Control ("parent");
  71. MockControl c = new MockControl ((Control) null, (string) null);
  72. Assert.AreEqual (0, c.OnLocationChangedCount, "#A:OnLocationChangedCount");
  73. Assert.AreEqual (0, c.OnResizeCount, "#A:OnResizeCount");
  74. Assert.AreEqual (0, c.OnSizeChangedCount, "#A:OnSizeChangedCount");
  75. Assert.AreEqual (0, c.Height, "#A:Height");
  76. Assert.AreEqual (0, c.Left, "#A:Left");
  77. Assert.AreEqual (string.Empty, c.Name, "#A:Name");
  78. Assert.IsNull (c.Parent, "#A:Parent");
  79. Assert.AreEqual (string.Empty, c.Text, "#A:Text");
  80. Assert.AreEqual (0, c.Top, "#A:Top");
  81. Assert.AreEqual (0, c.Width, "#A:Width");
  82. c = new MockControl ((Control) null, "child");
  83. Assert.AreEqual (0, c.OnLocationChangedCount, "#B:OnLocationChangedCount");
  84. Assert.AreEqual (0, c.OnResizeCount, "#B:OnResizeCount");
  85. Assert.AreEqual (0, c.OnSizeChangedCount, "#B:OnSizeChangedCount");
  86. Assert.AreEqual (0, c.Height, "#B:Height");
  87. Assert.AreEqual (0, c.Left, "#B:Left");
  88. Assert.AreEqual (string.Empty, c.Name, "#B:Name");
  89. Assert.IsNull (c.Parent, "#B:Parent");
  90. Assert.AreEqual ("child", c.Text, "#B:Text");
  91. Assert.AreEqual (0, c.Top, "#B:Top");
  92. Assert.AreEqual (0, c.Width, "#B:Width");
  93. c = new MockControl (parent, (string) null);
  94. Assert.AreEqual (0, c.OnLocationChangedCount, "#C:OnLocationChangedCount");
  95. Assert.AreEqual (0, c.OnResizeCount, "#C:OnResizeCount");
  96. Assert.AreEqual (0, c.OnSizeChangedCount, "#C:OnSizeChangedCount");
  97. Assert.AreEqual (0, c.Height, "#C:Height");
  98. Assert.AreEqual (0, c.Left, "#C:Left");
  99. Assert.AreEqual (string.Empty, c.Name, "#C:Name");
  100. Assert.AreSame (parent, c.Parent, "#C:Parent");
  101. Assert.AreEqual (string.Empty, c.Text, "#C:Text");
  102. Assert.AreEqual (0, c.Top, "#C:Top");
  103. Assert.AreEqual (0, c.Width, "#C:Width");
  104. c = new MockControl (parent, "child");
  105. Assert.AreEqual (0, c.OnLocationChangedCount, "#D:OnLocationChangedCount");
  106. Assert.AreEqual (0, c.OnResizeCount, "#D:OnResizeCount");
  107. Assert.AreEqual (0, c.OnSizeChangedCount, "#D:OnSizeChangedCount");
  108. Assert.AreEqual (0, c.Height, "#D:Height");
  109. Assert.AreEqual (0, c.Left, "#D:Left");
  110. Assert.AreEqual (string.Empty, c.Name, "#D:Name");
  111. Assert.AreSame (parent, c.Parent, "#D:Parent");
  112. Assert.AreEqual ("child", c.Text, "#D:Text");
  113. Assert.AreEqual (0, c.Top, "#D:Top");
  114. Assert.AreEqual (0, c.Width, "#D:Width");
  115. }
  116. [Test] // .ctor (String, Int32, Int32, Int32, Int32)
  117. public void Constructor4 ()
  118. {
  119. MockControl c = new MockControl ((string) null, 0, 0, 0, 0);
  120. Assert.AreEqual (0, c.OnLocationChangedCount, "#A:OnLocationChangedCount");
  121. Assert.AreEqual (0, c.OnResizeCount, "#A:OnResizeCount");
  122. Assert.AreEqual (0, c.OnSizeChangedCount, "#A:OnSizeChangedCount");
  123. Assert.AreEqual (0, c.Height, "#A:Height");
  124. Assert.AreEqual (0, c.Left, "#A:Left");
  125. Assert.AreEqual (string.Empty, c.Name, "#A:Name");
  126. Assert.IsNull (c.Parent, "#A:Parent");
  127. Assert.AreEqual (string.Empty, c.Text, "#A:Text");
  128. Assert.AreEqual (0, c.Top, "#A:Top");
  129. Assert.AreEqual (0, c.Width, "#A:Width");
  130. c = new MockControl ((string) null, 1, 0, 0, 0);
  131. Assert.AreEqual (1, c.OnLocationChangedCount, "#B:OnLocationChangedCount");
  132. Assert.AreEqual (0, c.OnResizeCount, "#B:OnResizeCount");
  133. Assert.AreEqual (0, c.OnSizeChangedCount, "#B:OnSizeChangedCount");
  134. Assert.AreEqual (0, c.Height, "#B:Height");
  135. Assert.AreEqual (1, c.Left, "#B:Left");
  136. Assert.AreEqual (string.Empty, c.Name, "#B:Name");
  137. Assert.IsNull (c.Parent, "#B:Parent");
  138. Assert.AreEqual (string.Empty, c.Text, "#B:Text");
  139. Assert.AreEqual (0, c.Top, "#B:Top");
  140. Assert.AreEqual (0, c.Width, "#B:Width");
  141. c = new MockControl ("child", 0, 1, 0, 0);
  142. Assert.AreEqual (1, c.OnLocationChangedCount, "#C:OnLocationChangedCount");
  143. Assert.AreEqual (0, c.OnResizeCount, "#C:OnResizeCount");
  144. Assert.AreEqual (0, c.OnSizeChangedCount, "#C:OnSizeChangedCount");
  145. Assert.AreEqual (0, c.Height, "#C:Height");
  146. Assert.AreEqual (0, c.Left, "#C:Left");
  147. Assert.AreEqual (string.Empty, c.Name, "#C:Name");
  148. Assert.IsNull (c.Parent, "#C:Parent");
  149. Assert.AreEqual ("child", c.Text, "#C:Text");
  150. Assert.AreEqual (1, c.Top, "#C:Top");
  151. Assert.AreEqual (0, c.Width, "#C:Width");
  152. c = new MockControl ("child", 0, 0, 1, 0);
  153. Assert.AreEqual (0, c.OnLocationChangedCount, "#D:OnLocationChangedCount");
  154. Assert.AreEqual (1, c.OnResizeCount, "#D:OnResizeCount");
  155. Assert.AreEqual (1, c.OnSizeChangedCount, "#D:OnSizeChangedCount");
  156. Assert.AreEqual (0, c.Height, "#D:Height");
  157. Assert.AreEqual (0, c.Left, "#D:Left");
  158. Assert.AreEqual (string.Empty, c.Name, "#D:Name");
  159. Assert.IsNull (c.Parent, "#D:Parent");
  160. Assert.AreEqual ("child", c.Text, "#D:Text");
  161. Assert.AreEqual (0, c.Top, "#D:Top");
  162. Assert.AreEqual (1, c.Width, "#D:Width");
  163. c = new MockControl ("child", 0, 0, 0, 1);
  164. Assert.AreEqual (0, c.OnLocationChangedCount, "#E:OnLocationChangedCount");
  165. Assert.AreEqual (1, c.OnResizeCount, "#E:OnResizeCount");
  166. Assert.AreEqual (1, c.OnSizeChangedCount, "#E:OnSizeChangedCount");
  167. Assert.AreEqual (1, c.Height, "#E:Height");
  168. Assert.AreEqual (0, c.Left, "#E:Left");
  169. Assert.AreEqual (string.Empty, c.Name, "#E:Name");
  170. Assert.IsNull (c.Parent, "#E:Parent");
  171. Assert.AreEqual ("child", c.Text, "#E:Text");
  172. Assert.AreEqual (0, c.Top, "#E:Top");
  173. Assert.AreEqual (0, c.Width, "#E:Width");
  174. c = new MockControl ("child", 1, 0, 1, 0);
  175. Assert.AreEqual (1, c.OnLocationChangedCount, "#F:OnLocationChangedCount");
  176. Assert.AreEqual (1, c.OnResizeCount, "#F:OnResizeCount");
  177. Assert.AreEqual (1, c.OnSizeChangedCount, "#F:OnSizeChangedCount");
  178. Assert.AreEqual (0, c.Height, "#F:Height");
  179. Assert.AreEqual (1, c.Left, "#F:Left");
  180. Assert.AreEqual (string.Empty, c.Name, "#F:Name");
  181. Assert.IsNull (c.Parent, "#F:Parent");
  182. Assert.AreEqual ("child", c.Text, "#F:Text");
  183. Assert.AreEqual (0, c.Top, "#F:Top");
  184. Assert.AreEqual (1, c.Width, "#F:Width");
  185. c = new MockControl ("child", 0, 1, 0, 1);
  186. Assert.AreEqual (1, c.OnLocationChangedCount, "#G:OnLocationChangedCount");
  187. Assert.AreEqual (1, c.OnResizeCount, "#G:OnResizeCount");
  188. Assert.AreEqual (1, c.OnSizeChangedCount, "#G:OnSizeChangedCount");
  189. Assert.AreEqual (1, c.Height, "#G:Height");
  190. Assert.AreEqual (0, c.Left, "#G:Left");
  191. Assert.AreEqual (string.Empty, c.Name, "#G:Name");
  192. Assert.IsNull (c.Parent, "#G:Parent");
  193. Assert.AreEqual ("child", c.Text, "#G:Text");
  194. Assert.AreEqual (1, c.Top, "#G:Top");
  195. Assert.AreEqual (0, c.Width, "#G:Width");
  196. }
  197. [Test] // .ctor (Control, String, Int32, Int32, Int32, Int32)
  198. public void Constructor5 ()
  199. {
  200. Control parent = new Control ("parent");
  201. MockControl c = new MockControl ((Control) null,
  202. (string) null, 0, 0, 0, 0);
  203. Assert.AreEqual (0, c.OnLocationChangedCount, "#A:OnLocationChangedCount");
  204. Assert.AreEqual (0, c.OnResizeCount, "#A:OnResizeCount");
  205. Assert.AreEqual (0, c.OnSizeChangedCount, "#A:OnSizeChangedCount");
  206. Assert.AreEqual (0, c.Height, "#A:Height");
  207. Assert.AreEqual (0, c.Left, "#A:Left");
  208. Assert.AreEqual (string.Empty, c.Name, "#A:Name");
  209. Assert.IsNull (c.Parent, "#A:Parent");
  210. Assert.AreEqual (string.Empty, c.Text, "#A:Text");
  211. Assert.AreEqual (0, c.Top, "#A:Top");
  212. Assert.AreEqual (0, c.Width, "#A:Width");
  213. c = new MockControl (parent, (string) null, 1, 0, 0, 0);
  214. Assert.AreEqual (1, c.OnLocationChangedCount, "#B:OnLocationChangedCount");
  215. Assert.AreEqual (0, c.OnResizeCount, "#B:OnResizeCount");
  216. Assert.AreEqual (0, c.OnSizeChangedCount, "#B:OnSizeChangedCount");
  217. Assert.AreEqual (0, c.Height, "#B:Height");
  218. Assert.AreEqual (1, c.Left, "#B:Left");
  219. Assert.AreEqual (string.Empty, c.Name, "#B:Name");
  220. Assert.AreSame (parent, c.Parent, "#B:Parent");
  221. Assert.AreEqual (string.Empty, c.Text, "#B:Text");
  222. Assert.AreEqual (0, c.Top, "#B:Top");
  223. Assert.AreEqual (0, c.Width, "#B:Width");
  224. c = new MockControl ((Control) null, "child", 0, 1, 0, 0);
  225. Assert.AreEqual (1, c.OnLocationChangedCount, "#C:OnLocationChangedCount");
  226. Assert.AreEqual (0, c.OnResizeCount, "#C:OnResizeCount");
  227. Assert.AreEqual (0, c.OnSizeChangedCount, "#C:OnSizeChangedCount");
  228. Assert.AreEqual (0, c.Height, "#C:Height");
  229. Assert.AreEqual (0, c.Left, "#C:Left");
  230. Assert.AreEqual (string.Empty, c.Name, "#C:Name");
  231. Assert.IsNull (c.Parent, "#C:Parent");
  232. Assert.AreEqual ("child", c.Text, "#C:Text");
  233. Assert.AreEqual (1, c.Top, "#C:Top");
  234. Assert.AreEqual (0, c.Width, "#C:Width");
  235. c = new MockControl (parent, "child", 0, 0, 1, 0);
  236. Assert.AreEqual (0, c.OnLocationChangedCount, "#D:OnLocationChangedCount");
  237. Assert.AreEqual (1, c.OnResizeCount, "#D:OnResizeCount");
  238. Assert.AreEqual (1, c.OnSizeChangedCount, "#D:OnSizeChangedCount");
  239. Assert.AreEqual (0, c.Height, "#D:Height");
  240. Assert.AreEqual (0, c.Left, "#D:Left");
  241. Assert.AreEqual (string.Empty, c.Name, "#D:Name");
  242. Assert.AreSame (parent, c.Parent, "#D:Parent");
  243. Assert.AreEqual ("child", c.Text, "#D:Text");
  244. Assert.AreEqual (0, c.Top, "#D:Top");
  245. Assert.AreEqual (1, c.Width, "#D:Width");
  246. c = new MockControl (parent, "child", 0, 0, 0, 1);
  247. Assert.AreEqual (0, c.OnLocationChangedCount, "#E:OnLocationChangedCount");
  248. Assert.AreEqual (1, c.OnResizeCount, "#E:OnResizeCount");
  249. Assert.AreEqual (1, c.OnSizeChangedCount, "#E:OnSizeChangedCount");
  250. Assert.AreEqual (1, c.Height, "#E:Height");
  251. Assert.AreEqual (0, c.Left, "#E:Left");
  252. Assert.AreEqual (string.Empty, c.Name, "#E:Name");
  253. Assert.AreSame (parent, c.Parent, "#E:Parent");
  254. Assert.AreEqual ("child", c.Text, "#E:Text");
  255. Assert.AreEqual (0, c.Top, "#E:Top");
  256. Assert.AreEqual (0, c.Width, "#E:Width");
  257. c = new MockControl (parent, "child", 1, 0, 1, 0);
  258. Assert.AreEqual (1, c.OnLocationChangedCount, "#F:OnLocationChangedCount");
  259. Assert.AreEqual (1, c.OnResizeCount, "#F:OnResizeCount");
  260. Assert.AreEqual (1, c.OnSizeChangedCount, "#F:OnSizeChangedCount");
  261. Assert.AreEqual (0, c.Height, "#F:Height");
  262. Assert.AreEqual (1, c.Left, "#F:Left");
  263. Assert.AreEqual (string.Empty, c.Name, "#F:Name");
  264. Assert.AreSame (parent, c.Parent, "#F:Parent");
  265. Assert.AreEqual ("child", c.Text, "#F:Text");
  266. Assert.AreEqual (0, c.Top, "#F:Top");
  267. Assert.AreEqual (1, c.Width, "#F:Width");
  268. c = new MockControl (parent, "child", 0, 1, 0, 1);
  269. Assert.AreEqual (1, c.OnLocationChangedCount, "#G:OnLocationChangedCount");
  270. Assert.AreEqual (1, c.OnResizeCount, "#G:OnResizeCount");
  271. Assert.AreEqual (1, c.OnSizeChangedCount, "#G:OnSizeChangedCount");
  272. Assert.AreEqual (1, c.Height, "#G:Height");
  273. Assert.AreEqual (0, c.Left, "#G:Left");
  274. Assert.AreEqual (string.Empty, c.Name, "#G:Name");
  275. Assert.AreSame (parent, c.Parent, "#G:Parent");
  276. Assert.AreEqual ("child", c.Text, "#G:Text");
  277. Assert.AreEqual (1, c.Top, "#G:Top");
  278. Assert.AreEqual (0, c.Width, "#G:Width");
  279. }
  280. [Test]
  281. public void DisposeTest ()
  282. {
  283. ControlDisposeTester control = new ControlDisposeTester ();
  284. control.Visible = true;
  285. control.Dispose ();
  286. try {
  287. control.CreateControl ();
  288. } catch (ObjectDisposedException ex) {
  289. Console.WriteLine (ex);
  290. Assert.Fail ("#1");
  291. }
  292. Assert.IsFalse (control.IsHandleCreated, "#2");
  293. // The control remains Visible until WM_DESTROY is received.
  294. Assert.IsTrue (control.Visible, "#3");
  295. try {
  296. control.InvokeCreateHandle ();
  297. Assert.Fail ("#4");
  298. } catch (ObjectDisposedException ex) {
  299. //Console.WriteLine (ex);
  300. }
  301. }
  302. [Test]
  303. public void AccessibilityPropertiesTest ()
  304. {
  305. MockControl c = new MockControl ();
  306. Assert.IsNull (c.AccessibleName, "AccessibleName");
  307. Assert.IsNull (c.AccessibleDescription, "AccessibleDescription");
  308. Assert.IsNull (c.AccessibleDefaultActionDescription, "AccessibleDefaultActionDescription");
  309. Assert.IsNotNull (c.AccessibleRole, "AccessibleRole");
  310. string accessible_name = "Accessible Name";
  311. c.AccessibleName = accessible_name;
  312. Assert.AreEqual (accessible_name, c.AccessibleName, "AccessibleName");
  313. string accessible_description = "Accessible Description";
  314. c.AccessibleDescription = accessible_description;
  315. Assert.AreEqual (accessible_description, c.AccessibleDescription, "AccessibleDescription");
  316. string accessible_default_action_description = "Accessible Default Action Description";
  317. c.AccessibleDefaultActionDescription = accessible_default_action_description;
  318. Assert.AreEqual (accessible_default_action_description, c.AccessibleDefaultActionDescription, "AccessibleDefaultActionDescription");
  319. Assert.AreEqual (AccessibleRole.Default, c.AccessibleRole, "AccessibleRole");
  320. c.AccessibleRole = AccessibleRole.Pane;
  321. Assert.AreEqual (AccessibleRole.Pane, c.AccessibleRole, "AccessibleRole.Pane");
  322. c.AccessibleRole = AccessibleRole.Dialog;
  323. Assert.AreEqual (AccessibleRole.Dialog, c.AccessibleRole, "AccessibleRole.Dialog");
  324. }
  325. private class ControlDisposeTester : Control
  326. {
  327. public void InvokeCreateHandle ()
  328. {
  329. CreateHandle ();
  330. }
  331. }
  332. #if NET_2_0
  333. [Test]
  334. public void AutoSizeTest ()
  335. {
  336. ControlAutoSizeTester c = new ControlAutoSizeTester (new Size (23, 17), AutoSizeMode.GrowAndShrink);
  337. Form f = new Form();
  338. f.Size = new Size (200, 200);
  339. c.Parent = f;
  340. f.Show();
  341. Size s = new Size (42, 42);
  342. c.Size = s;
  343. Point l = new Point (10, 10);
  344. c.Location = l;
  345. //Check wether normal size setting is OK
  346. Assert.AreEqual (s, c.Size, "#S1");
  347. //Check wether size remains without GetPreferredSize implemented even when AutoSize turned on.
  348. c.AutoSize = true;
  349. f.PerformLayout();
  350. Assert.AreEqual (s, c.Size, "#S2");
  351. //Simulate a Control implementing GetPreferredSize
  352. c.UseCustomPrefSize = true;
  353. f.PerformLayout();
  354. //Check wether size shrinks to preferred size
  355. Assert.AreEqual (c.CustomPrefSize, c.Size, "#S3");
  356. //Check wether Location stays constant
  357. Assert.AreEqual (l, c.Location, "#L1");
  358. //Check wether Dock is respected
  359. c.Dock = DockStyle.Bottom;
  360. Assert.AreEqual (f.ClientSize.Width, c.Width, "#D1");
  361. //Check wether size shrinks to preferred size again
  362. c.Dock = DockStyle.None;
  363. Assert.AreEqual (c.CustomPrefSize, c.Size, "#S4");
  364. //Check wether Anchor is respected for adjusting Locatioon
  365. c.Anchor = AnchorStyles.Bottom;
  366. f.Height += 50;
  367. Assert.AreEqual (l.Y + 50, c.Top, "#A1");
  368. //Check wether size is still OK
  369. Assert.AreEqual (c.CustomPrefSize, c.Size, "#S5");
  370. //just tidy up
  371. c.Anchor = AnchorStyles.Top | AnchorStyles.Left;
  372. c.Location = l;
  373. //Check wether shrinking to zero is possible
  374. c.CustomPrefSize = new Size (0, 0);
  375. f.PerformLayout();
  376. Assert.AreEqual (c.CustomPrefSize, c.Size, "#S6");
  377. //Check wether MinimumSize is honored
  378. c.MinimumSize = new Size (10, 12);
  379. c.CustomPrefSize = new Size (5, 5);
  380. f.PerformLayout();
  381. Assert.AreEqual (c.MinimumSize, c.Size, "#S7");
  382. c.MinimumSize = new Size (0, 0);
  383. //Check wether MaximumSize is honored
  384. c.MaximumSize = new Size (100, 120);
  385. c.CustomPrefSize = new Size (500, 500);
  386. f.PerformLayout();
  387. Assert.AreEqual (c.MaximumSize, c.Size, "#S8");
  388. //Check wether shrinking does not happen when GrowOnly
  389. c.AutoSize = false;
  390. s = new Size (23, 23);
  391. c.Size = s;
  392. c.CustomPrefSize = new Size (5, 5);
  393. c.AutoSizeMode = AutoSizeMode.GrowOnly;
  394. c.AutoSize = true;
  395. f.PerformLayout();
  396. Assert.AreEqual (s, c.Size, "#S9");
  397. f.Close ();
  398. }
  399. public class ControlAutoSizeTester : Control {
  400. public ControlAutoSizeTester (Size customPrefSize, AutoSizeMode autoSizeMode)
  401. {
  402. custom_prefsize = customPrefSize;
  403. AutoSizeMode = autoSizeMode;
  404. }
  405. public AutoSizeMode AutoSizeMode {
  406. set {
  407. base.SetAutoSizeMode (value);
  408. }
  409. }
  410. private bool use_custom_prefsize = false;
  411. public bool UseCustomPrefSize {
  412. set {
  413. use_custom_prefsize = value;
  414. }
  415. }
  416. private Size custom_prefsize;
  417. public Size CustomPrefSize {
  418. get {
  419. return custom_prefsize;
  420. }
  421. set {
  422. custom_prefsize = value;
  423. }
  424. }
  425. public override Size GetPreferredSize (Size proposedSize)
  426. {
  427. if (use_custom_prefsize) {
  428. return custom_prefsize;
  429. } else {
  430. return base.GetPreferredSize(proposedSize);
  431. }
  432. }
  433. }
  434. #endif
  435. [Test]
  436. public void Bug82748 ()
  437. {
  438. Form f = new Form ();
  439. f.ShowInTaskbar = false;
  440. Control c = new Control ();
  441. c.Size = new Size (100, 100);
  442. Control c2 = new Control ();
  443. c2.Size = c.Size;
  444. c2.Controls.Add (c);
  445. c.Anchor = AnchorStyles.Right;
  446. f.Controls.Add (c);
  447. f.Show ();
  448. Assert.AreEqual (0, c.Left, "A1");
  449. f.Close ();
  450. f.Dispose ();
  451. }
  452. [Test]
  453. public void InvokeTestParentHandle ()
  454. {
  455. Control child, parent;
  456. parent = new Control ();
  457. child = new Control ();
  458. parent.Controls.Add (child);
  459. parent.Visible = true;
  460. parent.CreateControl ();
  461. child.Invoke (new CrossAppDomainDelegate (dummy)) ;
  462. }
  463. public void dummy ()
  464. {
  465. }
  466. public class ControlStylesTester : Control {
  467. private WindowStyles style;
  468. private WindowStyles ex_style;
  469. private bool or_styles;
  470. public ControlStylesTester (WindowStyles Style, WindowStyles ExStyle, bool OrStyles)
  471. {
  472. style = Style;
  473. ex_style = ExStyle;
  474. or_styles = OrStyles;
  475. }
  476. protected override CreateParams CreateParams {
  477. get {
  478. CreateParams result = base.CreateParams;
  479. if (or_styles) {
  480. result.Style |= (int) style;
  481. result.ExStyle |= (int) ex_style;
  482. } else {
  483. result.Style = (int) style;
  484. result.ExStyle = (int) ex_style;
  485. }
  486. return result;
  487. }
  488. }
  489. }
  490. [Test]
  491. public void ControlSizeTest ()
  492. {
  493. ControlStylesTester c = new ControlStylesTester (WindowStyles.WS_CHILD, 0, true);
  494. Assert.AreEqual ("{X=0,Y=0}", c.Location.ToString (), "#L1");
  495. Assert.AreEqual ("{Width=0, Height=0}", c.Size.ToString (), "#S1");
  496. }
  497. #if NET_2_0
  498. [Test]
  499. public void CaptureTest ()
  500. {
  501. Form frm = new Form ();
  502. ControlOverrideLogger log = new ControlOverrideLogger ();
  503. frm.Controls.Add (log);
  504. log.Visible = true;
  505. log.Capture = true;
  506. log.Capture = false;
  507. log.BackColor = Color.Blue;
  508. log.Size = new Size (100, 100);
  509. frm.Show ();
  510. Application.DoEvents ();
  511. frm.Dispose ();
  512. Assert.IsTrue (log.Log.ToString ().IndexOf ("OnMouseCaptureChanged") > -1, "#01");
  513. log = new ControlOverrideLogger ();
  514. log.Capture = true;
  515. log.Capture = false;
  516. Assert.IsTrue (log.Log.ToString ().IndexOf ("OnMouseCaptureChanged") > -1, "#02");
  517. log = new ControlOverrideLogger ();
  518. log.Capture = true;
  519. Assert.IsTrue (log.IsHandleCreated, "#03");
  520. Assert.IsTrue (log.Log.ToString ().IndexOf ("OnMouseCaptureChanged") == -1, "#04");
  521. log = new ControlOverrideLogger ();
  522. log.Capture = false;
  523. Assert.IsFalse (log.IsHandleCreated, "#05");
  524. Assert.IsTrue (log.Log.ToString ().IndexOf ("OnMouseCaptureChanged") == -1, "#06");
  525. }
  526. #endif
  527. public class OnPaintTester : Form
  528. {
  529. int counter;
  530. int total;
  531. ArrayList list = new ArrayList ();
  532. public bool Recursive;
  533. public bool TestRefresh;
  534. public bool TestInvalidate;
  535. public bool TestUpdate;
  536. #if NET_2_0
  537. public new bool DoubleBuffered {
  538. get {
  539. return base.DoubleBuffered;
  540. }
  541. set {
  542. base.DoubleBuffered = value;
  543. }
  544. }
  545. #endif
  546. protected override void OnPaint (PaintEventArgs pevent)
  547. {
  548. Assert.IsFalse (list.Contains (pevent.Graphics), "OnPaintTester.OnPaint: Got the same Graphics twice");
  549. list.Add (pevent.Graphics);
  550. if (total > 10)
  551. return;
  552. Recursive = counter > 0 || Recursive;
  553. counter++;
  554. if (counter < 2) {
  555. if (TestRefresh)
  556. Refresh ();
  557. else if (TestInvalidate)
  558. Invalidate ();
  559. else {
  560. Update ();
  561. }
  562. }
  563. base.OnPaint (pevent);
  564. counter--;
  565. total++;
  566. }
  567. public new void Show ()
  568. {
  569. base.Show ();
  570. Application.DoEvents ();
  571. }
  572. }
  573. [Test]
  574. public void ControlCollectionTest ()
  575. {
  576. Form frm = new Form ();
  577. frm.IsMdiContainer = true;
  578. Form child = new Form ();
  579. Control.ControlCollection c = new Control.ControlCollection (frm);
  580. child.MdiParent = frm;
  581. c.Add (child);
  582. child.Dispose ();
  583. frm.Dispose ();
  584. }
  585. [Test]
  586. [ExpectedException (typeof (ArgumentException))]
  587. public void ControlCollectionExceptionTest ()
  588. {
  589. Form frm = new Form ();
  590. frm.IsMdiContainer = true;
  591. Form child = new Form ();
  592. Control.ControlCollection c = new Control.ControlCollection (frm);
  593. //child.MdiParent = frm;
  594. c.Add (child);
  595. child.Dispose ();
  596. frm.Dispose ();
  597. }
  598. [Test]
  599. [Category ("NotWorking")]
  600. public void OnPaintTest ()
  601. {
  602. using (OnPaintTester t = new OnPaintTester ()) {
  603. t.TestRefresh = true;
  604. t.Show ();
  605. Assert.IsTrue (t.Recursive, "#1");
  606. }
  607. using (OnPaintTester t = new OnPaintTester ()) {
  608. t.TestUpdate = true;
  609. t.Show ();
  610. Assert.IsFalse (t.Recursive, "#2");
  611. }
  612. using (OnPaintTester t = new OnPaintTester ()) {
  613. t.TestInvalidate = true;
  614. t.Show ();
  615. Assert.IsFalse (t.Recursive, "#3");
  616. }
  617. }
  618. #if NET_2_0
  619. [Test]
  620. [Category ("Interactive")]
  621. public void OnPaintDoubleBufferedTest ()
  622. {
  623. using (OnPaintTester t = new OnPaintTester ()) {
  624. t.DoubleBuffered = true;
  625. t.TestRefresh = true;
  626. t.Show ();
  627. Assert.IsTrue (t.Recursive, "#1");
  628. }
  629. using (OnPaintTester t = new OnPaintTester ()) {
  630. t.DoubleBuffered = true;
  631. t.TestUpdate = true;
  632. t.Show ();
  633. Assert.IsFalse (t.Recursive, "#2");
  634. }
  635. using (OnPaintTester t = new OnPaintTester ()) {
  636. t.DoubleBuffered = true;
  637. t.TestInvalidate = true;
  638. t.Show ();
  639. Assert.IsFalse (t.Recursive, "#3");
  640. }
  641. }
  642. #endif
  643. public class PaintEventForm : Form
  644. {
  645. public ArrayList overrides = new ArrayList ();
  646. public ArrayList events = new ArrayList ();
  647. public PaintEventForm ()
  648. {
  649. Paint += new PaintEventHandler (DoubleBufferEventForm_Paint);
  650. }
  651. public bool GetControlStyle (ControlStyles style)
  652. {
  653. return base.GetStyle (style);
  654. }
  655. public void SetControlStyle (ControlStyles style, bool value)
  656. {
  657. base.SetStyle (style, value);
  658. }
  659. void DoubleBufferEventForm_Paint (object sender, PaintEventArgs e)
  660. {
  661. events.Add("Paint");
  662. }
  663. protected override void OnPaintBackground (PaintEventArgs e)
  664. {
  665. base.OnPaintBackground (e);
  666. overrides.Add("OnPaintBackground");
  667. }
  668. protected override void OnPaint (PaintEventArgs pevent)
  669. {
  670. base.OnPaint (pevent);
  671. overrides.Add("OnPaint");
  672. }
  673. }
  674. [Test]
  675. [Ignore ("Can't find a reliable way to generate a paint message on Windows.")]
  676. public void EventStyleTest ()
  677. {
  678. #if NET_2_0
  679. using (PaintEventForm f = new PaintEventForm ()) {
  680. f.Show ();
  681. f.SetControlStyle (ControlStyles.OptimizedDoubleBuffer, true);
  682. f.Refresh ();
  683. Assert.IsTrue (f.overrides.Contains ("OnPaintBackground"), "#A1");
  684. Assert.IsTrue (f.overrides.Contains ("OnPaint"), "#A2");
  685. Assert.IsTrue (f.events.Contains ("Paint"), "#A3");
  686. }
  687. #endif
  688. using (PaintEventForm f = new PaintEventForm ()) {
  689. f.Show ();
  690. f.SetControlStyle (ControlStyles.DoubleBuffer, true);
  691. f.Refresh ();
  692. Assert.IsTrue (f.overrides.Contains ("OnPaintBackground"), "#B1");
  693. Assert.IsTrue (f.overrides.Contains ("OnPaint"), "#B2");
  694. Assert.IsTrue (f.events.Contains ("Paint"), "#B3");
  695. }
  696. using (PaintEventForm f = new PaintEventForm ()) {
  697. f.Show ();
  698. f.SetControlStyle (ControlStyles.AllPaintingInWmPaint, true);
  699. f.Refresh ();
  700. Assert.IsTrue (f.overrides.Contains ("OnPaintBackground"), "#C1");
  701. Assert.IsTrue (f.overrides.Contains ("OnPaint"), "#C2");
  702. Assert.IsTrue (f.events.Contains ("Paint"), "#C3");
  703. }
  704. using (PaintEventForm f = new PaintEventForm ()) {
  705. f.Show ();
  706. f.SetControlStyle (ControlStyles.UserPaint, true);
  707. f.Refresh ();
  708. Assert.IsTrue (f.overrides.Contains ("OnPaintBackground"), "#D1");
  709. Assert.IsTrue (f.overrides.Contains ("OnPaint"), "#D2");
  710. Assert.IsTrue (f.events.Contains ("Paint"), "#D3");
  711. }
  712. using (PaintEventForm f = new PaintEventForm ()) {
  713. f.Show ();
  714. f.SetControlStyle (ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true);
  715. f.Refresh ();
  716. Assert.IsTrue (f.overrides.Contains ("OnPaintBackground"), "#E1");
  717. Assert.IsTrue (f.overrides.Contains ("OnPaint"), "#E2");
  718. Assert.IsTrue (f.events.Contains ("Paint"), "#E3");
  719. }
  720. using (PaintEventForm f = new PaintEventForm ()) {
  721. f.Show ();
  722. f.SetControlStyle (ControlStyles.UserPaint | ControlStyles.DoubleBuffer, true);
  723. f.Refresh ();
  724. Assert.IsTrue (f.overrides.Contains ("OnPaintBackground"), "#F1");
  725. Assert.IsTrue (f.overrides.Contains ("OnPaint"), "#F2");
  726. Assert.IsTrue (f.events.Contains ("Paint"), "#F3");
  727. }
  728. using (PaintEventForm f = new PaintEventForm ()) {
  729. f.Show ();
  730. f.SetControlStyle (ControlStyles.DoubleBuffer | ControlStyles.AllPaintingInWmPaint, true);
  731. f.Refresh ();
  732. Assert.IsTrue (f.overrides.Contains ("OnPaintBackground"), "#G1");
  733. Assert.IsTrue (f.overrides.Contains ("OnPaint"), "#G2");
  734. Assert.IsTrue (f.events.Contains ("Paint"), "#G3");
  735. }
  736. using (PaintEventForm f = new PaintEventForm ()) {
  737. f.Show ();
  738. f.SetControlStyle (ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint | ControlStyles.DoubleBuffer, true);
  739. f.Refresh ();
  740. Assert.IsTrue (f.overrides.Contains ("OnPaintBackground"), "#H1");
  741. Assert.IsTrue (f.overrides.Contains ("OnPaint"), "#H2");
  742. Assert.IsTrue (f.events.Contains ("Paint"), "#H3");
  743. }
  744. }
  745. #if NET_2_0
  746. public class DoubleBufferedForm : Form
  747. {
  748. public bool painted;
  749. public bool failed;
  750. public DoubleBufferedForm ()
  751. {
  752. this.DoubleBuffered = true;
  753. }
  754. protected override void OnPaint (PaintEventArgs e)
  755. {
  756. if (failed || painted)
  757. return;
  758. painted = true;
  759. Height = Height + 1;
  760. try {
  761. e.Graphics.DrawString (Size.ToString (), Font, Brushes.AliceBlue, new Point (2, 2));
  762. } catch (Exception exception) {
  763. Console.WriteLine (exception.StackTrace);
  764. failed = true;
  765. }
  766. }
  767. }
  768. public class DoubleBufferControl : Control
  769. {
  770. public bool IsDoubleBuffered
  771. {
  772. get { return base.DoubleBuffered; }
  773. set { base.DoubleBuffered = value; }
  774. }
  775. public bool GetControlStyle (ControlStyles style)
  776. {
  777. return base.GetStyle (style);
  778. }
  779. public void SetControlStyle (ControlStyles style, bool value)
  780. {
  781. base.SetStyle (style, value);
  782. }
  783. }
  784. [Test]
  785. [Ignore ("Can't find a reliable way to generate a paint message on Windows.")]
  786. public void DoubleBufferTest ()
  787. {
  788. DoubleBufferedForm f = new DoubleBufferedForm ();
  789. f.ShowInTaskbar = false;
  790. f.Show ();
  791. f.Refresh ();
  792. Assert.IsFalse (f.failed, "#01");
  793. Assert.IsTrue (f.painted, "The control was never painted, so please check the test");
  794. f.Close ();
  795. }
  796. [Test]
  797. public void DoubleBufferedTest ()
  798. {
  799. DoubleBufferControl c = new DoubleBufferControl ();
  800. Assert.IsFalse (c.IsDoubleBuffered, "#A1");
  801. Assert.IsTrue (c.GetControlStyle (ControlStyles.AllPaintingInWmPaint), "#A2");
  802. Assert.IsFalse (c.GetControlStyle (ControlStyles.DoubleBuffer), "#A3");
  803. Assert.IsFalse (c.GetControlStyle (ControlStyles.OptimizedDoubleBuffer), "#A4");
  804. Assert.IsTrue (c.GetControlStyle (ControlStyles.UserPaint), "#A5");
  805. c.SetControlStyle (ControlStyles.OptimizedDoubleBuffer, true);
  806. Assert.IsTrue (c.IsDoubleBuffered, "#B1");
  807. Assert.IsTrue (c.GetControlStyle (ControlStyles.AllPaintingInWmPaint), "#B2");
  808. Assert.IsFalse (c.GetControlStyle (ControlStyles.DoubleBuffer), "#B3");
  809. Assert.IsTrue (c.GetControlStyle (ControlStyles.OptimizedDoubleBuffer), "#B4");
  810. Assert.IsTrue (c.GetControlStyle (ControlStyles.UserPaint), "#A5");
  811. c.SetControlStyle (ControlStyles.AllPaintingInWmPaint, false);
  812. c.SetControlStyle (ControlStyles.UserPaint, false);
  813. Assert.IsTrue (c.IsDoubleBuffered, "#C1");
  814. Assert.IsFalse (c.GetControlStyle (ControlStyles.AllPaintingInWmPaint), "#C2");
  815. Assert.IsFalse (c.GetControlStyle (ControlStyles.DoubleBuffer), "#C3");
  816. Assert.IsTrue (c.GetControlStyle (ControlStyles.OptimizedDoubleBuffer), "#C4");
  817. Assert.IsFalse (c.GetControlStyle (ControlStyles.UserPaint), "#C5");
  818. c.SetControlStyle (ControlStyles.OptimizedDoubleBuffer, false);
  819. Assert.IsFalse (c.IsDoubleBuffered, "#D1");
  820. Assert.IsFalse (c.GetControlStyle (ControlStyles.AllPaintingInWmPaint), "#D2");
  821. Assert.IsFalse (c.GetControlStyle (ControlStyles.DoubleBuffer), "#D3");
  822. Assert.IsFalse (c.GetControlStyle (ControlStyles.OptimizedDoubleBuffer), "#D4");
  823. Assert.IsFalse (c.GetControlStyle (ControlStyles.UserPaint), "#D5");
  824. c.SetControlStyle (ControlStyles.DoubleBuffer, true);
  825. Assert.IsFalse (c.IsDoubleBuffered, "#E1");
  826. Assert.IsFalse (c.GetControlStyle (ControlStyles.AllPaintingInWmPaint), "#E2");
  827. Assert.IsTrue (c.GetControlStyle (ControlStyles.DoubleBuffer), "#E3");
  828. Assert.IsFalse (c.GetControlStyle (ControlStyles.OptimizedDoubleBuffer), "#E4");
  829. Assert.IsFalse (c.GetControlStyle (ControlStyles.UserPaint), "#E5");
  830. c.SetControlStyle (ControlStyles.DoubleBuffer, false);
  831. Assert.IsFalse (c.IsDoubleBuffered, "#F1");
  832. Assert.IsFalse (c.GetControlStyle (ControlStyles.AllPaintingInWmPaint), "#F2");
  833. Assert.IsFalse (c.GetControlStyle (ControlStyles.DoubleBuffer), "#F3");
  834. Assert.IsFalse (c.GetControlStyle (ControlStyles.OptimizedDoubleBuffer), "#F4");
  835. Assert.IsFalse (c.GetControlStyle (ControlStyles.UserPaint), "#F5");
  836. c.IsDoubleBuffered = true;
  837. Assert.IsTrue (c.IsDoubleBuffered, "#G1");
  838. Assert.IsTrue (c.GetControlStyle (ControlStyles.AllPaintingInWmPaint), "#G2");
  839. Assert.IsFalse (c.GetControlStyle (ControlStyles.DoubleBuffer), "#G3");
  840. Assert.IsTrue (c.GetControlStyle (ControlStyles.OptimizedDoubleBuffer), "#G4");
  841. Assert.IsFalse (c.GetControlStyle (ControlStyles.UserPaint), "#G5");
  842. c.SetControlStyle (ControlStyles.AllPaintingInWmPaint, true);
  843. c.SetControlStyle (ControlStyles.OptimizedDoubleBuffer, true);
  844. c.SetControlStyle (ControlStyles.DoubleBuffer, true);
  845. c.SetControlStyle (ControlStyles.UserPaint, true);
  846. c.IsDoubleBuffered = false;
  847. Assert.IsFalse (c.IsDoubleBuffered, "#H1");
  848. Assert.IsTrue (c.GetControlStyle (ControlStyles.AllPaintingInWmPaint), "#H2");
  849. Assert.IsTrue (c.GetControlStyle (ControlStyles.DoubleBuffer), "#H3");
  850. Assert.IsFalse (c.GetControlStyle (ControlStyles.OptimizedDoubleBuffer), "#H4");
  851. Assert.IsTrue (c.GetControlStyle (ControlStyles.UserPaint), "#H5");
  852. }
  853. [Test]
  854. public void DoubleBufferedStyleTest ()
  855. {
  856. DoubleBufferControl c = new DoubleBufferControl ();
  857. TestControlStyle.CheckStyles (c, "#A1", ControlStyles.UserPaint, ControlStyles.StandardClick, ControlStyles.Selectable, ControlStyles.StandardDoubleClick, ControlStyles.AllPaintingInWmPaint, ControlStyles.UseTextForAccessibility);
  858. c.IsDoubleBuffered = true;
  859. TestControlStyle.CheckStyles (c, "#A2", ControlStyles.UserPaint, ControlStyles.StandardClick, ControlStyles.Selectable, ControlStyles.StandardDoubleClick, ControlStyles.AllPaintingInWmPaint, ControlStyles.UseTextForAccessibility, ControlStyles.OptimizedDoubleBuffer);
  860. c.IsDoubleBuffered = false;
  861. TestControlStyle.CheckStyles (c, "#A3", ControlStyles.UserPaint, ControlStyles.StandardClick, ControlStyles.Selectable, ControlStyles.StandardDoubleClick, ControlStyles.AllPaintingInWmPaint, ControlStyles.UseTextForAccessibility);
  862. c = new DoubleBufferControl ();
  863. foreach (ControlStyles style in Enum.GetValues (typeof(ControlStyles))) {
  864. c.SetControlStyle (style, false);
  865. }
  866. TestControlStyle.CheckStyles (c, "#B1");
  867. c.IsDoubleBuffered = true;
  868. TestControlStyle.CheckStyles (c, "#B2", ControlStyles.OptimizedDoubleBuffer, ControlStyles.AllPaintingInWmPaint);
  869. c.IsDoubleBuffered = false;
  870. TestControlStyle.CheckStyles (c, "#B3", ControlStyles.AllPaintingInWmPaint);
  871. }
  872. #endif
  873. class Helper {
  874. public static void TestAccessibility(Control c, string Default, string Description, string Name, AccessibleRole Role)
  875. {
  876. Assert.IsNotNull (c.AccessibilityObject, "Acc1");
  877. Assert.AreEqual (Default, c.AccessibleDefaultActionDescription, "Acc2");
  878. Assert.AreEqual (Description, c.AccessibleDescription, "Acc3");
  879. Assert.AreEqual (Name, c.AccessibleName, "Acc4");
  880. Assert.AreEqual (Role, c.AccessibleRole, "Acc5");
  881. }
  882. public static string TestControl(Control container, Control start, bool forward) {
  883. Control ctl;
  884. ctl = container.GetNextControl(start, forward);
  885. if (ctl == null) {
  886. return null;
  887. }
  888. return ctl.Text;
  889. }
  890. }
  891. [Test]
  892. public void CreatedTest ()
  893. {
  894. Control c = new Control ();
  895. Assert.IsFalse (c.Created, "A1");
  896. }
  897. [Test]
  898. [Category ("NotWorking")]
  899. public void CreatedAccessibilityTest ()
  900. {
  901. Control c = new Control ();
  902. Assert.IsFalse (c.Created, "A1");
  903. Helper.TestAccessibility(c, null, null, null, AccessibleRole.Default);
  904. Assert.IsTrue (c.Created, "A2");
  905. c.Dispose ();
  906. Assert.IsFalse (c.Created, "A3");
  907. }
  908. [Test]
  909. [Category ("NotWorking")]
  910. public void BoundsTest ()
  911. {
  912. Control c = new Control ();
  913. Assert.IsTrue (c.Bounds.IsEmpty, "A1");
  914. Assert.IsTrue (c.Size.IsEmpty, "A2");
  915. Assert.IsTrue (c.ClientSize.IsEmpty, "A3");
  916. Assert.IsTrue (c.ClientRectangle.IsEmpty, "A4");
  917. Assert.AreEqual (((IWin32Window)c).Handle, c.Handle, "A5");
  918. /* this part fails on linux because we can't allocate X windows which are 0x0,
  919. and the Control bounds directly reflect the size of the X window */
  920. Assert.IsTrue (c.Bounds.IsEmpty, "A6");
  921. Assert.IsTrue (c.Size.IsEmpty, "A7");
  922. Assert.IsTrue (c.ClientSize.IsEmpty, "A8");
  923. Assert.IsTrue (c.ClientRectangle.IsEmpty, "A9");
  924. }
  925. [Test]
  926. [Ignore ("Depends on specific DPI")]
  927. public void FontHeightTest ()
  928. {
  929. MockControl c = new MockControl ();
  930. Assert.AreEqual (13, c.font_height);
  931. }
  932. [Test]
  933. public void FontTest ()
  934. {
  935. Control c = new Control ();
  936. Assert.IsFalse (c.Font.Bold, "#A1");
  937. //Assert.AreEqual ("Microsoft Sans Serif", c.Font.FontFamily.Name, "#A2");
  938. Assert.IsFalse (c.Font.Italic, "#A3");
  939. //Assert.AreEqual ("Microsoft Sans Serif", c.Font.Name, "#A4");
  940. Assert.AreEqual (8.25, c.Font.Size, "#A5");
  941. Assert.AreEqual (8.25, c.Font.SizeInPoints, "#A6");
  942. Assert.IsFalse (c.Font.Strikeout, "#A7");
  943. Assert.IsFalse (c.Font.Underline, "#A8");
  944. Assert.AreEqual (GraphicsUnit.Point, c.Font.Unit, "#A9");
  945. #if NET_2_0
  946. Assert.IsTrue (c.Font.IsSystemFont, "#A10");
  947. #endif
  948. c.Font = new Font (c.Font.FontFamily, 3, FontStyle.Italic);
  949. Assert.IsFalse (c.Font.Bold, "#B1");
  950. //Assert.AreEqual ("Microsoft Sans Serif", c.Font.FontFamily.Name, "#B2");
  951. Assert.IsTrue (c.Font.Italic, "#B3");
  952. //Assert.AreEqual ("Microsoft Sans Serif", c.Font.Name, "#B4");
  953. Assert.AreEqual (3, c.Font.Size, "#B5");
  954. Assert.AreEqual (3, c.Font.SizeInPoints, "#B6");
  955. Assert.IsFalse (c.Font.Strikeout, "#B7");
  956. Assert.IsFalse (c.Font.Underline, "#B8");
  957. Assert.AreEqual (GraphicsUnit.Point, c.Font.Unit, "#B9");
  958. #if NET_2_0
  959. Assert.AreEqual (false, c.Font.IsSystemFont, "#B10");
  960. #endif
  961. }
  962. [Test]
  963. [Category ("NotWorking")] // on Unix mapping is done to Bitstream Vera Sans
  964. public void FontTest_Names ()
  965. {
  966. Control c = new Control ();
  967. Assert.AreEqual ("Microsoft Sans Serif", c.Font.FontFamily.Name, "#1");
  968. Assert.AreEqual ("Microsoft Sans Serif", c.Font.Name, "#2");
  969. }
  970. [Test]
  971. public void PubPropTest()
  972. {
  973. Control c = new Control();
  974. Assert.IsFalse (c.AllowDrop , "A1");
  975. Assert.AreEqual(AnchorStyles.Top | AnchorStyles.Left, c.Anchor, "A2");
  976. Assert.AreEqual ("Control", c.BackColor.Name , "B1");
  977. Assert.IsNull (c.BackgroundImage, "B2");
  978. Assert.IsNull (c.BindingContext, "B3");
  979. #if NET_2_0
  980. Assert.AreEqual (ImageLayout.Tile, c.BackgroundImageLayout, "B4");
  981. #endif
  982. Assert.IsFalse (c.CanFocus, "C1");
  983. Assert.IsTrue (c.CanSelect, "C2");
  984. Assert.IsFalse (c.Capture, "C3");
  985. Assert.IsTrue (c.CausesValidation, "C4");
  986. Assert.IsNotNull (c.CompanyName, "C7");
  987. Assert.IsNull (c.Container, "C8");
  988. Assert.IsFalse (c.ContainsFocus, "C9");
  989. Assert.IsNull (c.ContextMenu, "C10");
  990. Assert.AreEqual (0, c.Controls.Count, "C11");
  991. Assert.IsFalse (c.Created, "C12");
  992. Assert.AreEqual (Cursors.Default, c.Cursor, "C13");
  993. Assert.IsNotNull(c.DataBindings, "D1");
  994. Assert.AreEqual("Control", Control.DefaultBackColor.Name, "D2");
  995. Assert.AreEqual("ControlText", Control.DefaultForeColor.Name, "D3");
  996. Assert.AreEqual(FontStyle.Regular, Control.DefaultFont.Style, "D4");
  997. Assert.AreEqual (new Rectangle(0, 0, 0, 0), c.DisplayRectangle , "D5");
  998. Assert.IsFalse (c.Disposing, "D6");
  999. Assert.AreEqual(DockStyle.None, c.Dock, "D7");
  1000. Assert.IsTrue (c.Enabled, "E1");
  1001. Assert.IsFalse (c.Focused, "F1");
  1002. Assert.AreEqual (FontStyle.Regular, c.Font.Style, "F2");
  1003. Assert.AreEqual (SystemColors.ControlText, c.ForeColor, "F3");
  1004. Assert.IsFalse (c.HasChildren, "H2");
  1005. Assert.AreEqual (ImeMode.NoControl, c.ImeMode, "I1");
  1006. Assert.IsFalse (c.InvokeRequired, "I2");
  1007. Assert.IsFalse (c.IsAccessible, "I3");
  1008. Assert.IsFalse (c.IsDisposed, "I4");
  1009. Assert.IsFalse (c.IsHandleCreated, "I5");
  1010. Assert.AreEqual(Point.Empty, c.Location, "L2");
  1011. #if NET_2_0
  1012. Assert.IsTrue(c.MaximumSize.IsEmpty);
  1013. Assert.IsTrue(c.MinimumSize.IsEmpty);
  1014. #endif
  1015. Assert.AreEqual (Keys.None, Control.ModifierKeys, "M1");
  1016. Assert.IsTrue (Control.MousePosition.X >= 0 && Control.MousePosition.Y >= 0, "M2");
  1017. Assert.AreEqual (MouseButtons.None, Control.MouseButtons, "M3");
  1018. Assert.AreEqual("", c.Name, "N1");
  1019. c.Name = "Control Name";
  1020. Assert.AreEqual("Control Name", c.Name, "N2");
  1021. Assert.IsNull (c.Parent, "P1");
  1022. Assert.IsNotNull (c.ProductName, "P2");
  1023. Assert.IsTrue (c.ProductName != "", "P3");
  1024. Assert.IsNotNull (c.ProductVersion, "P4");
  1025. Assert.IsTrue (c.ProductVersion != "", "P5");
  1026. Assert.IsFalse (c.RecreatingHandle, "R1");
  1027. Assert.IsNull (c.Region, "R2");
  1028. Assert.AreEqual (RightToLeft.No, c.RightToLeft, "R4");
  1029. Assert.IsNull (c.Site, "S1");
  1030. Assert.AreEqual (0, c.TabIndex , "T1");
  1031. Assert.IsTrue (c.TabStop, "T2");
  1032. Assert.IsNull (c.Tag, "T3");
  1033. Assert.AreEqual ("", c.Text, "T4");
  1034. Assert.IsTrue (c.Visible, "V1");
  1035. }
  1036. [Test]
  1037. public void SizeChangeTest ()
  1038. {
  1039. Form f = new Form ();
  1040. Control c = new Control ();
  1041. f.Controls.Add(c);
  1042. f.Show();
  1043. c.Resize += new EventHandler(SizeChangedTest_ResizeHandler);
  1044. c.Tag = true;
  1045. c.Size = c.Size;
  1046. Assert.AreEqual (true, (bool) c.Tag, "#1");
  1047. f.Close ();
  1048. }
  1049. private void SizeChangedTest_ResizeHandler (object sender, EventArgs e)
  1050. {
  1051. ((Control) sender).Tag = false;
  1052. }
  1053. [Test]
  1054. public void NegativeHeightTest ()
  1055. {
  1056. Control c = new Control ();
  1057. IntPtr handle = c.Handle;
  1058. c.Resize += new EventHandler(NegativeHeightTest_ResizeHandler);
  1059. c.Tag = -2;
  1060. c.Height = 2;
  1061. c.Height = -2;
  1062. Assert.AreEqual (0, (int) c.Tag, "#1");
  1063. c.Dispose ();
  1064. Assert.AreEqual (handle, handle, "Removes warning.");
  1065. }
  1066. private void NegativeHeightTest_ResizeHandler (object sender, EventArgs e)
  1067. {
  1068. Control c = (Control) sender;
  1069. c.Tag = c.Height;
  1070. }
  1071. [Test]
  1072. public void TopLevelControlTest () {
  1073. Control c = new Control ();
  1074. Assert.AreEqual(null, c.TopLevelControl, "T1");
  1075. Panel p = new Panel ();
  1076. p.Controls.Add (c);
  1077. Assert.AreEqual(null, c.TopLevelControl, "T2");
  1078. Form f = new Form ();
  1079. f.ShowInTaskbar = false;
  1080. f.Controls.Add (p);
  1081. Assert.AreEqual (f, c.TopLevelControl, "T3");
  1082. Assert.AreEqual (f, f.TopLevelControl, "T4");
  1083. f.Dispose ();
  1084. }
  1085. [Test]
  1086. public void RelationTest() {
  1087. Control c1;
  1088. Control c2;
  1089. c1 = new Control();
  1090. c2 = new Control();
  1091. Assert.AreEqual(true , c1.Visible , "Rel1");
  1092. Assert.AreEqual(false, c1.Contains(c2) , "Rel2");
  1093. Assert.AreEqual("System.Windows.Forms.Control", c1.ToString() , "Rel3");
  1094. c1.Controls.Add(c2);
  1095. Assert.AreEqual(true , c2.Visible , "Rel4");
  1096. Assert.AreEqual(true, c1.Contains(c2) , "Rel5");
  1097. c1.Anchor = AnchorStyles.Top;
  1098. c1.SuspendLayout ();
  1099. c1.Anchor = AnchorStyles.Left ;
  1100. c1.ResumeLayout ();
  1101. Assert.AreEqual(AnchorStyles.Left , c1.Anchor, "Rel6");
  1102. c1.SetBounds(10, 20, 30, 40) ;
  1103. Assert.AreEqual(new Rectangle(10, 20, 30, 40), c1.Bounds, "Rel7");
  1104. Assert.AreEqual(c1, c2.Parent, "Rel8");
  1105. }
  1106. [Test]
  1107. public void AnchorDockTest ()
  1108. {
  1109. Control c = new Control ();
  1110. Assert.AreEqual (DockStyle.None, c.Dock, "1");
  1111. Assert.AreEqual (AnchorStyles.Top | AnchorStyles.Left, c.Anchor, "2");
  1112. c.Dock = DockStyle.Top;
  1113. Assert.AreEqual (DockStyle.Top, c.Dock, "3");
  1114. Assert.AreEqual (AnchorStyles.Top | AnchorStyles.Left, c.Anchor, "4");
  1115. c.Anchor = AnchorStyles.Top;
  1116. Assert.AreEqual (DockStyle.None, c.Dock, "5");
  1117. Assert.AreEqual (AnchorStyles.Top, c.Anchor, "6");
  1118. }
  1119. [Test]
  1120. [Category ("NotWorking")]
  1121. public void TabOrder()
  1122. {
  1123. Form form;
  1124. //Control active;
  1125. Label label1 = new Label(); // To test non-tabstop items as well
  1126. Label label2 = new Label();
  1127. GroupBox group1 = new GroupBox();
  1128. GroupBox group2 = new GroupBox();
  1129. GroupBox group3 = new GroupBox();
  1130. TextBox text1 = new TextBox();
  1131. RadioButton radio11 = new RadioButton();
  1132. RadioButton radio12 = new RadioButton();
  1133. RadioButton radio13 = new RadioButton();
  1134. RadioButton radio14 = new RadioButton();
  1135. RadioButton radio21 = new RadioButton();
  1136. RadioButton radio22 = new RadioButton();
  1137. RadioButton radio23 = new RadioButton();
  1138. RadioButton radio24 = new RadioButton();
  1139. RadioButton radio31 = new RadioButton();
  1140. RadioButton radio32 = new RadioButton();
  1141. RadioButton radio33 = new RadioButton();
  1142. RadioButton radio34 = new RadioButton();
  1143. form = new Form();
  1144. form.ShowInTaskbar = false;
  1145. form.ClientSize = new Size (520, 520);
  1146. Assert.AreEqual(new Size(520, 520), form.ClientSize, "Tab1");
  1147. form.Text = "SWF Taborder Test App Form";
  1148. Assert.AreEqual("SWF Taborder Test App Form", form.Text, "Tab2");
  1149. label1.Location = new Point(10, 10);
  1150. Assert.AreEqual(new Point(10, 10), label1.Location, "Tab3");
  1151. label1.Text = "Label1";
  1152. form.Controls.Add(label1);
  1153. label2.Location = new Point(200, 10);
  1154. label2.Text = "Label2";
  1155. form.Controls.Add(label2);
  1156. group1.Text = "Group1";
  1157. group2.Text = "Group2";
  1158. group3.Text = "Group3";
  1159. group1.Size = new Size(200, 400);
  1160. group2.Size = new Size(200, 400);
  1161. group3.Size = new Size(180, 180);
  1162. Assert.AreEqual(new Size(180, 180), group3.Size, "Tab4");
  1163. group1.Location = new Point(10, 40);
  1164. group2.Location = new Point(220, 40);
  1165. group3.Location = new Point(10, 210);
  1166. group1.TabIndex = 30;
  1167. Assert.AreEqual(30, group1.TabIndex, "Tab5");
  1168. group1.TabStop = true;
  1169. // Don't assign, test automatic assignment
  1170. //group2.TabIndex = 0;
  1171. group2.TabStop = true;
  1172. Assert.AreEqual(0, group2.TabIndex, "Tab6");
  1173. group3.TabIndex = 35;
  1174. group3.TabStop = true;
  1175. // Test default tab index
  1176. Assert.AreEqual(0, radio11.TabIndex, "Tab7");
  1177. text1.Text = "Edit Control";
  1178. radio11.Text = "Radio 1-1 [Tab1]";
  1179. radio12.Text = "Radio 1-2 [Tab2]";
  1180. radio13.Text = "Radio 1-3 [Tab3]";
  1181. radio14.Text = "Radio 1-4 [Tab4]";
  1182. radio21.Text = "Radio 2-1 [Tab4]";
  1183. radio22.Text = "Radio 2-2 [Tab3]";
  1184. radio23.Text = "Radio 2-3 [Tab2]";
  1185. radio24.Text = "Radio 2-4 [Tab1]";
  1186. radio31.Text = "Radio 3-1 [Tab1]";
  1187. radio32.Text = "Radio 3-2 [Tab3]";
  1188. radio33.Text = "Radio 3-3 [Tab2]";
  1189. radio34.Text = "Radio 3-4 [Tab4]";
  1190. // We don't assign TabIndex for radio1X; test automatic assignment
  1191. text1.TabStop = true;
  1192. radio11.TabStop = true;
  1193. radio21.TabIndex = 4;
  1194. radio22.TabIndex = 3;
  1195. radio23.TabIndex = 2;
  1196. radio24.TabIndex = 1;
  1197. radio24.TabStop = true;
  1198. radio31.TabIndex = 11;
  1199. radio31.TabStop = true;
  1200. radio32.TabIndex = 13;
  1201. radio33.TabIndex = 12;
  1202. radio34.TabIndex = 14;
  1203. text1.Location = new Point(10, 100);
  1204. radio11.Location = new Point(10, 20);
  1205. radio12.Location = new Point(10, 40);
  1206. radio13.Location = new Point(10, 60);
  1207. radio14.Location = new Point(10, 80);
  1208. radio21.Location = new Point(10, 20);
  1209. radio22.Location = new Point(10, 40);
  1210. radio23.Location = new Point(10, 60);
  1211. radio24.Location = new Point(10, 80);
  1212. radio31.Location = new Point(10, 20);
  1213. radio32.Location = new Point(10, 40);
  1214. radio33.Location = new Point(10, 60);
  1215. radio34.Location = new Point(10, 80);
  1216. text1.Size = new Size(150, text1.PreferredHeight);
  1217. radio11.Size = new Size(150, 20);
  1218. radio12.Size = new Size(150, 20);
  1219. radio13.Size = new Size(150, 20);
  1220. radio14.Size = new Size(150, 20);
  1221. radio21.Size = new Size(150, 20);
  1222. radio22.Size = new Size(150, 20);
  1223. radio23.Size = new Size(150, 20);
  1224. radio24.Size = new Size(150, 20);
  1225. radio31.Size = new Size(150, 20);
  1226. radio32.Size = new Size(150, 20);
  1227. radio33.Size = new Size(150, 20);
  1228. radio34.Size = new Size(150, 20);
  1229. group1.Controls.Add(text1);
  1230. group1.Controls.Add(radio11);
  1231. group1.Controls.Add(radio12);
  1232. group1.Controls.Add(radio13);
  1233. group1.Controls.Add(radio14);
  1234. group2.Controls.Add(radio21);
  1235. group2.Controls.Add(radio22);
  1236. group2.Controls.Add(radio23);
  1237. group2.Controls.Add(radio24);
  1238. group3.Controls.Add(radio31);
  1239. group3.Controls.Add(radio32);
  1240. group3.Controls.Add(radio33);
  1241. group3.Controls.Add(radio34);
  1242. form.Controls.Add(group1);
  1243. form.Controls.Add(group2);
  1244. group2.Controls.Add(group3);
  1245. // Perform some tests, the TabIndex stuff below will alter the outcome
  1246. Assert.AreEqual(null, Helper.TestControl(group2, radio34, true), "Tab8");
  1247. Assert.AreEqual(31, group2.TabIndex, "Tab9");
  1248. // Does the taborder of containers and non-selectable things change behaviour?
  1249. label1.TabIndex = 5;
  1250. label2.TabIndex = 4;
  1251. group1.TabIndex = 3;
  1252. group2.TabIndex = 1;
  1253. // Start verification
  1254. Assert.AreEqual(null, Helper.TestControl(group2, radio34, true), "Tab10");
  1255. Assert.AreEqual(radio24.Text, Helper.TestControl(group2, group2, true), "Tab11");
  1256. Assert.AreEqual(radio31.Text, Helper.TestControl(group2, group3, true), "Tab12");
  1257. Assert.AreEqual(null, Helper.TestControl(group1, radio14, true), "Tab13");
  1258. Assert.AreEqual(radio23.Text, Helper.TestControl(group2, radio24, true), "Tab14");
  1259. Assert.AreEqual(group3.Text, Helper.TestControl(group2, radio21, true), "Tab15");
  1260. Assert.AreEqual(radio13.Text, Helper.TestControl(form, radio12, true), "Tab16");
  1261. Assert.AreEqual(label2.Text, Helper.TestControl(form, radio14, true), "Tab17");
  1262. Assert.AreEqual(group1.Text, Helper.TestControl(form, radio34, true), "Tab18");
  1263. Assert.AreEqual(radio23.Text, Helper.TestControl(group2, radio24, true), "Tab19");
  1264. // Sanity checks
  1265. Assert.AreEqual(null, Helper.TestControl(radio11, radio21, true), "Tab20");
  1266. Assert.AreEqual(text1.Text, Helper.TestControl(group1, radio21, true), "Tab21");
  1267. Assert.AreEqual(radio14.Text, Helper.TestControl(form, label2, false), "Tab22");
  1268. Assert.AreEqual(radio21.Text, Helper.TestControl(group2, group3, false), "Tab23");
  1269. Assert.AreEqual(4, radio21.TabIndex, "Tab24");
  1270. Assert.AreEqual(1, radio11.TabIndex, "Tab25");
  1271. Assert.AreEqual(3, radio13.TabIndex, "Tab26");
  1272. Assert.AreEqual(35, group3.TabIndex, "Tab27");
  1273. Assert.AreEqual(1, group2.TabIndex, "Tab28");
  1274. Assert.AreEqual(label1.Text, Helper.TestControl(form, form, false), "Tab29");
  1275. Assert.AreEqual(radio14.Text, Helper.TestControl(group1, group1, false), "Tab30");
  1276. Assert.AreEqual(radio34.Text, Helper.TestControl(group3, group3, false), "Tab31");
  1277. Assert.AreEqual(null, Helper.TestControl(label1, label1, false), "Tab31");
  1278. Assert.AreEqual(null, Helper.TestControl(radio11, radio21, false), "Tab32");
  1279. form.Dispose ();
  1280. }
  1281. [Test]
  1282. public void ScaleTest()
  1283. {
  1284. Control r1 = new Control();
  1285. r1.Width = 40;
  1286. r1.Height = 20;
  1287. r1.Scale(2);
  1288. Assert.AreEqual(80, r1.Width, "Scale1");
  1289. Assert.AreEqual(40, r1.Height, "Scale2");
  1290. }
  1291. #if NET_2_0
  1292. [Test]
  1293. public void ScaleChildrenTest ()
  1294. {
  1295. ScaleChildrenControl c = new ScaleChildrenControl ();
  1296. Assert.AreEqual (true, c.PublicScaleChildren, "A1");
  1297. }
  1298. private class ScaleChildrenControl : Control
  1299. {
  1300. public bool PublicScaleChildren {
  1301. get { return base.ScaleChildren; }
  1302. }
  1303. }
  1304. [Test]
  1305. public void ScaleControlTest ()
  1306. {
  1307. ScaleControl c = new ScaleControl ();
  1308. c.Location = new Point (5, 10);
  1309. c.Size = new Size (15, 20);
  1310. Assert.AreEqual (new Rectangle (5, 10, 15, 20), c.Bounds, "A1");
  1311. c.PublicScaleControl (new SizeF (1.5f, 1.3f), BoundsSpecified.All);
  1312. Assert.AreEqual (new Rectangle (8, 13, 22, 26), c.Bounds, "A2");
  1313. c.PublicScaleControl (new SizeF (2f, 1.5f), BoundsSpecified.Location);
  1314. Assert.AreEqual (new Rectangle (16, 20, 22, 26), c.Bounds, "A3");
  1315. c.PublicScaleControl (new SizeF (1.5f, 2f), BoundsSpecified.Size);
  1316. Assert.AreEqual (new Rectangle (16, 20, 33, 52), c.Bounds, "A4");
  1317. c.PublicScaleControl (new SizeF (1.5f, 1.5f), BoundsSpecified.Width);
  1318. Assert.AreEqual (new Rectangle (16, 20, 50, 52), c.Bounds, "A5");
  1319. c.PublicScaleControl (new SizeF (1.5f, 1.3f), BoundsSpecified.None);
  1320. Assert.AreEqual (new Rectangle (16, 20, 50, 52), c.Bounds, "A6");
  1321. // Test with ScaleChildren
  1322. c = new ScaleControl ();
  1323. c.Location = new Point (5, 10);
  1324. c.Size = new Size (50, 50);
  1325. Control c2 = new Control ();
  1326. c2.Location = new Point (15, 15);
  1327. c2.Size = new Size (25, 25);
  1328. c.Controls.Add (c2);
  1329. Assert.AreEqual (new Rectangle (5, 10, 50, 50), c.Bounds, "B1");
  1330. Assert.AreEqual (new Rectangle (15, 15, 25, 25), c2.Bounds, "B2");
  1331. c.scale_children = false;
  1332. c.PublicScaleControl (new SizeF (2f, 2f), BoundsSpecified.All);
  1333. Assert.AreEqual (new Rectangle (10, 20, 100, 100), c.Bounds, "B3");
  1334. Assert.AreEqual (new Rectangle (15, 15, 25, 25), c2.Bounds, "B4");
  1335. c.scale_children = true;
  1336. // Will not scale children in ScaleControl
  1337. c.PublicScaleControl (new SizeF (2f, 2f), BoundsSpecified.All);
  1338. Assert.AreEqual (new Rectangle (20, 40, 200, 200), c.Bounds, "B5");
  1339. Assert.AreEqual (new Rectangle (15, 15, 25, 25), c2.Bounds, "B6");
  1340. // Does scale children in Scale
  1341. c.Scale (new SizeF (2f, 2f));
  1342. Assert.AreEqual (new Rectangle (40, 80, 400, 400), c.Bounds, "B7");
  1343. Assert.AreEqual (new Rectangle (30, 30, 50, 50), c2.Bounds, "B8");
  1344. }
  1345. [Test]
  1346. public void GetScaledBoundsTest ()
  1347. {
  1348. ScaleControl c = new ScaleControl ();
  1349. Rectangle r = new Rectangle (10, 20, 30, 40);
  1350. Assert.AreEqual (new Rectangle (20, 10, 60, 20), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.All), "A1");
  1351. Assert.AreEqual (new Rectangle (20, 10, 30, 40), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.Location), "A2");
  1352. Assert.AreEqual (new Rectangle (10, 20, 60, 20), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.Size), "A3");
  1353. Assert.AreEqual (new Rectangle (10, 20, 30, 20), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.Height), "A4");
  1354. Assert.AreEqual (new Rectangle (20, 20, 30, 40), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.X), "A5");
  1355. Assert.AreEqual (new Rectangle (10, 20, 30, 40), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.None), "A6");
  1356. c.PublicSetTopLevel (true);
  1357. Assert.AreEqual (new Rectangle (10, 20, 60, 20), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.All), "A7");
  1358. Assert.AreEqual (new Rectangle (10, 20, 30, 40), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.Location), "A8");
  1359. Assert.AreEqual (new Rectangle (10, 20, 60, 20), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.Size), "A9");
  1360. Assert.AreEqual (new Rectangle (10, 20, 30, 20), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.Height), "A10");
  1361. Assert.AreEqual (new Rectangle (10, 20, 30, 40), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.X), "A11");
  1362. Assert.AreEqual (new Rectangle (10, 20, 30, 40), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.None), "A12");
  1363. c = new ScaleControl ();
  1364. c.PublicSetStyle (ControlStyles.FixedHeight, true);
  1365. c.PublicSetStyle (ControlStyles.FixedWidth, true);
  1366. Assert.AreEqual (new Rectangle (20, 10, 30, 40), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.All), "A13");
  1367. Assert.AreEqual (new Rectangle (20, 10, 30, 40), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.Location), "A14");
  1368. Assert.AreEqual (new Rectangle (10, 20, 30, 40), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.Size), "A15");
  1369. Assert.AreEqual (new Rectangle (10, 20, 30, 40), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.Height), "A16");
  1370. Assert.AreEqual (new Rectangle (20, 20, 30, 40), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.X), "A17");
  1371. Assert.AreEqual (new Rectangle (10, 20, 30, 40), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.None), "A18");
  1372. }
  1373. private class ScaleControl : Control
  1374. {
  1375. public bool scale_children = true;
  1376. public void PublicScaleControl (SizeF factor, BoundsSpecified specified)
  1377. {
  1378. base.ScaleControl (factor, specified);
  1379. }
  1380. public Rectangle PublicGetScaledBounds (Rectangle bounds, SizeF factor, BoundsSpecified specified)
  1381. {
  1382. return base.GetScaledBounds (bounds, factor, specified);
  1383. }
  1384. public void PublicSetStyle (ControlStyles flag, bool value)
  1385. {
  1386. base.SetStyle (flag, value);
  1387. }
  1388. public void PublicSetTopLevel (bool value)
  1389. {
  1390. base.SetTopLevel (value);
  1391. }
  1392. protected override bool ScaleChildren {
  1393. get { return scale_children; }
  1394. }
  1395. }
  1396. #endif
  1397. [Test] // Bug #347282
  1398. public void ScaleHierarchy ()
  1399. {
  1400. Form f = new Form ();
  1401. Panel p = new Panel ();
  1402. Button b = new Button ();
  1403. f.ClientSize = new Size (300, 300);
  1404. f.Controls.Add (p);
  1405. p.Controls.Add (b);
  1406. f.AutoScaleBaseSize = new Size (3, 11);
  1407. f.Show ();
  1408. // Due to font differences, all we can guarantee is that
  1409. // the button is larger that the default.
  1410. Assert.IsTrue (b.Width > 75, "A1");
  1411. Assert.IsTrue (b.Height > 23, "A2");
  1412. f.Dispose ();
  1413. }
  1414. class TestWindowTarget : IWindowTarget
  1415. {
  1416. public void OnHandleChange (IntPtr newHandle) {
  1417. }
  1418. public void OnMessage (ref Message m) {
  1419. }
  1420. }
  1421. [Test]
  1422. public void WindowTargetTest()
  1423. {
  1424. Control c = new Control ();
  1425. Assert.IsNotNull (c.WindowTarget, "WindowTarget1");
  1426. c.WindowTarget = null;
  1427. Assert.IsNull (c.WindowTarget, "WindowTarget2");
  1428. IWindowTarget existing_target = c.WindowTarget;
  1429. IWindowTarget new_target = new TestWindowTarget ();
  1430. c.WindowTarget = new_target;
  1431. Assert.AreSame (new_target, c.WindowTarget, "WindowTarget3");
  1432. TestHelper.RemoveWarning (existing_target);
  1433. }
  1434. [Test]
  1435. public void TextTest()
  1436. {
  1437. Control r1 = new Control();
  1438. r1.Text = "Hi" ;
  1439. Assert.AreEqual("Hi" , r1.Text , "Text1");
  1440. r1.ResetText();
  1441. Assert.AreEqual("" , r1.Text , "Text2");
  1442. }
  1443. [Test]
  1444. public void PubMethodTest7()
  1445. {
  1446. Control r1 = new Control();
  1447. r1.RightToLeft = RightToLeft.Yes ;
  1448. r1.ResetRightToLeft() ;
  1449. Assert.AreEqual(RightToLeft.No , r1.RightToLeft , "#81");
  1450. r1.ImeMode = ImeMode.Off ;
  1451. r1.ResetImeMode () ;
  1452. Assert.AreEqual(ImeMode.NoControl , r1.ImeMode , "#82");
  1453. r1.ForeColor= SystemColors.GrayText ;
  1454. r1.ResetForeColor() ;
  1455. Assert.AreEqual(SystemColors.ControlText , r1.ForeColor , "#83");
  1456. //r1.Font = Font.FromHdc();
  1457. r1.ResetFont () ;
  1458. //Assert.AreEqual(FontFamily.GenericSansSerif , r1.Font , "#83");
  1459. r1.Cursor = Cursors.Hand ;
  1460. r1.ResetCursor () ;
  1461. Assert.AreEqual(Cursors.Default , r1.Cursor , "#83");
  1462. //r1.DataBindings = System.Windows.Forms.Binding ;
  1463. //r1.ResetBindings() ;
  1464. //Assert.AreEqual(ControlBindingsCollection , r1.DataBindings , "#83");
  1465. r1.BackColor = Color.Black ;
  1466. r1.ResetBackColor() ;
  1467. Assert.AreEqual( SystemColors.Control , r1.BackColor , "#84");
  1468. r1.BackColor = Color.Black ;
  1469. r1.Refresh() ;
  1470. Assert.AreEqual( null , r1.Region , "#85");
  1471. Rectangle M = new Rectangle(10, 20, 30 ,40);
  1472. r1.RectangleToScreen(M) ;
  1473. Assert.AreEqual( null , r1.Region , "#86");
  1474. }
  1475. [Test]
  1476. public void ScreenClientCoords()
  1477. {
  1478. Label l;
  1479. Point p1;
  1480. Point p2;
  1481. Point p3;
  1482. l = new Label();
  1483. l.Left = 10;
  1484. l.Top = 12;
  1485. l.Visible = true;
  1486. p1 = new Point (10,10);
  1487. p2 = l.PointToScreen(p1);
  1488. p3 = l.PointToClient(p2);
  1489. Assert.AreEqual (p1, p3, "SC1");
  1490. }
  1491. [Test]
  1492. public void ContainsTest ()
  1493. {
  1494. Control t = new Control ();
  1495. Control s = new Control ();
  1496. t.Controls.Add (s);
  1497. Assert.AreEqual (true, t.Contains (s), "Con1");
  1498. Assert.AreEqual (false, s.Contains (t), "Con2");
  1499. Assert.AreEqual (false, s.Contains (null), "Con3");
  1500. Assert.AreEqual (false, t.Contains (new Control ()), "Con4");
  1501. }
  1502. [Test]
  1503. public void IsHandleCreated_NotVisible ()
  1504. {
  1505. Control c = new Control ();
  1506. c.Visible = false;
  1507. Form form = new Form ();
  1508. form.ShowInTaskbar = false;
  1509. form.Controls.Add (c);
  1510. form.Show ();
  1511. Assert.IsFalse (c.IsHandleCreated, "#1");
  1512. c.Visible = true;
  1513. Assert.IsTrue (c.IsHandleCreated, "#2");
  1514. c.Visible = false;
  1515. Assert.IsTrue (c.IsHandleCreated, "#3");
  1516. form.Close ();
  1517. }
  1518. class OnCreateControlTest : Control {
  1519. public bool reached = false;
  1520. protected override void OnCreateControl () {
  1521. reached = true;
  1522. }
  1523. }
  1524. [Test]
  1525. public void CreateControlVisibleTest ()
  1526. {
  1527. OnCreateControlTest test = new OnCreateControlTest ();
  1528. test.Visible = false;
  1529. Assert.IsFalse (test.IsHandleCreated, "0");
  1530. Assert.IsFalse (test.Visible, "1");
  1531. test.Visible = true;
  1532. Assert.IsTrue (test.Visible, "2");
  1533. Assert.IsTrue (test.reached, "3");
  1534. }
  1535. [Test]
  1536. public void CreateGraphicsTest ()
  1537. {
  1538. Graphics g = null;
  1539. Pen p = null;
  1540. try {
  1541. Control c = new Control ();
  1542. c.SetBounds (0,0, 20, 20);
  1543. g = c.CreateGraphics ();
  1544. Assert.IsNotNull (g, "Graph1");
  1545. } finally {
  1546. if (p != null)
  1547. p.Dispose ();
  1548. if (g != null)
  1549. g.Dispose ();
  1550. }
  1551. }
  1552. bool delegateCalled = false;
  1553. public delegate void TestDelegate ();
  1554. public void delegate_call () {
  1555. delegateCalled = true;
  1556. TestHelper.RemoveWarning (delegateCalled);
  1557. }
  1558. [Test]
  1559. [ExpectedException(typeof(InvalidOperationException))]
  1560. public void InvokeException1 () {
  1561. Control c = new Control ();
  1562. IAsyncResult result;
  1563. result = c.BeginInvoke (new TestDelegate (delegate_call));
  1564. c.EndInvoke (result);
  1565. }
  1566. [Test]
  1567. public void FindFormTest () {
  1568. Form f = new Form ();
  1569. f.ShowInTaskbar = false;
  1570. f.Name = "form";
  1571. Control c = null;
  1572. try {
  1573. f.Controls.Add (c = new Control ());
  1574. Assert.AreEqual (f.Name, c.FindForm ().Name, "Find1");
  1575. f.Controls.Remove (c);
  1576. GroupBox g = new GroupBox ();
  1577. g.Name = "box";
  1578. f.Controls.Add (g);
  1579. g.Controls.Add (c);
  1580. Assert.AreEqual (f.Name, f.FindForm ().Name, "Find2");
  1581. g.Controls.Remove (c);
  1582. Assert.IsNull(c.FindForm (), "Find3");
  1583. } finally {
  1584. if (c != null)
  1585. c.Dispose ();
  1586. if (f != null)
  1587. f.Dispose ();
  1588. }
  1589. }
  1590. [Test]
  1591. public void FocusTest ()
  1592. {
  1593. Form f = null;
  1594. Button c = null, d = null;
  1595. try {
  1596. f = new Form ();
  1597. f.ShowInTaskbar = false;
  1598. f.Visible = true;
  1599. c = new Button ();
  1600. c.Visible = true;
  1601. f.Controls.Add (c);
  1602. d = new Button ();
  1603. d.Visible = false;
  1604. f.Controls.Add (d);
  1605. Assert.IsTrue (c.CanFocus, "Focus1");
  1606. Assert.IsFalse (c.Focused, "Focus2");
  1607. c.Focus ();
  1608. Assert.IsTrue (c.Focused, "Focus3");
  1609. d.Focus ();
  1610. Assert.IsFalse (d.Focused, "Focus4");
  1611. d.Visible = true;
  1612. d.Focus ();
  1613. Assert.IsTrue (d.Focused, "Focus5");
  1614. Assert.IsFalse (c.Focused, "Focus6");
  1615. c.Enabled = false;
  1616. Assert.IsFalse (c.Focused, "Focus7");
  1617. } finally {
  1618. if (f != null)
  1619. f.Dispose ();
  1620. if (c != null)
  1621. c.Dispose ();
  1622. if (d != null)
  1623. d.Dispose ();
  1624. }
  1625. }
  1626. [Test]
  1627. public void FromHandleTest ()
  1628. {
  1629. Control c1 = null;
  1630. Control c2 = null;
  1631. try {
  1632. c1 = new Control ();
  1633. c2 = new Control ();
  1634. c1.Name = "parent";
  1635. c2.Name = "child";
  1636. c1.Controls.Add(c2);
  1637. // Handle
  1638. Assert.AreEqual (c1.Name, Control.FromHandle (c1.Handle).Name, "Handle1");
  1639. Assert.IsNull (Control.FromHandle (IntPtr.Zero), "Handle2");
  1640. // ChildHandle
  1641. Assert.AreEqual (c1.Name, Control.FromChildHandle (c1.Handle).Name, "Handle3");
  1642. Assert.IsNull (Control.FromChildHandle (IntPtr.Zero), "Handle4");
  1643. } finally {
  1644. if (c1 != null)
  1645. c1.Dispose ();
  1646. if (c2 != null)
  1647. c2.Dispose ();
  1648. }
  1649. }
  1650. [Test]
  1651. public void GetChildAtPointTest ()
  1652. {
  1653. Control c = null, d = null;
  1654. TransparentControl e = null;
  1655. try {
  1656. c = new Control ();
  1657. c.Name = "c1";
  1658. c.SetBounds (0, 0, 100, 100);
  1659. d = new Control ();
  1660. d.Name = "d1";
  1661. d.SetBounds (10, 10, 40, 40);
  1662. c.Controls.Add (d);
  1663. e = new TransparentControl ();
  1664. e.Name = "e1";
  1665. e.SetBounds (55, 55, 10, 10);
  1666. Control l = c.GetChildAtPoint (new Point (15, 15));
  1667. Assert.AreEqual (d.Name, l.Name, "Child1");
  1668. Assert.IsFalse (e.Name == l.Name, "Child2");
  1669. l = c.GetChildAtPoint (new Point (57, 57));
  1670. Assert.AreEqual (null, l, "Child3");
  1671. l = c.GetChildAtPoint (new Point (10, 10));
  1672. Assert.AreEqual (d.Name, l.Name, "Child4");
  1673. // GetChildAtPointSkip is not implemented and the following test is breaking for Net_2_0 profile
  1674. #if NET_2_0
  1675. c.Controls.Add (e);
  1676. e.Visible = false;
  1677. l = c.GetChildAtPoint (new Point (57, 57), GetChildAtPointSkip.Invisible);
  1678. Assert.IsNull (l, "Child5");
  1679. e.Visible = true;
  1680. l = c.GetChildAtPoint (new Point (57, 57), GetChildAtPointSkip.Invisible);
  1681. Assert.AreSame (e.Name, l.Name, "Child6");
  1682. e.Enabled = false;
  1683. l = c.GetChildAtPoint (new Point (57, 57), GetChildAtPointSkip.Disabled);
  1684. Assert.IsNull (l, "Child7");
  1685. e.Enabled = true;
  1686. l = c.GetChildAtPoint (new Point (57, 57), GetChildAtPointSkip.Disabled);
  1687. Assert.AreSame (e.Name, l.Name, "Child8");
  1688. e.BackColor = Color.Transparent;
  1689. l = c.GetChildAtPoint (new Point (57, 57), GetChildAtPointSkip.Transparent);
  1690. Assert.IsNull (l, "Child9");
  1691. e.BackColor = Color.Green;
  1692. l = c.GetChildAtPoint (new Point (57, 57), GetChildAtPointSkip.Transparent);
  1693. Assert.AreSame (e.Name, l.Name, "Child10");
  1694. #endif // NET_2_0
  1695. } finally {
  1696. if (c != null)
  1697. c.Dispose ();
  1698. if (d != null)
  1699. d.Dispose ();
  1700. }
  1701. }
  1702. private class TransparentControl : Control
  1703. {
  1704. public TransparentControl ()
  1705. {
  1706. SetStyle (ControlStyles.SupportsTransparentBackColor, true);
  1707. }
  1708. protected override CreateParams CreateParams
  1709. {
  1710. get
  1711. {
  1712. CreateParams cp = base.CreateParams;
  1713. cp.ExStyle |= 0x00000020;
  1714. return cp;
  1715. }
  1716. }
  1717. }
  1718. [Test]
  1719. public void ResetFontTest ()
  1720. {
  1721. Control c = new Control ();
  1722. c.Font = new Font (c.Font.FontFamily, 3, FontStyle.Italic);
  1723. c.ResetFont ();
  1724. Assert.IsFalse (c.Font.Bold, "#1");
  1725. //Assert.AreEqual ("Microsoft Sans Serif", c.Font.FontFamily.Name, "#2");
  1726. Assert.IsFalse (c.Font.Italic, "#3");
  1727. //Assert.AreEqual ("Microsoft Sans Serif", c.Font.Name, "#4");
  1728. Assert.AreEqual (8.25, c.Font.Size, "#5");
  1729. Assert.AreEqual (8.25, c.Font.SizeInPoints, "#6");
  1730. Assert.IsFalse (c.Font.Strikeout, "#7");
  1731. Assert.IsFalse (c.Font.Underline, "#8");
  1732. Assert.AreEqual (GraphicsUnit.Point, c.Font.Unit, "#9");
  1733. #if NET_2_0
  1734. Assert.AreEqual (true, c.Font.IsSystemFont, "#10");
  1735. #endif
  1736. }
  1737. public class LayoutTestControl : Control {
  1738. public int LayoutCount;
  1739. public LayoutTestControl () : base() {
  1740. LayoutCount = 0;
  1741. }
  1742. protected override void OnLayout(LayoutEventArgs levent) {
  1743. LayoutCount++;
  1744. base.OnLayout (levent);
  1745. }
  1746. }
  1747. [Test]
  1748. public void LayoutTest() {
  1749. LayoutTestControl c;
  1750. c = new LayoutTestControl();
  1751. c.SuspendLayout();
  1752. c.SuspendLayout();
  1753. c.SuspendLayout();
  1754. c.SuspendLayout();
  1755. c.ResumeLayout(true);
  1756. c.PerformLayout();
  1757. c.ResumeLayout(true);
  1758. c.PerformLayout();
  1759. c.ResumeLayout(true);
  1760. c.PerformLayout();
  1761. c.ResumeLayout(true);
  1762. c.PerformLayout();
  1763. c.ResumeLayout(true);
  1764. c.PerformLayout();
  1765. c.ResumeLayout(true);
  1766. c.PerformLayout();
  1767. c.ResumeLayout(true);
  1768. c.PerformLayout();
  1769. c.SuspendLayout();
  1770. c.PerformLayout();
  1771. Assert.AreEqual(5, c.LayoutCount, "Layout Suspend/Resume locking does not bottom out at 0");
  1772. }
  1773. [Test]
  1774. [ExpectedException(typeof(ArgumentException))]
  1775. public void TransparentBackgroundTest1() {
  1776. Control c;
  1777. c = new Control();
  1778. c.BackColor = Color.Transparent;
  1779. }
  1780. [Test]
  1781. public void TransparentBackgroundTest2() {
  1782. Panel c;
  1783. c = new Panel();
  1784. c.BackColor = Color.Transparent;
  1785. Assert.AreEqual(Color.Transparent, c.BackColor, "Transparent background not set");
  1786. }
  1787. [Test]
  1788. public void TransparentBackgroundTest3() {
  1789. Control c;
  1790. c = new Control();
  1791. c.BackColor = Color.Empty;
  1792. Assert.AreEqual(Control.DefaultBackColor, c.BackColor, "Setting empty color failed");
  1793. }
  1794. [Test]
  1795. public void Dock_Value_Invalid ()
  1796. {
  1797. Control c = new Control ();
  1798. try {
  1799. c.Dock = (DockStyle) 666;
  1800. Assert.Fail ("#1");
  1801. } catch (InvalidEnumArgumentException ex) {
  1802. Assert.AreEqual (typeof (InvalidEnumArgumentException), ex.GetType (), "#2");
  1803. Assert.IsNotNull (ex.Message, "#3");
  1804. Assert.IsNotNull (ex.ParamName, "#4");
  1805. Assert.AreEqual ("value", ex.ParamName, "#5");
  1806. Assert.IsNull (ex.InnerException, "#6");
  1807. }
  1808. }
  1809. [Test]
  1810. public void EnabledTest1() {
  1811. Control child;
  1812. Control parent;
  1813. Control grandma;
  1814. grandma = new Control();
  1815. parent = new Control();
  1816. child = new Control();
  1817. grandma.Controls.Add(parent);
  1818. parent.Controls.Add(child);
  1819. grandma.Enabled = false;
  1820. Assert.AreEqual(grandma.Enabled, child.Enabled, "Child did not inherit disabled state");
  1821. }
  1822. int EnabledCalledCount = 0;
  1823. private void EnabledTest2EnabledChanged(object sender, EventArgs e) {
  1824. EnabledCalledCount++;
  1825. }
  1826. [Test]
  1827. public void EnabledTest2() {
  1828. // Check nesting of enabled calls
  1829. // OnEnabled is not called for disabled child controls
  1830. Control child;
  1831. Control parent;
  1832. Control grandma;
  1833. EnabledCalledCount = 0;
  1834. grandma = new Control();
  1835. parent = new Control();
  1836. child = new Control();
  1837. child.EnabledChanged += new EventHandler(EnabledTest2EnabledChanged);
  1838. grandma.Controls.Add(parent);
  1839. parent.Controls.Add(child);
  1840. grandma.Enabled = false;
  1841. Assert.AreEqual(1, EnabledCalledCount, "Child Enabled Event not properly fired");
  1842. grandma.Enabled = true;
  1843. Assert.AreEqual(2, EnabledCalledCount, "Child Enabled Event not properly fired");
  1844. child.Enabled = false;
  1845. grandma.Enabled = false;
  1846. Assert.AreEqual(3, EnabledCalledCount, "Child Enabled Event not properly fired");
  1847. }
  1848. [Test]
  1849. public void ControlsRemoveNullTest ()
  1850. {
  1851. Control c = new Control ();
  1852. c.Controls.Remove (null);
  1853. }
  1854. [Test]
  1855. public void ControlsAddNullTest ()
  1856. {
  1857. Control c = new Control ();
  1858. c.Controls.Add (null);
  1859. }
  1860. [Test]
  1861. [ExpectedException (typeof (ArgumentNullException))]
  1862. public void ControlsSetChildIndexNullTest ()
  1863. {
  1864. Control c = new Control ();
  1865. c.Controls.SetChildIndex (null, 1);
  1866. }
  1867. [Test]
  1868. [ExpectedException (typeof (ArgumentNullException))]
  1869. public void ControlsAddRangeNullTest ()
  1870. {
  1871. Control c = new Control ();
  1872. c.Controls.AddRange (null);
  1873. }
  1874. [Test]
  1875. public void ControlsAddRangeNullElementTest ()
  1876. {
  1877. Control c = new Control ();
  1878. Control[] subcontrols = new Control[2];
  1879. subcontrols[0] = new Control ();
  1880. subcontrols[1] = null;
  1881. c.Controls.AddRange (subcontrols);
  1882. }
  1883. [Test]
  1884. public void RegionTest () {
  1885. Form f = new Form ();
  1886. f.ShowInTaskbar = false;
  1887. Control c = new Control ();
  1888. f.Controls.Add (c);
  1889. Assert.IsNull (c.Region, "#A1");
  1890. f.Show ();
  1891. Assert.IsNull (c.Region, "#A2");
  1892. c.Region = null;
  1893. Assert.IsNull (c.Region, "#A3");
  1894. f.Dispose ();
  1895. Region region = new Region ();
  1896. f = new Form ();
  1897. f.ShowInTaskbar = false;
  1898. c = new Control ();
  1899. f.Controls.Add (c);
  1900. c.Region = region;
  1901. Assert.IsNotNull (c.Region, "#B1");
  1902. Assert.AreSame (region, c.Region, "#B2");
  1903. f.Show ();
  1904. c.Region = null;
  1905. Assert.IsNull (c.Region, "#B3");
  1906. f.Dispose ();
  1907. }
  1908. [Test] // bug #330501
  1909. public void OnValidating_Parent_Close ()
  1910. {
  1911. MockControl control = new MockControl ();
  1912. Form f = new Form ();
  1913. f.Controls.Add (control);
  1914. f.ShowInTaskbar = false;
  1915. f.Show ();
  1916. Assert.AreEqual (0, control.OnValidatingCount, "#A1");
  1917. f.Close ();
  1918. Assert.AreEqual (1, control.OnValidatingCount, "#A2");
  1919. f.Dispose ();
  1920. }
  1921. [Test] // bug #80280
  1922. public void Validated_Multiple_Containers ()
  1923. {
  1924. Form form = new Form ();
  1925. form.ShowInTaskbar = false;
  1926. UserControl control1 = new UserControl();
  1927. UserControl container1 = new UserControl();
  1928. control1.Tag = true;
  1929. control1.Validated += new EventHandler (Control_ValidatedHandler);
  1930. container1.Controls.Add(control1);
  1931. form.Controls.Add (container1);
  1932. UserControl container2 = new UserControl();
  1933. UserControl control2 = new UserControl();
  1934. container2.Controls.Add(control2);
  1935. form.Controls.Add (container2);
  1936. Assert.IsTrue ((bool) control1.Tag, "#1");
  1937. control1.Select();
  1938. Assert.IsTrue ((bool) control1.Tag, "#2");
  1939. control2.Select();
  1940. Assert.IsFalse ((bool) control1.Tag, "#3");
  1941. form.Dispose ();
  1942. }
  1943. private void Control_ValidatedHandler (object sender, EventArgs e)
  1944. {
  1945. ((Control) sender).Tag = false;
  1946. }
  1947. [Test]
  1948. public void ControlReparentLocationTest ()
  1949. {
  1950. Form form = new Form ();
  1951. Label l = new Label ();
  1952. l.Location = new Point (0, 0);
  1953. form.Controls.Add (l);
  1954. form.Show ();
  1955. Assert.AreEqual (0, l.Left, "#A1");
  1956. Assert.AreEqual (0, l.Top, "#A2");
  1957. form.Hide ();
  1958. form.Controls.Remove (l);
  1959. form.Show ();
  1960. form.Controls.Add (l);
  1961. Assert.AreEqual (0, l.Left, "#A3");
  1962. Assert.AreEqual (0, l.Top, "#A4");
  1963. form.Dispose ();
  1964. }
  1965. #if NET_2_0
  1966. [Test]
  1967. public void UseWaitCursorTest ()
  1968. {
  1969. Control c = new Control ();
  1970. Assert.IsFalse (c.UseWaitCursor, "#1");
  1971. c.Cursor = Cursors.Hand;
  1972. c.UseWaitCursor = true;
  1973. Assert.AreEqual (Cursors.WaitCursor, c.Cursor, "#2");
  1974. c.UseWaitCursor = false;
  1975. Assert.AreEqual (Cursors.Hand, c.Cursor, "#3");
  1976. c.UseWaitCursor = true;
  1977. c.Cursor = Cursors.Help;
  1978. Assert.AreEqual (Cursors.WaitCursor, c.Cursor, "#4");
  1979. Assert.AreEqual (true, c.UseWaitCursor, "#5");
  1980. c.UseWaitCursor = false;
  1981. Assert.AreEqual (Cursors.Help, c.Cursor, "#6");
  1982. }
  1983. [Test] // bug #80621, #81125
  1984. public void DontCallSizeFromClientSize ()
  1985. {
  1986. SizeControl sc = new SizeControl ();
  1987. Assert.AreEqual (0, sc.size_from_client_size_count, "A1");
  1988. sc.ClientSize = new Size (300, 300);
  1989. Assert.AreEqual (0, sc.size_from_client_size_count, "A2");
  1990. SizeForm sf = new SizeForm ();
  1991. sf.ShowInTaskbar = false;
  1992. sf.Show ();
  1993. Assert.AreEqual (0, sc.size_from_client_size_count, "A3");
  1994. sc.ClientSize = new Size (300, 300);
  1995. Assert.AreEqual (0, sc.size_from_client_size_count, "A4");
  1996. sf.Dispose ();
  1997. }
  1998. private class SizeControl : Control
  1999. {
  2000. public int size_from_client_size_count = 0;
  2001. protected override Size SizeFromClientSize (Size clientSize)
  2002. {
  2003. size_from_client_size_count++;
  2004. return base.SizeFromClientSize (clientSize);
  2005. }
  2006. }
  2007. private class SizeForm : Form
  2008. {
  2009. public int size_from_client_size_count = 0;
  2010. protected override Size SizeFromClientSize (Size clientSize)
  2011. {
  2012. size_from_client_size_count++;
  2013. return base.SizeFromClientSize (clientSize);
  2014. }
  2015. }
  2016. #endif
  2017. public class MockControl : Control
  2018. {
  2019. public int OnValidatingCount;
  2020. public int OnSizeChangedCount;
  2021. public int OnResizeCount;
  2022. public int OnLocationChangedCount;
  2023. public MockControl ()
  2024. {
  2025. }
  2026. public MockControl (string text)
  2027. : base (text)
  2028. {
  2029. }
  2030. public MockControl (Control parent, string text)
  2031. : base (parent, text)
  2032. {
  2033. }
  2034. public MockControl (string text, int left, int top, int width, int height)
  2035. : base (text, left, top, width, height)
  2036. {
  2037. }
  2038. public MockControl (Control parent, string text, int left, int top, int width, int height)
  2039. : base (parent, text, left, top, width, height)
  2040. {
  2041. }
  2042. public int font_height
  2043. {
  2044. get { return base.FontHeight; }
  2045. set { base.FontHeight = value; }
  2046. }
  2047. protected override void OnLocationChanged (EventArgs e)
  2048. {
  2049. OnLocationChangedCount++;
  2050. base.OnLocationChanged (e);
  2051. }
  2052. protected override void OnSizeChanged (EventArgs e)
  2053. {
  2054. OnSizeChangedCount++;
  2055. base.OnSizeChanged (e);
  2056. }
  2057. protected override void OnResize (EventArgs e)
  2058. {
  2059. OnResizeCount++;
  2060. base.OnResize (e);
  2061. }
  2062. protected override void OnValidating (CancelEventArgs e)
  2063. {
  2064. OnValidatingCount++;
  2065. }
  2066. }
  2067. const int WM_KEYDOWN = 0x0100;
  2068. const int WM_CHAR = 0x0102;
  2069. const int WM_SYSCHAR = 0x0106;
  2070. const int WM_KEYUP = 0x0101;
  2071. #if NET_2_0
  2072. [Test]
  2073. public void MethodPreProcessControlMessage ()
  2074. {
  2075. bool testing_callstack = false;
  2076. MyControl c = new MyControl ();
  2077. Message m = new Message ();
  2078. m.HWnd = c.Handle;
  2079. m.Msg = WM_KEYDOWN;
  2080. m.WParam = (IntPtr)Keys.Down;
  2081. m.LParam = IntPtr.Zero;
  2082. if (testing_callstack) Console.WriteLine ("Start");
  2083. Assert.AreEqual (PreProcessControlState.MessageNotNeeded, c.PreProcessControlMessage (ref m), "A1");
  2084. if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
  2085. c.SetState (State.OnPreviewKeyDown);
  2086. if (testing_callstack) Console.WriteLine ("Start");
  2087. Assert.AreEqual (PreProcessControlState.MessageNeeded, c.PreProcessControlMessage (ref m), "A2");
  2088. if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
  2089. c.SetState (State.ProcessCmdKey);
  2090. if (testing_callstack) Console.WriteLine ("Start");
  2091. Assert.AreEqual (PreProcessControlState.MessageProcessed, c.PreProcessControlMessage (ref m), "A3");
  2092. if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
  2093. c.SetState (State.IsInputKey);
  2094. if (testing_callstack) Console.WriteLine ("Start");
  2095. Assert.AreEqual (PreProcessControlState.MessageNeeded, c.PreProcessControlMessage (ref m), "A4");
  2096. if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
  2097. c.SetState (State.ProcessDialogKey);
  2098. if (testing_callstack) Console.WriteLine ("Start");
  2099. Assert.AreEqual (PreProcessControlState.MessageProcessed, c.PreProcessControlMessage (ref m), "A5");
  2100. if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
  2101. m.Msg = WM_CHAR;
  2102. c.SetState (State.None);
  2103. if (testing_callstack) Console.WriteLine ("Start");
  2104. Assert.AreEqual (PreProcessControlState.MessageNotNeeded, c.PreProcessControlMessage (ref m), "A6");
  2105. if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
  2106. c.SetState (State.IsInputChar);
  2107. if (testing_callstack) Console.WriteLine ("Start");
  2108. Assert.AreEqual (PreProcessControlState.MessageNeeded, c.PreProcessControlMessage (ref m), "A7");
  2109. if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
  2110. c.SetState (State.ProcessDialogChar);
  2111. if (testing_callstack) Console.WriteLine ("Start");
  2112. Assert.AreEqual (PreProcessControlState.MessageProcessed, c.PreProcessControlMessage (ref m), "A8");
  2113. if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
  2114. m.Msg = WM_SYSCHAR;
  2115. c.SetState (State.None);
  2116. if (testing_callstack) Console.WriteLine ("Start");
  2117. Assert.AreEqual (PreProcessControlState.MessageNotNeeded, c.PreProcessControlMessage (ref m), "A9");
  2118. if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
  2119. c.SetState (State.IsInputChar);
  2120. if (testing_callstack) Console.WriteLine ("Start");
  2121. Assert.AreEqual (PreProcessControlState.MessageNeeded, c.PreProcessControlMessage (ref m), "A10");
  2122. if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
  2123. c.SetState (State.ProcessDialogChar);
  2124. if (testing_callstack) Console.WriteLine ("Start");
  2125. Assert.AreEqual (PreProcessControlState.MessageProcessed, c.PreProcessControlMessage (ref m), "A11");
  2126. if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
  2127. m.Msg = WM_KEYUP;
  2128. if (testing_callstack) Console.WriteLine ("Start");
  2129. Assert.AreEqual (PreProcessControlState.MessageNotNeeded, c.PreProcessControlMessage (ref m), "A12");
  2130. if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
  2131. c.SetState (State.OnPreviewKeyDown);
  2132. if (testing_callstack) Console.WriteLine ("Start");
  2133. Assert.AreEqual (PreProcessControlState.MessageNotNeeded, c.PreProcessControlMessage (ref m), "A13");
  2134. if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
  2135. c.SetState (State.ProcessCmdKey);
  2136. if (testing_callstack) Console.WriteLine ("Start");
  2137. Assert.AreEqual (PreProcessControlState.MessageNotNeeded, c.PreProcessControlMessage (ref m), "A14");
  2138. if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
  2139. c.SetState (State.IsInputKey);
  2140. if (testing_callstack) Console.WriteLine ("Start");
  2141. Assert.AreEqual (PreProcessControlState.MessageNotNeeded, c.PreProcessControlMessage (ref m), "A15");
  2142. if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
  2143. c.SetState (State.ProcessDialogKey);
  2144. if (testing_callstack) Console.WriteLine ("Start");
  2145. Assert.AreEqual (PreProcessControlState.MessageNotNeeded, c.PreProcessControlMessage (ref m), "A16");
  2146. if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
  2147. }
  2148. #endif
  2149. [Test]
  2150. public void MethodPreProcessMessage ()
  2151. {
  2152. bool testing_callstack = false;
  2153. MyControl c = new MyControl ();
  2154. Message m = new Message ();
  2155. m.HWnd = c.Handle;
  2156. m.Msg = WM_KEYDOWN;
  2157. m.WParam = (IntPtr)Keys.Down;
  2158. m.LParam = IntPtr.Zero;
  2159. if (testing_callstack) Console.WriteLine ("Start");
  2160. Assert.AreEqual (false, c.PreProcessMessage (ref m), "A1");
  2161. if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
  2162. c.SetState (State.OnPreviewKeyDown);
  2163. if (testing_callstack) Console.WriteLine ("Start");
  2164. Assert.AreEqual (false, c.PreProcessMessage (ref m), "A2");
  2165. if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
  2166. c.SetState (State.ProcessCmdKey);
  2167. if (testing_callstack) Console.WriteLine ("Start");
  2168. Assert.AreEqual (true, c.PreProcessMessage (ref m), "A3");
  2169. if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
  2170. c.SetState (State.IsInputKey);
  2171. if (testing_callstack) Console.WriteLine ("Start");
  2172. Assert.AreEqual (false, c.PreProcessMessage (ref m), "A4");
  2173. if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
  2174. c.SetState (State.ProcessDialogKey);
  2175. if (testing_callstack) Console.WriteLine ("Start");
  2176. Assert.AreEqual (true, c.PreProcessMessage (ref m), "A5");
  2177. if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
  2178. m.Msg = WM_CHAR;
  2179. c.SetState (State.None);
  2180. if (testing_callstack) Console.WriteLine ("Start");
  2181. Assert.AreEqual (false, c.PreProcessMessage (ref m), "A6");
  2182. if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
  2183. c.SetState (State.IsInputChar);
  2184. if (testing_callstack) Console.WriteLine ("Start");
  2185. Assert.AreEqual (false, c.PreProcessMessage (ref m), "A7");
  2186. if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
  2187. c.SetState (State.ProcessDialogChar);
  2188. if (testing_callstack) Console.WriteLine ("Start");
  2189. Assert.AreEqual (true, c.PreProcessMessage (ref m), "A8");
  2190. if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
  2191. m.Msg = WM_SYSCHAR;
  2192. c.SetState (State.None);
  2193. if (testing_callstack) Console.WriteLine ("Start");
  2194. Assert.AreEqual (false, c.PreProcessMessage (ref m), "A9");
  2195. if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
  2196. c.SetState (State.IsInputChar);
  2197. if (testing_callstack) Console.WriteLine ("Start");
  2198. Assert.AreEqual (false, c.PreProcessMessage (ref m), "A10");
  2199. if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
  2200. c.SetState (State.ProcessDialogChar);
  2201. if (testing_callstack) Console.WriteLine ("Start");
  2202. Assert.AreEqual (true, c.PreProcessMessage (ref m), "A11");
  2203. if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
  2204. m.Msg = WM_KEYUP;
  2205. if (testing_callstack) Console.WriteLine ("Start");
  2206. Assert.AreEqual (false, c.PreProcessMessage (ref m), "A12");
  2207. if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
  2208. c.SetState (State.OnPreviewKeyDown);
  2209. if (testing_callstack) Console.WriteLine ("Start");
  2210. Assert.AreEqual (false, c.PreProcessMessage (ref m), "A13");
  2211. if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
  2212. c.SetState (State.ProcessCmdKey);
  2213. if (testing_callstack) Console.WriteLine ("Start");
  2214. Assert.AreEqual (false, c.PreProcessMessage (ref m), "A14");
  2215. if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
  2216. c.SetState (State.IsInputKey);
  2217. if (testing_callstack) Console.WriteLine ("Start");
  2218. Assert.AreEqual (false, c.PreProcessMessage (ref m), "A15");
  2219. if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
  2220. c.SetState (State.ProcessDialogKey);
  2221. if (testing_callstack) Console.WriteLine ("Start");
  2222. Assert.AreEqual (false, c.PreProcessMessage (ref m), "A16");
  2223. if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
  2224. }
  2225. private enum State
  2226. {
  2227. None,
  2228. ProcessCmdKey,
  2229. OnPreviewKeyDown,
  2230. IsInputChar,
  2231. IsInputKey,
  2232. PreProcessMessage,
  2233. ProcessDialogKey,
  2234. ProcessDialogChar
  2235. }
  2236. private class MyControl : Control
  2237. {
  2238. private State current_state;
  2239. bool testing_callstack = false;
  2240. public void SetState (State state)
  2241. {
  2242. current_state = state;
  2243. }
  2244. protected override bool ProcessCmdKey (ref Message msg, Keys keyData)
  2245. {
  2246. if (testing_callstack) Console.Write ("ProcessCmdKey[");
  2247. if (current_state == State.ProcessCmdKey) {
  2248. if (testing_callstack) Console.WriteLine ("]");
  2249. return true;
  2250. }
  2251. bool retval = base.ProcessCmdKey (ref msg, keyData);
  2252. if (testing_callstack) Console.WriteLine ("]");
  2253. return retval;
  2254. }
  2255. #if NET_2_0
  2256. protected override void OnPreviewKeyDown (PreviewKeyDownEventArgs e)
  2257. {
  2258. if (testing_callstack) Console.Write ("OnPreviewKeyDown[");
  2259. if (current_state == State.OnPreviewKeyDown) {
  2260. e.IsInputKey = true;
  2261. if (testing_callstack) Console.WriteLine ("]");
  2262. return;
  2263. }
  2264. base.OnPreviewKeyDown (e);
  2265. if (testing_callstack) Console.WriteLine ("]");
  2266. }
  2267. #endif
  2268. protected override bool IsInputChar (char charCode)
  2269. {
  2270. if (testing_callstack) Console.Write ("IsInputChar[");
  2271. if (current_state == State.IsInputChar) {
  2272. if (testing_callstack) Console.WriteLine ("true]");
  2273. return true;
  2274. }
  2275. bool retval = base.IsInputChar (charCode);
  2276. if (testing_callstack) Console.WriteLine ("{0}]", retval.ToString ());
  2277. return retval;
  2278. }
  2279. protected override bool IsInputKey (Keys keyData)
  2280. {
  2281. if (testing_callstack) Console.Write ("IsInputKey[");
  2282. if (current_state == State.IsInputKey) {
  2283. if (testing_callstack) Console.WriteLine ("]");
  2284. return true;
  2285. }
  2286. bool retval = base.IsInputKey (keyData);
  2287. if (testing_callstack) Console.WriteLine ("]");
  2288. return retval;
  2289. }
  2290. public override bool PreProcessMessage (ref Message msg)
  2291. {
  2292. if (testing_callstack) Console.Write ("PreProcessMessage[");
  2293. if (current_state == State.PreProcessMessage) {
  2294. if (testing_callstack) Console.WriteLine ("]");
  2295. return true;
  2296. }
  2297. bool retval = base.PreProcessMessage (ref msg);
  2298. if (testing_callstack) Console.WriteLine ("]");
  2299. return retval;
  2300. }
  2301. protected override bool ProcessDialogKey (Keys keyData)
  2302. {
  2303. if (testing_callstack) Console.Write ("ProcessDialogKey[");
  2304. if (current_state == State.ProcessDialogKey) {
  2305. if (testing_callstack) Console.WriteLine ("]");
  2306. return true;
  2307. }
  2308. bool retval = base.ProcessDialogKey (keyData);
  2309. if (testing_callstack) Console.WriteLine ("]");
  2310. return retval;
  2311. }
  2312. protected override bool ProcessDialogChar (char charCode)
  2313. {
  2314. if (testing_callstack) Console.Write ("ProcessDialogChar[");
  2315. if (current_state == State.ProcessDialogChar) {
  2316. if (testing_callstack) Console.WriteLine ("]");
  2317. return true;
  2318. }
  2319. bool retval = base.ProcessDialogChar (charCode);
  2320. if (testing_callstack) Console.WriteLine ("]");
  2321. return retval;
  2322. }
  2323. }
  2324. [Test]
  2325. public void MethodIsInputChar ()
  2326. {
  2327. // Basically, show that this method always returns false
  2328. InputCharControl m = new InputCharControl ();
  2329. bool result = false;
  2330. for (int i = 0; i < 256; i++)
  2331. result |= m.PublicIsInputChar ((char)i);
  2332. Assert.AreEqual (false, result, "I1");
  2333. }
  2334. private class InputCharControl : Control
  2335. {
  2336. public bool PublicIsInputChar (char charCode)
  2337. {
  2338. return base.IsInputChar (charCode);
  2339. }
  2340. }
  2341. [Test] // bug #81118, 81718
  2342. public void VisibleTriggersLayout ()
  2343. {
  2344. Form f = new Form ();
  2345. f.ShowInTaskbar = false;
  2346. Control c = new Control ();
  2347. c.Visible = false;
  2348. f.Controls.Add (c);
  2349. c.Dock = DockStyle.Fill;
  2350. c.Visible = true;
  2351. Assert.AreEqual (f.ClientSize.Width, c.Width, "L1");
  2352. f.Dispose ();
  2353. }
  2354. [Test]
  2355. public void ResumeLayoutEffects ()
  2356. {
  2357. Form f = new Form ();
  2358. f.ShowInTaskbar = false;
  2359. f.ClientSize = new Size (300, 300);
  2360. Button button1 = new Button ();
  2361. f.Controls.Add (button1);
  2362. button1.Anchor = AnchorStyles.Right | AnchorStyles.Bottom;
  2363. button1.Location = new Point (f.ClientSize.Width - button1.Width, f.ClientSize.Height - button1.Height);
  2364. f.Show ();
  2365. Assert.AreEqual (new Point (225, 277), button1.Location, "A1");
  2366. f.SuspendLayout ();
  2367. f.Height += 10;
  2368. f.ResumeLayout (false);
  2369. f.PerformLayout ();
  2370. Assert.AreEqual (new Point (225, 277), button1.Location, "A2");
  2371. f.SuspendLayout ();
  2372. f.Height += 10;
  2373. f.ResumeLayout ();
  2374. Assert.AreEqual (new Point (225, 287), button1.Location, "A3");
  2375. f.Dispose ();
  2376. }
  2377. [Test]
  2378. public void DisposeEnumerator ()
  2379. {
  2380. // We can modify the collection while looping through it without crashing
  2381. Control c = new Control ();
  2382. c.Controls.Add (new Control ());
  2383. c.Controls.Add (new Control ());
  2384. foreach (Control c1 in c.Controls)
  2385. c.Controls.Remove (c1);
  2386. }
  2387. [Test]
  2388. public void MethodSetBounds ()
  2389. {
  2390. Control myControl = new Control();
  2391. myControl.SetBounds(10, 20, 30, 40);
  2392. myControl.SetBounds(50, 60, 70, 70, BoundsSpecified.Location);
  2393. Assert.AreEqual (new Rectangle (50, 60, 30, 40), myControl.Bounds, "A1");
  2394. }
  2395. [Test]
  2396. public void Bug386450 ()
  2397. {
  2398. // Should not crash. We have to check for the font object
  2399. // being different, not just if they represent the same font.
  2400. Form f = new Form ();
  2401. Label l = new Label ();
  2402. l.Text = "Hello";
  2403. Font f1 = new Font ("Arial", 12);
  2404. Font f2 = new Font ("Arial", 12);
  2405. l.Font = f1;
  2406. l.Font = f2;
  2407. f1.Dispose ();
  2408. f.Controls.Add (l);
  2409. f.Show ();
  2410. f.Dispose ();
  2411. }
  2412. }
  2413. [TestFixture]
  2414. public class ControlSetTopLevelTest : TestHelper
  2415. {
  2416. class ControlPoker : Control {
  2417. public void DoSetTopLevel ()
  2418. {
  2419. SetTopLevel (true);
  2420. }
  2421. public bool DoGetTopLevel ()
  2422. {
  2423. return GetTopLevel ();
  2424. }
  2425. }
  2426. [Test]
  2427. public void TestControl ()
  2428. {
  2429. ControlPoker c = new ControlPoker ();
  2430. c.Visible = false;
  2431. c.DoSetTopLevel ();
  2432. Assert.IsTrue (c.DoGetTopLevel (), "1");
  2433. Assert.IsFalse (c.Visible, "2");
  2434. }
  2435. [Test]
  2436. [ExpectedException (typeof (ArgumentException))]
  2437. public void TestChildControl ()
  2438. {
  2439. Control c1 = new Control();
  2440. ControlPoker c2 = new ControlPoker ();
  2441. c1.Controls.Add (c2);
  2442. c2.DoSetTopLevel ();
  2443. }
  2444. [Test]
  2445. [ExpectedException (typeof (ArgumentException))]
  2446. public void TestTopLevelAdd () {
  2447. Form f = new Form();
  2448. Form f1 = new Form();
  2449. f.Controls.Add(f1);
  2450. }
  2451. [Test]
  2452. [Category ("NotWorking")]
  2453. public void TestForm ()
  2454. {
  2455. Form f = new Form ();
  2456. Assert.IsFalse (f.Visible, "3");
  2457. f.TopLevel = true;
  2458. Assert.IsFalse (f.Visible, "4");
  2459. f.Dispose ();
  2460. }
  2461. }
  2462. [TestFixture]
  2463. public class ControlResizeLayoutTest : TestHelper
  2464. {
  2465. class ControlPoker : Control {
  2466. public void DoOnResize ()
  2467. {
  2468. OnResize (EventArgs.Empty);
  2469. }
  2470. }
  2471. int child_event;
  2472. string child_affected_property;
  2473. void ChildLayoutEvent (object sender, LayoutEventArgs e)
  2474. {
  2475. child_event ++;
  2476. child_affected_property = e.AffectedProperty;
  2477. }
  2478. int parent_event;
  2479. string parent_affected_property;
  2480. void ParentLayoutEvent (object sender, LayoutEventArgs e)
  2481. {
  2482. parent_event ++;
  2483. parent_affected_property = e.AffectedProperty;
  2484. TestHelper.RemoveWarning (parent_affected_property);
  2485. }
  2486. [Test]
  2487. public void Test ()
  2488. {
  2489. Panel p = new Panel ();
  2490. ControlPoker c = new ControlPoker();
  2491. p.Controls.Add (c);
  2492. p.Layout += new LayoutEventHandler (ParentLayoutEvent);
  2493. c.Layout += new LayoutEventHandler (ChildLayoutEvent);
  2494. c.DoOnResize ();
  2495. Assert.AreEqual (1, child_event, "1");
  2496. Assert.AreEqual ("Bounds", child_affected_property, "2");
  2497. Assert.AreEqual (0, parent_event, "3");
  2498. }
  2499. }
  2500. [TestFixture]
  2501. [Category ("NotWorking")]
  2502. public class ControlInvokeTest : TestHelper {
  2503. [TearDown]
  2504. protected override void TearDown ()
  2505. {
  2506. if (f != null && !f.IsDisposed)
  2507. f.Dispose ();
  2508. base.TearDown ();
  2509. }
  2510. public delegate void TestDelegate ();
  2511. Form f;
  2512. Control c;
  2513. Thread control_t;
  2514. ApplicationContext control_context;
  2515. bool delegateCalled = false;
  2516. bool threadDied = false;
  2517. object m;
  2518. void CreateControl ()
  2519. {
  2520. try {
  2521. f = new Form ();
  2522. f.ShowInTaskbar = false;
  2523. c = new Control ();
  2524. f.Controls.Add (c);
  2525. Console.WriteLine ("f.Handle = {0}", f.Handle);
  2526. Console.WriteLine ("c.Handle = {0}", c.Handle);
  2527. control_context = new ApplicationContext (f);
  2528. Monitor.Enter (m);
  2529. Console.WriteLine ("pulsing");
  2530. Monitor.Pulse (m);
  2531. Monitor.Exit (m);
  2532. Console.WriteLine ("control thread running");
  2533. Application.Run (control_context);
  2534. c.Dispose ();
  2535. Console.WriteLine ("dying");
  2536. threadDied = true;
  2537. Monitor.Enter (m);
  2538. Console.WriteLine ("pulsing again");
  2539. Monitor.Pulse (m);
  2540. Monitor.Exit (m);
  2541. } catch (Exception e) { Console.WriteLine (e); }
  2542. }
  2543. [Test]
  2544. public void InvokeTest ()
  2545. {
  2546. m = new object ();
  2547. control_t = new Thread(new ThreadStart(CreateControl));
  2548. Monitor.Enter (m);
  2549. control_t.Start ();
  2550. Console.WriteLine ("waiting on monitor");
  2551. Monitor.Wait (m);
  2552. Console.WriteLine ("making async call");
  2553. IAsyncResult result;
  2554. result = c.BeginInvoke (new TestDelegate (delegate_call));
  2555. c.EndInvoke (result);
  2556. Assert.IsTrue (delegateCalled, "Invoke1");
  2557. Monitor.Wait (m);
  2558. Assert.IsTrue (threadDied, "Invoke2");
  2559. }
  2560. public void delegate_call () {
  2561. try {
  2562. /* invoked on control_context's thread */
  2563. delegateCalled = true;
  2564. f.Dispose ();
  2565. Console.WriteLine ("calling Application.Exit");
  2566. control_context.ExitThread ();
  2567. } catch (Exception e) { Console.WriteLine (e); }
  2568. }
  2569. }
  2570. [TestFixture]
  2571. public class ControlWMTest : TestHelper
  2572. {
  2573. [Test]
  2574. public void WM_PARENTNOTIFY_Test ()
  2575. {
  2576. WMTester tester;
  2577. Control child;
  2578. int child_handle;
  2579. tester = new WMTester ();
  2580. child = new Control ();
  2581. tester.Controls.Add (child);
  2582. tester.Visible = true;
  2583. child.Visible = true;
  2584. child_handle = child.Handle.ToInt32 ();
  2585. ArrayList msgs;
  2586. Message m1;
  2587. msgs = tester.Find (WndMsg.WM_PARENTNOTIFY);
  2588. Assert.AreEqual (1, msgs.Count, "#1");
  2589. m1 = (Message) msgs [0];
  2590. Assert.AreEqual (WndMsg.WM_CREATE, ((WndMsg) LowOrder (m1.WParam)), "#2");
  2591. //Assert.AreEqual (child.Identifier??, HighOrder (m1.WParam), "#3");
  2592. Assert.AreEqual (child_handle, m1.LParam.ToInt32 (), "#4");
  2593. child.Dispose ();
  2594. msgs = tester.Find (WndMsg.WM_PARENTNOTIFY);
  2595. Assert.AreEqual (2, msgs.Count, "#5");
  2596. m1 = (Message) msgs [1];
  2597. Assert.AreEqual (WndMsg.WM_DESTROY, ((WndMsg) LowOrder (m1.WParam)), "#6");
  2598. //Assert.AreEqual (child.Identifier??, HighOrder (m1.WParam), "#7");
  2599. Assert.AreEqual (child_handle, m1.LParam.ToInt32 (), "#8");
  2600. tester.Dispose ();
  2601. }
  2602. internal static int LowOrder (int param)
  2603. {
  2604. return ((int)(short)(param & 0xffff));
  2605. }
  2606. internal static int HighOrder (int param)
  2607. {
  2608. return ((int)(short)(param >> 16));
  2609. }
  2610. internal static int LowOrder (IntPtr param)
  2611. {
  2612. return ((int)(short)(param.ToInt32 () & 0xffff));
  2613. }
  2614. internal static int HighOrder (IntPtr param)
  2615. {
  2616. return ((int)(short)(param.ToInt32 () >> 16));
  2617. }
  2618. internal class WMTester : Form
  2619. {
  2620. internal ArrayList Messages = new ArrayList ();
  2621. internal bool Contains (WndMsg msg)
  2622. {
  2623. return Contains (msg, Messages);
  2624. }
  2625. internal bool Contains (WndMsg msg, ArrayList list)
  2626. {
  2627. foreach (Message m in Messages)
  2628. {
  2629. if (m.Msg == (int) msg)
  2630. return true;
  2631. }
  2632. return false;
  2633. }
  2634. internal ArrayList Find (WndMsg msg)
  2635. {
  2636. ArrayList result = new ArrayList ();
  2637. foreach (Message m in Messages)
  2638. {
  2639. if (m.Msg == (int) msg)
  2640. result.Add (m);
  2641. }
  2642. return result;
  2643. }
  2644. protected override void WndProc(ref Message m)
  2645. {
  2646. Console.WriteLine ("WndProc: " + m.ToString ());
  2647. Messages.Add (m);
  2648. base.WndProc (ref m);
  2649. }
  2650. }
  2651. }
  2652. #if NET_2_0
  2653. [TestFixture]
  2654. public class ControlLayoutTest : TestHelper
  2655. {
  2656. [SetUp]
  2657. protected override void SetUp ()
  2658. {
  2659. _layoutCount = 0;
  2660. base.SetUp ();
  2661. }
  2662. [Test] // bug #80456
  2663. public void LayoutTest ()
  2664. {
  2665. MockLayoutEngine layoutEngine = new MockLayoutEngine ();
  2666. MockControl c = new MockControl (layoutEngine);
  2667. c.Layout += new LayoutEventHandler (LayoutEvent);
  2668. Assert.IsFalse (layoutEngine.LayoutInvoked, "#A1");
  2669. Assert.AreEqual (0, _layoutCount, "#A2");
  2670. c.PerformLayout ();
  2671. Assert.IsTrue (layoutEngine.LayoutInvoked, "#A3");
  2672. Assert.AreEqual (1, _layoutCount, "#A4");
  2673. layoutEngine.Reset ();
  2674. c.OverrideOnLayout = true;
  2675. Assert.IsFalse (layoutEngine.LayoutInvoked, "#B1");
  2676. c.PerformLayout ();
  2677. Assert.IsFalse (layoutEngine.LayoutInvoked, "#B2");
  2678. Assert.AreEqual (1, _layoutCount, "#B3");
  2679. }
  2680. void LayoutEvent (object sender, LayoutEventArgs e)
  2681. {
  2682. _layoutCount++;
  2683. }
  2684. private int _layoutCount;
  2685. class MockControl : Control
  2686. {
  2687. public MockControl (LayoutEngine layoutEngine)
  2688. {
  2689. _layoutEngine = layoutEngine;
  2690. }
  2691. public bool OverrideOnLayout
  2692. {
  2693. get { return _overrideOnLayout; }
  2694. set { _overrideOnLayout = value; }
  2695. }
  2696. protected override void OnLayout (LayoutEventArgs levent)
  2697. {
  2698. if (!OverrideOnLayout)
  2699. base.OnLayout (levent);
  2700. }
  2701. public override LayoutEngine LayoutEngine {
  2702. get {
  2703. if (_layoutEngine == null)
  2704. return base.LayoutEngine;
  2705. return _layoutEngine;
  2706. }
  2707. }
  2708. private bool _overrideOnLayout;
  2709. private LayoutEngine _layoutEngine;
  2710. }
  2711. class MockLayoutEngine : LayoutEngine
  2712. {
  2713. public bool LayoutInvoked {
  2714. get { return _layoutInvoked; }
  2715. }
  2716. public void Reset ()
  2717. {
  2718. _layoutInvoked = false;
  2719. }
  2720. public override bool Layout (object container, LayoutEventArgs args)
  2721. {
  2722. _layoutInvoked = true;
  2723. return true;
  2724. }
  2725. private bool _layoutInvoked;
  2726. }
  2727. }
  2728. #endif
  2729. }