Exemplo n.º 1
0
        public void TextBox_OnHandleCreated_InvokeWithHandle_CallsHandleCreated(EventArgs eventArgs)
        {
            using var control = new SubTextBox();
            Assert.NotEqual(IntPtr.Zero, control.Handle);
            int          callCount = 0;
            EventHandler handler   = (sender, e) =>
            {
                Assert.Same(control, sender);
                Assert.Same(eventArgs, e);
                callCount++;
            };

            // Call with handler.
            control.HandleCreated += handler;
            control.OnHandleCreated(eventArgs);
            Assert.Equal(1, callCount);
            Assert.Equal(s_preferredHeight, control.Height);
            Assert.True(control.IsHandleCreated);

            // Remove handler.
            control.HandleCreated -= handler;
            control.OnHandleCreated(eventArgs);
            Assert.Equal(1, callCount);
            Assert.Equal(s_preferredHeight, control.Height);
            Assert.True(control.IsHandleCreated);
        }
Exemplo n.º 2
0
        public void TextBox_PasswordChar_GetWithHandle_ReturnsExpected()
        {
            using var control = new SubTextBox();
            Assert.NotEqual(IntPtr.Zero, control.Handle);
            int invalidatedCallCount = 0;

            control.Invalidated += (sender, e) => invalidatedCallCount++;
            int styleChangedCallCount = 0;

            control.StyleChanged += (sender, e) => styleChangedCallCount++;
            int createdCallCount = 0;

            control.HandleCreated += (sender, e) => createdCallCount++;

            Assert.Equal('\0', control.PasswordChar);
            Assert.True(control.IsHandleCreated);
            Assert.Equal(0, invalidatedCallCount);
            Assert.Equal(0, styleChangedCallCount);
            Assert.Equal(0, createdCallCount);

            // Get again.
            Assert.Equal('\0', control.PasswordChar);
            Assert.True(control.IsHandleCreated);
            Assert.Equal(0, invalidatedCallCount);
            Assert.Equal(0, styleChangedCallCount);
            Assert.Equal(0, createdCallCount);
        }
Exemplo n.º 3
0
        public void TextBox_GetStyle_Invoke_ReturnsExpected(ControlStyles flag, bool expected)
        {
            using var control = new SubTextBox();
            Assert.Equal(expected, control.GetStyle(flag));

            // Call again to test caching.
            Assert.Equal(expected, control.GetStyle(flag));
        }
Exemplo n.º 4
0
        public void TextBox_CanEnableIme_GetWithoutHandle_ReturnsExpected()
        {
            using var control = new SubTextBox();
            Assert.True(control.CanEnableIme);
            Assert.True(control.IsHandleCreated);

            // Get again.
            Assert.True(control.CanEnableIme);
            Assert.True(control.IsHandleCreated);
        }
Exemplo n.º 5
0
 public void TextBox_CreateAccessibilityInstance_Invoke_ReturnsExpected()
 {
     using var control = new SubTextBox();
     Control.ControlAccessibleObject instance = Assert.IsType <Control.ControlAccessibleObject>(control.CreateAccessibilityInstance());
     Assert.NotNull(instance);
     Assert.Same(control, instance.Owner);
     Assert.Equal(AccessibleRole.Text, instance.Role);
     Assert.NotSame(control.CreateAccessibilityInstance(), instance);
     Assert.NotSame(control.AccessibilityObject, instance);
 }
Exemplo n.º 6
0
        public void TextBox_PasswordChar_GetWithoutHandle_ReturnsExpected()
        {
            using var control = new SubTextBox();
            Assert.Equal('\0', control.PasswordChar);
            Assert.True(control.IsHandleCreated);

            // Get again.
            Assert.Equal('\0', control.PasswordChar);
            Assert.True(control.IsHandleCreated);
        }
Exemplo n.º 7
0
        public void TextBox_ImeModeBase_GetWithoutHandle_ReturnsExpected()
        {
            using var control = new SubTextBox();
            Assert.Equal(ImeMode.NoControl, control.ImeModeBase);
            Assert.True(control.IsHandleCreated);

            // Get again.
            Assert.Equal(ImeMode.NoControl, control.ImeModeBase);
            Assert.True(control.IsHandleCreated);
        }
Exemplo n.º 8
0
        public void TextBox_PlaceholderText_When_InAccessibility_Doesnot_Raise_TextChanged()
        {
            var          tb          = new SubTextBox();
            bool         eventRaised = false;
            EventHandler handler     = (o, e) => eventRaised = true;

            tb.TextChanged += handler;
            tb.CreateAccessibility();
            Assert.False(eventRaised);
            tb.TextChanged -= handler;
        }
