2007-04-16 Sebastien Pouliot <sebastien@ximian.com>
authorSebastien Pouliot <sebastien@ximian.com>
Mon, 16 Apr 2007 12:58:17 +0000 (12:58 -0000)
committerSebastien Pouliot <sebastien@ximian.com>
Mon, 16 Apr 2007 12:58:17 +0000 (12:58 -0000)
* GDIPlusTest.cs: Add test cases for GdipBitmap[Get|Set]Pixel on an
indexed bitmap (1bpp) and on a 16bpp grayscale bitmap.
* TestBitmap.cs: Add test cases for Format[1,4,8]bppIndexed and
Format16bppGrayScale.

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

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

index 28a47ea4b661183e5f06ea08fbbd1775e49e39e3..4c1e9ae7afc0e100a17bcd28516f552dac663568 100644 (file)
@@ -1,3 +1,10 @@
+2007-04-16  Sebastien Pouliot  <sebastien@ximian.com>
+
+       * GDIPlusTest.cs: Add test cases for GdipBitmap[Get|Set]Pixel on an
+       indexed bitmap (1bpp) and on a 16bpp grayscale bitmap.
+       * TestBitmap.cs: Add test cases for Format[1,4,8]bppIndexed and 
+       Format16bppGrayScale.
+
 2007-04-14  Sebastien Pouliot  <sebastien@ximian.com>
 
        * TestBitmap.cs: Always test buffer byte-by-byte to avoid endian 
index a011dd75a44b95db8c0a48327fab4a00fa301d4c..43e96abc38bd209d3f67569f99ebbe2d8fa9950c 100644 (file)
@@ -144,6 +144,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 ()
                {
index f24179b9cbdeb375826903c25980c600359b2859..71f46ec5162c073701cc40fe6572718452725dae 100644 (file)
@@ -333,6 +333,62 @@ namespace MonoTests.System.Drawing {
                }
 #endif
 
+               [Test]
+#if NET_2_0
+               [ExpectedException (typeof (InvalidOperationException))]
+#else
+               [ExpectedException (typeof (Exception))]
+#endif
+               public void Format1bppIndexed ()
+               {
+                       using (Bitmap bmp = new Bitmap (1, 1, PixelFormat.Format1bppIndexed)) {
+                               Color c = bmp.GetPixel (0, 0);
+                               Assert.AreEqual (-16777216, c.ToArgb (), "Color");
+                               bmp.SetPixel (0, 0, c);
+                       }
+               }
+
+               [Test]
+#if NET_2_0
+               [ExpectedException (typeof (InvalidOperationException))]
+#else
+               [ExpectedException (typeof (Exception))]
+#endif
+               public void Format4bppIndexed ()
+               {
+                       using (Bitmap bmp = new Bitmap (1, 1, PixelFormat.Format4bppIndexed)) {
+                               Color c = bmp.GetPixel (0, 0);
+                               Assert.AreEqual (-16777216, c.ToArgb (), "Color");
+                               bmp.SetPixel (0, 0, c);
+                       }
+               }
+
+               [Test]
+#if NET_2_0
+               [ExpectedException (typeof (InvalidOperationException))]
+#else
+               [ExpectedException (typeof (Exception))]
+#endif
+               public void Format8bppIndexed ()
+               {
+                       using (Bitmap bmp = new Bitmap (1, 1, PixelFormat.Format8bppIndexed)) {
+                               Color c = bmp.GetPixel (0, 0);
+                               Assert.AreEqual (-16777216, c.ToArgb (), "Color");
+                               bmp.SetPixel (0, 0, c);
+                       }
+               }
+
+               [Test]
+               [ExpectedException (typeof (ArgumentException))]
+               [Category ("NotWorking")] // libgdiplus doesn't support this format
+               public void Format16bppGrayScale ()
+               {
+                       using (Bitmap bmp = new Bitmap (1, 1, PixelFormat.Format16bppGrayScale)) {
+                               // and MS GDI+ support seems quite limited too
+                               bmp.GetPixel (0, 0);
+                       }
+               }
+
                private void FormatTest (PixelFormat format)
                {
                        bool alpha = Image.IsAlphaPixelFormat (format);