LabelTest.cs 27 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027
  1. //
  2. // Copyright (c) 2005 Novell, Inc.
  3. //
  4. // Authors:
  5. // Hisham Mardam Bey ([email protected])
  6. //
  7. //
  8. using System;
  9. using NUnit.Framework;
  10. using System.Windows.Forms;
  11. using System.Drawing;
  12. using System.Collections;
  13. namespace MonoTests.System.Windows.Forms
  14. {
  15. [TestFixture]
  16. public class LabelTest2
  17. {
  18. [Test]
  19. [Category ("NotWorking")]
  20. public void PubPropTest ()
  21. {
  22. Label l = new Label ();
  23. // A
  24. Assert.AreEqual (false, l.AutoSize, "A1");
  25. l.AutoSize = true;
  26. Assert.AreEqual (true, l.AutoSize, "A2");
  27. l.AutoSize = false;
  28. Assert.AreEqual (false, l.AutoSize, "A3");
  29. // B
  30. Assert.AreEqual (null, l.BackgroundImage, "B1");
  31. l.BackgroundImage = Image.FromFile ("Test/System.Windows.Forms/bitmaps/a.png");
  32. Assert.IsNotNull (l.BackgroundImage, "B2");
  33. Bitmap bmp = (Bitmap)l.BackgroundImage;
  34. Assert.IsNotNull (bmp.GetPixel (0, 0), "B3");
  35. Assert.AreEqual (BorderStyle.None, l.BorderStyle, "B4");
  36. l.BorderStyle = BorderStyle.FixedSingle;
  37. Assert.AreEqual (BorderStyle.FixedSingle, l.BorderStyle, "B5");
  38. l.BorderStyle = BorderStyle.Fixed3D;
  39. Assert.AreEqual (BorderStyle.Fixed3D, l.BorderStyle, "B6");
  40. l.BorderStyle = BorderStyle.None;
  41. Assert.AreEqual (BorderStyle.None, l.BorderStyle, "B7");
  42. // C
  43. string name = l.CompanyName;
  44. if (!name.Equals("Mono Project, Novell, Inc.") && !name.Equals("Microsoft Corporation")) {
  45. Assert.Fail("CompanyName property does not match any accepted value - C1");
  46. }
  47. // F
  48. Assert.AreEqual (FlatStyle.Standard, l.FlatStyle, "F1");
  49. l.FlatStyle = FlatStyle.Flat;
  50. Assert.AreEqual (FlatStyle.Flat, l.FlatStyle, "F1");
  51. l.FlatStyle = FlatStyle.Popup;
  52. Assert.AreEqual (FlatStyle.Popup, l.FlatStyle, "F2");
  53. l.FlatStyle = FlatStyle.Standard;
  54. Assert.AreEqual (FlatStyle.Standard, l.FlatStyle, "F3");
  55. l.FlatStyle = FlatStyle.System;
  56. Assert.AreEqual (FlatStyle.System, l.FlatStyle, "F4");
  57. // I
  58. Assert.AreEqual (ContentAlignment.MiddleCenter, l.ImageAlign, "I1");
  59. l.ImageAlign = ContentAlignment.TopLeft;
  60. Assert.AreEqual (ContentAlignment.TopLeft, l.ImageAlign, "I2");
  61. l.ImageAlign = ContentAlignment.TopCenter;
  62. Assert.AreEqual (ContentAlignment.TopCenter, l.ImageAlign, "I3");
  63. l.ImageAlign = ContentAlignment.TopRight;
  64. Assert.AreEqual (ContentAlignment.TopRight, l.ImageAlign, "I4");
  65. l.ImageAlign = ContentAlignment.MiddleLeft;
  66. Assert.AreEqual (ContentAlignment.MiddleLeft, l.ImageAlign, "I5");
  67. l.ImageAlign = ContentAlignment.MiddleCenter;
  68. Assert.AreEqual (ContentAlignment.MiddleCenter, l.ImageAlign, "I6");
  69. l.ImageAlign = ContentAlignment.MiddleRight;
  70. Assert.AreEqual (ContentAlignment.MiddleRight, l.ImageAlign, "I7");
  71. l.ImageAlign = ContentAlignment.BottomLeft;
  72. Assert.AreEqual (ContentAlignment.BottomLeft, l.ImageAlign, "I8");
  73. l.ImageAlign = ContentAlignment.BottomCenter;
  74. Assert.AreEqual (ContentAlignment.BottomCenter, l.ImageAlign, "I9");
  75. l.ImageAlign = ContentAlignment.BottomRight;
  76. Assert.AreEqual (ContentAlignment.BottomRight, l.ImageAlign, "I10");
  77. Assert.AreEqual (-1, l.ImageIndex, "I11");
  78. Assert.AreEqual (null, l.ImageList, "I12");
  79. Assert.AreEqual (null, l.Image, "I13");
  80. l.Image = Image.FromFile ("Test/System.Windows.Forms/bitmaps/a.png");
  81. Assert.IsNotNull (l.Image, "I14");
  82. bmp = (Bitmap)l.Image;
  83. Assert.IsNotNull (bmp.GetPixel (0, 0), "I15");
  84. ImageList il = new ImageList ();
  85. il.ColorDepth = ColorDepth.Depth32Bit;
  86. il.ImageSize = new Size (15, 15);
  87. il.Images.Add (Image.FromFile ("Test/System.Windows.Forms/bitmaps/a.png"));
  88. l.ImageList = il;
  89. l.ImageIndex = 0;
  90. Assert.AreEqual (0, l.ImageIndex, "I16");
  91. Assert.IsNotNull (l.ImageList, "I17");
  92. // PreferredHeight
  93. // PregerredWidth
  94. // RenderTransparent
  95. //
  96. // T
  97. // Assert.AreEqual (false, l.TabStop, "T1");
  98. Assert.AreEqual (ContentAlignment.TopLeft, l.TextAlign, "T2");
  99. // U
  100. Assert.AreEqual (true, l.UseMnemonic, "U1");
  101. l.UseMnemonic = false;
  102. Assert.AreEqual (false, l.UseMnemonic, "U2");
  103. }
  104. [Test]
  105. public void LabelEqualsTest ()
  106. {
  107. Label s1 = new Label ();
  108. Label s2 = new Label ();
  109. s1.Text = "abc";
  110. s2.Text = "abc";
  111. Assert.AreEqual (false, s1.Equals (s2), "E1");
  112. Assert.AreEqual (true, s1.Equals (s1), "E2");
  113. }
  114. [Test]
  115. public void LabelScaleTest ()
  116. {
  117. Label r1 = new Label ();
  118. r1.Width = 40;
  119. r1.Height = 20 ;
  120. r1.Scale (2);
  121. Assert.AreEqual (80, r1.Width, "W1");
  122. Assert.AreEqual (40, r1.Height, "H1");
  123. }
  124. [Test]
  125. public void PubMethodTest ()
  126. {
  127. Label l = new Label ();
  128. l.Text = "My Label";
  129. Assert.AreEqual ("System.Windows.Forms.Label, Text: My Label", l.ToString (), "T1");
  130. }
  131. }
  132. [TestFixture]
  133. public class LabelEventTest
  134. {
  135. static bool eventhandled = false;
  136. public void Label_EventHandler (object sender,EventArgs e)
  137. {
  138. eventhandled = true;
  139. }
  140. public void Label_KeyDownEventHandler (object sender, KeyEventArgs e)
  141. {
  142. eventhandled = true;
  143. }
  144. [Test]
  145. public void AutoSizeChangedChangedTest ()
  146. {
  147. Form myform = new Form ();
  148. myform.Visible = true;
  149. Label l = new Label ();
  150. l.Visible = true;
  151. myform.Controls.Add (l);
  152. l.AutoSizeChanged += new EventHandler (Label_EventHandler);
  153. l.AutoSize = true;
  154. Assert.AreEqual (true, eventhandled, "B4");
  155. eventhandled = false;
  156. myform.Dispose();
  157. }
  158. [Test]
  159. public void BackgroundImageChangedTest ()
  160. {
  161. Form myform = new Form ();
  162. myform.Visible = true;
  163. Label l = new Label ();
  164. l.Visible = true;
  165. myform.Controls.Add (l);
  166. l.BackgroundImageChanged += new EventHandler (Label_EventHandler);
  167. l.BackgroundImage = Image.FromFile ("Test/System.Windows.Forms/bitmaps/a.png");
  168. Assert.AreEqual (true, eventhandled, "B4");
  169. eventhandled = false;
  170. myform.Dispose();
  171. }
  172. [Test]
  173. public void ImeModeChangedTest ()
  174. {
  175. Form myform = new Form ();
  176. myform.Visible = true;
  177. Label l = new Label ();
  178. l.Visible = true;
  179. myform.Controls.Add (l);
  180. l.ImeModeChanged += new EventHandler (Label_EventHandler);
  181. l.ImeMode = ImeMode.Katakana;
  182. Assert.AreEqual (true, eventhandled, "I16");
  183. eventhandled = false;
  184. myform.Dispose();
  185. }
  186. [Test]
  187. public void KeyDownTest ()
  188. {
  189. Form myform = new Form ();
  190. myform.Visible = true;
  191. MyLabel l = new MyLabel ();
  192. l.Visible = true;
  193. myform.Controls.Add (l);
  194. l.KeyDown += new KeyEventHandler (Label_KeyDownEventHandler);
  195. l.KeyPressA ();
  196. Assert.AreEqual (true, eventhandled, "K1");
  197. eventhandled = false;
  198. myform.Dispose();
  199. }
  200. [Test]
  201. public void TabStopChangedTest ()
  202. {
  203. Form myform = new Form ();
  204. myform.Visible = true;
  205. Label l = new Label ();
  206. l.Visible = true;
  207. myform.Controls.Add (l);
  208. l.TabStopChanged += new EventHandler (Label_EventHandler);
  209. l.TabStop = true;
  210. Assert.AreEqual (true, eventhandled, "T3");
  211. eventhandled = false;
  212. myform.Dispose();
  213. }
  214. [Test]
  215. public void TextAlignChangedTest ()
  216. {
  217. Form myform = new Form ();
  218. myform.Visible = true;
  219. Label l = new Label ();
  220. l.Visible = true;
  221. myform.Controls.Add (l);
  222. l.TextAlignChanged += new EventHandler (Label_EventHandler);
  223. l.TextAlign = ContentAlignment.TopRight;
  224. Assert.AreEqual (true, eventhandled, "T4");
  225. eventhandled = false;
  226. myform.Dispose();
  227. }
  228. }
  229. public class MyLabelInvalidate : MyLabel
  230. {
  231. //protected ArrayList results = new ArrayList ();
  232. public MyLabelInvalidate () : base ()
  233. {}
  234. protected override void OnInvalidated (InvalidateEventArgs e)
  235. {
  236. base.OnInvalidated (e);
  237. string res = (string)results [results.Count - 1];
  238. results [results.Count - 1 ] = string.Concat (res, "," + e.InvalidRect.ToString ());
  239. //results.Add ("OnInvalidate," + e.InvalidRect.ToString ());
  240. }
  241. //public ArrayList Results {
  242. // get { return results; }
  243. //}
  244. }
  245. public class MyLabel : Label
  246. {
  247. protected ArrayList results = new ArrayList ();
  248. public MyLabel () : base ()
  249. { }
  250. protected override void OnAutoSizeChanged (EventArgs e)
  251. {
  252. results.Add ("OnAutoSizeChanged");
  253. base.OnAutoSizeChanged (e);
  254. }
  255. protected override void OnBackgroundImageChanged (EventArgs e)
  256. {
  257. results.Add ("OnBackgroundImageChanged");
  258. base.OnBackgroundImageChanged (e);
  259. }
  260. protected override void OnImeModeChanged (EventArgs e)
  261. {
  262. results.Add ("OnImeModeChanged");
  263. base.OnImeModeChanged (e);
  264. }
  265. protected override void OnKeyDown (KeyEventArgs e)
  266. {
  267. results.Add ("OnKeyDown,"+(char)e.KeyValue);
  268. base.OnKeyDown (e);
  269. }
  270. protected override void OnKeyPress (KeyPressEventArgs e)
  271. {
  272. results.Add ("OnKeyPress,"+e.KeyChar.ToString ());
  273. base.OnKeyPress (e);
  274. }
  275. protected override void OnKeyUp (KeyEventArgs e)
  276. {
  277. results.Add ("OnKeyUp,"+(char)e.KeyValue);
  278. base.OnKeyUp (e);
  279. }
  280. protected override void OnHandleCreated (EventArgs e)
  281. {
  282. results.Add ("OnHandleCreated");
  283. base.OnHandleCreated (e);
  284. }
  285. protected override void OnBindingContextChanged (EventArgs e)
  286. {
  287. results.Add ("OnBindingContextChanged");
  288. base.OnBindingContextChanged (e);
  289. }
  290. protected override void OnInvalidated (InvalidateEventArgs e)
  291. {
  292. results.Add("OnInvalidated");
  293. base.OnInvalidated (e);
  294. }
  295. protected override void OnResize (EventArgs e)
  296. {
  297. results.Add("OnResize");
  298. base.OnResize (e);
  299. }
  300. protected override void OnSizeChanged (EventArgs e)
  301. {
  302. results.Add("OnSizeChanged");
  303. base.OnSizeChanged (e);
  304. }
  305. protected override void OnLayout (LayoutEventArgs e)
  306. {
  307. results.Add("OnLayout");
  308. base.OnLayout (e);
  309. }
  310. protected override void OnVisibleChanged (EventArgs e)
  311. {
  312. results.Add("OnVisibleChanged");
  313. base.OnVisibleChanged (e);
  314. }
  315. protected override void OnPaint (PaintEventArgs e)
  316. {
  317. results.Add("OnPaint");
  318. base.OnPaint (e);
  319. }
  320. public void KeyPressA()
  321. {
  322. Message m;
  323. m = new Message();
  324. m.Msg = (int)WndMsg.WM_KEYDOWN;
  325. m.HWnd = this.Handle;
  326. m.WParam = (IntPtr)0x41;
  327. m.LParam = (IntPtr)0x1e0001;
  328. this.WndProc(ref m);
  329. m.Msg = (int)WndMsg.WM_CHAR;
  330. m.HWnd = this.Handle;
  331. m.WParam = (IntPtr)0x61;
  332. m.LParam = (IntPtr)0x1e0001;
  333. this.WndProc(ref m);
  334. m.Msg = (int)WndMsg.WM_KEYUP;
  335. m.HWnd = this.Handle;
  336. m.WParam = (IntPtr)0x41;
  337. m.LParam = (IntPtr)unchecked((int)0xC01e0001);
  338. this.WndProc(ref m);
  339. }
  340. public void KeyDownA()
  341. {
  342. Message m;
  343. m = new Message();
  344. m.Msg = (int)WndMsg.WM_KEYDOWN;
  345. m.HWnd = this.Handle;
  346. m.WParam = (IntPtr)0x41;
  347. m.LParam = (IntPtr)0x1e0001;
  348. this.WndProc(ref m);
  349. m.Msg = (int)WndMsg.WM_CHAR;
  350. m.HWnd = this.Handle;
  351. m.WParam = (IntPtr)0x61;
  352. m.LParam = (IntPtr)0x1e0001;
  353. this.WndProc(ref m);
  354. }
  355. public void KeyUpA()
  356. {
  357. Message m;
  358. m = new Message();
  359. m.Msg = (int)WndMsg.WM_KEYUP;
  360. m.HWnd = this.Handle;
  361. m.WParam = (IntPtr)0x41;
  362. m.LParam = (IntPtr)unchecked((int)0xC01e0001);
  363. this.WndProc(ref m);
  364. }
  365. public ArrayList Results {
  366. get { return results; }
  367. }
  368. }
  369. [TestFixture]
  370. [Ignore("Comparisons too strict")]
  371. public class LabelTestEventsOrder
  372. {
  373. public string [] ArrayListToString (ArrayList arrlist)
  374. {
  375. string [] retval = new string [arrlist.Count];
  376. for (int i = 0; i < arrlist.Count; i++)
  377. retval[i] = (string)arrlist[i];
  378. return retval;
  379. }
  380. private void OrderedAssert(string[] wanted, ArrayList found) {
  381. int last_target;
  382. bool seen;
  383. last_target = 0;
  384. for (int i = 0; i < wanted.Length; i++) {
  385. seen = false;
  386. for (int j = last_target; j < found.Count; j++) {
  387. if (wanted[i] == (string)found[j]) {
  388. seen = true;
  389. last_target = j + 1;
  390. break;
  391. }
  392. }
  393. if (!seen) {
  394. Console.WriteLine("Needed {0}", wanted[i]);
  395. }
  396. }
  397. }
  398. public void PrintList(string name, ArrayList list) {
  399. Console.WriteLine("{0}", name);
  400. for (int i = 0; i < list.Count; i++) {
  401. Console.WriteLine(" {0}", list[i]);
  402. }
  403. Console.WriteLine("");
  404. }
  405. [Test]
  406. public void CreateEventsOrder ()
  407. {
  408. string[] EventsWanted = {
  409. "OnHandleCreated",
  410. "OnBindingContextChanged",
  411. "OnBindingContextChanged"
  412. };
  413. Form myform = new Form ();
  414. myform.Visible = true;
  415. MyLabel l = new MyLabel ();
  416. myform.Controls.Add (l);
  417. Assert.AreEqual (EventsWanted, ArrayListToString (l.Results));
  418. myform.Dispose();
  419. }
  420. [Test]
  421. public void SizeChangedEventsOrder ()
  422. {
  423. string[] EventsWanted = {
  424. "OnHandleCreated",
  425. "OnBindingContextChanged",
  426. "OnBindingContextChanged",
  427. "OnSizeChanged",
  428. "OnResize",
  429. "OnInvalidated",
  430. "OnLayout"
  431. };
  432. Form myform = new Form ();
  433. myform.Visible = true;
  434. MyLabel l = new MyLabel ();
  435. myform.Controls.Add (l);
  436. l.Size = new Size (150, 20);
  437. Assert.AreEqual (EventsWanted, ArrayListToString (l.Results));
  438. myform.Dispose();
  439. }
  440. [Test]
  441. public void AutoSizeChangedEventsOrder ()
  442. {
  443. string[] EventsWanted = {
  444. "OnHandleCreated",
  445. "OnBindingContextChanged",
  446. "OnBindingContextChanged",
  447. "OnSizeChanged",
  448. "OnResize",
  449. "OnInvalidated",
  450. "OnLayout",
  451. "OnAutoSizeChanged"
  452. };
  453. Form myform = new Form ();
  454. myform.Visible = true;
  455. MyLabel l = new MyLabel ();
  456. myform.Controls.Add (l);
  457. l.AutoSize = true;
  458. Assert.AreEqual (EventsWanted, ArrayListToString (l.Results));
  459. myform.Dispose();
  460. }
  461. [Test]
  462. public void BackgroundImageChangedEventsOrder ()
  463. {
  464. string[] EventsWanted = {
  465. "OnHandleCreated",
  466. "OnBindingContextChanged",
  467. "OnBindingContextChanged",
  468. "OnBackgroundImageChanged",
  469. "OnInvalidated"
  470. };
  471. Form myform = new Form ();
  472. myform.Visible = true;
  473. MyLabel l = new MyLabel ();
  474. myform.Controls.Add (l);
  475. l.BackgroundImage = Image.FromFile ("Test/System.Windows.Forms/bitmaps/a.png");
  476. Assert.AreEqual (EventsWanted, ArrayListToString (l.Results));
  477. myform.Dispose();
  478. }
  479. [Test]
  480. public void ImeModeChangedChangedEventsOrder ()
  481. {
  482. string[] EventsWanted = {
  483. "OnHandleCreated",
  484. "OnBindingContextChanged",
  485. "OnBindingContextChanged",
  486. "OnImeModeChanged"
  487. };
  488. Form myform = new Form ();
  489. myform.Visible = true;
  490. MyLabel l = new MyLabel ();
  491. myform.Controls.Add (l);
  492. l.ImeMode = ImeMode.Katakana;
  493. Assert.AreEqual (EventsWanted, ArrayListToString (l.Results));
  494. myform.Dispose();
  495. }
  496. [Test]
  497. public void KeyPressEventsOrder ()
  498. {
  499. string[] EventsWanted = {
  500. "OnHandleCreated",
  501. "OnBindingContextChanged",
  502. "OnBindingContextChanged",
  503. "OnKeyDown,A",
  504. "OnKeyPress,a",
  505. "OnKeyUp,A"
  506. };
  507. Form myform = new Form ();
  508. myform.Visible = true;
  509. MyLabel l = new MyLabel ();
  510. myform.Controls.Add (l);
  511. l.KeyPressA ();
  512. Assert.AreEqual (EventsWanted, ArrayListToString (l.Results));
  513. myform.Dispose();
  514. }
  515. [Test]
  516. public void TabStopChangedEventsOrder ()
  517. {
  518. string[] EventsWanted = {
  519. "OnHandleCreated",
  520. "OnBindingContextChanged",
  521. "OnBindingContextChanged"
  522. };
  523. Form myform = new Form ();
  524. myform.Visible = true;
  525. MyLabel l = new MyLabel ();
  526. myform.Controls.Add (l);
  527. l.TabStop = true;
  528. PrintList("TabStopChanged", l.Results);
  529. Assert.AreEqual (EventsWanted, ArrayListToString (l.Results));
  530. myform.Dispose();
  531. }
  532. [Test]
  533. public void TextAlignChangedEventsOrder ()
  534. {
  535. string[] EventsWanted = {
  536. "OnHandleCreated",
  537. "OnBindingContextChanged",
  538. "OnBindingContextChanged",
  539. "OnInvalidated"
  540. };
  541. Form myform = new Form ();
  542. myform.Visible = true;
  543. MyLabel l = new MyLabel ();
  544. myform.Controls.Add (l);
  545. l.TextAlign = ContentAlignment.TopRight;
  546. Assert.AreEqual (EventsWanted, ArrayListToString (l.Results));
  547. myform.Dispose();
  548. }
  549. [Test]
  550. public void InvalidateEventsOrder ()
  551. {
  552. Rectangle rect = new Rectangle (new Point (0,0), new Size (2, 2));
  553. Form myform = new Form ();
  554. myform.Visible = true;
  555. MyLabelInvalidate l = new MyLabelInvalidate ();
  556. myform.Controls.Add (l);
  557. l.TextAlign = ContentAlignment.TopRight;
  558. string [] EventsWanted = {
  559. "OnHandleCreated",
  560. "OnBindingContextChanged",
  561. "OnBindingContextChanged",
  562. "OnInvalidated,{X=0,Y=0,Width="+l.Size.Width+",Height="+l.Size.Height+"}",
  563. "OnInvalidated," + rect.ToString ()
  564. };
  565. l.Invalidate (rect);
  566. Assert.AreEqual (EventsWanted, ArrayListToString (l.Results));
  567. myform.Dispose();
  568. }
  569. [Test]
  570. public void PaintEventsOrder ()
  571. {
  572. string[] EventsWanted = {
  573. "OnHandleCreated",
  574. "OnBindingContextChanged",
  575. "OnBindingContextChanged",
  576. "OnInvalidated",
  577. "OnInvalidated",
  578. "OnPaint"
  579. };
  580. Form myform = new Form ();
  581. myform.Visible = true;
  582. MyLabel l = new MyLabel ();
  583. myform.Controls.Add (l);
  584. l.TextAlign = ContentAlignment.TopRight;
  585. l.Refresh ();
  586. Assert.AreEqual (EventsWanted, ArrayListToString (l.Results));
  587. myform.Dispose();
  588. }
  589. }
  590. public class MyLabel2 : Label
  591. {
  592. protected ArrayList results = new ArrayList ();
  593. public MyLabel2 () : base ()
  594. {
  595. this.AutoSizeChanged += new EventHandler (AutoSizeChanged_Handler);
  596. this.HandleCreated += new EventHandler (HandleCreated_Handler);
  597. this.BindingContextChanged += new EventHandler (BindingContextChanged_Handler);
  598. this.BackgroundImageChanged += new EventHandler (BackgroundImageChanged_Handler);
  599. this.ImeModeChanged += new EventHandler (ImeModeChanged_Handler);
  600. this.KeyDown += new KeyEventHandler (KeyDown_Handler);
  601. this.KeyPress += new KeyPressEventHandler (KeyPress_Handler);
  602. this.KeyUp += new KeyEventHandler (KeyUp_Handler);
  603. this.Invalidated += new InvalidateEventHandler (Invalidated_Handler);
  604. this.Resize += new EventHandler (Resize_Handler);
  605. this.SizeChanged += new EventHandler (SizeChanged_Handler);
  606. this.Layout += new LayoutEventHandler (Layout_Handler);
  607. this.VisibleChanged += new EventHandler (VisibleChanged_Handler);
  608. this.Paint += new PaintEventHandler (Paint_Handler);
  609. }
  610. protected void AutoSizeChanged_Handler (object sender, EventArgs e)
  611. {
  612. results.Add ("AutoSizeChanged");
  613. }
  614. protected void BackgroundImageChanged_Handler (object sender, EventArgs e)
  615. {
  616. results.Add ("BackgroundImageChanged");
  617. }
  618. protected void ImeModeChanged_Handler (object sender, EventArgs e)
  619. {
  620. results.Add ("ImeModeChanged");
  621. }
  622. protected void KeyDown_Handler (object sender, KeyEventArgs e)
  623. {
  624. results.Add ("KeyDown,"+(char)e.KeyValue);
  625. }
  626. protected void KeyPress_Handler (object sender, KeyPressEventArgs e)
  627. {
  628. results.Add ("KeyPress,"+e.KeyChar.ToString ());
  629. }
  630. protected void KeyUp_Handler (object sender, KeyEventArgs e)
  631. {
  632. results.Add ("KeyUp,"+(char)e.KeyValue);
  633. }
  634. protected void HandleCreated_Handler (object sender, EventArgs e)
  635. {
  636. results.Add ("HandleCreated");
  637. }
  638. protected void BindingContextChanged_Handler (object sender, EventArgs e)
  639. {
  640. results.Add ("BindingContextChanged");
  641. }
  642. protected void Invalidated_Handler (object sender, InvalidateEventArgs e)
  643. {
  644. results.Add("Invalidated");
  645. }
  646. protected void Resize_Handler (object sender, EventArgs e)
  647. {
  648. results.Add("Resize");
  649. }
  650. protected void SizeChanged_Handler (object sender, EventArgs e)
  651. {
  652. results.Add("SizeChanged");
  653. }
  654. protected void Layout_Handler (object sender, LayoutEventArgs e)
  655. {
  656. results.Add("Layout");
  657. }
  658. protected void VisibleChanged_Handler (object sender, EventArgs e)
  659. {
  660. results.Add("VisibleChanged");
  661. }
  662. protected void Paint_Handler (object sender, PaintEventArgs e)
  663. {
  664. results.Add("Paint");
  665. }
  666. public void KeyPressA()
  667. {
  668. Message m;
  669. m = new Message();
  670. m.Msg = (int)WndMsg.WM_KEYDOWN;
  671. m.HWnd = this.Handle;
  672. m.WParam = (IntPtr)0x41;
  673. m.LParam = (IntPtr)0x1e0001;
  674. this.WndProc(ref m);
  675. m.Msg = (int)WndMsg.WM_CHAR;
  676. m.HWnd = this.Handle;
  677. m.WParam = (IntPtr)0x61;
  678. m.LParam = (IntPtr)0x1e0001;
  679. this.WndProc(ref m);
  680. m.Msg = (int)WndMsg.WM_KEYUP;
  681. m.HWnd = this.Handle;
  682. m.WParam = (IntPtr)0x41;
  683. m.LParam = (IntPtr)unchecked((int)0xC01e0001);
  684. this.WndProc(ref m);
  685. }
  686. public void KeyDownA()
  687. {
  688. Message m;
  689. m = new Message();
  690. m.Msg = (int)WndMsg.WM_KEYDOWN;
  691. m.HWnd = this.Handle;
  692. m.WParam = (IntPtr)0x41;
  693. m.LParam = (IntPtr)0x1e0001;
  694. this.WndProc(ref m);
  695. m.Msg = (int)WndMsg.WM_CHAR;
  696. m.HWnd = this.Handle;
  697. m.WParam = (IntPtr)0x61;
  698. m.LParam = (IntPtr)0x1e0001;
  699. this.WndProc(ref m);
  700. }
  701. public void KeyUpA()
  702. {
  703. Message m;
  704. m = new Message();
  705. m.Msg = (int)WndMsg.WM_KEYUP;
  706. m.HWnd = this.Handle;
  707. m.WParam = (IntPtr)0x41;
  708. m.LParam = (IntPtr)unchecked((int)0xC01e0001);
  709. this.WndProc(ref m);
  710. }
  711. public ArrayList Results {
  712. get { return results; }
  713. }
  714. }
  715. [TestFixture]
  716. [Ignore("Comparisons too strict")]
  717. public class LabelTestEventsOrder2
  718. {
  719. public string [] ArrayListToString (ArrayList arrlist)
  720. {
  721. string [] retval = new string [arrlist.Count];
  722. for (int i = 0; i < arrlist.Count; i++)
  723. retval[i] = (string)arrlist[i];
  724. return retval;
  725. }
  726. [Test]
  727. public void CreateEventsOrder ()
  728. {
  729. string[] EventsWanted = {
  730. "HandleCreated",
  731. "BindingContextChanged",
  732. "BindingContextChanged"
  733. };
  734. Form myform = new Form ();
  735. myform.Visible = true;
  736. MyLabel2 l = new MyLabel2 ();
  737. myform.Controls.Add (l);
  738. Assert.AreEqual (EventsWanted, ArrayListToString (l.Results));
  739. myform.Dispose();
  740. }
  741. [Test]
  742. public void SizeChangedEventsOrder ()
  743. {
  744. string[] EventsWanted = {
  745. "HandleCreated",
  746. "BindingContextChanged",
  747. "BindingContextChanged",
  748. "Invalidated",
  749. "Layout",
  750. "Resize",
  751. "SizeChanged"
  752. };
  753. Form myform = new Form ();
  754. myform.Visible = true;
  755. MyLabel2 l = new MyLabel2 ();
  756. myform.Controls.Add (l);
  757. l.Size = new Size (150, 20);
  758. Assert.AreEqual (EventsWanted, ArrayListToString (l.Results));
  759. myform.Dispose();
  760. }
  761. [Test]
  762. public void AutoSizeChangedEventsOrder ()
  763. {
  764. string[] EventsWanted = {
  765. "HandleCreated",
  766. "BindingContextChanged",
  767. "BindingContextChanged",
  768. "Invalidated",
  769. "Layout",
  770. "Resize",
  771. "SizeChanged",
  772. "AutoSizeChanged"
  773. };
  774. Form myform = new Form ();
  775. myform.Visible = true;
  776. MyLabel2 l = new MyLabel2 ();
  777. myform.Controls.Add (l);
  778. l.AutoSize = true;
  779. Assert.AreEqual (EventsWanted, ArrayListToString (l.Results));
  780. myform.Dispose();
  781. }
  782. [Test]
  783. public void BackgroundImageChangedEventsOrder ()
  784. {
  785. string[] EventsWanted = {
  786. "HandleCreated",
  787. "BindingContextChanged",
  788. "BindingContextChanged",
  789. "Invalidated",
  790. "BackgroundImageChanged"
  791. };
  792. Form myform = new Form ();
  793. myform.Visible = true;
  794. MyLabel2 l = new MyLabel2 ();
  795. myform.Controls.Add (l);
  796. l.BackgroundImage = Image.FromFile ("Test/System.Windows.Forms/bitmaps/a.png");
  797. Assert.AreEqual (EventsWanted, ArrayListToString (l.Results));
  798. myform.Dispose();
  799. }
  800. [Test]
  801. public void ImeModeChangedChangedEventsOrder ()
  802. {
  803. string[] EventsWanted = {
  804. "HandleCreated",
  805. "BindingContextChanged",
  806. "BindingContextChanged",
  807. "ImeModeChanged"
  808. };
  809. Form myform = new Form ();
  810. myform.Visible = true;
  811. MyLabel2 l = new MyLabel2 ();
  812. myform.Controls.Add (l);
  813. l.ImeMode = ImeMode.Katakana;
  814. Assert.AreEqual (EventsWanted, ArrayListToString (l.Results));
  815. myform.Dispose();
  816. }
  817. [Test]
  818. public void KeyPressEventsOrder ()
  819. {
  820. string[] EventsWanted = {
  821. "HandleCreated",
  822. "BindingContextChanged",
  823. "BindingContextChanged",
  824. "KeyDown,A",
  825. "KeyPress,a",
  826. "KeyUp,A"
  827. };
  828. Form myform = new Form ();
  829. myform.Visible = true;
  830. MyLabel2 l = new MyLabel2 ();
  831. myform.Controls.Add (l);
  832. l.KeyPressA ();
  833. Assert.AreEqual (EventsWanted, ArrayListToString (l.Results));
  834. myform.Dispose();
  835. }
  836. [Test]
  837. public void TabStopChangedEventsOrder ()
  838. {
  839. string[] EventsWanted = {
  840. "HandleCreated",
  841. "BindingContextChanged",
  842. "BindingContextChanged"
  843. };
  844. Form myform = new Form ();
  845. myform.Visible = true;
  846. MyLabel2 l = new MyLabel2 ();
  847. myform.Controls.Add (l);
  848. l.TabStop = true;
  849. Assert.AreEqual (EventsWanted, ArrayListToString (l.Results));
  850. myform.Dispose();
  851. }
  852. [Test]
  853. public void TextAlignChangedEventsOrder ()
  854. {
  855. string[] EventsWanted = {
  856. "HandleCreated",
  857. "BindingContextChanged",
  858. "BindingContextChanged",
  859. "Invalidated"
  860. };
  861. Form myform = new Form ();
  862. myform.Visible = true;
  863. MyLabel2 l = new MyLabel2 ();
  864. myform.Controls.Add (l);
  865. l.TextAlign = ContentAlignment.TopRight;
  866. Assert.AreEqual (EventsWanted, ArrayListToString (l.Results));
  867. myform.Dispose();
  868. }
  869. [Test]
  870. public void PaintEventsOrder ()
  871. {
  872. string[] EventsWanted = {
  873. "HandleCreated",
  874. "BindingContextChanged",
  875. "BindingContextChanged",
  876. "Invalidated",
  877. "Invalidated",
  878. "Paint"
  879. };
  880. Form myform = new Form ();
  881. myform.Visible = true;
  882. MyLabel2 l = new MyLabel2 ();
  883. myform.Controls.Add (l);
  884. l.TextAlign = ContentAlignment.TopRight;
  885. l.Refresh ();
  886. Assert.AreEqual (EventsWanted, ArrayListToString (l.Results));
  887. myform.Dispose();
  888. }
  889. }
  890. }