| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027 |
- //
- // Copyright (c) 2005 Novell, Inc.
- //
- // Authors:
- // Hisham Mardam Bey ([email protected])
- //
- //
- using System;
- using NUnit.Framework;
- using System.Windows.Forms;
- using System.Drawing;
- using System.Collections;
- namespace MonoTests.System.Windows.Forms
- {
- [TestFixture]
- public class LabelTest2
- {
- [Test]
- [Category ("NotWorking")]
- public void PubPropTest ()
- {
- Label l = new Label ();
- // A
- Assert.AreEqual (false, l.AutoSize, "A1");
- l.AutoSize = true;
- Assert.AreEqual (true, l.AutoSize, "A2");
- l.AutoSize = false;
- Assert.AreEqual (false, l.AutoSize, "A3");
- // B
- Assert.AreEqual (null, l.BackgroundImage, "B1");
- l.BackgroundImage = Image.FromFile ("Test/System.Windows.Forms/bitmaps/a.png");
- Assert.IsNotNull (l.BackgroundImage, "B2");
- Bitmap bmp = (Bitmap)l.BackgroundImage;
- Assert.IsNotNull (bmp.GetPixel (0, 0), "B3");
- Assert.AreEqual (BorderStyle.None, l.BorderStyle, "B4");
- l.BorderStyle = BorderStyle.FixedSingle;
- Assert.AreEqual (BorderStyle.FixedSingle, l.BorderStyle, "B5");
- l.BorderStyle = BorderStyle.Fixed3D;
- Assert.AreEqual (BorderStyle.Fixed3D, l.BorderStyle, "B6");
- l.BorderStyle = BorderStyle.None;
- Assert.AreEqual (BorderStyle.None, l.BorderStyle, "B7");
- // C
- string name = l.CompanyName;
- if (!name.Equals("Mono Project, Novell, Inc.") && !name.Equals("Microsoft Corporation")) {
- Assert.Fail("CompanyName property does not match any accepted value - C1");
- }
- // F
- Assert.AreEqual (FlatStyle.Standard, l.FlatStyle, "F1");
- l.FlatStyle = FlatStyle.Flat;
- Assert.AreEqual (FlatStyle.Flat, l.FlatStyle, "F1");
- l.FlatStyle = FlatStyle.Popup;
- Assert.AreEqual (FlatStyle.Popup, l.FlatStyle, "F2");
- l.FlatStyle = FlatStyle.Standard;
- Assert.AreEqual (FlatStyle.Standard, l.FlatStyle, "F3");
- l.FlatStyle = FlatStyle.System;
- Assert.AreEqual (FlatStyle.System, l.FlatStyle, "F4");
- // I
- Assert.AreEqual (ContentAlignment.MiddleCenter, l.ImageAlign, "I1");
- l.ImageAlign = ContentAlignment.TopLeft;
- Assert.AreEqual (ContentAlignment.TopLeft, l.ImageAlign, "I2");
- l.ImageAlign = ContentAlignment.TopCenter;
- Assert.AreEqual (ContentAlignment.TopCenter, l.ImageAlign, "I3");
- l.ImageAlign = ContentAlignment.TopRight;
- Assert.AreEqual (ContentAlignment.TopRight, l.ImageAlign, "I4");
- l.ImageAlign = ContentAlignment.MiddleLeft;
- Assert.AreEqual (ContentAlignment.MiddleLeft, l.ImageAlign, "I5");
- l.ImageAlign = ContentAlignment.MiddleCenter;
- Assert.AreEqual (ContentAlignment.MiddleCenter, l.ImageAlign, "I6");
- l.ImageAlign = ContentAlignment.MiddleRight;
- Assert.AreEqual (ContentAlignment.MiddleRight, l.ImageAlign, "I7");
- l.ImageAlign = ContentAlignment.BottomLeft;
- Assert.AreEqual (ContentAlignment.BottomLeft, l.ImageAlign, "I8");
- l.ImageAlign = ContentAlignment.BottomCenter;
- Assert.AreEqual (ContentAlignment.BottomCenter, l.ImageAlign, "I9");
- l.ImageAlign = ContentAlignment.BottomRight;
- Assert.AreEqual (ContentAlignment.BottomRight, l.ImageAlign, "I10");
- Assert.AreEqual (-1, l.ImageIndex, "I11");
- Assert.AreEqual (null, l.ImageList, "I12");
- Assert.AreEqual (null, l.Image, "I13");
- l.Image = Image.FromFile ("Test/System.Windows.Forms/bitmaps/a.png");
- Assert.IsNotNull (l.Image, "I14");
- bmp = (Bitmap)l.Image;
- Assert.IsNotNull (bmp.GetPixel (0, 0), "I15");
- ImageList il = new ImageList ();
- il.ColorDepth = ColorDepth.Depth32Bit;
- il.ImageSize = new Size (15, 15);
- il.Images.Add (Image.FromFile ("Test/System.Windows.Forms/bitmaps/a.png"));
- l.ImageList = il;
- l.ImageIndex = 0;
- Assert.AreEqual (0, l.ImageIndex, "I16");
- Assert.IsNotNull (l.ImageList, "I17");
- // PreferredHeight
- // PregerredWidth
- // RenderTransparent
- //
- // T
- // Assert.AreEqual (false, l.TabStop, "T1");
- Assert.AreEqual (ContentAlignment.TopLeft, l.TextAlign, "T2");
- // U
- Assert.AreEqual (true, l.UseMnemonic, "U1");
- l.UseMnemonic = false;
- Assert.AreEqual (false, l.UseMnemonic, "U2");
- }
- [Test]
- public void LabelEqualsTest ()
- {
- Label s1 = new Label ();
- Label s2 = new Label ();
- s1.Text = "abc";
- s2.Text = "abc";
- Assert.AreEqual (false, s1.Equals (s2), "E1");
- Assert.AreEqual (true, s1.Equals (s1), "E2");
- }
- [Test]
- public void LabelScaleTest ()
- {
- Label r1 = new Label ();
- r1.Width = 40;
- r1.Height = 20 ;
- r1.Scale (2);
- Assert.AreEqual (80, r1.Width, "W1");
- Assert.AreEqual (40, r1.Height, "H1");
- }
- [Test]
- public void PubMethodTest ()
- {
- Label l = new Label ();
- l.Text = "My Label";
- Assert.AreEqual ("System.Windows.Forms.Label, Text: My Label", l.ToString (), "T1");
- }
- }
- [TestFixture]
- public class LabelEventTest
- {
- static bool eventhandled = false;
- public void Label_EventHandler (object sender,EventArgs e)
- {
- eventhandled = true;
- }
- public void Label_KeyDownEventHandler (object sender, KeyEventArgs e)
- {
- eventhandled = true;
- }
- [Test]
- public void AutoSizeChangedChangedTest ()
- {
- Form myform = new Form ();
- myform.Visible = true;
- Label l = new Label ();
- l.Visible = true;
- myform.Controls.Add (l);
- l.AutoSizeChanged += new EventHandler (Label_EventHandler);
- l.AutoSize = true;
- Assert.AreEqual (true, eventhandled, "B4");
- eventhandled = false;
- myform.Dispose();
- }
- [Test]
- public void BackgroundImageChangedTest ()
- {
- Form myform = new Form ();
- myform.Visible = true;
- Label l = new Label ();
- l.Visible = true;
- myform.Controls.Add (l);
- l.BackgroundImageChanged += new EventHandler (Label_EventHandler);
- l.BackgroundImage = Image.FromFile ("Test/System.Windows.Forms/bitmaps/a.png");
- Assert.AreEqual (true, eventhandled, "B4");
- eventhandled = false;
- myform.Dispose();
- }
- [Test]
- public void ImeModeChangedTest ()
- {
- Form myform = new Form ();
- myform.Visible = true;
- Label l = new Label ();
- l.Visible = true;
- myform.Controls.Add (l);
- l.ImeModeChanged += new EventHandler (Label_EventHandler);
- l.ImeMode = ImeMode.Katakana;
- Assert.AreEqual (true, eventhandled, "I16");
- eventhandled = false;
- myform.Dispose();
- }
- [Test]
- public void KeyDownTest ()
- {
- Form myform = new Form ();
- myform.Visible = true;
- MyLabel l = new MyLabel ();
- l.Visible = true;
- myform.Controls.Add (l);
- l.KeyDown += new KeyEventHandler (Label_KeyDownEventHandler);
- l.KeyPressA ();
- Assert.AreEqual (true, eventhandled, "K1");
- eventhandled = false;
- myform.Dispose();
- }
- [Test]
- public void TabStopChangedTest ()
- {
- Form myform = new Form ();
- myform.Visible = true;
- Label l = new Label ();
- l.Visible = true;
- myform.Controls.Add (l);
- l.TabStopChanged += new EventHandler (Label_EventHandler);
- l.TabStop = true;
- Assert.AreEqual (true, eventhandled, "T3");
- eventhandled = false;
- myform.Dispose();
- }
- [Test]
- public void TextAlignChangedTest ()
- {
- Form myform = new Form ();
- myform.Visible = true;
- Label l = new Label ();
- l.Visible = true;
- myform.Controls.Add (l);
- l.TextAlignChanged += new EventHandler (Label_EventHandler);
- l.TextAlign = ContentAlignment.TopRight;
- Assert.AreEqual (true, eventhandled, "T4");
- eventhandled = false;
- myform.Dispose();
- }
- }
- public class MyLabelInvalidate : MyLabel
- {
- //protected ArrayList results = new ArrayList ();
- public MyLabelInvalidate () : base ()
- {}
- protected override void OnInvalidated (InvalidateEventArgs e)
- {
- base.OnInvalidated (e);
- string res = (string)results [results.Count - 1];
- results [results.Count - 1 ] = string.Concat (res, "," + e.InvalidRect.ToString ());
- //results.Add ("OnInvalidate," + e.InvalidRect.ToString ());
- }
- //public ArrayList Results {
- // get { return results; }
- //}
- }
- public class MyLabel : Label
- {
- protected ArrayList results = new ArrayList ();
- public MyLabel () : base ()
- { }
- protected override void OnAutoSizeChanged (EventArgs e)
- {
- results.Add ("OnAutoSizeChanged");
- base.OnAutoSizeChanged (e);
- }
- protected override void OnBackgroundImageChanged (EventArgs e)
- {
- results.Add ("OnBackgroundImageChanged");
- base.OnBackgroundImageChanged (e);
- }
- protected override void OnImeModeChanged (EventArgs e)
- {
- results.Add ("OnImeModeChanged");
- base.OnImeModeChanged (e);
- }
- protected override void OnKeyDown (KeyEventArgs e)
- {
- results.Add ("OnKeyDown,"+(char)e.KeyValue);
- base.OnKeyDown (e);
- }
- protected override void OnKeyPress (KeyPressEventArgs e)
- {
- results.Add ("OnKeyPress,"+e.KeyChar.ToString ());
- base.OnKeyPress (e);
- }
- protected override void OnKeyUp (KeyEventArgs e)
- {
- results.Add ("OnKeyUp,"+(char)e.KeyValue);
- base.OnKeyUp (e);
- }
- protected override void OnHandleCreated (EventArgs e)
- {
- results.Add ("OnHandleCreated");
- base.OnHandleCreated (e);
- }
- protected override void OnBindingContextChanged (EventArgs e)
- {
- results.Add ("OnBindingContextChanged");
- base.OnBindingContextChanged (e);
- }
- protected override void OnInvalidated (InvalidateEventArgs e)
- {
- results.Add("OnInvalidated");
- base.OnInvalidated (e);
- }
- protected override void OnResize (EventArgs e)
- {
- results.Add("OnResize");
- base.OnResize (e);
- }
- protected override void OnSizeChanged (EventArgs e)
- {
- results.Add("OnSizeChanged");
- base.OnSizeChanged (e);
- }
- protected override void OnLayout (LayoutEventArgs e)
- {
- results.Add("OnLayout");
- base.OnLayout (e);
- }
- protected override void OnVisibleChanged (EventArgs e)
- {
- results.Add("OnVisibleChanged");
- base.OnVisibleChanged (e);
- }
- protected override void OnPaint (PaintEventArgs e)
- {
- results.Add("OnPaint");
- base.OnPaint (e);
- }
- public void KeyPressA()
- {
- Message m;
- m = new Message();
- m.Msg = (int)WndMsg.WM_KEYDOWN;
- m.HWnd = this.Handle;
- m.WParam = (IntPtr)0x41;
- m.LParam = (IntPtr)0x1e0001;
- this.WndProc(ref m);
- m.Msg = (int)WndMsg.WM_CHAR;
- m.HWnd = this.Handle;
- m.WParam = (IntPtr)0x61;
- m.LParam = (IntPtr)0x1e0001;
- this.WndProc(ref m);
- m.Msg = (int)WndMsg.WM_KEYUP;
- m.HWnd = this.Handle;
- m.WParam = (IntPtr)0x41;
- m.LParam = (IntPtr)unchecked((int)0xC01e0001);
- this.WndProc(ref m);
- }
- public void KeyDownA()
- {
- Message m;
- m = new Message();
- m.Msg = (int)WndMsg.WM_KEYDOWN;
- m.HWnd = this.Handle;
- m.WParam = (IntPtr)0x41;
- m.LParam = (IntPtr)0x1e0001;
- this.WndProc(ref m);
- m.Msg = (int)WndMsg.WM_CHAR;
- m.HWnd = this.Handle;
- m.WParam = (IntPtr)0x61;
- m.LParam = (IntPtr)0x1e0001;
- this.WndProc(ref m);
- }
- public void KeyUpA()
- {
- Message m;
- m = new Message();
- m.Msg = (int)WndMsg.WM_KEYUP;
- m.HWnd = this.Handle;
- m.WParam = (IntPtr)0x41;
- m.LParam = (IntPtr)unchecked((int)0xC01e0001);
- this.WndProc(ref m);
- }
- public ArrayList Results {
- get { return results; }
- }
- }
- [TestFixture]
- [Ignore("Comparisons too strict")]
- public class LabelTestEventsOrder
- {
- public string [] ArrayListToString (ArrayList arrlist)
- {
- string [] retval = new string [arrlist.Count];
- for (int i = 0; i < arrlist.Count; i++)
- retval[i] = (string)arrlist[i];
- return retval;
- }
- private void OrderedAssert(string[] wanted, ArrayList found) {
- int last_target;
- bool seen;
- last_target = 0;
- for (int i = 0; i < wanted.Length; i++) {
- seen = false;
- for (int j = last_target; j < found.Count; j++) {
- if (wanted[i] == (string)found[j]) {
- seen = true;
- last_target = j + 1;
- break;
- }
- }
- if (!seen) {
- Console.WriteLine("Needed {0}", wanted[i]);
- }
- }
- }
- public void PrintList(string name, ArrayList list) {
- Console.WriteLine("{0}", name);
- for (int i = 0; i < list.Count; i++) {
- Console.WriteLine(" {0}", list[i]);
- }
- Console.WriteLine("");
- }
- [Test]
- public void CreateEventsOrder ()
- {
- string[] EventsWanted = {
- "OnHandleCreated",
- "OnBindingContextChanged",
- "OnBindingContextChanged"
- };
- Form myform = new Form ();
- myform.Visible = true;
- MyLabel l = new MyLabel ();
- myform.Controls.Add (l);
- Assert.AreEqual (EventsWanted, ArrayListToString (l.Results));
- myform.Dispose();
- }
- [Test]
- public void SizeChangedEventsOrder ()
- {
- string[] EventsWanted = {
- "OnHandleCreated",
- "OnBindingContextChanged",
- "OnBindingContextChanged",
- "OnSizeChanged",
- "OnResize",
- "OnInvalidated",
- "OnLayout"
- };
- Form myform = new Form ();
- myform.Visible = true;
- MyLabel l = new MyLabel ();
- myform.Controls.Add (l);
- l.Size = new Size (150, 20);
- Assert.AreEqual (EventsWanted, ArrayListToString (l.Results));
- myform.Dispose();
- }
- [Test]
- public void AutoSizeChangedEventsOrder ()
- {
- string[] EventsWanted = {
- "OnHandleCreated",
- "OnBindingContextChanged",
- "OnBindingContextChanged",
- "OnSizeChanged",
- "OnResize",
- "OnInvalidated",
- "OnLayout",
- "OnAutoSizeChanged"
- };
- Form myform = new Form ();
- myform.Visible = true;
- MyLabel l = new MyLabel ();
- myform.Controls.Add (l);
- l.AutoSize = true;
- Assert.AreEqual (EventsWanted, ArrayListToString (l.Results));
- myform.Dispose();
- }
- [Test]
- public void BackgroundImageChangedEventsOrder ()
- {
- string[] EventsWanted = {
- "OnHandleCreated",
- "OnBindingContextChanged",
- "OnBindingContextChanged",
- "OnBackgroundImageChanged",
- "OnInvalidated"
- };
- Form myform = new Form ();
- myform.Visible = true;
- MyLabel l = new MyLabel ();
- myform.Controls.Add (l);
- l.BackgroundImage = Image.FromFile ("Test/System.Windows.Forms/bitmaps/a.png");
- Assert.AreEqual (EventsWanted, ArrayListToString (l.Results));
- myform.Dispose();
- }
- [Test]
- public void ImeModeChangedChangedEventsOrder ()
- {
- string[] EventsWanted = {
- "OnHandleCreated",
- "OnBindingContextChanged",
- "OnBindingContextChanged",
- "OnImeModeChanged"
- };
- Form myform = new Form ();
- myform.Visible = true;
- MyLabel l = new MyLabel ();
- myform.Controls.Add (l);
- l.ImeMode = ImeMode.Katakana;
- Assert.AreEqual (EventsWanted, ArrayListToString (l.Results));
- myform.Dispose();
- }
- [Test]
- public void KeyPressEventsOrder ()
- {
- string[] EventsWanted = {
- "OnHandleCreated",
- "OnBindingContextChanged",
- "OnBindingContextChanged",
- "OnKeyDown,A",
- "OnKeyPress,a",
- "OnKeyUp,A"
- };
- Form myform = new Form ();
- myform.Visible = true;
- MyLabel l = new MyLabel ();
- myform.Controls.Add (l);
- l.KeyPressA ();
- Assert.AreEqual (EventsWanted, ArrayListToString (l.Results));
- myform.Dispose();
- }
- [Test]
- public void TabStopChangedEventsOrder ()
- {
- string[] EventsWanted = {
- "OnHandleCreated",
- "OnBindingContextChanged",
- "OnBindingContextChanged"
- };
- Form myform = new Form ();
- myform.Visible = true;
- MyLabel l = new MyLabel ();
- myform.Controls.Add (l);
- l.TabStop = true;
- PrintList("TabStopChanged", l.Results);
- Assert.AreEqual (EventsWanted, ArrayListToString (l.Results));
- myform.Dispose();
- }
- [Test]
- public void TextAlignChangedEventsOrder ()
- {
- string[] EventsWanted = {
- "OnHandleCreated",
- "OnBindingContextChanged",
- "OnBindingContextChanged",
- "OnInvalidated"
- };
- Form myform = new Form ();
- myform.Visible = true;
- MyLabel l = new MyLabel ();
- myform.Controls.Add (l);
- l.TextAlign = ContentAlignment.TopRight;
- Assert.AreEqual (EventsWanted, ArrayListToString (l.Results));
- myform.Dispose();
- }
- [Test]
- public void InvalidateEventsOrder ()
- {
- Rectangle rect = new Rectangle (new Point (0,0), new Size (2, 2));
- Form myform = new Form ();
- myform.Visible = true;
- MyLabelInvalidate l = new MyLabelInvalidate ();
- myform.Controls.Add (l);
- l.TextAlign = ContentAlignment.TopRight;
- string [] EventsWanted = {
- "OnHandleCreated",
- "OnBindingContextChanged",
- "OnBindingContextChanged",
- "OnInvalidated,{X=0,Y=0,Width="+l.Size.Width+",Height="+l.Size.Height+"}",
- "OnInvalidated," + rect.ToString ()
- };
- l.Invalidate (rect);
- Assert.AreEqual (EventsWanted, ArrayListToString (l.Results));
- myform.Dispose();
- }
- [Test]
- public void PaintEventsOrder ()
- {
- string[] EventsWanted = {
- "OnHandleCreated",
- "OnBindingContextChanged",
- "OnBindingContextChanged",
- "OnInvalidated",
- "OnInvalidated",
- "OnPaint"
- };
- Form myform = new Form ();
- myform.Visible = true;
- MyLabel l = new MyLabel ();
- myform.Controls.Add (l);
- l.TextAlign = ContentAlignment.TopRight;
- l.Refresh ();
- Assert.AreEqual (EventsWanted, ArrayListToString (l.Results));
- myform.Dispose();
- }
- }
- public class MyLabel2 : Label
- {
- protected ArrayList results = new ArrayList ();
- public MyLabel2 () : base ()
- {
- this.AutoSizeChanged += new EventHandler (AutoSizeChanged_Handler);
- this.HandleCreated += new EventHandler (HandleCreated_Handler);
- this.BindingContextChanged += new EventHandler (BindingContextChanged_Handler);
- this.BackgroundImageChanged += new EventHandler (BackgroundImageChanged_Handler);
- this.ImeModeChanged += new EventHandler (ImeModeChanged_Handler);
- this.KeyDown += new KeyEventHandler (KeyDown_Handler);
- this.KeyPress += new KeyPressEventHandler (KeyPress_Handler);
- this.KeyUp += new KeyEventHandler (KeyUp_Handler);
- this.Invalidated += new InvalidateEventHandler (Invalidated_Handler);
- this.Resize += new EventHandler (Resize_Handler);
- this.SizeChanged += new EventHandler (SizeChanged_Handler);
- this.Layout += new LayoutEventHandler (Layout_Handler);
- this.VisibleChanged += new EventHandler (VisibleChanged_Handler);
- this.Paint += new PaintEventHandler (Paint_Handler);
- }
- protected void AutoSizeChanged_Handler (object sender, EventArgs e)
- {
- results.Add ("AutoSizeChanged");
- }
- protected void BackgroundImageChanged_Handler (object sender, EventArgs e)
- {
- results.Add ("BackgroundImageChanged");
- }
- protected void ImeModeChanged_Handler (object sender, EventArgs e)
- {
- results.Add ("ImeModeChanged");
- }
- protected void KeyDown_Handler (object sender, KeyEventArgs e)
- {
- results.Add ("KeyDown,"+(char)e.KeyValue);
- }
- protected void KeyPress_Handler (object sender, KeyPressEventArgs e)
- {
- results.Add ("KeyPress,"+e.KeyChar.ToString ());
- }
- protected void KeyUp_Handler (object sender, KeyEventArgs e)
- {
- results.Add ("KeyUp,"+(char)e.KeyValue);
- }
- protected void HandleCreated_Handler (object sender, EventArgs e)
- {
- results.Add ("HandleCreated");
- }
- protected void BindingContextChanged_Handler (object sender, EventArgs e)
- {
- results.Add ("BindingContextChanged");
- }
- protected void Invalidated_Handler (object sender, InvalidateEventArgs e)
- {
- results.Add("Invalidated");
- }
- protected void Resize_Handler (object sender, EventArgs e)
- {
- results.Add("Resize");
- }
- protected void SizeChanged_Handler (object sender, EventArgs e)
- {
- results.Add("SizeChanged");
- }
- protected void Layout_Handler (object sender, LayoutEventArgs e)
- {
- results.Add("Layout");
- }
- protected void VisibleChanged_Handler (object sender, EventArgs e)
- {
- results.Add("VisibleChanged");
- }
- protected void Paint_Handler (object sender, PaintEventArgs e)
- {
- results.Add("Paint");
- }
- public void KeyPressA()
- {
- Message m;
- m = new Message();
- m.Msg = (int)WndMsg.WM_KEYDOWN;
- m.HWnd = this.Handle;
- m.WParam = (IntPtr)0x41;
- m.LParam = (IntPtr)0x1e0001;
- this.WndProc(ref m);
- m.Msg = (int)WndMsg.WM_CHAR;
- m.HWnd = this.Handle;
- m.WParam = (IntPtr)0x61;
- m.LParam = (IntPtr)0x1e0001;
- this.WndProc(ref m);
- m.Msg = (int)WndMsg.WM_KEYUP;
- m.HWnd = this.Handle;
- m.WParam = (IntPtr)0x41;
- m.LParam = (IntPtr)unchecked((int)0xC01e0001);
- this.WndProc(ref m);
- }
- public void KeyDownA()
- {
- Message m;
- m = new Message();
- m.Msg = (int)WndMsg.WM_KEYDOWN;
- m.HWnd = this.Handle;
- m.WParam = (IntPtr)0x41;
- m.LParam = (IntPtr)0x1e0001;
- this.WndProc(ref m);
- m.Msg = (int)WndMsg.WM_CHAR;
- m.HWnd = this.Handle;
- m.WParam = (IntPtr)0x61;
- m.LParam = (IntPtr)0x1e0001;
- this.WndProc(ref m);
- }
- public void KeyUpA()
- {
- Message m;
- m = new Message();
- m.Msg = (int)WndMsg.WM_KEYUP;
- m.HWnd = this.Handle;
- m.WParam = (IntPtr)0x41;
- m.LParam = (IntPtr)unchecked((int)0xC01e0001);
- this.WndProc(ref m);
- }
- public ArrayList Results {
- get { return results; }
- }
- }
- [TestFixture]
- [Ignore("Comparisons too strict")]
- public class LabelTestEventsOrder2
- {
- public string [] ArrayListToString (ArrayList arrlist)
- {
- string [] retval = new string [arrlist.Count];
- for (int i = 0; i < arrlist.Count; i++)
- retval[i] = (string)arrlist[i];
- return retval;
- }
- [Test]
- public void CreateEventsOrder ()
- {
- string[] EventsWanted = {
- "HandleCreated",
- "BindingContextChanged",
- "BindingContextChanged"
- };
- Form myform = new Form ();
- myform.Visible = true;
- MyLabel2 l = new MyLabel2 ();
- myform.Controls.Add (l);
- Assert.AreEqual (EventsWanted, ArrayListToString (l.Results));
- myform.Dispose();
- }
- [Test]
- public void SizeChangedEventsOrder ()
- {
- string[] EventsWanted = {
- "HandleCreated",
- "BindingContextChanged",
- "BindingContextChanged",
- "Invalidated",
- "Layout",
- "Resize",
- "SizeChanged"
- };
- Form myform = new Form ();
- myform.Visible = true;
- MyLabel2 l = new MyLabel2 ();
- myform.Controls.Add (l);
- l.Size = new Size (150, 20);
- Assert.AreEqual (EventsWanted, ArrayListToString (l.Results));
- myform.Dispose();
- }
- [Test]
- public void AutoSizeChangedEventsOrder ()
- {
- string[] EventsWanted = {
- "HandleCreated",
- "BindingContextChanged",
- "BindingContextChanged",
- "Invalidated",
- "Layout",
- "Resize",
- "SizeChanged",
- "AutoSizeChanged"
- };
- Form myform = new Form ();
- myform.Visible = true;
- MyLabel2 l = new MyLabel2 ();
- myform.Controls.Add (l);
- l.AutoSize = true;
- Assert.AreEqual (EventsWanted, ArrayListToString (l.Results));
- myform.Dispose();
- }
- [Test]
- public void BackgroundImageChangedEventsOrder ()
- {
- string[] EventsWanted = {
- "HandleCreated",
- "BindingContextChanged",
- "BindingContextChanged",
- "Invalidated",
- "BackgroundImageChanged"
- };
- Form myform = new Form ();
- myform.Visible = true;
- MyLabel2 l = new MyLabel2 ();
- myform.Controls.Add (l);
- l.BackgroundImage = Image.FromFile ("Test/System.Windows.Forms/bitmaps/a.png");
- Assert.AreEqual (EventsWanted, ArrayListToString (l.Results));
- myform.Dispose();
- }
- [Test]
- public void ImeModeChangedChangedEventsOrder ()
- {
- string[] EventsWanted = {
- "HandleCreated",
- "BindingContextChanged",
- "BindingContextChanged",
- "ImeModeChanged"
- };
- Form myform = new Form ();
- myform.Visible = true;
- MyLabel2 l = new MyLabel2 ();
- myform.Controls.Add (l);
- l.ImeMode = ImeMode.Katakana;
- Assert.AreEqual (EventsWanted, ArrayListToString (l.Results));
- myform.Dispose();
- }
- [Test]
- public void KeyPressEventsOrder ()
- {
- string[] EventsWanted = {
- "HandleCreated",
- "BindingContextChanged",
- "BindingContextChanged",
- "KeyDown,A",
- "KeyPress,a",
- "KeyUp,A"
- };
- Form myform = new Form ();
- myform.Visible = true;
- MyLabel2 l = new MyLabel2 ();
- myform.Controls.Add (l);
- l.KeyPressA ();
- Assert.AreEqual (EventsWanted, ArrayListToString (l.Results));
- myform.Dispose();
- }
- [Test]
- public void TabStopChangedEventsOrder ()
- {
- string[] EventsWanted = {
- "HandleCreated",
- "BindingContextChanged",
- "BindingContextChanged"
- };
- Form myform = new Form ();
- myform.Visible = true;
- MyLabel2 l = new MyLabel2 ();
- myform.Controls.Add (l);
- l.TabStop = true;
- Assert.AreEqual (EventsWanted, ArrayListToString (l.Results));
- myform.Dispose();
- }
- [Test]
- public void TextAlignChangedEventsOrder ()
- {
- string[] EventsWanted = {
- "HandleCreated",
- "BindingContextChanged",
- "BindingContextChanged",
- "Invalidated"
- };
- Form myform = new Form ();
- myform.Visible = true;
- MyLabel2 l = new MyLabel2 ();
- myform.Controls.Add (l);
- l.TextAlign = ContentAlignment.TopRight;
- Assert.AreEqual (EventsWanted, ArrayListToString (l.Results));
- myform.Dispose();
- }
- [Test]
- public void PaintEventsOrder ()
- {
- string[] EventsWanted = {
- "HandleCreated",
- "BindingContextChanged",
- "BindingContextChanged",
- "Invalidated",
- "Invalidated",
- "Paint"
- };
- Form myform = new Form ();
- myform.Visible = true;
- MyLabel2 l = new MyLabel2 ();
- myform.Controls.Add (l);
- l.TextAlign = ContentAlignment.TopRight;
- l.Refresh ();
- Assert.AreEqual (EventsWanted, ArrayListToString (l.Results));
- myform.Dispose();
- }
- }
- }
|