Пример #1
0
        public void TestProtectedProperties()
        {
            // Not a surprise, but none of these cause handle creation.
            // Included just to absolutely certain.
            ProtectedPropertyForm c = new ProtectedPropertyForm();

            object o;

#if !MONO
            o = c.PublicCanRaiseEvents;
            Assert.IsFalse(c.IsHandleCreated, "A1");
#endif
            o = c.PublicCreateParams;
            Assert.IsFalse(c.IsHandleCreated, "A2");
            o = c.PublicDefaultCursor;
            Assert.IsFalse(c.IsHandleCreated, "A3");
            o = c.PublicDefaultImeMode;
            Assert.IsFalse(c.IsHandleCreated, "A4");
            o = c.PublicDefaultMargin;
            Assert.IsFalse(c.IsHandleCreated, "A5");
            o = c.PublicDefaultMaximumSize;
            Assert.IsFalse(c.IsHandleCreated, "A6");
            o = c.PublicDefaultMinimumSize;
            Assert.IsFalse(c.IsHandleCreated, "A7");
            o = c.PublicDefaultPadding;
            Assert.IsFalse(c.IsHandleCreated, "A8");
            o = c.PublicDefaultSize;
            Assert.IsFalse(c.IsHandleCreated, "A9");
            o = c.PublicDoubleBuffered;
            c.PublicDoubleBuffered = !c.PublicDoubleBuffered;
            Assert.IsFalse(c.IsHandleCreated, "A10");
            o = c.PublicFontHeight;
            c.PublicFontHeight = c.PublicFontHeight + 1;
            Assert.IsFalse(c.IsHandleCreated, "A11");
            o = c.PublicRenderRightToLeft;
            Assert.IsFalse(c.IsHandleCreated, "A12");
            o = c.PublicResizeRedraw;
            c.PublicResizeRedraw = !c.PublicResizeRedraw;
            Assert.IsFalse(c.IsHandleCreated, "A13");
#if !MONO
            o = c.PublicScaleChildren;
            Assert.IsFalse(c.IsHandleCreated, "A14");
#endif
            o = c.PublicShowFocusCues;
            Assert.IsFalse(c.IsHandleCreated, "A15");
            o = c.PublicShowKeyboardCues;
            Assert.IsFalse(c.IsHandleCreated, "A16");

            o = c.PublicAutoScaleFactor;
            Assert.IsFalse(c.IsHandleCreated, "F1");

            o = c.PublicDesignMode;
            Assert.IsFalse(c.IsHandleCreated, "F2");

            o = c.PublicEvents;
            Assert.IsFalse(c.IsHandleCreated, "F3");

            o = c.PublicHScroll;
            c.PublicHScroll = !c.PublicHScroll;
            Assert.IsFalse(c.IsHandleCreated, "F4");

            o = c.PublicMaximizedBounds;
            c.PublicMaximizedBounds = new Rectangle(1, 1, 1, 1);
            Assert.IsFalse(c.IsHandleCreated, "F5");

            o = c.PublicShowWithoutActivation;
            Assert.IsFalse(c.IsHandleCreated, "F6");

            o = c.PublicVScroll;
            c.PublicVScroll = !c.PublicVScroll;
            Assert.IsFalse(c.IsHandleCreated, "F7");


            TestHelper.RemoveWarning(o);
        }
