Author: spouliot
Date: 2007-02-26 08:44:45 -0500 (Mon, 26 Feb 2007)
New Revision: 73425

Modified:
   trunk/mcs/class/System.Drawing/Test/System.Drawing/ChangeLog
   trunk/mcs/class/System.Drawing/Test/System.Drawing/TestRegion.cs
Log:
 TestRegion.cs: Add test cases for ReleaseHrgn and fix GetHrgn tests to avoid 
leaking memory under 2.0 (where ReleaseHrgn is available).

Modified: trunk/mcs/class/System.Drawing/Test/System.Drawing/ChangeLog
===================================================================
--- trunk/mcs/class/System.Drawing/Test/System.Drawing/ChangeLog        
2007-02-26 13:42:51 UTC (rev 73424)
+++ trunk/mcs/class/System.Drawing/Test/System.Drawing/ChangeLog        
2007-02-26 13:44:45 UTC (rev 73425)
@@ -1,3 +1,8 @@
+2007-02-26  Sebastien Pouliot  <[EMAIL PROTECTED]>
+
+       * 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  <[EMAIL PROTECTED]> 
 
        * ColorConverter.cs: Rename fixture to match our styleguide.

Modified: trunk/mcs/class/System.Drawing/Test/System.Drawing/TestRegion.cs
===================================================================
--- trunk/mcs/class/System.Drawing/Test/System.Drawing/TestRegion.cs    
2007-02-26 13:42:51 UTC (rev 73424)
+++ trunk/mcs/class/System.Drawing/Test/System.Drawing/TestRegion.cs    
2007-02-26 13:44:45 UTC (rev 73425)
@@ -1542,6 +1542,9 @@
                        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 @@
                        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,15 +1569,32 @@
                        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]
                public void GetHrgn_FromHrgn ()
                {
                        Region r1 = new Region (new GraphicsPath ());
@@ -1581,6 +1605,10 @@
                        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 @@
                {
                        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
        }
 }

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to