2 // Image class testing unit
5 // Jordi Mas i Hernàndez (jmas@softcatala.org>
6 // Sebastien Pouliot <sebastien@ximian.com>
8 // (C) 2005 Ximian, Inc. http://www.ximian.com
9 // Copyright (C) 2005, 2006 Novell, Inc (http://www.novell.com)
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 using System.Drawing.Imaging;
35 using System.Security.Permissions;
36 using NUnit.Framework;
38 namespace MonoTests.System.Drawing{
41 [SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
42 public class ImageTest {
45 private bool callback;
48 public void FixtureSetup ()
50 fname = Path.GetTempFileName ();
54 public void FixtureTearDown ()
70 [ExpectedException (typeof (FileNotFoundException))]
71 public void FileDoesNotExists ()
73 Image.FromFile ("FileDoesNotExists.jpg");
76 private bool CallbackTrue ()
82 private bool CallbackFalse ()
89 public void GetThumbnailImage_NullCallback_Tiff ()
91 using (Bitmap bmp = new Bitmap (10, 10)) {
92 // according to documentation a callback is mandatory
93 Image tn = bmp.GetThumbnailImage (10, 5, null, IntPtr.Zero);
94 Assert.AreEqual (5, tn.Height, "Height");
95 Assert.AreEqual (10, tn.Width, "Width");
96 Assert.IsFalse (callback, "Callback called");
97 tn.Save (fname, ImageFormat.Tiff);
102 [ExpectedException (typeof (OutOfMemoryException))]
103 public void GetThumbnailImage_Height_Zero ()
105 using (Bitmap bmp = new Bitmap (10, 10)) {
106 Image tn = bmp.GetThumbnailImage (5, 0, new Image.GetThumbnailImageAbort (CallbackFalse), IntPtr.Zero);
111 [ExpectedException (typeof (OutOfMemoryException))]
112 public void GetThumbnailImage_Width_Negative ()
114 using (Bitmap bmp = new Bitmap (10, 10)) {
115 Image tn = bmp.GetThumbnailImage (-5, 5, new Image.GetThumbnailImageAbort (CallbackFalse), IntPtr.Zero);
120 public void GetThumbnailImage_CallbackData_Invalid ()
122 using (Bitmap bmp = new Bitmap (10, 10)) {
123 // according to documentation IntPtr.Zero must be supplied as data
124 Image tn = bmp.GetThumbnailImage (5, 5, new Image.GetThumbnailImageAbort (CallbackFalse), (IntPtr)Int32.MaxValue);
125 Assert.AreEqual (5, tn.Height, "Height");
126 Assert.AreEqual (5, tn.Width, "Width");
127 Assert.IsFalse (callback, "Callback called");
128 tn.Save (fname, ImageFormat.Tiff);
133 public void GetThumbnailImage_SameSize_Bmp ()
135 using (Bitmap bmp = new Bitmap (10, 10)) {
136 Image tn = bmp.GetThumbnailImage (10, 10, new Image.GetThumbnailImageAbort (CallbackFalse), IntPtr.Zero);
137 Assert.AreEqual (10, tn.Height, "Height");
138 Assert.AreEqual (10, tn.Width, "Width");
139 Assert.IsFalse (callback, "Callback called");
140 tn.Save (fname, ImageFormat.Bmp);
145 public void GetThumbnailImage_Smaller_Gif ()
147 using (Bitmap bmp = new Bitmap (10, 10)) {
148 Image tn = bmp.GetThumbnailImage (4, 4, new Image.GetThumbnailImageAbort (CallbackTrue), IntPtr.Zero);
149 Assert.AreEqual (4, tn.Height, "Height");
150 Assert.AreEqual (4, tn.Width, "Width");
151 Assert.IsFalse (callback, "Callback called");
152 tn.Save (fname, ImageFormat.Gif);
157 public void GetThumbnailImage_Bigger_Png ()
159 using (Bitmap bmp = new Bitmap (10, 10)) {
160 Image tn = bmp.GetThumbnailImage (40, 40, new Image.GetThumbnailImageAbort (CallbackTrue), IntPtr.Zero);
161 Assert.AreEqual (40, tn.Height, "Height");
162 Assert.AreEqual (40, tn.Width, "Width");
163 Assert.IsFalse (callback, "Callback called");
164 tn.Save (fname, ImageFormat.Png);