Skip to content

Commit

Permalink
Remove unused local variables and methods from System.Drawing.Common
Browse files Browse the repository at this point in the history
Remove unused locals, and update a few unit tests that has no asserts.
  • Loading branch information
MattKotsenas committed Jul 17, 2020
1 parent ba40348 commit fb2055e
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@ public void Render_ParameterlessWithTargetGraphics_Success()
[ConditionalFact(Helpers.IsDrawingSupported)]
public void Render_ParameterlessWithNullTargetGraphics_Success()
{
Color color = Color.FromArgb(255, 0, 0, 0);

using (var context = new BufferedGraphicsContext())
using (var image = new Bitmap(3, 3))
using (Graphics graphics = Graphics.FromImage(image))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,6 @@ public void Rewind_Success()
gp.StartFigure();
gp.AddLine(20, 21, 22, 23);
gp.AddBezier(5, 6, 7, 8, 9, 10, 11, 12);
byte[] types = new byte[] { 0, 3, 3, 3, 1, 33, 0, 1 };

using (GraphicsPathIterator gpi = new GraphicsPathIterator(gp))
{
Expand Down
2 changes: 1 addition & 1 deletion src/libraries/System.Drawing.Common/tests/FontTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@ public void FromLogFont_UnblittableStruct()
using (var image = new Bitmap(10, 10))
using (Graphics graphics = Graphics.FromImage(image))
{
IntPtr hdc = graphics.GetHdc();
graphics.GetHdc();
try
{
var logFont = new UnblittableLOGFONT
Expand Down
69 changes: 33 additions & 36 deletions src/libraries/System.Drawing.Common/tests/GraphicsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void GetHdc_NotReleased_ThrowsInvalidOperationException()
using (var bitmap = new Bitmap(10, 10))
using (Graphics graphics = Graphics.FromImage(bitmap))
{
IntPtr hdc = graphics.GetHdc();
graphics.GetHdc();
try
{
Assert.Throws<InvalidOperationException>(() => graphics.GetHdc());
Expand Down Expand Up @@ -416,7 +416,7 @@ public void CompositingMode_GetSetWhenBusy_ThrowsInvalidOperationException()
using (var image = new Bitmap(10, 10))
using (Graphics graphics = Graphics.FromImage(image))
{
IntPtr hdc = graphics.GetHdc();
graphics.GetHdc();
try
{
Assert.Throws<InvalidOperationException>(() => graphics.CompositingMode);
Expand Down Expand Up @@ -510,7 +510,7 @@ public void CompositingQuality_GetSetWhenBusy_ThrowsInvalidOperationException()
using (var image = new Bitmap(10, 10))
using (Graphics graphics = Graphics.FromImage(image))
{
IntPtr hdc = graphics.GetHdc();
graphics.GetHdc();
try
{
Assert.Throws<InvalidOperationException>(() => graphics.CompositingQuality);
Expand Down Expand Up @@ -573,7 +573,7 @@ public void DpiX_GetWhenBusy_ThrowsInvalidOperationException()
using (var image = new Bitmap(10, 10))
using (Graphics graphics = Graphics.FromImage(image))
{
IntPtr hdc = graphics.GetHdc();
graphics.GetHdc();
try
{
Assert.Throws<InvalidOperationException>(() => graphics.DpiX);
Expand Down Expand Up @@ -604,7 +604,7 @@ public void DpiY_GetWhenBusy_ThrowsInvalidOperationException()
using (var image = new Bitmap(10, 10))
using (Graphics graphics = Graphics.FromImage(image))
{
IntPtr hdc = graphics.GetHdc();
graphics.GetHdc();
try
{
Assert.Throws<InvalidOperationException>(() => graphics.DpiX);
Expand Down Expand Up @@ -656,7 +656,7 @@ public void Flush_Busy_ThrowsInvalidOperationException()
using (var image = new Bitmap(10, 10))
using (Graphics graphics = Graphics.FromImage(image))
{
IntPtr hdc = graphics.GetHdc();
graphics.GetHdc();
try
{
Assert.Throws<InvalidOperationException>(() => graphics.Flush());
Expand Down Expand Up @@ -730,7 +730,7 @@ public void InterpolationMode_GetSetWhenBusy_ThrowsInvalidOperationException()
using (var image = new Bitmap(10, 10))
using (Graphics graphics = Graphics.FromImage(image))
{
IntPtr hdc = graphics.GetHdc();
graphics.GetHdc();
try
{
Assert.Throws<InvalidOperationException>(() => graphics.InterpolationMode);
Expand Down Expand Up @@ -792,7 +792,7 @@ public void PageScale_GetSetWhenBusy_ThrowsInvalidOperationException()
using (var image = new Bitmap(10, 10))
using (Graphics graphics = Graphics.FromImage(image))
{
IntPtr hdc = graphics.GetHdc();
graphics.GetHdc();
try
{
Assert.Throws<InvalidOperationException>(() => graphics.PageScale);
Expand Down Expand Up @@ -864,7 +864,7 @@ public void PageUnit_GetSetWhenBusy_ThrowsInvalidOperationException()
using (var image = new Bitmap(10, 10))
using (Graphics graphics = Graphics.FromImage(image))
{
IntPtr hdc = graphics.GetHdc();
graphics.GetHdc();
try
{
Assert.Throws<InvalidOperationException>(() => graphics.PageUnit);
Expand Down Expand Up @@ -935,7 +935,7 @@ public void PixelOffsetMode_GetSetWhenBusy_ThrowsInvalidOperationException()
using (var image = new Bitmap(10, 10))
using (Graphics graphics = Graphics.FromImage(image))
{
IntPtr hdc = graphics.GetHdc();
graphics.GetHdc();
try
{
Assert.Throws<InvalidOperationException>(() => graphics.PixelOffsetMode);
Expand Down Expand Up @@ -1004,7 +1004,6 @@ public static IEnumerable<object[]> RenderingOrigin_TestData()
[MemberData(nameof(RenderingOrigin_TestData))]
public void RenderingOrigin_SetToCustom_RendersExpected(Point renderingOrigin, Color[][] expectedRendering)
{
Color empty = Color.FromArgb(255, 0, 0, 0);
Color red = Color.FromArgb(Color.Red.ToArgb());

using (var image = new Bitmap(3, 3))
Expand All @@ -1026,7 +1025,7 @@ public void RenderingOrigin_GetSetWhenBusy_ThrowsInvalidOperationException()
using (var image = new Bitmap(10, 10))
using (Graphics graphics = Graphics.FromImage(image))
{
IntPtr hdc = graphics.GetHdc();
graphics.GetHdc();
try
{
Assert.Throws<InvalidOperationException>(() => graphics.RenderingOrigin);
Expand Down Expand Up @@ -1097,7 +1096,7 @@ public void SmoothingMode_GetSetWhenBusy_ThrowsInvalidOperationException()
using (var image = new Bitmap(10, 10))
using (Graphics graphics = Graphics.FromImage(image))
{
IntPtr hdc = graphics.GetHdc();
graphics.GetHdc();
try
{
Assert.Throws<InvalidOperationException>(() => graphics.SmoothingMode);
Expand Down Expand Up @@ -1156,7 +1155,7 @@ public void TextContrast_GetSetWhenBusy_ThrowsInvalidOperationException()
using (var image = new Bitmap(10, 10))
using (Graphics graphics = Graphics.FromImage(image))
{
IntPtr hdc = graphics.GetHdc();
graphics.GetHdc();
try
{
Assert.Throws<InvalidOperationException>(() => graphics.TextContrast);
Expand Down Expand Up @@ -1218,7 +1217,7 @@ public void TextRenderingHint_GetSetWhenBusy_ThrowsInvalidOperationException()
using (var image = new Bitmap(10, 10))
using (Graphics graphics = Graphics.FromImage(image))
{
IntPtr hdc = graphics.GetHdc();
graphics.GetHdc();
try
{
Assert.Throws<InvalidOperationException>(() => graphics.TextRenderingHint);
Expand Down Expand Up @@ -1315,7 +1314,7 @@ public void Transform_GetSetWhenBusy_ThrowsInvalidOperationException()
using (Graphics graphics = Graphics.FromImage(image))
using (var matrix = new Matrix())
{
IntPtr hdc = graphics.GetHdc();
graphics.GetHdc();
try
{
Assert.Throws<InvalidOperationException>(() => graphics.Transform);
Expand Down Expand Up @@ -1364,7 +1363,7 @@ public void ResetTransform_Busy_ThrowsInvalidOperationException()
using (var image = new Bitmap(10, 10))
using (Graphics graphics = Graphics.FromImage(image))
{
IntPtr hdc = graphics.GetHdc();
graphics.GetHdc();
try
{
Assert.Throws<InvalidOperationException>(() => graphics.ResetTransform());
Expand Down Expand Up @@ -1483,7 +1482,7 @@ public void MultiplyTransform_Busy_ThrowsInvalidOperationException()
using (Graphics graphics = Graphics.FromImage(image))
using (var matrix = new Matrix())
{
IntPtr hdc = graphics.GetHdc();
graphics.GetHdc();
try
{
Assert.Throws<InvalidOperationException>(() => graphics.MultiplyTransform(matrix));
Expand Down Expand Up @@ -1570,7 +1569,7 @@ public void TranslateTransform_Busy_ThrowsInvalidOperationException()
using (var image = new Bitmap(10, 10))
using (Graphics graphics = Graphics.FromImage(image))
{
IntPtr hdc = graphics.GetHdc();
graphics.GetHdc();
try
{
Assert.Throws<InvalidOperationException>(() => graphics.TranslateTransform(0, 0));
Expand Down Expand Up @@ -1664,7 +1663,7 @@ public void ScaleTransform_Busy_ThrowsInvalidOperationException()
using (var image = new Bitmap(10, 10))
using (Graphics graphics = Graphics.FromImage(image))
{
IntPtr hdc = graphics.GetHdc();
graphics.GetHdc();
try
{
Assert.Throws<InvalidOperationException>(() => graphics.ScaleTransform(0, 0));
Expand Down Expand Up @@ -1751,7 +1750,7 @@ public void RotateTransform_Busy_ThrowsInvalidOperationException()
using (var image = new Bitmap(10, 10))
using (Graphics graphics = Graphics.FromImage(image))
{
IntPtr hdc = graphics.GetHdc();
graphics.GetHdc();
try
{
Assert.Throws<InvalidOperationException>(() => graphics.RotateTransform(0));
Expand Down Expand Up @@ -1814,8 +1813,6 @@ public void CopyFromScreen_OutOfRange_DoesNotAffectGraphics(int sourceX, int sou
[InlineData(1, 1, 2, 2, 3, 3)]
public void CopyFromScreen_ValidRange_AffectsGraphics(int sourceX, int sourceY, int destinationX, int destinationY, int width, int height)
{
Size screenSize = Helpers.GetHWndRect(IntPtr.Zero).Size;

Color color = Color.FromArgb(2, 3, 4);
using (var image = new Bitmap(10, 10))
using (Graphics graphics = Graphics.FromImage(image))
Expand Down Expand Up @@ -1934,7 +1931,7 @@ public void CopyFromScreen_Busy_ThrowsInvalidOperationException()
using (var image = new Bitmap(10, 10))
using (Graphics graphics = Graphics.FromImage(image))
{
IntPtr hdc = graphics.GetHdc();
graphics.GetHdc();
try
{
Assert.Throws<InvalidOperationException>(() => graphics.CopyFromScreen(0, 0, 0, 0, Size.Empty));
Expand Down Expand Up @@ -2198,7 +2195,7 @@ public void TransformPoints_Busy_ThrowsInvalidOperationException()
using (var image = new Bitmap(10, 10))
using (Graphics graphics = Graphics.FromImage(image))
{
IntPtr hdc = graphics.GetHdc();
graphics.GetHdc();
try
{
Assert.Throws<InvalidOperationException>(() => graphics.TransformPoints(CoordinateSpace.Page, CoordinateSpace.Page, new Point[] { Point.Empty }));
Expand Down Expand Up @@ -2250,7 +2247,7 @@ public void GetNearestColor_Busy_ThrowsInvalidOperationException()
using (var image = new Bitmap(10, 10))
using (Graphics graphics = Graphics.FromImage(image))
{
IntPtr hdc = graphics.GetHdc();
graphics.GetHdc();
try
{
Assert.Throws<InvalidOperationException>(() => graphics.GetNearestColor(Color.Red));
Expand Down Expand Up @@ -2344,7 +2341,7 @@ public void DrawArc_Busy_ThrowsInvalidOperationException()
using (Graphics graphics = Graphics.FromImage(image))
using (var pen = new Pen(Color.Red))
{
IntPtr hdc = graphics.GetHdc();
graphics.GetHdc();
try
{
Assert.Throws<InvalidOperationException>(() => graphics.DrawArc(pen, new Rectangle(0, 0, 1, 1), 0, 90));
Expand Down Expand Up @@ -2412,7 +2409,7 @@ public void DrawRectangle_Busy_ThrowsInvalidOperationException()
using (Graphics graphics = Graphics.FromImage(image))
using (var pen = new Pen(Color.Red))
{
IntPtr hdc = graphics.GetHdc();
graphics.GetHdc();
try
{
Assert.Throws<InvalidOperationException>(() => graphics.DrawRectangle(pen, new Rectangle(0, 0, 1, 1)));
Expand Down Expand Up @@ -2498,7 +2495,7 @@ public void DrawRectangles_Busy_ThrowsInvalidOperationException()
using (Graphics graphics = Graphics.FromImage(image))
using (var pen = new Pen(Color.Red))
{
IntPtr hdc = graphics.GetHdc();
graphics.GetHdc();
try
{
Assert.Throws<InvalidOperationException>(() => graphics.DrawRectangles(pen, new Rectangle[2]));
Expand Down Expand Up @@ -2563,7 +2560,7 @@ public void DrawEllipse_Busy_ThrowsInvalidOperationException()
using (Graphics graphics = Graphics.FromImage(image))
using (var pen = new Pen(Color.Red))
{
IntPtr hdc = graphics.GetHdc();
graphics.GetHdc();
try
{
Assert.Throws<InvalidOperationException>(() => graphics.DrawEllipse(pen, new Rectangle(0, 0, 1, 1)));
Expand Down Expand Up @@ -2661,7 +2658,7 @@ public void DrawPie_Busy_ThrowsInvalidOperationException()
using (Graphics graphics = Graphics.FromImage(image))
using (var pen = new Pen(Color.Red))
{
IntPtr hdc = graphics.GetHdc();
graphics.GetHdc();
try
{
Assert.Throws<InvalidOperationException>(() => graphics.DrawPie(pen, new Rectangle(0, 0, 1, 1), 0, 90));
Expand Down Expand Up @@ -2751,7 +2748,7 @@ public void DrawPolygon_Busy_ThrowsInvalidOperationException()
using (Graphics graphics = Graphics.FromImage(image))
using (var pen = new Pen(Color.Red))
{
IntPtr hdc = graphics.GetHdc();
graphics.GetHdc();
try
{
Assert.Throws<InvalidOperationException>(() => graphics.DrawPolygon(pen, new Point[2]));
Expand Down Expand Up @@ -2837,7 +2834,7 @@ public void DrawPath_Busy_ThrowsInvalidOperationException()
using (var pen = new Pen(Color.Red))
using (var graphicsPath = new GraphicsPath())
{
IntPtr hdc = graphics.GetHdc();
graphics.GetHdc();
try
{
Assert.Throws<InvalidOperationException>(() => graphics.DrawPath(pen, graphicsPath));
Expand Down Expand Up @@ -2961,7 +2958,7 @@ public void DrawCurve_Busy_ThrowsInvalidOperationException()
using (Graphics graphics = Graphics.FromImage(image))
using (var pen = new Pen(Color.Red))
{
IntPtr hdc = graphics.GetHdc();
graphics.GetHdc();
try
{
Assert.Throws<InvalidOperationException>(() => graphics.DrawCurve(pen, new Point[2]));
Expand Down Expand Up @@ -3066,7 +3063,7 @@ public void DrawClosedCurve_Busy_ThrowsInvalidOperationException()
using (Graphics graphics = Graphics.FromImage(image))
using (var pen = new Pen(Color.Red))
{
IntPtr hdc = graphics.GetHdc();
graphics.GetHdc();
try
{
Assert.Throws<InvalidOperationException>(() => graphics.DrawClosedCurve(pen, new Point[3]));
Expand Down Expand Up @@ -3125,7 +3122,7 @@ public void Clear_Busy_ThrowsInvalidOperationException()
using (Graphics graphics = Graphics.FromImage(image))
using (var pen = new Pen(Color.Red))
{
IntPtr hdc = graphics.GetHdc();
graphics.GetHdc();
try
{
Assert.Throws<InvalidOperationException>(() => graphics.Clear(Color.Red));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public void DrawBezier_Busy_ThrowsInvalidOperationException()
using (Graphics graphics = Graphics.FromImage(image))
using (var pen = new Pen(Color.Red))
{
IntPtr hdc = graphics.GetHdc();
graphics.GetHdc();
try
{
Assert.Throws<InvalidOperationException>(() => graphics.DrawBezier(pen, 1, 2, 3, 4, 5, 6, 7, 8));
Expand Down Expand Up @@ -190,7 +190,7 @@ public void DrawBeziers_Busy_ThrowsInvalidOperationException()
using (Graphics graphics = Graphics.FromImage(image))
using (var pen = new Pen(Color.Red))
{
IntPtr hdc = graphics.GetHdc();
graphics.GetHdc();
try
{
Assert.Throws<InvalidOperationException>(() => graphics.DrawBeziers(pen, new Point[2]));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public void DrawLine_Busy_ThrowsInvalidOperationException()
using (Graphics graphics = Graphics.FromImage(image))
using (var pen = new Pen(Color.Red))
{
IntPtr hdc = graphics.GetHdc();
graphics.GetHdc();
try
{
Assert.Throws<InvalidOperationException>(() => graphics.DrawLine(pen, Point.Empty, Point.Empty));
Expand Down Expand Up @@ -166,7 +166,7 @@ public void DrawLines_Busy_ThrowsInvalidOperationException()
using (Graphics graphics = Graphics.FromImage(image))
using (var pen = new Pen(Color.Red))
{
IntPtr hdc = graphics.GetHdc();
graphics.GetHdc();
try
{
Assert.Throws<InvalidOperationException>(() => graphics.DrawLines(pen, new Point[2]));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public void AccessToNotExistingElement_ThrowsIndexOutOfRangeException()
new float[] { 4.0f, 4.1f, 4.2f, 4.3f, 4.4f, 4.5f },
new float[] { 5.0f, 5.1f, 5.2f, 5.3f, 5.4f, 5.5f }
});
Assert.Throws<IndexOutOfRangeException>(() => { var x = cm[5, 5]; });
Assert.Throws<IndexOutOfRangeException>(() => _ = cm[5, 5]);
}

[ConditionalFact(Helpers.IsDrawingSupported)]
Expand Down
Loading

0 comments on commit fb2055e

Please sign in to comment.