* LabelTest.cs : Added messages to simulate Key* events.
[mono.git] / mcs / class / Managed.Windows.Forms / Test / System.Windows.Forms / LabelTest.cs
1 //
2 // Copyright (c) 2005 Novell, Inc.
3 //
4 // Authors:
5 //      Hisham Mardam Bey (hisham.mardambey@gmail.com)
6 //
7 //
8
9 using System;
10 using NUnit.Framework;
11 using System.Windows.Forms;
12 using System.Drawing;
13 using System.Collections;
14
15 namespace MonoTests.System.Windows.Forms
16 {
17         internal enum WndMsg {
18                 WM_NULL                   = 0x0000,
19                 WM_CREATE                 = 0x0001,
20                 WM_DESTROY                = 0x0002,
21                 WM_MOVE                   = 0x0003,
22                 WM_SIZE                   = 0x0005,
23                 WM_ACTIVATE               = 0x0006,
24                 WM_SETFOCUS               = 0x0007,
25                 WM_KILLFOCUS              = 0x0008,
26                 //              public const uint WM_SETVISIBLE           = 0x0009;
27                 WM_ENABLE                 = 0x000A,
28                 WM_SETREDRAW              = 0x000B,
29                 WM_SETTEXT                = 0x000C,
30                 WM_GETTEXT                = 0x000D,
31                 WM_GETTEXTLENGTH          = 0x000E,
32                 WM_PAINT                  = 0x000F,
33                 WM_CLOSE                  = 0x0010,
34                 WM_QUERYENDSESSION        = 0x0011,
35                 WM_QUIT                   = 0x0012,
36                 WM_QUERYOPEN              = 0x0013,
37                 WM_ERASEBKGND             = 0x0014,
38                 WM_SYSCOLORCHANGE         = 0x0015,
39                 WM_ENDSESSION             = 0x0016,
40                 //              public const uint WM_SYSTEMERROR          = 0x0017;
41                 WM_SHOWWINDOW             = 0x0018,
42                 WM_CTLCOLOR               = 0x0019,
43                 WM_WININICHANGE           = 0x001A,
44                 WM_SETTINGCHANGE          = 0x001A,
45                 WM_DEVMODECHANGE          = 0x001B,
46                 WM_ACTIVATEAPP            = 0x001C,
47                 WM_FONTCHANGE             = 0x001D,
48                 WM_TIMECHANGE             = 0x001E,
49                 WM_CANCELMODE             = 0x001F,
50                 WM_SETCURSOR              = 0x0020,
51                 WM_MOUSEACTIVATE          = 0x0021,
52                 WM_CHILDACTIVATE          = 0x0022,
53                 WM_QUEUESYNC              = 0x0023,
54                 WM_GETMINMAXINFO          = 0x0024,
55                 WM_PAINTICON              = 0x0026,
56                 WM_ICONERASEBKGND         = 0x0027,
57                 WM_NEXTDLGCTL             = 0x0028,
58                 //              public const uint WM_ALTTABACTIVE         = 0x0029;
59                 WM_SPOOLERSTATUS          = 0x002A,
60                 WM_DRAWITEM               = 0x002B,
61                 WM_MEASUREITEM            = 0x002C,
62                 WM_DELETEITEM             = 0x002D,
63                 WM_VKEYTOITEM             = 0x002E,
64                 WM_CHARTOITEM             = 0x002F,
65                 WM_SETFONT                = 0x0030,
66                 WM_GETFONT                = 0x0031,
67                 WM_SETHOTKEY              = 0x0032,
68                 WM_GETHOTKEY              = 0x0033,
69                 //              public const uint WM_FILESYSCHANGE        = 0x0034;
70                 //              public const uint WM_ISACTIVEICON         = 0x0035;
71                 //              public const uint WM_QUERYPARKICON        = 0x0036;
72                 WM_QUERYDRAGICON          = 0x0037,
73                 WM_COMPAREITEM            = 0x0039,
74                 //              public const uint WM_TESTING              = 0x003a;
75                 //              public const uint WM_OTHERWINDOWCREATED = 0x003c;
76                 WM_GETOBJECT              = 0x003D,
77                 //                      public const uint WM_ACTIVATESHELLWINDOW        = 0x003e;
78                 WM_COMPACTING             = 0x0041,
79                 WM_COMMNOTIFY             = 0x0044 ,
80                 WM_WINDOWPOSCHANGING      = 0x0046,
81                 WM_WINDOWPOSCHANGED       = 0x0047,
82                 WM_POWER                  = 0x0048,
83                 WM_COPYDATA               = 0x004A,
84                 WM_CANCELJOURNAL          = 0x004B,
85                 WM_NOTIFY                 = 0x004E,
86                 WM_INPUTLANGCHANGEREQUEST = 0x0050,
87                 WM_INPUTLANGCHANGE        = 0x0051,
88                 WM_TCARD                  = 0x0052,
89                 WM_HELP                   = 0x0053,
90                 WM_USERCHANGED            = 0x0054,
91                 WM_NOTIFYFORMAT           = 0x0055,
92                 WM_CONTEXTMENU            = 0x007B,
93                 WM_STYLECHANGING          = 0x007C,
94                 WM_STYLECHANGED           = 0x007D,
95                 WM_DISPLAYCHANGE          = 0x007E,
96                 WM_GETICON                = 0x007F,
97
98                 // Non-Client messages
99                 WM_SETICON                = 0x0080,
100                 WM_NCCREATE               = 0x0081,
101                 WM_NCDESTROY              = 0x0082,
102                 WM_NCCALCSIZE             = 0x0083,
103                 WM_NCHITTEST              = 0x0084,
104                 WM_NCPAINT                = 0x0085,
105                 WM_NCACTIVATE             = 0x0086,
106                 WM_GETDLGCODE             = 0x0087,
107                 WM_SYNCPAINT              = 0x0088,
108                 //              public const uint WM_SYNCTASK       = 0x0089;
109                 WM_NCMOUSEMOVE            = 0x00A0,
110                 WM_NCLBUTTONDOWN          = 0x00A1,
111                 WM_NCLBUTTONUP            = 0x00A2,
112                 WM_NCLBUTTONDBLCLK        = 0x00A3,
113                 WM_NCRBUTTONDOWN          = 0x00A4,
114                 WM_NCRBUTTONUP            = 0x00A5,
115                 WM_NCRBUTTONDBLCLK        = 0x00A6,
116                 WM_NCMBUTTONDOWN          = 0x00A7,
117                 WM_NCMBUTTONUP            = 0x00A8,
118                 WM_NCMBUTTONDBLCLK        = 0x00A9,
119                 //              public const uint WM_NCXBUTTONDOWN    = 0x00ab;
120                 //              public const uint WM_NCXBUTTONUP      = 0x00ac;
121                 //              public const uint WM_NCXBUTTONDBLCLK  = 0x00ad;
122                 WM_KEYDOWN                = 0x0100,
123                 WM_KEYFIRST               = 0x0100,
124                 WM_KEYUP                  = 0x0101,
125                 WM_CHAR                   = 0x0102,
126                 WM_DEADCHAR               = 0x0103,
127                 WM_SYSKEYDOWN             = 0x0104,
128                 WM_SYSKEYUP               = 0x0105,
129                 WM_SYSCHAR                = 0x0106,
130                 WM_SYSDEADCHAR            = 0x0107,
131                 WM_KEYLAST                = 0x0108,
132                 WM_IME_STARTCOMPOSITION   = 0x010D,
133                 WM_IME_ENDCOMPOSITION     = 0x010E,
134                 WM_IME_COMPOSITION        = 0x010F,
135                 WM_IME_KEYLAST            = 0x010F,
136                 WM_INITDIALOG             = 0x0110,
137                 WM_COMMAND                = 0x0111,
138                 WM_SYSCOMMAND             = 0x0112,
139                 WM_TIMER                  = 0x0113,
140                 WM_HSCROLL                = 0x0114,
141                 WM_VSCROLL                = 0x0115,
142                 WM_INITMENU               = 0x0116,
143                 WM_INITMENUPOPUP          = 0x0117,
144                 //              public const uint WM_SYSTIMER       = 0x0118;
145                 WM_MENUSELECT             = 0x011F,
146                 WM_MENUCHAR               = 0x0120,
147                 WM_ENTERIDLE              = 0x0121,
148                 WM_MENURBUTTONUP          = 0x0122,
149                 WM_MENUDRAG               = 0x0123,
150                 WM_MENUGETOBJECT          = 0x0124,
151                 WM_UNINITMENUPOPUP        = 0x0125,
152                 WM_MENUCOMMAND            = 0x0126,
153                 //              public const uint WM_CHANGEUISTATE    = 0x0127;
154                 //              public const uint WM_UPDATEUISTATE    = 0x0128;
155                 //              public const uint WM_QUERYUISTATE     = 0x0129;
156
157                 //              public const uint WM_LBTRACKPOINT     = 0x0131;
158                 WM_CTLCOLORMSGBOX         = 0x0132,
159                 WM_CTLCOLOREDIT           = 0x0133,
160                 WM_CTLCOLORLISTBOX        = 0x0134,
161                 WM_CTLCOLORBTN            = 0x0135,
162                 WM_CTLCOLORDLG            = 0x0136,
163                 WM_CTLCOLORSCROLLBAR      = 0x0137,
164                 WM_CTLCOLORSTATIC         = 0x0138,
165                 WM_MOUSEMOVE              = 0x0200,
166                 WM_MOUSEFIRST                     = 0x0200,
167                 WM_LBUTTONDOWN            = 0x0201,
168                 WM_LBUTTONUP              = 0x0202,
169                 WM_LBUTTONDBLCLK          = 0x0203,
170                 WM_RBUTTONDOWN            = 0x0204,
171                 WM_RBUTTONUP              = 0x0205,
172                 WM_RBUTTONDBLCLK          = 0x0206,
173                 WM_MBUTTONDOWN            = 0x0207,
174                 WM_MBUTTONUP              = 0x0208,
175                 WM_MBUTTONDBLCLK          = 0x0209,
176                 WM_MOUSEWHEEL             = 0x020A,
177                 WM_MOUSELAST             = 0x020D,
178                 //              public const uint WM_XBUTTONDOWN      = 0x020B;
179                 //              public const uint WM_XBUTTONUP        = 0x020C;
180                 //              public const uint WM_XBUTTONDBLCLK    = 0x020D;
181                 WM_PARENTNOTIFY           = 0x0210,
182                 WM_ENTERMENULOOP          = 0x0211,
183                 WM_EXITMENULOOP           = 0x0212,
184                 WM_NEXTMENU               = 0x0213,
185                 WM_SIZING                 = 0x0214,
186                 WM_CAPTURECHANGED         = 0x0215,
187                 WM_MOVING                 = 0x0216,
188                 //              public const uint WM_POWERBROADCAST   = 0x0218;
189                 WM_DEVICECHANGE           = 0x0219,
190                 WM_MDICREATE              = 0x0220,
191                 WM_MDIDESTROY             = 0x0221,
192                 WM_MDIACTIVATE            = 0x0222,
193                 WM_MDIRESTORE             = 0x0223,
194                 WM_MDINEXT                = 0x0224,
195                 WM_MDIMAXIMIZE            = 0x0225,
196                 WM_MDITILE                = 0x0226,
197                 WM_MDICASCADE             = 0x0227,
198                 WM_MDIICONARRANGE         = 0x0228,
199                 WM_MDIGETACTIVE           = 0x0229,
200                 /* D&D messages */
201                 //              public const uint WM_DROPOBJECT     = 0x022A;
202                 //              public const uint WM_QUERYDROPOBJECT  = 0x022B;
203                 //              public const uint WM_BEGINDRAG      = 0x022C;
204                 //              public const uint WM_DRAGLOOP       = 0x022D;
205                 //              public const uint WM_DRAGSELECT     = 0x022E;
206                 //              public const uint WM_DRAGMOVE       = 0x022F;
207                 WM_MDISETMENU             = 0x0230,
208                 WM_ENTERSIZEMOVE          = 0x0231,
209                 WM_EXITSIZEMOVE           = 0x0232,
210                 WM_DROPFILES              = 0x0233,
211                 WM_MDIREFRESHMENU         = 0x0234,
212                 WM_IME_SETCONTEXT         = 0x0281,
213                 WM_IME_NOTIFY             = 0x0282,
214                 WM_IME_CONTROL            = 0x0283,
215                 WM_IME_COMPOSITIONFULL    = 0x0284,
216                 WM_IME_SELECT             = 0x0285,
217                 WM_IME_CHAR               = 0x0286,
218                 WM_IME_REQUEST            = 0x0288,
219                 WM_IME_KEYDOWN            = 0x0290,
220                 WM_IME_KEYUP              = 0x0291,
221                 WM_MOUSEHOVER             = 0x02A1,
222                 WM_MOUSELEAVE             = 0x02A3,
223                 WM_CUT                    = 0x0300,
224                 WM_COPY                   = 0x0301,
225                 WM_PASTE                  = 0x0302,
226                 WM_CLEAR                  = 0x0303,
227                 WM_UNDO                   = 0x0304,
228                 WM_RENDERFORMAT           = 0x0305,
229                 WM_RENDERALLFORMATS       = 0x0306,
230                 WM_DESTROYCLIPBOARD       = 0x0307,
231                 WM_DRAWCLIPBOARD          = 0x0308,
232                 WM_PAINTCLIPBOARD         = 0x0309,
233                 WM_VSCROLLCLIPBOARD       = 0x030A,
234                 WM_SIZECLIPBOARD          = 0x030B,
235                 WM_ASKCBFORMATNAME        = 0x030C,
236                 WM_CHANGECBCHAIN          = 0x030D,
237                 WM_HSCROLLCLIPBOARD       = 0x030E,
238                 WM_QUERYNEWPALETTE        = 0x030F,
239                 WM_PALETTEISCHANGING      = 0x0310,
240                 WM_PALETTECHANGED         = 0x0311,
241                 WM_HOTKEY                 = 0x0312,
242                 WM_PRINT                  = 0x0317,
243                 WM_PRINTCLIENT            = 0x0318,
244                 WM_HANDHELDFIRST          = 0x0358,
245                 WM_HANDHELDLAST           = 0x035F,
246                 WM_AFXFIRST               = 0x0360,
247                 WM_AFXLAST                = 0x037F,
248                 WM_PENWINFIRST            = 0x0380,
249                 WM_PENWINLAST             = 0x038F,
250                 WM_APP                    = 0x8000,
251                 WM_USER                   = 0x0400,
252
253                 // Our "private" ones
254                 WM_MOUSE_ENTER            = 0x0401,
255                 WM_MOUSE_LEAVE            = 0x0402,
256                 WM_ASYNC_MESSAGE          = 0x0403,
257                 WM_REFLECT                = WM_USER + 0x1c00
258         }
259    
260         [TestFixture]
261         
262         public class LabelTest2 
263         {
264
265                 [Test]
266                 public void PubPropTest ()
267                 {
268                         Label l = new Label ();
269
270                         // A
271                         Assert.AreEqual (false, l.AutoSize, "A1");
272                         l.AutoSize = true;
273                         Assert.AreEqual (true, l.AutoSize, "A2");
274                         l.AutoSize = false;
275                         Assert.AreEqual (false, l.AutoSize, "A3");
276
277                         // B
278                         Assert.AreEqual (null, l.BackgroundImage, "B1");
279                         l.BackgroundImage = Image.FromFile ("Test/System.Windows.Forms/bitmaps/a.png");
280                         Assert.IsNotNull (l.BackgroundImage, "B2");
281                         Bitmap bmp = (Bitmap)l.BackgroundImage;
282                         Assert.IsNotNull (bmp.GetPixel (0, 0), "B3");
283
284                         Assert.AreEqual (BorderStyle.None, l.BorderStyle, "B4");
285                         l.BorderStyle = BorderStyle.FixedSingle;
286                         Assert.AreEqual (BorderStyle.FixedSingle, l.BorderStyle, "B5");
287                         l.BorderStyle = BorderStyle.Fixed3D;
288                         Assert.AreEqual (BorderStyle.Fixed3D, l.BorderStyle, "B6");
289                         l.BorderStyle = BorderStyle.None;
290                         Assert.AreEqual (BorderStyle.None, l.BorderStyle, "B7");
291                         
292                         // C
293                         string name = l.CompanyName;
294                         if (!name.Equals("Mono Project, Novell, Inc.") && !name.Equals("Microsoft Corporation")) {
295                                 Assert.Fail("CompanyName property does not match any accepted value - C1");
296                         }
297                         
298                         
299                         // F
300                         Assert.AreEqual (FlatStyle.Standard, l.FlatStyle, "F1");
301                         l.FlatStyle = FlatStyle.Flat;
302                         Assert.AreEqual (FlatStyle.Flat, l.FlatStyle, "F1");
303                         l.FlatStyle = FlatStyle.Popup;
304                         Assert.AreEqual (FlatStyle.Popup, l.FlatStyle, "F2");
305                         l.FlatStyle = FlatStyle.Standard;
306                         Assert.AreEqual (FlatStyle.Standard, l.FlatStyle, "F3");
307                         l.FlatStyle = FlatStyle.System;
308                         Assert.AreEqual (FlatStyle.System, l.FlatStyle, "F4");
309                         
310                         // I
311                         Assert.AreEqual (ContentAlignment.MiddleCenter, l.ImageAlign, "I1");
312                         l.ImageAlign = ContentAlignment.TopLeft;
313                         Assert.AreEqual (ContentAlignment.TopLeft, l.ImageAlign, "I2");
314                         l.ImageAlign = ContentAlignment.TopCenter;
315                         Assert.AreEqual (ContentAlignment.TopCenter, l.ImageAlign, "I3");
316                         l.ImageAlign = ContentAlignment.TopRight;
317                         Assert.AreEqual (ContentAlignment.TopRight, l.ImageAlign, "I4");
318                         l.ImageAlign = ContentAlignment.MiddleLeft;
319                         Assert.AreEqual (ContentAlignment.MiddleLeft, l.ImageAlign, "I5");
320                         l.ImageAlign = ContentAlignment.MiddleCenter;
321                         Assert.AreEqual (ContentAlignment.MiddleCenter, l.ImageAlign, "I6");
322                         l.ImageAlign = ContentAlignment.MiddleRight;
323                         Assert.AreEqual (ContentAlignment.MiddleRight, l.ImageAlign, "I7");
324                         l.ImageAlign = ContentAlignment.BottomLeft;
325                         Assert.AreEqual (ContentAlignment.BottomLeft, l.ImageAlign, "I8");
326                         l.ImageAlign = ContentAlignment.BottomCenter;
327                         Assert.AreEqual (ContentAlignment.BottomCenter, l.ImageAlign, "I9");
328                         l.ImageAlign = ContentAlignment.BottomRight;
329                         Assert.AreEqual (ContentAlignment.BottomRight, l.ImageAlign, "I10");
330                         Assert.AreEqual (-1, l.ImageIndex, "I11");
331                         Assert.AreEqual (null, l.ImageList, "I12");
332                         Assert.AreEqual (null, l.Image, "I13");
333                         l.Image = Image.FromFile ("Test/System.Windows.Forms/bitmaps/a.png");
334                         Assert.IsNotNull (l.Image, "I14");
335                         bmp = (Bitmap)l.Image;
336                         Assert.IsNotNull (bmp.GetPixel (0, 0), "I15");
337                         
338                         
339                         ImageList il = new ImageList ();
340                         il.ColorDepth = ColorDepth.Depth32Bit;
341                         il.ImageSize = new Size (15, 15);
342                         il.Images.Add (Image.FromFile ("Test/System.Windows.Forms/bitmaps/a.png"));
343                         l.ImageList = il;
344                         l.ImageIndex = 0;
345                         
346                         Assert.AreEqual (0, l.ImageIndex, "I16");
347                         Assert.IsNotNull (l.ImageList, "I17");
348                         
349                         // PreferredHeight
350                         // PregerredWidth
351                         // RenderTransparent
352                         
353                         // T
354                         // Assert.AreEqual (false, l.TabStop, "T1");
355                         Assert.AreEqual (ContentAlignment.TopLeft, l.TextAlign, "T2");
356                         
357                         // U
358                         Assert.AreEqual (true, l.UseMnemonic, "U1");
359                         l.UseMnemonic = false;
360                         Assert.AreEqual (false, l.UseMnemonic, "U2");
361                 }
362
363                         
364                 [Test]
365                 public void LabelEqualsTest () 
366                 {
367                         Label s1 = new Label ();
368                         Label s2 = new Label ();
369                         s1.Text = "abc";
370                         s2.Text = "abc";
371                         Assert.AreEqual (false, s1.Equals (s2), "E1");
372                         Assert.AreEqual (true, s1.Equals (s1), "E2");
373                 }
374                                         
375                 [Test]
376                 public void LabelScaleTest () 
377                 {
378                         Label r1 = new Label ();
379                         r1.Width = 40;
380                         r1.Height = 20 ;
381                         r1.Scale (2);
382                         Assert.AreEqual (80, r1.Width, "W1");
383                         Assert.AreEqual (40, r1.Height, "H1");
384                 }
385                                 
386                 [Test]
387                 public void PubMethodTest ()
388                 {
389                         Label l = new Label ();
390                         
391                         l.Text = "My Label";
392                         
393                         Assert.AreEqual ("System.Windows.Forms.Label, Text: My Label", l.ToString (), "T1");
394                           
395                 }
396         }
397    
398         [TestFixture]
399         public class LabelEventTest
400         {
401                 static bool eventhandled = false;
402                 public void Label_EventHandler (object sender,EventArgs e)
403                 {
404                         eventhandled = true;
405                 }
406                 
407                 [Test]
408                 public void AutoSizeChangedChangedTest ()
409                 {
410                         Form myform = new Form ();
411                         myform.Visible = true;
412                         Label l = new Label ();
413                         l.Visible = true;
414                         myform.Controls.Add (l);
415                         l.AutoSizeChanged += new EventHandler (Label_EventHandler);
416                         l.AutoSize = true;
417                         Assert.AreEqual (true, eventhandled, "B4");
418                         eventhandled = false;                   
419                 }
420                 
421                 [Test]
422                 public void BackgroundImageChangedTest ()
423                 {
424                         Form myform = new Form ();
425                         myform.Visible = true;
426                         Label l = new Label ();
427                         l.Visible = true;
428                         myform.Controls.Add (l);
429                         l.BackgroundImageChanged += new EventHandler (Label_EventHandler);
430                         l.BackgroundImage = Image.FromFile ("Test/System.Windows.Forms/bitmaps/a.png");
431                         Assert.AreEqual (true, eventhandled, "B4");
432                         eventhandled = false;                   
433                 }
434                 
435                 [Test]
436                 public void ImeModeChangedTest ()
437                 {
438                         Form myform = new Form ();
439                         myform.Visible = true;
440                         Label l = new Label ();
441                         l.Visible = true;
442                         myform.Controls.Add (l);
443                         l.ImeModeChanged += new EventHandler (Label_EventHandler);
444                         l.ImeMode = ImeMode.Katakana;
445                         Assert.AreEqual (true, eventhandled, "I16");
446                         eventhandled = false;
447                 }
448
449                 [Test, Ignore ("This isnt complete.")]
450                 public void KeyDownTest ()
451                 {
452                         Form myform = new Form ();
453                         myform.Visible = true;
454                         Label l = new Label ();
455                         l.Visible = true;
456                         myform.Controls.Add (l);
457                         l.KeyDown += new KeyEventHandler (Label_EventHandler);
458                         
459                         //Assert.AreEqual (true, eventhandled, "K1");
460                         eventhandled = false;
461                 }
462
463
464                 [Test, Ignore ("This is failing.")]
465                 public void TabStopChangedTest ()
466                 {
467                         Form myform = new Form ();
468                         myform.Visible = true;
469                         Label l = new Label ();
470                         l.Visible = true;
471                         myform.Controls.Add (l);
472                         l.TabStopChanged += new EventHandler (Label_EventHandler);
473                         l.TabStop = true;
474                         Assert.AreEqual (true, eventhandled, "T3");
475                         eventhandled = false;
476                 }
477                 
478                 [Test]
479                 public void TextAlignChangedTest ()
480                 {
481                         Form myform = new Form ();
482                         myform.Visible = true;
483                         Label l = new Label ();
484                         l.Visible = true;
485                         myform.Controls.Add (l);
486                         l.TextAlignChanged += new EventHandler (Label_EventHandler);
487                         l.TextAlign = ContentAlignment.TopRight;
488                         Assert.AreEqual (true, eventhandled, "T4");
489                         eventhandled = false;
490                 }
491         }
492    
493         public class MyLabel : Label
494         {
495                 private ArrayList results = new ArrayList ();
496                 public MyLabel () : base ()
497                 {
498                         // TODO: we need to add those later.
499                         //this.HandleCreated += new EventHandler (HandleCreatedHandler);
500                         //this.BindingContextChanged += new EventHandler (BindingContextChangedHandler);
501                         //this.Invalidated += new InvalidateEventHandler (InvalidatedHandler);
502                         //this.Resize += new EventHandler (ResizeHandler);
503                         //this.SizeChanged += new EventHandler (SizeChangedHandler);
504                         //this.Layout += new LayoutEventHandler (LayoutHandler);
505                         //this.VisibleChanged += new EventHandler (VisibleChangedHandler);
506                         //this.Paint += new PaintEventHandler (PaintHandler);
507                 }
508                 
509                 protected override void OnAutoSizeChanged (EventArgs e)
510                 {
511                         results.Add ("OnAutoSizeChanged");
512                         base.OnAutoSizeChanged (e);
513                 }
514                 
515                 protected override void OnBackgroundImageChanged (EventArgs e)
516                 {
517                         results.Add ("OnBackgroundImageChanged");
518                         base.OnBackgroundImageChanged (e);
519                 }
520                 
521                 protected override void OnImeModeChanged (EventArgs e)
522                 {
523                         results.Add ("OnImeModeChanged");
524                         base.OnImeModeChanged (e);
525                 }
526                 
527                 protected override void OnKeyDown (KeyEventArgs e)
528                 {
529                         results.Add ("OnKeyDown");
530                         base.OnKeyDown (e);
531                 }
532                 
533                 protected override void OnKeyPress (KeyPressEventArgs e)
534                 {
535                         results.Add ("OnKeyPress");
536                         base.OnKeyPress (e);
537                 }
538                 
539                 protected override void OnKeyUp (KeyEventArgs e)
540                 {
541                         results.Add ("OnKeyUp");
542                         base.OnKeyUp (e);
543                 }
544                 
545                 protected override void OnHandleCreated (EventArgs e)
546                 {
547                         results.Add ("OnHandleCreated");
548                         base.OnHandleCreated (e);
549                 }
550                 
551                 protected override void OnBindingContextChanged (EventArgs e)
552                 {
553                         results.Add ("OnBindingContextChanged");
554                         base.OnBindingContextChanged (e);
555                 }
556                 
557                 protected override void OnInvalidated (InvalidateEventArgs e)
558                 {
559                         results.Add("OnInvalidated");
560                         base.OnInvalidated (e);
561                 }
562                 
563                 protected override void OnResize (EventArgs e)
564                 {
565                         results.Add("OnResize");
566                         base.OnResize (e);
567                 }
568                 
569                 protected override void OnSizeChanged (EventArgs e)
570                 {
571                         results.Add("OnSizeChanged");
572                         base.OnSizeChanged (e);
573                 }
574                 
575                 protected override void OnLayout (LayoutEventArgs e)
576                 {
577                         results.Add("OnLayout");
578                         base.OnLayout (e);
579                 }
580                 
581                 protected override void OnVisibleChanged (EventArgs e)
582                 {
583                         results.Add("OnVisibleChanged");
584                         base.OnVisibleChanged (e);
585                 }
586                 
587                 protected override void OnPaint (PaintEventArgs e)
588                 {
589                         results.Add("OnPaint");
590                         base.OnPaint (e);
591                 }
592                 
593                 public void KeyPressA() 
594                 {
595                         Message m;
596
597                         m = new Message();
598
599                         m.Msg = (int)WndMsg.WM_KEYDOWN;
600                         m.HWnd = this.Handle;
601                         m.WParam = (IntPtr)0x41;
602                         m.LParam = (IntPtr)0x1e0001;
603                         this.WndProc(ref m);
604
605                         m.Msg = (int)WndMsg.WM_CHAR;
606                         m.HWnd = this.Handle;
607                         m.WParam = (IntPtr)0x61;
608                         m.LParam = (IntPtr)0x1e0001;
609                         this.WndProc(ref m);
610
611                         m.Msg = (int)WndMsg.WM_KEYUP;
612                         m.HWnd = this.Handle;
613                         m.WParam = (IntPtr)0x41;
614                         m.LParam = (IntPtr)unchecked((int)0xC01e0001);
615                         this.WndProc(ref m);
616                 }
617                 
618                 public void KeyDownA() 
619                 {
620                         Message m;
621
622                         m = new Message();
623
624                         m.Msg = (int)WndMsg.WM_KEYDOWN;
625                         m.HWnd = this.Handle;
626                         m.WParam = (IntPtr)0x41;
627                         m.LParam = (IntPtr)0x1e0001;
628                         this.WndProc(ref m);
629
630                         m.Msg = (int)WndMsg.WM_CHAR;
631                         m.HWnd = this.Handle;
632                         m.WParam = (IntPtr)0x61;
633                         m.LParam = (IntPtr)0x1e0001;
634                         this.WndProc(ref m);                    
635                 }
636                 
637                 public void KeyUpA() 
638                 {
639                         Message m;
640
641                         m = new Message();
642                         
643                         m.Msg = (int)WndMsg.WM_KEYUP;
644                         m.HWnd = this.Handle;
645                         m.WParam = (IntPtr)0x41;
646                         m.LParam = (IntPtr)unchecked((int)0xC01e0001);
647                         this.WndProc(ref m);
648                 }               
649                 
650                 public ArrayList Results {
651                         get {   return results; }
652                 }               
653         }       
654    
655         [TestFixture]
656         public class LabelTestEventsOrder
657         {                               
658                 public string [] ArrayListToString (ArrayList arrlist)
659                 {
660                         string [] retval = new string [arrlist.Count];
661                         for (int i = 0; i < arrlist.Count; i++)
662                           retval[i] = (string)arrlist[i];
663                         return retval;
664                 }
665                 
666                 [Test]
667                 public void CreateEventsOrder ()
668                 {
669                         string[] EventsWanted = {
670                                 "OnHandleCreated",
671                                   "OnBindingContextChanged",
672                                   "OnBindingContextChanged"
673                         };              
674                         Form myform = new Form ();
675                         myform.Visible = true;
676                         MyLabel l = new MyLabel ();                     
677                         myform.Controls.Add (l);                        
678                         
679                         Assert.AreEqual (EventsWanted, ArrayListToString (l.Results));
680                 }
681                 
682                 [Test]
683                 public void SizeChangedEventsOrder ()
684                 {
685                         string[] EventsWanted = {
686                                 "OnHandleCreated",
687                                   "OnBindingContextChanged",
688                                   "OnBindingContextChanged",
689                                   "OnSizeChanged",
690                                   "OnResize",
691                                   "OnInvalidated",
692                                   "OnLayout"
693                         };              
694                         Form myform = new Form ();
695                         myform.Visible = true;
696                         MyLabel l = new MyLabel ();                     
697                         myform.Controls.Add (l);
698                         l.Size = new Size (150, 20);
699                         
700                         Assert.AreEqual (EventsWanted, ArrayListToString (l.Results));
701                 }
702                 
703                 [Test]
704                 public void AutoSizeChangedEventsOrder ()
705                 {
706                         string[] EventsWanted = {
707                                 "OnHandleCreated",
708                                   "OnBindingContextChanged",
709                                   "OnBindingContextChanged",
710                                   "OnSizeChanged",
711                                   "OnResize",
712                                   "OnInvalidated",
713                                   "OnLayout",
714                                   "OnAutoSizeChanged"
715                         };              
716                         Form myform = new Form ();
717                         myform.Visible = true;
718                         MyLabel l = new MyLabel ();                     
719                         myform.Controls.Add (l);
720                         l.AutoSize = true;
721                         
722                         Assert.AreEqual (EventsWanted, ArrayListToString (l.Results));
723                 }               
724                 
725                 [Test]
726                 public void BackgroundImageChangedEventsOrder ()
727                 {
728                         string[] EventsWanted = {
729                                 "OnHandleCreated",
730                                   "OnBindingContextChanged",
731                                   "OnBindingContextChanged",
732                                   "OnBackgroundImageChanged",
733                                   "OnInvalidated"
734                         };              
735                         Form myform = new Form ();
736                         myform.Visible = true;
737                         MyLabel l = new MyLabel ();                     
738                         myform.Controls.Add (l);
739                         l.BackgroundImage = Image.FromFile ("Test/System.Windows.Forms/bitmaps/a.png");
740                         
741                         Assert.AreEqual (EventsWanted, ArrayListToString (l.Results));
742                 }
743                 
744                 [Test]
745                 public void ImeModeChangedChangedEventsOrder ()
746                 {
747                         string[] EventsWanted = {
748                                 "OnHandleCreated",
749                                   "OnBindingContextChanged",
750                                   "OnBindingContextChanged",            
751                                   "OnImeModeChanged"            
752                         };              
753                         Form myform = new Form ();
754                         myform.Visible = true;
755                         MyLabel l = new MyLabel ();                     
756                         myform.Controls.Add (l);
757                         l.ImeMode = ImeMode.Katakana;
758                         
759                         Assert.AreEqual (EventsWanted, ArrayListToString (l.Results));
760                 }
761                 
762                 [Test]
763                 public void KeyDownEventsOrder ()
764                 {
765                         string[] EventsWanted = {
766                                 "OnHandleCreated",
767                                   "OnBindingContextChanged",
768                                   "OnBindingContextChanged",
769                                   "OnKeyDown",
770                                   "OnKeyPress"
771                         };              
772                         Form myform = new Form ();
773                         myform.Visible = true;
774                         MyLabel l = new MyLabel ();                     
775                         myform.Controls.Add (l);
776                         l.KeyDownA ();
777                         
778                         Assert.AreEqual (EventsWanted, ArrayListToString (l.Results));
779                 }
780                 
781                 [Test]
782                 public void KeyPressEventsOrder ()
783                 {
784                         string[] EventsWanted = {
785                                 "OnHandleCreated",
786                                   "OnBindingContextChanged",
787                                   "OnBindingContextChanged",
788                                   "OnKeyDown",
789                                   "OnKeyPress",
790                                   "OnKeyUp"                             
791                         };              
792                         Form myform = new Form ();
793                         myform.Visible = true;
794                         MyLabel l = new MyLabel ();                     
795                         myform.Controls.Add (l);
796                         l.KeyPressA ();
797                         
798                         Assert.AreEqual (EventsWanted, ArrayListToString (l.Results));
799                 }
800                 
801                 [Test]
802                 public void KeyUpEventsOrder ()
803                 {
804                         string[] EventsWanted = {
805                                 "OnHandleCreated",
806                                   "OnBindingContextChanged",
807                                   "OnBindingContextChanged",            
808                                   "OnKeyUp"             
809                         };              
810                         Form myform = new Form ();
811                         myform.Visible = true;
812                         MyLabel l = new MyLabel ();                     
813                         myform.Controls.Add (l);
814                         l.KeyUpA ();
815                         
816                         Assert.AreEqual (EventsWanted, ArrayListToString (l.Results));
817                 }
818                 
819                 [Test]
820                 public void TabStopChangedEventsOrder ()
821                 {
822                         string[] EventsWanted = {
823                                 "OnHandleCreated",
824                                   "OnBindingContextChanged",
825                                   "OnBindingContextChanged"
826                         };              
827                         Form myform = new Form ();
828                         myform.Visible = true;
829                         MyLabel l = new MyLabel ();                     
830                         myform.Controls.Add (l);
831                         l.TabStop = true;
832                         
833                         Assert.AreEqual (EventsWanted, ArrayListToString (l.Results));
834                 }
835                 
836                 [Test]
837                 public void TextAlignChangedEventsOrder ()
838                 {
839                         string[] EventsWanted = {
840                                 "OnHandleCreated",
841                                   "OnBindingContextChanged",
842                                   "OnBindingContextChanged",
843                                   "OnInvalidated"
844                         };              
845                         Form myform = new Form ();
846                         myform.Visible = true;
847                         MyLabel l = new MyLabel ();                     
848                         myform.Controls.Add (l);
849                         l.TextAlign = ContentAlignment.TopRight;
850                         
851                         Assert.AreEqual (EventsWanted, ArrayListToString (l.Results));
852                 }               
853         }      
854 }
855