2007-01-11 Sebastien Pouliot <sebastien@ximian.com>
authorSebastien Pouliot <sebastien@ximian.com>
Thu, 11 Jan 2007 18:24:16 +0000 (18:24 -0000)
committerSebastien Pouliot <sebastien@ximian.com>
Thu, 11 Jan 2007 18:24:16 +0000 (18:24 -0000)
* GDIPlusTest.cs: Add test case for loading an icon and playing with
it's color palette.
* TestIcon.cs: Add test cases for different sizes of icons.

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

mcs/class/System.Drawing/Test/System.Drawing/ChangeLog
mcs/class/System.Drawing/Test/System.Drawing/GDIPlusTest.cs
mcs/class/System.Drawing/Test/System.Drawing/TestIcon.cs

index bbc1e462b7219fa809dbfb73121cd7fcc60a7817..b0819fb524c13c55f8c5915e90c833ce8b112a0d 100644 (file)
@@ -1,3 +1,9 @@
+2007-01-11  Sebastien Pouliot  <sebastien@ximian.com>
+
+       * GDIPlusTest.cs: Add test case for loading an icon and playing with
+       it's color palette.
+       * TestIcon.cs: Add test cases for different sizes of icons.
+
 2007-01-07  Sebastien Pouliot  <sebastien@ximian.com>
 
        * TestGraphics.cs: Mark MeasureString_StringFontInt_LongString and
