Author: spouliot
Date: 2006-01-18 14:42:37 -0500 (Wed, 18 Jan 2006)
New Revision: 55754
Added:
trunk/mcs/class/System.Drawing/Test/System.Drawing/RegionDataTest.cs
trunk/mcs/class/System.Drawing/Test/System.Drawing/RegionNonRectTest.cs
Modified:
trunk/mcs/class/System.Drawing/Test/System.Drawing/ChangeLog
trunk/mcs/class/System.Drawing/Test/System.Drawing/TestRegion.cs
Log:
2006-01-18 Sebastien Pouliot <[EMAIL PROTECTED]>
* RegionDataTest.cs: New. Unit tests for RegionData.
* RegionNonRectTest.cs: New. Unit tests for non-rectangular regions.
* TestRegion.cs: Added new test cases for empty region and IsInfinite
behaviour with multiple rectangles / path-rectangle regions.
Modified: trunk/mcs/class/System.Drawing/Test/System.Drawing/ChangeLog
===================================================================
--- trunk/mcs/class/System.Drawing/Test/System.Drawing/ChangeLog
2006-01-18 19:41:13 UTC (rev 55753)
+++ trunk/mcs/class/System.Drawing/Test/System.Drawing/ChangeLog
2006-01-18 19:42:37 UTC (rev 55754)
@@ -1,3 +1,10 @@
+2006-01-18 Sebastien Pouliot <[EMAIL PROTECTED]>
+
+ * RegionDataTest.cs: New. Unit tests for RegionData.
+ * RegionNonRectTest.cs: New. Unit tests for non-rectangular regions.
+ * TestRegion.cs: Added new test cases for empty region and IsInfinite
+ behaviour with multiple rectangles / path-rectangle regions.
+
2006-01-16 Sebastien Pouliot <[EMAIL PROTECTED]>
* TestRegion.cs: Mark a test case as NotWorking as it caused a
Added: trunk/mcs/class/System.Drawing/Test/System.Drawing/RegionDataTest.cs
===================================================================
--- trunk/mcs/class/System.Drawing/Test/System.Drawing/RegionDataTest.cs
2006-01-18 19:41:13 UTC (rev 55753)
+++ trunk/mcs/class/System.Drawing/Test/System.Drawing/RegionDataTest.cs
2006-01-18 19:42:37 UTC (rev 55754)
@@ -0,0 +1,101 @@
+//
+// System.Drawing.RegionData unit tests
+//
+// Authors:
+// Sebastien Pouliot <[EMAIL PROTECTED]>
+//
+// Copyright (C) 2006 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+using System.Drawing;
+using System.Drawing.Drawing2D;
+using System.Runtime.InteropServices;
+using System.Security.Permissions;
+using NUnit.Framework;
+
+namespace MonoTests.System.Drawing {
+
+ [TestFixture]
+ [SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
+ public class RegionDataTest {
+
+ private Bitmap bitmap;
+ private Graphics graphic;
+
+ [TestFixtureSetUp]
+ public void FixtureSetUp ()
+ {
+ bitmap = new Bitmap (10, 10);
+ graphic = Graphics.FromImage (bitmap);
+ }
+
+ [Test]
+ [ExpectedException (typeof (NullReferenceException))]
+ public void RegionData_Null ()
+ {
+ RegionData data = new Region ().GetRegionData ();
+ data.Data = null;
+ Assert.IsNull (data.Data, "Data");
+ Region region = new Region (data);
+ }
+
+ [Test]
+ public void RegionData_EmptyData ()
+ {
+ RegionData data = new Region ().GetRegionData ();
+ data.Data = new byte[0];
+ Assert.AreEqual (0, data.Data.Length, "Data");
+ try {
+ new Region (data);
+ }
+ catch (ExternalException) {
+ // MS
+ }
+ catch (ArgumentException) {
+ // Mono
+ }
+ }
+
+ [Test]
+ public void EmptyRegion ()
+ {
+ // note: an empty region is (for libgdiplus) a
rectangular based region
+ Region empty = new Region ();
+ RegionData data = empty.GetRegionData ();
+ Assert.IsNotNull (data.Data, "Data");
+ Region region = new Region (data);
+ }
+
+ [Test]
+ public void PathRegion ()
+ {
+ GraphicsPath path = new GraphicsPath ();
+ path.AddCurve (new Point[2] { new Point (1, 1), new
Point (2, 2) });
+ Region r = new Region (path);
+ RegionData data = r.GetRegionData ();
+ Assert.IsNotNull (data.Data, "Data");
+ Region region = new Region (data);
+ Assert.IsTrue (r.GetBounds (graphic).Equals
(region.GetBounds (graphic)), "Bounds");
+ }
+ }
+}
Property changes on:
trunk/mcs/class/System.Drawing/Test/System.Drawing/RegionDataTest.cs
___________________________________________________________________
Name: svn:executable
+ *
Added: trunk/mcs/class/System.Drawing/Test/System.Drawing/RegionNonRectTest.cs
===================================================================
--- trunk/mcs/class/System.Drawing/Test/System.Drawing/RegionNonRectTest.cs
2006-01-18 19:41:13 UTC (rev 55753)
+++ trunk/mcs/class/System.Drawing/Test/System.Drawing/RegionNonRectTest.cs
2006-01-18 19:42:37 UTC (rev 55754)
@@ -0,0 +1,160 @@
+//
+// System.Drawing.Region non-rectangular unit tests
+//
+// Authors:
+// Sebastien Pouliot <[EMAIL PROTECTED]>
+//
+// Copyright (C) 2006 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+using System.Drawing.Imaging;
+using System.Drawing;
+using System.Drawing.Drawing2D;
+using System.Security.Permissions;
+using NUnit.Framework;
+
+namespace MonoTests.System.Drawing {
+
+ /* NOTE: General tests and rectangular region tests are located in
TestRegion.cs */
+ /* Here we exclusively tests non-rectangular (GraphicsPath based)
regions. */
+
+ [TestFixture]
+ [SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
+ public class RegionNonRectTest {
+
+ private Bitmap bitmap;
+ private Graphics graphic;
+
+ [TestFixtureSetUp]
+ public void FixtureSetUp ()
+ {
+ bitmap = new Bitmap (10, 10);
+ graphic = Graphics.FromImage (bitmap);
+ }
+
+ // a region with an "empty ctor" graphic path is "empty" (i.e.
not infinite)
+ private void CheckEmpty (string prefix, Region region)
+ {
+ Assert.IsTrue (region.IsEmpty (graphic), prefix +
"IsEmpty");
+ Assert.IsFalse (region.IsInfinite (graphic), prefix +
"graphic");
+
+ RectangleF rect = region.GetBounds (graphic);
+ Assert.AreEqual (0f, rect.X, prefix + "GetBounds.X");
+ Assert.AreEqual (0f, rect.Y, prefix + "GetBounds.Y");
+ Assert.AreEqual (0f, rect.Width, prefix +
"GetBounds.Width");
+ Assert.AreEqual (0f, rect.Height, prefix +
"GetBounds.Height");
+ }
+
+ [Test]
+ public void Region_Ctor_GraphicsPath_Empty ()
+ {
+ Region region = new Region (new GraphicsPath ());
+ CheckEmpty ("GraphicsPath.", region);
+
+ Region clone = region.Clone ();
+ CheckEmpty ("Clone.", region);
+ }
+
+ [Test]
+ [Category ("NotDotNet")] // MS.NET (atleast 2.0) throws an
ExternalException in this case
+ public void Region_Ctor_RegionData ()
+ {
+ Region region = new Region (new GraphicsPath ());
+ RegionData data = region.GetRegionData ();
+ Region r2 = new Region (data);
+ CheckEmpty ("RegionData.", region);
+ }
+
+ [Test]
+ public void Region_Ctor_GraphicsPath ()
+ {
+ GraphicsPath gp = new GraphicsPath ();
+ Region region = new Region (gp);
+ CheckEmpty ("GraphicsPath.", region);
+
+ Region clone = region.Clone ();
+ CheckEmpty ("Clone.", region);
+ }
+
+ private void CheckInfiniteBounds (GraphicsPath path)
+ {
+ RectangleF rect = path.GetBounds ();
+ Assert.AreEqual (-4194304f, rect.X, "Bounds.X");
+ Assert.AreEqual (-4194304f, rect.Y, "Bounds.Y");
+ Assert.AreEqual (8388608f, rect.Width, "Bounds.Width");
+ Assert.AreEqual (8388608f, rect.Height,
"Bounds.Height");
+ }
+
+ [Test]
+ public void Region_Curve_IsInfinite ()
+ {
+ Point[] points = new Point[2] { new Point (-4194304,
-4194304), new Point (4194304, 4194304) };
+ GraphicsPath gp = new GraphicsPath ();
+ gp.AddCurve (points);
+ CheckInfiniteBounds (gp);
+
+ Region region = new Region (gp);
+ Assert.IsFalse (region.IsInfinite (graphic),
"IsInfinite");
+ // note: infinity isn't based on the bounds
+ }
+
+ [Test]
+ [Category ("NotWorking")]
+ public void Region_Polygon4_IsInfinite ()
+ {
+ Point[] points = new Point[4] { new Point (-4194304,
-4194304), new Point (-4194304, 4194304), new Point (4194304, 4194304), new
Point (4194304, -4194304) };
+ GraphicsPath gp = new GraphicsPath ();
+ gp.AddPolygon (points);
+ CheckInfiniteBounds (gp);
+
+ Region region = new Region (gp);
+ Assert.IsTrue (region.IsInfinite (graphic),
"IsInfinite");
+ }
+
+ [Test]
+ [Category ("NotWorking")]
+ public void Region_Polygon5_IsInfinite ()
+ {
+ // overlap the first/last point
+ Point[] points = new Point[5] { new Point (-4194304,
-4194304), new Point (-4194304, 4194304), new Point (4194304, 4194304), new
Point (4194304, -4194304), new Point (-4194304, -4194304) };
+ GraphicsPath gp = new GraphicsPath ();
+ gp.AddPolygon (points);
+ CheckInfiniteBounds (gp);
+
+ Region region = new Region (gp);
+ Assert.IsTrue (region.IsInfinite (graphic),
"IsInfinite");
+ }
+
+ [Test]
+ [Category ("NotWorking")]
+ public void Region_Rectangle_IsInfinite ()
+ {
+ GraphicsPath gp = new GraphicsPath ();
+ gp.AddRectangle (new Rectangle (-4194304, -4194304,
8388608, 8388608));
+ CheckInfiniteBounds (gp);
+
+ Region region = new Region (gp);
+ Assert.IsTrue (region.IsInfinite (graphic),
"IsInfinite");
+ }
+ }
+}
Property changes on:
trunk/mcs/class/System.Drawing/Test/System.Drawing/RegionNonRectTest.cs
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: trunk/mcs/class/System.Drawing/Test/System.Drawing/TestRegion.cs
===================================================================
--- trunk/mcs/class/System.Drawing/Test/System.Drawing/TestRegion.cs
2006-01-18 19:41:13 UTC (rev 55753)
+++ trunk/mcs/class/System.Drawing/Test/System.Drawing/TestRegion.cs
2006-01-18 19:42:37 UTC (rev 55754)
@@ -51,6 +51,16 @@
Console.WriteLine ( rects[i]);
}
+ private Bitmap bitmap;
+ private Graphics graphic;
+
+ [TestFixtureSetUp]
+ public void FixtureSetUp ()
+ {
+ bitmap = new Bitmap (10, 10);
+ graphic = Graphics.FromImage (bitmap);
+ }
+
[Test]
public void TestBounds()
{
@@ -1231,5 +1241,54 @@
{
new Region ().Transform (null);
}
+
+ // an "empty ctor" Region is infinite
+ private void CheckEmpty (string prefix, Region region)
+ {
+ Assert.IsFalse (region.IsEmpty (graphic), prefix +
"IsEmpty");
+ Assert.IsTrue (region.IsInfinite (graphic), prefix +
"graphic");
+
+ RectangleF rect = region.GetBounds (graphic);
+ Assert.AreEqual (-4194304f, rect.X, prefix +
"GetBounds.X");
+ Assert.AreEqual (-4194304f, rect.Y, prefix +
"GetBounds.Y");
+ Assert.AreEqual (8388608f, rect.Width, prefix +
"GetBounds.Width");
+ Assert.AreEqual (8388608f, rect.Height, prefix +
"GetBounds.Height");
+ }
+
+ [Test]
+ public void Region_Empty ()
+ {
+ Region region = new Region ();
+ CheckEmpty ("Empty.", region);
+
+ Region clone = region.Clone ();
+ CheckEmpty ("Clone.", region);
+
+ RegionData data = region.GetRegionData ();
+ Region r2 = new Region (data);
+ CheckEmpty ("RegionData.", region);
+ }
+
+ [Test]
+ [Category ("NotWorking")]
+ public void Region_Infinite_MultipleRectangles ()
+ {
+ Region region = new Region ();
+ Assert.IsTrue (region.IsInfinite (graphic),
"Empty.IsInfinite");
+
+ GraphicsPath gp = new GraphicsPath ();
+ gp.AddRectangle (new Rectangle (-4194304, -4194304,
8388608, 8388608));
+ region = new Region (gp);
+ Assert.IsTrue (region.IsInfinite (graphic),
"OneRectangle.IsInfinite");
+
+ gp.AddRectangle (new Rectangle (1, 1, 2, 2));
+ region = new Region (gp);
+ Assert.IsFalse (region.IsInfinite (graphic),
"TwoOverlappingRectangle.IsInfinite");
+
+ gp = new GraphicsPath ();
+ gp.AddRectangle (new Rectangle (-4194304, -4194304,
4194304, 8388608));
+ gp.AddRectangle (new Rectangle (0, -4194304, 4194304,
8388608));
+ Assert.IsFalse (region.IsInfinite (graphic),
"TwoSideBySideRectangle.IsInfinite");
+ }
}
}
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches