Exemplo n.º 1
0
        public void TestProtectedMethods()
        {
            // Protected Methods that force Handle creation:
            // - CreateAccessibilityInstance ()
            // - CreateHandle ()
            // - IsInputChar ()
            // - Select ()
            // - SetVisibleCore ()
            // - CenterToParent ()
            // - CenterToScreen ()
            ProtectedMethodsForm c = new ProtectedMethodsForm();

            c.PublicAccessibilityNotifyClients(AccessibleEvents.Focus, 0);
            Assert.IsFalse(c.IsHandleCreated, "A1");
            c.PublicCreateAccessibilityInstance();
            Assert.IsTrue(c.IsHandleCreated, "A2");
            c.Dispose();
            c = new ProtectedMethodsForm();
            c.PublicCreateControlsInstance();
            Assert.IsFalse(c.IsHandleCreated, "A3");
            c.PublicCreateHandle();
            Assert.IsTrue(c.IsHandleCreated, "A4");
            c.Dispose();

            c = new ProtectedMethodsForm();
            c.PublicDestroyHandle();
            Assert.IsFalse(c.IsHandleCreated, "A5");
            c.Dispose();
            c = new ProtectedMethodsForm();
            c.PublicGetAccessibilityObjectById(0);
            Assert.IsFalse(c.IsHandleCreated, "A6");
#if !__MonoCS__
            c.PublicGetAutoSizeMode();
            Assert.IsFalse(c.IsHandleCreated, "A7");
            c.PublicGetScaledBounds(new Rectangle(0, 0, 100, 100), new SizeF(1.5f, 1.5f), BoundsSpecified.All);
            Assert.IsFalse(c.IsHandleCreated, "A8");
#endif
            c.PublicGetStyle(ControlStyles.FixedHeight);
            Assert.IsFalse(c.IsHandleCreated, "A9");
            c.PublicGetTopLevel();
            Assert.IsFalse(c.IsHandleCreated, "A10");
            c.PublicInitLayout();
            Assert.IsFalse(c.IsHandleCreated, "A11");
            c.PublicInvokeGotFocus(c, EventArgs.Empty);
            Assert.IsFalse(c.IsHandleCreated, "A12");
            c.PublicInvokeLostFocus(c, EventArgs.Empty);
            Assert.IsFalse(c.IsHandleCreated, "A13");
            c.PublicInvokeOnClick(c, EventArgs.Empty);
            Assert.IsFalse(c.IsHandleCreated, "A14");
            c.PublicInvokePaint(c, new PaintEventArgs(Graphics.FromImage(new Bitmap(1, 1)), Rectangle.Empty));
            Assert.IsFalse(c.IsHandleCreated, "A15");
            c.PublicInvokePaintBackground(c, new PaintEventArgs(Graphics.FromImage(new Bitmap(1, 1)), Rectangle.Empty));
            Assert.IsFalse(c.IsHandleCreated, "A16");
            c.PublicIsInputChar('c');
            Assert.IsTrue(c.IsHandleCreated, "A17");
            c.Dispose();

            c = new ProtectedMethodsForm();
            c.PublicIsInputKey(Keys.B);
            Assert.IsFalse(c.IsHandleCreated, "A18");
            c.PublicNotifyInvalidate(Rectangle.Empty);
            Assert.IsFalse(c.IsHandleCreated, "A19");
            Form f = new Form();
            c.TopLevel = false;
            f.Controls.Add(c);
            c.PublicOnVisibleChanged(EventArgs.Empty);
            Assert.IsFalse(c.IsHandleCreated, "A20");
            c.Dispose();
            c = new ProtectedMethodsForm();
            c.PublicRaiseDragEvent(null, null);
            Assert.IsFalse(c.IsHandleCreated, "A21");
            c.PublicRaiseKeyEvent(null, null);
            Assert.IsFalse(c.IsHandleCreated, "A22");
            c.PublicRaiseMouseEvent(null, null);
            Assert.IsFalse(c.IsHandleCreated, "A23");
            c.PublicRaisePaintEvent(null, null);
            Assert.IsFalse(c.IsHandleCreated, "A24");
            c.PublicRecreateHandle();
            Assert.IsFalse(c.IsHandleCreated, "A25");
            c.PublicResetMouseEventArgs();
            Assert.IsFalse(c.IsHandleCreated, "A26");
            c.PublicRtlTranslateAlignment(ContentAlignment.BottomLeft);
            Assert.IsFalse(c.IsHandleCreated, "A27");
            c.PublicRtlTranslateContent(ContentAlignment.BottomLeft);
            Assert.IsFalse(c.IsHandleCreated, "A28");
            c.PublicRtlTranslateHorizontal(HorizontalAlignment.Left);
            Assert.IsFalse(c.IsHandleCreated, "A29");
            c.PublicRtlTranslateLeftRight(LeftRightAlignment.Left);
            Assert.IsFalse(c.IsHandleCreated, "A30");
#if !__MonoCS__
            c.PublicScaleControl(new SizeF(1.5f, 1.5f), BoundsSpecified.All);
            Assert.IsFalse(c.IsHandleCreated, "A31");
#endif
            c.PublicScaleCore(1.5f, 1.5f);
            Assert.IsFalse(c.IsHandleCreated, "A32");
            c.PublicSelect();
            Assert.IsTrue(c.IsHandleCreated, "A33");
            c.Dispose();

            c = new ProtectedMethodsForm();
#if !__MonoCS__
            c.PublicSetAutoSizeMode(AutoSizeMode.GrowAndShrink);
            Assert.IsFalse(c.IsHandleCreated, "A34");
#endif
            c.PublicSetBoundsCore(0, 0, 100, 100, BoundsSpecified.All);
            Assert.IsFalse(c.IsHandleCreated, "A35");
            c.PublicSetClientSizeCore(122, 122);
            Assert.IsFalse(c.IsHandleCreated, "A36");
            c.PublicSetStyle(ControlStyles.FixedHeight, true);
            Assert.IsFalse(c.IsHandleCreated, "A37");

            c.PublicSetTopLevel(true);
            Assert.IsFalse(c.IsHandleCreated, "A38");
            c.Dispose();

            c = new ProtectedMethodsForm();

            c.PublicSetVisibleCore(true);
            Assert.IsTrue(c.IsHandleCreated, "A39");
            c.Dispose();

            c = new ProtectedMethodsForm();
            c.PublicSizeFromClientSize(new Size(160, 160));
            Assert.IsFalse(c.IsHandleCreated, "A40");
            c.PublicUpdateBounds();
            Assert.IsFalse(c.IsHandleCreated, "A41");
            c.PublicUpdateStyles();
            Assert.IsFalse(c.IsHandleCreated, "A42");
            c.PublicUpdateZOrder();
            Assert.IsFalse(c.IsHandleCreated, "A43");
            c.Dispose();

            // Form
            c = new ProtectedMethodsForm();
            c.IsMdiContainer     = true;
            new Form().MdiParent = c;
            new Form().MdiParent = c;
            c.PublicActivateMdiChild(c.MdiChildren [0]);
            c.PublicActivateMdiChild(c.MdiChildren [1]);
            Assert.IsFalse(c.IsHandleCreated, "F1");
            c.Dispose();
            c = new ProtectedMethodsForm();

            c.PublicAdjustFormScrollbars(true);
            Assert.IsFalse(c.IsHandleCreated, "F2");

            c.PublicCenterToParent();
            Assert.IsTrue(c.IsHandleCreated, "F3");
            c.Dispose();
            c = new ProtectedMethodsForm();

            c.PublicCenterToScreen();
            Assert.IsTrue(c.IsHandleCreated, "F4");
            c.Dispose();
            c = new ProtectedMethodsForm();

            c.PublicGetScrollState(1);
            Assert.IsFalse(c.IsHandleCreated, "F5");

            c.PublicGetService(typeof(int));
            Assert.IsFalse(c.IsHandleCreated, "F6");

            Message m = new Message();
            c.PublicProcessCmdKey(ref m, Keys.C);
            Assert.IsFalse(c.IsHandleCreated, "F7");

            c.PublicProcessDialogChar('p');
            Assert.IsFalse(c.IsHandleCreated, "F8");

            c.PublicProcessDialogKey(Keys.D);
            Assert.IsFalse(c.IsHandleCreated, "F9");

            c.PublicProcessKeyEventArgs(ref m);
            Assert.IsFalse(c.IsHandleCreated, "F10");

            c.PublicProcessKeyMessage(ref m);
            Assert.IsFalse(c.IsHandleCreated, "F11");

            c.PublicProcessKeyPreview(ref m);
            Assert.IsFalse(c.IsHandleCreated, "F12");

            c.PublicProcessMnemonic('Z');
            Assert.IsFalse(c.IsHandleCreated, "F13");

            c.PublicProcessTabKey(true);
            Assert.IsFalse(c.IsHandleCreated, "F14");

#if !__MonoCS__
            c.Controls.Add(new Control());
            c.PublicScrollToControl(c.Controls [0]);
            Assert.IsFalse(c.IsHandleCreated, "F15");
            c.Dispose();
            c = new ProtectedMethodsForm();
#endif

            c.PublicSelect(true, true);
            Assert.IsTrue(c.IsHandleCreated, "F16");
            c.Dispose();

            c = new ProtectedMethodsForm();

            c.PublicSetDisplayRectLocation(13, 17);
            Assert.IsFalse(c.IsHandleCreated, "F17");

            c.PublicSetScrollState(5, false);
            Assert.IsFalse(c.IsHandleCreated, "F18");

            c.PublicUpdateDefaultButton(3, false);
            Assert.IsFalse(c.IsHandleCreated, "F19");

            c.Dispose();
        }
