2 // Direct GDI+ API unit tests
5 // Sebastien Pouliot <sebastien@ximian.com>
7 // Copyright (C) 2006 Novell, Inc (http://www.novell.com)
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 using System.Drawing.Imaging;
32 using System.Runtime.InteropServices;
33 using NUnit.Framework;
35 namespace MonoTests.System.Drawing {
37 // copied from Mono's System.Drawing.dll gdiEnums.cs
38 internal enum Status {
44 InsufficientBuffer = 5,
52 UnknownImageFormat = 13,
53 FontFamilyNotFound = 14,
54 FontStyleNotFound = 15,
56 UnsupportedGdiplusVersion = 17,
57 GdiplusNotInitialized = 18,
58 PropertyNotFound = 19,
59 PropertyNotSupported = 20,
64 public class GDIPlusTest {
66 [DllImport ("gdiplus.dll")]
67 internal static extern Status GdipCreateBitmapFromScan0 (int width, int height, int stride, PixelFormat format, IntPtr scan0, out IntPtr bmp);
70 public void CreateBitmapFromScan0 ()
73 Assert.AreEqual (Status.InvalidParameter, GdipCreateBitmapFromScan0 (-1, 10, 10, PixelFormat.Format32bppArgb, IntPtr.Zero, out bmp), "negative width");
77 [DllImport ("gdiplus.dll")]
78 internal static extern Status GdipDisposeImage (IntPtr image);
81 public void DisposeImage ()
83 // invalid image pointer (null)
84 Assert.AreEqual (Status.InvalidParameter, GdipDisposeImage (IntPtr.Zero), "null");
87 GdipCreateBitmapFromScan0 (10, 10, 0, PixelFormat.Format32bppArgb, IntPtr.Zero, out image);
88 Assert.AreEqual (Status.Ok, GdipDisposeImage (image), "first");
92 [Category ("NotWorking")]
93 public void DisposeImage_Dual ()
96 GdipCreateBitmapFromScan0 (10, 10, 0, PixelFormat.Format32bppArgb, IntPtr.Zero, out image);
98 Assert.AreEqual (Status.Ok, GdipDisposeImage (image), "first");
100 Assert.AreEqual (Status.ObjectBusy, GdipDisposeImage (image), "second");
104 [DllImport ("gdiplus.dll")]
105 internal static extern Status GdipGetImageThumbnail (IntPtr image, uint width, uint height, out IntPtr thumbImage, IntPtr callback, IntPtr callBackData);
108 [Category ("NotWorking")] // libgdiplus doesn't implement GdipGetImageThumbnail (it is done inside S.D)
109 public void GetImageThumbnail ()
113 // invalid image pointer (null)
114 Assert.AreEqual (Status.InvalidParameter, GdipGetImageThumbnail (IntPtr.Zero, 10, 10, out ptr, IntPtr.Zero, IntPtr.Zero));
117 GdipCreateBitmapFromScan0 (10, 10, 0, PixelFormat.Format32bppArgb, IntPtr.Zero, out image);
120 Assert.AreEqual (Status.OutOfMemory, GdipGetImageThumbnail (image, 0, 10, out ptr, IntPtr.Zero, IntPtr.Zero));
121 // invalid width (negative)
122 Assert.AreEqual (Status.OutOfMemory, GdipGetImageThumbnail (image, 0x8000000, 10, out ptr, IntPtr.Zero, IntPtr.Zero));
123 // invalid height (0)
124 Assert.AreEqual (Status.OutOfMemory, GdipGetImageThumbnail (image, 10, 0, out ptr, IntPtr.Zero, IntPtr.Zero));
125 // invalid height (negative)
126 Assert.AreEqual (Status.OutOfMemory, GdipGetImageThumbnail (image, 10, 0x8000000, out ptr, IntPtr.Zero, IntPtr.Zero));
129 GdipDisposeImage (image);