2007-05-15 Sebastien Pouliot <sebastien@ximian.com>
authorSebastien Pouliot <sebastien@ximian.com>
Tue, 15 May 2007 20:16:00 +0000 (20:16 -0000)
committerSebastien Pouliot <sebastien@ximian.com>
Tue, 15 May 2007 20:16:00 +0000 (20:16 -0000)
* GDIPlusTest.cs: Add test cases for GdipDrawImage[I] (overflow) and
GdipDrawImageRectRect (GraphicsUnit).
* TestGraphics.cs: Add test cases for DrawImage, DrawImageUnscaled and
DrawImageUnscaledAndClipped (2.0).
* TestRectangle.cs: Add test cases for negative width/height. Fix some
test cases that were using RectangleF instead of Rectangle.
* TestRectangleF.cs: Add test cases for negative width/height.

svn path=/trunk/mcs/; revision=77436

mcs/class/System.Drawing/Test/System.Drawing/ChangeLog
mcs/class/System.Drawing/Test/System.Drawing/GDIPlusTest.cs
mcs/class/System.Drawing/Test/System.Drawing/TestGraphics.cs
mcs/class/System.Drawing/Test/System.Drawing/TestRectangle.cs
mcs/class/System.Drawing/Test/System.Drawing/TestRectangleF.cs

index a2de5a8f661c6d485074473d3fd49f09b14ebd5a..1f2d0dbf8687ab5f295d04063f90a5924160ad50 100644 (file)
@@ -1,3 +1,13 @@
+2007-05-15  Sebastien Pouliot  <sebastien@ximian.com>
+
+       * GDIPlusTest.cs: Add test cases for GdipDrawImage[I] (overflow) and 
+       GdipDrawImageRectRect (GraphicsUnit).
+       * TestGraphics.cs: Add test cases for DrawImage, DrawImageUnscaled and
+       DrawImageUnscaledAndClipped (2.0).
+       * TestRectangle.cs: Add test cases for negative width/height. Fix some
+       test cases that were using RectangleF instead of Rectangle.
+       * TestRectangleF.cs: Add test cases for negative width/height.
+
 2007-05-08  Everaldo Canuto  <everaldo@simios.org>
 
        * TestGraphics.cs: MeasureString_MultlineString_Width added (NotWorking)