Exemplo n.º 9
0
        public void TextBox_ShouldRenderPlaceHolderText(string text, bool isUserPaint, bool isIsFocused, int textCount, bool expected)
        {
            using var textBox = new SubTextBox()
                  {
                      PlaceholderText = text, IsUserPaint = isUserPaint, IsFocused = isIsFocused, TextCount = textCount
                  };

            bool result = textBox.TestAccessor().Dynamic.ShouldRenderPlaceHolderText();

            Assert.Equal(expected, result);
        }
Exemplo n.º 10
0
        public void TextBox_OnHandleDestroyed_InvokeWithHandle_CallsHandleDestroyed(bool modified, EventArgs eventArgs)
        {
            using var control = new SubTextBox
                  {
                      Text            = "Text",
                      SelectionStart  = 1,
                      SelectionLength = 2,
                      Modified        = modified
                  };
            Assert.NotEqual(IntPtr.Zero, control.Handle);
            int invalidatedCallCount = 0;

            control.Invalidated += (sender, e) => invalidatedCallCount++;
            int styleChangedCallCount = 0;

            control.StyleChanged += (sender, e) => styleChangedCallCount++;
            int createdCallCount = 0;

            control.HandleCreated += (sender, e) => createdCallCount++;
            int          callCount = 0;
            EventHandler handler   = (sender, e) =>
            {
                Assert.Same(control, sender);
                Assert.Same(eventArgs, e);
                callCount++;
            };

            // Call with handler.
            control.HandleDestroyed += handler;
            control.OnHandleDestroyed(eventArgs);
            Assert.Equal(1, callCount);
            Assert.Equal(s_preferredHeight, control.Height);
            Assert.Equal(0, control.SelectionStart);
            Assert.Equal(0, control.SelectionLength);
            Assert.Equal(modified, control.Modified);
            Assert.True(control.IsHandleCreated);
            Assert.Equal(0, invalidatedCallCount);
            Assert.Equal(0, styleChangedCallCount);
            Assert.Equal(0, createdCallCount);

            // Remove handler.
            control.HandleDestroyed -= handler;
            control.OnHandleDestroyed(eventArgs);
            Assert.Equal(1, callCount);
            Assert.Equal(s_preferredHeight, control.Height);
            Assert.Equal(0, control.SelectionStart);
            Assert.Equal(0, control.SelectionLength);
            Assert.Equal(modified, control.Modified);
            Assert.True(control.IsHandleCreated);
            Assert.Equal(0, invalidatedCallCount);
            Assert.Equal(0, styleChangedCallCount);
            Assert.Equal(0, createdCallCount);
        }
Exemplo n.º 11
0
 public void TextBox_CreateAccessibilityInstance_InvokeWithCustomRole_ReturnsExpected()
 {
     using var control = new SubTextBox
           {
               AccessibleRole = AccessibleRole.HelpBalloon
           };
     Control.ControlAccessibleObject instance = Assert.IsType <TextBoxBase.TextBoxBaseAccessibleObject>(control.CreateAccessibilityInstance());
     Assert.NotNull(instance);
     Assert.Same(control, instance.Owner);
     Assert.Equal(AccessibleRole.HelpBalloon, instance.Role);
     Assert.NotSame(control.CreateAccessibilityInstance(), instance);
     Assert.NotSame(control.AccessibilityObject, instance);
     Assert.False(control.IsHandleCreated);
 }
Exemplo n.º 12
0
        public void TextBox_CreateAccessibilityInstance_Invoke_ReturnsExpected(bool createControl, AccessibleRole expectedAccessibleRole)
        {
            using var control = new SubTextBox();
            if (createControl)
            {
                control.CreateControl();
            }

            Assert.Equal(createControl, control.IsHandleCreated);
            Control.ControlAccessibleObject instance = Assert.IsType <Control.ControlAccessibleObject>(control.CreateAccessibilityInstance());
            Assert.Equal(createControl, control.IsHandleCreated);
            Assert.NotNull(instance);
            Assert.Same(control, instance.Owner);
            Assert.Equal(expectedAccessibleRole, instance.Role);
            Assert.NotSame(control.CreateAccessibilityInstance(), instance);
            Assert.NotSame(control.AccessibilityObject, instance);
        }
Exemplo n.º 13
0
        public void TextBox_CreateParams_GetDefault_ReturnsExpected()
        {
            using var control = new SubTextBox();
            CreateParams createParams = control.CreateParams;

            Assert.Null(createParams.Caption);
            Assert.Equal("Edit", createParams.ClassName);
            Assert.Equal(0x8, createParams.ClassStyle);
            Assert.Equal(0x200, createParams.ExStyle);
            Assert.Equal(control.PreferredHeight, createParams.Height);
            Assert.Equal(IntPtr.Zero, createParams.Parent);
            Assert.Null(createParams.Param);
            Assert.Equal(0x560100C0, createParams.Style);
            Assert.Equal(100, createParams.Width);
            Assert.Equal(0, createParams.X);
            Assert.Equal(0, createParams.Y);
            Assert.Same(createParams, control.CreateParams);
            Assert.False(control.IsHandleCreated);
        }
