720bb76c1ebd6374fcd5377f98b2036f0a5892b5
[mono.git] / mcs / class / System.Drawing / Test / System.Drawing / GDIPlusTest.cs
1 //
2 // Direct GDI+ API unit tests
3 //
4 // Authors:
5 //      Sebastien Pouliot  <sebastien@ximian.com>
6 //
7 // Copyright (C) 2006 Novell, Inc (http://www.novell.com)
8 //
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:
16 //
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 //
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.
27 //
28
29 using System;
30 using System.Drawing;
31 using System.Drawing.Drawing2D;
32 using System.Drawing.Imaging;
33 using System.Runtime.InteropServices;
34 using NUnit.Framework;
35
36 namespace MonoTests.System.Drawing {
37
38         // copied from Mono's System.Drawing.dll gdiEnums.cs
39         internal enum Status {
40                 Ok = 0,
41                 GenericError = 1,
42                 InvalidParameter = 2,
43                 OutOfMemory = 3,
44                 ObjectBusy = 4,
45                 InsufficientBuffer = 5,
46                 NotImplemented = 6,
47                 Win32Error = 7,
48                 WrongState = 8,
49                 Aborted = 9,
50                 FileNotFound = 10,
51                 ValueOverflow = 11,
52                 AccessDenied = 12,
53                 UnknownImageFormat = 13,
54                 FontFamilyNotFound = 14,
55                 FontStyleNotFound = 15,
56                 NotTrueTypeFont = 16,
57                 UnsupportedGdiplusVersion = 17,
58                 GdiplusNotInitialized = 18,
59                 PropertyNotFound = 19,
60                 PropertyNotSupported = 20,
61                 ProfileNotFound = 21
62         }
63
64         // copied from Mono's System.Drawing.dll gdiEnums.cs
65         internal enum Unit {
66                 UnitWorld = 0,
67                 UnitDisplay = 1,
68                 UnitPixel = 2,
69                 UnitPoint = 3,
70                 UnitInch = 4,
71                 UnitDocument = 5,
72                 UnitMillimeter = 6
73         }
74
75         [StructLayout (LayoutKind.Sequential, CharSet = CharSet.Auto)]
76         public class LOGFONT {
77                 public int lfHeight = 0;
78                 public int lfWidth = 0;
79                 public int lfEscapement = 0;
80                 public int lfOrientation = 0;
81                 public int lfWeight = 0;
82                 public byte lfItalic = 0;
83                 public byte lfUnderline = 0;
84                 public byte lfStrikeOut = 0;
85                 public byte lfCharSet = 0;
86                 public byte lfOutPrecision = 0;
87                 public byte lfClipPrecision = 0;
88                 public byte lfQuality = 0;
89                 public byte lfPitchAndFamily = 0;
90                 [MarshalAs (UnmanagedType.ByValTStr, SizeConst = 32)]
91                 public string lfFaceName = null;
92         }
93
94         [TestFixture]
95         public class GDIPlusTest {
96
97                 // FontFamily
98
99                 [DllImport ("gdiplus.dll", CharSet=CharSet.Auto)]
100                 internal static extern Status GdipCreateFontFamilyFromName (
101                         [MarshalAs (UnmanagedType.LPWStr)] string fName, IntPtr collection, out IntPtr fontFamily);
102
103                 [DllImport ("gdiplus.dll")]
104                 internal static extern Status GdipGetGenericFontFamilySerif (out IntPtr fontFamily);
105
106                 [DllImport ("gdiplus.dll")]
107                 internal static extern Status GdipDeleteFontFamily (IntPtr fontfamily);
108
109                 [Test]
110                 public void DeleteFontFamily ()
111                 {
112                         // invalid image pointer (null)
113                         Assert.AreEqual (Status.InvalidParameter, GdipDeleteFontFamily (IntPtr.Zero), "null");
114
115                         IntPtr font_family;
116                         GdipCreateFontFamilyFromName ("Arial", IntPtr.Zero, out font_family);
117                         Assert.IsTrue (font_family != IntPtr.Zero, "GdipCreateFontFamilyFromName");
118                         Assert.AreEqual (Status.Ok, GdipDeleteFontFamily (font_family), "first");
119                 }
120
121                 [Test]
122                 [Category ("NotWorking")]
123                 public void DeleteFontFamily_DoubleDispose ()
124                 {
125                         IntPtr font_family;
126                         GdipGetGenericFontFamilySerif (out font_family);
127                         // first dispose
128                         Assert.AreEqual (Status.Ok, GdipDeleteFontFamily (font_family), "first");
129                         // second dispose
130                         Assert.AreEqual (Status.Ok, GdipDeleteFontFamily (font_family), "second");
131                 }
132
133                 // Font
134
135                 [DllImport ("gdiplus.dll")]
136                 internal static extern Status GdipCreateFont (IntPtr fontFamily, float emSize, FontStyle style, GraphicsUnit unit, out IntPtr font);
137
138                 [DllImport ("gdiplus.dll", CharSet = CharSet.Auto)]
139                 internal static extern Status GdipGetLogFont (IntPtr font, IntPtr graphics, [MarshalAs (UnmanagedType.AsAny), Out] object logfontA);
140
141                 [DllImport ("gdiplus.dll")]
142                 internal static extern Status GdipDeleteFont (IntPtr font);             
143
144                 [Test]
145                 public void CreateFont ()
146                 {
147                         IntPtr family;
148                         GdipCreateFontFamilyFromName ("Arial", IntPtr.Zero, out family);
149                         Assert.IsTrue (family != IntPtr.Zero, "family");
150
151                         IntPtr font;
152                         Assert.AreEqual (Status.Ok, GdipCreateFont (family, 10f, FontStyle.Regular, GraphicsUnit.Point, out font), "GdipCreateFont");
153                         Assert.IsTrue (font != IntPtr.Zero, "font");
154
155                         LOGFONT lf = new LOGFONT ();
156                         lf.lfCharSet = 1;
157                         Assert.AreEqual (Status.InvalidParameter, GdipGetLogFont (font, IntPtr.Zero, (object) lf), "GdipGetLogFont-null-graphics");
158                         Assert.AreEqual (0, lf.lfCharSet, "lfCharSet-null-graphics");
159
160                         IntPtr image;
161                         GdipCreateBitmapFromScan0 (10, 10, 0, PixelFormat.Format32bppArgb, IntPtr.Zero, out image);
162                         Assert.IsTrue (image != IntPtr.Zero, "image");
163
164                         IntPtr graphics;
165                         GdipGetImageGraphicsContext (image, out graphics);
166                         Assert.IsTrue (graphics != IntPtr.Zero, "graphics");
167
168                         lf.lfCharSet = 1;
169                         Assert.AreEqual (Status.InvalidParameter, GdipGetLogFont (IntPtr.Zero, graphics, (object) lf), "GdipGetLogFont-null");
170                         Assert.AreEqual (0, lf.lfCharSet, "lfCharSet-null");
171
172                         lf.lfCharSet = 1;
173                         Assert.AreEqual (Status.Ok, GdipGetLogFont (font, graphics, (object) lf), "GdipGetLogFont");
174                         Assert.AreEqual (0, lf.lfCharSet, "lfCharSet");
175                         // strangely this is 1 in the managed side
176
177                         Assert.AreEqual (Status.Ok, GdipDeleteFont (font), "GdipDeleteFont");
178                         Assert.AreEqual (Status.InvalidParameter, GdipDeleteFont (IntPtr.Zero), "GdipDeleteFont-null");
179
180                         Assert.AreEqual (Status.Ok, GdipDeleteFontFamily (family), "GdipDeleteFontFamily");
181                         Assert.AreEqual (Status.Ok, GdipDisposeImage (image), "GdipDisposeImage");
182                         Assert.AreEqual (Status.Ok, GdipDeleteGraphics (graphics), "GdipDeleteGraphics");
183                 }
184
185                 // Bitmap
186
187                 [DllImport ("gdiplus.dll")]
188                 internal static extern Status GdipCreateBitmapFromScan0 (int width, int height, int stride, PixelFormat format, IntPtr scan0, out IntPtr bmp);
189
190                 [Test]
191                 public void CreateBitmapFromScan0 ()
192                 {
193                         IntPtr bmp;
194                         Assert.AreEqual (Status.InvalidParameter, GdipCreateBitmapFromScan0 (-1, 10, 10, PixelFormat.Format32bppArgb, IntPtr.Zero, out bmp), "negative width");
195                 }
196
197                 // Brush
198
199                 [DllImport ("gdiplus.dll")]
200                 static internal extern Status GdipDeleteBrush (IntPtr brush);
201
202                 [Test]
203                 public void DeleteBrush ()
204                 {
205                         Assert.AreEqual (Status.InvalidParameter, GdipDeleteBrush (IntPtr.Zero), "GdipDeleteBrush");
206                 }
207
208                 // Graphics
209
210                 [DllImport ("gdiplus.dll")]
211                 internal static extern Status GdipGetImageGraphicsContext (IntPtr image, out IntPtr graphics);
212
213                 [DllImport ("gdiplus.dll")]
214                 static internal extern Status GdipDeleteGraphics (IntPtr graphics);
215
216                 [Test]
217                 public void Graphics ()
218                 {
219                         IntPtr graphics;
220                         Assert.AreEqual (Status.InvalidParameter, GdipGetImageGraphicsContext (IntPtr.Zero, out graphics), "GdipGetImageGraphicsContext");
221
222                         IntPtr image;
223                         GdipCreateBitmapFromScan0 (10, 10, 0, PixelFormat.Format32bppArgb, IntPtr.Zero, out image);
224                         Assert.IsTrue (image != IntPtr.Zero, "image");
225
226                         Assert.AreEqual (Status.Ok, GdipGetImageGraphicsContext (image, out graphics), "GdipGetImageGraphicsContext");
227                         Assert.IsTrue (graphics != IntPtr.Zero, "graphics");
228
229                         Assert.AreEqual (Status.Ok, GdipDeleteGraphics (graphics), "GdipDeleteGraphics");
230                         Assert.AreEqual (Status.InvalidParameter, GdipDeleteGraphics (IntPtr.Zero), "GdipDeleteGraphics-null");
231
232                         Assert.AreEqual (Status.Ok, GdipDisposeImage (image), "GdipDisposeImage");
233                 }
234
235                 // GraphicsPath
236
237                 [DllImport ("gdiplus.dll")]
238                 internal static extern Status GdipCreatePath (FillMode brushMode, out IntPtr path);
239
240                 [DllImport ("gdiplus.dll")]
241                 internal static extern Status GdipGetPointCount (IntPtr path, out int count);
242
243                 [DllImport ("gdiplus.dll")]
244                 internal static extern Status GdipGetPathPoints (IntPtr path, [Out] PointF[] points, int count);
245
246                 [DllImport ("gdiplus.dll")]
247                 internal static extern Status GdipGetPathTypes (IntPtr path, [Out] byte[] types, int count);
248
249                 [DllImport ("gdiplus.dll")]
250                 internal static extern Status GdipResetPath (IntPtr path);
251
252                 [DllImport ("gdiplus.dll")]
253                 internal static extern Status GdipAddPathLine (IntPtr path, float x1, float y1, float x2, float y2);
254
255                 [DllImport ("gdiplus.dll")]
256                 internal static extern Status GdipAddPathLine2 (IntPtr path, PointF[] points, int count);
257
258                 [DllImport ("gdiplus.dll")]
259                 internal static extern Status GdipWidenPath (IntPtr path, IntPtr pen, IntPtr matrix, float flatness);
260
261                 [DllImport ("gdiplus.dll")]                
262                 internal static extern Status GdipDeletePath (IntPtr path);
263
264                 [Test]
265                 public void GetPointCount_Zero ()
266                 {
267                         IntPtr path;
268                         Assert.AreEqual (Status.Ok, GdipCreatePath (FillMode.Alternate, out path), "GdipCreatePath");
269                         Assert.IsTrue (path != IntPtr.Zero, "Handle");
270
271                         int count;
272                         Assert.AreEqual (Status.InvalidParameter, GdipGetPointCount (IntPtr.Zero, out count), "GdipGetPointCount-null");
273                         Assert.AreEqual (Status.Ok, GdipGetPointCount (path, out count), "GdipGetPointCount");
274                         Assert.AreEqual (0, count, "Count");
275
276                         PointF[] points = new PointF[count];
277                         Assert.AreEqual (Status.InvalidParameter, GdipGetPathPoints (IntPtr.Zero, points, count), "GdipGetPathPoints-null-1");
278                         Assert.AreEqual (Status.InvalidParameter, GdipGetPathPoints (path, null, count), "GdipGetPathPoints-null-2");
279                         Assert.AreEqual (Status.InvalidParameter, GdipGetPathPoints (path, points, count), "GdipGetPathPoints");
280                         // can't get the points if the count is zero!
281
282                         byte[] types = new byte[count];
283                         Assert.AreEqual (Status.InvalidParameter, GdipGetPathTypes (IntPtr.Zero, types, count), "GdipGetPathTypes-null-1");
284                         Assert.AreEqual (Status.InvalidParameter, GdipGetPathTypes (path, null, count), "GdipGetPathTypes-null-2");
285                         Assert.AreEqual (Status.InvalidParameter, GdipGetPathTypes (path, types, count), "GdipGetPathTypes");
286                         // can't get the types if the count is zero!
287
288                         PointF[] pts_2f = new PointF[2] { new PointF (2f, 4f), new PointF (10f, 30f) };
289                         Assert.AreEqual (Status.InvalidParameter, GdipAddPathLine2 (IntPtr.Zero, pts_2f, pts_2f.Length), "GdipAddPathLine2-null-path");
290                         Assert.AreEqual (Status.InvalidParameter, GdipAddPathLine2 (path, null, pts_2f.Length), "GdipAddPathLine2-null-points");
291                         Assert.AreEqual (Status.InvalidParameter, GdipAddPathLine2 (path, pts_2f, -1), "GdipAddPathLine2-negative-count");
292                         Assert.AreEqual (Status.Ok, GdipAddPathLine2 (path, pts_2f, pts_2f.Length), "GdipAddPathLine2");
293
294                         Assert.AreEqual (Status.Ok, GdipGetPointCount (path, out count), "GdipGetPointCount");
295                         Assert.AreEqual (2, count, "Count");
296
297                         points = new PointF[count];
298                         Assert.AreEqual (Status.Ok, GdipGetPathPoints (path, points, count), "GdipGetPathPoints-ok");
299
300                         types = new byte[count];
301                         Assert.AreEqual (Status.Ok, GdipGetPathTypes (path, types, count), "GdipGetPathTypes-ok");
302
303                         Assert.AreEqual (Status.Ok, GdipResetPath (path), "GdipResetPath");
304                         Assert.AreEqual (Status.InvalidParameter, GdipResetPath (IntPtr.Zero), "GdipResetPath-null");
305
306                         Assert.AreEqual (Status.Ok, GdipDeletePath (path), "GdipDeletePath");
307                         Assert.AreEqual (Status.InvalidParameter, GdipDeletePath (IntPtr.Zero), "GdipDeletePath-null");
308                 }
309
310                 [Test]
311                 public void Widen ()
312                 {
313                         IntPtr pen;
314                         Assert.AreEqual (Status.Ok, GdipCreatePen1 (0, 0f, Unit.UnitWorld, out pen), "GdipCreatePen1");
315
316                         IntPtr path;
317                         Assert.AreEqual (Status.Ok, GdipCreatePath (FillMode.Alternate, out path), "GdipCreatePath");
318
319                         IntPtr matrix;
320                         Assert.AreEqual (Status.Ok, GdipCreateMatrix (out matrix), "GdipCreateMatrix");
321
322                         Assert.AreEqual (Status.InvalidParameter, GdipWidenPath (IntPtr.Zero, pen, matrix, 1.0f), "GdipWidenPath-null-path");
323                         // empty path
324                         Assert.AreEqual (Status.OutOfMemory, GdipWidenPath (path, pen, matrix, 1.0f), "GdipWidenPath");
325
326                         // add something to the path
327                         Assert.AreEqual (Status.InvalidParameter, GdipAddPathLine (IntPtr.Zero, 1, 1, 10, 10), "GdipAddPathLine");
328                         Assert.AreEqual (Status.Ok, GdipAddPathLine (path, 1, 1, 10, 10), "GdipAddPathLine");
329
330                         int count;
331                         Assert.AreEqual (Status.Ok, GdipGetPointCount (path, out count), "GdipGetPointCount");
332                         Assert.AreEqual (2, count, "Count");
333
334                         Assert.AreEqual (Status.Ok, GdipWidenPath (path, pen, matrix, 1.0f), "GdipWidenPath-2");
335
336                         Assert.AreEqual (Status.Ok, GdipDeleteMatrix (matrix), "GdipDeleteMatrix");
337                         Assert.AreEqual (Status.Ok, GdipDeletePath (path), "GdipDeletePath");
338                         Assert.AreEqual (Status.Ok, GdipDeletePen (pen), "GdipDeletePen");
339                 }
340
341                 // Matrix
342
343                 [DllImport ("gdiplus.dll")]
344                 internal static extern Status GdipCreateMatrix (out IntPtr matrix);
345
346                 [DllImport ("gdiplus.dll")]
347                 internal static extern Status GdipDeleteMatrix (IntPtr matrix);
348
349                 [Test]
350                 public void Matrix ()
351                 {
352                         IntPtr matrix;
353                         Assert.AreEqual (Status.Ok, GdipCreateMatrix (out matrix), "GdipCreateMatrix");
354                         Assert.IsTrue (matrix != IntPtr.Zero, "Handle");
355
356                         Assert.AreEqual (Status.InvalidParameter, GdipDeleteMatrix (IntPtr.Zero), "GdipDeleteMatrix-null");
357                         Assert.AreEqual (Status.Ok, GdipDeleteMatrix (matrix), "GdipDeleteMatrix");
358                 }
359
360                 // Image
361
362                 [DllImport ("gdiplus.dll")]
363                 internal static extern Status GdipDisposeImage (IntPtr image);
364
365                 [Test]
366                 public void DisposeImage ()
367                 {
368                         // invalid image pointer (null)
369                         Assert.AreEqual (Status.InvalidParameter, GdipDisposeImage (IntPtr.Zero), "null");
370
371                         IntPtr image;
372                         GdipCreateBitmapFromScan0 (10, 10, 0, PixelFormat.Format32bppArgb, IntPtr.Zero, out image);
373                         Assert.AreEqual (Status.Ok, GdipDisposeImage (image), "first");
374                 }
375
376                 [Test]
377                 [Category ("NotWorking")]
378                 public void DisposeImage_Dual ()
379                 {
380                         IntPtr image;
381                         GdipCreateBitmapFromScan0 (10, 10, 0, PixelFormat.Format32bppArgb, IntPtr.Zero, out image);
382                         // first dispose
383                         Assert.AreEqual (Status.Ok, GdipDisposeImage (image), "first");
384                         // second dispose
385                         Assert.AreEqual (Status.ObjectBusy, GdipDisposeImage (image), "second");
386                 }
387
388
389                 [DllImport ("gdiplus.dll")]
390                 internal static extern Status GdipGetImageThumbnail (IntPtr image, uint width, uint height, out IntPtr thumbImage, IntPtr callback, IntPtr callBackData);
391
392                 [Test]
393                 [Category ("NotWorking")] // libgdiplus doesn't implement GdipGetImageThumbnail (it is done inside S.D)
394                 public void GetImageThumbnail ()
395                 {
396                         IntPtr ptr;
397
398                         // invalid image pointer (null)
399                         Assert.AreEqual (Status.InvalidParameter, GdipGetImageThumbnail (IntPtr.Zero, 10, 10, out ptr, IntPtr.Zero, IntPtr.Zero));
400
401                         IntPtr image;
402                         GdipCreateBitmapFromScan0 (10, 10, 0, PixelFormat.Format32bppArgb, IntPtr.Zero, out image);
403                         try {
404                                 // invalid width (0)
405                                 Assert.AreEqual (Status.OutOfMemory, GdipGetImageThumbnail (image, 0, 10, out ptr, IntPtr.Zero, IntPtr.Zero));
406                                 // invalid width (negative)
407                                 Assert.AreEqual (Status.OutOfMemory, GdipGetImageThumbnail (image, 0x8000000, 10, out ptr, IntPtr.Zero, IntPtr.Zero));
408                                 // invalid height (0)
409                                 Assert.AreEqual (Status.OutOfMemory, GdipGetImageThumbnail (image, 10, 0, out ptr, IntPtr.Zero, IntPtr.Zero));
410                                 // invalid height (negative)
411                                 Assert.AreEqual (Status.OutOfMemory, GdipGetImageThumbnail (image, 10, 0x8000000, out ptr, IntPtr.Zero, IntPtr.Zero));
412                         }
413                         finally {
414                                 GdipDisposeImage (image);
415                         }
416                 }
417
418                 // PathGradientBrush
419
420                 [DllImport ("gdiplus.dll")]
421                 static internal extern Status GdipCreatePathGradient (PointF[] points, int count, WrapMode wrapMode, out IntPtr brush);
422
423                 [DllImport ("gdiplus.dll")]
424                 static internal extern Status GdipCreatePathGradientFromPath (IntPtr path, out IntPtr brush);
425
426                 [DllImport ("gdiplus.dll")]
427                 static internal extern Status GdipGetPathGradientBlendCount (IntPtr brush, out int count);
428
429                 [DllImport ("gdiplus.dll")]
430                 static internal extern Status GdipGetPathGradientPresetBlend (IntPtr brush, int[] blend, float[] positions, int count);
431
432
433                 [Test]
434                 public void CreatePathGradient ()
435                 {
436                         PointF[] points = null;
437                         IntPtr brush;
438                         Assert.AreEqual (Status.OutOfMemory, GdipCreatePathGradient (points, 0, WrapMode.Clamp, out brush), "null");
439
440                         points = new PointF [0];
441                         Assert.AreEqual (Status.OutOfMemory, GdipCreatePathGradient (points, 0, WrapMode.Clamp, out brush), "empty");
442
443                         points = new PointF[1];
444                         Assert.AreEqual (Status.OutOfMemory, GdipCreatePathGradient (points, 1, WrapMode.Clamp, out brush), "one");
445
446                         points = new PointF[2] { new PointF (1, 2), new PointF (20, 30) };
447                         Assert.AreEqual (Status.Ok, GdipCreatePathGradient (points, 2, WrapMode.Clamp, out brush), "two");
448                         Assert.IsTrue (brush != IntPtr.Zero, "Handle");
449
450                         int count;
451                         Assert.AreEqual (Status.Ok, GdipGetPathGradientBlendCount (brush, out count), "GdipGetPathGradientBlendCount");
452                         Assert.AreEqual (1, count, "blend count");
453
454                         int[] colors = new int[count];
455                         float[] positions = new float[count];
456                         Assert.AreEqual (Status.InvalidParameter, GdipGetPathGradientPresetBlend (brush, colors, positions, count), "GdipGetPathGradientBlend");
457                         // can't call that for 1 count!
458
459                         Assert.AreEqual (Status.Ok, GdipDeleteBrush (brush), "GdipDeleteBrush");
460                 }
461
462                 [Test]
463                 public void CreatePathGradient_FromPath_Line ()
464                 {
465                         IntPtr path;
466                         Assert.AreEqual (Status.Ok, GdipCreatePath (FillMode.Alternate, out path), "GdipCreatePath");
467
468                         IntPtr brush;
469                         Assert.AreEqual (Status.OutOfMemory, GdipCreatePathGradientFromPath (IntPtr.Zero, out brush), "null");
470                         Assert.AreEqual (Status.OutOfMemory, GdipCreatePathGradientFromPath (path, out brush), "empty path");
471
472                         Assert.AreEqual (Status.Ok, GdipAddPathLine (path, 1, 1, 10, 10), "GdipAddPathLine");
473
474                         Assert.AreEqual (Status.Ok, GdipCreatePathGradientFromPath (path, out brush), "path");
475                         Assert.IsTrue (brush != IntPtr.Zero, "Handle");
476
477                         int count;
478                         Assert.AreEqual (Status.Ok, GdipGetPathGradientBlendCount (brush, out count), "GdipGetPathGradientBlendCount");
479                         Assert.AreEqual (1, count, "blend count");
480
481                         int[] colors = new int[count];
482                         float[] positions = new float[count];
483                         Assert.AreEqual (Status.InvalidParameter, GdipGetPathGradientPresetBlend (brush, colors, positions, count), "GdipGetPathGradientBlend");
484
485                         Assert.AreEqual (Status.Ok, GdipDeleteBrush (brush), "GdipDeleteBrush");
486                         Assert.AreEqual (Status.Ok, GdipDeletePath (path), "GdipDeletePath");
487                 }
488
489                 [Test]
490                 public void CreatePathGradient_FromPath_Lines ()
491                 {
492                         IntPtr path;
493                         Assert.AreEqual (Status.Ok, GdipCreatePath (FillMode.Alternate, out path), "GdipCreatePath");
494
495                         PointF[] pts_2f = new PointF[2] { new PointF (2f, 4f), new PointF (10f, 30f) };
496                         Assert.AreEqual (Status.Ok, GdipAddPathLine2 (path, pts_2f, pts_2f.Length), "GdipAddPathLine2");
497
498                         IntPtr brush;
499                         Assert.AreEqual (Status.Ok, GdipCreatePathGradientFromPath (path, out brush), "path");
500                         Assert.IsTrue (brush != IntPtr.Zero, "Handle");
501
502                         int count;
503                         Assert.AreEqual (Status.Ok, GdipGetPathGradientBlendCount (brush, out count), "GdipGetPathGradientBlendCount");
504                         Assert.AreEqual (1, count, "blend count");
505
506                         int[] colors = new int[count];
507                         float[] positions = new float[count];
508                         Assert.AreEqual (Status.InvalidParameter, GdipGetPathGradientPresetBlend (brush, colors, positions, count), "GdipGetPathGradientBlend");
509
510                         Assert.AreEqual (Status.Ok, GdipDeleteBrush (brush), "GdipDeleteBrush");
511                         Assert.AreEqual (Status.Ok, GdipDeletePath (path), "GdipDeletePath");
512                 }
513
514                 // Pen
515
516                 [DllImport ("gdiplus.dll")]
517                 internal static extern Status GdipCreatePen1 (int argb, float width, Unit unit, out IntPtr pen);
518
519                 [DllImport ("gdiplus.dll")]
520                 internal static extern Status GdipGetPenDashStyle (IntPtr pen, out DashStyle dashStyle);
521
522                 [DllImport ("gdiplus.dll")]
523                 internal static extern Status GdipSetPenDashStyle (IntPtr pen, DashStyle dashStyle);
524
525                 [DllImport ("gdiplus.dll")]
526                 internal static extern Status GdipGetPenDashCount (IntPtr pen, out int count);
527
528                 [DllImport ("gdiplus.dll")]
529                 internal static extern Status GdipGetPenDashArray (IntPtr pen, float[] dash, int count);
530
531                 [DllImport ("gdiplus.dll")]
532                 internal static extern Status GdipDeletePen (IntPtr pen);
533
534                 [Test]
535                 public void CreatePen ()
536                 {
537                         IntPtr pen;
538                         Assert.AreEqual (Status.Ok, GdipCreatePen1 (0, 0f, Unit.UnitWorld, out pen), "GdipCreatePen1");
539                         Assert.IsTrue (pen != IntPtr.Zero, "pen");
540
541                         DashStyle ds;
542                         Assert.AreEqual (Status.Ok, GdipGetPenDashStyle (pen, out ds), "GdipGetPenDashStyle");
543                         Assert.AreEqual (Status.InvalidParameter, GdipGetPenDashStyle (IntPtr.Zero, out ds), "GdipGetPenDashStyle-null");
544
545                         ds = DashStyle.Custom;
546                         Assert.AreEqual (Status.Ok, GdipSetPenDashStyle (pen, ds), "GdipSetPenDashStyle");
547                         Assert.AreEqual (Status.InvalidParameter, GdipSetPenDashStyle (IntPtr.Zero, ds), "GdipSetPenDashStyle-null");
548
549                         int count;
550                         Assert.AreEqual (Status.Ok, GdipGetPenDashCount (pen, out count), "GdipGetPenDashCount");
551                         Assert.AreEqual (Status.InvalidParameter, GdipGetPenDashCount (IntPtr.Zero, out count), "GdipGetPenDashCount-null");
552                         Assert.AreEqual (0, count, "count");
553
554                         float[] dash = new float[count];
555                         Assert.AreEqual (Status.OutOfMemory, GdipGetPenDashArray (pen, dash, count), "GdipGetPenDashArray");
556                         Assert.AreEqual (Status.InvalidParameter, GdipGetPenDashArray (IntPtr.Zero, dash, count), "GdipGetPenDashArray-null-pen");
557                         Assert.AreEqual (Status.InvalidParameter, GdipGetPenDashArray (pen, null, count), "GdipGetPenDashArray-null-dash");
558
559                         Assert.AreEqual (Status.Ok, GdipDeletePen (pen), "GdipDeletePen");
560                         Assert.AreEqual (Status.InvalidParameter, GdipDeletePen (IntPtr.Zero), "GdipDeletePen-null");
561                 }
562
563                 // Region
564
565                 [DllImport ("gdiplus.dll")]
566                 static internal extern Status GdipCreateRegionRgnData (byte[] data, int size, out IntPtr region);
567
568                 [Test]
569                 public void CreateRegionRgnData ()
570                 {
571                         IntPtr region;
572                         Assert.AreEqual (Status.InvalidParameter, GdipCreateRegionRgnData (null, 0, out region));
573
574                         byte[] data = new byte[0];
575                         Assert.AreEqual (Status.GenericError, GdipCreateRegionRgnData (data, 0, out region));
576                 }
577         }
578 }