Remove invalid tests for image palettes in GdiPlusTest (#5671)
[mono.git] / mcs / class / System.Drawing / Test / System.Drawing / GDIPlusTest.cs
index 2a7228c394bc6491900f5fd8a28322ae314c1b96..4e6c25725298c8f808a2ac4720fcbd63a8c4dece 100644 (file)
@@ -4,7 +4,7 @@
 // Authors:
 //     Sebastien Pouliot  <sebastien@ximian.com>
 //
-// Copyright (C) 2006 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2006-2007 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
@@ -31,6 +31,7 @@ using System.Drawing;
 using System.Drawing.Drawing2D;
 using System.Drawing.Imaging;
 using System.Drawing.Text;
+using System.IO;
 using System.Runtime.InteropServices;
 using NUnit.Framework;
 
@@ -59,6 +60,25 @@ namespace MonoTests.System.Drawing {
                        public string lfFaceName = null;
                }
 
+               // CustomLineCap
+
+               [Test]
+               public void CreateCustomLineCap ()
+               {
+                       IntPtr cap;
+
+                       IntPtr path;
+                       Assert.AreEqual (Status.Ok, GDIPlus.GdipCreatePath (FillMode.Alternate, out path), "GdipCreatePath");
+
+                       // test invalid conditions for #81829
+                       Assert.AreEqual (Status.Ok, GDIPlus.GdipCreateCustomLineCap (IntPtr.Zero, path, LineCap.Flat, 1.0f, out cap), "GdipCreateCustomLineCap-FillPath-Null");
+                       Assert.AreEqual (Status.Ok, GDIPlus.GdipDeleteCustomLineCap (cap), "GdipDeleteCustomLineCap-1");
+                       Assert.AreEqual (Status.Ok, GDIPlus.GdipCreateCustomLineCap (path, IntPtr.Zero, LineCap.Flat, 1.0f, out cap), "GdipCreateCustomLineCap-StrokePath-Null");
+                       Assert.AreEqual (Status.Ok, GDIPlus.GdipDeleteCustomLineCap (cap), "GdipDeleteCustomLineCap-2");
+
+                       Assert.AreEqual (Status.Ok, GDIPlus.GdipDeletePath (path), "GdipDeletePath");
+               }
+
                // FontFamily
                [Test]
                public void DeleteFontFamily ()
@@ -86,6 +106,23 @@ namespace MonoTests.System.Drawing {
                        Assert.AreEqual (Status.Ok, GDIPlus.GdipDeleteFontFamily (font_family), "second");
                }
 
+               [Test]
+               public void CloneFontFamily ()
+               {
+                       IntPtr font_family = IntPtr.Zero;
+                       Assert.AreEqual (Status.InvalidParameter, GDIPlus.GdipCloneFontFamily (IntPtr.Zero, out font_family), "GdipCloneFontFamily(null)");
+
+                       GDIPlus.GdipCreateFontFamilyFromName ("Arial", IntPtr.Zero, out font_family);
+                       if (font_family != IntPtr.Zero) {
+                               IntPtr clone;
+                               Assert.AreEqual (Status.Ok, GDIPlus.GdipCloneFontFamily (font_family, out clone), "GdipCloneFontFamily(arial)");
+                               Assert.IsTrue (clone != IntPtr.Zero, "clone");
+                               Assert.AreEqual (Status.Ok, GDIPlus.GdipDeleteFontFamily (font_family), "GdipDeleteFontFamily(arial)");
+                               Assert.AreEqual (Status.Ok, GDIPlus.GdipDeleteFontFamily (clone), "GdipDeleteFontFamily(clone)");
+                       } else
+                               Assert.Ignore ("Arial isn't available on this platform");
+               }
+
                // Font
                [Test]
                public void CreateFont ()
@@ -143,6 +180,41 @@ namespace MonoTests.System.Drawing {
                        Assert.AreEqual (Status.InvalidParameter, GDIPlus.GdipCreateBitmapFromScan0 (-1, 10, 10, PixelFormat.Format32bppArgb, IntPtr.Zero, out bmp), "negative width");
                }
 
+               [Test]
+               public void Format1bppIndexed_GetSetPixel ()
+               {
+                       IntPtr bmp;
+                       Assert.AreEqual (Status.Ok, GDIPlus.GdipCreateBitmapFromScan0 (10, 10, 0, PixelFormat.Format1bppIndexed, IntPtr.Zero, out bmp), "GdipCreateBitmapFromScan0");
+                       Assert.IsTrue (bmp != IntPtr.Zero, "bmp");
+                       try {
+                               int argb;
+                               Assert.AreEqual (Status.Ok, GDIPlus.GdipBitmapGetPixel (bmp, 0, 0, out argb), "GdipBitmapGetPixel");
+                               Assert.AreEqual (-16777216, argb, "argb");
+                               Assert.AreEqual (Status.InvalidParameter, GDIPlus.GdipBitmapSetPixel (bmp, 0, 0, argb), "GdipBitmapSetPixel");
+                       }
+                       finally {
+                               Assert.AreEqual (Status.Ok, GDIPlus.GdipDisposeImage (bmp), "GdipDisposeImage");
+                       }
+               }
+
+               [Test]
+               [Category ("NotWorking")] // libgdiplus doesn't support this format
+               public void Format16bppGrayScale_GetSetPixel ()
+               {
+                       IntPtr bmp;
+                       Assert.AreEqual (Status.Ok, GDIPlus.GdipCreateBitmapFromScan0 (10, 10, 0, PixelFormat.Format16bppGrayScale, IntPtr.Zero, out bmp), "GdipCreateBitmapFromScan0");
+                       Assert.IsTrue (bmp != IntPtr.Zero, "bmp");
+                       try {
+                               int argb = 0;
+                               // and MS GDI+ can get or set pixels on it
+                               Assert.AreEqual (Status.InvalidParameter, GDIPlus.GdipBitmapGetPixel (bmp, 0, 0, out argb), "GdipBitmapGetPixel");
+                               Assert.AreEqual (Status.InvalidParameter, GDIPlus.GdipBitmapSetPixel (bmp, 0, 0, argb), "GdipBitmapSetPixel");
+                       }
+                       finally {
+                               Assert.AreEqual (Status.Ok, GDIPlus.GdipDisposeImage (bmp), "GdipDisposeImage");
+                       }
+               }
+
                [Test]
                public void Unlock ()
                {
@@ -160,6 +232,8 @@ namespace MonoTests.System.Drawing {
 
                        Rectangle rect = new Rectangle (2, 2, 5, 5);
                        Assert.AreEqual (Status.Ok, GDIPlus.GdipBitmapLockBits (bmp, ref rect, ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb, bd), "locked");
+                       Assert.AreEqual (Status.Win32Error, GDIPlus.GdipBitmapLockBits (bmp, ref rect, ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb, bd), "second lock");
+
                        Assert.AreEqual (rect.Width, bd.Width, "Width");
                        Assert.AreEqual (rect.Height, bd.Height, "Height");
                        Assert.AreEqual (PixelFormat.Format24bppRgb, bd.PixelFormat, "PixelFormat");
@@ -180,21 +254,138 @@ namespace MonoTests.System.Drawing {
 
                // Graphics
                [Test]
-               public void Graphics ()
+               public void GdipGetImageGraphicsContext_Null ()
                {
                        IntPtr graphics;
                        Assert.AreEqual (Status.InvalidParameter, GDIPlus.GdipGetImageGraphicsContext (IntPtr.Zero, out graphics), "GdipGetImageGraphicsContext");
+               }
 
+               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 GdipCreateFromHDC_Null ()
+               {
+                       IntPtr graphics;
+                       Assert.AreEqual (Status.OutOfMemory, GDIPlus.GdipCreateFromHDC (IntPtr.Zero, out graphics), "GdipCreateFromHDC(null)");
+               }
+
+               [Test]
+               public void DrawRectangles ()
+               {
+                       IntPtr image;
+                       GDIPlus.GdipCreateBitmapFromScan0 (10, 10, 0, PixelFormat.Format32bppArgb, IntPtr.Zero, out image);
+                       Assert.IsTrue (image != IntPtr.Zero, "image");
+
+                       IntPtr graphics;
                        Assert.AreEqual (Status.Ok, GDIPlus.GdipGetImageGraphicsContext (image, out graphics), "GdipGetImageGraphicsContext");
                        Assert.IsTrue (graphics != IntPtr.Zero, "graphics");
 
-                       Assert.AreEqual (Status.Ok, GDIPlus.GdipDeleteGraphics (graphics), "GdipDeleteGraphics");
-                       Assert.AreEqual (Status.InvalidParameter, GDIPlus.GdipDeleteGraphics (IntPtr.Zero), "GdipDeleteGraphics-null");
+                       Rectangle[] r = new Rectangle[1] { new Rectangle (1, 2, -2, -1) };
+                       Assert.AreEqual (Status.InvalidParameter, GDIPlus.GdipDrawRectanglesI (graphics, IntPtr.Zero, r, 1), "GdipDrawRectanglesI-PenNull");
+
+                       RectangleF[] rf = new RectangleF[2] { new RectangleF (1, 2, -2, -1), new RectangleF (0, 0, 10, 10) };
+                       Assert.AreEqual (Status.InvalidParameter, GDIPlus.GdipDrawRectangles (graphics, IntPtr.Zero, rf, 2), "GdipDrawRectanglesI-PenNull");
+
+                       IntPtr pen;
+                       Assert.AreEqual (Status.Ok, GDIPlus.GdipCreatePen1 (0, 0f, GraphicsUnit.World, out pen), "GdipCreatePen1");
+                       Assert.IsTrue (pen != IntPtr.Zero, "pen");
 
+                       Assert.AreEqual (Status.InvalidParameter, GDIPlus.GdipDrawRectanglesI (IntPtr.Zero, pen, r, 1), "GdipDrawRectanglesI-GraphicsNull");
+                       Assert.AreEqual (Status.InvalidParameter, GDIPlus.GdipDrawRectangles (IntPtr.Zero, pen, rf, 2), "GdipDrawRectangles-GraphicsNull");
+
+                       Assert.AreEqual (Status.InvalidParameter, GDIPlus.GdipDrawRectanglesI (graphics, pen, null, 1), "GdipDrawRectanglesI-RectanglesNull");
+                       Assert.AreEqual (Status.InvalidParameter, GDIPlus.GdipDrawRectangles (graphics, pen, null, 1), "GdipDrawRectangles-RectanglesNull");
+
+                       Assert.AreEqual (Status.InvalidParameter, GDIPlus.GdipDrawRectanglesI (graphics, pen, new Rectangle[0], 0), "GdipDrawRectanglesI-RectanglesEmpty");
+                       Assert.AreEqual (Status.InvalidParameter, GDIPlus.GdipDrawRectangles (graphics, pen, new RectangleF[0], 0), "GdipDrawRectangles-RectanglesEmpty");
+
+                       Assert.AreEqual (Status.InvalidParameter, GDIPlus.GdipDrawRectanglesI (graphics, pen, r, -1), "GdipDrawRectanglesI-RectanglesNegative");
+                       Assert.AreEqual (Status.InvalidParameter, GDIPlus.GdipDrawRectangles (graphics, pen, rf, -1), "GdipDrawRectangles-RectanglesNegative");
+
+                       Assert.AreEqual (Status.Ok, GDIPlus.GdipDrawRectanglesI (graphics, pen, r, 1), "GdipDrawRectanglesI-Rectangles1");
+                       Assert.AreEqual (Status.Ok, GDIPlus.GdipDrawRectangles (graphics, pen, rf, 2), "GdipDrawRectangles-Rectangles2");
+
+                       Assert.AreEqual (Status.Ok, GDIPlus.GdipDeletePen (pen), "GdipDeletePen");
+
+                       Assert.AreEqual (Status.Ok, GDIPlus.GdipDeleteGraphics (graphics), "GdipDeleteGraphics");
                        Assert.AreEqual (Status.Ok, GDIPlus.GdipDisposeImage (image), "GdipDisposeImage");
                }
 
@@ -289,7 +480,7 @@ namespace MonoTests.System.Drawing {
                public void Widen ()
                {
                        IntPtr pen;
-                       Assert.AreEqual (Status.Ok, GDIPlus.GdipCreatePen1 (0, 0f, Unit.UnitWorld, out pen), "GdipCreatePen1");
+                       Assert.AreEqual (Status.Ok, GDIPlus.GdipCreatePen1 (0, 0f, GraphicsUnit.World, out pen), "GdipCreatePen1");
 
                        IntPtr path;
                        Assert.AreEqual (Status.Ok, GDIPlus.GdipCreatePath (FillMode.Alternate, out path), "GdipCreatePath");
@@ -641,6 +832,101 @@ namespace MonoTests.System.Drawing {
                        }
                }
 
+               [Test]
+               public void Icon ()
+               {
+                       string filename = TestBitmap.getInFile ("bitmaps/64x64x256.ico");
+                       IntPtr bitmap;
+                       Assert.AreEqual (Status.Ok, GDIPlus.GdipCreateBitmapFromFile (filename, out bitmap), "GdipCreateBitmapFromFile");
+                       try {
+                               int size;
+                               Assert.AreEqual (Status.Ok, GDIPlus.GdipGetImagePaletteSize (bitmap, out size), "GdipGetImagePaletteSize");
+                               Assert.AreEqual (1032, size, "size");
+
+                               IntPtr clone;
+                               Assert.AreEqual (Status.Ok, GDIPlus.GdipCloneImage (bitmap, out clone), "GdipCloneImage");
+                               try {
+                                       Assert.AreEqual (Status.Ok, GDIPlus.GdipGetImagePaletteSize (clone, out size), "GdipGetImagePaletteSize/Clone");
+                                       Assert.AreEqual (1032, size, "size/clone");
+                               }
+                               finally {
+                                       GDIPlus.GdipDisposeImage (clone);
+                               }
+
+                               IntPtr palette = Marshal.AllocHGlobal (size);
+                               try {
+
+                                       Assert.AreEqual (Status.InvalidParameter, GDIPlus.GdipGetImagePalette (IntPtr.Zero, palette, size), "GdipGetImagePalette(null,palette,size)");
+                                       Assert.AreEqual (Status.InvalidParameter, GDIPlus.GdipGetImagePalette (bitmap, IntPtr.Zero, size), "GdipGetImagePalette(bitmap,null,size)");
+                                       Assert.AreEqual (Status.InvalidParameter, GDIPlus.GdipGetImagePalette (bitmap, palette, 0), "GdipGetImagePalette(bitmap,palette,0)");
+                                       Assert.AreEqual (Status.Ok, GDIPlus.GdipGetImagePalette (bitmap, palette, size), "GdipGetImagePalette");
+
+                                       Assert.AreEqual (Status.InvalidParameter, GDIPlus.GdipSetImagePalette (IntPtr.Zero, palette), "GdipSetImagePalette(null,palette)");
+                                       Assert.AreEqual (Status.InvalidParameter, GDIPlus.GdipSetImagePalette (bitmap, IntPtr.Zero), "GdipSetImagePalette(bitmap,null)");
+                                       Assert.AreEqual (Status.Ok, GDIPlus.GdipSetImagePalette (bitmap, palette), "GdipSetImagePalette");
+                               }
+                               finally {
+                                       Marshal.FreeHGlobal (palette);
+                               }
+                       }
+                       finally {
+                               GDIPlus.GdipDisposeImage (bitmap);
+                       }
+               }
+
+               [Test]
+               public void FromFile_IndexedBitmap ()
+               {
+                       // despite it's name it's a 4bpp indexed bitmap
+                       string filename = TestBitmap.getInFile ("bitmaps/almogaver1bit.bmp");
+                       IntPtr graphics;
+
+                       IntPtr image;
+                       Assert.AreEqual (Status.Ok, GDIPlus.GdipLoadImageFromFile (filename, out image), "GdipLoadImageFromFile");
+                       try {
+                               Assert.AreEqual (Status.OutOfMemory, GDIPlus.GdipGetImageGraphicsContext (image, out graphics), "GdipGetImageGraphicsContext/image");
+                               Assert.AreEqual (IntPtr.Zero, graphics, "image/graphics");
+                       }
+                       finally {
+                               GDIPlus.GdipDisposeImage (image);
+                       }
+
+                       IntPtr bitmap;
+                       Assert.AreEqual (Status.Ok, GDIPlus.GdipCreateBitmapFromFile (filename, out bitmap), "GdipCreateBitmapFromFile");
+                       try {
+                               Assert.AreEqual (Status.OutOfMemory, GDIPlus.GdipGetImageGraphicsContext (bitmap, out graphics), "GdipGetImageGraphicsContext/bitmap");
+                               Assert.AreEqual (IntPtr.Zero, graphics, "bitmap/graphics");
+                       }
+                       finally {
+                               GDIPlus.GdipDisposeImage (bitmap);
+                       }
+               }
+
+               [Test]
+               public void GdipLoadImageFromFile_FileNotFound ()
+               {
+                       string filename = "filenotfound";
+
+                       IntPtr image;
+                       Assert.AreEqual (Status.OutOfMemory, GDIPlus.GdipLoadImageFromFile (filename, out image), "GdipLoadImageFromFile");
+                       Assert.AreEqual (IntPtr.Zero, image, "image handle");
+
+                       // this doesn't throw a OutOfMemoryException
+                       Assert.Throws<FileNotFoundException> (() => Image.FromFile (filename));
+               }
+
+               [Test]
+               public void GdipCreateBitmapFromFile_FileNotFound ()
+               {
+                       string filename = "filenotfound";
+
+                       IntPtr bitmap;
+                       Assert.AreEqual (Status.InvalidParameter, GDIPlus.GdipCreateBitmapFromFile (filename, out bitmap), "GdipCreateBitmapFromFile");
+                       Assert.AreEqual (IntPtr.Zero, bitmap, "bitmap handle");
+
+                       Assert.Throws<ArgumentException> (() => new Bitmap (filename));
+               }
+
                [Test]
                public void Encoder ()
                {
@@ -783,7 +1069,7 @@ namespace MonoTests.System.Drawing {
                public void CreatePen ()
                {
                        IntPtr pen;
-                       Assert.AreEqual (Status.Ok, GDIPlus.GdipCreatePen1 (0, 0f, Unit.UnitWorld, out pen), "GdipCreatePen1");
+                       Assert.AreEqual (Status.Ok, GDIPlus.GdipCreatePen1 (0, 0f, GraphicsUnit.World, out pen), "GdipCreatePen1");
                        Assert.IsTrue (pen != IntPtr.Zero, "pen");
 
                        DashStyle ds;
@@ -808,6 +1094,47 @@ namespace MonoTests.System.Drawing {
                        Assert.AreEqual (Status.InvalidParameter, GDIPlus.GdipDeletePen (IntPtr.Zero), "GdipDeletePen-null");
                }
 
+               [Test]
+               public void PenColor_81266 ()
+               {
+                       IntPtr pen;
+                       Assert.AreEqual (Status.Ok, GDIPlus.GdipCreatePen1 (0x7f0000ff, 1f, GraphicsUnit.Pixel, out pen), "GdipCreatePen1");
+                       try {
+                               int color = 0;
+                               IntPtr brush;
+                               Assert.AreEqual (Status.InvalidParameter, GDIPlus.GdipGetPenBrushFill (IntPtr.Zero, out brush), "GdipGetPenBrushFill-null");
+                               Assert.AreEqual (Status.Ok, GDIPlus.GdipGetPenBrushFill (pen, out brush), "GdipGetPenBrushFill");
+                               try {
+                                       Assert.AreEqual (Status.InvalidParameter, GDIPlus.GdipGetSolidFillColor (IntPtr.Zero, out color), "GdipGetSolidFillColor-null");
+                                       Assert.AreEqual (Status.Ok, GDIPlus.GdipGetSolidFillColor (brush, out color), "GdipGetSolidFillColor-0");
+                                       Assert.AreEqual (0x7f0000ff, color, "color-0");
+
+                                       Assert.AreEqual (Status.InvalidParameter, GDIPlus.GdipSetPenColor (IntPtr.Zero, 0x7fff0000), "GdipSetPenColor-null");
+                                       Assert.AreEqual (Status.Ok, GDIPlus.GdipSetPenColor (pen, 0x7fff0000), "GdipSetPenColor");
+
+                                       Assert.AreEqual (Status.Ok, GDIPlus.GdipGetSolidFillColor (brush, out color), "GdipGetSolidFillColor-1");
+                                       // previous brush color didn't change
+                                       Assert.AreEqual (0x7f0000ff, color, "color-1");
+                               }
+                               finally {
+                                       Assert.AreEqual (Status.Ok, GDIPlus.GdipDeleteBrush (brush), "GdipDeleteBrush");
+                               }
+
+                               Assert.AreEqual (Status.Ok, GDIPlus.GdipGetPenBrushFill (pen, out brush), "GdipGetPenBrushFill-2");
+                               try {
+                                       Assert.AreEqual (Status.Ok, GDIPlus.GdipGetSolidFillColor (brush, out color), "GdipGetSolidFillColor-2");
+                                       // new brush color is updated
+                                       Assert.AreEqual (0x7fff0000, color, "color-2");
+                               }
+                               finally {
+                                       Assert.AreEqual (Status.Ok, GDIPlus.GdipDeleteBrush (brush), "GdipDeleteBrush-2");
+                               }
+                       }
+                       finally {
+                               Assert.AreEqual (Status.Ok, GDIPlus.GdipDeletePen (pen), "GdipDeletePen");
+                       }
+               }
+
                // Region
                [Test]
                public void CreateRegionRgnData ()
@@ -829,7 +1156,7 @@ namespace MonoTests.System.Drawing {
                                                           out image);
 
                        GDIPlus.GdipGetImageGraphicsContext (image, out graphics);
-                       GDIPlus.GdipCreatePen1 (0, 0f, Unit.UnitWorld, out pen);
+                       GDIPlus.GdipCreatePen1 (0, 0f, GraphicsUnit.World, out pen);
 
                        // DrawCurve
 
@@ -845,8 +1172,8 @@ namespace MonoTests.System.Drawing {
                                         "DrawCurve with 1 pt");
                        Assert.AreEqual (Status.Ok,
                                         GDIPlus.GdipDrawCurveI (graphics, pen,
-                                                                new Point [] { new Point (1, 1),
-                                                                               new Point (2, 2) }, 2),
+                                                                new Point [] { new Point (1, 1),
+                                                                               new Point (2, 2) }, 2),
                                         "DrawCurve with 2 pts");
 
                        // DrawClosedCurve
@@ -856,12 +1183,12 @@ namespace MonoTests.System.Drawing {
                                         "DrawClosedCurve with no pts");
                        Assert.AreEqual (Status.InvalidParameter,
                                         GDIPlus.GdipDrawClosedCurveI (graphics, pen,
-                                                                      new Point [] { new Point (1, 1) }, 1),
+                                                                      new Point [] { new Point (1, 1) }, 1),
                                         "DrawClosedCurve with 1 pt");
                        Assert.AreEqual (Status.InvalidParameter,
                                         GDIPlus.GdipDrawClosedCurveI (graphics, pen,
-                                                                      new Point [] { new Point (1, 1),
-                                                                                     new Point (2, 2) }, 2),
+                                                                      new Point [] { new Point (1, 1),
+                                                                                     new Point (2, 2) }, 2),
                                         "DrawClosedCurve with 2 pt2");
 
                        // DrawPolygon
@@ -871,7 +1198,7 @@ namespace MonoTests.System.Drawing {
                                         "DrawPolygon with no pts");
                        Assert.AreEqual (Status.InvalidParameter,
                                         GDIPlus.GdipDrawPolygonI (graphics, pen,
-                                                                  new Point [] { new Point (1, 1) }, 1),
+                                                                  new Point [] { new Point (1, 1) }, 1),
                                         "DrawPolygon with only one pt");
 
                        GDIPlus.GdipDeletePen (pen);                    
@@ -887,12 +1214,12 @@ namespace MonoTests.System.Drawing {
                                         "FillClosedCurve with no pts");
                        Assert.AreEqual (Status.Ok,
                                         GDIPlus.GdipFillClosedCurveI (graphics, brush, 
-                                                                      new Point [] { new Point (1, 1) }, 1),
+                                                                                               new Point [] { new Point (1, 1) }, 1),
                                         "FillClosedCurve with 1 pt");
                        Assert.AreEqual (Status.Ok,
                                         GDIPlus.GdipFillClosedCurveI (graphics, brush,
-                                                                      new Point [] { new Point (1, 1),
-                                                                                     new Point (2, 2) }, 2),
+                                                                      new Point [] { new Point (1, 1),
+                                                                                     new Point (2, 2) }, 2),
                                         "FillClosedCurve with 2 pts");
                        
                        GDIPlus.GdipDeleteBrush (brush);
@@ -1103,5 +1430,334 @@ namespace MonoTests.System.Drawing {
                        Assert.AreEqual (Status.Ok, GDIPlus.GdipDeleteBrush (brush), "GdipDeleteBrush");
                        Assert.AreEqual (Status.Ok, GDIPlus.GdipDisposeImage (image), "GdipDisposeImage");
                }
+
+               // Get the input directory depending on the runtime
+               internal string getInFile (string file)
+               {
+                       string sRslt = Path.GetFullPath ("../System.Drawing/" + file);
+
+                       if (!File.Exists (sRslt))
+                               sRslt = "Test/System.Drawing/" + file;
+
+                       return sRslt;
+               }
+
+               private void CheckMetafileHeader (MetafileHeader header)
+               {
+                       MetafileHeader mh1 = new Metafile (getInFile ("bitmaps/telescope_01.wmf")).GetMetafileHeader ();
+                       // compare MetafileHeader
+                       Assert.AreEqual (mh1.Bounds.X, header.Bounds.X, "Bounds.X");
+                       Assert.AreEqual (mh1.Bounds.Y, header.Bounds.Y, "Bounds.Y");
+                       Assert.AreEqual (mh1.Bounds.Width, header.Bounds.Width, "Bounds.Width");
+                       Assert.AreEqual (mh1.Bounds.Height, header.Bounds.Height, "Bounds.Height");
+                       Assert.AreEqual (mh1.DpiX, header.DpiX, "DpiX");
+                       Assert.AreEqual (mh1.DpiY, header.DpiY, "DpiY");
+                       Assert.AreEqual (mh1.EmfPlusHeaderSize, header.EmfPlusHeaderSize, "EmfPlusHeaderSize");
+                       Assert.AreEqual (mh1.LogicalDpiX, header.LogicalDpiX, "LogicalDpiX");
+                       Assert.AreEqual (mh1.LogicalDpiY, header.LogicalDpiY, "LogicalDpiY");
+                       Assert.AreEqual (mh1.MetafileSize, header.MetafileSize, "MetafileSize");
+                       Assert.AreEqual (mh1.Type, header.Type, "Type");
+                       Assert.AreEqual (mh1.Version, header.Version, "Version");
+                       // compare MetaHeader
+                       MetaHeader mh1h = mh1.WmfHeader;
+                       MetaHeader mh2h = header.WmfHeader;
+                       Assert.AreEqual (mh1h.HeaderSize, mh2h.HeaderSize, "HeaderSize");
+                       Assert.AreEqual (mh1h.MaxRecord, mh2h.MaxRecord, "MaxRecord");
+                       Assert.AreEqual (mh1h.NoObjects, mh2h.NoObjects, "NoObjects");
+                       Assert.AreEqual (mh1h.NoParameters, mh2h.NoParameters, "NoParameters");
+                       Assert.AreEqual (mh1h.Size, mh2h.Size, "Size");
+                       Assert.AreEqual (mh1h.Type, mh2h.Type, "Type");
+                       Assert.AreEqual (mh1h.Version, mh2h.Version, "Version");
+               }
+
+               [Test]
+               public void Metafile ()
+               {
+                       string filename = getInFile ("bitmaps/telescope_01.wmf");
+                       IntPtr metafile = IntPtr.Zero;
+
+                       Assert.AreEqual (Status.InvalidParameter, GDIPlus.GdipCreateMetafileFromFile (null, out metafile), "GdipCreateMetafileFromFile(null)");
+                       Assert.AreEqual (Status.GenericError, GDIPlus.GdipCreateMetafileFromFile ("doesnotexists", out metafile), "GdipCreateMetafileFromFile(doesnotexists)");
+                       Assert.AreEqual (Status.Ok, GDIPlus.GdipCreateMetafileFromFile (filename, out metafile), "GdipCreateMetafileFromFile");
+
+                       // looks like it applies to EmfOnly and EmfDual (not EmfPlus or Wmf*)
+                       uint limit = UInt32.MaxValue;
+                       Assert.AreEqual (Status.InvalidParameter, GDIPlus.GdipGetMetafileDownLevelRasterizationLimit (IntPtr.Zero, ref limit), "GdipGetMetafileDownLevelRasterizationLimit/null");
+                       Assert.AreEqual (Status.WrongState, GDIPlus.GdipGetMetafileDownLevelRasterizationLimit (metafile, ref limit), "GdipGetMetafileDownLevelRasterizationLimit");
+                       Assert.AreEqual (UInt32.MaxValue, limit, "DownLevelRasterizationLimit");
+                       Assert.AreEqual (Status.InvalidParameter, GDIPlus.GdipSetMetafileDownLevelRasterizationLimit (IntPtr.Zero, limit), "GdipSetMetafileDownLevelRasterizationLimit/null");
+                       Assert.AreEqual (Status.WrongState, GDIPlus.GdipSetMetafileDownLevelRasterizationLimit (metafile, limit), "GdipSetMetafileDownLevelRasterizationLimit");
+
+                       int size = Marshal.SizeOf (typeof (MetafileHeader));
+                       IntPtr header = Marshal.AllocHGlobal (size);
+                       try {
+                               Assert.AreEqual (Status.InvalidParameter, GDIPlus.GdipGetMetafileHeaderFromMetafile (IntPtr.Zero, header), "GdipGetMetafileHeaderFromMetafile(null,header)");
+// We get access violation here!
+//                             Assert.AreEqual (Status.InvalidParameter, GDIPlus.GdipGetMetafileHeaderFromMetafile (metafile, IntPtr.Zero), "GdipGetMetafileHeaderFromMetafile(metafile,null)");
+                               Assert.AreEqual (Status.Ok, GDIPlus.GdipGetMetafileHeaderFromMetafile (metafile, header), "GdipGetMetafileHeaderFromMetafile(metafile,header)");
+
+                               MetafileHeader mh2 = new Metafile (getInFile ("bitmaps/telescope_01.wmf")).GetMetafileHeader ();
+                               Marshal.PtrToStructure (header, mh2);
+                               CheckMetafileHeader (mh2);
+                       }
+                       finally {
+                               Marshal.FreeHGlobal (header);
+                       }
+
+                       Assert.AreEqual (Status.Ok, GDIPlus.GdipDisposeImage (metafile), "GdipDisposeImage");
+               }
+
+               [Test]
+               public void Metafile_GetMetafileHeaderFromFile ()
+               {
+                       string filename = getInFile ("bitmaps/telescope_01.wmf");
+
+                       int size = Marshal.SizeOf (typeof (MetafileHeader));
+                       IntPtr ptr = Marshal.AllocHGlobal (size);
+                       try {
+                               Assert.AreEqual (Status.InvalidParameter, GDIPlus.GdipGetMetafileHeaderFromFile ("does-not-exists", ptr), "GdipGetMetafileHeaderFromFile(doesnotexists,ptr)");
+                               Assert.AreEqual (Status.InvalidParameter, GDIPlus.GdipGetMetafileHeaderFromFile (null, ptr), "GdipGetMetafileHeaderFromFile(null,ptr)");
+// We get access violation here!
+//                             Assert.AreEqual (Status.InvalidParameter, GDIPlus.GdipGetMetafileHeaderFromFile (filename, IntPtr.Zero), "GdipGetMetafileHeaderFromFile(file,null)");
+                               Assert.AreEqual (Status.Ok, GDIPlus.GdipGetMetafileHeaderFromFile (filename, ptr), "GdipGetMetafileHeaderFromFile(file,ptr)");
+
+                               MetafileHeader header = new Metafile (getInFile ("bitmaps/telescope_01.wmf")).GetMetafileHeader ();
+                               Marshal.PtrToStructure (ptr, header);
+                               CheckMetafileHeader (header);
+                       }
+                       finally {
+                               Marshal.FreeHGlobal (ptr);
+                       }
+               }
+
+               [Test]
+               public void Metafile_Hemf ()
+               {
+                       string filename = getInFile ("bitmaps/telescope_01.wmf");
+                       IntPtr metafile = IntPtr.Zero;
+                       Assert.AreEqual (Status.Ok, GDIPlus.GdipCreateMetafileFromFile (filename, out metafile), "GdipCreateMetafileFromFile");
+
+                       IntPtr emf = IntPtr.Zero;
+                       Assert.AreEqual (Status.InvalidParameter, GDIPlus.GdipGetHemfFromMetafile (IntPtr.Zero, out emf), "GdipGetHemfFromMetafile(null,emf)");
+                       Assert.AreEqual (Status.Ok, GDIPlus.GdipGetHemfFromMetafile (metafile, out emf), "GdipGetHemfFromMetafile(metafile,emf)");
+
+                       int size = Marshal.SizeOf (typeof (MetafileHeader));
+                       IntPtr header = Marshal.AllocHGlobal (size);
+                       try {
+                               Assert.AreEqual (Status.InvalidParameter, GDIPlus.GdipGetMetafileHeaderFromEmf (IntPtr.Zero, header), "GdipGetMetafileHeaderFromEmf(null,header)");
+// We get access violation here!
+//                             Assert.AreEqual (Status.InvalidParameter, GDIPlus.GdipGetMetafileHeaderFromEmf (emf, IntPtr.Zero), "GdipGetMetafileHeaderFromEmf(emf,null)");
+                               // the HEMF handle cannot be used here
+                               Assert.AreEqual (Status.InvalidParameter, GDIPlus.GdipGetMetafileHeaderFromEmf (emf, header), "GdipGetMetafileHeaderFromEmf(emf,header)");
+                       }
+                       finally {
+                               Marshal.FreeHGlobal (header);
+                       }
+
+                       Assert.AreEqual (Status.Ok, GDIPlus.GdipDisposeImage (metafile), "GdipDisposeImage");
+               }
+
+               private void InImageAPI (IntPtr image)
+               {
+                       IntPtr ptr = IntPtr.Zero;
+                       Assert.AreEqual (Status.OutOfMemory, GDIPlus.GdipGetImageGraphicsContext (image, out ptr), "GdipGetImageGraphicsContext");
+
+                       RectangleF bounds;
+                       GraphicsUnit unit = GraphicsUnit.Display;
+                       Assert.AreEqual (Status.Ok, GDIPlus.GdipGetImageBounds (image, out bounds, ref unit), "GdipGetImageBounds");
+                       Assert.AreEqual (-30, bounds.X, "bounds.X");
+                       Assert.AreEqual (-40, bounds.Y, "bounds.Y");
+                       Assert.AreEqual (3096, bounds.Width, "bounds.Width");
+                       Assert.AreEqual (4127, bounds.Height, "bounds.Height");
+                       Assert.AreEqual (GraphicsUnit.Pixel, unit, "uint");
+
+                       float width, height;
+                       Assert.AreEqual (Status.Ok, GDIPlus.GdipGetImageDimension (image, out width, out height), "GdipGetImageDimension");
+                       Assert.AreEqual (12976.6328f, width, 0.001f, "GdipGetImageDimension/Width");
+                       Assert.AreEqual (17297.9863f, height, 0.001f, "GdipGetImageDimension/Height");
+
+                       ImageType type;
+                       Assert.AreEqual (Status.Ok, GDIPlus.GdipGetImageType (image, out type), "GdipGetImageType");
+                       Assert.AreEqual (ImageType.Metafile, type, "Metafile");
+
+                       uint w;
+                       Assert.AreEqual (Status.Ok, GDIPlus.GdipGetImageWidth (image, out w), "GdipGetImageWidth");
+                       Assert.AreEqual (3096, w, "GdipGetImageWidth/Width");
+
+                       uint h;
+                       Assert.AreEqual (Status.Ok, GDIPlus.GdipGetImageHeight (image, out h), "GdipGetImageHeight");
+                       Assert.AreEqual (4127, h, "GdipGetImageHeight/Height");
+
+                       float horz;
+                       Assert.AreEqual (Status.Ok, GDIPlus.GdipGetImageHorizontalResolution (image, out horz), "GdipGetImageHorizontalResolution");
+                       Assert.AreEqual (606, horz, "HorizontalResolution");
+
+                       float vert;
+                       Assert.AreEqual (Status.Ok, GDIPlus.GdipGetImageVerticalResolution (image, out vert), "GdipGetImageVerticalResolution");
+                       Assert.AreEqual (606, vert, "VerticalResolution");
+
+                       int flags;
+                       Assert.AreEqual (Status.Ok, GDIPlus.GdipGetImageFlags (image, out flags), "GdipGetImageFlags");
+                       Assert.AreEqual (327683, flags, "Flags");
+
+                       Guid format;
+                       Assert.AreEqual (Status.Ok, GDIPlus.GdipGetImageRawFormat (image, out format), "GdipGetImageRawFormat");
+                       Assert.AreEqual ("b96b3cad-0728-11d3-9d7b-0000f81ef32e", format.ToString (), "Format");
+
+                       PixelFormat pformat;
+                       Assert.AreEqual (Status.Ok, GDIPlus.GdipGetImagePixelFormat (image, out pformat), "GdipGetImagePixelFormat");
+                       Assert.AreEqual (PixelFormat.Format32bppRgb, pformat, "PixelFormat");
+
+                       uint count;
+                       Assert.AreEqual (Status.Ok, GDIPlus.GdipImageGetFrameDimensionsCount (image, out count), "GdipImageGetFrameDimensionsCount");
+                       Assert.AreEqual (1, count, "FrameDimensionsCount");
+
+                       Guid[] dimid = new Guid[1];
+                       Assert.AreEqual (Status.Ok, GDIPlus.GdipImageGetFrameDimensionsList (image, dimid, count), "GdipImageGetFrameDimensionsList");
+                       Assert.AreEqual ("7462dc86-6180-4c7e-8e3f-ee7333a7a483", dimid[0].ToString (), "Id[0]");
+                       Assert.AreEqual (Status.InvalidParameter, GDIPlus.GdipImageGetFrameDimensionsList (image, dimid, 0), "GdipImageGetFrameDimensionsList/0");
+                       Assert.AreEqual (Status.InvalidParameter, GDIPlus.GdipImageGetFrameDimensionsList (image, dimid, 2), "GdipImageGetFrameDimensionsList/2");
+
+                       Assert.AreEqual (Status.Ok, GDIPlus.GdipImageGetFrameCount (image, ref dimid[0], out count), "GdipImageGetFrameCount");
+                       Assert.AreEqual (1, count, "FrameCount");
+                       Guid g = Guid.Empty;
+                       Assert.AreEqual (Status.Ok, GDIPlus.GdipImageGetFrameCount (image, ref g, out count), "GdipImageGetFrameCount/Empty");
+                       Assert.AreEqual (1, count, "FrameCount/Empty");
+
+                       Assert.AreEqual (Status.Ok, GDIPlus.GdipImageSelectActiveFrame (image, ref dimid[0], 0), "GdipImageSelectActiveFrame");
+                       Assert.AreEqual (Status.Ok, GDIPlus.GdipImageSelectActiveFrame (image, ref g, 0), "GdipImageSelectActiveFrame/Empty");
+                       Assert.AreEqual (Status.Ok, GDIPlus.GdipImageSelectActiveFrame (image, ref dimid[0], Int32.MinValue), "GdipImageSelectActiveFrame/MinValue");
+                       Assert.AreEqual (Status.Ok, GDIPlus.GdipImageSelectActiveFrame (image, ref dimid[0], Int32.MaxValue), "GdipImageSelectActiveFrame/MaxValue");
+
+                       // woohoo :)
+                       foreach (RotateFlipType rft in Enum.GetValues (typeof (RotateFlipType))) {
+                               Assert.AreEqual (Status.NotImplemented, GDIPlus.GdipImageRotateFlip (image, rft), rft.ToString ());
+                       }
+
+                       int size;
+                       Assert.AreEqual (Status.GenericError, GDIPlus.GdipGetImagePaletteSize (image, out size), "GdipGetImagePaletteSize");
+                       Assert.AreEqual (Status.NotImplemented, GDIPlus.GdipGetImagePalette (image, image, 1024), "GdipGetImagePalette");
+                       Assert.AreEqual (Status.NotImplemented, GDIPlus.GdipSetImagePalette (image, image), "GdipSetImagePalette");
+
+                       Assert.AreEqual (Status.Ok, GDIPlus.GdipGetPropertyCount (image, out count), "GdipGetPropertyCount");
+                       Assert.AreEqual (0, count, "PropertyCount");
+                       Assert.AreEqual (Status.NotImplemented, GDIPlus.GdipGetPropertyIdList (image, 0, new int[1]), "GdipGetPropertyIdList");
+                       Assert.AreEqual (Status.NotImplemented, GDIPlus.GdipGetPropertyItemSize (image, 0, out size), "GdipGetPropertyItemSize");
+                       Assert.AreEqual (Status.NotImplemented, GDIPlus.GdipGetPropertyItem (image, 0, size, image), "GdipGetPropertyItem");
+                       int numbers;
+                       Assert.AreEqual (Status.NotImplemented, GDIPlus.GdipGetPropertySize (image, out size, out numbers), "GdipGetPropertySize");
+                       Assert.AreEqual (Status.NotImplemented, GDIPlus.GdipRemovePropertyItem (image, 0), "GdipRemovePropertyItem");
+                       //Assert.AreEqual (Status.NotImplemented, GDIPlus.GdipSetPropertyItem (image, image), "GdipSetPropertyItem");
+                       Assert.AreEqual (Status.NotImplemented, GDIPlus.GdipGetAllPropertyItems (image, 1000, 1, image), "GdipGetAllPropertyItems");
+
+                       Guid wmf = ImageFormat.Wmf.Guid;
+                       Assert.AreEqual (Status.FileNotFound, GDIPlus.GdipGetEncoderParameterListSize (image, ref wmf, out count), "GdipGetEncoderParameterListSize/wmf");
+                       Assert.AreEqual (Status.FileNotFound, GDIPlus.GdipGetEncoderParameterListSize (image, ref g, out count), "GdipGetEncoderParameterListSize/unknown");
+
+                       Assert.AreEqual (Status.FileNotFound, GDIPlus.GdipGetEncoderParameterList (image, ref wmf, count, image), "GdipGetEncoderParameterList/wmf");
+                       Assert.AreEqual (Status.FileNotFound, GDIPlus.GdipGetEncoderParameterList (image, ref g, count, image), "GdipGetEncoderParameterList/unknown");
+
+                       IntPtr clone;
+                       Assert.AreEqual (Status.Ok, GDIPlus.GdipCloneImage (image, out clone), "GdipCloneImage");
+                       try {
+                               Assert.IsFalse (image == clone, "Handle");
+                       }
+                       finally {
+                               Assert.AreEqual (Status.Ok, GDIPlus.GdipDisposeImage (clone), "GdipDisposeImage");
+                       }
+               }
+
+               [Test]
+               public void MetafileAsImage_InImageAPI ()
+               {
+                       string filename = getInFile ("bitmaps/telescope_01.wmf");
+                       IntPtr image = IntPtr.Zero;
+
+                       Assert.AreEqual (Status.Ok, GDIPlus.GdipLoadImageFromFile (filename, out image), "GdipLoadImageFromFile");
+                       try {
+                               InImageAPI (image);
+                       }
+                       finally {
+                               Assert.AreEqual (Status.Ok, GDIPlus.GdipDisposeImage (image), "GdipDisposeImage");
+                       }
+               }
+
+               [Test]
+               public void Metafile_InImageAPI ()
+               {
+                       string filename = getInFile ("bitmaps/telescope_01.wmf");
+                       IntPtr metafile = IntPtr.Zero;
+
+                       Assert.AreEqual (Status.Ok, GDIPlus.GdipCreateMetafileFromFile (filename, out metafile), "GdipCreateMetafileFromFile");
+                       try {
+                               InImageAPI (metafile);
+                       }
+                       finally {
+                               Assert.AreEqual (Status.Ok, GDIPlus.GdipDisposeImage (metafile), "GdipDisposeImage");
+                       }
+               }
+
+               private void RecordFileName (IntPtr hdc, EmfType type, MetafileFrameUnit unit)
+               {
+                       string filename = String.Format ("test-{0}-{1}.emf", type, unit);
+                       IntPtr metafile;
+                       RectangleF rect = new RectangleF (10, 20, 100, 200);
+                       Status status = GDIPlus.GdipRecordMetafileFileName (filename, hdc, type, ref rect, unit, filename, out metafile);
+                       if (metafile != IntPtr.Zero)
+                               GDIPlus.GdipDisposeImage (metafile);
+                       if (status == Status.Ok)
+                               File.Delete (filename);
+                       Assert.AreEqual (Status.Ok, status, filename);
+               }
+
+               private Status RecordFileName_EmptyRectangle (IntPtr hdc, MetafileFrameUnit unit)
+               {
+                       string filename = String.Format ("emptyrectangle-{0}.emf", unit);
+                       IntPtr metafile = IntPtr.Zero;
+                       RectangleF empty = new RectangleF ();
+                       Status status = GDIPlus.GdipRecordMetafileFileName (filename, hdc, EmfType.EmfPlusDual, ref empty, unit, filename, out metafile);
+                       if (metafile != IntPtr.Zero)
+                               GDIPlus.GdipDisposeImage (metafile);
+                       if (status == Status.Ok)
+                               File.Delete (filename);
+                       return status;
+               }
+
+               [Test]
+               public void RecordMetafileFileName ()
+               {
+                       using (Bitmap bmp = new Bitmap (100, 100, PixelFormat.Format32bppArgb)) {
+                               using (Graphics g = Graphics.FromImage (bmp)) {
+                                       IntPtr hdc = g.GetHdc ();
+                                       try {
+                                               IntPtr metafile;
+                                               RectangleF rect = new RectangleF ();
+                                               Assert.AreEqual (Status.InvalidParameter, GDIPlus.GdipRecordMetafileFileName (null, hdc, EmfType.EmfPlusOnly, ref rect, MetafileFrameUnit.GdiCompatible, "unit test", out metafile), "filename-null");
+                                               Assert.AreEqual (Status.InvalidParameter, GDIPlus.GdipRecordMetafileFileName ("a.emf", IntPtr.Zero, EmfType.EmfPlusOnly, ref rect, MetafileFrameUnit.GdiCompatible, "unit test", out metafile), "hdc-null");
+                                               Assert.AreEqual (Status.InvalidParameter, GDIPlus.GdipRecordMetafileFileName ("b.emf", hdc, (EmfType)Int32.MaxValue, ref rect, MetafileFrameUnit.GdiCompatible, "unit test", out metafile), "type-invalid");
+                                               Assert.AreEqual (Status.InvalidParameter, GDIPlus.GdipRecordMetafileFileName ("c.emf", hdc, EmfType.EmfPlusOnly, ref rect, (MetafileFrameUnit)Int32.MaxValue, "unit test", out metafile), "unit-invalid");
+                                               Assert.AreEqual (Status.Ok, GDIPlus.GdipRecordMetafileFileName ("d.emf", hdc, EmfType.EmfPlusOnly, ref rect, MetafileFrameUnit.GdiCompatible, null, out metafile), "description-null");
+                                               GDIPlus.GdipDisposeImage (metafile);
+                                               File.Delete ("d.emf");
+                                               // test some variations
+                                               Assert.AreEqual (Status.GenericError, RecordFileName_EmptyRectangle (hdc, MetafileFrameUnit.Document), "EmptyRectangle-Document");
+                                               Assert.AreEqual (Status.GenericError, RecordFileName_EmptyRectangle (hdc, MetafileFrameUnit.Inch), "EmptyRectangle-Inch");
+                                               Assert.AreEqual (Status.GenericError, RecordFileName_EmptyRectangle (hdc, MetafileFrameUnit.Millimeter), "EmptyRectangle-Millimeter");
+                                               Assert.AreEqual (Status.GenericError, RecordFileName_EmptyRectangle (hdc, MetafileFrameUnit.Pixel), "EmptyRectangle-Pixel");
+                                               Assert.AreEqual (Status.GenericError, RecordFileName_EmptyRectangle (hdc, MetafileFrameUnit.Point), "EmptyRectangle-Point");
+                                               Assert.AreEqual (Status.Ok, RecordFileName_EmptyRectangle (hdc, MetafileFrameUnit.GdiCompatible), "EmptyRectangle-GdiCompatible");
+                                               RecordFileName (hdc, EmfType.EmfOnly, MetafileFrameUnit.Document);
+                                               RecordFileName (hdc, EmfType.EmfPlusDual, MetafileFrameUnit.GdiCompatible);
+                                               RecordFileName (hdc, EmfType.EmfPlusOnly, MetafileFrameUnit.Inch);
+                                               RecordFileName (hdc, EmfType.EmfOnly, MetafileFrameUnit.Millimeter);
+                                               RecordFileName (hdc, EmfType.EmfPlusDual, MetafileFrameUnit.Pixel);
+                                               RecordFileName (hdc, EmfType.EmfPlusOnly, MetafileFrameUnit.Point);
+                                       }
+                                       finally {
+                                               g.ReleaseHdc (hdc);
+                                       }
+                               }
+                       }
+               }
        }
 }