// 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 ()
{
}
}
}
+
+ [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
}
}
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]
[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");
}
}
}
-