TestRegion.cs: Add test cases for ReleaseHrgn and fix GetHrgn tests to avoid leaking...
authorSebastien Pouliot <sebastien@ximian.com>
Mon, 26 Feb 2007 13:44:45 +0000 (13:44 -0000)
committerSebastien Pouliot <sebastien@ximian.com>
Mon, 26 Feb 2007 13:44:45 +0000 (13:44 -0000)
svn path=/trunk/mcs/; revision=73425

mcs/class/System.Drawing/Test/System.Drawing/ChangeLog
mcs/class/System.Drawing/Test/System.Drawing/TestRegion.cs

index d3edcdf07a3b48acb96975e4054ccbda0a983cc5..a2d19cc50c64cf2ecc95aa58615964f1e9a2cdda 100644 (file)
@@ -1,3 +1,8 @@
+2007-02-26  Sebastien Pouliot  <sebastien@ximian.com>
+
+       * TestRegion.cs: Add test cases for ReleaseHrgn and fix GetHrgn tests
+       to avoid leaking memory under 2.0 (where ReleaseHrgn is available).
+
 2007-02-21  Sebastien Pouliot  <sebastien@ximian.com> 
 
        * ColorConverter.cs: Rename fixture to match our styleguide.
index bb11bcd74d44eff23bed465abd2a5a58df69e441..0bf1528b351e22132ea84cebe0a1419e2a268a1b 100644 (file)
@@ -1542,6 +1542,9 @@ namespace MonoTests.System.Drawing
                        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 ()
                {
@@ -1553,7 +1556,11 @@ namespace MonoTests.System.Drawing
                        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]
@@ -1562,12 +1569,29 @@ namespace MonoTests.System.Drawing
                        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]
@@ -1581,6 +1605,10 @@ namespace MonoTests.System.Drawing
                        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]
@@ -1589,5 +1617,23 @@ namespace MonoTests.System.Drawing
                {
                        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
        }
 }