public void ByteViewer_OnPaint_InvokeWithHandle_CallsPaint() { using var image = new Bitmap(10, 10); using Graphics graphics = Graphics.FromImage(image); var eventArgs = new PaintEventArgs(graphics, Rectangle.Empty); using var control = new SubByteViewer(); int callCount = 0; PaintEventHandler handler = (sender, e) => { Assert.Same(control, sender); Assert.Same(eventArgs, e); callCount++; }; // Call with handler. control.Paint += handler; control.OnPaint(eventArgs); Assert.Equal(1, callCount); Assert.False(control.IsHandleCreated); // Remove handler. control.Paint -= handler; control.OnPaint(eventArgs); Assert.Equal(1, callCount); Assert.False(control.IsHandleCreated); }
public void ByteViewer_ScrollChanged_InvokeWithHandle_Success(object source, EventArgs e) { using var control = new SubByteViewer(); 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++; control.ScrollChanged(source, e); Assert.True(control.IsHandleCreated); Assert.Equal(1, invalidatedCallCount); Assert.Equal(0, styleChangedCallCount); Assert.Equal(0, createdCallCount); // Call again. control.ScrollChanged(source, e); Assert.True(control.IsHandleCreated); Assert.Equal(2, invalidatedCallCount); Assert.Equal(0, styleChangedCallCount); Assert.Equal(0, createdCallCount); }
public void ByteViewer_GetStyle_Invoke_ReturnsExpected(ControlStyles flag, bool expected) { using var control = new SubByteViewer(); Assert.Equal(expected, control.GetStyle(flag)); // Call again to test caching. Assert.Equal(expected, control.GetStyle(flag)); }
public void ByteViewer_ScrollChanged_Invoke_Success(object source, EventArgs e) { using var control = new SubByteViewer(); control.ScrollChanged(source, e); Assert.False(control.IsHandleCreated); // Call again. control.ScrollChanged(source, e); Assert.False(control.IsHandleCreated); }
public void ByteViewer_OnPaint_InvokeWithBytesWithHandle_CallsPaint(byte[] bytes, DisplayMode displayMode) { using var image = new Bitmap(10, 10); using Graphics graphics = Graphics.FromImage(image); var eventArgs = new PaintEventArgs(graphics, Rectangle.Empty); using var control = new SubByteViewer(); control.SetBytes(bytes); control.SetDisplayMode(displayMode); 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; PaintEventHandler handler = (sender, e) => { Assert.Same(control, sender); Assert.Same(eventArgs, e); callCount++; }; // Call with handler. control.Paint += handler; control.OnPaint(eventArgs); Assert.Equal(1, callCount); Assert.True(control.IsHandleCreated); Assert.Equal(0, invalidatedCallCount); Assert.Equal(0, styleChangedCallCount); Assert.Equal(0, createdCallCount); // Remove handler. control.Paint -= handler; control.OnPaint(eventArgs); Assert.Equal(1, callCount); Assert.True(control.IsHandleCreated); Assert.Equal(0, invalidatedCallCount); Assert.Equal(0, styleChangedCallCount); Assert.Equal(0, createdCallCount); }
public void ByteViewer_CreateParams_GetDefault_ReturnsExpected() { using var control = new SubByteViewer(); CreateParams createParams = control.CreateParams; Assert.Null(createParams.Caption); Assert.Null(createParams.ClassName); Assert.Equal(0x8, createParams.ClassStyle); Assert.Equal(0x10000, createParams.ExStyle); Assert.Equal(control.Height, createParams.Height); Assert.Equal(IntPtr.Zero, createParams.Parent); Assert.Null(createParams.Param); Assert.Equal(0x56000000, createParams.Style); Assert.Equal(control.Width, createParams.Width); Assert.Equal(0, createParams.X); Assert.Equal(0, createParams.Y); Assert.Same(createParams, control.CreateParams); Assert.False(control.IsHandleCreated); }
public void ByteViewer_OnKeyDown_Invoke_CallsKeyDown(KeyEventArgs eventArgs) { using var control = new SubByteViewer(); int callCount = 0; KeyEventHandler handler = (sender, e) => { Assert.Same(control, sender); Assert.Same(eventArgs, e); callCount++; }; // Call with handler. control.KeyDown += handler; control.OnKeyDown(eventArgs); Assert.Equal(0, callCount); // Remove handler. control.KeyDown -= handler; control.OnKeyDown(eventArgs); Assert.Equal(0, callCount); }
public void ByteViewer_OnLayout_InvokeWithHandle_CallsLayout(LayoutEventArgs eventArgs) { using var control = new SubByteViewer(); 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; LayoutEventHandler handler = (sender, e) => { Assert.Same(control, sender); Assert.Same(eventArgs, e); callCount++; }; // Call with handler. control.Layout += handler; control.OnLayout(eventArgs); Assert.Equal(1, callCount); Assert.True(control.IsHandleCreated); Assert.Equal(1, invalidatedCallCount); Assert.Equal(0, styleChangedCallCount); Assert.Equal(0, createdCallCount); // Remove handler. control.Layout -= handler; control.OnLayout(eventArgs); Assert.Equal(1, callCount); Assert.True(control.IsHandleCreated); Assert.Equal(2, invalidatedCallCount); Assert.Equal(0, styleChangedCallCount); Assert.Equal(0, createdCallCount); }
public void ByteViewer_OnLayout_Invoke_CallsLayout(LayoutEventArgs eventArgs) { using var control = new SubByteViewer(); int callCount = 0; LayoutEventHandler handler = (sender, e) => { Assert.Same(control, sender); Assert.Same(eventArgs, e); callCount++; }; // Call with handler. control.Layout += handler; control.OnLayout(eventArgs); Assert.Equal(1, callCount); Assert.False(control.IsHandleCreated); // Remove handler. control.Layout -= handler; control.OnLayout(eventArgs); Assert.Equal(1, callCount); Assert.False(control.IsHandleCreated); }
public void ByteViewer_OnHandleDestroyed_InvokeWithHandle_CallsHandleDestroyed(EventArgs eventArgs) { using var control = new SubByteViewer(); 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.HandleDestroyed += handler; control.OnHandleDestroyed(eventArgs); Assert.Equal(1, callCount); Assert.True(control.IsHandleCreated); // Remove handler. control.HandleDestroyed -= handler; control.OnHandleDestroyed(eventArgs); Assert.Equal(1, callCount); Assert.True(control.IsHandleCreated); }
public void ByteViewer_OnPaint_NullE_ThrowsNullReferenceException() { using var control = new SubByteViewer(); Assert.Throws <NullReferenceException>(() => control.OnPaint(null)); }
public void ByteViewer_GetTopLevel_Invoke_ReturnsExpected() { using var control = new SubByteViewer(); Assert.False(control.GetTopLevel()); }
public void ByteViewer_Ctor_Default() { using var control = new SubByteViewer(); Assert.Null(control.AccessibleDefaultActionDescription); Assert.Null(control.AccessibleDescription); Assert.Null(control.AccessibleName); Assert.Equal(AccessibleRole.Default, control.AccessibleRole); Assert.False(control.AllowDrop); Assert.Equal(AnchorStyles.Top | AnchorStyles.Left, control.Anchor); Assert.False(control.AutoScroll); Assert.Equal(Size.Empty, control.AutoScrollMargin); Assert.Equal(Size.Empty, control.AutoScrollMinSize); Assert.Equal(Point.Empty, control.AutoScrollPosition); Assert.False(control.AutoSize); Assert.Equal(AutoSizeMode.GrowOnly, control.AutoSizeMode); Assert.Equal(Control.DefaultBackColor, control.BackColor); Assert.Null(control.BackgroundImage); Assert.Equal(ImageLayout.Tile, control.BackgroundImageLayout); Assert.Null(control.BindingContext); Assert.Equal(BorderStyle.None, control.BorderStyle); Assert.True(control.Bottom > 0); Assert.Equal(new Rectangle(0, 0, control.Width, control.Height), control.Bounds); Assert.True(control.CanEnableIme); Assert.False(control.CanFocus); Assert.True(control.CanRaiseEvents); Assert.False(control.CanSelect); Assert.False(control.Capture); Assert.True(control.CausesValidation); Assert.Equal(TableLayoutPanelCellBorderStyle.Inset, control.CellBorderStyle); Assert.Equal(new Rectangle(0, 0, control.Width, control.Height), control.ClientRectangle); Assert.Equal(new Size(control.Width, control.Height), control.ClientSize); Assert.Equal(1, control.ColumnCount); ColumnStyle columnStyle = Assert.IsType <ColumnStyle>(Assert.Single(control.ColumnStyles)); Assert.Equal(SizeType.Percent, columnStyle.SizeType); Assert.Equal(100F, columnStyle.Width); Assert.Same(control.LayoutSettings.ColumnStyles, control.ColumnStyles); Assert.Null(control.Container); Assert.False(control.ContainsFocus); Assert.Null(control.ContextMenuStrip); Assert.NotEmpty(control.Controls); Assert.Same(control.Controls, control.Controls); Assert.False(control.Created); Assert.Equal(Cursors.Default, control.Cursor); Assert.Equal(Cursors.Default, 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(200, 100), control.DefaultSize); Assert.False(control.DesignMode); Assert.Equal(new Rectangle(0, 0, control.Width, control.Height), control.DisplayRectangle); Assert.Equal(DockStyle.None, control.Dock); Assert.NotNull(control.DockPadding); Assert.Same(control.DockPadding, control.DockPadding); Assert.Equal(0, control.DockPadding.Top); Assert.Equal(0, control.DockPadding.Bottom); Assert.Equal(0, control.DockPadding.Left); Assert.Equal(0, control.DockPadding.Right); Assert.True(control.DoubleBuffered); Assert.True(control.Enabled); Assert.NotNull(control.Events); Assert.Same(control.Events, control.Events); Assert.False(control.Focused); Assert.Equal(Control.DefaultFont, control.Font); Assert.Equal(control.Font.Height, control.FontHeight); Assert.Equal(Control.DefaultForeColor, control.ForeColor); Assert.Equal(TableLayoutPanelGrowStyle.AddRows, control.GrowStyle); Assert.True(control.HasChildren); Assert.True(control.Height > 0); Assert.NotNull(control.HorizontalScroll); Assert.Same(control.HorizontalScroll, control.HorizontalScroll); Assert.False(control.HScroll); Assert.Equal(ImeMode.NoControl, control.ImeMode); Assert.Equal(ImeMode.NoControl, control.ImeModeBase); Assert.False(control.IsAccessible); Assert.False(control.IsMirrored); Assert.NotNull(control.LayoutEngine); Assert.Same(control.LayoutEngine, control.LayoutEngine); Assert.NotNull(control.LayoutSettings); Assert.Same(control.LayoutSettings, control.LayoutSettings); Assert.Equal(0, control.Left); Assert.Equal(Point.Empty, control.Location); Assert.Equal(new Padding(3), control.Margin); Assert.Equal(Size.Empty, control.MaximumSize); Assert.Equal(Size.Empty, control.MinimumSize); Assert.Equal(Padding.Empty, control.Padding); Assert.Null(control.Parent); Assert.Equal(new Size(4, 4), control.PreferredSize); Assert.Equal("Microsoft\u00AE .NET", control.ProductName); Assert.False(control.RecreatingHandle); Assert.Null(control.Region); Assert.True(control.ResizeRedraw); Assert.True(control.Right > 0); Assert.Equal(RightToLeft.No, control.RightToLeft); Assert.Equal(1, control.RowCount); RowStyle rowStyle = Assert.IsType <RowStyle>(Assert.Single(control.RowStyles)); Assert.Equal(SizeType.Percent, rowStyle.SizeType); Assert.Equal(100F, rowStyle.Height); Assert.Same(control.LayoutSettings.RowStyles, control.RowStyles); Assert.True(control.ShowFocusCues); Assert.True(control.ShowKeyboardCues); Assert.Equal(new Size(control.Width, control.Height), control.Size); Assert.Equal(0, control.TabIndex); Assert.False(control.TabStop); Assert.Empty(control.Text); Assert.Equal(0, control.Top); Assert.Null(control.TopLevelControl); Assert.False(control.UseWaitCursor); Assert.True(control.Visible); Assert.NotNull(control.VerticalScroll); Assert.Same(control.VerticalScroll, control.VerticalScroll); Assert.False(control.VScroll); Assert.True(control.Width > 0); Assert.False(control.IsHandleCreated); }
public void ByteViewer_GetScrollState_Invoke_ReturnsExpected(int bit, bool expected) { using var control = new SubByteViewer(); Assert.Equal(expected, control.GetScrollState(bit)); }
public void ByteViewer_GetAutoSizeMode_Invoke_ReturnsExpected() { using var control = new SubByteViewer(); Assert.Equal(AutoSizeMode.GrowOnly, control.GetAutoSizeMode()); }