| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460 |
- //
- // Copyright (c) 2005 Novell, Inc.
- //
- // Authors:
- // Hisham Mardam Bey ([email protected])
- // Ritvik Mayank ([email protected])
- //
- //
- using System;
- using NUnit.Framework;
- using System.Windows.Forms;
- using System.Drawing;
- using System.Collections;
- namespace MonoTests.System.Windows.Forms
- {
- public class MyScrollBar : HScrollBar
- {
- private ArrayList results = new ArrayList ();
- public MyScrollBar () : base ()
- {}
- protected override void OnBackColorChanged (EventArgs e)
- {
- results.Add ("OnBackColorChanged");
- base.OnBackColorChanged (e);
- }
- protected override void OnBackgroundImageChanged (EventArgs e)
- {
- results.Add ("OnBackgroundImageChanged");
- base.OnBackgroundImageChanged (e);
- }
- protected override void OnClick (EventArgs e)
- {
- results.Add ("OnClick");
- base.OnClick (e);
- }
- protected override void OnDoubleClick (EventArgs e)
- {
- results.Add ("OnDoubleClick");
- base.OnDoubleClick (e);
- }
- protected override void OnFontChanged (EventArgs e)
- {
- results.Add ("OnFontChanged");
- base.OnFontChanged (e);
- }
- protected override void OnForeColorChanged (EventArgs e)
- {
- results.Add ("OnForeColorChanged");
- base.OnForeColorChanged (e);
- }
- protected override void OnImeModeChanged (EventArgs e)
- {
- results.Add ("OnImeModeChanged");
- base.OnImeModeChanged (e);
- }
- protected override void OnMouseDown (MouseEventArgs e)
- {
- results.Add ("OnMouseDown");
- base.OnMouseDown (e);
- }
- protected override void OnMouseMove (MouseEventArgs e)
- {
- results.Add ("OnMouseMove");
- base.OnMouseMove (e);
- }
- protected override void OnMouseEnter (EventArgs e)
- {
- results.Add ("OnMouseEnter");
- base.OnMouseEnter (e);
- }
- protected override void OnMouseLeave (EventArgs e)
- {
- results.Add ("OnMouseLeave");
- base.OnMouseLeave (e);
- }
- protected override void OnMouseHover (EventArgs e)
- {
- results.Add ("OnMouseHover");
- base.OnMouseHover (e);
- }
- protected override void OnMouseUp (MouseEventArgs e)
- {
- results.Add ("OnMouseUp");
- base.OnMouseUp (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 OnScroll (ScrollEventArgs e)
- {
- results.Add("OnScroll");
- base.OnScroll (e);
- }
- protected override void OnTextChanged (EventArgs e)
- {
- results.Add("OnTextChanged");
- base.OnTextChanged (e);
- }
- protected override void OnValueChanged (EventArgs e)
- {
- results.Add("OnValueChanged");
- base.OnValueChanged (e);
- }
- protected override void OnPaint (PaintEventArgs e)
- {
- results.Add("OnPaint");
- base.OnPaint (e);
- }
- public ArrayList Results {
- get { return results; }
- }
- public void MoveMouse ()
- {
- Message m;
- m = new Message ();
- m.Msg = (int)WndMsg.WM_NCHITTEST;
- m.HWnd = this.Handle;
- m.WParam = (IntPtr)0x0;
- m.LParam = (IntPtr)0x1c604ea;
- this.WndProc(ref m);
- m.Msg = (int)WndMsg.WM_SETCURSOR;
- m.HWnd = this.Handle;
- m.WParam = (IntPtr)0x100448;
- m.LParam = (IntPtr)0x2000001;
- this.WndProc(ref m);
- m.Msg = (int)WndMsg.WM_MOUSEFIRST;
- m.HWnd = this.Handle;
- m.WParam = (IntPtr)0x0;
- m.LParam = (IntPtr)0x14000b;
- this.WndProc(ref m);
- m.Msg = (int)WndMsg.WM_MOUSEHOVER;
- m.HWnd = this.Handle;
- m.WParam = (IntPtr)0x0;
- m.LParam = (IntPtr)0x14000b;
- this.WndProc(ref m);
- }
- public void MouseClick()
- {
- Message m;
- m = new Message();
- m.Msg = (int)WndMsg.WM_LBUTTONDOWN;
- m.HWnd = this.Handle;
- m.WParam = (IntPtr)0x01;
- m.LParam = (IntPtr)0x9004f;
- this.WndProc(ref m);
- m = new Message();
- m.Msg = (int)WndMsg.WM_LBUTTONUP;
- m.HWnd = this.Handle;
- m.WParam = (IntPtr)0x01;
- m.LParam = (IntPtr)0x9004f;
- this.WndProc(ref m);
- }
- public void MouseDoubleClick ()
- {
- MouseClick ();
- MouseClick ();
- }
- public void MouseRightDown()
- {
- Message m;
- m = new Message();
- m.Msg = (int)WndMsg.WM_RBUTTONDOWN;
- m.HWnd = this.Handle;
- m.WParam = (IntPtr)0x01;
- m.LParam = (IntPtr)0x9004f;
- this.WndProc(ref m);
- }
- public void MouseRightUp()
- {
- Message m;
- m = new Message();
- m.Msg = (int)WndMsg.WM_RBUTTONUP;
- m.HWnd = this.Handle;
- m.WParam = (IntPtr)0x01;
- m.LParam = (IntPtr)0x9004f;
- this.WndProc(ref m);
- }
- public void ScrollNow ()
- {
- Message m;
- m = new Message ();
- m.Msg = 8468;
- m.HWnd = this.Handle;
- m.WParam = (IntPtr)0x1;
- m.LParam = (IntPtr)0x1a051a;
- this.WndProc(ref m);
- m.Msg = 233;
- m.HWnd = this.Handle;
- m.WParam = (IntPtr)0x1;
- m.LParam = (IntPtr)0x12eb34;
- this.WndProc(ref m);
- }
- }
- [TestFixture]
- public class ScrollBarTest
- {
- [Test]
- [Category ("NotWorking")]
- public void PubPropTest ()
- {
- MyScrollBar myscrlbar = new MyScrollBar ();
- // B
- myscrlbar.BackColor = Color.Red;
- Assert.AreEqual (255, myscrlbar.BackColor.R, "B2");
- myscrlbar.BackgroundImage = Image.FromFile ("Test/System.Windows.Forms/bitmaps/a.png");
- Assert.AreEqual (16, myscrlbar.BackgroundImage.Height, "B3");
- // F
- Assert.AreEqual ("ControlText", myscrlbar.ForeColor.Name, "F1");
- // I
- //Assert.AreEqual (ImeMode.Disable, myscrlbar.ImeMode, "I1");
- // L
- Assert.AreEqual (10, myscrlbar.LargeChange, "L1");
- // M
- Assert.AreEqual (100, myscrlbar.Maximum, "M1");
- Assert.AreEqual (0, myscrlbar.Minimum, "M2");
- myscrlbar.Maximum = 300;
- myscrlbar.Minimum = 100;
- Assert.AreEqual (300, myscrlbar.Maximum, "M3");
- Assert.AreEqual (100, myscrlbar.Minimum, "M4");
- // S
- Assert.AreEqual (null, myscrlbar.Site, "S1");
- Assert.AreEqual (1, myscrlbar.SmallChange, "S2");
- myscrlbar.SmallChange = 10;
- Assert.AreEqual (10, myscrlbar.SmallChange, "S3");
- // T
- Assert.AreEqual (false, myscrlbar.TabStop, "T1");
- myscrlbar.TabStop = true;
- Assert.AreEqual (true, myscrlbar.TabStop, "T2");
- Assert.AreEqual ("", myscrlbar.Text, "T3");
- myscrlbar.Text = "MONO SCROLLBAR";
- Assert.AreEqual ("MONO SCROLLBAR", myscrlbar.Text, "T4");
- // V
- Assert.AreEqual (100, myscrlbar.Value, "V1");
- myscrlbar.Value = 150;
- Assert.AreEqual (150, myscrlbar.Value, "V2");
- }
- [Test]
- [ExpectedException (typeof (ArgumentException))]
- public void ExceptionValueTest ()
- {
- MyScrollBar myscrlbar = new MyScrollBar ();
- myscrlbar.Minimum = 10;
- myscrlbar.Maximum = 20;
- myscrlbar.Value = 9;
- myscrlbar.Value = 21;
- }
- [Test]
- [ExpectedException (typeof (ArgumentException))]
- public void ExceptionSmallChangeTest ()
- {
- MyScrollBar myscrlbar = new MyScrollBar ();
- myscrlbar.SmallChange = -1;
- }
- [Test]
- [ExpectedException (typeof (ArgumentException))]
- public void ExceptionLargeChangeTest ()
- {
- MyScrollBar myscrlbar = new MyScrollBar ();
- myscrlbar.LargeChange = -1;
- }
- [Test]
- public void PubMethodTest ()
- {
- MyScrollBar myscrlbar = new MyScrollBar ();
- myscrlbar.Text = "New HScrollBar";
- Assert.AreEqual ("MonoTests.System.Windows.Forms.MyScrollBar, Minimum: 0, Maximum: 100, Value: 0",
- myscrlbar.ToString (), "T5");
- }
- }
- [TestFixture]
- public class ScrollBarEventTest
- {
- static bool eventhandled = false;
- public void ScrollBar_EventHandler (object sender,EventArgs e)
- {
- eventhandled = true;
- }
- public void ScrollBarMouse_EventHandler (object sender,MouseEventArgs e)
- {
- eventhandled = true;
- }
- public void ScrollBarScroll_EventHandler (object sender,ScrollEventArgs e)
- {
- eventhandled = true;
- }
- public void ScrollBarPaint_EventHandler (object sender,PaintEventArgs e)
- {
- eventhandled = true;
- }
- [Test]
- public void BackColorChangedTest ()
- {
- Form myform = new Form ();
- myform.Visible = true;
- ScrollBar myHscrlbar = new HScrollBar ();
- myform.Controls.Add (myHscrlbar);
- myHscrlbar.BackColorChanged += new EventHandler (ScrollBar_EventHandler);
- myHscrlbar.BackColor = Color.Red;
- Assert.AreEqual (true, eventhandled, "B4");
- eventhandled = false;
- myform.Dispose ();
- }
- [Test]
- public void BackgroundImageChangedTest ()
- {
- Form myform = new Form ();
- myform.Visible = true;
- ScrollBar myHscrlbar = new HScrollBar ();
- myform.Controls.Add (myHscrlbar);
- myHscrlbar.BackgroundImageChanged += new EventHandler (ScrollBar_EventHandler);
- myHscrlbar.BackgroundImage = Image.FromFile ("Test/System.Windows.Forms/bitmaps/a.png");
- Assert.AreEqual (true, eventhandled, "B5");
- eventhandled = false;
- myform.Dispose ();
- }
- [Test]
- public void FontChangedTest ()
- {
- Form myform = new Form ();
- myform.Visible = true;
- ScrollBar myHscrlbar = new HScrollBar ();
- myform.Controls.Add (myHscrlbar);
- myHscrlbar.Font = new Font (FontFamily.GenericMonospace, 10);
- myHscrlbar.FontChanged += new EventHandler (ScrollBar_EventHandler);
- FontDialog myFontDialog = new FontDialog();
- myHscrlbar.Font = myFontDialog.Font;
- Assert.AreEqual (true, eventhandled, "F2");
- eventhandled = false;
- myform.Dispose ();
- }
- [Test]
- public void ForeColorChangedTest ()
- {
- Form myform = new Form ();
- myform.Visible = true;
- ScrollBar myHscrlbar = new HScrollBar ();
- myform.Controls.Add (myHscrlbar);
- myHscrlbar.ForeColorChanged += new EventHandler (ScrollBar_EventHandler);
- myHscrlbar.ForeColor = Color.Azure;
- Assert.AreEqual (true, eventhandled, "F3");
- eventhandled = false;
- myform.Dispose ();
- }
- [Test]
- public void ImeModehangedTest ()
- {
- Form myform = new Form ();
- myform.Visible = true;
- ScrollBar myHscrlbar = new HScrollBar ();
- myform.Controls.Add (myHscrlbar);
- myHscrlbar.ImeModeChanged += new EventHandler (ScrollBar_EventHandler);
- myHscrlbar.ImeMode = ImeMode.Katakana;
- Assert.AreEqual (true, eventhandled, "I2");
- eventhandled = false;
- myform.Dispose ();
- }
- [Test]
- public void MouseDownTest ()
- {
- Form myform = new Form ();
- myform.Visible = true;
- MyScrollBar myHscrlbar = new MyScrollBar ();
- myform.Controls.Add (myHscrlbar);
- myHscrlbar.MouseDown += new MouseEventHandler (ScrollBarMouse_EventHandler);
- myHscrlbar.MouseRightDown ();
- Assert.AreEqual (true, eventhandled, "M5");
- eventhandled = false;
- myform.Dispose ();
- }
- [Test]
- public void MouseMoveTest ()
- {
- Form myform = new Form ();
- myform.Visible = true;
- MyScrollBar myHscrlbar = new MyScrollBar ();
- myform.Controls.Add (myHscrlbar);
- myHscrlbar.MouseMove += new MouseEventHandler (ScrollBarMouse_EventHandler);
- myHscrlbar.MoveMouse ();
- Assert.AreEqual (true, eventhandled, "M6");
- eventhandled = false;
- myform.Dispose ();
- }
- [Test]
- public void MouseUpTest ()
- {
- Form myform = new Form ();
- myform.Visible = true;
- MyScrollBar myHscrlbar = new MyScrollBar ();
- myform.Controls.Add (myHscrlbar);
- myHscrlbar.MouseUp += new MouseEventHandler (ScrollBarMouse_EventHandler);
- myHscrlbar.MouseRightUp ();
- Assert.AreEqual (true, eventhandled, "M7");
- eventhandled = false;
- myform.Dispose ();
- }
- [Test]
- [Category ("NotWorking")]
- public void ScrollTest ()
- {
- Form myform = new Form ();
- myform.Visible = true;
- MyScrollBar myHscrlbar = new MyScrollBar ();
- myform.Controls.Add (myHscrlbar);
- myHscrlbar.Scroll += new ScrollEventHandler (ScrollBarScroll_EventHandler);
- myHscrlbar.ScrollNow ();
- Assert.AreEqual (true, eventhandled, "S4");
- eventhandled = false;
- myform.Dispose ();
- }
- [Test]
- public void TextChangedTest ()
- {
- Form myform = new Form ();
- myform.Visible = true;
- MyScrollBar myHscrlbar = new MyScrollBar ();
- myform.Controls.Add (myHscrlbar);
- myHscrlbar.TextChanged += new EventHandler (ScrollBar_EventHandler);
- myHscrlbar.Text = "foo";
- Assert.AreEqual (true, eventhandled, "T6");
- eventhandled = false;
- myform.Dispose ();
- }
- [Test]
- public void ValueChangeTest ()
- {
- Form myform = new Form ();
- myform.Visible = true;
- MyScrollBar myHscrlbar = new MyScrollBar ();
- myform.Controls.Add (myHscrlbar);
- myHscrlbar.Value = 40 ;
- myHscrlbar.ValueChanged += new EventHandler (ScrollBar_EventHandler);
- myHscrlbar.Value = 50 ;
- Assert.AreEqual (true, eventhandled, "V3");
- eventhandled = false;
- myform.Dispose ();
- }
- }
- public class MyHScrollBar : HScrollBar
- {
- public MyHScrollBar () : base ()
- {
- }
- public Size MyDefaultSize {
- get { return DefaultSize; }
- }
- public CreateParams MyCreateParams {
- get { return CreateParams; }
- }
- }
- [TestFixture]
- public class MyHScrollBarTest
- {
- [Test]
- public void ProtectedTest ()
- {
- MyHScrollBar msbar = new MyHScrollBar ();
- Assert.AreEqual (80, msbar.MyDefaultSize.Width, "D1");
- // this is environment dependent.
- //Assert.AreEqual (21, msbar.MyDefaultSize.Height, "D2");
- }
- }
- public class MyVScrollBar : VScrollBar
- {
- public MyVScrollBar () : base ()
- {
- }
- public Size MyDefaultSize {
- get { return DefaultSize; }
- }
- public CreateParams MyCreateParams {
- get { return CreateParams; }
- }
- }
- [TestFixture]
- public class MyVScrollBarTest
- {
- [Test]
- public void PubMethodTest ()
- {
- MyVScrollBar msbar = new MyVScrollBar ();
- Assert.AreEqual (RightToLeft.No, msbar.RightToLeft, "R1");
- }
- [Test]
- public void ProtMethodTest ()
- {
- MyVScrollBar msbar = new MyVScrollBar ();
- // This is environment dependent.
- //Assert.AreEqual (21, msbar.MyDefaultSize.Width, "D3");
- Assert.AreEqual (80, msbar.MyDefaultSize.Height, "D4");
- }
- }
- [TestFixture]
- [Ignore("Tests too strict")]
- public class HScrollBarTestEventsOrder
- {
- 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 = {
- "OnHandleCreated",
- "OnBindingContextChanged",
- "OnBindingContextChanged"
- };
- Form myform = new Form ();
- myform.Visible = true;
- MyScrollBar s = new MyScrollBar ();
- myform.Controls.Add (s);
- Assert.AreEqual (EventsWanted, ArrayListToString (s.Results));
- myform.Dispose ();
- }
- [Test]
- public void BackColorChangedEventsOrder ()
- {
- string[] EventsWanted = {
- "OnHandleCreated",
- "OnBindingContextChanged",
- "OnBindingContextChanged",
- "OnBackColorChanged",
- "OnInvalidated"
- };
- Form myform = new Form ();
- myform.Visible = true;
- MyScrollBar s = new MyScrollBar ();
- myform.Controls.Add (s);
- s.BackColor = Color.Aqua;
- Assert.AreEqual (EventsWanted, ArrayListToString (s.Results));
- myform.Dispose ();
- }
- [Test]
- public void BackgroundImageChangedEventsOrder ()
- {
- string[] EventsWanted = {
- "OnHandleCreated",
- "OnBindingContextChanged",
- "OnBindingContextChanged",
- "OnBackgroundImageChanged",
- "OnInvalidated"
- };
- Form myform = new Form ();
- myform.Visible = true;
- MyScrollBar s = new MyScrollBar ();
- myform.Controls.Add (s);
- s.BackgroundImage = Image.FromFile ("Test/System.Windows.Forms/bitmaps/a.png");
- Assert.AreEqual (EventsWanted, ArrayListToString (s.Results));
- myform.Dispose ();
- }
- [Test, Ignore ("Need to send proper Click / DoubleClick")]
- public void ClickEventsOrder ()
- {
- string[] EventsWanted = {
- "OnHandleCreated",
- "OnBindingContextChanged",
- "OnBindingContextChanged"
- };
- Form myform = new Form ();
- myform.Visible = true;
- MyScrollBar s = new MyScrollBar ();
- myform.Controls.Add (s);
- s.MouseClick ();
- Assert.AreEqual (EventsWanted, ArrayListToString (s.Results));
- myform.Dispose ();
- }
- [Test, Ignore ("Need to send proper Click / DoubleClick")]
- public void DoubleClickEventsOrder ()
- {
- string[] EventsWanted = {
- "OnHandleCreated",
- "OnBindingContextChanged",
- "OnBindingContextChanged"
- };
- Form myform = new Form ();
- myform.Visible = true;
- MyScrollBar s = new MyScrollBar ();
- myform.Controls.Add (s);
- s.MouseDoubleClick ();
- Assert.AreEqual (EventsWanted, ArrayListToString (s.Results));
- myform.Dispose ();
- }
- [Test]
- public void FontChangedEventsOrder ()
- {
- string[] EventsWanted = {
- "OnHandleCreated",
- "OnBindingContextChanged",
- "OnBindingContextChanged"
- };
- Form myform = new Form ();
- myform.Visible = true;
- MyScrollBar s = new MyScrollBar ();
- myform.Controls.Add (s);
- FontDialog myFontDialog = new FontDialog();
- s.Font = myFontDialog.Font;
- Assert.AreEqual (EventsWanted, ArrayListToString (s.Results));
- myform.Dispose ();
- }
- [Test]
- public void ForeColorChangedEventsOrder ()
- {
- string[] EventsWanted = {
- "OnHandleCreated",
- "OnBindingContextChanged",
- "OnBindingContextChanged",
- "OnForeColorChanged",
- "OnInvalidated"
- };
- Form myform = new Form ();
- myform.Visible = true;
- MyScrollBar s = new MyScrollBar ();
- myform.Controls.Add (s);
- s.ForeColor = Color.Aqua;
- Assert.AreEqual (EventsWanted, ArrayListToString (s.Results));
- myform.Dispose ();
- }
- [Test]
- public void ImeModeChangedChangedEventsOrder ()
- {
- string[] EventsWanted = {
- "OnHandleCreated",
- "OnBindingContextChanged",
- "OnBindingContextChanged",
- "OnImeModeChanged"
- };
- Form myform = new Form ();
- myform.Visible = true;
- MyScrollBar s = new MyScrollBar ();
- myform.Controls.Add (s);
- s.ImeMode = ImeMode.Katakana;
- Assert.AreEqual (EventsWanted, ArrayListToString (s.Results));
- myform.Dispose ();
- }
- [Test]
- public void MouseDownEventsOrder ()
- {
- string[] EventsWanted = {
- "OnHandleCreated",
- "OnBindingContextChanged",
- "OnBindingContextChanged",
- "OnMouseDown"
- };
- Form myform = new Form ();
- myform.Visible = true;
- MyScrollBar s = new MyScrollBar ();
- myform.Controls.Add (s);
- s.MouseRightDown ();
- Assert.AreEqual (EventsWanted, ArrayListToString (s.Results));
- myform.Dispose ();
- }
- [Test]
- public void MouseMoveEventsOrder ()
- {
- string[] EventsWanted = {
- "OnHandleCreated",
- "OnBindingContextChanged",
- "OnBindingContextChanged",
- "OnMouseMove",
- "OnMouseHover"
- };
- Form myform = new Form ();
- myform.Visible = true;
- MyScrollBar s = new MyScrollBar ();
- myform.Controls.Add (s);
- s.MoveMouse ();
- Assert.AreEqual (EventsWanted, ArrayListToString (s.Results));
- myform.Dispose ();
- }
- [Test]
- public void MouseUpEventsOrder ()
- {
- string[] EventsWanted = {
- "OnHandleCreated",
- "OnBindingContextChanged",
- "OnBindingContextChanged",
- "OnMouseUp"
- };
- Form myform = new Form ();
- myform.Visible = true;
- MyScrollBar s = new MyScrollBar ();
- myform.Controls.Add (s);
- s.MouseRightUp ();
- Assert.AreEqual (EventsWanted, ArrayListToString (s.Results));
- myform.Dispose ();
- }
- [Test]
- public void PaintEventsOrder ()
- {
- string[] EventsWanted = {
- "OnHandleCreated",
- "OnBindingContextChanged",
- "OnBindingContextChanged",
- "OnInvalidated"
- };
- Form myform = new Form ();
- myform.Visible = true;
- MyScrollBar s = new MyScrollBar ();
- myform.Controls.Add (s);
- s.Visible = true;
- s.Refresh ();
- Assert.AreEqual (EventsWanted, ArrayListToString (s.Results));
- myform.Dispose ();
- }
- [Test]
- public void ScrollEventsOrder ()
- {
- string[] EventsWanted = {
- "OnHandleCreated",
- "OnBindingContextChanged",
- "OnBindingContextChanged",
- "OnScroll",
- "OnValueChanged"
- };
- Form myform = new Form ();
- myform.Visible = true;
- MyScrollBar s = new MyScrollBar ();
- myform.Controls.Add (s);
- s.ScrollNow ();
- Assert.AreEqual (EventsWanted, ArrayListToString (s.Results));
- myform.Dispose ();
- }
- [Test]
- public void TextChangedEventsOrder ()
- {
- string[] EventsWanted = {
- "OnHandleCreated",
- "OnBindingContextChanged",
- "OnBindingContextChanged",
- "OnTextChanged"
- };
- Form myform = new Form ();
- myform.Visible = true;
- MyScrollBar s = new MyScrollBar ();
- myform.Controls.Add (s);
- s.Text = "foobar";
- Assert.AreEqual (EventsWanted, ArrayListToString (s.Results));
- myform.Dispose ();
- }
- [Test]
- public void ValueChangedEventsOrder ()
- {
- string[] EventsWanted = {
- "OnHandleCreated",
- "OnBindingContextChanged",
- "OnBindingContextChanged",
- "OnValueChanged"
- };
- Form myform = new Form ();
- myform.Visible = true;
- MyScrollBar s = new MyScrollBar ();
- myform.Controls.Add (s);
- s.Value = 10;
- Assert.AreEqual (EventsWanted, ArrayListToString (s.Results));
- myform.Dispose ();
- }
- }
- public class MyScrollBar2 : HScrollBar
- {
- protected ArrayList results = new ArrayList ();
- public MyScrollBar2 () : base ()
- {
- this.HandleCreated += new EventHandler (HandleCreated_Handler);
- this.BackColorChanged += new EventHandler (BackColorChanged_Handler);
- this.BackgroundImageChanged += new EventHandler (BackgroundImageChanged_Handler);
- this.BindingContextChanged += new EventHandler (BindingContextChanged_Handler);
- this.Click += new EventHandler (Click_Handler);
- this.DoubleClick += new EventHandler (DoubleClick_Handler);
- this.FontChanged += new EventHandler (FontChanged_Handler);
- this.ForeColorChanged += new EventHandler (ForeColorChanged_Handler);
- this.ImeModeChanged += new EventHandler (ImeModeChanged_Handler);
- this.MouseDown += new MouseEventHandler (MouseDown_Handler);
- this.MouseMove += new MouseEventHandler (MouseMove_Handler);
- this.MouseUp += new MouseEventHandler (MouseUp_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);
- this.Scroll += new ScrollEventHandler (Scroll_Handler);
- this.TextChanged += new EventHandler (TextChanged_Handler);
- this.ValueChanged += new EventHandler (ValueChanged_Handler);
- }
- protected void HandleCreated_Handler (object sender, EventArgs e)
- {
- results.Add ("HandleCreated");
- }
- protected void BackColorChanged_Handler (object sender, EventArgs e)
- {
- results.Add ("BackColorChanged");
- }
- protected void BackgroundImageChanged_Handler (object sender, EventArgs e)
- {
- results.Add ("BackgroundImageChanged");
- }
- protected void Click_Handler (object sender, EventArgs e)
- {
- results.Add ("Click");
- }
- protected void DoubleClick_Handler (object sender, EventArgs e)
- {
- results.Add ("DoubleClick");
- }
- protected void FontChanged_Handler (object sender, EventArgs e)
- {
- results.Add ("FontChanged");
- }
- protected void ForeColorChanged_Handler (object sender, EventArgs e)
- {
- results.Add ("ForeColorChanged");
- }
- protected void ImeModeChanged_Handler (object sender, EventArgs e)
- {
- results.Add ("ImeModeChanged");
- }
- protected void MouseDown_Handler (object sender, MouseEventArgs e)
- {
- results.Add ("MouseDown");
- }
- protected void MouseMove_Handler (object sender, MouseEventArgs e)
- {
- results.Add ("MouseMove");
- }
- protected void MouseUp_Handler (object sender, MouseEventArgs e)
- {
- results.Add ("MouseUp");
- }
- 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");
- }
- protected void Scroll_Handler (object sender, ScrollEventArgs e)
- {
- results.Add ("Scroll");
- }
- protected void TextChanged_Handler (object sender, EventArgs e)
- {
- results.Add ("TextChanged");
- }
- protected void ValueChanged_Handler (object sender, EventArgs e)
- {
- results.Add ("ValueChanged");
- }
- public ArrayList Results {
- get { return results; }
- }
- public void MoveMouse ()
- {
- Message m;
- m = new Message ();
- m.Msg = (int)WndMsg.WM_NCHITTEST;
- m.HWnd = this.Handle;
- m.WParam = (IntPtr)0x0;
- m.LParam = (IntPtr)0x1c604ea;
- this.WndProc(ref m);
- m.Msg = (int)WndMsg.WM_SETCURSOR;
- m.HWnd = this.Handle;
- m.WParam = (IntPtr)0x100448;
- m.LParam = (IntPtr)0x2000001;
- this.WndProc(ref m);
- m.Msg = (int)WndMsg.WM_MOUSEFIRST;
- m.HWnd = this.Handle;
- m.WParam = (IntPtr)0x0;
- m.LParam = (IntPtr)0x14000b;
- this.WndProc(ref m);
- m.Msg = (int)WndMsg.WM_MOUSEHOVER;
- m.HWnd = this.Handle;
- m.WParam = (IntPtr)0x0;
- m.LParam = (IntPtr)0x14000b;
- this.WndProc(ref m);
- }
- public void MouseRightDown()
- {
- Message m;
- m = new Message();
- m.Msg = (int)WndMsg.WM_RBUTTONDOWN;
- m.HWnd = this.Handle;
- m.WParam = (IntPtr)0x01;
- m.LParam = (IntPtr)0x9004f;
- this.WndProc(ref m);
- }
- public void MouseClick()
- {
- Message m;
- m = new Message();
- m.Msg = (int)WndMsg.WM_LBUTTONDOWN;
- m.HWnd = this.Handle;
- m.WParam = (IntPtr)0x01;
- m.LParam = (IntPtr)0x9004f;
- this.WndProc(ref m);
- m = new Message();
- m.Msg = (int)WndMsg.WM_LBUTTONUP;
- m.HWnd = this.Handle;
- m.WParam = (IntPtr)0x01;
- m.LParam = (IntPtr)0x9004f;
- this.WndProc(ref m);
- }
- public void MouseDoubleClick ()
- {
- MouseClick ();
- MouseClick ();
- }
- public void MouseRightUp()
- {
- Message m;
- m = new Message();
- m.Msg = (int)WndMsg.WM_RBUTTONUP;
- m.HWnd = this.Handle;
- m.WParam = (IntPtr)0x01;
- m.LParam = (IntPtr)0x9004f;
- this.WndProc(ref m);
- }
- public void ScrollNow ()
- {
- Message m;
- m = new Message ();
- m.Msg = 8468;
- m.HWnd = this.Handle;
- m.WParam = (IntPtr)0x1;
- m.LParam = (IntPtr)0x1a051a;
- this.WndProc(ref m);
- m.Msg = 233;
- m.HWnd = this.Handle;
- m.WParam = (IntPtr)0x1;
- m.LParam = (IntPtr)0x12eb34;
- this.WndProc(ref m);
- }
- }
- [TestFixture]
- [Ignore("Tests too strict")]
- public class HScrollBarTestEventsOrder2
- {
- 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;
- MyScrollBar2 s = new MyScrollBar2 ();
- myform.Controls.Add (s);
- Assert.AreEqual (EventsWanted, ArrayListToString (s.Results));
- myform.Dispose ();
- }
- [Test]
- public void BackColorChangedEventsOrder ()
- {
- string[] EventsWanted = {
- "HandleCreated",
- "BindingContextChanged",
- "BindingContextChanged",
- "Invalidated",
- "BackColorChanged"
- };
- Form myform = new Form ();
- myform.Visible = true;
- MyScrollBar2 s = new MyScrollBar2 ();
- myform.Controls.Add (s);
- s.BackColor = Color.Aqua;
- Assert.AreEqual (EventsWanted, ArrayListToString (s.Results));
- myform.Dispose ();
- }
- [Test]
- public void BackgroundImageChangedEventsOrder ()
- {
- string[] EventsWanted = {
- "HandleCreated",
- "BindingContextChanged",
- "BindingContextChanged",
- "Invalidated",
- "BackgroundImageChanged"
- };
- Form myform = new Form ();
- myform.Visible = true;
- MyScrollBar2 s = new MyScrollBar2 ();
- myform.Controls.Add (s);
- s.BackgroundImage = Image.FromFile ("Test/System.Windows.Forms/bitmaps/a.png");
- Assert.AreEqual (EventsWanted, ArrayListToString (s.Results));
- myform.Dispose ();
- }
- [Test, Ignore ("Need to send proper Click / DoubleClick")]
- public void ClickEventsOrder ()
- {
- string[] EventsWanted = {
- "HandleCreated",
- "BindingContextChanged",
- "BindingContextChanged"
- };
- Form myform = new Form ();
- myform.Visible = true;
- MyScrollBar2 s = new MyScrollBar2 ();
- myform.Controls.Add (s);
- s.MouseClick ();
- Assert.AreEqual (EventsWanted, ArrayListToString (s.Results));
- myform.Dispose ();
- }
- [Test, Ignore ("Need to send proper Click / DoubleClick")]
- public void DoubleClickEventsOrder ()
- {
- string[] EventsWanted = {
- "HandleCreated",
- "BindingContextChanged",
- "BindingContextChanged"
- };
- Form myform = new Form ();
- myform.Visible = true;
- MyScrollBar2 s = new MyScrollBar2 ();
- myform.Controls.Add (s);
- s.MouseDoubleClick ();
- Assert.AreEqual (EventsWanted, ArrayListToString (s.Results));
- myform.Dispose ();
- }
- [Test]
- public void FontChangedEventsOrder ()
- {
- string[] EventsWanted = {
- "HandleCreated",
- "BindingContextChanged",
- "BindingContextChanged"
- };
- Form myform = new Form ();
- myform.Visible = true;
- MyScrollBar2 s = new MyScrollBar2 ();
- myform.Controls.Add (s);
- FontDialog myFontDialog = new FontDialog();
- s.Font = myFontDialog.Font;
- Assert.AreEqual (EventsWanted, ArrayListToString (s.Results));
- myform.Dispose ();
- }
- [Test]
- public void ForeColorChangedEventsOrder ()
- {
- string[] EventsWanted = {
- "HandleCreated",
- "BindingContextChanged",
- "BindingContextChanged",
- "Invalidated",
- "ForeColorChanged"
- };
- Form myform = new Form ();
- myform.Visible = true;
- MyScrollBar2 s = new MyScrollBar2 ();
- myform.Controls.Add (s);
- s.ForeColor = Color.Aqua;
- Assert.AreEqual (EventsWanted, ArrayListToString (s.Results));
- myform.Dispose ();
- }
- [Test]
- public void ImeModeChangedChangedEventsOrder ()
- {
- string[] EventsWanted = {
- "HandleCreated",
- "BindingContextChanged",
- "BindingContextChanged",
- "ImeModeChanged"
- };
- Form myform = new Form ();
- myform.Visible = true;
- MyScrollBar2 s = new MyScrollBar2 ();
- myform.Controls.Add (s);
- s.ImeMode = ImeMode.Katakana;
- Assert.AreEqual (EventsWanted, ArrayListToString (s.Results));
- myform.Dispose ();
- }
- [Test]
- public void MouseDownEventsOrder ()
- {
- string[] EventsWanted = {
- "HandleCreated",
- "BindingContextChanged",
- "BindingContextChanged",
- "MouseDown"
- };
- Form myform = new Form ();
- myform.Visible = true;
- MyScrollBar2 s = new MyScrollBar2 ();
- myform.Controls.Add (s);
- s.MouseRightDown ();
- Assert.AreEqual (EventsWanted, ArrayListToString (s.Results));
- myform.Dispose ();
- }
- [Test]
- public void MouseMoveEventsOrder ()
- {
- string[] EventsWanted = {
- "HandleCreated",
- "BindingContextChanged",
- "BindingContextChanged",
- "MouseMove"
- };
- Form myform = new Form ();
- myform.Visible = true;
- MyScrollBar2 s = new MyScrollBar2 ();
- myform.Controls.Add (s);
- s.MoveMouse ();
- Assert.AreEqual (EventsWanted, ArrayListToString (s.Results));
- myform.Dispose ();
- }
- [Test]
- public void MouseUpEventsOrder ()
- {
- string[] EventsWanted = {
- "HandleCreated",
- "BindingContextChanged",
- "BindingContextChanged",
- "MouseUp"
- };
- Form myform = new Form ();
- myform.Visible = true;
- MyScrollBar2 s = new MyScrollBar2 ();
- myform.Controls.Add (s);
- s.MouseRightUp ();
- Assert.AreEqual (EventsWanted, ArrayListToString (s.Results));
- myform.Dispose ();
- }
- [Test]
- public void PaintEventsOrder ()
- {
- string[] EventsWanted = {
- "HandleCreated",
- "BindingContextChanged",
- "BindingContextChanged",
- "Invalidated"
- };
- Form myform = new Form ();
- myform.Visible = true;
- MyScrollBar2 s = new MyScrollBar2 ();
- myform.Controls.Add (s);
- s.Visible = true;
- s.Refresh ();
- Assert.AreEqual (EventsWanted, ArrayListToString (s.Results));
- myform.Dispose ();
- }
- [Test]
- public void ScrollEventsOrder ()
- {
- string[] EventsWanted = {
- "HandleCreated",
- "BindingContextChanged",
- "BindingContextChanged",
- "Scroll",
- "ValueChanged"
- };
- Form myform = new Form ();
- myform.Visible = true;
- MyScrollBar2 s = new MyScrollBar2 ();
- myform.Controls.Add (s);
- s.ScrollNow ();
- Assert.AreEqual (EventsWanted, ArrayListToString (s.Results));
- myform.Dispose ();
- }
- [Test]
- public void TextChangedEventsOrder ()
- {
- string[] EventsWanted = {
- "HandleCreated",
- "BindingContextChanged",
- "BindingContextChanged",
- "TextChanged"
- };
- Form myform = new Form ();
- myform.Visible = true;
- MyScrollBar2 s = new MyScrollBar2 ();
- myform.Controls.Add (s);
- s.Text = "foobar";
- Assert.AreEqual (EventsWanted, ArrayListToString (s.Results));
- myform.Dispose ();
- }
- [Test]
- public void ValueChangedEventsOrder ()
- {
- string[] EventsWanted = {
- "HandleCreated",
- "BindingContextChanged",
- "BindingContextChanged",
- "ValueChanged"
- };
- Form myform = new Form ();
- myform.Visible = true;
- MyScrollBar2 s = new MyScrollBar2 ();
- myform.Controls.Add (s);
- s.Value = 10;
- Assert.AreEqual (EventsWanted, ArrayListToString (s.Results));
- myform.Dispose ();
- }
- }
- }
|