Exemplo n.º 14
0
        public void TextBox_OnHandleDestroyed_Invoke_CallsHandleDestroyed(EventArgs eventArgs)
        {
            using var control = new SubTextBox();
            int          callCount = 0;
            EventHandler handler   = (sender, e) =>
            {
                Assert.Same(control, sender);
                Assert.Same(eventArgs, e);
                callCount++;
            };

            // Call with handler.
            control.HandleDestroyed += handler;
            control.OnHandleDestroyed(eventArgs);
            Assert.Equal(1, callCount);
            Assert.False(control.IsHandleCreated);

            // Remove handler.
            control.HandleDestroyed -= handler;
            control.OnHandleDestroyed(eventArgs);
            Assert.Equal(1, callCount);
            Assert.False(control.IsHandleCreated);
        }
Exemplo n.º 15
0
 public void TextBox_GetAutoSizeMode_Invoke_ReturnsExpected()
 {
     using var control = new SubTextBox();
     Assert.Equal(AutoSizeMode.GrowOnly, control.GetAutoSizeMode());
 }
Exemplo n.º 16
0
        public void TextBox_PlaceholderText_Overriden()
        {
            var tb = new SubTextBox();

            Assert.NotNull(tb);
        }
Exemplo n.º 17
0
        public static IEnumerable <object[]> TextBox_ShouldRenderPlaceHolderText_TestData()
        {
            // Test PlaceholderText
            var tb = new SubTextBox()
            {
                PlaceholderText = "", IsUserPaint = false, IsFocused = false, TextCount = 0
            };
            var msg = new Message()
            {
                Msg = WindowMessages.WM_PAINT
            };

            yield return(new object[] { tb, msg, false });

            // Test PlaceholderText
            tb = new SubTextBox()
            {
                PlaceholderText = null, IsUserPaint = false, IsFocused = false, TextCount = 0
            };
            msg = new Message()
            {
                Msg = WindowMessages.WM_PAINT
            };
            yield return(new object[] { tb, msg, false });

            // Test Message
            msg.Msg = WindowMessages.WM_USER;
            tb      = new SubTextBox()
            {
                PlaceholderText = "Text", IsUserPaint = false, IsFocused = false, TextCount = 0
            };
            yield return(new object[] { tb, msg, false });

            // Test UserPaint
            msg.Msg = WindowMessages.WM_PAINT;
            tb      = new SubTextBox()
            {
                PlaceholderText = "Text", IsUserPaint = true, IsFocused = false, TextCount = 0
            };
            yield return(new object[] { tb, msg, false });

            // Test Focused
            msg.Msg = WindowMessages.WM_PAINT;
            tb      = new SubTextBox()
            {
                PlaceholderText = "Text", IsUserPaint = false, IsFocused = true, TextCount = 0
            };
            yield return(new object[] { tb, msg, false });

            // Test TextLength
            msg.Msg = WindowMessages.WM_PAINT;
            tb      = new SubTextBox()
            {
                PlaceholderText = "Text", IsUserPaint = false, IsFocused = false, TextCount = 1
            };
            yield return(new object[] { tb, msg, false });

            // Test WM_PAINT
            tb = new SubTextBox()
            {
                PlaceholderText = "Text", IsUserPaint = false, IsFocused = false, TextCount = 0
            };
            msg.Msg = WindowMessages.WM_PAINT;
            yield return(new object[] { tb, msg, true });

            // Test WM_KILLFOCUS
            tb = new SubTextBox()
            {
                PlaceholderText = "Text", IsUserPaint = false, IsFocused = false, TextCount = 0
            };
            msg.Msg = WindowMessages.WM_KILLFOCUS;
            yield return(new object[] { tb, msg, true });
        }