index ead3992f06bc0f24e76a6492887b70384678f3bb..640ed6a299800b750ae9524855ce4189aaede18a 100644 (file)
@@ -218,24 +218,92 @@ namespace MonoTests.System.Drawing {
 
                // Graphics
                [Test]
-               public void Graphics_FromImage ()
+               public void GdipGetImageGraphicsContext_Null ()
                {
                        IntPtr graphics;
                        Assert.AreEqual (Status.InvalidParameter, GDIPlus.GdipGetImageGraphicsContext (IntPtr.Zero, out graphics), "GdipGetImageGraphicsContext");
+               }
 
-                       IntPtr image;
-                       GDIPlus.GdipCreateBitmapFromScan0 (10, 10, 0, PixelFormat.Format32bppArgb, IntPtr.Zero, out image);
-                       Assert.IsTrue (image != IntPtr.Zero, "image");
-
+               private void Graphics_DrawImage (IntPtr image, bool metafile)
+               {
+                       IntPtr graphics;
                        Assert.AreEqual (Status.Ok, GDIPlus.GdipGetImageGraphicsContext (image, out graphics), "GdipGetImageGraphicsContext");
                        Assert.IsTrue (graphics != IntPtr.Zero, "graphics");
 
+                       if (metafile) {
+                               Assert.AreEqual (Status.Ok, GDIPlus.GdipDrawImage (graphics, image, Single.MinValue, Single.MaxValue), "FloatMinMax");
+                               Assert.AreEqual (Status.Ok, GDIPlus.GdipDrawImageI (graphics, image, Int32.MinValue, Int32.MaxValue), "IntMinMax");
+                       } else {
+                               Assert.AreEqual (Status.ValueOverflow, GDIPlus.GdipDrawImage (graphics, image, Single.MinValue, Single.MaxValue), "FloatOverflow");
+                               Assert.AreEqual (Status.Ok, GDIPlus.GdipDrawImage (graphics, image, 1073741888, 0), "FloatXMax");
+                               Assert.AreEqual (Status.ValueOverflow, GDIPlus.GdipDrawImage (graphics, image, 1073741889, 0), "FloatXMaxOverflow");
+                               Assert.AreEqual (Status.Ok, GDIPlus.GdipDrawImage (graphics, image, 0, 1073741888), "FloatYMax");
+                               Assert.AreEqual (Status.ValueOverflow, GDIPlus.GdipDrawImage (graphics, image, 0, 1073741889), "FloatYMaxOverflow");
+                               Assert.AreEqual (Status.Ok, GDIPlus.GdipDrawImage (graphics, image, -1073741888, 0), "FloatXMin");
+                               Assert.AreEqual (Status.ValueOverflow, GDIPlus.GdipDrawImage (graphics, image, -1073741889, 0), "FloatXMinOverflow");
+                               Assert.AreEqual (Status.Ok, GDIPlus.GdipDrawImage (graphics, image, 0, -1073741888), "FloatYMin");
+                               Assert.AreEqual (Status.ValueOverflow, GDIPlus.GdipDrawImage (graphics, image, 0, -1073741889), "FloatYMinOverflow");
+
+                               Assert.AreEqual (Status.ValueOverflow, GDIPlus.GdipDrawImageI (graphics, image, Int32.MinValue, Int32.MaxValue), "IntOverflow");
+                               // the real limit of MS GDI+ is 1073741951 but differs (by a very few) from the float limit 
+                               Assert.AreEqual (Status.Ok, GDIPlus.GdipDrawImageI (graphics, image, 1073741824, 0), "IntXMax");
+                               Assert.AreEqual (Status.ValueOverflow, GDIPlus.GdipDrawImageI (graphics, image, 1073741952, 0), "IntXMaxOverflow");
+                               Assert.AreEqual (Status.Ok, GDIPlus.GdipDrawImageI (graphics, image, 0, 1073741824), "IntYMax");
+                               Assert.AreEqual (Status.ValueOverflow, GDIPlus.GdipDrawImageI (graphics, image, 0, 1073741952), "IntYMaxOverflow");
+                               Assert.AreEqual (Status.Ok, GDIPlus.GdipDrawImageI (graphics, image, -1073741824, 0), "IntXMin");
+                               // the real limit of MS GDI+ is -1073741825 but int-to-float convertion in libgdiplus turns this into a -1073741824
+                               Assert.AreEqual (Status.ValueOverflow, GDIPlus.GdipDrawImageI (graphics, image, -1073741899, 0), "IntXMinOverflow");
+                               Assert.AreEqual (Status.Ok, GDIPlus.GdipDrawImageI (graphics, image, 0, -1073741824), "IntYMin");
+                               Assert.AreEqual (Status.ValueOverflow, GDIPlus.GdipDrawImageI (graphics, image, 0, -1073741899), "IntYMinOverflow");
+                       }
+
+                       Assert.AreEqual (Status.InvalidParameter, GDIPlus.GdipDrawImageRectRectI (graphics, image, 0, 0, 10, 10, 0, 0, 10, 10, GraphicsUnit.Display, IntPtr.Zero, null, IntPtr.Zero), "Display");
+                       Assert.AreEqual (Status.NotImplemented, GDIPlus.GdipDrawImageRectRectI (graphics, image, 0, 0, 10, 10, 0, 0, 10, 10, GraphicsUnit.Document, IntPtr.Zero, null, IntPtr.Zero), "Document");
+                       Assert.AreEqual (Status.NotImplemented, GDIPlus.GdipDrawImageRectRectI (graphics, image, 0, 0, 10, 10, 0, 0, 10, 10, GraphicsUnit.Inch, IntPtr.Zero, null, IntPtr.Zero), "Inch");
+                       Assert.AreEqual (Status.NotImplemented, GDIPlus.GdipDrawImageRectRectI (graphics, image, 0, 0, 10, 10, 0, 0, 10, 10, GraphicsUnit.Millimeter, IntPtr.Zero, null, IntPtr.Zero), "Millimeter");
+                       Assert.AreEqual (Status.Ok, GDIPlus.GdipDrawImageRectRectI (graphics, image, 0, 0, 10, 10, 0, 0, 10, 10, GraphicsUnit.Pixel, IntPtr.Zero, null, IntPtr.Zero), "Pixel");
+                       Assert.AreEqual (Status.NotImplemented, GDIPlus.GdipDrawImageRectRectI (graphics, image, 0, 0, 10, 10, 0, 0, 10, 10, GraphicsUnit.Point, IntPtr.Zero, null, IntPtr.Zero), "Point");
+                       Assert.AreEqual (Status.InvalidParameter, GDIPlus.GdipDrawImageRectRectI (graphics, image, 0, 0, 10, 10, 0, 0, 10, 10, GraphicsUnit.World, IntPtr.Zero, null, IntPtr.Zero), "World");
+                       Assert.AreEqual (Status.InvalidParameter, GDIPlus.GdipDrawImageRectRectI (graphics, image, 0, 0, 10, 10, 0, 0, 10, 10, (GraphicsUnit) Int32.MinValue, IntPtr.Zero, null, IntPtr.Zero), "invalid");
+
                        Assert.AreEqual (Status.Ok, GDIPlus.GdipDeleteGraphics (graphics), "GdipDeleteGraphics");
                        Assert.AreEqual (Status.InvalidParameter, GDIPlus.GdipDeleteGraphics (IntPtr.Zero), "GdipDeleteGraphics-null");
+               }
+
+               [Test]
+               public void Graphics_FromImage_Bitmap ()
+               {
+                       IntPtr image;
+                       GDIPlus.GdipCreateBitmapFromScan0 (10, 10, 0, PixelFormat.Format32bppArgb, IntPtr.Zero, out image);
+                       Assert.IsTrue (image != IntPtr.Zero, "image");
+
+                       Graphics_DrawImage (image, false);
 
                        Assert.AreEqual (Status.Ok, GDIPlus.GdipDisposeImage (image), "GdipDisposeImage");
                }
 
+               [Test]
+               [Category ("NotWorking")] // incomplete GdipDrawImageRectRect[I] support
+               public void Graphics_FromImage_Metafile ()
+               {
+                       using (Bitmap bmp = new Bitmap (100, 100, PixelFormat.Format32bppArgb)) {
+                               using (Graphics g = Graphics.FromImage (bmp)) {
+                                       IntPtr metafile = IntPtr.Zero;
+                                       IntPtr hdc = g.GetHdc ();
+                                       try {
+                                               RectangleF rect = new RectangleF (10, 20, 100, 200);
+                                               Assert.AreEqual (Status.Ok, GDIPlus.GdipRecordMetafileFileName ("test-drawimage.emf", hdc, EmfType.EmfPlusOnly, ref rect, MetafileFrameUnit.GdiCompatible, null, out metafile), "GdipRecordMetafileFileName");
+                                               Assert.IsTrue (metafile != IntPtr.Zero, "image");
+
+                                               Graphics_DrawImage (metafile, true);
+                                       }
+                                       finally {
+                                               Assert.AreEqual (Status.Ok, GDIPlus.GdipDisposeImage (metafile), "GdipDisposeImage");
+                                       }
+                               }
+                       }
+               }
+
                [Test]
                public void MeasureCharacterRanges ()
                {
index fc2d3c957da4383fddcbf235e3929ab451ec725b..16d63d03869627ce7ab874c34b14bd8db1f3f643 100644 (file)
@@ -2192,5 +2192,518 @@ namespace MonoTests.System.Drawing
                                }
                        }
                }
+
+               [Test]
+               [ExpectedException (typeof (ArgumentNullException))]
+               public void DrawIcon_NullRectangle ()
+               {
+                       using (Bitmap bmp = new Bitmap (40, 40)) {
+                               using (Graphics g = Graphics.FromImage (bmp)) {
+                                       g.DrawIcon (null, new Rectangle (0, 0, 32, 32));
+                               }
+                       }
+               }
+
+               [Test]
+               public void DrawIcon_IconRectangle ()
+               {
+                       using (Bitmap bmp = new Bitmap (40, 40)) {
+                               using (Graphics g = Graphics.FromImage (bmp)) {
+                                       g.DrawIcon (SystemIcons.Application, new Rectangle (0, 0, 40, 20));
+                                       // Rectangle is empty when X, Y, Width and Height == 0 
+                                       // (yep X and Y too, RectangleF only checks for Width and Height)
+                                       g.DrawIcon (SystemIcons.Asterisk, new Rectangle (0, 0, 0, 0));
+                                       // so this one is half-empty ;-)
+                                       g.DrawIcon (SystemIcons.Error, new Rectangle (20, 40, 0, 0));
+                                       // negative width or height isn't empty (for Rectangle)
+                                       g.DrawIconUnstretched (SystemIcons.WinLogo, new Rectangle (10, 20, -1, 0));
+                                       g.DrawIconUnstretched (SystemIcons.WinLogo, new Rectangle (20, 10, 0, -1));
+                               }
+                       }
+               }
+
+               [Test]
+               [ExpectedException (typeof (ArgumentNullException))]
+               public void DrawIcon_NullIntInt ()
+               {
+                       using (Bitmap bmp = new Bitmap (40, 40)) {
+                               using (Graphics g = Graphics.FromImage (bmp)) {
+                                       g.DrawIcon (null, 4, 2);
+                               }
+                       }
+               }
+
+               [Test]
+               public void DrawIcon_IconIntInt ()
+               {
+                       using (Bitmap bmp = new Bitmap (40, 40)) {
+                               using (Graphics g = Graphics.FromImage (bmp)) {
+                                       g.DrawIcon (SystemIcons.Exclamation, 4, 2);
+                                       g.DrawIcon (SystemIcons.Hand, 0, 0);
+                               }
+                       }
+               }
+
+               [Test]
+               [ExpectedException (typeof (ArgumentNullException))]
+               public void DrawIconUnstretched_NullRectangle ()
+               {
+                       using (Bitmap bmp = new Bitmap (40, 40)) {
+                               using (Graphics g = Graphics.FromImage (bmp)) {
+                                       g.DrawIconUnstretched (null, new Rectangle (0, 0, 40, 20));
+                               }
+                       }
+               }
+
+               [Test]
+               public void DrawIconUnstretched_IconRectangle ()
+               {
+                       using (Bitmap bmp = new Bitmap (40, 40)) {
+                               using (Graphics g = Graphics.FromImage (bmp)) {
+                                       g.DrawIconUnstretched (SystemIcons.Information, new Rectangle (0, 0, 40, 20));
+                                       // Rectangle is empty when X, Y, Width and Height == 0 
+                                       // (yep X and Y too, RectangleF only checks for Width and Height)
+                                       g.DrawIconUnstretched (SystemIcons.Question, new Rectangle (0, 0, 0, 0));
+                                       // so this one is half-empty ;-)
+                                       g.DrawIconUnstretched (SystemIcons.Warning, new Rectangle (20, 40, 0, 0));
+                                       // negative width or height isn't empty (for Rectangle)
+                                       g.DrawIconUnstretched (SystemIcons.WinLogo, new Rectangle (10, 20, -1, 0));
+                                       g.DrawIconUnstretched (SystemIcons.WinLogo, new Rectangle (20, 10, 0, -1));
+                               }
+                       }
+               }
+
+               [Test]
+               [ExpectedException (typeof (ArgumentNullException))]
+               public void DrawImage_NullRectangleF ()
+               {
+                       using (Bitmap bmp = new Bitmap (40, 40)) {
+                               using (Graphics g = Graphics.FromImage (bmp)) {
+                                       g.DrawImage (null, new RectangleF (0, 0, 0, 0));
+                               }
+                       }
+               }
+
+               [Test]
+               public void DrawImage_ImageRectangleF ()
+               {
+                       using (Bitmap bmp = new Bitmap (40, 40)) {
+                               using (Graphics g = Graphics.FromImage (bmp)) {
+                                       g.DrawImage (bmp, new RectangleF (0, 0, 0, 0));
+                                       g.DrawImage (bmp, new RectangleF (20, 40, 0, 0));
+                                       g.DrawImage (bmp, new RectangleF (10, 20, -1, 0));
+                                       g.DrawImage (bmp, new RectangleF (20, 10, 0, -1));
+                               }
+                       }
+               }
+
+               [Test]
+               [ExpectedException (typeof (ArgumentNullException))]
+               public void DrawImage_NullPointF ()
+               {
+                       using (Bitmap bmp = new Bitmap (40, 40)) {
+                               using (Graphics g = Graphics.FromImage (bmp)) {
+                                       g.DrawImage (null, new PointF (0, 0));
+                               }
+                       }
+               }
+
+               [Test]
+               public void DrawImage_ImagePointF ()
+               {
+                       using (Bitmap bmp = new Bitmap (40, 40)) {
+                               using (Graphics g = Graphics.FromImage (bmp)) {
+                                       g.DrawImage (bmp, new PointF (0, 0));
+                               }
+                       }
+               }
+
+               [Test]
+               [ExpectedException (typeof (ArgumentNullException))]
+               public void DrawImage_NullPointFArray ()
+               {
+                       using (Bitmap bmp = new Bitmap (40, 40)) {
+                               using (Graphics g = Graphics.FromImage (bmp)) {
+                                       g.DrawImage (null, new PointF[0]);
+                               }
+                       }
+               }
+
+               [Test]
+               [ExpectedException (typeof (ArgumentNullException))]
+               public void DrawImage_ImagePointFArrayNull ()
+               {
+                       using (Bitmap bmp = new Bitmap (40, 40)) {
+                               using (Graphics g = Graphics.FromImage (bmp)) {
+                                       g.DrawImage (bmp, (PointF[])null);
+                               }
+                       }
+               }
+
+               [Test]
+               [ExpectedException (typeof (ArgumentException))]
+               public void DrawImage_ImagePointFArrayEmpty ()
+               {
+                       using (Bitmap bmp = new Bitmap (40, 40)) {
+                               using (Graphics g = Graphics.FromImage (bmp)) {
+                                       g.DrawImage (bmp, new PointF[0]);
+                               }
+                       }
+               }
+
+               [Test]
+               public void DrawImage_ImagePointFArray ()
+               {
+                       using (Bitmap bmp = new Bitmap (40, 40)) {
+                               using (Graphics g = Graphics.FromImage (bmp)) {
+                                       g.DrawImage (bmp, new PointF[] { 
+                                               new PointF (0, 0), new PointF (1, 1), new PointF (2, 2) });
+                               }
+                       }
+               }
+
+               [Test]
+               [ExpectedException (typeof (ArgumentNullException))]
+               public void DrawImage_NullRectangle ()
+               {
+                       using (Bitmap bmp = new Bitmap (40, 40)) {
+                               using (Graphics g = Graphics.FromImage (bmp)) {
+                                       g.DrawImage (null, new Rectangle (0, 0, 0, 0));
+                               }
+                       }
+               }
+
+               [Test]
+               public void DrawImage_ImageRectangle ()
+               {
+                       using (Bitmap bmp = new Bitmap (40, 40)) {
+                               using (Graphics g = Graphics.FromImage (bmp)) {
+                                       // Rectangle is empty when X, Y, Width and Height == 0 
+                                       // (yep X and Y too, RectangleF only checks for Width and Height)
+                                       g.DrawImage (bmp, new Rectangle (0, 0, 0, 0));
+                                       // so this one is half-empty ;-)
+                                       g.DrawImage (bmp, new Rectangle (20, 40, 0, 0));
+                                       // negative width or height isn't empty (for Rectangle)
+                                       g.DrawImage (bmp, new Rectangle (10, 20, -1, 0));
+                                       g.DrawImage (bmp, new Rectangle (20, 10, 0, -1));
+                               }
+                       }
+               }
+
+               [Test]
+               [ExpectedException (typeof (ArgumentNullException))]
+               public void DrawImage_NullPoint ()
+               {
+                       using (Bitmap bmp = new Bitmap (40, 40)) {
+                               using (Graphics g = Graphics.FromImage (bmp)) {
+                                       g.DrawImage (null, new Point (0, 0));
+                               }
+                       }
+               }
+
+               [Test]
+               public void DrawImage_ImagePoint ()
+               {
+                       using (Bitmap bmp = new Bitmap (40, 40)) {
+                               using (Graphics g = Graphics.FromImage (bmp)) {
+                                       g.DrawImage (bmp, new Point (0, 0));
+                               }
+                       }
+               }
+
+               [Test]
+               [ExpectedException (typeof (ArgumentNullException))]
+               public void DrawImage_NullPointArray ()
+               {
+                       using (Bitmap bmp = new Bitmap (40, 40)) {
+                               using (Graphics g = Graphics.FromImage (bmp)) {
+                                       g.DrawImage (null, new Point[0]);
+                               }
+                       }
+               }
+
+               [Test]
+               [ExpectedException (typeof (ArgumentNullException))]
+               public void DrawImage_ImagePointArrayNull ()
+               {
+                       using (Bitmap bmp = new Bitmap (40, 40)) {
+                               using (Graphics g = Graphics.FromImage (bmp)) {
+                                       g.DrawImage (bmp, (Point[]) null);
+                               }
+                       }
+               }
+
+               [Test]
+               [ExpectedException (typeof (ArgumentException))]
+               public void DrawImage_ImagePointArrayEmpty ()
+               {
+                       using (Bitmap bmp = new Bitmap (40, 40)) {
+                               using (Graphics g = Graphics.FromImage (bmp)) {
+                                       g.DrawImage (bmp, new Point[0]);
+                               }
+                       }
+               }
+
+               [Test]
+               public void DrawImage_ImagePointArray ()
+               {
+                       using (Bitmap bmp = new Bitmap (40, 40)) {
+                               using (Graphics g = Graphics.FromImage (bmp)) {
+                                       g.DrawImage (bmp, new Point[] { 
+                                               new Point (0, 0), new Point (1, 1), new Point (2, 2) });
+                               }
+                       }
+               }
+
+               [Test]
+               [ExpectedException (typeof (ArgumentNullException))]
+               public void DrawImage_NullIntInt ()
+               {
+                       using (Bitmap bmp = new Bitmap (40, 40)) {
+                               using (Graphics g = Graphics.FromImage (bmp)) {
+                                       g.DrawImage (null, Int32.MaxValue, Int32.MinValue);
+                               }
+                       }
+               }
+
+               [Test]
+               [ExpectedException (typeof (OverflowException))]
+               public void DrawImage_ImageIntInt_Overflow ()
+               {
+                       using (Bitmap bmp = new Bitmap (40, 40)) {
+                               using (Graphics g = Graphics.FromImage (bmp)) {
+                                       g.DrawImage (bmp, Int32.MaxValue, Int32.MinValue);
+                               }
+                       }
+               }
+
+               [Test]
+               public void DrawImage_ImageIntInt ()
+               {
+                       using (Bitmap bmp = new Bitmap (40, 40)) {
+                               using (Graphics g = Graphics.FromImage (bmp)) {
+                                       g.DrawImage (bmp, -40, -40);
+                               }
+                       }
+               }
+
+               [Test]
+               [ExpectedException (typeof (ArgumentNullException))]
+               public void DrawImage_NullFloat ()
+               {
+                       using (Bitmap bmp = new Bitmap (40, 40)) {
+                               using (Graphics g = Graphics.FromImage (bmp)) {
+                                       g.DrawImage (null, Single.MaxValue, Single.MinValue);
+                               }
+                       }
+               }
+
+               [Test]
+               [ExpectedException (typeof (OverflowException))]
+               public void DrawImage_ImageFloatFloat_Overflow ()
+               {
+                       using (Bitmap bmp = new Bitmap (40, 40)) {
+                               using (Graphics g = Graphics.FromImage (bmp)) {
+                                       g.DrawImage (bmp, Single.MaxValue, Single.MinValue);
+                               }
+                       }
+               }
+
+               [Test]
+               public void DrawImage_ImageFloatFloat ()
+               {
+                       using (Bitmap bmp = new Bitmap (40, 40)) {
+                               using (Graphics g = Graphics.FromImage (bmp)) {
+                                       g.DrawImage (bmp, -40.0f, -40.0f);
+                               }
+                       }
+               }
+
+               [Test]
+               [ExpectedException (typeof (ArgumentNullException))]
+               public void DrawImage_NullRectangleRectangleGraphicsUnit ()
+               {
+                       using (Bitmap bmp = new Bitmap (40, 40)) {
+                               using (Graphics g = Graphics.FromImage (bmp)) {
+                                       g.DrawImage (null, new Rectangle (), new Rectangle (), GraphicsUnit.Display);
+                               }
+                       }
+               }
+
+               private void DrawImage_ImageRectangleRectangleGraphicsUnit (GraphicsUnit unit)
+               {
+                       using (Bitmap bmp = new Bitmap (40, 40)) {
+                               using (Graphics g = Graphics.FromImage (bmp)) {
+                                       Rectangle r = new Rectangle (0, 0, 40, 40);
+                                       g.DrawImage (bmp, r, r, unit);
+                               }
+                       }
+               }
+
+               [Test]
+               [ExpectedException (typeof (ArgumentException))]
+               public void DrawImage_ImageRectangleRectangleGraphicsUnit_Display ()
+               {
+                       DrawImage_ImageRectangleRectangleGraphicsUnit (GraphicsUnit.Display);
+               }
+
+               [Test]
+               [ExpectedException (typeof (NotImplementedException))]
+               public void DrawImage_ImageRectangleRectangleGraphicsUnit_Document ()
+               {
+                       DrawImage_ImageRectangleRectangleGraphicsUnit (GraphicsUnit.Document);
+               }
+
+               [Test]
+               [ExpectedException (typeof (NotImplementedException))]
+               public void DrawImage_ImageRectangleRectangleGraphicsUnit_Inch ()
+               {
+                       DrawImage_ImageRectangleRectangleGraphicsUnit (GraphicsUnit.Inch);
+               }
+
+               [Test]
+               [ExpectedException (typeof (NotImplementedException))]
+               public void DrawImage_ImageRectangleRectangleGraphicsUnit_Millimeter ()
+               {
+                       DrawImage_ImageRectangleRectangleGraphicsUnit (GraphicsUnit.Millimeter);
+               }
+
+               [Test]
+               public void DrawImage_ImageRectangleRectangleGraphicsUnit_Pixel ()
+               {
+                       // this unit works
+                       DrawImage_ImageRectangleRectangleGraphicsUnit (GraphicsUnit.Pixel);
+               }
+
+               [Test]
+               [ExpectedException (typeof (NotImplementedException))]
+               public void DrawImage_ImageRectangleRectangleGraphicsUnit_Point ()
+               {
+                       DrawImage_ImageRectangleRectangleGraphicsUnit (GraphicsUnit.Point);
+               }
+
+               [Test]
+               [ExpectedException (typeof (ArgumentException))]
+               public void DrawImage_ImageRectangleRectangleGraphicsUnit_World ()
+               {
+                       DrawImage_ImageRectangleRectangleGraphicsUnit (GraphicsUnit.World);
+               }
+
+               [Test]
+               [ExpectedException (typeof (ArgumentNullException))]
+               public void DrawImageUnscaled_NullPoint ()
+               {
+                       using (Bitmap bmp = new Bitmap (40, 40)) {
+                               using (Graphics g = Graphics.FromImage (bmp)) {
+                                       g.DrawImageUnscaled (null, new Point (0, 0));
+                               }
+                       }
+               }
+
+               [Test]
+               public void DrawImageUnscaled_ImagePoint ()
+               {
+                       using (Bitmap bmp = new Bitmap (40, 40)) {
+                               using (Graphics g = Graphics.FromImage (bmp)) {
+                                       g.DrawImageUnscaled (bmp, new Point (0, 0));
+                               }
+                       }
+               }
+
+               [Test]
+               [ExpectedException (typeof (ArgumentNullException))]
+               public void DrawImageUnscaled_NullRectangle ()
+               {
+                       using (Bitmap bmp = new Bitmap (40, 40)) {
+                               using (Graphics g = Graphics.FromImage (bmp)) {
+                                       g.DrawImageUnscaled (null, new Rectangle (0, 0, -1, -1));
+                               }
+                       }
+               }
+
+               [Test]
+               public void DrawImageUnscaled_ImageRectangle ()
+               {
+                       using (Bitmap bmp = new Bitmap (40, 40)) {
+                               using (Graphics g = Graphics.FromImage (bmp)) {
+                                       g.DrawImageUnscaled (bmp, new Rectangle (0, 0, -1, -1));
+                               }
+                       }
+               }
+
+               [Test]
+               [ExpectedException (typeof (ArgumentNullException))]
+               public void DrawImageUnscaled_NullIntInt ()
+               {
+                       using (Bitmap bmp = new Bitmap (40, 40)) {
+                               using (Graphics g = Graphics.FromImage (bmp)) {
+                                       g.DrawImageUnscaled (null, 0, 0);
+                               }
+                       }
+               }
+
+               [Test]
+               public void DrawImageUnscaled_ImageIntInt ()
+               {
+                       using (Bitmap bmp = new Bitmap (40, 40)) {
+                               using (Graphics g = Graphics.FromImage (bmp)) {
+                                       g.DrawImageUnscaled (bmp, 0, 0);
+                               }
+                       }
+               }
+
+               [Test]
+               [ExpectedException (typeof (ArgumentNullException))]
+               public void DrawImageUnscaled_NullIntIntIntInt ()
+               {
+                       using (Bitmap bmp = new Bitmap (40, 40)) {
+                               using (Graphics g = Graphics.FromImage (bmp)) {
+                                       g.DrawImageUnscaled (null, 0, 0, -1, -1);
+                               }
+                       }
+               }
+
+               [Test]
+               public void DrawImageUnscaled_ImageIntIntIntInt ()
+               {
+                       using (Bitmap bmp = new Bitmap (40, 40)) {
+                               using (Graphics g = Graphics.FromImage (bmp)) {
+                                       g.DrawImageUnscaled (bmp, 0, 0, -1, -1);
+                               }
+                       }
+               }
+#if NET_2_0
+               [Test]
+               [ExpectedException (typeof (ArgumentNullException))]
+               public void DrawImageUnscaledAndClipped_Null ()
+               {
+                       using (Bitmap bmp = new Bitmap (40, 40)) {
+                               using (Graphics g = Graphics.FromImage (bmp)) {
+                                       g.DrawImageUnscaledAndClipped (null, new Rectangle (0, 0, 0, 0));
+                               }
+                       }
+               }
+
+               [Test]
+               public void DrawImageUnscaledAndClipped ()
+               {
+                       using (Bitmap bmp = new Bitmap (40, 40)) {
+                               using (Graphics g = Graphics.FromImage (bmp)) {
+                                       // Rectangle is empty when X, Y, Width and Height == 0 
+                                       // (yep X and Y too, RectangleF only checks for Width and Height)
+                                       g.DrawImageUnscaledAndClipped (bmp, new Rectangle (0, 0, 0, 0));
+                                       // so this one is half-empty ;-)
+                                       g.DrawImageUnscaledAndClipped (bmp, new Rectangle (20, 40, 0, 0));
+                                       // negative width or height isn't empty (for Rectangle)
+                                       g.DrawImageUnscaledAndClipped (bmp, new Rectangle (10, 20, -1, 0));
+                                       g.DrawImageUnscaledAndClipped (bmp, new Rectangle (20, 10, 0, -1));
+                                       // smaller
+                                       g.DrawImageUnscaledAndClipped (bmp, new Rectangle (0, 0, 10, 20));
+                                       g.DrawImageUnscaledAndClipped (bmp, new Rectangle (0, 0, 40, 10));
+                                       g.DrawImageUnscaledAndClipped (bmp, new Rectangle (0, 0, 80, 20));
+                               }
+                       }
+               }
+#endif
        }
 }
