graphic = Graphics.FromImage (bitmap);
}
+ // Note: Test cases calling GetHrng will leak memory unless ReleaseHrgn
+ // (which only exists in 2.0) is called.
+
[Test]
public void GetHrgn_Infinite_MakeEmpty ()
{
r.MakeEmpty ();
Assert.IsTrue (r.IsEmpty (graphic), "Empty");
Assert.IsFalse (r.IsInfinite (graphic), "!Infinite");
- Assert.IsFalse (r.GetHrgn (graphic) == IntPtr.Zero, "Handle!=0");
+ IntPtr h = r.GetHrgn (graphic);
+ Assert.IsFalse (h == IntPtr.Zero, "Handle!=0");
+#if NET_2_0
+ r.ReleaseHrgn (h);
+#endif
}
[Test]
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");
+ IntPtr h = r.GetHrgn (graphic);
+ Assert.IsFalse (h == 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");
+#if NET_2_0
+ r.ReleaseHrgn (h);
+#endif
+ }
+
+ [Test]
+ public void GetHrgn_TwiceFromSameRegionInstance ()
+ {
+ Region r = new Region (new GraphicsPath ());
+ IntPtr h1 = r.GetHrgn (graphic);
+ IntPtr h2 = r.GetHrgn (graphic);
+ Assert.IsFalse (h1 == h2, "Handle_1!=Handle_2");
+#if NET_2_0
+ r.ReleaseHrgn (h1);
+ r.ReleaseHrgn (h2);
+#endif
}
[Test]
IntPtr h2 = r2.GetHrgn (graphic);
Assert.IsFalse (h2 == IntPtr.Zero, "Handle_2!=0");
Assert.IsFalse (h1 == h2, "Handle_1!=Handle_2");
+#if NET_2_0
+ r1.ReleaseHrgn (h1);
+ r2.ReleaseHrgn (h2);
+#endif
}
[Test]
{
Region.FromHrgn (IntPtr.Zero);
}
+#if NET_2_0
+ [Test]
+ [ExpectedException (typeof (ArgumentNullException))]
+ public void ReleaseHrng_Zero ()
+ {
+ Region r = new Region (new GraphicsPath ());
+ r.ReleaseHrgn (IntPtr.Zero);
+ }
+
+ [Test]
+ public void ReleaseHrng ()
+ {
+ Region r = new Region (new GraphicsPath ());
+ IntPtr ptr = r.GetHrgn (graphic);
+ Assert.IsFalse (IntPtr.Zero == ptr, "ptr");
+ r.ReleaseHrgn (ptr);
+ }
+#endif
}
}