Remove invalid tests for image palettes in GdiPlusTest (#5671)
[mono.git] / mcs / class / System.Drawing / Test / System.Drawing / GDIPlusTest.cs
index 640ed6a299800b750ae9524855ce4189aaede18a..4e6c25725298c8f808a2ac4720fcbd63a8c4dece 100644 (file)
@@ -60,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 ()
@@ -87,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 ()
@@ -304,6 +340,55 @@ namespace MonoTests.System.Drawing {
                        }
                }
 
+               [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");
+
+                       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");
+               }
+
                [Test]
                public void MeasureCharacterRanges ()
                {
@@ -395,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");
@@ -779,14 +864,6 @@ namespace MonoTests.System.Drawing {
                                        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");
-
-                                       // change palette to 0 entries
-                                       int flags = Marshal.ReadInt32 (palette);
-                                       Marshal.WriteInt64 (palette, flags << 32);
-                                       Assert.AreEqual (Status.Ok, GDIPlus.GdipSetImagePalette (bitmap, palette), "GdipSetImagePalette/Empty");
-
-                                       Assert.AreEqual (Status.Ok, GDIPlus.GdipGetImagePaletteSize (bitmap, out size), "GdipGetImagePaletteSize/Empty");
-                                       Assert.AreEqual (8, size, "size");
                                }
                                finally {
                                        Marshal.FreeHGlobal (palette);
@@ -826,7 +903,6 @@ namespace MonoTests.System.Drawing {
                }
 
                [Test]
-               [ExpectedException (typeof (FileNotFoundException))]
                public void GdipLoadImageFromFile_FileNotFound ()
                {
                        string filename = "filenotfound";
@@ -836,11 +912,10 @@ namespace MonoTests.System.Drawing {
                        Assert.AreEqual (IntPtr.Zero, image, "image handle");
 
                        // this doesn't throw a OutOfMemoryException
-                       Image.FromFile (filename);
+                       Assert.Throws<FileNotFoundException> (() => Image.FromFile (filename));
                }
 
                [Test]
-               [ExpectedException (typeof (ArgumentException))]
                public void GdipCreateBitmapFromFile_FileNotFound ()
                {
                        string filename = "filenotfound";
@@ -849,7 +924,7 @@ namespace MonoTests.System.Drawing {
                        Assert.AreEqual (Status.InvalidParameter, GDIPlus.GdipCreateBitmapFromFile (filename, out bitmap), "GdipCreateBitmapFromFile");
                        Assert.AreEqual (IntPtr.Zero, bitmap, "bitmap handle");
 
-                       new Bitmap (filename);
+                       Assert.Throws<ArgumentException> (() => new Bitmap (filename));
                }
 
                [Test]
@@ -994,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;
@@ -1023,7 +1098,7 @@ namespace MonoTests.System.Drawing {
                public void PenColor_81266 ()
                {
                        IntPtr pen;
-                       Assert.AreEqual (Status.Ok, GDIPlus.GdipCreatePen1 (0x7f0000ff, 1f, Unit.UnitPixel, out pen), "GdipCreatePen1");
+                       Assert.AreEqual (Status.Ok, GDIPlus.GdipCreatePen1 (0x7f0000ff, 1f, GraphicsUnit.Pixel, out pen), "GdipCreatePen1");
                        try {
                                int color = 0;
                                IntPtr brush;
@@ -1081,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
 
@@ -1097,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
@@ -1108,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
@@ -1123,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);                    
@@ -1139,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);
@@ -1498,8 +1573,8 @@ namespace MonoTests.System.Drawing {
 
                        float width, height;
                        Assert.AreEqual (Status.Ok, GDIPlus.GdipGetImageDimension (image, out width, out height), "GdipGetImageDimension");
-                       Assert.AreEqual (12976.63, width, "GdipGetImageDimension/Width");
-                       Assert.AreEqual (17297.99, height, "GdipGetImageDimension/Height");
+                       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");
@@ -1572,7 +1647,7 @@ namespace MonoTests.System.Drawing {
                        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.GdipSetPropertyItem (image, image), "GdipSetPropertyItem");
                        Assert.AreEqual (Status.NotImplemented, GDIPlus.GdipGetAllPropertyItems (image, 1000, 1, image), "GdipGetAllPropertyItems");
 
                        Guid wmf = ImageFormat.Wmf.Guid;