Пример #2
0
        public void TestPublicProperties()
        {
            // This long, carpal-tunnel syndrome inducing test shows us that
            // the following properties cause the Handle to be created:
            // - AccessibilityObject	[get]
            // - Capture			[set]
            // - Handle			[get]
            // - Visible			[set]

            Form c = new Form();
            // A
            object o = c.AccessibilityObject;

            Assert.IsTrue(c.IsHandleCreated, "A0");
            c.Dispose();

            c = new Form();
            o = c.AccessibleDefaultActionDescription;
            c.AccessibleDefaultActionDescription = "playdoh";
            Assert.IsFalse(c.IsHandleCreated, "A1");
            o = c.AccessibleDescription;
            c.AccessibleDescription = "more playdoh!";
            Assert.IsFalse(c.IsHandleCreated, "A2");
            o = c.AccessibleName;
            c.AccessibleName = "playdoh fun factory";
            Assert.IsFalse(c.IsHandleCreated, "A3");
            o = c.AccessibleRole;
            c.AccessibleRole = AccessibleRole.Border;
            Assert.IsFalse(c.IsHandleCreated, "A4");
            o           = c.AllowDrop;
            c.AllowDrop = true;
            Assert.IsFalse(c.IsHandleCreated, "A5");
            // If we don't reset the control, handle creation will fail
            // because AllowDrop requires STAThread, which Nunit doesn't do
            c.Dispose();

            c        = new Form();
            o        = c.Anchor;
            c.Anchor = AnchorStyles.Right;
            Assert.IsFalse(c.IsHandleCreated, "A6");
#if !MONO
            o = c.AutoScrollOffset;
            c.AutoScrollOffset = new Point(40, 40);
            Assert.IsFalse(c.IsHandleCreated, "A7");
#endif
            o          = c.AutoSize;
            c.AutoSize = true;
            Assert.IsFalse(c.IsHandleCreated, "A8");

            // A - Form
            o = c.AcceptButton;
            c.AcceptButton = null;
            Assert.IsFalse(c.IsHandleCreated, "FA1");

            o = c.ActiveControl;
            c.ActiveControl = null;
            Assert.IsFalse(c.IsHandleCreated, "FA2");

            o = c.ActiveMdiChild;
            Assert.IsFalse(c.IsHandleCreated, "FA3");

            o = c.AllowTransparency;
            c.AllowTransparency = !c.AllowTransparency;
            Assert.IsFalse(c.IsHandleCreated, "FA4");

            o = c.AutoScaleDimensions;
            c.AutoScaleDimensions = SizeF.Empty;
            Assert.IsFalse(c.IsHandleCreated, "FA5");

            o = c.AutoScaleMode;
            c.AutoScaleMode = AutoScaleMode.Dpi;
            Assert.IsFalse(c.IsHandleCreated, "FA6");
            o            = c.AutoScroll;
            c.AutoScroll = !c.AutoScroll;
            Assert.IsFalse(c.IsHandleCreated, "FA7");

            o = c.AutoScrollMargin;
            c.AutoScrollMargin = new Size(c.AutoScrollMargin.Width + 1, c.AutoScrollMargin.Height + 1);
            Assert.IsFalse(c.IsHandleCreated, "FA8");

            o = c.AutoScrollMinSize;
            c.AutoScrollMinSize = new Size(c.AutoScrollMinSize.Width + 1, c.AutoScrollMinSize.Height + 1);
            Assert.IsFalse(c.IsHandleCreated, "FA9");

#if !MONO
            o = c.AutoScrollOffset;
            c.AutoScrollOffset = new Point(c.AutoScrollOffset.X + 1, c.AutoScrollOffset.Y + 1);
            Assert.IsFalse(c.IsHandleCreated, "FA10");
#endif

            o = c.AutoScrollPosition;
            c.AutoScrollPosition = new Point(c.AutoScrollPosition.X + 1, c.AutoScrollPosition.Y + 1);
            Assert.IsFalse(c.IsHandleCreated, "FA11");

            o          = c.AutoSize;
            c.AutoSize = !c.AutoSize;
            Assert.IsFalse(c.IsHandleCreated, "FA12");
#if !MONO
            o = c.AutoSizeMode;
            c.AutoSizeMode = AutoSizeMode.GrowAndShrink;
            Assert.IsFalse(c.IsHandleCreated, "FA13");
#endif
            o = c.AutoValidate;
            c.AutoValidate = AutoValidate.EnableAllowFocusChange;
            Assert.IsFalse(c.IsHandleCreated, "FA14");

            // B
            o           = c.BackColor;
            c.BackColor = Color.Green;
            Assert.IsFalse(c.IsHandleCreated, "A9");
            o = c.BackgroundImage;
            c.BackgroundImage = new Bitmap(1, 1);
            Assert.IsFalse(c.IsHandleCreated, "A10");
            o = c.BackgroundImageLayout;
            c.BackgroundImageLayout = ImageLayout.Stretch;
            Assert.IsFalse(c.IsHandleCreated, "A11");
            o = c.BindingContext;
            c.BindingContext = new BindingContext();
            Assert.IsFalse(c.IsHandleCreated, "A12");
            o = c.Bottom;
            Assert.IsFalse(c.IsHandleCreated, "A13");
            o        = c.Bounds;
            c.Bounds = new Rectangle(0, 0, 12, 12);
            Assert.IsFalse(c.IsHandleCreated, "A14");


            // B - Form
            o = c.BindingContext;
            c.BindingContext = null;
            Assert.IsFalse(c.IsHandleCreated, "FB1");

            // C
            o = c.CanFocus;
            Assert.IsFalse(c.IsHandleCreated, "A15");
            o = c.CanSelect;
            Assert.IsFalse(c.IsHandleCreated, "A16");
            o = c.Capture;
            Assert.IsFalse(c.IsHandleCreated, "A17a");
            c.Capture = true;
            Assert.IsTrue(c.IsHandleCreated, "A17b");
            c.Dispose();

            c = new Form();
            o = c.CausesValidation;
            c.CausesValidation = false;
            Assert.IsFalse(c.IsHandleCreated, "A18");
            o = c.ClientRectangle;
            Assert.IsFalse(c.IsHandleCreated, "A19");
            o            = c.ClientSize;
            c.ClientSize = new Size(30, 30);
            Assert.IsFalse(c.IsHandleCreated, "A20");
            o = c.CompanyName;
            Assert.IsFalse(c.IsHandleCreated, "A21");
            o = c.Container;
            Assert.IsFalse(c.IsHandleCreated, "A22");
            o = c.ContainsFocus;
            Assert.IsFalse(c.IsHandleCreated, "A23");
            o             = c.ContextMenu;
            c.ContextMenu = new ContextMenu();
            Assert.IsFalse(c.IsHandleCreated, "A24");
            o = c.ContextMenuStrip;
            c.ContextMenuStrip = new ContextMenuStrip();
            Assert.IsFalse(c.IsHandleCreated, "A25");
            o = c.Controls;
            Assert.IsFalse(c.IsHandleCreated, "A26");
            o = c.Created;
            Assert.IsFalse(c.IsHandleCreated, "A27");
            o        = c.Cursor;
            c.Cursor = Cursors.Arrow;
            Assert.IsFalse(c.IsHandleCreated, "A28");

            // C - Form
            o = c.CancelButton;
            c.CancelButton = null;
            Assert.IsFalse(c.IsHandleCreated, "FC1");

            o            = c.ClientSize;
            c.ClientSize = new Size(c.ClientSize.Width + 1, c.ClientSize.Height + 1);
            Assert.IsFalse(c.IsHandleCreated, "FC2");

            o = c.Container;
            Assert.IsFalse(c.IsHandleCreated, "FC3");

            o            = c.ControlBox;
            c.ControlBox = !c.ControlBox;
            Assert.IsFalse(c.IsHandleCreated, "FC4");

            o = c.CurrentAutoScaleDimensions;
            Assert.IsFalse(c.IsHandleCreated, "FC5");

            // D
            o = c.DataBindings;
            Assert.IsFalse(c.IsHandleCreated, "A29");
            o = c.DisplayRectangle;
            Assert.IsFalse(c.IsHandleCreated, "A30");
            o = c.Disposing;
            Assert.IsFalse(c.IsHandleCreated, "A31");
            o      = c.Dock;
            c.Dock = DockStyle.Fill;
            Assert.IsFalse(c.IsHandleCreated, "A32");

            // D - Form
            o = c.DataBindings;
            Assert.IsFalse(c.IsHandleCreated, "FD6");

            o = c.DesktopBounds;
            c.DesktopBounds = new Rectangle(3, 5, c.DesktopBounds.Width + 1, c.DesktopBounds.Height + 1);
            Assert.IsFalse(c.IsHandleCreated, "FD7");

            o = c.DesktopLocation;
            c.DesktopLocation = c.DesktopLocation + new Size(1, 1);
            Assert.IsFalse(c.IsHandleCreated, "FD8");

            o = c.DialogResult;
            c.DialogResult = DialogResult.Abort;
            Assert.IsFalse(c.IsHandleCreated, "FD9");

            o = c.DisplayRectangle;
            Assert.IsFalse(c.IsHandleCreated, "FD10");

            o = c.Disposing;
            Assert.IsFalse(c.IsHandleCreated, "FD11");

            o      = c.Dock;
            c.Dock = DockStyle.Right;
            Assert.IsFalse(c.IsHandleCreated, "FD12");

            // E-H
            o         = c.Enabled;
            c.Enabled = false;
            Assert.IsFalse(c.IsHandleCreated, "A33");
            c.Dispose();

            c = new Form();               //Reset just in case enable = false affects things
            o = c.Focused;
            Assert.IsFalse(c.IsHandleCreated, "A34");
            o      = c.Font;
            c.Font = new Font(c.Font, FontStyle.Bold);
            Assert.IsFalse(c.IsHandleCreated, "A35");
            o           = c.ForeColor;
            c.ForeColor = Color.Green;
            Assert.IsFalse(c.IsHandleCreated, "A36");
            o = c.Handle;
            Assert.IsTrue(c.IsHandleCreated, "A37");
            c.Dispose();

            c = new Form();
            o = c.HasChildren;
            Assert.IsFalse(c.IsHandleCreated, "A38");
            o        = c.Height;
            c.Height = 12;
            Assert.IsFalse(c.IsHandleCreated, "A39");

            // E-H - Form
            o = c.FormBorderStyle;
            c.FormBorderStyle = FormBorderStyle.FixedToolWindow;
            Assert.IsFalse(c.IsHandleCreated, "FF1");

            o            = c.HelpButton;
            c.HelpButton = !c.HelpButton;
            Assert.IsFalse(c.IsHandleCreated, "FH1");

#if !MONO
            o = c.HorizontalScroll;
            Assert.IsFalse(c.IsHandleCreated, "FH2");
#endif
            // I - L
            c.ImeMode = ImeMode.On;
            Assert.IsFalse(c.IsHandleCreated, "A40");
            o = c.InvokeRequired;
            Assert.IsFalse(c.IsHandleCreated, "A41");
            o = c.IsAccessible;
            Assert.IsFalse(c.IsHandleCreated, "A42");
            o = c.IsDisposed;
            Assert.IsFalse(c.IsHandleCreated, "A43");
#if !MONO
            o = c.IsMirrored;
            Assert.IsFalse(c.IsHandleCreated, "A44");
#endif
            o = c.LayoutEngine;
            Assert.IsFalse(c.IsHandleCreated, "A45");
            o      = c.Left;
            c.Left = 15;
            Assert.IsFalse(c.IsHandleCreated, "A46");
            o          = c.Location;
            c.Location = new Point(20, 20);
            Assert.IsFalse(c.IsHandleCreated, "A47");

            // I - L - Form

            o      = c.Icon;
            c.Icon = null;
            Assert.IsFalse(c.IsHandleCreated, "FI1");

            o = c.IsMdiChild;
            Assert.IsFalse(c.IsHandleCreated, "FI2");

            o = c.IsMdiContainer;
            c.IsMdiContainer = false;
            Assert.IsFalse(c.IsHandleCreated, "FI3");

            o = c.IsRestrictedWindow;
            Assert.IsFalse(c.IsHandleCreated, "FI4");

            o            = c.KeyPreview;
            c.KeyPreview = !c.KeyPreview;
            Assert.IsFalse(c.IsHandleCreated, "FK1");

            o          = c.Location;
            c.Location = c.Location + new Size(1, 1);
            Assert.IsFalse(c.IsHandleCreated, "FL1");


            // M - N
            o        = c.Margin;
            c.Margin = new Padding(6);
            Assert.IsFalse(c.IsHandleCreated, "A48");
            o             = c.MaximumSize;
            c.MaximumSize = new Size(500, 500);
            Assert.IsFalse(c.IsHandleCreated, "A49");
            o             = c.MinimumSize;
            c.MinimumSize = new Size(100, 100);
            Assert.IsFalse(c.IsHandleCreated, "A50");
            o      = c.Name;
            c.Name = "web";
            Assert.IsFalse(c.IsHandleCreated, "A51");

            // M - O - Form
            o = c.MainMenuStrip;
            c.MainMenuStrip = null;
            Assert.IsFalse(c.IsHandleCreated, "FM1");

            o             = c.MaximizeBox;
            c.MaximizeBox = !c.MaximizeBox;
            Assert.IsFalse(c.IsHandleCreated, "FM2");

            o             = c.MaximumSize;
            c.MaximumSize = c.MaximumSize + new Size(1, 1);
            Assert.IsFalse(c.IsHandleCreated, "FM3");

            o = c.MdiChildren;
            Assert.IsFalse(c.IsHandleCreated, "FM4");

            o           = c.MdiParent;
            c.MdiParent = null;
            Assert.IsFalse(c.IsHandleCreated, "FM5");

            o      = c.Menu;
            c.Menu = null;
            Assert.IsFalse(c.IsHandleCreated, "FM6");

            o = c.MergedMenu;
            Assert.IsFalse(c.IsHandleCreated, "FM7");

            o             = c.MinimizeBox;
            c.MinimizeBox = !c.MinimizeBox;
            Assert.IsFalse(c.IsHandleCreated, "FM8");

            o             = c.MinimumSize;
            c.MinimumSize = c.MinimumSize + new Size(1, 1);
            Assert.IsFalse(c.IsHandleCreated, "FM9");

            o = c.Modal;
            Assert.IsFalse(c.IsHandleCreated, "FM10");

            o         = c.Opacity;
            c.Opacity = 0.9;
            Assert.IsFalse(c.IsHandleCreated, "FO1");

            o = c.OwnedForms;
            Assert.IsFalse(c.IsHandleCreated, "FO2");

            o       = c.Owner;
            c.Owner = null;
            Assert.IsFalse(c.IsHandleCreated, "FO3");

            // P - R
            o         = c.Padding;
            c.Padding = new Padding(4);
            Assert.IsFalse(c.IsHandleCreated, "A52");
            o          = c.Parent;
            c.TopLevel = false;
            c.Parent   = new Form();
            Assert.IsFalse(c.IsHandleCreated, "A53");
            c.Close();

            c = new Form();
            o = c.PreferredSize;
            Assert.IsFalse(c.IsHandleCreated, "A54");
            o = c.ProductName;
            Assert.IsFalse(c.IsHandleCreated, "A55");
            o = c.ProductVersion;
            Assert.IsFalse(c.IsHandleCreated, "A56");
            o = c.RecreatingHandle;
            Assert.IsFalse(c.IsHandleCreated, "A57");
            o        = c.Region;
            c.Region = new Region(new Rectangle(0, 0, 177, 177));
            Assert.IsFalse(c.IsHandleCreated, "A58");
            o = c.Right;
            Assert.IsFalse(c.IsHandleCreated, "A59");
            o             = c.RightToLeft;
            c.RightToLeft = RightToLeft.Yes;
            Assert.IsFalse(c.IsHandleCreated, "A60");

            // P - R - Form
            o = c.ParentForm;
            Assert.IsFalse(c.IsHandleCreated, "FP1");

#if !MONO
            o = c.RestoreBounds;
            Assert.IsFalse(c.IsHandleCreated, "FR1");
#endif


            // S - W
            o = c.Site;
            Assert.IsFalse(c.IsHandleCreated, "A61");
            o      = c.Size;
            c.Size = new Size(188, 188);
            Assert.IsFalse(c.IsHandleCreated, "A62");
            o          = c.TabIndex;
            c.TabIndex = 5;
            Assert.IsFalse(c.IsHandleCreated, "A63");
            o     = c.Tag;
            c.Tag = "moooooooo";
            Assert.IsFalse(c.IsHandleCreated, "A64");
            o      = c.Text;
            c.Text = "meoooowww";
            Assert.IsFalse(c.IsHandleCreated, "A65");
            o     = c.Top;
            c.Top = 16;
            Assert.IsFalse(c.IsHandleCreated, "A66");
            o = c.TopLevelControl;
            Assert.IsFalse(c.IsHandleCreated, "A67");
#if !MONO
            o = c.UseWaitCursor;
            c.UseWaitCursor = true;
            Assert.IsFalse(c.IsHandleCreated, "A68");
#endif
            o = c.Visible;
            Assert.IsFalse(c.IsHandleCreated, "A69");

            c.Visible = true;
            Assert.IsTrue(c.IsHandleCreated, "A69-b");
            c.Dispose();
            c = new Form();

            o       = c.Width;
            c.Width = 190;
            Assert.IsFalse(c.IsHandleCreated, "A70");
            o = c.WindowTarget;
            Assert.IsFalse(c.IsHandleCreated, "A71");

            // S - W - Form

            o          = c.ShowIcon;
            c.ShowIcon = !c.ShowIcon;
            Assert.IsFalse(c.IsHandleCreated, "FS1");

            o = c.ShowInTaskbar;
            c.ShowInTaskbar = !c.ShowInTaskbar;
            Assert.IsFalse(c.IsHandleCreated, "FS2");

            o      = c.Size;
            c.Size = c.Size + new Size(1, 1);
            Assert.IsFalse(c.IsHandleCreated, "FS3");

            o = c.SizeGripStyle;
            c.SizeGripStyle = SizeGripStyle.Show;
            Assert.IsFalse(c.IsHandleCreated, "FS4");

            o = c.StartPosition;
            c.StartPosition = FormStartPosition.Manual;
            Assert.IsFalse(c.IsHandleCreated, "FS5");

            o      = c.Text;
            c.Text = "hooray!";
            Assert.IsFalse(c.IsHandleCreated, "FT1");

            o          = c.TopLevel;
            c.TopLevel = true;
            Assert.IsFalse(c.IsHandleCreated, "FT2-a");

            o          = c.TopLevel;
            c.TopLevel = false;
            Assert.IsFalse(c.IsHandleCreated, "FT2-b");

            o         = c.TopMost;
            c.TopMost = !c.TopMost;
            Assert.IsFalse(c.IsHandleCreated, "FT3");

            o = c.TransparencyKey;
            c.TransparencyKey = Color.BurlyWood;
            Assert.IsFalse(c.IsHandleCreated, "FT4");

#if !MONO
            o = c.VerticalScroll;
            Assert.IsFalse(c.IsHandleCreated, "FV1");
#endif

            o             = c.WindowState;
            c.WindowState = FormWindowState.Maximized;
            Assert.IsFalse(c.IsHandleCreated, "FW1");

            c.Dispose();
            TestHelper.RemoveWarning(o);
        }