LabelTest.cs 27 KB

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