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.Drawing2D;
32 using System.Drawing.Imaging;
33 using System.Runtime.InteropServices;
34 using NUnit.Framework;
36 namespace MonoTests.System.Drawing {
38 // copied from Mono's System.Drawing.dll gdiEnums.cs
39 internal enum Status {
45 InsufficientBuffer = 5,
53 UnknownImageFormat = 13,
54 FontFamilyNotFound = 14,
55 FontStyleNotFound = 15,
57 UnsupportedGdiplusVersion = 17,
58 GdiplusNotInitialized = 18,
59 PropertyNotFound = 19,
60 PropertyNotSupported = 20,
65 public class GDIPlusTest {
69 [DllImport ("gdiplus.dll", CharSet=CharSet.Auto)]
70 internal static extern Status GdipCreateFontFamilyFromName (
71 [MarshalAs (UnmanagedType.LPWStr)] string fName, IntPtr collection, out IntPtr fontFamily);
73 [DllImport ("gdiplus.dll")]
74 internal static extern Status GdipGetGenericFontFamilySerif (out IntPtr fontFamily);
76 [DllImport ("gdiplus.dll")]
77 internal static extern Status GdipDeleteFontFamily (IntPtr fontfamily);
80 public void DeleteFontFamily ()
82 // invalid image pointer (null)
83 Assert.AreEqual (Status.InvalidParameter, GdipDeleteFontFamily (IntPtr.Zero), "null");
86 GdipCreateFontFamilyFromName ("Arial", IntPtr.Zero, out font_family);
87 Assert.IsTrue (font_family != IntPtr.Zero, "GdipCreateFontFamilyFromName");
88 Assert.AreEqual (Status.Ok, GdipDeleteFontFamily (font_family), "first");
92 [Category ("NotWorking")]
93 public void DeleteFontFamily_DoubleDispose ()
96 GdipGetGenericFontFamilySerif (out font_family);
98 Assert.AreEqual (Status.Ok, GdipDeleteFontFamily (font_family), "first");
100 Assert.AreEqual (Status.Ok, GdipDeleteFontFamily (font_family), "second");
105 [DllImport ("gdiplus.dll")]
106 internal static extern Status GdipCreateBitmapFromScan0 (int width, int height, int stride, PixelFormat format, IntPtr scan0, out IntPtr bmp);
109 public void CreateBitmapFromScan0 ()
112 Assert.AreEqual (Status.InvalidParameter, GdipCreateBitmapFromScan0 (-1, 10, 10, PixelFormat.Format32bppArgb, IntPtr.Zero, out bmp), "negative width");
117 [DllImport ("gdiplus.dll")]
118 internal static extern Status GdipCreatePath (FillMode brushMode, out IntPtr path);
120 [DllImport ("gdiplus.dll")]
121 internal static extern Status GdipGetPointCount (IntPtr path, out int count);
123 [DllImport ("gdiplus.dll")]
124 internal static extern Status GdipGetPathPoints (IntPtr path, [Out] PointF[] points, int count);
126 [DllImport ("gdiplus.dll")]
127 internal static extern Status GdipGetPathTypes (IntPtr path, [Out] byte[] types, int count);
130 public void GetPointCount_Zero ()
133 Assert.AreEqual (Status.Ok, GdipCreatePath (FillMode.Alternate, out path), "GdipCreatePath");
134 Assert.IsTrue (path != IntPtr.Zero, "Handle");
137 Assert.AreEqual (Status.Ok, GdipGetPointCount (path, out count), "GdipGetPointCount");
138 Assert.AreEqual (0, count, "Count");
140 PointF[] points = new PointF[count];
141 Assert.AreEqual (Status.InvalidParameter, GdipGetPathPoints (path, points, count), "GdipGetPathPoints");
142 // can't get the points if the count is zero!
144 byte[] types = new byte[count];
145 Assert.AreEqual (Status.InvalidParameter, GdipGetPathTypes (path, types, count), "GdipGetPathTypes");
146 // can't get the types if the count is zero!
151 [DllImport ("gdiplus.dll")]
152 internal static extern Status GdipDisposeImage (IntPtr image);
155 public void DisposeImage ()
157 // invalid image pointer (null)
158 Assert.AreEqual (Status.InvalidParameter, GdipDisposeImage (IntPtr.Zero), "null");
161 GdipCreateBitmapFromScan0 (10, 10, 0, PixelFormat.Format32bppArgb, IntPtr.Zero, out image);
162 Assert.AreEqual (Status.Ok, GdipDisposeImage (image), "first");
166 [Category ("NotWorking")]
167 public void DisposeImage_Dual ()
170 GdipCreateBitmapFromScan0 (10, 10, 0, PixelFormat.Format32bppArgb, IntPtr.Zero, out image);
172 Assert.AreEqual (Status.Ok, GdipDisposeImage (image), "first");
174 Assert.AreEqual (Status.ObjectBusy, GdipDisposeImage (image), "second");
178 [DllImport ("gdiplus.dll")]
179 internal static extern Status GdipGetImageThumbnail (IntPtr image, uint width, uint height, out IntPtr thumbImage, IntPtr callback, IntPtr callBackData);
182 [Category ("NotWorking")] // libgdiplus doesn't implement GdipGetImageThumbnail (it is done inside S.D)
183 public void GetImageThumbnail ()
187 // invalid image pointer (null)
188 Assert.AreEqual (Status.InvalidParameter, GdipGetImageThumbnail (IntPtr.Zero, 10, 10, out ptr, IntPtr.Zero, IntPtr.Zero));
191 GdipCreateBitmapFromScan0 (10, 10, 0, PixelFormat.Format32bppArgb, IntPtr.Zero, out image);
194 Assert.AreEqual (Status.OutOfMemory, GdipGetImageThumbnail (image, 0, 10, out ptr, IntPtr.Zero, IntPtr.Zero));
195 // invalid width (negative)
196 Assert.AreEqual (Status.OutOfMemory, GdipGetImageThumbnail (image, 0x8000000, 10, out ptr, IntPtr.Zero, IntPtr.Zero));
197 // invalid height (0)
198 Assert.AreEqual (Status.OutOfMemory, GdipGetImageThumbnail (image, 10, 0, out ptr, IntPtr.Zero, IntPtr.Zero));
199 // invalid height (negative)
200 Assert.AreEqual (Status.OutOfMemory, GdipGetImageThumbnail (image, 10, 0x8000000, out ptr, IntPtr.Zero, IntPtr.Zero));
203 GdipDisposeImage (image);
209 [DllImport ("gdiplus.dll")]
210 static internal extern Status GdipCreateRegionRgnData (byte[] data, int size, out IntPtr region);
213 public void CreateRegionRgnData ()
216 Assert.AreEqual (Status.InvalidParameter, GdipCreateRegionRgnData (null, 0, out region));
218 byte[] data = new byte[0];
219 Assert.AreEqual (Status.GenericError, GdipCreateRegionRgnData (data, 0, out region));