New test.
[mono.git] / mcs / class / System.Drawing / Test / System.Drawing / TestRegion.cs
index cd953b462b0bbab70ae2155cee17a59e7388e032..efd9f2e7bb57b16ddf814ae7872106d1576d180c 100644 (file)
@@ -1108,6 +1108,17 @@ namespace MonoTests.System.Drawing
                        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 ()
@@ -1362,5 +1373,102 @@ namespace MonoTests.System.Drawing
                        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);
+               }
        }
 }