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