-
Notifications
You must be signed in to change notification settings - Fork 971
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add regression test for ToolStrip (#3994)
* Add regression test for ToolStrip Adds basic clipping support to the EMF validation system and a validation test for the background rendering of ToolStrip. * Check for null
- Loading branch information
1 parent
717ea5d
commit 548ab3a
Showing
9 changed files
with
205 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
...stem.Windows.Forms.Primitives/tests/TestUtilities/Metafiles/Validators/BitBltValidator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
#nullable enable | ||
|
||
using System.Drawing; | ||
using Xunit; | ||
using static Interop; | ||
|
||
namespace System.Windows.Forms.Metafiles | ||
{ | ||
internal sealed class BitBltValidator : StateValidator | ||
{ | ||
private readonly Rectangle? _bounds; | ||
|
||
/// <param name="bounds">Optional bounds to validate.</param> | ||
/// <param name="stateValidators">Optional device context state validation to perform.</param> | ||
public BitBltValidator( | ||
RECT? bounds, | ||
params IStateValidator[] stateValidators) : base(stateValidators) | ||
{ | ||
_bounds = bounds; | ||
} | ||
|
||
public override bool ShouldValidate(Gdi32.EMR recordType) => recordType == Gdi32.EMR.BITBLT; | ||
|
||
public override unsafe void Validate(ref EmfRecord record, DeviceContextState state, out bool complete) | ||
{ | ||
base.Validate(ref record, state, out _); | ||
|
||
// We're only checking one BitBlt record, so this call completes our work. | ||
complete = true; | ||
|
||
if (_bounds.HasValue) | ||
{ | ||
EMRBITBLT* bitBlt = record.BitBltRecord; | ||
Assert.Equal(_bounds.Value, (Rectangle)bitBlt->rclBounds); | ||
} | ||
} | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...em.Windows.Forms.Primitives/tests/TestUtilities/Metafiles/Validators/ClippingValidator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
#nullable enable | ||
|
||
using Xunit; | ||
using static Interop; | ||
|
||
namespace System.Windows.Forms.Metafiles | ||
{ | ||
internal class ClippingValidator : IStateValidator | ||
{ | ||
private readonly RECT[] _clippingRectangles; | ||
public ClippingValidator(RECT[] clippingRectangles) => _clippingRectangles = clippingRectangles; | ||
|
||
public void Validate(DeviceContextState state) | ||
=> Assert.Equal(_clippingRectangles, state.ClipRegion); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ToolStripTests.Rendering.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System.Drawing; | ||
using System.Windows.Forms.Metafiles; | ||
using Xunit; | ||
using static Interop; | ||
|
||
namespace System.Windows.Forms.Tests | ||
{ | ||
public partial class ToolStripTests : IClassFixture<ThreadExceptionFixture> | ||
{ | ||
[WinFormsFact] | ||
public void ToolStrip_RendersBackgroundCorrectly() | ||
{ | ||
using Form form = new Form(); | ||
using ToolStrip toolStrip = new ToolStrip | ||
{ | ||
BackColor = Color.Blue, | ||
Size = new Size(200, 38) | ||
}; | ||
form.Controls.Add(toolStrip); | ||
|
||
// Force the handle creation | ||
_ = form.Handle; | ||
_ = toolStrip.Handle; | ||
form.PerformLayout(); | ||
|
||
using var emf = new EmfScope(); | ||
DeviceContextState state = new DeviceContextState(emf); | ||
|
||
Rectangle bounds = toolStrip.Bounds; | ||
PaintEventArgs e = new PaintEventArgs(emf, bounds); | ||
toolStrip.TestAccessor().Dynamic.OnPaintBackground(e); | ||
|
||
Rectangle bitBltBounds = new Rectangle(bounds.X, bounds.Y, bounds.Width - 1, bounds.Height - 1); | ||
|
||
RECT[] expectedRects = new RECT[] | ||
{ | ||
new RECT(0, 0, 1, 1), | ||
new RECT(bounds.Width - 3, 0, bounds.Width, 1), | ||
new RECT(bounds.Width - 1, 1, bounds.Width, 3), | ||
new RECT(0, bounds.Height - 2, 1, bounds.Height - 1), | ||
new RECT(bounds.Width - 1, bounds.Height - 2, bounds.Width, bounds.Height - 1), | ||
new RECT(0, bounds.Height - 1, 2, bounds.Height), | ||
new RECT(bounds.Width - 2, bounds.Height - 1, bounds.Width, bounds.Height) | ||
}; | ||
|
||
emf.Validate( | ||
state, | ||
Validate.BitBltValidator( | ||
bitBltBounds, | ||
State.BrushColor(Color.Blue)), | ||
Validate.BitBltValidator( | ||
bitBltBounds, | ||
State.BrushColor(form.BackColor), | ||
State.Clipping(expectedRects))); | ||
|
||
var details = emf.RecordsToString(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters