ControlTest.cs 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971
  1. //
  2. // Copyright (c) 2005 Novell, Inc.
  3. //
  4. // Authors:
  5. // Ritvik Mayank ([email protected])
  6. //
  7. using System;
  8. using System.Collections;
  9. using InvalidEnumArgumentException = System.ComponentModel.InvalidEnumArgumentException;
  10. using System.Drawing;
  11. using System.Reflection;
  12. using System.Runtime.Remoting;
  13. using System.Threading;
  14. using System.Windows.Forms;
  15. #if NET_2_0
  16. using System.Windows.Forms.Layout;
  17. #endif
  18. using NUnit.Framework;
  19. namespace MonoTests.System.Windows.Forms
  20. {
  21. [TestFixture]
  22. public class ControlTest
  23. {
  24. public class ControlStylesTester : Control {
  25. private int style;
  26. private int ex_style;
  27. private bool or_styles;
  28. public ControlStylesTester (int Style, int ExStyle, bool OrStyles)
  29. {
  30. style = Style;
  31. ex_style = ExStyle;
  32. or_styles = OrStyles;
  33. }
  34. protected override CreateParams CreateParams {
  35. get {
  36. CreateParams result = base.CreateParams;
  37. if (or_styles) {
  38. result.Style |= style;
  39. result.ExStyle |= ex_style;
  40. } else {
  41. result.Style = style;
  42. result.ExStyle = ex_style;
  43. }
  44. return result;
  45. }
  46. }
  47. }
  48. [Test]
  49. public void ControlSizeTest ()
  50. {
  51. ControlStylesTester c = new ControlStylesTester (0x40000000, 0, true);
  52. Assert.AreEqual ("{X=0,Y=0}", c.Location.ToString (), "#L1");
  53. Assert.AreEqual ("{Width=0, Height=0}", c.Size.ToString (), "#S1");
  54. }
  55. public class OnPaintTester : Form
  56. {
  57. int counter;
  58. int total;
  59. ArrayList list = new ArrayList ();
  60. public bool Recursive;
  61. public bool TestRefresh;
  62. public bool TestInvalidate;
  63. public bool TestUpdate;
  64. #if NET_2_0
  65. public new bool DoubleBuffered {
  66. get {
  67. return base.DoubleBuffered;
  68. }
  69. set {
  70. base.DoubleBuffered = value;
  71. }
  72. }
  73. #endif
  74. protected override void OnPaint (PaintEventArgs pevent)
  75. {
  76. Assert.IsFalse (list.Contains (pevent.Graphics), "OnPaintTester.OnPaint: Got the same Graphics twice");
  77. list.Add (pevent.Graphics);
  78. if (total > 10)
  79. return;
  80. Recursive = counter > 0 || Recursive;
  81. counter++;
  82. if (counter < 2) {
  83. if (TestRefresh)
  84. Refresh ();
  85. else if (TestInvalidate)
  86. Invalidate ();
  87. else {
  88. Update ();
  89. }
  90. }
  91. base.OnPaint (pevent);
  92. counter--;
  93. total++;
  94. }
  95. public new void Show ()
  96. {
  97. base.Show ();
  98. Application.DoEvents ();
  99. }
  100. }
  101. [Test]
  102. public void ControlCollectionTest ()
  103. {
  104. Form frm = new Form ();
  105. frm.IsMdiContainer = true;
  106. Form child = new Form ();
  107. Control.ControlCollection c = new Control.ControlCollection (frm);
  108. child.MdiParent = frm;
  109. c.Add (child);
  110. }
  111. [Test]
  112. [ExpectedException (typeof (ArgumentException))]
  113. public void ControlCollectionExceptionTest ()
  114. {
  115. Form frm = new Form ();
  116. frm.IsMdiContainer = true;
  117. Form child = new Form ();
  118. Control.ControlCollection c = new Control.ControlCollection (frm);
  119. //child.MdiParent = frm;
  120. c.Add (child);
  121. }
  122. [Test]
  123. [Category ("NotWorking")]
  124. public void OnPaintTest ()
  125. {
  126. using (OnPaintTester t = new OnPaintTester ()) {
  127. t.TestRefresh = true;
  128. t.Show ();
  129. Assert.IsTrue (t.Recursive, "#1");
  130. }
  131. using (OnPaintTester t = new OnPaintTester ()) {
  132. t.TestUpdate = true;
  133. t.Show ();
  134. Assert.IsFalse (t.Recursive, "#2");
  135. }
  136. using (OnPaintTester t = new OnPaintTester ()) {
  137. t.TestInvalidate = true;
  138. t.Show ();
  139. Assert.IsFalse (t.Recursive, "#3");
  140. }
  141. }
  142. #if NET_2_0
  143. [Test]
  144. [Category ("Interactive")]
  145. public void OnPaintDoubleBufferedTest ()
  146. {
  147. using (OnPaintTester t = new OnPaintTester ()) {
  148. t.DoubleBuffered = true;
  149. t.TestRefresh = true;
  150. t.Show ();
  151. Assert.IsTrue (t.Recursive, "#1");
  152. }
  153. using (OnPaintTester t = new OnPaintTester ()) {
  154. t.DoubleBuffered = true;
  155. t.TestUpdate = true;
  156. t.Show ();
  157. Assert.IsFalse (t.Recursive, "#2");
  158. }
  159. using (OnPaintTester t = new OnPaintTester ()) {
  160. t.DoubleBuffered = true;
  161. t.TestInvalidate = true;
  162. t.Show ();
  163. Assert.IsFalse (t.Recursive, "#3");
  164. }
  165. }
  166. #endif
  167. public class PaintEventForm : Form
  168. {
  169. public ArrayList overrides = new ArrayList ();
  170. public ArrayList events = new ArrayList ();
  171. public PaintEventForm ()
  172. {
  173. Paint += new PaintEventHandler (DoubleBufferEventForm_Paint);
  174. }
  175. public bool GetControlStyle (ControlStyles style)
  176. {
  177. return base.GetStyle (style);
  178. }
  179. public void SetControlStyle (ControlStyles style, bool value)
  180. {
  181. base.SetStyle (style, value);
  182. }
  183. void DoubleBufferEventForm_Paint (object sender, PaintEventArgs e)
  184. {
  185. events.Add("Paint");
  186. }
  187. protected override void OnPaintBackground (PaintEventArgs e)
  188. {
  189. base.OnPaintBackground (e);
  190. overrides.Add("OnPaintBackground");
  191. }
  192. protected override void OnPaint (PaintEventArgs pevent)
  193. {
  194. base.OnPaint (pevent);
  195. overrides.Add("OnPaint");
  196. }
  197. }
  198. [Test]
  199. public void EventStyleTest ()
  200. {
  201. #if NET_2_0
  202. using (PaintEventForm f = new PaintEventForm ()) {
  203. f.Show ();
  204. f.SetControlStyle (ControlStyles.OptimizedDoubleBuffer, true);
  205. f.Refresh ();
  206. Assert.IsTrue (f.overrides.Contains ("OnPaintBackground"), "#A1");
  207. Assert.IsTrue (f.overrides.Contains ("OnPaint"), "#A2");
  208. Assert.IsTrue (f.events.Contains ("Paint"), "#A3");
  209. }
  210. #endif
  211. using (PaintEventForm f = new PaintEventForm ()) {
  212. f.Show ();
  213. f.SetControlStyle (ControlStyles.DoubleBuffer, true);
  214. f.Refresh ();
  215. Assert.IsTrue (f.overrides.Contains ("OnPaintBackground"), "#B1");
  216. Assert.IsTrue (f.overrides.Contains ("OnPaint"), "#B2");
  217. Assert.IsTrue (f.events.Contains ("Paint"), "#B3");
  218. }
  219. using (PaintEventForm f = new PaintEventForm ()) {
  220. f.Show ();
  221. f.SetControlStyle (ControlStyles.AllPaintingInWmPaint, true);
  222. f.Refresh ();
  223. Assert.IsTrue (f.overrides.Contains ("OnPaintBackground"), "#C1");
  224. Assert.IsTrue (f.overrides.Contains ("OnPaint"), "#C2");
  225. Assert.IsTrue (f.events.Contains ("Paint"), "#C3");
  226. }
  227. using (PaintEventForm f = new PaintEventForm ()) {
  228. f.Show ();
  229. f.SetControlStyle (ControlStyles.UserPaint, true);
  230. f.Refresh ();
  231. Assert.IsTrue (f.overrides.Contains ("OnPaintBackground"), "#D1");
  232. Assert.IsTrue (f.overrides.Contains ("OnPaint"), "#D2");
  233. Assert.IsTrue (f.events.Contains ("Paint"), "#D3");
  234. }
  235. using (PaintEventForm f = new PaintEventForm ()) {
  236. f.Show ();
  237. f.SetControlStyle (ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true);
  238. f.Refresh ();
  239. Assert.IsTrue (f.overrides.Contains ("OnPaintBackground"), "#E1");
  240. Assert.IsTrue (f.overrides.Contains ("OnPaint"), "#E2");
  241. Assert.IsTrue (f.events.Contains ("Paint"), "#E3");
  242. }
  243. using (PaintEventForm f = new PaintEventForm ()) {
  244. f.Show ();
  245. f.SetControlStyle (ControlStyles.UserPaint | ControlStyles.DoubleBuffer, true);
  246. f.Refresh ();
  247. Assert.IsTrue (f.overrides.Contains ("OnPaintBackground"), "#F1");
  248. Assert.IsTrue (f.overrides.Contains ("OnPaint"), "#F2");
  249. Assert.IsTrue (f.events.Contains ("Paint"), "#F3");
  250. }
  251. using (PaintEventForm f = new PaintEventForm ()) {
  252. f.Show ();
  253. f.SetControlStyle (ControlStyles.DoubleBuffer | ControlStyles.AllPaintingInWmPaint, true);
  254. f.Refresh ();
  255. Assert.IsTrue (f.overrides.Contains ("OnPaintBackground"), "#G1");
  256. Assert.IsTrue (f.overrides.Contains ("OnPaint"), "#G2");
  257. Assert.IsTrue (f.events.Contains ("Paint"), "#G3");
  258. }
  259. using (PaintEventForm f = new PaintEventForm ()) {
  260. f.Show ();
  261. f.SetControlStyle (ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint | ControlStyles.DoubleBuffer, true);
  262. f.Refresh ();
  263. Assert.IsTrue (f.overrides.Contains ("OnPaintBackground"), "#H1");
  264. Assert.IsTrue (f.overrides.Contains ("OnPaint"), "#H2");
  265. Assert.IsTrue (f.events.Contains ("Paint"), "#H3");
  266. }
  267. }
  268. #if NET_2_0
  269. public class DoubleBufferedForm : Form
  270. {
  271. public bool painted;
  272. public bool failed;
  273. public DoubleBufferedForm ()
  274. {
  275. this.DoubleBuffered = true;
  276. }
  277. protected override void OnPaint (PaintEventArgs e)
  278. {
  279. if (failed || painted)
  280. return;
  281. painted = true;
  282. Height = Height + 1;
  283. try {
  284. e.Graphics.DrawString (Size.ToString (), Font, Brushes.AliceBlue, new Point (2, 2));
  285. } catch (Exception exception) {
  286. Console.WriteLine (exception.StackTrace);
  287. failed = true;
  288. }
  289. }
  290. }
  291. public class DoubleBufferControl : Control
  292. {
  293. public bool IsDoubleBuffered
  294. {
  295. get { return base.DoubleBuffered; }
  296. set { base.DoubleBuffered = value; }
  297. }
  298. public bool GetControlStyle (ControlStyles style)
  299. {
  300. return base.GetStyle (style);
  301. }
  302. public void SetControlStyle (ControlStyles style, bool value)
  303. {
  304. base.SetStyle (style, value);
  305. }
  306. }
  307. [Test]
  308. public void DoubleBufferTest ()
  309. {
  310. DoubleBufferedForm f = new DoubleBufferedForm ();
  311. f.Show ();
  312. f.Refresh ();
  313. Assert.IsFalse (f.failed, "#01");
  314. Assert.IsTrue (f.painted, "The control was never painted, so please check the test");
  315. }
  316. [Test]
  317. public void DoubleBufferedTest ()
  318. {
  319. DoubleBufferControl c = new DoubleBufferControl ();
  320. Assert.IsFalse (c.IsDoubleBuffered, "#A1");
  321. Assert.IsTrue (c.GetControlStyle (ControlStyles.AllPaintingInWmPaint), "#A2");
  322. Assert.IsFalse (c.GetControlStyle (ControlStyles.DoubleBuffer), "#A3");
  323. Assert.IsFalse (c.GetControlStyle (ControlStyles.OptimizedDoubleBuffer), "#A4");
  324. Assert.IsTrue (c.GetControlStyle (ControlStyles.UserPaint), "#A5");
  325. c.SetControlStyle (ControlStyles.OptimizedDoubleBuffer, true);
  326. Assert.IsTrue (c.IsDoubleBuffered, "#B1");
  327. Assert.IsTrue (c.GetControlStyle (ControlStyles.AllPaintingInWmPaint), "#B2");
  328. Assert.IsFalse (c.GetControlStyle (ControlStyles.DoubleBuffer), "#B3");
  329. Assert.IsTrue (c.GetControlStyle (ControlStyles.OptimizedDoubleBuffer), "#B4");
  330. Assert.IsTrue (c.GetControlStyle (ControlStyles.UserPaint), "#A5");
  331. c.SetControlStyle (ControlStyles.AllPaintingInWmPaint, false);
  332. c.SetControlStyle (ControlStyles.UserPaint, false);
  333. Assert.IsTrue (c.IsDoubleBuffered, "#C1");
  334. Assert.IsFalse (c.GetControlStyle (ControlStyles.AllPaintingInWmPaint), "#C2");
  335. Assert.IsFalse (c.GetControlStyle (ControlStyles.DoubleBuffer), "#C3");
  336. Assert.IsTrue (c.GetControlStyle (ControlStyles.OptimizedDoubleBuffer), "#C4");
  337. Assert.IsFalse (c.GetControlStyle (ControlStyles.UserPaint), "#C5");
  338. c.SetControlStyle (ControlStyles.OptimizedDoubleBuffer, false);
  339. Assert.IsFalse (c.IsDoubleBuffered, "#D1");
  340. Assert.IsFalse (c.GetControlStyle (ControlStyles.AllPaintingInWmPaint), "#D2");
  341. Assert.IsFalse (c.GetControlStyle (ControlStyles.DoubleBuffer), "#D3");
  342. Assert.IsFalse (c.GetControlStyle (ControlStyles.OptimizedDoubleBuffer), "#D4");
  343. Assert.IsFalse (c.GetControlStyle (ControlStyles.UserPaint), "#D5");
  344. c.SetControlStyle (ControlStyles.DoubleBuffer, true);
  345. Assert.IsFalse (c.IsDoubleBuffered, "#E1");
  346. Assert.IsFalse (c.GetControlStyle (ControlStyles.AllPaintingInWmPaint), "#E2");
  347. Assert.IsTrue (c.GetControlStyle (ControlStyles.DoubleBuffer), "#E3");
  348. Assert.IsFalse (c.GetControlStyle (ControlStyles.OptimizedDoubleBuffer), "#E4");
  349. Assert.IsFalse (c.GetControlStyle (ControlStyles.UserPaint), "#E5");
  350. c.SetControlStyle (ControlStyles.DoubleBuffer, false);
  351. Assert.IsFalse (c.IsDoubleBuffered, "#F1");
  352. Assert.IsFalse (c.GetControlStyle (ControlStyles.AllPaintingInWmPaint), "#F2");
  353. Assert.IsFalse (c.GetControlStyle (ControlStyles.DoubleBuffer), "#F3");
  354. Assert.IsFalse (c.GetControlStyle (ControlStyles.OptimizedDoubleBuffer), "#F4");
  355. Assert.IsFalse (c.GetControlStyle (ControlStyles.UserPaint), "#F5");
  356. c.IsDoubleBuffered = true;
  357. Assert.IsTrue (c.IsDoubleBuffered, "#G1");
  358. Assert.IsTrue (c.GetControlStyle (ControlStyles.AllPaintingInWmPaint), "#G2");
  359. Assert.IsFalse (c.GetControlStyle (ControlStyles.DoubleBuffer), "#G3");
  360. Assert.IsTrue (c.GetControlStyle (ControlStyles.OptimizedDoubleBuffer), "#G4");
  361. Assert.IsFalse (c.GetControlStyle (ControlStyles.UserPaint), "#G5");
  362. c.SetControlStyle (ControlStyles.AllPaintingInWmPaint, true);
  363. c.SetControlStyle (ControlStyles.OptimizedDoubleBuffer, true);
  364. c.SetControlStyle (ControlStyles.DoubleBuffer, true);
  365. c.SetControlStyle (ControlStyles.UserPaint, true);
  366. c.IsDoubleBuffered = false;
  367. Assert.IsFalse (c.IsDoubleBuffered, "#H1");
  368. Assert.IsTrue (c.GetControlStyle (ControlStyles.AllPaintingInWmPaint), "#H2");
  369. Assert.IsTrue (c.GetControlStyle (ControlStyles.DoubleBuffer), "#H3");
  370. Assert.IsFalse (c.GetControlStyle (ControlStyles.OptimizedDoubleBuffer), "#H4");
  371. Assert.IsTrue (c.GetControlStyle (ControlStyles.UserPaint), "#H5");
  372. }
  373. [Test]
  374. public void DoubleBufferedStyleTest ()
  375. {
  376. DoubleBufferControl c = new DoubleBufferControl ();
  377. TestControlStyle.CheckStyles (c, "#A1", ControlStyles.UserPaint, ControlStyles.StandardClick, ControlStyles.Selectable, ControlStyles.StandardDoubleClick, ControlStyles.AllPaintingInWmPaint, ControlStyles.UseTextForAccessibility);
  378. c.IsDoubleBuffered = true;
  379. TestControlStyle.CheckStyles (c, "#A2", ControlStyles.UserPaint, ControlStyles.StandardClick, ControlStyles.Selectable, ControlStyles.StandardDoubleClick, ControlStyles.AllPaintingInWmPaint, ControlStyles.UseTextForAccessibility, ControlStyles.OptimizedDoubleBuffer);
  380. c.IsDoubleBuffered = false;
  381. TestControlStyle.CheckStyles (c, "#A3", ControlStyles.UserPaint, ControlStyles.StandardClick, ControlStyles.Selectable, ControlStyles.StandardDoubleClick, ControlStyles.AllPaintingInWmPaint, ControlStyles.UseTextForAccessibility);
  382. c = new DoubleBufferControl ();
  383. foreach (ControlStyles style in Enum.GetValues (typeof(ControlStyles))) {
  384. c.SetControlStyle (style, false);
  385. }
  386. TestControlStyle.CheckStyles (c, "#B1");
  387. c.IsDoubleBuffered = true;
  388. TestControlStyle.CheckStyles (c, "#B2", ControlStyles.OptimizedDoubleBuffer, ControlStyles.AllPaintingInWmPaint);
  389. c.IsDoubleBuffered = false;
  390. TestControlStyle.CheckStyles (c, "#B3", ControlStyles.AllPaintingInWmPaint);
  391. }
  392. #endif
  393. class Helper {
  394. public static void TestAccessibility(Control c, string Default, string Description, string Name, AccessibleRole Role)
  395. {
  396. Assert.IsNotNull (c.AccessibilityObject, "Acc1");
  397. Assert.AreEqual (Default, c.AccessibleDefaultActionDescription, "Acc2");
  398. Assert.AreEqual (Description, c.AccessibleDescription, "Acc3");
  399. Assert.AreEqual (Name, c.AccessibleName, "Acc4");
  400. Assert.AreEqual (Role, c.AccessibleRole, "Acc5");
  401. }
  402. public static string TestControl(Control container, Control start, bool forward) {
  403. Control ctl;
  404. ctl = container.GetNextControl(start, forward);
  405. if (ctl == null) {
  406. return null;
  407. }
  408. return ctl.Text;
  409. }
  410. }
  411. [Test]
  412. public void CreatedTest ()
  413. {
  414. Control c = new Control ();
  415. Assert.IsFalse (c.Created, "A1");
  416. }
  417. [Test]
  418. [Category ("NotWorking")]
  419. public void CreatedAccessibilityTest ()
  420. {
  421. Control c = new Control ();
  422. Assert.IsFalse (c.Created, "A1");
  423. Helper.TestAccessibility(c, null, null, null, AccessibleRole.Default);
  424. Assert.IsTrue (c.Created, "A2");
  425. c.Dispose ();
  426. Assert.IsFalse (c.Created, "A3");
  427. }
  428. [Test]
  429. [Category ("NotWorking")]
  430. public void BoundsTest ()
  431. {
  432. Control c = new Control ();
  433. Assert.IsTrue (c.Bounds.IsEmpty, "A1");
  434. Assert.IsTrue (c.Size.IsEmpty, "A2");
  435. Assert.IsTrue (c.ClientSize.IsEmpty, "A3");
  436. Assert.IsTrue (c.ClientRectangle.IsEmpty, "A4");
  437. Assert.AreEqual (((IWin32Window)c).Handle, c.Handle, "A5");
  438. /* this part fails on linux because we can't allocate X windows which are 0x0,
  439. and the Control bounds directly reflect the size of the X window */
  440. Assert.IsTrue (c.Bounds.IsEmpty, "A6");
  441. Assert.IsTrue (c.Size.IsEmpty, "A7");
  442. Assert.IsTrue (c.ClientSize.IsEmpty, "A8");
  443. Assert.IsTrue (c.ClientRectangle.IsEmpty, "A9");
  444. }
  445. [Test]
  446. [Ignore ("Depends on specific DPI")]
  447. public void FontHeightTest ()
  448. {
  449. MockControl c = new MockControl ();
  450. Assert.AreEqual (13, c.font_height);
  451. }
  452. [Test]
  453. public void FontTest ()
  454. {
  455. Control c = new Control ();
  456. Assert.IsFalse (c.Font.Bold, "#A1");
  457. //Assert.AreEqual ("Microsoft Sans Serif", c.Font.FontFamily.Name, "#A2");
  458. Assert.IsFalse (c.Font.Italic, "#A3");
  459. //Assert.AreEqual ("Microsoft Sans Serif", c.Font.Name, "#A4");
  460. Assert.AreEqual (8.25, c.Font.Size, "#A5");
  461. Assert.AreEqual (8.25, c.Font.SizeInPoints, "#A6");
  462. Assert.IsFalse (c.Font.Strikeout, "#A7");
  463. Assert.IsFalse (c.Font.Underline, "#A8");
  464. Assert.AreEqual (GraphicsUnit.Point, c.Font.Unit, "#A9");
  465. #if NET_2_0
  466. Assert.IsTrue (c.Font.IsSystemFont, "#A10");
  467. #endif
  468. c.Font = new Font (c.Font.FontFamily, 3, FontStyle.Italic);
  469. Assert.IsFalse (c.Font.Bold, "#B1");
  470. //Assert.AreEqual ("Microsoft Sans Serif", c.Font.FontFamily.Name, "#B2");
  471. Assert.IsTrue (c.Font.Italic, "#B3");
  472. //Assert.AreEqual ("Microsoft Sans Serif", c.Font.Name, "#B4");
  473. Assert.AreEqual (3, c.Font.Size, "#B5");
  474. Assert.AreEqual (3, c.Font.SizeInPoints, "#B6");
  475. Assert.IsFalse (c.Font.Strikeout, "#B7");
  476. Assert.IsFalse (c.Font.Underline, "#B8");
  477. Assert.AreEqual (GraphicsUnit.Point, c.Font.Unit, "#B9");
  478. #if NET_2_0
  479. Assert.AreEqual (false, c.Font.IsSystemFont, "#B10");
  480. #endif
  481. }
  482. [Test]
  483. [Category ("NotWorking")] // on Unix mapping is done to Bitstream Vera Sans
  484. public void FontTest_Names ()
  485. {
  486. Control c = new Control ();
  487. Assert.AreEqual ("Microsoft Sans Serif", c.Font.FontFamily.Name, "#1");
  488. Assert.AreEqual ("Microsoft Sans Serif", c.Font.Name, "#2");
  489. }
  490. [Test]
  491. public void PubPropTest()
  492. {
  493. Control c = new Control();
  494. Assert.IsFalse (c.AllowDrop , "A1");
  495. Assert.AreEqual(AnchorStyles.Top | AnchorStyles.Left, c.Anchor, "A2");
  496. Assert.AreEqual ("Control", c.BackColor.Name , "B1");
  497. Assert.IsNull (c.BackgroundImage, "B2");
  498. Assert.IsNull (c.BindingContext, "B3");
  499. #if NET_2_0
  500. Assert.AreEqual (ImageLayout.Tile, c.BackgroundImageLayout, "B4");
  501. #endif
  502. Assert.IsFalse (c.CanFocus, "C1");
  503. Assert.IsTrue (c.CanSelect, "C2");
  504. Assert.IsFalse (c.Capture, "C3");
  505. Assert.IsTrue (c.CausesValidation, "C4");
  506. Assert.IsNotNull (c.CompanyName, "C7");
  507. Assert.IsNull (c.Container, "C8");
  508. Assert.IsFalse (c.ContainsFocus, "C9");
  509. Assert.IsNull (c.ContextMenu, "C10");
  510. Assert.AreEqual (0, c.Controls.Count, "C11");
  511. Assert.IsFalse (c.Created, "C12");
  512. Assert.AreEqual (Cursors.Default, c.Cursor, "C13");
  513. Assert.IsNotNull(c.DataBindings, "D1");
  514. Assert.AreEqual("Control", Control.DefaultBackColor.Name, "D2");
  515. Assert.AreEqual("ControlText", Control.DefaultForeColor.Name, "D3");
  516. Assert.AreEqual(FontStyle.Regular, Control.DefaultFont.Style, "D4");
  517. Assert.AreEqual (new Rectangle(0, 0, 0, 0), c.DisplayRectangle , "D5");
  518. Assert.IsFalse (c.Disposing, "D6");
  519. Assert.AreEqual(DockStyle.None, c.Dock, "D7");
  520. Assert.IsTrue (c.Enabled, "E1");
  521. Assert.IsFalse (c.Focused, "F1");
  522. Assert.AreEqual (FontStyle.Regular, c.Font.Style, "F2");
  523. Assert.AreEqual (SystemColors.ControlText, c.ForeColor, "F3");
  524. Assert.IsFalse (c.HasChildren, "H2");
  525. Assert.AreEqual (ImeMode.NoControl, c.ImeMode, "I1");
  526. Assert.IsFalse (c.InvokeRequired, "I2");
  527. Assert.IsFalse (c.IsAccessible, "I3");
  528. Assert.IsFalse (c.IsDisposed, "I4");
  529. Assert.IsFalse (c.IsHandleCreated, "I5");
  530. Assert.AreEqual(Point.Empty, c.Location, "L2");
  531. #if NET_2_0
  532. Assert.IsTrue(c.MaximumSize.IsEmpty);
  533. Assert.IsTrue(c.MinimumSize.IsEmpty);
  534. #endif
  535. Assert.AreEqual (Keys.None, Control.ModifierKeys, "M1");
  536. Assert.IsFalse (Control.MousePosition.IsEmpty, "M2");
  537. Assert.AreEqual (MouseButtons.None, Control.MouseButtons, "M3");
  538. Assert.AreEqual("", c.Name, "N1");
  539. c.Name = "Control Name";
  540. Assert.AreEqual("Control Name", c.Name, "N2");
  541. Assert.IsNull (c.Parent, "P1");
  542. Assert.IsNotNull (c.ProductName, "P2");
  543. Assert.IsTrue (c.ProductName != "", "P3");
  544. Assert.IsNotNull (c.ProductVersion, "P4");
  545. Assert.IsTrue (c.ProductVersion != "", "P5");
  546. Assert.IsFalse (c.RecreatingHandle, "R1");
  547. Assert.IsNull (c.Region, "R2");
  548. Assert.AreEqual (RightToLeft.No, c.RightToLeft, "R4");
  549. Assert.IsNull (c.Site, "S1");
  550. Assert.AreEqual (0, c.TabIndex , "T1");
  551. Assert.IsTrue (c.TabStop, "T2");
  552. Assert.IsNull (c.Tag, "T3");
  553. Assert.AreEqual ("", c.Text, "T4");
  554. Assert.IsTrue (c.Visible, "V1");
  555. }
  556. [Test]
  557. public void SizeChangeTest ()
  558. {
  559. Form f = new Form ();
  560. Control c = new Control ();
  561. f.Controls.Add(c);
  562. f.Show();
  563. c.Resize += new EventHandler(SizeChangedTest_ResizeHandler);
  564. c.Tag = true;
  565. c.Size = c.Size;
  566. Assert.AreEqual (true, (bool) c.Tag, "#1");
  567. f.Close ();
  568. }
  569. private void SizeChangedTest_ResizeHandler (object sender, EventArgs e)
  570. {
  571. ((Control) sender).Tag = false;
  572. }
  573. [Test]
  574. public void NegativeHeightTest ()
  575. {
  576. Control c = new Control ();
  577. IntPtr handle = c.Handle;
  578. c.Resize += new EventHandler(NegativeHeightTest_ResizeHandler);
  579. c.Tag = -2;
  580. c.Height = 2;
  581. c.Height = -2;
  582. Assert.AreEqual (0, (int) c.Tag, "#1");
  583. c.Dispose ();
  584. Assert.AreEqual (handle, handle, "Removes warning.");
  585. }
  586. private void NegativeHeightTest_ResizeHandler (object sender, EventArgs e)
  587. {
  588. Control c = (Control) sender;
  589. c.Tag = c.Height;
  590. }
  591. [Test]
  592. public void TopLevelControlTest () {
  593. Control c = new Control ();
  594. Assert.AreEqual(null, c.TopLevelControl, "T1");
  595. Panel p = new Panel ();
  596. p.Controls.Add (c);
  597. Assert.AreEqual(null, c.TopLevelControl, "T2");
  598. Form f = new Form ();
  599. f.ShowInTaskbar = false;
  600. f.Controls.Add (p);
  601. Assert.AreEqual (f, c.TopLevelControl, "T3");
  602. Assert.AreEqual (f, f.TopLevelControl, "T4");
  603. }
  604. [Test]
  605. public void RelationTest() {
  606. Control c1;
  607. Control c2;
  608. c1 = new Control();
  609. c2 = new Control();
  610. Assert.AreEqual(true , c1.Visible , "Rel1");
  611. Assert.AreEqual(false, c1.Contains(c2) , "Rel2");
  612. Assert.AreEqual("System.Windows.Forms.Control", c1.ToString() , "Rel3");
  613. c1.Controls.Add(c2);
  614. Assert.AreEqual(true , c2.Visible , "Rel4");
  615. Assert.AreEqual(true, c1.Contains(c2) , "Rel5");
  616. c1.Anchor = AnchorStyles.Top;
  617. c1.SuspendLayout ();
  618. c1.Anchor = AnchorStyles.Left ;
  619. c1.ResumeLayout ();
  620. Assert.AreEqual(AnchorStyles.Left , c1.Anchor, "Rel6");
  621. c1.SetBounds(10, 20, 30, 40) ;
  622. Assert.AreEqual(new Rectangle(10, 20, 30, 40), c1.Bounds, "Rel7");
  623. Assert.AreEqual(c1, c2.Parent, "Rel8");
  624. }
  625. [Test]
  626. public void AnchorDockTest ()
  627. {
  628. Control c = new Control ();
  629. Assert.AreEqual (DockStyle.None, c.Dock, "1");
  630. Assert.AreEqual (AnchorStyles.Top | AnchorStyles.Left, c.Anchor, "2");
  631. c.Dock = DockStyle.Top;
  632. Assert.AreEqual (DockStyle.Top, c.Dock, "3");
  633. Assert.AreEqual (AnchorStyles.Top | AnchorStyles.Left, c.Anchor, "4");
  634. c.Anchor = AnchorStyles.Top;
  635. Assert.AreEqual (DockStyle.None, c.Dock, "5");
  636. Assert.AreEqual (AnchorStyles.Top, c.Anchor, "6");
  637. }
  638. [Test]
  639. [Category ("NotWorking")]
  640. public void TabOrder()
  641. {
  642. Form form;
  643. Control active;
  644. Label label1 = new Label(); // To test non-tabstop items as well
  645. Label label2 = new Label();
  646. GroupBox group1 = new GroupBox();
  647. GroupBox group2 = new GroupBox();
  648. GroupBox group3 = new GroupBox();
  649. TextBox text1 = new TextBox();
  650. RadioButton radio11 = new RadioButton();
  651. RadioButton radio12 = new RadioButton();
  652. RadioButton radio13 = new RadioButton();
  653. RadioButton radio14 = new RadioButton();
  654. RadioButton radio21 = new RadioButton();
  655. RadioButton radio22 = new RadioButton();
  656. RadioButton radio23 = new RadioButton();
  657. RadioButton radio24 = new RadioButton();
  658. RadioButton radio31 = new RadioButton();
  659. RadioButton radio32 = new RadioButton();
  660. RadioButton radio33 = new RadioButton();
  661. RadioButton radio34 = new RadioButton();
  662. form = new Form();
  663. form.ShowInTaskbar = false;
  664. form.ClientSize = new Size (520, 520);
  665. Assert.AreEqual(new Size(520, 520), form.ClientSize, "Tab1");
  666. form.Text = "SWF Taborder Test App Form";
  667. Assert.AreEqual("SWF Taborder Test App Form", form.Text, "Tab2");
  668. label1.Location = new Point(10, 10);
  669. Assert.AreEqual(new Point(10, 10), label1.Location, "Tab3");
  670. label1.Text = "Label1";
  671. form.Controls.Add(label1);
  672. label2.Location = new Point(200, 10);
  673. label2.Text = "Label2";
  674. form.Controls.Add(label2);
  675. group1.Text = "Group1";
  676. group2.Text = "Group2";
  677. group3.Text = "Group3";
  678. group1.Size = new Size(200, 400);
  679. group2.Size = new Size(200, 400);
  680. group3.Size = new Size(180, 180);
  681. Assert.AreEqual(new Size(180, 180), group3.Size, "Tab4");
  682. group1.Location = new Point(10, 40);
  683. group2.Location = new Point(220, 40);
  684. group3.Location = new Point(10, 210);
  685. group1.TabIndex = 30;
  686. Assert.AreEqual(30, group1.TabIndex, "Tab5");
  687. group1.TabStop = true;
  688. // Don't assign, test automatic assignment
  689. //group2.TabIndex = 0;
  690. group2.TabStop = true;
  691. Assert.AreEqual(0, group2.TabIndex, "Tab6");
  692. group3.TabIndex = 35;
  693. group3.TabStop = true;
  694. // Test default tab index
  695. Assert.AreEqual(0, radio11.TabIndex, "Tab7");
  696. text1.Text = "Edit Control";
  697. radio11.Text = "Radio 1-1 [Tab1]";
  698. radio12.Text = "Radio 1-2 [Tab2]";
  699. radio13.Text = "Radio 1-3 [Tab3]";
  700. radio14.Text = "Radio 1-4 [Tab4]";
  701. radio21.Text = "Radio 2-1 [Tab4]";
  702. radio22.Text = "Radio 2-2 [Tab3]";
  703. radio23.Text = "Radio 2-3 [Tab2]";
  704. radio24.Text = "Radio 2-4 [Tab1]";
  705. radio31.Text = "Radio 3-1 [Tab1]";
  706. radio32.Text = "Radio 3-2 [Tab3]";
  707. radio33.Text = "Radio 3-3 [Tab2]";
  708. radio34.Text = "Radio 3-4 [Tab4]";
  709. // We don't assign TabIndex for radio1X; test automatic assignment
  710. text1.TabStop = true;
  711. radio11.TabStop = true;
  712. radio21.TabIndex = 4;
  713. radio22.TabIndex = 3;
  714. radio23.TabIndex = 2;
  715. radio24.TabIndex = 1;
  716. radio24.TabStop = true;
  717. radio31.TabIndex = 11;
  718. radio31.TabStop = true;
  719. radio32.TabIndex = 13;
  720. radio33.TabIndex = 12;
  721. radio34.TabIndex = 14;
  722. text1.Location = new Point(10, 100);
  723. radio11.Location = new Point(10, 20);
  724. radio12.Location = new Point(10, 40);
  725. radio13.Location = new Point(10, 60);
  726. radio14.Location = new Point(10, 80);
  727. radio21.Location = new Point(10, 20);
  728. radio22.Location = new Point(10, 40);
  729. radio23.Location = new Point(10, 60);
  730. radio24.Location = new Point(10, 80);
  731. radio31.Location = new Point(10, 20);
  732. radio32.Location = new Point(10, 40);
  733. radio33.Location = new Point(10, 60);
  734. radio34.Location = new Point(10, 80);
  735. text1.Size = new Size(150, text1.PreferredHeight);
  736. radio11.Size = new Size(150, 20);
  737. radio12.Size = new Size(150, 20);
  738. radio13.Size = new Size(150, 20);
  739. radio14.Size = new Size(150, 20);
  740. radio21.Size = new Size(150, 20);
  741. radio22.Size = new Size(150, 20);
  742. radio23.Size = new Size(150, 20);
  743. radio24.Size = new Size(150, 20);
  744. radio31.Size = new Size(150, 20);
  745. radio32.Size = new Size(150, 20);
  746. radio33.Size = new Size(150, 20);
  747. radio34.Size = new Size(150, 20);
  748. group1.Controls.Add(text1);
  749. group1.Controls.Add(radio11);
  750. group1.Controls.Add(radio12);
  751. group1.Controls.Add(radio13);
  752. group1.Controls.Add(radio14);
  753. group2.Controls.Add(radio21);
  754. group2.Controls.Add(radio22);
  755. group2.Controls.Add(radio23);
  756. group2.Controls.Add(radio24);
  757. group3.Controls.Add(radio31);
  758. group3.Controls.Add(radio32);
  759. group3.Controls.Add(radio33);
  760. group3.Controls.Add(radio34);
  761. form.Controls.Add(group1);
  762. form.Controls.Add(group2);
  763. group2.Controls.Add(group3);
  764. // Perform some tests, the TabIndex stuff below will alter the outcome
  765. Assert.AreEqual(null, Helper.TestControl(group2, radio34, true), "Tab8");
  766. Assert.AreEqual(31, group2.TabIndex, "Tab9");
  767. // Does the taborder of containers and non-selectable things change behaviour?
  768. label1.TabIndex = 5;
  769. label2.TabIndex = 4;
  770. group1.TabIndex = 3;
  771. group2.TabIndex = 1;
  772. // Start verification
  773. Assert.AreEqual(null, Helper.TestControl(group2, radio34, true), "Tab10");
  774. Assert.AreEqual(radio24.Text, Helper.TestControl(group2, group2, true), "Tab11");
  775. Assert.AreEqual(radio31.Text, Helper.TestControl(group2, group3, true), "Tab12");
  776. Assert.AreEqual(null, Helper.TestControl(group1, radio14, true), "Tab13");
  777. Assert.AreEqual(radio23.Text, Helper.TestControl(group2, radio24, true), "Tab14");
  778. Assert.AreEqual(group3.Text, Helper.TestControl(group2, radio21, true), "Tab15");
  779. Assert.AreEqual(radio13.Text, Helper.TestControl(form, radio12, true), "Tab16");
  780. Assert.AreEqual(label2.Text, Helper.TestControl(form, radio14, true), "Tab17");
  781. Assert.AreEqual(group1.Text, Helper.TestControl(form, radio34, true), "Tab18");
  782. Assert.AreEqual(radio23.Text, Helper.TestControl(group2, radio24, true), "Tab19");
  783. // Sanity checks
  784. Assert.AreEqual(null, Helper.TestControl(radio11, radio21, true), "Tab20");
  785. Assert.AreEqual(text1.Text, Helper.TestControl(group1, radio21, true), "Tab21");
  786. Assert.AreEqual(radio14.Text, Helper.TestControl(form, label2, false), "Tab22");
  787. Assert.AreEqual(radio21.Text, Helper.TestControl(group2, group3, false), "Tab23");
  788. Assert.AreEqual(4, radio21.TabIndex, "Tab24");
  789. Assert.AreEqual(1, radio11.TabIndex, "Tab25");
  790. Assert.AreEqual(3, radio13.TabIndex, "Tab26");
  791. Assert.AreEqual(35, group3.TabIndex, "Tab27");
  792. Assert.AreEqual(1, group2.TabIndex, "Tab28");
  793. Assert.AreEqual(label1.Text, Helper.TestControl(form, form, false), "Tab29");
  794. Assert.AreEqual(radio14.Text, Helper.TestControl(group1, group1, false), "Tab30");
  795. Assert.AreEqual(radio34.Text, Helper.TestControl(group3, group3, false), "Tab31");
  796. Assert.AreEqual(null, Helper.TestControl(label1, label1, false), "Tab31");
  797. Assert.AreEqual(null, Helper.TestControl(radio11, radio21, false), "Tab32");
  798. form.Dispose ();
  799. }
  800. [Test]
  801. public void ScaleTest()
  802. {
  803. Control r1 = new Control();
  804. r1.Width = 40;
  805. r1.Height = 20;
  806. r1.Scale(2);
  807. Assert.AreEqual(80, r1.Width, "Scale1");
  808. Assert.AreEqual(40, r1.Height, "Scale2");
  809. }
  810. [Test]
  811. public void TextTest()
  812. {
  813. Control r1 = new Control();
  814. r1.Text = "Hi" ;
  815. Assert.AreEqual("Hi" , r1.Text , "Text1");
  816. r1.ResetText();
  817. Assert.AreEqual("" , r1.Text , "Text2");
  818. }
  819. [Test]
  820. public void PubMethodTest7()
  821. {
  822. Control r1 = new Control();
  823. r1.RightToLeft = RightToLeft.Yes ;
  824. r1.ResetRightToLeft() ;
  825. Assert.AreEqual(RightToLeft.No , r1.RightToLeft , "#81");
  826. r1.ImeMode = ImeMode.Off ;
  827. r1.ResetImeMode () ;
  828. Assert.AreEqual(ImeMode.NoControl , r1.ImeMode , "#82");
  829. r1.ForeColor= SystemColors.GrayText ;
  830. r1.ResetForeColor() ;
  831. Assert.AreEqual(SystemColors.ControlText , r1.ForeColor , "#83");
  832. //r1.Font = Font.FromHdc();
  833. r1.ResetFont () ;
  834. //Assert.AreEqual(FontFamily.GenericSansSerif , r1.Font , "#83");
  835. r1.Cursor = Cursors.Hand ;
  836. r1.ResetCursor () ;
  837. Assert.AreEqual(Cursors.Default , r1.Cursor , "#83");
  838. //r1.DataBindings = System.Windows.Forms.Binding ;
  839. //r1.ResetBindings() ;
  840. //Assert.AreEqual(ControlBindingsCollection , r1.DataBindings , "#83");
  841. r1.BackColor = Color.Black ;
  842. r1.ResetBackColor() ;
  843. Assert.AreEqual( SystemColors.Control , r1.BackColor , "#84");
  844. r1.BackColor = Color.Black ;
  845. r1.Refresh() ;
  846. Assert.AreEqual( null , r1.Region , "#85");
  847. Rectangle M = new Rectangle(10, 20, 30 ,40);
  848. r1.RectangleToScreen(M) ;
  849. Assert.AreEqual( null , r1.Region , "#86");
  850. }
  851. [Test]
  852. public void ScreenClientCoords()
  853. {
  854. Label l;
  855. Point p1;
  856. Point p2;
  857. Point p3;
  858. l = new Label();
  859. l.Left = 10;
  860. l.Top = 12;
  861. l.Visible = true;
  862. p1 = new Point (10,10);
  863. p2 = l.PointToScreen(p1);
  864. p3 = l.PointToClient(p2);
  865. Assert.AreEqual (p1, p3, "SC1");
  866. }
  867. [Test]
  868. public void ContainsTest ()
  869. {
  870. Control t = new Control ();
  871. Control s = new Control ();
  872. t.Controls.Add (s);
  873. Assert.AreEqual (true, t.Contains (s), "Con1");
  874. Assert.AreEqual (false, s.Contains (t), "Con2");
  875. Assert.AreEqual (false, s.Contains (null), "Con3");
  876. Assert.AreEqual (false, t.Contains (new Control ()), "Con4");
  877. }
  878. [Test]
  879. public void CreateHandleTest ()
  880. {
  881. Control parent;
  882. Control child;
  883. parent = null;
  884. child = null;
  885. try {
  886. parent = new Control ();
  887. child = new Control ();
  888. parent.Visible = true;
  889. parent.Controls.Add (child);
  890. Assert.IsFalse (parent.IsHandleCreated, "CH1");
  891. Assert.IsFalse (child.IsHandleCreated, "CH2");
  892. parent.CreateControl ();
  893. Assert.IsNotNull (parent.Handle, "CH3");
  894. Assert.IsNotNull (child.Handle, "CH4");
  895. Assert.IsTrue (parent.IsHandleCreated, "CH5");
  896. Assert.IsTrue (child.IsHandleCreated, "CH6");
  897. } finally {
  898. if (parent != null)
  899. parent.Dispose ();
  900. if (child != null)
  901. child.Dispose ();
  902. }
  903. // Accessing Handle Property creates the handle
  904. try {
  905. parent = new Control ();
  906. parent.Visible = true;
  907. child = new Control ();
  908. parent.Controls.Add (child);
  909. Assert.IsFalse (parent.IsHandleCreated, "CH7");
  910. Assert.IsFalse (child.IsHandleCreated, "CH8");
  911. Assert.IsNotNull (parent.Handle, "CH9");
  912. Assert.IsTrue (parent.IsHandleCreated, "CH10");
  913. Assert.IsTrue (child.IsHandleCreated, "CH11");
  914. } finally {
  915. if (parent != null)
  916. parent.Dispose ();
  917. if (child != null)
  918. child.Dispose ();
  919. }
  920. }
  921. [Test]
  922. [Category ("NotWorking")]
  923. public void CreateHandleTest2 ()
  924. {
  925. // This should eventually test all operations
  926. // that can be performed on a control (within
  927. // reason)
  928. Control c = new Control ();
  929. Assert.IsFalse (c.IsHandleCreated, "0");
  930. c.Width = 100;
  931. Assert.IsFalse (c.IsHandleCreated, "1");
  932. c.Height = 100;
  933. Assert.IsFalse (c.IsHandleCreated, "2");
  934. c.Name = "hi";
  935. Assert.IsFalse (c.IsHandleCreated, "3");
  936. c.Left = 5;
  937. Assert.IsFalse (c.IsHandleCreated, "5");
  938. c.Top = 5;
  939. Assert.IsFalse (c.IsHandleCreated, "6");
  940. c.Location = new Point (1, 1);
  941. Assert.IsFalse (c.IsHandleCreated, "7");
  942. c.Region = new Region ();
  943. Assert.IsFalse (c.IsHandleCreated, "8");
  944. c.Size = new Size (100, 100);
  945. Assert.IsFalse (c.IsHandleCreated, "9");
  946. c.Text = "bye";
  947. Assert.IsFalse (c.IsHandleCreated, "10");
  948. c.Visible = !c.Visible;
  949. Assert.IsFalse (c.IsHandleCreated, "11");
  950. }
  951. [Test]
  952. [Category ("NotWorking")]
  953. public void IsHandleCreated_NotVisible ()
  954. {
  955. Control c = new Control ();
  956. c.Visible = false;
  957. Form form = new Form ();
  958. form.ShowInTaskbar = false;
  959. form.Controls.Add (c);
  960. form.Show ();
  961. Assert.IsFalse (c.IsHandleCreated, "#1");
  962. c.Visible = true;
  963. Assert.IsTrue (c.IsHandleCreated, "#2");
  964. c.Visible = false;
  965. Assert.IsTrue (c.IsHandleCreated, "#3");
  966. }
  967. [Test]
  968. public void CreateGraphicsTest ()
  969. {
  970. Graphics g = null;
  971. Pen p = null;
  972. try {
  973. Control c = new Control ();
  974. c.SetBounds (0,0, 20, 20);
  975. g = c.CreateGraphics ();
  976. Assert.IsNotNull (g, "Graph1");
  977. } finally {
  978. if (p != null)
  979. p.Dispose ();
  980. if (g != null)
  981. g.Dispose ();
  982. }
  983. }
  984. bool delegateCalled = false;
  985. public delegate void TestDelegate ();
  986. public void delegate_call () {
  987. delegateCalled = true;
  988. }
  989. [Test]
  990. [ExpectedException(typeof(InvalidOperationException))]
  991. public void InvokeException1 () {
  992. Control c = new Control ();
  993. IAsyncResult result;
  994. result = c.BeginInvoke (new TestDelegate (delegate_call));
  995. c.EndInvoke (result);
  996. }
  997. [Test]
  998. public void FindFormTest () {
  999. Form f = new Form ();
  1000. f.ShowInTaskbar = false;
  1001. f.Name = "form";
  1002. Control c = null;
  1003. try {
  1004. f.Controls.Add (c = new Control ());
  1005. Assert.AreEqual (f.Name, c.FindForm ().Name, "Find1");
  1006. f.Controls.Remove (c);
  1007. GroupBox g = new GroupBox ();
  1008. g.Name = "box";
  1009. f.Controls.Add (g);
  1010. g.Controls.Add (c);
  1011. Assert.AreEqual (f.Name, f.FindForm ().Name, "Find2");
  1012. g.Controls.Remove (c);
  1013. Assert.IsNull(c.FindForm (), "Find3");
  1014. } finally {
  1015. if (c != null)
  1016. c.Dispose ();
  1017. if (f != null)
  1018. f.Dispose ();
  1019. }
  1020. }
  1021. [Test]
  1022. public void FocusTest ()
  1023. {
  1024. Form f = null;
  1025. Button c = null, d = null;
  1026. try {
  1027. f = new Form ();
  1028. f.ShowInTaskbar = false;
  1029. f.Visible = true;
  1030. c = new Button ();
  1031. c.Visible = true;
  1032. f.Controls.Add (c);
  1033. d = new Button ();
  1034. d.Visible = false;
  1035. f.Controls.Add (d);
  1036. Assert.IsTrue (c.CanFocus, "Focus1");
  1037. Assert.IsFalse (c.Focused, "Focus2");
  1038. c.Focus ();
  1039. Assert.IsTrue (c.Focused, "Focus3");
  1040. d.Focus ();
  1041. Assert.IsFalse (d.Focused, "Focus4");
  1042. d.Visible = true;
  1043. d.Focus ();
  1044. Assert.IsTrue (d.Focused, "Focus5");
  1045. Assert.IsFalse (c.Focused, "Focus6");
  1046. c.Enabled = false;
  1047. Assert.IsFalse (c.Focused, "Focus7");
  1048. } finally {
  1049. if (f != null)
  1050. f.Dispose ();
  1051. if (c != null)
  1052. c.Dispose ();
  1053. if (d != null)
  1054. d.Dispose ();
  1055. }
  1056. }
  1057. [Test]
  1058. public void FromHandleTest ()
  1059. {
  1060. Control c1 = null;
  1061. Control c2 = null;
  1062. try {
  1063. c1 = new Control ();
  1064. c2 = new Control ();
  1065. c1.Name = "parent";
  1066. c2.Name = "child";
  1067. c1.Controls.Add(c2);
  1068. // Handle
  1069. Assert.AreEqual (c1.Name, Control.FromHandle (c1.Handle).Name, "Handle1");
  1070. Assert.IsNull (Control.FromHandle (IntPtr.Zero), "Handle2");
  1071. // ChildHandle
  1072. Assert.AreEqual (c1.Name, Control.FromChildHandle (c1.Handle).Name, "Handle3");
  1073. Assert.IsNull (Control.FromChildHandle (IntPtr.Zero), "Handle4");
  1074. } finally {
  1075. if (c1 != null)
  1076. c1.Dispose ();
  1077. if (c2 != null)
  1078. c2.Dispose ();
  1079. }
  1080. }
  1081. [Test]
  1082. public void GetChildAtPointTest ()
  1083. {
  1084. Control c = null, d = null, e = null;
  1085. try {
  1086. c = new Control ();
  1087. c.Name = "c1";
  1088. c.SetBounds (0, 0, 100, 100);
  1089. d = new Control ();
  1090. d.Name = "d1";
  1091. d.SetBounds (10, 10, 40, 40);
  1092. c.Controls.Add (d);
  1093. e = new Control ();
  1094. e.Name = "e1";
  1095. e.SetBounds (55, 55, 10, 10);
  1096. Control l = c.GetChildAtPoint (new Point (15, 15));
  1097. Assert.AreEqual (d.Name, l.Name, "Child1");
  1098. Assert.IsFalse (e.Name == l.Name, "Child2");
  1099. l = c.GetChildAtPoint (new Point (57, 57));
  1100. Assert.IsNull (l, "Child3");
  1101. l = c.GetChildAtPoint (new Point (10, 10));
  1102. Assert.AreEqual (d.Name, l.Name, "Child4");
  1103. // GetChildAtPointSkip is not implemented and the following test is breaking for Net_2_0 profile
  1104. // #if NET_2_0
  1105. // c.Controls.Add (e);
  1106. // e.Visible = false;
  1107. // l = c.GetChildAtPoint (new Point (57, 57), GetChildAtPointSkip.Invisible);
  1108. // Assert.IsNull (l, "Child5");
  1109. // e.Visible = true;
  1110. // l = c.GetChildAtPoint (new Point (57, 57), GetChildAtPointSkip.Invisible);
  1111. // Assert.AreSame (e.Name, l.Name, "Child6");
  1112. // #endif // NET_2_0
  1113. } finally {
  1114. if (c != null)
  1115. c.Dispose ();
  1116. if (d != null)
  1117. d.Dispose ();
  1118. }
  1119. }
  1120. [Test]
  1121. public void ResetFontTest ()
  1122. {
  1123. Control c = new Control ();
  1124. c.Font = new Font (c.Font.FontFamily, 3, FontStyle.Italic);
  1125. c.ResetFont ();
  1126. Assert.IsFalse (c.Font.Bold, "#1");
  1127. //Assert.AreEqual ("Microsoft Sans Serif", c.Font.FontFamily.Name, "#2");
  1128. Assert.IsFalse (c.Font.Italic, "#3");
  1129. //Assert.AreEqual ("Microsoft Sans Serif", c.Font.Name, "#4");
  1130. Assert.AreEqual (8.25, c.Font.Size, "#5");
  1131. Assert.AreEqual (8.25, c.Font.SizeInPoints, "#6");
  1132. Assert.IsFalse (c.Font.Strikeout, "#7");
  1133. Assert.IsFalse (c.Font.Underline, "#8");
  1134. Assert.AreEqual (GraphicsUnit.Point, c.Font.Unit, "#9");
  1135. #if NET_2_0
  1136. Assert.AreEqual (true, c.Font.IsSystemFont, "#10");
  1137. #endif
  1138. }
  1139. public class LayoutTestControl : Control {
  1140. public int LayoutCount;
  1141. public LayoutTestControl () : base() {
  1142. LayoutCount = 0;
  1143. }
  1144. protected override void OnLayout(LayoutEventArgs levent) {
  1145. LayoutCount++;
  1146. base.OnLayout (levent);
  1147. }
  1148. }
  1149. [Test]
  1150. public void LayoutTest() {
  1151. LayoutTestControl c;
  1152. c = new LayoutTestControl();
  1153. c.SuspendLayout();
  1154. c.SuspendLayout();
  1155. c.SuspendLayout();
  1156. c.SuspendLayout();
  1157. c.ResumeLayout(true);
  1158. c.PerformLayout();
  1159. c.ResumeLayout(true);
  1160. c.PerformLayout();
  1161. c.ResumeLayout(true);
  1162. c.PerformLayout();
  1163. c.ResumeLayout(true);
  1164. c.PerformLayout();
  1165. c.ResumeLayout(true);
  1166. c.PerformLayout();
  1167. c.ResumeLayout(true);
  1168. c.PerformLayout();
  1169. c.ResumeLayout(true);
  1170. c.PerformLayout();
  1171. c.SuspendLayout();
  1172. c.PerformLayout();
  1173. Assert.AreEqual(5, c.LayoutCount, "Layout Suspend/Resume locking does not bottom out at 0");
  1174. }
  1175. [Test]
  1176. [ExpectedException(typeof(ArgumentException))]
  1177. public void TransparentBackgroundTest1() {
  1178. Control c;
  1179. c = new Control();
  1180. c.BackColor = Color.Transparent;
  1181. }
  1182. [Test]
  1183. public void TransparentBackgroundTest2() {
  1184. Panel c;
  1185. c = new Panel();
  1186. c.BackColor = Color.Transparent;
  1187. Assert.AreEqual(Color.Transparent, c.BackColor, "Transparent background not set");
  1188. }
  1189. [Test]
  1190. public void TransparentBackgroundTest3() {
  1191. Control c;
  1192. c = new Control();
  1193. c.BackColor = Color.Empty;
  1194. Assert.AreEqual(Control.DefaultBackColor, c.BackColor, "Setting empty color failed");
  1195. }
  1196. [Test]
  1197. public void Dock_Value_Invalid ()
  1198. {
  1199. Control c = new Control ();
  1200. try {
  1201. c.Dock = (DockStyle) 666;
  1202. Assert.Fail ("#1");
  1203. } catch (InvalidEnumArgumentException ex) {
  1204. Assert.AreEqual (typeof (InvalidEnumArgumentException), ex.GetType (), "#2");
  1205. Assert.IsNotNull (ex.Message, "#3");
  1206. Assert.IsNotNull (ex.ParamName, "#4");
  1207. Assert.AreEqual ("value", ex.ParamName, "#5");
  1208. Assert.IsNull (ex.InnerException, "#6");
  1209. }
  1210. }
  1211. [Test]
  1212. public void EnabledTest1() {
  1213. Control child;
  1214. Control parent;
  1215. Control grandma;
  1216. grandma = new Control();
  1217. parent = new Control();
  1218. child = new Control();
  1219. grandma.Controls.Add(parent);
  1220. parent.Controls.Add(child);
  1221. grandma.Enabled = false;
  1222. Assert.AreEqual(grandma.Enabled, child.Enabled, "Child did not inherit disabled state");
  1223. }
  1224. int EnabledCalledCount = 0;
  1225. private void EnabledTest2EnabledChanged(object sender, EventArgs e) {
  1226. EnabledCalledCount++;
  1227. }
  1228. [Test]
  1229. public void EnabledTest2() {
  1230. // Check nesting of enabled calls
  1231. // OnEnabled is not called for disabled child controls
  1232. Control child;
  1233. Control parent;
  1234. Control grandma;
  1235. EnabledCalledCount = 0;
  1236. grandma = new Control();
  1237. parent = new Control();
  1238. child = new Control();
  1239. child.EnabledChanged += new EventHandler(EnabledTest2EnabledChanged);
  1240. grandma.Controls.Add(parent);
  1241. parent.Controls.Add(child);
  1242. grandma.Enabled = false;
  1243. Assert.AreEqual(1, EnabledCalledCount, "Child Enabled Event not properly fired");
  1244. grandma.Enabled = true;
  1245. Assert.AreEqual(2, EnabledCalledCount, "Child Enabled Event not properly fired");
  1246. child.Enabled = false;
  1247. grandma.Enabled = false;
  1248. Assert.AreEqual(3, EnabledCalledCount, "Child Enabled Event not properly fired");
  1249. }
  1250. [Test]
  1251. public void ControlsRemoveNullTest ()
  1252. {
  1253. Control c = new Control ();
  1254. c.Controls.Remove (null);
  1255. }
  1256. [Test]
  1257. public void ControlsAddNullTest ()
  1258. {
  1259. Control c = new Control ();
  1260. c.Controls.Add (null);
  1261. }
  1262. [Test]
  1263. [ExpectedException (typeof (ArgumentNullException))]
  1264. public void ControlsSetChildIndexNullTest ()
  1265. {
  1266. Control c = new Control ();
  1267. c.Controls.SetChildIndex (null, 1);
  1268. }
  1269. [Test]
  1270. [ExpectedException (typeof (ArgumentNullException))]
  1271. public void ControlsAddRangeNullTest ()
  1272. {
  1273. Control c = new Control ();
  1274. c.Controls.AddRange (null);
  1275. }
  1276. [Test]
  1277. public void ControlsAddRangeNullElementTest ()
  1278. {
  1279. Control c = new Control ();
  1280. Control[] subcontrols = new Control[2];
  1281. subcontrols[0] = new Control ();
  1282. subcontrols[1] = null;
  1283. c.Controls.AddRange (subcontrols);
  1284. }
  1285. [Test]
  1286. public void RegionTest () {
  1287. Form f = new Form ();
  1288. f.ShowInTaskbar = false;
  1289. Control c = new Control ();
  1290. f.Controls.Add (c);
  1291. Assert.IsNull (c.Region, "#A1");
  1292. f.Show ();
  1293. Assert.IsNull (c.Region, "#A2");
  1294. c.Region = null;
  1295. Assert.IsNull (c.Region, "#A3");
  1296. f.Dispose ();
  1297. Region region = new Region ();
  1298. f = new Form ();
  1299. f.ShowInTaskbar = false;
  1300. c = new Control ();
  1301. f.Controls.Add (c);
  1302. c.Region = region;
  1303. Assert.IsNotNull (c.Region, "#B1");
  1304. Assert.AreSame (region, c.Region, "#B2");
  1305. f.Show ();
  1306. c.Region = null;
  1307. Assert.IsNull (c.Region, "#B3");
  1308. f.Dispose ();
  1309. }
  1310. [Test] // bug #80280
  1311. public void Validated_Multiple_Containers ()
  1312. {
  1313. Form form = new Form ();
  1314. form.ShowInTaskbar = false;
  1315. UserControl control1 = new UserControl();
  1316. UserControl container1 = new UserControl();
  1317. control1.Tag = true;
  1318. control1.Validated += new EventHandler (Control_ValidatedHandler);
  1319. container1.Controls.Add(control1);
  1320. form.Controls.Add (container1);
  1321. UserControl container2 = new UserControl();
  1322. UserControl control2 = new UserControl();
  1323. container2.Controls.Add(control2);
  1324. form.Controls.Add (container2);
  1325. Assert.IsTrue ((bool) control1.Tag, "#1");
  1326. control1.Select();
  1327. Assert.IsTrue ((bool) control1.Tag, "#2");
  1328. control2.Select();
  1329. Assert.IsFalse ((bool) control1.Tag, "#3");
  1330. form.Dispose ();
  1331. }
  1332. private void Control_ValidatedHandler (object sender, EventArgs e)
  1333. {
  1334. ((Control) sender).Tag = false;
  1335. }
  1336. public class MockControl : Control
  1337. {
  1338. public int font_height {
  1339. get { return base.FontHeight; }
  1340. set { base.FontHeight = value; }
  1341. }
  1342. }
  1343. }
  1344. [TestFixture]
  1345. public class ControlSetTopLevelTest
  1346. {
  1347. class ControlPoker : Control {
  1348. public void DoSetTopLevel ()
  1349. {
  1350. SetTopLevel (true);
  1351. }
  1352. public bool DoGetTopLevel ()
  1353. {
  1354. return GetTopLevel ();
  1355. }
  1356. }
  1357. [Test]
  1358. public void TestControl ()
  1359. {
  1360. ControlPoker c = new ControlPoker ();
  1361. c.Visible = false;
  1362. c.DoSetTopLevel ();
  1363. Assert.IsTrue (c.DoGetTopLevel (), "1");
  1364. Assert.IsFalse (c.Visible, "2");
  1365. }
  1366. [Test]
  1367. [ExpectedException (typeof (ArgumentException))]
  1368. public void TestChildControl ()
  1369. {
  1370. Control c1 = new Control();
  1371. ControlPoker c2 = new ControlPoker ();
  1372. c1.Controls.Add (c2);
  1373. c2.DoSetTopLevel ();
  1374. }
  1375. [Test]
  1376. [ExpectedException (typeof (ArgumentException))]
  1377. public void TestTopLevelAdd () {
  1378. Form f = new Form();
  1379. Form f1 = new Form();
  1380. f.Controls.Add(f1);
  1381. }
  1382. [Category ("NotWorking")]
  1383. [Test]
  1384. public void TestForm ()
  1385. {
  1386. Form f = new Form ();
  1387. Assert.IsFalse (f.Visible, "3");
  1388. f.TopLevel = true;
  1389. Assert.IsFalse (f.Visible, "4");
  1390. }
  1391. }
  1392. [TestFixture]
  1393. public class ControlResizeLayoutTest
  1394. {
  1395. class ControlPoker : Control {
  1396. public void DoOnResize ()
  1397. {
  1398. OnResize (EventArgs.Empty);
  1399. }
  1400. }
  1401. int child_event;
  1402. string child_affected_property;
  1403. void ChildLayoutEvent (object sender, LayoutEventArgs e)
  1404. {
  1405. child_event ++;
  1406. child_affected_property = e.AffectedProperty;
  1407. }
  1408. int parent_event;
  1409. string parent_affected_property;
  1410. void ParentLayoutEvent (object sender, LayoutEventArgs e)
  1411. {
  1412. parent_event ++;
  1413. parent_affected_property = e.AffectedProperty;
  1414. }
  1415. [Test]
  1416. public void Test ()
  1417. {
  1418. Panel p = new Panel ();
  1419. ControlPoker c = new ControlPoker();
  1420. p.Controls.Add (c);
  1421. p.Layout += new LayoutEventHandler (ParentLayoutEvent);
  1422. c.Layout += new LayoutEventHandler (ChildLayoutEvent);
  1423. c.DoOnResize ();
  1424. Assert.AreEqual (1, child_event, "1");
  1425. Assert.AreEqual ("Bounds", child_affected_property, "2");
  1426. Assert.AreEqual (0, parent_event, "3");
  1427. }
  1428. }
  1429. [TestFixture]
  1430. public class ControlInvokeTest {
  1431. public delegate void TestDelegate ();
  1432. Form f;
  1433. Control c;
  1434. Thread control_t;
  1435. ApplicationContext control_context;
  1436. bool delegateCalled = false;
  1437. object m;
  1438. void CreateControl ()
  1439. {
  1440. f = new Form ();
  1441. f.ShowInTaskbar = false;
  1442. c = new Control ();
  1443. f.Controls.Add (c);
  1444. Console.WriteLine ("f.Handle = {0}", f.Handle);
  1445. Console.WriteLine ("c.Handle = {0}", c.Handle);
  1446. control_context = new ApplicationContext (f);
  1447. Monitor.Enter (m);
  1448. Console.WriteLine ("pulsing");
  1449. Monitor.Pulse (m);
  1450. Monitor.Exit (m);
  1451. Console.WriteLine ("control thread running");
  1452. Application.Run (control_context);
  1453. c.Dispose ();
  1454. }
  1455. [Test]
  1456. public void InvokeTest ()
  1457. {
  1458. m = new object ();
  1459. control_t = new Thread(new ThreadStart(CreateControl));
  1460. Monitor.Enter (m);
  1461. control_t.Start ();
  1462. Console.WriteLine ("waiting on monitor");
  1463. Monitor.Wait (m);
  1464. Console.WriteLine ("making async call");
  1465. IAsyncResult result;
  1466. result = c.BeginInvoke (new TestDelegate (delegate_call));
  1467. c.EndInvoke (result);
  1468. Assert.AreEqual (true, delegateCalled, "Invoke1");
  1469. }
  1470. public void delegate_call () {
  1471. /* invoked on control_context's thread */
  1472. delegateCalled = true;
  1473. f.Dispose ();
  1474. Application.Exit ();
  1475. }
  1476. }
  1477. [TestFixture]
  1478. public class ControlWMTest
  1479. {
  1480. [Test]
  1481. public void WM_PARENTNOTIFY_Test ()
  1482. {
  1483. WMTester tester;
  1484. Control child;
  1485. int child_handle;
  1486. tester = new WMTester ();
  1487. child = new Control ();
  1488. tester.Controls.Add (child);
  1489. tester.Visible = true;
  1490. child.Visible = true;
  1491. child_handle = child.Handle.ToInt32 ();
  1492. ArrayList msgs;
  1493. Message m1;
  1494. msgs = tester.Find (WndMsg.WM_PARENTNOTIFY);
  1495. Assert.AreEqual (1, msgs.Count, "#1");
  1496. m1 = (Message) msgs [0];
  1497. Assert.AreEqual (WndMsg.WM_CREATE, ((WndMsg) LowOrder (m1.WParam)), "#2");
  1498. //Assert.AreEqual (child.Identifier??, HighOrder (m1.WParam), "#3");
  1499. Assert.AreEqual (child_handle, m1.LParam.ToInt32 (), "#4");
  1500. child.Dispose ();
  1501. msgs = tester.Find (WndMsg.WM_PARENTNOTIFY);
  1502. Assert.AreEqual (2, msgs.Count, "#5");
  1503. m1 = (Message) msgs [1];
  1504. Assert.AreEqual (WndMsg.WM_DESTROY, ((WndMsg) LowOrder (m1.WParam)), "#6");
  1505. //Assert.AreEqual (child.Identifier??, HighOrder (m1.WParam), "#7");
  1506. Assert.AreEqual (child_handle, m1.LParam.ToInt32 (), "#8");
  1507. tester.Dispose ();
  1508. }
  1509. internal static int LowOrder (int param)
  1510. {
  1511. return ((int)(short)(param & 0xffff));
  1512. }
  1513. internal static int HighOrder (int param)
  1514. {
  1515. return ((int)(short)(param >> 16));
  1516. }
  1517. internal static int LowOrder (IntPtr param)
  1518. {
  1519. return ((int)(short)(param.ToInt32 () & 0xffff));
  1520. }
  1521. internal static int HighOrder (IntPtr param)
  1522. {
  1523. return ((int)(short)(param.ToInt32 () >> 16));
  1524. }
  1525. internal class WMTester : Form
  1526. {
  1527. internal ArrayList Messages = new ArrayList ();
  1528. internal bool Contains (WndMsg msg)
  1529. {
  1530. return Contains (msg, Messages);
  1531. }
  1532. internal bool Contains (WndMsg msg, ArrayList list)
  1533. {
  1534. foreach (Message m in Messages)
  1535. {
  1536. if (m.Msg == (int) msg)
  1537. return true;
  1538. }
  1539. return false;
  1540. }
  1541. internal ArrayList Find (WndMsg msg)
  1542. {
  1543. ArrayList result = new ArrayList ();
  1544. foreach (Message m in Messages)
  1545. {
  1546. if (m.Msg == (int) msg)
  1547. result.Add (m);
  1548. }
  1549. return result;
  1550. }
  1551. protected override void WndProc(ref Message m)
  1552. {
  1553. Console.WriteLine ("WndProc: " + m.ToString ());
  1554. Messages.Add (m);
  1555. base.WndProc (ref m);
  1556. }
  1557. }
  1558. }
  1559. #if NET_2_0
  1560. [TestFixture]
  1561. public class ControlLayoutTest
  1562. {
  1563. [Test]
  1564. public void SetUp ()
  1565. {
  1566. _layoutCount = 0;
  1567. }
  1568. [Test] // bug #80456
  1569. public void LayoutTest ()
  1570. {
  1571. MockLayoutEngine layoutEngine = new MockLayoutEngine ();
  1572. MockControl c = new MockControl (layoutEngine);
  1573. c.Layout += new LayoutEventHandler (LayoutEvent);
  1574. Assert.IsFalse (layoutEngine.LayoutInvoked, "#A1");
  1575. Assert.AreEqual (0, _layoutCount, "#A2");
  1576. c.PerformLayout ();
  1577. Assert.IsTrue (layoutEngine.LayoutInvoked, "#A3");
  1578. Assert.AreEqual (1, _layoutCount, "#A4");
  1579. layoutEngine.Reset ();
  1580. c.OverrideOnLayout = true;
  1581. Assert.IsFalse (layoutEngine.LayoutInvoked, "#B1");
  1582. c.PerformLayout ();
  1583. Assert.IsFalse (layoutEngine.LayoutInvoked, "#B2");
  1584. Assert.AreEqual (1, _layoutCount, "#B3");
  1585. }
  1586. void LayoutEvent (object sender, LayoutEventArgs e)
  1587. {
  1588. _layoutCount++;
  1589. }
  1590. private int _layoutCount;
  1591. class MockControl : Control
  1592. {
  1593. public MockControl (LayoutEngine layoutEngine)
  1594. {
  1595. _layoutEngine = layoutEngine;
  1596. }
  1597. public bool OverrideOnLayout
  1598. {
  1599. get { return _overrideOnLayout; }
  1600. set { _overrideOnLayout = value; }
  1601. }
  1602. protected override void OnLayout (LayoutEventArgs levent)
  1603. {
  1604. if (!OverrideOnLayout)
  1605. base.OnLayout (levent);
  1606. }
  1607. public override LayoutEngine LayoutEngine {
  1608. get {
  1609. if (_layoutEngine == null)
  1610. return base.LayoutEngine;
  1611. return _layoutEngine;
  1612. }
  1613. }
  1614. private bool _overrideOnLayout;
  1615. private LayoutEngine _layoutEngine;
  1616. }
  1617. class MockLayoutEngine : LayoutEngine
  1618. {
  1619. public bool LayoutInvoked {
  1620. get { return _layoutInvoked; }
  1621. }
  1622. public void Reset ()
  1623. {
  1624. _layoutInvoked = false;
  1625. }
  1626. public override bool Layout (object container, LayoutEventArgs args)
  1627. {
  1628. _layoutInvoked = true;
  1629. return true;
  1630. }
  1631. private bool _layoutInvoked;
  1632. }
  1633. }
  1634. #endif
  1635. }