// Jordi Mas, jordi@ximian.com
// Sebastien Pouliot <sebastien@ximian.com>
//
-// Copyright (C) 2004-2006 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2004-2008 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
}
[Test]
-#if TARGET_JVM
- [Category ("NotWorking")]
-#endif
public void TestCloneAndEquals()
{
Bitmap bmp = new Bitmap (600, 800);
/*Tests infinite, empty, etc*/
[Test]
-#if TARGET_JVM
- [Category ("NotWorking")]
-#endif
public void TestInfiniteAndEmpty()
{
Bitmap bmp = new Bitmap (600, 800);
[Test]
-#if TARGET_JVM
- [Category ("NotWorking")]
-#endif
public void TestUnionGroup1 ()
{
Bitmap bmp = new Bitmap (600, 800);
}
[Test]
-#if TARGET_JVM
- [Category ("NotWorking")]
-#endif
public void TestUnionGroup2 ()
{
RectangleF[] rects;
[Test]
-#if TARGET_JVM
- [Category ("NotWorking")]
-#endif
public void TestComplementGroup1 ()
{
RectangleF[] rects;
}
[Test]
-#if TARGET_JVM
- [Category ("NotWorking")]
-#endif
public void TestComplementGroup2 ()
{
[Test]
-#if TARGET_JVM
- [Category ("NotWorking")]
-#endif
public void TestExcludeGroup1 ()
{
RectangleF[] rects;
}
[Test]
-#if TARGET_JVM
- [Category ("NotWorking")]
-#endif
public void TestExcludeGroup2 ()
{
Bitmap bmp = new Bitmap (600, 800);
}
[Test]
-#if TARGET_JVM
- [Category ("NotWorking")]
-#endif
+ public void ExcludeBug402613 ()
+ {
+ Region r = new Region();
+ r.MakeInfinite ();
+ r.Exclude (new Rectangle (387,292,189,133));
+ r.Exclude (new Rectangle (387,66,189,133));
+ Assert.IsTrue (r.IsVisible (new Rectangle (66,292,189,133)));
+ }
+
+ [Test]
public void TestIntersect()
{
}
[Test]
-#if TARGET_JVM
- [Category ("NotWorking")]
-#endif
public void TestXor()
{
Bitmap bmp = new Bitmap (600, 800);
}
[Test]
-#if TARGET_JVM
- [Category ("NotWorking")]
-#endif
public void TestTranslate()
{
Region rgn1 = new Region (new RectangleF (10, 10, 120,120));
}
[Test]
- [ExpectedException (typeof (ArgumentNullException))]
-#if TARGET_JVM
- [Category ("NotWorking")]
-#endif
public void Constructor_GraphicsPath_Null ()
{
GraphicsPath gp = null;
- Region r = new Region (gp);
+ Assert.Throws<ArgumentNullException> (() => new Region (gp));
}
[Test]
- [ExpectedException (typeof (ArgumentNullException))]
-#if TARGET_JVM
- [Category ("NotWorking")]
-#endif
public void Constructor_RegionData_Null ()
{
RegionData rd = null;
- Region r = new Region (rd);
+ Assert.Throws<ArgumentNullException> (() => new Region (rd));
}
[Test]
- [ExpectedException (typeof (ArgumentNullException))]
public void Union_GraphicsPath_Null ()
{
GraphicsPath gp = null;
- new Region ().Union (gp);
+ Assert.Throws<ArgumentNullException> (() => new Region ().Union (gp));
}
[Test]
- [ExpectedException (typeof (ArgumentNullException))]
public void Union_Region_Null ()
{
Region r = null;
- new Region ().Union (r);
+ Assert.Throws<ArgumentNullException> (() => new Region ().Union (r));
}
[Test]
}
[Test]
- [ExpectedException (typeof (ArgumentNullException))]
public void Intersect_GraphicsPath_Null ()
{
GraphicsPath gp = null;
- new Region ().Intersect (gp);
+ Assert.Throws<ArgumentNullException> (() => new Region ().Intersect (gp));
}
[Test]
- [ExpectedException (typeof (ArgumentNullException))]
public void Intersect_Region_Null ()
{
Region r = null;
- new Region ().Intersect (r);
+ Assert.Throws<ArgumentNullException> (() => new Region ().Intersect (r));
}
[Test]
- [ExpectedException (typeof (ArgumentNullException))]
public void Complement_GraphicsPath_Null ()
{
GraphicsPath gp = null;
- new Region ().Complement (gp);
+ Assert.Throws<ArgumentNullException> (() => new Region ().Complement (gp));
}
[Test]
- [ExpectedException (typeof (ArgumentNullException))]
public void Complement_Region_Null ()
{
Region r = null;
- new Region ().Complement (r);
+ Assert.Throws<ArgumentNullException> (() => new Region ().Complement (r));
}
[Test]
- [ExpectedException (typeof (ArgumentNullException))]
public void Exclude_GraphicsPath_Null ()
{
GraphicsPath gp = null;
- new Region ().Exclude (gp);
+ Assert.Throws<ArgumentNullException> (() => new Region ().Exclude (gp));
}
[Test]
- [ExpectedException (typeof (ArgumentNullException))]
public void Exclude_Region_Null ()
{
Region r = null;
- new Region ().Exclude (r);
+ Assert.Throws<ArgumentNullException> (() => new Region ().Exclude (r));
}
[Test]
- [ExpectedException (typeof (ArgumentNullException))]
public void Xor_GraphicsPath_Null ()
{
GraphicsPath gp = null;
- new Region ().Xor (gp);
+ Assert.Throws<ArgumentNullException> (() => new Region ().Xor (gp));
}
[Test]
- [ExpectedException (typeof (ArgumentNullException))]
public void Xor_Region_Null ()
{
Region r = null;
- new Region ().Xor (r);
+ Assert.Throws<ArgumentNullException> (() => new Region ().Xor (r));
}
[Test]
- [ExpectedException (typeof (ArgumentNullException))]
public void GetBounds_Null ()
{
- new Region ().GetBounds (null);
+ Assert.Throws<ArgumentNullException> (() => new Region ().GetBounds (null));
}
[Test]
-#if TARGET_JVM
- [Category ("NotWorking")]
-#endif
public void IsVisible_IntIntNull ()
{
Assert.IsTrue (new Region ().IsVisible (0, 0, null));
}
[Test]
-#if TARGET_JVM
- [Category ("NotWorking")]
-#endif
public void IsVisible_IntIntIntIntNull ()
{
Assert.IsFalse (new Region ().IsVisible (0, 0, 0, 0, null));
}
[Test]
-#if TARGET_JVM
- [Category ("NotWorking")]
-#endif
public void IsVisible_PointNull ()
{
Point p = new Point ();
}
[Test]
-#if TARGET_JVM
- [Category ("NotWorking")]
-#endif
public void IsVisible_PointFNull ()
{
PointF p = new PointF ();
}
[Test]
-#if TARGET_JVM
- [Category ("NotWorking")]
-#endif
public void IsVisible_RectangleNull ()
{
Rectangle r = new Rectangle ();
}
[Test]
-#if TARGET_JVM
- [Category ("NotWorking")]
-#endif
public void IsVisible_RectangleFNull ()
{
RectangleF r = new RectangleF ();
}
[Test]
-#if TARGET_JVM
- [Category ("NotWorking")]
-#endif
public void IsVisible_SingleSingleNull ()
{
Assert.IsTrue (new Region ().IsVisible (0f, 0f, null));
}
[Test]
-#if TARGET_JVM
- [Category ("NotWorking")]
-#endif
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);
+ Assert.Throws<ArgumentNullException> (() => new Region ().IsEmpty (null));
}
[Test]
- [ExpectedException (typeof (ArgumentNullException))]
public void IsInfinite_Null ()
{
- new Region ().IsInfinite (null);
+ Assert.Throws<ArgumentNullException> (() => new Region ().IsInfinite (null));
}
[Test]
-#if TARGET_JVM
- [Category ("NotWorking")]
-#endif
- [ExpectedException (typeof (ArgumentNullException))]
public void Equals_NullGraphics ()
{
- new Region ().Equals (null, Graphics.FromImage (new Bitmap (10, 10)));
+ Assert.Throws<ArgumentNullException> (() => new Region ().Equals (null, Graphics.FromImage (new Bitmap (10, 10))));
}
[Test]
- [ExpectedException (typeof (ArgumentNullException))]
public void Equals_RegionNull ()
{
- new Region ().Equals (new Region (), null);
+ Assert.Throws<ArgumentNullException> (() => new Region ().Equals (new Region (), null));
}
[Test]
- [ExpectedException (typeof (ArgumentNullException))]
[Category ("NotWorking")] // caused regression in SWF
public void GetHrgn_Null ()
{
- new Region ().GetHrgn (null);
+ Assert.Throws<ArgumentNullException> (() => new Region ().GetHrgn (null));
}
[Test]
-#if TARGET_JVM
- [Category ("NotWorking")]
-#endif
- [ExpectedException (typeof (ArgumentNullException))]
public void GetRegionScans_Null ()
{
- new Region ().GetRegionScans (null);
+ Assert.Throws<ArgumentNullException> (() => new Region ().GetRegionScans (null));
}
[Test]
- [ExpectedException (typeof (ArgumentNullException))]
public void Transform_Null ()
{
- new Region ().Transform (null);
+ Assert.Throws<ArgumentNullException> (() => new Region ().Transform (null));
}
// an "empty ctor" Region is infinite
}
[Test]
-#if TARGET_JVM
- [Category ("NotWorking")]
-#endif
public void Region_Empty ()
{
Region region = new Region ();
}
[Test]
-#if TARGET_JVM
- [Category ("NotWorking")]
-#endif
public void Rectangle_GetRegionScans ()
{
Matrix matrix = new Matrix ();
}
[Test]
- public void ExcludeFromInfinity ()
+ public void InfinityExclude ()
{
- 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");
+ using (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");
+ }
+ }
+
+ [Test]
+ public void InfinityIntersect ()
+ {
+ using (Region r = new Region ()) {
+ Assert.IsTrue (r.IsInfinite (graphic), "before");
+ r.Intersect (new Rectangle (-10, -10, 20, 20));
+ Assert.IsFalse (r.IsInfinite (graphic), "after");
+ RectangleF bounds = r.GetBounds (graphic);
+ Assert.AreEqual (-10, bounds.X, "X");
+ Assert.AreEqual (-10, bounds.Y, "Y");
+ Assert.AreEqual (20, bounds.Width, "Width");
+ Assert.AreEqual (20, bounds.Height, "Height");
+ }
+ }
+
+ [Test]
+ public void InfinityIntersectTranslate ()
+ {
+ using (Region r = new Region ()) {
+ Assert.IsTrue (r.IsInfinite (graphic), "before");
+ r.Intersect (new Rectangle (-10, -10, 20, 20));
+ r.Translate (10, 10);
+ RectangleF bounds = r.GetBounds (graphic);
+ Assert.AreEqual (0, bounds.X, "X");
+ Assert.AreEqual (0, bounds.Y, "Y");
+ Assert.AreEqual (20, bounds.Width, "Width");
+ Assert.AreEqual (20, bounds.Height, "Height");
+ }
+ }
+
+ [Test]
+ public void InfinityIntersectScale ()
+ {
+ using (Region r = new Region ()) {
+ Assert.IsTrue (r.IsInfinite (graphic), "before");
+ r.Intersect (new Rectangle (-10, -10, 20, 20));
+ using (Matrix m = new Matrix ()) {
+ m.Scale (2, 0.5f);
+ r.Transform (m);
+ }
+ RectangleF bounds = r.GetBounds (graphic);
+ Assert.AreEqual (-20, bounds.X, "X");
+ Assert.AreEqual (-5, bounds.Y, "Y");
+ Assert.AreEqual (40, bounds.Width, "Width");
+ Assert.AreEqual (10, bounds.Height, "Height");
+ }
+ }
+
+ [Test]
+ public void InfinityIntersectTransform ()
+ {
+ using (Region r = new Region ()) {
+ Assert.IsTrue (r.IsInfinite (graphic), "before");
+ r.Intersect (new Rectangle (-10, -10, 20, 20));
+ using (Matrix m = new Matrix (2, 0, 0, 0.5f, 10, 10)) {
+ r.Transform (m);
+ }
+ RectangleF bounds = r.GetBounds (graphic);
+ Assert.AreEqual (-10, bounds.X, "X");
+ Assert.AreEqual (5, bounds.Y, "Y");
+ Assert.AreEqual (40, bounds.Width, "Width");
+ Assert.AreEqual (10, bounds.Height, "Height");
+ }
+ }
+
+ [Test]
+ public void InfinityTranslate ()
+ {
+ using (Region r = new Region ()) {
+ Assert.IsTrue (r.IsInfinite (graphic), "before");
+ r.Translate (10, 10);
+ Assert.IsTrue (r.IsInfinite (graphic), "after");
+ CheckEmpty ("InfinityTranslate", r);
+ }
+ }
+
+ [Test]
+ public void InfinityScaleUp ()
+ {
+ using (Region r = new Region ()) {
+ Assert.IsTrue (r.IsInfinite (graphic), "before");
+ using (Matrix m = new Matrix ()) {
+ m.Scale (2, 2);
+ r.Transform (m);
+ }
+ Assert.IsTrue (r.IsInfinite (graphic), "after");
+ CheckEmpty ("InfinityScaleUp", r);
+ }
+ }
+
+ [Test]
+ public void InfinityScaleDown ()
+ {
+ using (Region r = new Region ()) {
+ Assert.IsTrue (r.IsInfinite (graphic), "before");
+ using (Matrix m = new Matrix ()) {
+ m.Scale (0.5f, 0.5f);
+ r.Transform (m);
+ }
+ Assert.IsTrue (r.IsInfinite (graphic), "after");
+ CheckEmpty ("InfinityScaleDown", r);
+ }
+ }
+
+ [Test]
+ public void InfinityRotate ()
+ {
+ using (Region r = new Region ()) {
+ Assert.IsTrue (r.IsInfinite (graphic), "before");
+ using (Matrix m = new Matrix ()) {
+ m.Rotate (45);
+ r.Transform (m);
+ }
+ Assert.IsTrue (r.IsInfinite (graphic), "after");
+ CheckEmpty ("InfinityRotate", r);
+ }
+ }
+
+ [Test]
+ public void Intersect_383878 ()
+ {
+ using (Region clipRegion = new Region ()) {
+ clipRegion.MakeInfinite ();
+
+ Rectangle smaller = new Rectangle (5, 5, -10, -10);
+
+ clipRegion.Intersect (smaller);
+ Assert.IsFalse (clipRegion.IsEmpty (graphic), "IsEmpty");
+ Assert.IsFalse (clipRegion.IsInfinite (graphic), "IsInfinite");
+
+ RectangleF [] rects = clipRegion.GetRegionScans (new Matrix ());
+ Assert.AreEqual (1, rects.Length, "Length");
+ Assert.AreEqual (new RectangleF (-5, -5, 10, 10), rects [0], "0");
+ }
+ }
+
+ [Test]
+ public void Complement_383878 ()
+ {
+ using (Region clipRegion = new Region ()) {
+ clipRegion.MakeInfinite ();
+
+ Rectangle smaller = new Rectangle (5, 5, -10, -10);
+ Rectangle bigger = new Rectangle (-5, -5, 12, 12);
+
+ clipRegion.Intersect (smaller);
+ clipRegion.Complement (bigger);
+
+ Assert.IsFalse (clipRegion.IsEmpty (graphic), "IsEmpty");
+ Assert.IsFalse (clipRegion.IsInfinite (graphic), "IsInfinite");
+
+ RectangleF [] rects = clipRegion.GetRegionScans (new Matrix ());
+ Assert.AreEqual (2, rects.Length, "Length");
+ Assert.AreEqual (new RectangleF (5, -5, 2, 10), rects [0], "0");
+ Assert.AreEqual (new RectangleF (-5, 5, 12, 2), rects [1], "1");
+ }
}
}
[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;
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");
+ r.ReleaseHrgn (h);
}
[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");
+ r.ReleaseHrgn (h);
+ }
+
+ [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");
+ r.ReleaseHrgn (h1);
+ r.ReleaseHrgn (h2);
}
[Test]
IntPtr h2 = r2.GetHrgn (graphic);
Assert.IsFalse (h2 == IntPtr.Zero, "Handle_2!=0");
Assert.IsFalse (h1 == h2, "Handle_1!=Handle_2");
+ r1.ReleaseHrgn (h1);
+ r2.ReleaseHrgn (h2);
}
[Test]
- [ExpectedException (typeof (ArgumentException))]
public void FromHrgn_Zero ()
{
- Region.FromHrgn (IntPtr.Zero);
+ Assert.Throws<ArgumentException> (() => Region.FromHrgn (IntPtr.Zero));
+ }
+ [Test]
+ public void ReleaseHrng_Zero ()
+ {
+ Region r = new Region (new GraphicsPath ());
+ Assert.Throws<ArgumentNullException> (() => 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);
}
}
}