new Region ().Union (r);
}
+ [Test]
+ public void Union_Region_Infinite ()
+ {
+ // default ctor creates an infinite region
+ Region r = new Region ();
+ CheckEmpty ("default .ctor", r);
+ // union-ing to infinity doesn't change the results
+ r.Union (new Rectangle (10, 10, 100, 100));
+ CheckEmpty ("U infinity", r);
+ }
+
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void Intersect_GraphicsPath_Null ()
gp.AddRectangle (new Rectangle (0, -4194304, 4194304, 8388608));
Assert.IsFalse (region.IsInfinite (graphic), "TwoSideBySideRectangle.IsInfinite");
}
+
+ [Test]
+#if TARGET_JVM
+ [Category ("NotWorking")]
+#endif
+ public void Rectangle_GetRegionScans ()
+ {
+ Matrix matrix = new Matrix ();
+ GraphicsPath gp = new GraphicsPath ();
+ gp.AddRectangle (new Rectangle (10, 10, 10, 10));
+ Region region = new Region (gp);
+ Assert.AreEqual (1, region.GetRegionScans (matrix).Length, "1");
+
+ gp.AddRectangle (new Rectangle (20, 20, 20, 20));
+ region = new Region (gp);
+ Assert.AreEqual (2, region.GetRegionScans (matrix).Length, "2");
+ }
+
+ [Test]
+ public void ExcludeFromInfinity ()
+ {
+ Region r = new Region ();
+ Assert.IsTrue (r.IsInfinite (graphic), "before");
+ r.Exclude (new Rectangle (5, 5, 10, 10));
+ Assert.IsFalse (r.IsInfinite (graphic), "after");
+ RectangleF bounds = r.GetBounds (graphic);
+ Assert.AreEqual (-4194304, bounds.X, "X");
+ Assert.AreEqual (-4194304, bounds.Y, "Y");
+ Assert.AreEqual (8388608, bounds.Width, "Width");
+ Assert.AreEqual (8388608, bounds.Height, "Height");
+ }
+ }
+
+ [TestFixture]
+#if TARGET_JVM
+ [Category ("NotWorking")]
+#endif
+ // the test cases in this fixture aren't restricted wrt running unmanaged code
+ public class RegionTestUnmanaged {
+
+ private Bitmap bitmap;
+ private Graphics graphic;
+
+ [TestFixtureSetUp]
+ public void FixtureSetUp ()
+ {
+ bitmap = new Bitmap (10, 10);
+ graphic = Graphics.FromImage (bitmap);
+ }
+
+ [Test]
+ public void GetHrgn_Infinite_MakeEmpty ()
+ {
+ Region r = new Region ();
+ Assert.IsFalse (r.IsEmpty (graphic), "!Empty");
+ Assert.IsTrue (r.IsInfinite (graphic), "Infinite");
+ Assert.AreEqual (IntPtr.Zero, r.GetHrgn (graphic), "Handle==0");
+
+ r.MakeEmpty ();
+ Assert.IsTrue (r.IsEmpty (graphic), "Empty");
+ Assert.IsFalse (r.IsInfinite (graphic), "!Infinite");
+ Assert.IsFalse (r.GetHrgn (graphic) == IntPtr.Zero, "Handle!=0");
+ }
+
+ [Test]
+ public void GetHrgn_Empty_MakeInfinite ()
+ {
+ Region r = new Region (new GraphicsPath ());
+ Assert.IsTrue (r.IsEmpty (graphic), "Empty");
+ Assert.IsFalse (r.IsInfinite (graphic), "!Infinite");
+ Assert.IsFalse (r.GetHrgn (graphic) == IntPtr.Zero, "Handle!=0");
+
+ r.MakeInfinite ();
+ Assert.IsFalse (r.IsEmpty (graphic), "!Empty");
+ Assert.IsTrue (r.IsInfinite (graphic), "Infinite");
+ Assert.AreEqual (IntPtr.Zero, r.GetHrgn (graphic), "Handle==0");
+ }
+
+ [Test]
+ public void GetHrgn_FromHrgn ()
+ {
+ Region r1 = new Region (new GraphicsPath ());
+ IntPtr h1 = r1.GetHrgn (graphic);
+ Assert.IsFalse (h1 == IntPtr.Zero, "Handle_1!=0");
+
+ Region r2 = Region.FromHrgn (h1);
+ IntPtr h2 = r2.GetHrgn (graphic);
+ Assert.IsFalse (h2 == IntPtr.Zero, "Handle_2!=0");
+ Assert.IsFalse (h1 == h2, "Handle_1!=Handle_2");
+ }
+
+ [Test]
+ [ExpectedException (typeof (ArgumentException))]
+ public void FromHrgn_Zero ()
+ {
+ Region.FromHrgn (IntPtr.Zero);
+ }
}
}