From 119bb12fcadb6388607b0d2ffe071c8270a01e49 Mon Sep 17 00:00:00 2001 From: Sebastien Pouliot Date: Fri, 19 Jan 2007 19:27:17 +0000 Subject: [PATCH] 2007-01-19 Sebastien Pouliot * GDIPlusTest.cs: Add test cases for loading unexisting files in GdipLoadImageFromFile and GdipCreateBitmapFromFile. Added test case for error code returned by GdipGetImageGraphicsContext for indexed bitmaps. svn path=/trunk/mcs/; revision=71362 --- .../Test/System.Drawing/ChangeLog | 7 +++ .../Test/System.Drawing/GDIPlusTest.cs | 56 +++++++++++++++++++ 2 files changed, 63 insertions(+) diff --git a/mcs/class/System.Drawing/Test/System.Drawing/ChangeLog b/mcs/class/System.Drawing/Test/System.Drawing/ChangeLog index 1f869b5e31e..9fdb0b716a9 100644 --- a/mcs/class/System.Drawing/Test/System.Drawing/ChangeLog +++ b/mcs/class/System.Drawing/Test/System.Drawing/ChangeLog @@ -1,3 +1,10 @@ +2007-01-19 Sebastien Pouliot + + * GDIPlusTest.cs: Add test cases for loading unexisting files in + GdipLoadImageFromFile and GdipCreateBitmapFromFile. Added test case + for error code returned by GdipGetImageGraphicsContext for indexed + bitmaps. + 2007-01-18 Sebastien Pouliot * TestGraphics.cs: Fix the LoadIndexed test case as it's current diff --git a/mcs/class/System.Drawing/Test/System.Drawing/GDIPlusTest.cs b/mcs/class/System.Drawing/Test/System.Drawing/GDIPlusTest.cs index 4f34b9464d1..c1f6472e1ab 100644 --- a/mcs/class/System.Drawing/Test/System.Drawing/GDIPlusTest.cs +++ b/mcs/class/System.Drawing/Test/System.Drawing/GDIPlusTest.cs @@ -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; @@ -691,6 +692,61 @@ namespace MonoTests.System.Drawing { } } + [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] + [ExpectedException (typeof (FileNotFoundException))] + 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 + Image.FromFile (filename); + } + + [Test] + [ExpectedException (typeof (ArgumentException))] + 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"); + + new Bitmap (filename); + } + [Test] public void Encoder () { -- 2.25.1