* roottypes.cs: Rename from tree.cs.
[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.Imaging;
32 using System.Runtime.InteropServices;
33 using NUnit.Framework;
34
35 namespace MonoTests.System.Drawing {
36
37         // copied from Mono's System.Drawing.dll gdiEnums.cs
38         internal enum Status {
39                 Ok = 0,
40                 GenericError = 1,
41                 InvalidParameter = 2,
42                 OutOfMemory = 3,
43                 ObjectBusy = 4,
44                 InsufficientBuffer = 5,
45                 NotImplemented = 6,
46                 Win32Error = 7,
47                 WrongState = 8,
48                 Aborted = 9,
49                 FileNotFound = 10,
50                 ValueOverflow = 11,
51                 AccessDenied = 12,
52                 UnknownImageFormat = 13,
53                 FontFamilyNotFound = 14,
54                 FontStyleNotFound = 15,
55                 NotTrueTypeFont = 16,
56                 UnsupportedGdiplusVersion = 17,
57                 GdiplusNotInitialized = 18,
58                 PropertyNotFound = 19,
59                 PropertyNotSupported = 20,
60                 ProfileNotFound = 21
61         }
62
63         [TestFixture]
64         public class GDIPlusTest {
65
66                 [DllImport ("gdiplus.dll")]
67                 internal static extern Status GdipCreateBitmapFromScan0 (int width, int height, int stride, PixelFormat format, IntPtr scan0, out IntPtr bmp);
68
69                 [Test]
70                 public void CreateBitmapFromScan0 ()
71                 {
72                         IntPtr bmp;
73                         Assert.AreEqual (Status.InvalidParameter, GdipCreateBitmapFromScan0 (-1, 10, 10, PixelFormat.Format32bppArgb, IntPtr.Zero, out bmp), "negative width");
74                 }
75
76
77                 [DllImport ("gdiplus.dll")]
78                 internal static extern Status GdipDisposeImage (IntPtr image);
79
80                 [Test]
81                 public void DisposeImage ()
82                 {
83                         // invalid image pointer (null)
84                         Assert.AreEqual (Status.InvalidParameter, GdipDisposeImage (IntPtr.Zero), "null");
85
86                         IntPtr image;
87                         GdipCreateBitmapFromScan0 (10, 10, 0, PixelFormat.Format32bppArgb, IntPtr.Zero, out image);
88                         Assert.AreEqual (Status.Ok, GdipDisposeImage (image), "first");
89                 }
90
91                 [Test]
92                 [Category ("NotWorking")]
93                 public void DisposeImage_Dual ()
94                 {
95                         IntPtr image;
96                         GdipCreateBitmapFromScan0 (10, 10, 0, PixelFormat.Format32bppArgb, IntPtr.Zero, out image);
97                         // first dispose
98                         Assert.AreEqual (Status.Ok, GdipDisposeImage (image), "first");
99                         // second dispose
100                         Assert.AreEqual (Status.ObjectBusy, GdipDisposeImage (image), "second");
101                 }
102
103
104                 [DllImport ("gdiplus.dll")]
105                 internal static extern Status GdipGetImageThumbnail (IntPtr image, uint width, uint height, out IntPtr thumbImage, IntPtr callback, IntPtr callBackData);
106
107                 [Test]
108                 [Category ("NotWorking")] // libgdiplus doesn't implement GdipGetImageThumbnail (it is done inside S.D)
109                 public void GetImageThumbnail ()
110                 {
111                         IntPtr ptr;
112
113                         // invalid image pointer (null)
114                         Assert.AreEqual (Status.InvalidParameter, GdipGetImageThumbnail (IntPtr.Zero, 10, 10, out ptr, IntPtr.Zero, IntPtr.Zero));
115
116                         IntPtr image;
117                         GdipCreateBitmapFromScan0 (10, 10, 0, PixelFormat.Format32bppArgb, IntPtr.Zero, out image);
118                         try {
119                                 // invalid width (0)
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));
127                         }
128                         finally {
129                                 GdipDisposeImage (image);
130                         }
131                 }
132         }
133 }