Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Commit

Permalink
Merge pull request #23089 from mellinoe/system.drawing-drawstring-tests
Browse files Browse the repository at this point in the history
Add two tests for Graphics.DrawString.
  • Loading branch information
mellinoe authored Aug 10, 2017
2 parents 47b0136 + f97a840 commit 277411f
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/System.Drawing.Common/tests/GraphicsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Drawing.Text;
using System.Linq;
using Xunit;
using Xunit.Sdk;

namespace System.Drawing.Tests
{
Expand Down Expand Up @@ -3460,6 +3461,32 @@ public void Clear_Disposed_ThrowsArgumentException()
}
}

[ActiveIssue(20884, TestPlatforms.AnyUnix)]
[ConditionalFact(Helpers.GdiplusIsAvailable)]
public void DrawString_DefaultFont_Succeeds()
{
using (var image = new Bitmap(50, 50))
using (Graphics graphics = Graphics.FromImage(image))
{
graphics.DrawString("Test text", SystemFonts.DefaultFont, Brushes.White, new Point());
Helpers.VerifyBitmapNotBlank(image);
}
}

[ActiveIssue(20884, TestPlatforms.AnyUnix)]
[ConditionalFact(Helpers.GdiplusIsAvailable)]
public void DrawString_CompositingModeSourceCopy_ThrowsArgumentException()
{
using (var image = new Bitmap(10, 10))
using (Graphics graphics = Graphics.FromImage(image))
{
graphics.CompositingMode = CompositingMode.SourceCopy;
AssertExtensions.Throws<ArgumentException>(
null,
() => graphics.DrawString("Test text", SystemFonts.DefaultFont, Brushes.White, new Point()));
}
}

private static void VerifyGraphics(Graphics graphics, RectangleF expectedVisibleClipBounds)
{
Assert.NotNull(graphics.Clip);
Expand Down
18 changes: 18 additions & 0 deletions src/System.Drawing.Common/tests/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,5 +174,23 @@ private struct RECT
public int Right;
public int Bottom;
}

public static void VerifyBitmapNotBlank(Bitmap bmp)
{
Color emptyColor = Color.FromArgb(0);
for (int y = 0; y < bmp.Height; y++)
{
for (int x = 0; x < bmp.Width; x++)
{
Color pixel = bmp.GetPixel(x, y);
if (!pixel.Equals(emptyColor))
{
return;
}
}
}

throw new XunitException("The entire image was blank.");
}
}
}

0 comments on commit 277411f

Please sign in to comment.