Exemplo n.º 2
0
		public void TestProtectedMethods ()
		{
			// Protected Methods that force Handle creation:
			// - CreateAccessibilityInstance ()
			// - CreateHandle ()
			// - IsInputChar ()
			// - Select ()
			// - SetVisibleCore ()
			// - CenterToParent ()
			// - CenterToScreen ()
			ProtectedMethodsForm c = new ProtectedMethodsForm ();

			c.PublicAccessibilityNotifyClients (AccessibleEvents.Focus, 0);
			Assert.IsFalse (c.IsHandleCreated, "A1");
			c.PublicCreateAccessibilityInstance ();
			Assert.IsTrue (c.IsHandleCreated, "A2");
			c.Dispose ();
			c = new ProtectedMethodsForm ();
			c.PublicCreateControlsInstance ();
			Assert.IsFalse (c.IsHandleCreated, "A3");
			c.PublicCreateHandle ();
			Assert.IsTrue (c.IsHandleCreated, "A4");
			c.Dispose ();
			
			c = new ProtectedMethodsForm ();
			c.PublicDestroyHandle ();
			Assert.IsFalse (c.IsHandleCreated, "A5");
			c.Dispose ();
			c = new ProtectedMethodsForm ();
			c.PublicGetAccessibilityObjectById (0);
			Assert.IsFalse (c.IsHandleCreated, "A6");
#if !MONO
			c.PublicGetAutoSizeMode ();
			Assert.IsFalse (c.IsHandleCreated, "A7");
			c.PublicGetScaledBounds (new Rectangle (0, 0, 100, 100), new SizeF (1.5f, 1.5f), BoundsSpecified.All);
			Assert.IsFalse (c.IsHandleCreated, "A8");
#endif
			c.PublicGetStyle (ControlStyles.FixedHeight);
			Assert.IsFalse (c.IsHandleCreated, "A9");
			c.PublicGetTopLevel ();
			Assert.IsFalse (c.IsHandleCreated, "A10");
			c.PublicInitLayout ();
			Assert.IsFalse (c.IsHandleCreated, "A11");
			c.PublicInvokeGotFocus (c, EventArgs.Empty);
			Assert.IsFalse (c.IsHandleCreated, "A12");
			c.PublicInvokeLostFocus (c, EventArgs.Empty);
			Assert.IsFalse (c.IsHandleCreated, "A13");
			c.PublicInvokeOnClick (c, EventArgs.Empty);
			Assert.IsFalse (c.IsHandleCreated, "A14");
			c.PublicInvokePaint (c, new PaintEventArgs (Graphics.FromImage (new Bitmap (1, 1)), Rectangle.Empty));
			Assert.IsFalse (c.IsHandleCreated, "A15");
			c.PublicInvokePaintBackground (c, new PaintEventArgs (Graphics.FromImage (new Bitmap (1, 1)), Rectangle.Empty));
			Assert.IsFalse (c.IsHandleCreated, "A16");
			c.PublicIsInputChar ('c');
			Assert.IsTrue (c.IsHandleCreated, "A17");
			c.Dispose ();
			
			c = new ProtectedMethodsForm ();
			c.PublicIsInputKey (Keys.B);
			Assert.IsFalse (c.IsHandleCreated, "A18");
			c.PublicNotifyInvalidate (Rectangle.Empty);
			Assert.IsFalse (c.IsHandleCreated, "A19");
			Form f = new Form ();
			c.TopLevel = false;
			f.Controls.Add (c);
			c.PublicOnVisibleChanged (EventArgs.Empty);
			Assert.IsFalse (c.IsHandleCreated, "A20");
			c.Dispose ();
			c = new ProtectedMethodsForm ();
			c.PublicRaiseDragEvent (null, null);
			Assert.IsFalse (c.IsHandleCreated, "A21");
			c.PublicRaiseKeyEvent (null, null);
			Assert.IsFalse (c.IsHandleCreated, "A22");
			c.PublicRaiseMouseEvent (null, null);
			Assert.IsFalse (c.IsHandleCreated, "A23");
			c.PublicRaisePaintEvent (null, null);
			Assert.IsFalse (c.IsHandleCreated, "A24");
			c.PublicRecreateHandle ();
			Assert.IsFalse (c.IsHandleCreated, "A25");
			c.PublicResetMouseEventArgs ();
			Assert.IsFalse (c.IsHandleCreated, "A26");
			c.PublicRtlTranslateAlignment (ContentAlignment.BottomLeft);
			Assert.IsFalse (c.IsHandleCreated, "A27");
			c.PublicRtlTranslateContent (ContentAlignment.BottomLeft);
			Assert.IsFalse (c.IsHandleCreated, "A28");
			c.PublicRtlTranslateHorizontal (HorizontalAlignment.Left);
			Assert.IsFalse (c.IsHandleCreated, "A29");
			c.PublicRtlTranslateLeftRight (LeftRightAlignment.Left);
			Assert.IsFalse (c.IsHandleCreated, "A30");
#if !MONO
			c.PublicScaleControl (new SizeF (1.5f, 1.5f), BoundsSpecified.All);
			Assert.IsFalse (c.IsHandleCreated, "A31");
#endif
			c.PublicScaleCore (1.5f, 1.5f);
			Assert.IsFalse (c.IsHandleCreated, "A32");
			c.PublicSelect ();
			Assert.IsTrue (c.IsHandleCreated, "A33");
			c.Dispose ();
			
			c = new ProtectedMethodsForm ();
#if !MONO
			c.PublicSetAutoSizeMode (AutoSizeMode.GrowAndShrink);
			Assert.IsFalse (c.IsHandleCreated, "A34");
#endif
			c.PublicSetBoundsCore (0, 0, 100, 100, BoundsSpecified.All);
			Assert.IsFalse (c.IsHandleCreated, "A35");
			c.PublicSetClientSizeCore (122, 122);
			Assert.IsFalse (c.IsHandleCreated, "A36");
			c.PublicSetStyle (ControlStyles.FixedHeight, true);
			Assert.IsFalse (c.IsHandleCreated, "A37");
			
			c.PublicSetTopLevel (true);
			Assert.IsFalse (c.IsHandleCreated, "A38");
			c.Dispose ();
			
			c = new ProtectedMethodsForm ();
			
			c.PublicSetVisibleCore (true);
			Assert.IsTrue (c.IsHandleCreated, "A39");
			c.Dispose ();
			
			c = new ProtectedMethodsForm ();
			c.PublicSizeFromClientSize (new Size (160, 160));
			Assert.IsFalse (c.IsHandleCreated, "A40");
			c.PublicUpdateBounds ();
			Assert.IsFalse (c.IsHandleCreated, "A41");
			c.PublicUpdateStyles ();
			Assert.IsFalse (c.IsHandleCreated, "A42");
			c.PublicUpdateZOrder ();
			Assert.IsFalse (c.IsHandleCreated, "A43");
			c.Dispose ();
			
			// Form
			c = new ProtectedMethodsForm ();
			c.IsMdiContainer = true;
			new Form ().MdiParent = c;
			new Form ().MdiParent = c;
			c.PublicActivateMdiChild (c.MdiChildren [0]);
			c.PublicActivateMdiChild (c.MdiChildren [1]);
			Assert.IsFalse (c.IsHandleCreated, "F1");
			c.Dispose ();
			c = new ProtectedMethodsForm();

			c.PublicAdjustFormScrollbars (true);
			Assert.IsFalse (c.IsHandleCreated, "F2");
			
			c.PublicCenterToParent ();
			Assert.IsTrue (c.IsHandleCreated, "F3");
			c.Dispose ();
			c = new ProtectedMethodsForm ();
			
			c.PublicCenterToScreen ();
			Assert.IsTrue (c.IsHandleCreated, "F4");
			c.Dispose ();
			c = new ProtectedMethodsForm ();
			
			c.PublicGetScrollState (1);
			Assert.IsFalse (c.IsHandleCreated, "F5");
			
			c.PublicGetService (typeof (int));
			Assert.IsFalse (c.IsHandleCreated, "F6");

			Message m = new Message ();
			c.PublicProcessCmdKey (ref m, Keys.C);
			Assert.IsFalse (c.IsHandleCreated, "F7");
			
			c.PublicProcessDialogChar ('p');
			Assert.IsFalse (c.IsHandleCreated, "F8");
			
			c.PublicProcessDialogKey (Keys.D);
			Assert.IsFalse (c.IsHandleCreated, "F9");
			
			c.PublicProcessKeyEventArgs (ref m);
			Assert.IsFalse (c.IsHandleCreated, "F10");
			
			c.PublicProcessKeyMessage (ref m);
			Assert.IsFalse (c.IsHandleCreated, "F11");
			
			c.PublicProcessKeyPreview (ref m);
			Assert.IsFalse (c.IsHandleCreated, "F12");

			c.PublicProcessMnemonic ('Z');
			Assert.IsFalse (c.IsHandleCreated, "F13");
			
			c.PublicProcessTabKey (true);
			Assert.IsFalse (c.IsHandleCreated, "F14");

#if !MONO
			c.Controls.Add (new Control ());
			c.PublicScrollToControl (c.Controls [0]);
			Assert.IsFalse (c.IsHandleCreated, "F15");
			c.Dispose ();
			c = new ProtectedMethodsForm (); 
#endif
			
			c.PublicSelect (true, true);
			Assert.IsTrue (c.IsHandleCreated, "F16");
			c.Dispose ();
			
			c = new ProtectedMethodsForm();
			
			c.PublicSetDisplayRectLocation (13, 17);
			Assert.IsFalse (c.IsHandleCreated, "F17");
			
			c.PublicSetScrollState (5, false);
			Assert.IsFalse (c.IsHandleCreated, "F18");
			
			c.PublicUpdateDefaultButton (3, false);
			Assert.IsFalse (c.IsHandleCreated, "F19");

			c.Dispose ();
		}