From a8dedaebddfb147a25551b877c21f6d0bb907bff Mon Sep 17 00:00:00 2001 From: Josip Medved Date: Fri, 3 Dec 2021 21:31:01 -0800 Subject: [PATCH 1/9] Added DrawRectangle overload accepting RectangleF --- .../System.Drawing.Common/src/System/Drawing/Graphics.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/libraries/System.Drawing.Common/src/System/Drawing/Graphics.cs b/src/libraries/System.Drawing.Common/src/System/Drawing/Graphics.cs index 4917e8f33d831..96031f2d2b425 100644 --- a/src/libraries/System.Drawing.Common/src/System/Drawing/Graphics.cs +++ b/src/libraries/System.Drawing.Common/src/System/Drawing/Graphics.cs @@ -708,6 +708,14 @@ public void DrawBezier(Pen pen, Point pt1, Point pt2, Point pt3, Point pt4) DrawBezier(pen, pt1.X, pt1.Y, pt2.X, pt2.Y, pt3.X, pt3.Y, pt4.X, pt4.Y); } + /// + /// Draws the outline of a rectangle specified by . + /// + public void DrawRectangle(Pen pen, RectangleF rect) + { + DrawRectangle(pen, rect.X, rect.Y, rect.Width, rect.Height); + } + /// /// Draws the outline of a rectangle specified by . /// From dc886b406912acd2cf545602168c3126adf39546 Mon Sep 17 00:00:00 2001 From: Josip Medved Date: Mon, 6 Dec 2021 00:04:48 -0800 Subject: [PATCH 2/9] Added DrawRectangle overload to reference assembly file --- src/libraries/System.Drawing.Common/ref/System.Drawing.Common.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libraries/System.Drawing.Common/ref/System.Drawing.Common.cs b/src/libraries/System.Drawing.Common/ref/System.Drawing.Common.cs index 8c057f5369b77..15ae4c9f2bf73 100644 --- a/src/libraries/System.Drawing.Common/ref/System.Drawing.Common.cs +++ b/src/libraries/System.Drawing.Common/ref/System.Drawing.Common.cs @@ -506,6 +506,7 @@ public void DrawPie(System.Drawing.Pen pen, float x, float y, float width, float public void DrawPolygon(System.Drawing.Pen pen, System.Drawing.PointF[] points) { } public void DrawPolygon(System.Drawing.Pen pen, System.Drawing.Point[] points) { } public void DrawRectangle(System.Drawing.Pen pen, System.Drawing.Rectangle rect) { } + public void DrawRectangle(System.Drawing.Pen pen, System.Drawing.RectangleF rect) { } public void DrawRectangle(System.Drawing.Pen pen, int x, int y, int width, int height) { } public void DrawRectangle(System.Drawing.Pen pen, float x, float y, float width, float height) { } public void DrawRectangles(System.Drawing.Pen pen, System.Drawing.RectangleF[] rects) { } From da90c4dc9e79e7ec633c493351d2ffb1aa169d3a Mon Sep 17 00:00:00 2001 From: Josip Medved Date: Tue, 14 Dec 2021 20:41:20 -0800 Subject: [PATCH 3/9] Added FillPie overload accepting RectangleF --- .../System.Drawing.Common/ref/System.Drawing.Common.cs | 1 + .../System.Drawing.Common/src/System/Drawing/Graphics.cs | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/src/libraries/System.Drawing.Common/ref/System.Drawing.Common.cs b/src/libraries/System.Drawing.Common/ref/System.Drawing.Common.cs index 15ae4c9f2bf73..bc20c0aa6679b 100644 --- a/src/libraries/System.Drawing.Common/ref/System.Drawing.Common.cs +++ b/src/libraries/System.Drawing.Common/ref/System.Drawing.Common.cs @@ -568,6 +568,7 @@ public void FillEllipse(System.Drawing.Brush brush, int x, int y, int width, int public void FillEllipse(System.Drawing.Brush brush, float x, float y, float width, float height) { } public void FillPath(System.Drawing.Brush brush, System.Drawing.Drawing2D.GraphicsPath path) { } public void FillPie(System.Drawing.Brush brush, System.Drawing.Rectangle rect, float startAngle, float sweepAngle) { } + public void FillPie(System.Drawing.Brush brush, System.Drawing.RectangleF rect, float startAngle, float sweepAngle) { } public void FillPie(System.Drawing.Brush brush, int x, int y, int width, int height, int startAngle, int sweepAngle) { } public void FillPie(System.Drawing.Brush brush, float x, float y, float width, float height, float startAngle, float sweepAngle) { } public void FillPolygon(System.Drawing.Brush brush, System.Drawing.PointF[] points) { } diff --git a/src/libraries/System.Drawing.Common/src/System/Drawing/Graphics.cs b/src/libraries/System.Drawing.Common/src/System/Drawing/Graphics.cs index 96031f2d2b425..bcbce961f2884 100644 --- a/src/libraries/System.Drawing.Common/src/System/Drawing/Graphics.cs +++ b/src/libraries/System.Drawing.Common/src/System/Drawing/Graphics.cs @@ -1333,6 +1333,14 @@ public void FillPie(Brush brush, Rectangle rect, float startAngle, float sweepAn FillPie(brush, rect.X, rect.Y, rect.Width, rect.Height, startAngle, sweepAngle); } + /// + /// Fills the interior of a pie section defined by an ellipse and two radial lines. + /// + public void FillPie(Brush brush, RectangleF rect, float startAngle, float sweepAngle) + { + FillPie(brush, rect.X, rect.Y, rect.Width, rect.Height, startAngle, sweepAngle); + } + /// /// Fills the interior of a pie section defined by an ellipse and two radial lines. /// From 797a39dfd35ecf98c907f0bf0f8bc34a56f054c6 Mon Sep 17 00:00:00 2001 From: Josip Medved Date: Wed, 15 Dec 2021 16:27:11 -0800 Subject: [PATCH 4/9] Added test cases for DrawRectangle accepting RectangleF --- src/libraries/System.Drawing.Common/tests/GraphicsTests.cs | 4 ++++ .../tests/mono/System.Drawing/GraphicsTests.cs | 2 ++ 2 files changed, 6 insertions(+) diff --git a/src/libraries/System.Drawing.Common/tests/GraphicsTests.cs b/src/libraries/System.Drawing.Common/tests/GraphicsTests.cs index 8c0f280b86361..77abedf48999a 100644 --- a/src/libraries/System.Drawing.Common/tests/GraphicsTests.cs +++ b/src/libraries/System.Drawing.Common/tests/GraphicsTests.cs @@ -2385,6 +2385,7 @@ public void DrawRectangle_NullPen_ThrowsArgumentNullException() using (Graphics graphics = Graphics.FromImage(image)) { AssertExtensions.Throws("pen", () => graphics.DrawRectangle(null, new Rectangle(0, 0, 1, 1))); + AssertExtensions.Throws("pen", () => graphics.DrawRectangle(null, new RectangleF(0f, 0f, 1f, 1f))); AssertExtensions.Throws("pen", () => graphics.DrawRectangle(null, 0, 0, 1, 1)); AssertExtensions.Throws("pen", () => graphics.DrawRectangle(null, 0f, 0f, 1f, 1f)); } @@ -2401,6 +2402,7 @@ public void DrawRectangle_DisposedPen_ThrowsArgumentException() AssertExtensions.Throws(null, () => graphics.DrawRectangle(pen, new Rectangle(0, 0, 1, 1))); + AssertExtensions.Throws(null, () => graphics.DrawRectangle(pen, new RectangleF(0f, 0f, 1f, 1f))); AssertExtensions.Throws(null, () => graphics.DrawRectangle(pen, 0, 0, 1, 1)); AssertExtensions.Throws(null, () => graphics.DrawRectangle(pen, 0f, 0f, 1f, 1f)); } @@ -2418,6 +2420,7 @@ public void DrawRectangle_Busy_ThrowsInvalidOperationException() try { Assert.Throws(() => graphics.DrawRectangle(pen, new Rectangle(0, 0, 1, 1))); + Assert.Throws(() => graphics.DrawRectangle(pen, new RectangleF(0f, 0f, 1f, 1f))); Assert.Throws(() => graphics.DrawRectangle(pen, 0, 0, 1, 1)); Assert.Throws(() => graphics.DrawRectangle(pen, 0f, 0f, 1f, 1f)); } @@ -2438,6 +2441,7 @@ public void DrawRectangle_Disposed_ThrowsArgumentException() graphics.Dispose(); AssertExtensions.Throws(null, () => graphics.DrawRectangle(pen, new Rectangle(0, 0, 1, 1))); + AssertExtensions.Throws(null, () => graphics.DrawRectangle(pen, new RectangleF(0f, 0f, 1f, 1f))); AssertExtensions.Throws(null, () => graphics.DrawRectangle(pen, 0, 0, 1, 1)); AssertExtensions.Throws(null, () => graphics.DrawRectangle(pen, 0f, 0f, 1f, 1f)); } diff --git a/src/libraries/System.Drawing.Common/tests/mono/System.Drawing/GraphicsTests.cs b/src/libraries/System.Drawing.Common/tests/mono/System.Drawing/GraphicsTests.cs index 756e860a2a644..1354f61d19910 100644 --- a/src/libraries/System.Drawing.Common/tests/mono/System.Drawing/GraphicsTests.cs +++ b/src/libraries/System.Drawing.Common/tests/mono/System.Drawing/GraphicsTests.cs @@ -921,6 +921,7 @@ public void DrawRectangle_Negative() g.DrawRectangle(pen, 5, 5, -10, -10); g.DrawRectangle(pen, 0.0f, 0.0f, 5.0f, -10.0f); g.DrawRectangle(pen, new Rectangle(15, 0, -10, 5)); + g.DrawRectangle(pen, new RectangleF(0.0f, 5.0f, -10.0f, -10.0f)); CheckForEmptyBitmap(bitmap); pen.Dispose(); g.Dispose(); @@ -964,6 +965,7 @@ public void FillRectangle_Negative() g.FillRectangle(brush, 5, 5, -10, -10); g.FillRectangle(brush, 0.0f, 0.0f, 5.0f, -10.0f); g.FillRectangle(brush, new Rectangle(15, 0, -10, 5)); + g.FillRectangle(brush, new RectangleF(15.0f, 0.0f, -10.0f, 5.0f)); CheckForEmptyBitmap(bitmap); brush.Dispose(); g.Dispose(); From a4b7b3837e2ef0772d99c16730e6b9fa1f6a425b Mon Sep 17 00:00:00 2001 From: Josip Medved Date: Wed, 15 Dec 2021 16:44:24 -0800 Subject: [PATCH 5/9] Added FillPie argument test cases --- .../tests/GraphicsTests.cs | 98 +++++++++++++++++++ 1 file changed, 98 insertions(+) diff --git a/src/libraries/System.Drawing.Common/tests/GraphicsTests.cs b/src/libraries/System.Drawing.Common/tests/GraphicsTests.cs index 77abedf48999a..6eb06e855b9f2 100644 --- a/src/libraries/System.Drawing.Common/tests/GraphicsTests.cs +++ b/src/libraries/System.Drawing.Common/tests/GraphicsTests.cs @@ -3103,6 +3103,104 @@ public void DrawClosedCurve_Disposed_ThrowsArgumentException() } } + [ConditionalFact(Helpers.IsDrawingSupported)] + public void FillPie_NullPen_ThrowsArgumentNullException() + { + using (var image = new Bitmap(10, 10)) + using (Graphics graphics = Graphics.FromImage(image)) + { + AssertExtensions.Throws("brush", () => graphics.FillPie(null, new Rectangle(0, 0, 1, 1), 0, 90)); + AssertExtensions.Throws("brush", () => graphics.FillPie(null, 0, 0, 1, 1, 0, 90)); + AssertExtensions.Throws("brush", () => graphics.FillPie(null, new RectangleF(0, 0, 1, 1), 0, 90)); + AssertExtensions.Throws("brush", () => graphics.FillPie(null, 0f, 0f, 1f, 1f, 0, 90)); + } + } + + [ConditionalFact(Helpers.IsDrawingSupported)] + public void FillPie_DisposedPen_ThrowsArgumentException() + { + using (var image = new Bitmap(10, 10)) + using (Graphics graphics = Graphics.FromImage(image)) + { + var brush = new SolidBrush(Color.Red); + brush.Dispose(); + + AssertExtensions.Throws(null, () => graphics.FillPie(brush, new Rectangle(0, 0, 1, 1), 0, 90)); + AssertExtensions.Throws(null, () => graphics.FillPie(brush, 0, 0, 1, 1, 0, 90)); + AssertExtensions.Throws(null, () => graphics.FillPie(brush, new RectangleF(0, 0, 1, 1), 0, 90)); + AssertExtensions.Throws(null, () => graphics.FillPie(brush, 0f, 0f, 1f, 1f, 0, 90)); + } + } + + [ActiveIssue("https://github.com/dotnet/runtime/issues/22221", TestPlatforms.AnyUnix)] + [ConditionalFact(Helpers.IsDrawingSupported)] + public void FillPie_ZeroWidth_ThrowsArgumentException() + { + using (var image = new Bitmap(10, 10)) + using (Graphics graphics = Graphics.FromImage(image)) + using (var brush = new SolidBrush(Color.Red)) + { + AssertExtensions.Throws(null, () => graphics.FillPie(brush, new Rectangle(0, 0, 0, 1), 0, 90)); + AssertExtensions.Throws(null, () => graphics.FillPie(brush, 0, 0, 0, 1, 0, 90)); + AssertExtensions.Throws(null, () => graphics.FillPie(brush, new RectangleF(0, 0, 0, 1), 0, 90)); + AssertExtensions.Throws(null, () => graphics.FillPie(brush, 0f, 0f, 0f, 1f, 0, 90)); + } + } + + [ActiveIssue("https://github.com/dotnet/runtime/issues/22221", TestPlatforms.AnyUnix)] + [ConditionalFact(Helpers.IsDrawingSupported)] + public void FillPie_ZeroHeight_ThrowsArgumentException() + { + using (var image = new Bitmap(10, 10)) + using (Graphics graphics = Graphics.FromImage(image)) + using (var brush = new SolidBrush(Color.Red)) + { + AssertExtensions.Throws(null, () => graphics.FillPie(brush, new Rectangle(0, 0, 1, 0), 0, 90)); + AssertExtensions.Throws(null, () => graphics.FillPie(brush, 0, 0, 1, 0, 0, 90)); + AssertExtensions.Throws(null, () => graphics.FillPie(brush, new RectangleF(0, 0, 1, 0), 0, 90)); + AssertExtensions.Throws(null, () => graphics.FillPie(brush, 0f, 0f, 1f, 0f, 0, 90)); + } + } + + [ActiveIssue("https://github.com/dotnet/runtime/issues/22221", TestPlatforms.AnyUnix)] + [ConditionalFact(Helpers.IsDrawingSupported)] + public void FillPie_Busy_ThrowsInvalidOperationException() + { + using (var image = new Bitmap(10, 10)) + using (Graphics graphics = Graphics.FromImage(image)) + using (var brush = new SolidBrush(Color.Red)) + { + graphics.GetHdc(); + try + { + Assert.Throws(() => graphics.FillPie(brush, new Rectangle(0, 0, 1, 1), 0, 90)); + Assert.Throws(() => graphics.FillPie(brush, 0, 0, 1, 1, 0, 90)); + Assert.Throws(() => graphics.FillPie(brush, new RectangleF(0, 0, 1, 1), 0, 90)); + Assert.Throws(() => graphics.FillPie(brush, 0f, 0f, 1f, 1f, 0, 90)); + } + finally + { + graphics.ReleaseHdc(); + } + } + } + + [ConditionalFact(Helpers.IsDrawingSupported)] + public void FillPie_Disposed_ThrowsArgumentException() + { + using (var image = new Bitmap(10, 10)) + using (var brush = new SolidBrush(Color.Red)) + { + Graphics graphics = Graphics.FromImage(image); + graphics.Dispose(); + + AssertExtensions.Throws(null, () => graphics.FillPie(brush, new Rectangle(0, 0, 1, 1), 0, 90)); + AssertExtensions.Throws(null, () => graphics.FillPie(brush, 0, 0, 1, 1, 0, 90)); + AssertExtensions.Throws(null, () => graphics.FillPie(brush, new RectangleF(0, 0, 1, 1), 0, 90)); + AssertExtensions.Throws(null, () => graphics.FillPie(brush, 0f, 0f, 1f, 1f, 0, 90)); + } + } + [ConditionalFact(Helpers.IsDrawingSupported)] public void Clear_Color_Success() { From ce47ab510daf07f124833ec1961e6b24f5b29594 Mon Sep 17 00:00:00 2001 From: Josip Medved Date: Mon, 3 Jan 2022 16:44:58 -0800 Subject: [PATCH 6/9] Added XML parameters for newly added FillPie and DrawRectangle --- .../System.Drawing.Common/src/System/Drawing/Graphics.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/libraries/System.Drawing.Common/src/System/Drawing/Graphics.cs b/src/libraries/System.Drawing.Common/src/System/Drawing/Graphics.cs index bcbce961f2884..c390a05f92eff 100644 --- a/src/libraries/System.Drawing.Common/src/System/Drawing/Graphics.cs +++ b/src/libraries/System.Drawing.Common/src/System/Drawing/Graphics.cs @@ -711,6 +711,8 @@ public void DrawBezier(Pen pen, Point pt1, Point pt2, Point pt3, Point pt4) /// /// Draws the outline of a rectangle specified by . /// + /// A Pen that determines the color, width, and style of the rectangle. + /// A Rectangle structure that represents the rectangle to draw. public void DrawRectangle(Pen pen, RectangleF rect) { DrawRectangle(pen, rect.X, rect.Y, rect.Width, rect.Height); @@ -1336,6 +1338,10 @@ public void FillPie(Brush brush, Rectangle rect, float startAngle, float sweepAn /// /// Fills the interior of a pie section defined by an ellipse and two radial lines. /// + /// A Brush that determines the characteristics of the fill. + /// A Rectangle structure that represents the bounding rectangle that defines the ellipse from which the pie section comes. + /// Angle in degrees measured clockwise from the x-axis to the first side of the pie section. + /// Angle in degrees measured clockwise from the parameter to the second side of the pie section. public void FillPie(Brush brush, RectangleF rect, float startAngle, float sweepAngle) { FillPie(brush, rect.X, rect.Y, rect.Width, rect.Height, startAngle, sweepAngle); From c2f55139b48202d8e6b3173d0162e95af70ce0ca Mon Sep 17 00:00:00 2001 From: Josip Medved Date: Mon, 10 Jan 2022 23:02:43 -0800 Subject: [PATCH 7/9] Moving DrawRectangle and FillPie with RectangleF to netcoreapp --- .../System.Drawing.Common/ref/System.Drawing.Common.cs | 2 -- .../ref/System.Drawing.Common.netcoreapp.cs | 2 ++ 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libraries/System.Drawing.Common/ref/System.Drawing.Common.cs b/src/libraries/System.Drawing.Common/ref/System.Drawing.Common.cs index bc20c0aa6679b..8c057f5369b77 100644 --- a/src/libraries/System.Drawing.Common/ref/System.Drawing.Common.cs +++ b/src/libraries/System.Drawing.Common/ref/System.Drawing.Common.cs @@ -506,7 +506,6 @@ public void DrawPie(System.Drawing.Pen pen, float x, float y, float width, float public void DrawPolygon(System.Drawing.Pen pen, System.Drawing.PointF[] points) { } public void DrawPolygon(System.Drawing.Pen pen, System.Drawing.Point[] points) { } public void DrawRectangle(System.Drawing.Pen pen, System.Drawing.Rectangle rect) { } - public void DrawRectangle(System.Drawing.Pen pen, System.Drawing.RectangleF rect) { } public void DrawRectangle(System.Drawing.Pen pen, int x, int y, int width, int height) { } public void DrawRectangle(System.Drawing.Pen pen, float x, float y, float width, float height) { } public void DrawRectangles(System.Drawing.Pen pen, System.Drawing.RectangleF[] rects) { } @@ -568,7 +567,6 @@ public void FillEllipse(System.Drawing.Brush brush, int x, int y, int width, int public void FillEllipse(System.Drawing.Brush brush, float x, float y, float width, float height) { } public void FillPath(System.Drawing.Brush brush, System.Drawing.Drawing2D.GraphicsPath path) { } public void FillPie(System.Drawing.Brush brush, System.Drawing.Rectangle rect, float startAngle, float sweepAngle) { } - public void FillPie(System.Drawing.Brush brush, System.Drawing.RectangleF rect, float startAngle, float sweepAngle) { } public void FillPie(System.Drawing.Brush brush, int x, int y, int width, int height, int startAngle, int sweepAngle) { } public void FillPie(System.Drawing.Brush brush, float x, float y, float width, float height, float startAngle, float sweepAngle) { } public void FillPolygon(System.Drawing.Brush brush, System.Drawing.PointF[] points) { } diff --git a/src/libraries/System.Drawing.Common/ref/System.Drawing.Common.netcoreapp.cs b/src/libraries/System.Drawing.Common/ref/System.Drawing.Common.netcoreapp.cs index 7c5f8f890a84d..f9d987de24d1c 100644 --- a/src/libraries/System.Drawing.Common/ref/System.Drawing.Common.netcoreapp.cs +++ b/src/libraries/System.Drawing.Common/ref/System.Drawing.Common.netcoreapp.cs @@ -8,6 +8,8 @@ namespace System.Drawing { public sealed partial class Graphics { + public void DrawRectangle(System.Drawing.Pen pen, System.Drawing.RectangleF rect) { } + public void FillPie(System.Drawing.Brush brush, System.Drawing.RectangleF rect, float startAngle, float sweepAngle) { } public System.Numerics.Matrix3x2 TransformElements { get { throw null; } set { } } [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] [System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")] From f6b9b4dedf6b37ae365dac4a15648aef4618bf86 Mon Sep 17 00:00:00 2001 From: Josip Medved Date: Mon, 10 Jan 2022 23:21:10 -0800 Subject: [PATCH 8/9] Moving DrawRectangle and FillPie RectangleF tests to netcoreapp * Only testing RectangleF overloads in GraphicsTests.Core.cs; other overloads stay as they are. * FillPie tests that were newly added as part of issue #62385 are split in the same manner. --- .../tests/GraphicsTests.Core.cs | 149 ++++++++++++++++++ .../tests/GraphicsTests.cs | 11 -- 2 files changed, 149 insertions(+), 11 deletions(-) diff --git a/src/libraries/System.Drawing.Common/tests/GraphicsTests.Core.cs b/src/libraries/System.Drawing.Common/tests/GraphicsTests.Core.cs index 3a137da17c7e5..d691cd23ff9df 100644 --- a/src/libraries/System.Drawing.Common/tests/GraphicsTests.Core.cs +++ b/src/libraries/System.Drawing.Common/tests/GraphicsTests.Core.cs @@ -77,5 +77,154 @@ public void TransformElements_RoundTrip() } } } + + [ConditionalFact(Helpers.IsDrawingSupported)] + public void DrawRectangle_NullPen_ThrowsArgumentNullException_Core() + { + using (var image = new Bitmap(10, 10)) + using (Graphics graphics = Graphics.FromImage(image)) + { + AssertExtensions.Throws("pen", () => graphics.DrawRectangle(null, new RectangleF(0f, 0f, 1f, 1f))); + // other DrawRectangle overloads tested in DrawRectangle_NullPen_ThrowsArgumentNullException() + } + } + + [ConditionalFact(Helpers.IsDrawingSupported)] + public void DrawRectangle_DisposedPen_ThrowsArgumentException_Core() + { + using (var image = new Bitmap(10, 10)) + using (Graphics graphics = Graphics.FromImage(image)) + { + var pen = new Pen(Color.Red); + pen.Dispose(); + + AssertExtensions.Throws(null, () => graphics.DrawRectangle(pen, new RectangleF(0f, 0f, 1f, 1f))); + // other DrawRectangle overloads tested in DrawRectangle_DisposedPen_ThrowsArgumentException() + } + } + + [ActiveIssue("https://github.com/dotnet/runtime/issues/22221", TestPlatforms.AnyUnix)] + [ConditionalFact(Helpers.IsDrawingSupported)] + public void DrawRectangle_Busy_ThrowsInvalidOperationException_Core() + { + using (var image = new Bitmap(10, 10)) + using (Graphics graphics = Graphics.FromImage(image)) + using (var pen = new Pen(Color.Red)) + { + graphics.GetHdc(); + try + { + Assert.Throws(() => graphics.DrawRectangle(pen, new RectangleF(0f, 0f, 1f, 1f))); + // other DrawRectangle overloads tested in DrawRectangle_Busy_ThrowsInvalidOperationException() + } + finally + { + graphics.ReleaseHdc(); + } + } + } + + [ConditionalFact(Helpers.IsDrawingSupported)] + public void DrawRectangle_Disposed_ThrowsArgumentException_Core() + { + using (var image = new Bitmap(10, 10)) + using (var pen = new Pen(Color.Red)) + { + Graphics graphics = Graphics.FromImage(image); + graphics.Dispose(); + + AssertExtensions.Throws(null, () => graphics.DrawRectangle(pen, new RectangleF(0f, 0f, 1f, 1f))); + // other DrawRectangle overloads tested in DrawRectangle_Disposed_ThrowsArgumentException() + } + } + + [ConditionalFact(Helpers.IsDrawingSupported)] + public void FillPie_NullPen_ThrowsArgumentNullException_Core() + { + using (var image = new Bitmap(10, 10)) + using (Graphics graphics = Graphics.FromImage(image)) + { + AssertExtensions.Throws("brush", () => graphics.FillPie(null, new RectangleF(0, 0, 1, 1), 0, 90)); + // other FillPie overloads tested in FillPie_NullPen_ThrowsArgumentNullException() + } + } + + [ConditionalFact(Helpers.IsDrawingSupported)] + public void FillPie_DisposedPen_ThrowsArgumentException_Core() + { + using (var image = new Bitmap(10, 10)) + using (Graphics graphics = Graphics.FromImage(image)) + { + var brush = new SolidBrush(Color.Red); + brush.Dispose(); + + AssertExtensions.Throws(null, () => graphics.FillPie(brush, new RectangleF(0, 0, 1, 1), 0, 90)); + // other FillPie overloads tested in FillPie_DisposedPen_ThrowsArgumentException() + } + } + + [ActiveIssue("https://github.com/dotnet/runtime/issues/22221", TestPlatforms.AnyUnix)] + [ConditionalFact(Helpers.IsDrawingSupported)] + public void FillPie_ZeroWidth_ThrowsArgumentException_Core() + { + using (var image = new Bitmap(10, 10)) + using (Graphics graphics = Graphics.FromImage(image)) + using (var brush = new SolidBrush(Color.Red)) + { + AssertExtensions.Throws(null, () => graphics.FillPie(brush, new RectangleF(0, 0, 0, 1), 0, 90)); + // other FillPie overloads tested in FillPie_ZeroWidth_ThrowsArgumentException() + } + } + + [ActiveIssue("https://github.com/dotnet/runtime/issues/22221", TestPlatforms.AnyUnix)] + [ConditionalFact(Helpers.IsDrawingSupported)] + public void FillPie_ZeroHeight_ThrowsArgumentException_Core() + { + using (var image = new Bitmap(10, 10)) + using (Graphics graphics = Graphics.FromImage(image)) + using (var brush = new SolidBrush(Color.Red)) + { + AssertExtensions.Throws(null, () => graphics.FillPie(brush, new RectangleF(0, 0, 1, 0), 0, 90)); + // other FillPie overloads tested in FillPie_ZeroHeight_ThrowsArgumentException() + } + } + + [ActiveIssue("https://github.com/dotnet/runtime/issues/22221", TestPlatforms.AnyUnix)] + [ConditionalFact(Helpers.IsDrawingSupported)] + public void FillPie_Busy_ThrowsInvalidOperationException_Core() + { + using (var image = new Bitmap(10, 10)) + using (Graphics graphics = Graphics.FromImage(image)) + using (var brush = new SolidBrush(Color.Red)) + { + graphics.GetHdc(); + try + { + Assert.Throws(() => graphics.FillPie(brush, new RectangleF(0, 0, 1, 1), 0, 90)); + // other FillPie overloads tested in FillPie_Busy_ThrowsInvalidOperationException() + } + finally + { + graphics.ReleaseHdc(); + } + } + } + + [ConditionalFact(Helpers.IsDrawingSupported)] + public void FillPie_Disposed_ThrowsArgumentException_Core() + { + using (var image = new Bitmap(10, 10)) + using (var brush = new SolidBrush(Color.Red)) + { + Graphics graphics = Graphics.FromImage(image); + graphics.Dispose(); + + AssertExtensions.Throws(null, () => graphics.FillPie(brush, new RectangleF(0, 0, 1, 1), 0, 90)); + // other FillPie overloads tested in FillPie_Disposed_ThrowsArgumentException() + } + } + + + } } diff --git a/src/libraries/System.Drawing.Common/tests/GraphicsTests.cs b/src/libraries/System.Drawing.Common/tests/GraphicsTests.cs index 6eb06e855b9f2..c99ad88ea40ae 100644 --- a/src/libraries/System.Drawing.Common/tests/GraphicsTests.cs +++ b/src/libraries/System.Drawing.Common/tests/GraphicsTests.cs @@ -2385,7 +2385,6 @@ public void DrawRectangle_NullPen_ThrowsArgumentNullException() using (Graphics graphics = Graphics.FromImage(image)) { AssertExtensions.Throws("pen", () => graphics.DrawRectangle(null, new Rectangle(0, 0, 1, 1))); - AssertExtensions.Throws("pen", () => graphics.DrawRectangle(null, new RectangleF(0f, 0f, 1f, 1f))); AssertExtensions.Throws("pen", () => graphics.DrawRectangle(null, 0, 0, 1, 1)); AssertExtensions.Throws("pen", () => graphics.DrawRectangle(null, 0f, 0f, 1f, 1f)); } @@ -2400,9 +2399,7 @@ public void DrawRectangle_DisposedPen_ThrowsArgumentException() var pen = new Pen(Color.Red); pen.Dispose(); - AssertExtensions.Throws(null, () => graphics.DrawRectangle(pen, new Rectangle(0, 0, 1, 1))); - AssertExtensions.Throws(null, () => graphics.DrawRectangle(pen, new RectangleF(0f, 0f, 1f, 1f))); AssertExtensions.Throws(null, () => graphics.DrawRectangle(pen, 0, 0, 1, 1)); AssertExtensions.Throws(null, () => graphics.DrawRectangle(pen, 0f, 0f, 1f, 1f)); } @@ -2420,7 +2417,6 @@ public void DrawRectangle_Busy_ThrowsInvalidOperationException() try { Assert.Throws(() => graphics.DrawRectangle(pen, new Rectangle(0, 0, 1, 1))); - Assert.Throws(() => graphics.DrawRectangle(pen, new RectangleF(0f, 0f, 1f, 1f))); Assert.Throws(() => graphics.DrawRectangle(pen, 0, 0, 1, 1)); Assert.Throws(() => graphics.DrawRectangle(pen, 0f, 0f, 1f, 1f)); } @@ -2441,7 +2437,6 @@ public void DrawRectangle_Disposed_ThrowsArgumentException() graphics.Dispose(); AssertExtensions.Throws(null, () => graphics.DrawRectangle(pen, new Rectangle(0, 0, 1, 1))); - AssertExtensions.Throws(null, () => graphics.DrawRectangle(pen, new RectangleF(0f, 0f, 1f, 1f))); AssertExtensions.Throws(null, () => graphics.DrawRectangle(pen, 0, 0, 1, 1)); AssertExtensions.Throws(null, () => graphics.DrawRectangle(pen, 0f, 0f, 1f, 1f)); } @@ -3111,7 +3106,6 @@ public void FillPie_NullPen_ThrowsArgumentNullException() { AssertExtensions.Throws("brush", () => graphics.FillPie(null, new Rectangle(0, 0, 1, 1), 0, 90)); AssertExtensions.Throws("brush", () => graphics.FillPie(null, 0, 0, 1, 1, 0, 90)); - AssertExtensions.Throws("brush", () => graphics.FillPie(null, new RectangleF(0, 0, 1, 1), 0, 90)); AssertExtensions.Throws("brush", () => graphics.FillPie(null, 0f, 0f, 1f, 1f, 0, 90)); } } @@ -3127,7 +3121,6 @@ public void FillPie_DisposedPen_ThrowsArgumentException() AssertExtensions.Throws(null, () => graphics.FillPie(brush, new Rectangle(0, 0, 1, 1), 0, 90)); AssertExtensions.Throws(null, () => graphics.FillPie(brush, 0, 0, 1, 1, 0, 90)); - AssertExtensions.Throws(null, () => graphics.FillPie(brush, new RectangleF(0, 0, 1, 1), 0, 90)); AssertExtensions.Throws(null, () => graphics.FillPie(brush, 0f, 0f, 1f, 1f, 0, 90)); } } @@ -3142,7 +3135,6 @@ public void FillPie_ZeroWidth_ThrowsArgumentException() { AssertExtensions.Throws(null, () => graphics.FillPie(brush, new Rectangle(0, 0, 0, 1), 0, 90)); AssertExtensions.Throws(null, () => graphics.FillPie(brush, 0, 0, 0, 1, 0, 90)); - AssertExtensions.Throws(null, () => graphics.FillPie(brush, new RectangleF(0, 0, 0, 1), 0, 90)); AssertExtensions.Throws(null, () => graphics.FillPie(brush, 0f, 0f, 0f, 1f, 0, 90)); } } @@ -3157,7 +3149,6 @@ public void FillPie_ZeroHeight_ThrowsArgumentException() { AssertExtensions.Throws(null, () => graphics.FillPie(brush, new Rectangle(0, 0, 1, 0), 0, 90)); AssertExtensions.Throws(null, () => graphics.FillPie(brush, 0, 0, 1, 0, 0, 90)); - AssertExtensions.Throws(null, () => graphics.FillPie(brush, new RectangleF(0, 0, 1, 0), 0, 90)); AssertExtensions.Throws(null, () => graphics.FillPie(brush, 0f, 0f, 1f, 0f, 0, 90)); } } @@ -3175,7 +3166,6 @@ public void FillPie_Busy_ThrowsInvalidOperationException() { Assert.Throws(() => graphics.FillPie(brush, new Rectangle(0, 0, 1, 1), 0, 90)); Assert.Throws(() => graphics.FillPie(brush, 0, 0, 1, 1, 0, 90)); - Assert.Throws(() => graphics.FillPie(brush, new RectangleF(0, 0, 1, 1), 0, 90)); Assert.Throws(() => graphics.FillPie(brush, 0f, 0f, 1f, 1f, 0, 90)); } finally @@ -3196,7 +3186,6 @@ public void FillPie_Disposed_ThrowsArgumentException() AssertExtensions.Throws(null, () => graphics.FillPie(brush, new Rectangle(0, 0, 1, 1), 0, 90)); AssertExtensions.Throws(null, () => graphics.FillPie(brush, 0, 0, 1, 1, 0, 90)); - AssertExtensions.Throws(null, () => graphics.FillPie(brush, new RectangleF(0, 0, 1, 1), 0, 90)); AssertExtensions.Throws(null, () => graphics.FillPie(brush, 0f, 0f, 1f, 1f, 0, 90)); } } From 6352e26d43e1cb1e8a756391049f0e6058a6735d Mon Sep 17 00:00:00 2001 From: Josip Medved Date: Tue, 11 Jan 2022 07:44:12 -0800 Subject: [PATCH 9/9] Removing RectangleF overload from mono tests DrawRectangle with RectangleF overload is new and not compiled into mono. --- .../tests/mono/System.Drawing/GraphicsTests.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/libraries/System.Drawing.Common/tests/mono/System.Drawing/GraphicsTests.cs b/src/libraries/System.Drawing.Common/tests/mono/System.Drawing/GraphicsTests.cs index 1354f61d19910..756e860a2a644 100644 --- a/src/libraries/System.Drawing.Common/tests/mono/System.Drawing/GraphicsTests.cs +++ b/src/libraries/System.Drawing.Common/tests/mono/System.Drawing/GraphicsTests.cs @@ -921,7 +921,6 @@ public void DrawRectangle_Negative() g.DrawRectangle(pen, 5, 5, -10, -10); g.DrawRectangle(pen, 0.0f, 0.0f, 5.0f, -10.0f); g.DrawRectangle(pen, new Rectangle(15, 0, -10, 5)); - g.DrawRectangle(pen, new RectangleF(0.0f, 5.0f, -10.0f, -10.0f)); CheckForEmptyBitmap(bitmap); pen.Dispose(); g.Dispose(); @@ -965,7 +964,6 @@ public void FillRectangle_Negative() g.FillRectangle(brush, 5, 5, -10, -10); g.FillRectangle(brush, 0.0f, 0.0f, 5.0f, -10.0f); g.FillRectangle(brush, new Rectangle(15, 0, -10, 5)); - g.FillRectangle(brush, new RectangleF(15.0f, 0.0f, -10.0f, 5.0f)); CheckForEmptyBitmap(bitmap); brush.Dispose(); g.Dispose();