index 2a7228c394bc6491900f5fd8a28322ae314c1b96..4f34b9464d132d53929fac1f0d5bbfcd4537b98d 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
@@ -641,6 +641,56 @@ 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");
+
+                                       // 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);
+                               }
+                       }
+                       finally {
+                               GDIPlus.GdipDisposeImage (bitmap);
+                       }
+               }
+
                [Test]
                public void Encoder ()
                {
index db37a832716a1a3dc3e6b265bde43c38bc3370e3..ae3f9ae86b50b5c7cc11c2a2ad14bc1cba6befa6 100644 (file)
@@ -5,7 +5,7 @@
 //     Sanjay Gupta <gsanjay@novell.com>
 //     Sebastien Pouliot  <sebastien@ximian.com>
 //
-// Copyright (C) 2004,2006 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2004,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
@@ -29,6 +29,7 @@
 
 using System;
 using System.Drawing;
+using System.Drawing.Imaging;
 using System.IO;
 using System.Reflection;
 using System.Security.Permissions;
@@ -42,6 +43,7 @@ namespace MonoTests.System.Drawing {
                
                Icon icon;
                Icon newIcon;
+               Icon icon16, icon32, icon48, icon64, icon96;
                FileStream fs;
                FileStream fs1;
 
@@ -59,6 +61,12 @@ namespace MonoTests.System.Drawing {
                        String path = TestBitmap.getInFile ("bitmaps/smiley.ico");
                        icon = new Icon (path);                 
                        fs1 = new FileStream (path, FileMode.Open);
+
+                       icon16 = new Icon (TestBitmap.getInFile ("bitmaps/16x16x16.ico"));
+                       icon32 = new Icon (TestBitmap.getInFile ("bitmaps/32x32x16.ico"));
+                       icon48 = new Icon (TestBitmap.getInFile ("bitmaps/48x48x1.ico"));
+                       icon64 = new Icon (TestBitmap.getInFile ("bitmaps/64x64x256.ico"));
+                       icon96 = new Icon (TestBitmap.getInFile ("bitmaps/96x96x256.ico"));
                }
 
                [TearDown]
@@ -72,13 +80,15 @@ namespace MonoTests.System.Drawing {
                                File.Delete ("newIcon.ico");
                }
 
-
                [Test]
 #if TARGET_JVM
                [Category ("NotWorking")]
 #endif
                public void TestConstructors ()
                {
+                       Assert.AreEqual (32, icon.Height, "C#0a");
+                       Assert.AreEqual (32, icon.Width, "C#0b");
+
                        newIcon = new Icon (fs1, 48, 48);
                        Assert.AreEqual (48, newIcon.Height, "C#1a");                   
                        Assert.AreEqual (48, newIcon.Width, "C#1b");
@@ -98,7 +108,6 @@ namespace MonoTests.System.Drawing {
                        Assert.AreEqual (32, icon.Width, "P#2");
                        Assert.AreEqual (32, icon.Size.Width, "P#3");
                        Assert.AreEqual (32, icon.Size.Height, "P#4");
-
                }
 
                [Test]
@@ -125,6 +134,77 @@ namespace MonoTests.System.Drawing {
                        
                        Assert.AreEqual (fs1.Length, fs.Length, "M#3");                 
                }
+
+               [Test]
+               public void Icon16ToBitmap ()
+               {
+                       using (Bitmap b = icon16.ToBitmap ()) {
+                               Assert.AreEqual (PixelFormat.Format32bppArgb, b.PixelFormat, "PixelFormat");
+                               // unlike the GDI+ icon decoder the palette isn't kept
+                               Assert.AreEqual (0, b.Palette.Entries.Length, "Palette");
+                               Assert.AreEqual (icon16.Height, b.Height, "Height");
+                               Assert.AreEqual (icon16.Width, b.Width, "Width");
+                               Assert.IsTrue (b.RawFormat.Equals (ImageFormat.MemoryBmp), "RawFormat");
+                               Assert.AreEqual (2, b.Flags, "Flags");
+                       }
+               }
+
+               [Test]
+               public void Icon32ToBitmap ()
+               {
+                       using (Bitmap b = icon32.ToBitmap ()) {
+                               Assert.AreEqual (PixelFormat.Format32bppArgb, b.PixelFormat, "PixelFormat");
+                               // unlike the GDI+ icon decoder the palette isn't kept
+                               Assert.AreEqual (0, b.Palette.Entries.Length, "Palette");
+                               Assert.AreEqual (icon32.Height, b.Height, "Height");
+                               Assert.AreEqual (icon32.Width, b.Width, "Width");
+                               Assert.IsTrue (b.RawFormat.Equals (ImageFormat.MemoryBmp), "RawFormat");
+                               Assert.AreEqual (2, b.Flags, "Flags");
+                       }
+               }
+
+               [Test]
+               public void Icon48ToBitmap ()
+               {
+                       using (Bitmap b = icon48.ToBitmap ()) {
+                               Assert.AreEqual (PixelFormat.Format32bppArgb, b.PixelFormat, "PixelFormat");
+                               // unlike the GDI+ icon decoder the palette isn't kept
+                               Assert.AreEqual (0, b.Palette.Entries.Length, "Palette");
+                               Assert.AreEqual (icon48.Height, b.Height, "Height");
+                               Assert.AreEqual (icon48.Width, b.Width, "Width");
+                               Assert.IsTrue (b.RawFormat.Equals (ImageFormat.MemoryBmp), "RawFormat");
+                               Assert.AreEqual (2, b.Flags, "Flags");
+                       }
+               }
+
+               [Test]
+               public void Icon64ToBitmap ()
+               {
+                       using (Bitmap b = icon64.ToBitmap ()) {
+                               Assert.AreEqual (PixelFormat.Format32bppArgb, b.PixelFormat, "PixelFormat");
+                               // unlike the GDI+ icon decoder the palette isn't kept
+                               Assert.AreEqual (0, b.Palette.Entries.Length, "Palette");
+                               Assert.AreEqual (icon64.Height, b.Height, "Height");
+                               Assert.AreEqual (icon64.Width, b.Width, "Width");
+                               Assert.IsTrue (b.RawFormat.Equals (ImageFormat.MemoryBmp), "RawFormat");
+                               Assert.AreEqual (2, b.Flags, "Flags");
+                       }
+               }
+
+               [Test]
+               public void Icon96ToBitmap ()
+               {
+                       using (Bitmap b = icon96.ToBitmap ()) {
+                               Assert.AreEqual (PixelFormat.Format32bppArgb, b.PixelFormat, "PixelFormat");
+                               // unlike the GDI+ icon decoder the palette isn't kept
+                               Assert.AreEqual (0, b.Palette.Entries.Length, "Palette");
+                               Assert.AreEqual (icon96.Height, b.Height, "Height");
+                               Assert.AreEqual (icon96.Width, b.Width, "Width");
+                               Assert.IsTrue (b.RawFormat.Equals (ImageFormat.MemoryBmp), "RawFormat");
+                               Assert.AreEqual (2, b.Flags, "Flags");
+                       }
+               }
+
 #if NET_2_0
                [Test]
                [ExpectedException (typeof (ArgumentException))]