index 41796a8857916048da8c2a0ca3883b69ada0da8d..efeb09bdc97ead1ca6ce85534156cf3ca6da4e65 100644 (file)
@@ -82,6 +82,7 @@ namespace MonoTests.System.Drawing
                        Assert.IsFalse (rect_0.IsEmpty, "0");
                        Assert.IsTrue (rect_2.IsEmpty, "2");
                        Assert.IsFalse (rect_3.IsEmpty, "3");
+                       Assert.IsFalse (new Rectangle (0, 0, -1, -1).IsEmpty, "negative w/h");
                }
 
                [Test]
@@ -202,32 +203,51 @@ namespace MonoTests.System.Drawing
                [Test]
                public void Union ()
                {
-                       Assert.AreEqual (RectangleF.FromLTRB (5, 5, 50, 50), RectangleF.Union (rect_0, rect_1));
+                       Assert.AreEqual (Rectangle.FromLTRB (5, 5, 50, 50), Rectangle.Union (rect_0, rect_1));
                }
 
                [Test]
                public void Operator_Equal ()
                {
-                       RectangleF r0 = new RectangleF (1, 2, 3, 4);
-                       RectangleF r1 = r0;
+                       Rectangle r0 = new Rectangle (1, 2, 3, 4);
+                       Rectangle r1 = r0;
                        Assert.IsTrue (r0 == r1, "self");
-                       Assert.IsFalse (r0 == new RectangleF (0, 2, 3, 4), "X");
-                       Assert.IsFalse (r0 == new RectangleF (1, 0, 3, 4), "Y");
-                       Assert.IsFalse (r0 == new RectangleF (1, 2, 0, 4), "Width");
-                       Assert.IsFalse (r0 == new RectangleF (1, 2, 3, 0), "Height");
+                       Assert.IsFalse (r0 == new Rectangle (0, 2, 3, 4), "X");
+                       Assert.IsFalse (r0 == new Rectangle (1, 0, 3, 4), "Y");
+                       Assert.IsFalse (r0 == new Rectangle (1, 2, 0, 4), "Width");
+                       Assert.IsFalse (r0 == new Rectangle (1, 2, 3, 0), "Height");
                }
 
                [Test]
                public void Operator_NotEqual ()
                {
-                       RectangleF r0 = new RectangleF (1, 2, 3, 4);
-                       RectangleF r1 = r0;
+                       Rectangle r0 = new Rectangle (1, 2, 3, 4);
+                       Rectangle r1 = r0;
                        Assert.IsFalse (r0 != r1, "self");
-                       Assert.IsTrue (r0 != new RectangleF (0, 2, 3, 4), "X");
-                       Assert.IsTrue (r0 != new RectangleF (1, 0, 3, 4), "Y");
-                       Assert.IsTrue (r0 != new RectangleF (1, 2, 0, 4), "Width");
-                       Assert.IsTrue (r0 != new RectangleF (1, 2, 3, 0), "Height");
+                       Assert.IsTrue (r0 != new Rectangle (0, 2, 3, 4), "X");
+                       Assert.IsTrue (r0 != new Rectangle (1, 0, 3, 4), "Y");
+                       Assert.IsTrue (r0 != new Rectangle (1, 2, 0, 4), "Width");
+                       Assert.IsTrue (r0 != new Rectangle (1, 2, 3, 0), "Height");
+               }
+
+               [Test]
+               public void NegativeWidth ()
+               {
+                       Rectangle r = new Rectangle (0, 0, -1, 10);
+                       Assert.AreEqual (0, r.X, "X");
+                       Assert.AreEqual (0, r.Y, "Y");
+                       Assert.AreEqual (-1, r.Width, "Width");
+                       Assert.AreEqual (10, r.Height, "Height");
+               }
+
+               [Test]
+               public void NegativeHeight ()
+               {
+                       Rectangle r = new Rectangle (10, 10, 10, -1);
+                       Assert.AreEqual (10, r.X, "X");
+                       Assert.AreEqual (10, r.Y, "Y");
+                       Assert.AreEqual (10, r.Width, "Width");
+                       Assert.AreEqual (-1, r.Height, "Height");
                }
        }
 }
