Преглед изворни кода

2006-01-11 Sebastien Pouliot <[email protected]>

	* RegionCas.cs: New. CAS unit tests for Region.
	* TestRegion.cs: Added test cases to check for expected exceptions.


svn path=/trunk/mcs/; revision=55392
Sebastien Pouliot пре 20 година
родитељ
комит
c84dde5dc2

+ 5 - 0
mcs/class/System.Drawing/Test/System.Drawing/ChangeLog

@@ -1,3 +1,8 @@
+2006-01-11  Sebastien Pouliot  <[email protected]>
+
+	* RegionCas.cs: New. CAS unit tests for Region.
+	* TestRegion.cs: Added test cases to check for expected exceptions.
+
 2005-12-05  Peter Dennis Bartok  <[email protected]>
 
 	* TestFont.cs: Added test for LogFont conversion

+ 97 - 0
mcs/class/System.Drawing/Test/System.Drawing/RegionCas.cs

@@ -0,0 +1,97 @@
+//
+// GraphicsCas.cs - CAS unit tests for System.Drawing.Graphics
+//
+// Author:
+//	Sebastien Pouliot  <[email protected]>
+//
+// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using NUnit.Framework;
+
+using System;
+using System.Drawing;
+using System.Reflection;
+using System.Security;
+using System.Security.Permissions;
+using System.Security.Policy;
+
+namespace MonoCasTests.System.Drawing {
+
+	[TestFixture]
+	[Category ("CAS")]
+	public class RegionCas {
+
+		private MethodInfo fromHdcInternal;
+		private MethodInfo fromHwndInternal;
+		private MethodInfo releaseHdcInternal;
+
+		[TestFixtureSetUp]
+		public void FixtureSetUp ()
+		{
+			// this executes at fulltrust
+			fromHdcInternal = typeof (Graphics).GetMethod ("FromHdcInternal");
+			fromHwndInternal = typeof (Graphics).GetMethod ("FromHwndInternal");
+			releaseHdcInternal = typeof (Graphics).GetMethod ("ReleaseHdcInternal");
+		}
+
+		[SetUp]
+		public void SetUp ()
+		{
+			if (!SecurityManager.SecurityEnabled)
+				Assert.Ignore ("SecurityManager.SecurityEnabled is OFF");
+		}
+
+		[Test]
+		[SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
+		[ExpectedException (typeof (SecurityException))]
+		public void FromHrgn_Deny_UnmanagedCode ()
+		{
+			Region.FromHrgn (IntPtr.Zero);
+		}
+
+		[Test]
+		[SecurityPermission (SecurityAction.PermitOnly, UnmanagedCode = true)]
+		[ExpectedException (typeof (ArgumentException))]
+		public void FromHrgn_PermitOnly_UnmanagedCode ()
+		{
+			Region.FromHrgn (IntPtr.Zero);
+		}
+#if NET_2_0
+		[Test]
+		[SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
+		[ExpectedException (typeof (SecurityException))]
+		public void ReleaseHrgn_Deny_UnmanagedCode ()
+		{
+			new Region ().ReleaseHrgn (IntPtr.Zero);
+		}
+
+		[Test]
+		[SecurityPermission (SecurityAction.PermitOnly, UnmanagedCode = true)]
+		[ExpectedException (typeof (ArgumentNullException))]
+		public void ReleaseHrgn_PermitOnly_UnmanagedCode ()
+		{
+			new Region ().ReleaseHrgn (IntPtr.Zero);
+		}
+#endif
+	}
+}

+ 206 - 15
mcs/class/System.Drawing/Test/System.Drawing/TestRegion.cs

@@ -1,12 +1,11 @@
 //
 // Region class testing unit
 //
-// Author:
+// Authors:
 //   Jordi Mas, [email protected]
+//   Sebastien Pouliot  <[email protected]>
 //
-
-//
-// Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2004-2006 Novell, Inc (http://www.novell.com)
 //
 // Permission is hereby granted, free of charge, to any person obtaining
 // a copy of this software and associated documentation files (the
@@ -42,15 +41,6 @@ namespace MonoTests.System.Drawing
 	[SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
 	public class TestRegion
 	{
-		[TearDown]
-		public void Clean() {}
-
-		[SetUp]
-		public void GetReady()
-		{
-
-		}
-
 		/* For debugging */
 		public static void DumpRegion (Region rgn)
 		{
@@ -1037,7 +1027,208 @@ namespace MonoTests.System.Drawing
 			Assert.AreEqual (120, rects[0].Height);
 		}
 
-	}
-}
+		[Test]
+		[ExpectedException (typeof (ArgumentNullException))]
+		public void Constructor_GraphicsPath_Null ()
+		{
+			GraphicsPath gp = null;
+			Region r = new Region (gp);
+		}
+
+		[Test]
+		[ExpectedException (typeof (ArgumentNullException))]
+		public void Constructor_RegionData_Null ()
+		{
+			RegionData rd = null;
+			Region r = new Region (rd);
+		}
+
+		[Test]
+		[ExpectedException (typeof (ArgumentNullException))]
+		public void Union_GraphicsPath_Null ()
+		{
+			GraphicsPath gp = null;
+			new Region ().Union (gp);
+		}
+
+		[Test]
+		[ExpectedException (typeof (ArgumentNullException))]
+		public void Union_Region_Null ()
+		{
+			Region r = null;
+			new Region ().Union (r);
+		}
+
+		[Test]
+		[ExpectedException (typeof (ArgumentNullException))]
+		public void Intersect_GraphicsPath_Null ()
+		{
+			GraphicsPath gp = null;
+			new Region ().Intersect (gp);
+		}
+
+		[Test]
+		[ExpectedException (typeof (ArgumentNullException))]
+		public void Intersect_Region_Null ()
+		{
+			Region r = null;
+			new Region ().Intersect (r);
+		}
+
+		[Test]
+		[ExpectedException (typeof (ArgumentNullException))]
+		public void Complement_GraphicsPath_Null ()
+		{
+			GraphicsPath gp = null;
+			new Region ().Complement (gp);
+		}
+
+		[Test]
+		[ExpectedException (typeof (ArgumentNullException))]
+		public void Complement_Region_Null ()
+		{
+			Region r = null;
+			new Region ().Complement (r);
+		}
+
+		[Test]
+		[ExpectedException (typeof (ArgumentNullException))]
+		public void Exclude_GraphicsPath_Null ()
+		{
+			GraphicsPath gp = null;
+			new Region ().Exclude (gp);
+		}
+
+		[Test]
+		[ExpectedException (typeof (ArgumentNullException))]
+		public void Exclude_Region_Null ()
+		{
+			Region r = null;
+			new Region ().Exclude (r);
+		}
+
+		[Test]
+		[ExpectedException (typeof (ArgumentNullException))]
+		public void Xor_GraphicsPath_Null ()
+		{
+			GraphicsPath gp = null;
+			new Region ().Xor (gp);
+		}
+
+		[Test]
+		[ExpectedException (typeof (ArgumentNullException))]
+		public void Xor_Region_Null ()
+		{
+			Region r = null;
+			new Region ().Xor (r);
+		}
+
+		[Test]
+		[ExpectedException (typeof (ArgumentNullException))]
+		public void GetBounds_Null ()
+		{
+			new Region ().GetBounds (null);
+		}
 
+		[Test]
+		public void IsVisible_IntIntNull ()
+		{
+			Assert.IsTrue (new Region ().IsVisible (0, 0, null));
+		}
+
+		[Test]
+		public void IsVisible_IntIntIntIntNull ()
+		{
+			Assert.IsFalse (new Region ().IsVisible (0, 0, 0, 0, null));
+		}
+
+		[Test]
+		public void IsVisible_PointNull ()
+		{
+			Point p = new Point ();
+			Assert.IsTrue (new Region ().IsVisible (p, null));
+		}
+
+		[Test]
+		public void IsVisible_PointFNull ()
+		{
+			PointF p = new PointF ();
+			Assert.IsTrue (new Region ().IsVisible (p, null));
+		}
+
+		[Test]
+		public void IsVisible_RectangleNull ()
+		{
+			Rectangle r = new Rectangle ();
+			Assert.IsFalse (new Region ().IsVisible (r, null));
+		}
+
+		[Test]
+		public void IsVisible_RectangleFNull ()
+		{
+			RectangleF r = new RectangleF ();
+			Assert.IsFalse (new Region ().IsVisible (r, null));
+		}
+
+		[Test]
+		public void IsVisible_SingleSingleNull ()
+		{
+			Assert.IsTrue (new Region ().IsVisible (0f, 0f, null));
+		}
+
+		[Test]
+		public void IsVisible_SingleSingleSingleSingleNull ()
+		{
+			Assert.IsFalse (new Region ().IsVisible (0f, 0f, 0f, 0f, null));
+		}
+
+		[Test]
+		[ExpectedException (typeof (ArgumentNullException))]
+		public void IsEmpty_Null ()
+		{
+			new Region ().IsEmpty (null);
+		}
+
+		[Test]
+		[ExpectedException (typeof (ArgumentNullException))]
+		public void IsInfinite_Null ()
+		{
+			new Region ().IsInfinite (null);
+		}
+
+		[Test]
+		[ExpectedException (typeof (ArgumentNullException))]
+		public void Equals_NullGraphics ()
+		{
+			new Region ().Equals (null, Graphics.FromImage (new Bitmap (10, 10)));
+		}
+
+		[Test]
+		[ExpectedException (typeof (ArgumentNullException))]
+		public void Equals_RegionNull ()
+		{
+			new Region ().Equals (new Region (), null);
+		}
+
+		[Test]
+		[ExpectedException (typeof (ArgumentNullException))]
+		public void GetHrgn_Null ()
+		{
+			new Region ().GetHrgn (null);
+		}
 
+		[Test]
+		[ExpectedException (typeof (ArgumentNullException))]
+		public void GetRegionScans_Null ()
+		{
+			new Region ().GetRegionScans (null);
+		}
+
+		[Test]
+		[ExpectedException (typeof (ArgumentNullException))]
+		public void Transform_Null ()
+		{
+			new Region ().Transform (null);
+		}
+	}
+}