Exemplo n.º 18
0
        public void TextBox_Ctor_Default()
        {
            using var control = new SubTextBox();
            Assert.False(control.AcceptsReturn);
            Assert.False(control.AcceptsTab);
            Assert.False(control.AllowDrop);
            Assert.Equal(AnchorStyles.Top | AnchorStyles.Left, control.Anchor);
            Assert.Empty(control.AutoCompleteCustomSource);
            Assert.Same(control.AutoCompleteCustomSource, control.AutoCompleteCustomSource);
            Assert.Equal(AutoCompleteMode.None, control.AutoCompleteMode);
            Assert.Equal(AutoCompleteSource.None, control.AutoCompleteSource);
            Assert.True(control.AutoSize);
            Assert.Equal(SystemColors.Window, control.BackColor);
            Assert.Null(control.BackgroundImage);
            Assert.Equal(ImageLayout.Tile, control.BackgroundImageLayout);
            Assert.Null(control.BindingContext);
            Assert.Equal(BorderStyle.Fixed3D, control.BorderStyle);
            Assert.Equal(control.PreferredHeight, control.Bottom);
            Assert.Equal(new Rectangle(0, 0, 100, control.PreferredHeight), control.Bounds);
            Assert.True(control.CanRaiseEvents);
            Assert.False(control.CanUndo);
            Assert.True(control.CausesValidation);
            Assert.Equal(CharacterCasing.Normal, control.CharacterCasing);
            Assert.Equal(new Size(96, control.PreferredHeight - 4), control.ClientSize);
            Assert.Equal(new Rectangle(0, 0, 96, control.PreferredHeight - 4), control.ClientRectangle);
            Assert.Null(control.Container);
            Assert.Null(control.ContextMenuStrip);
            Assert.Empty(control.Controls);
            Assert.Same(control.Controls, control.Controls);
            Assert.False(control.Created);
            Assert.Same(Cursors.IBeam, control.Cursor);
            Assert.Same(Cursors.IBeam, control.DefaultCursor);
            Assert.Equal(ImeMode.Inherit, control.DefaultImeMode);
            Assert.Equal(new Padding(3), control.DefaultMargin);
            Assert.Equal(Size.Empty, control.DefaultMaximumSize);
            Assert.Equal(Size.Empty, control.DefaultMinimumSize);
            Assert.Equal(Padding.Empty, control.DefaultPadding);
            Assert.Equal(new Size(100, control.PreferredHeight), control.DefaultSize);
            Assert.False(control.DesignMode);
            Assert.Equal(new Rectangle(0, 0, 96, control.PreferredHeight - 4), control.DisplayRectangle);
            Assert.Equal(DockStyle.None, control.Dock);
            Assert.False(control.DoubleBuffered);
            Assert.True(control.Enabled);
            Assert.NotNull(control.Events);
            Assert.Same(control.Events, control.Events);
            Assert.Equal(Control.DefaultFont, control.Font);
            Assert.Equal(control.Font.Height, control.FontHeight);
            Assert.Equal(SystemColors.WindowText, control.ForeColor);
            Assert.False(control.HasChildren);
            Assert.Equal(control.PreferredHeight, control.Height);
            Assert.True(control.HideSelection);
            Assert.NotNull(control.LayoutEngine);
            Assert.Same(control.LayoutEngine, control.LayoutEngine);
            Assert.Equal(0, control.Left);
            Assert.Empty(control.Lines);
            Assert.Equal(Point.Empty, control.Location);
            Assert.Equal(new Padding(3), control.Margin);
            Assert.Equal(Size.Empty, control.MaximumSize);
            Assert.Equal(32767, control.MaxLength);
            Assert.Equal(Size.Empty, control.MinimumSize);
            Assert.False(control.Modified);
            Assert.False(control.Multiline);
            Assert.Equal(Padding.Empty, control.Padding);
            Assert.Null(control.Parent);
            Assert.Equal("Microsoft\u00AE .NET", control.ProductName);
            Assert.Equal(4, control.PreferredSize.Width);
            Assert.True(control.PreferredSize.Height > 0);
            Assert.True(control.PreferredHeight > 0);
            Assert.False(control.ReadOnly);
            Assert.False(control.RecreatingHandle);
            Assert.Null(control.Region);
            Assert.False(control.ResizeRedraw);
            Assert.Equal(100, control.Right);
            Assert.Equal(RightToLeft.No, control.RightToLeft);
            Assert.Equal(ScrollBars.None, control.ScrollBars);
            Assert.Empty(control.SelectedText);
            Assert.Equal(0, control.SelectionLength);
            Assert.Equal(0, control.SelectionStart);
            Assert.True(control.ShowFocusCues);
            Assert.True(control.ShowKeyboardCues);
            Assert.Null(control.Site);
            Assert.Equal(new Size(100, control.PreferredHeight), control.Size);
            Assert.Equal(0, control.TabIndex);
            Assert.True(control.TabStop);
            Assert.Empty(control.Text);
            Assert.Equal(HorizontalAlignment.Left, control.TextAlign);
            Assert.Equal(0, control.TextLength);
            Assert.Equal(0, control.Top);
            Assert.Null(control.TopLevelControl);
            Assert.False(control.UseSystemPasswordChar);
            Assert.True(control.Visible);
            Assert.Equal(100, control.Width);
            Assert.True(control.WordWrap);

            Assert.False(control.IsHandleCreated);
        }
Exemplo n.º 19
0
 public void TextBox_GetTopLevel_Invoke_ReturnsExpected()
 {
     using var control = new SubTextBox();
     Assert.False(control.GetTopLevel());
 }