-
index 2bdcc74ade07532151781093afedb5c45a45b94b..5d9ccf40872d24393431d552f60cc0ea8887fc2f 100644 (file)
@@ -84,6 +84,7 @@ namespace MonoTests.System.Drawing
                        Assert.IsTrue (rect_2.IsEmpty, "2");
                        Assert.IsTrue (rect_3.IsEmpty, "3");
                        Assert.IsTrue (rect_6.IsEmpty, "6");
+                       Assert.IsTrue (new RectangleF (0, 0, -1, -1).IsEmpty, "negative w/h");
                }
 
                [Test]
@@ -216,6 +217,25 @@ namespace MonoTests.System.Drawing
                        Assert.IsTrue (r0 != new RectangleF (1, 2, 0, 4), "Width");
                        Assert.IsTrue (r0 != new RectangleF (1, 2, 3, 0), "Height");
                }
+
+               [Test]
+               public void NegativeWidth ()
+               {
+                       RectangleF r = new RectangleF (0, 0, -1, 10);
+                       Assert.AreEqual (0, r.X, "X");
+                       Assert.AreEqual (0, r.Y, "Y");
+                       Assert.AreEqual (-1, r.Width, "Width");
+                       Assert.AreEqual (10, r.Height, "Height");
+               }
+
+               [Test]
+               public void NegativeHeight ()
+               {
+                       RectangleF r = new RectangleF (10, 10, 10, -1);
+                       Assert.AreEqual (10, r.X, "X");
+                       Assert.AreEqual (10, r.Y, "Y");
+                       Assert.AreEqual (10, r.Width, "Width");
+                       Assert.AreEqual (-1, r.Height, "Height");
+               }
        }
 }
-