2 // ImageImageListTest.cs: Test cases for ImageImageList.
5 // Ritvik Mayank (mritvik@novell.com)
7 // (C) 2005 Novell, Inc. (http://www.novell.com)
11 using System.Collections;
12 using System.ComponentModel;
14 using System.Drawing.Imaging;
15 using System.Reflection;
16 using System.Threading;
17 using System.Windows.Forms;
19 using NUnit.Framework;
21 namespace MonoTests.System.Windows.Forms
24 public class ImageListTest : TestHelper
27 public void ImageListPropertyTest ()
29 ImageList myimagelist = new ImageList ();
32 Assert.AreEqual (ColorDepth.Depth8Bit, myimagelist.ColorDepth, "#C1");
33 myimagelist.ColorDepth = ColorDepth.Depth32Bit;
34 Assert.AreEqual (ColorDepth.Depth32Bit, myimagelist.ColorDepth, "#C2");
35 Assert.AreEqual (0, myimagelist.Images.Count, "#C3");
37 Assert.AreEqual (false, myimagelist.HandleCreated, "#H1");
38 myimagelist.Handle.ToInt32 ();
39 Assert.AreEqual (true, myimagelist.HandleCreated, "#H2");
40 Assert.AreEqual ("System.IntPtr", myimagelist.Handle.GetType ().FullName, "#H3");
43 Image myImage = Image.FromFile("M.gif");
44 myimagelist.Images.Add (myImage);
45 Assert.AreEqual (1, myimagelist.Images.Count, "#I1");
46 Assert.AreEqual (16, myimagelist.ImageSize.Height, "#I2");
47 Assert.AreEqual (16, myimagelist.ImageSize.Width, "#I3");
48 // [MonoTODO ("Add test for ImageStream")]
49 // [MonoTODO ("Test for Draw Method (visual test)")]
52 Assert.AreEqual (Color.Transparent, myimagelist.TransparentColor, "#T1");
56 public void ImageListComponentModelTest ()
58 PropertyDescriptor colordepth_prop = TypeDescriptor.GetProperties (typeof (ImageList))["ColorDepth"];
59 PropertyDescriptor imagesize_prop = TypeDescriptor.GetProperties (typeof (ImageList))["ImageSize"];
60 PropertyDescriptor transparentcolor_prop = TypeDescriptor.GetProperties (typeof (ImageList))["TransparentColor"];
62 // create a blank ImageList
63 ImageList il = new ImageList ();
67 Assert.IsTrue (colordepth_prop.ShouldSerializeValue (il), "1");
68 Assert.IsTrue (colordepth_prop.CanResetValue (il), "2");
69 Assert.IsTrue (imagesize_prop.ShouldSerializeValue (il), "3");
70 Assert.IsTrue (imagesize_prop.CanResetValue (il), "4");
71 Assert.IsTrue (transparentcolor_prop.ShouldSerializeValue (il), "5");
72 Assert.IsTrue (transparentcolor_prop.CanResetValue (il), "6");
74 // test what happens when we set the transparent color to LightGray
75 il.TransparentColor = Color.LightGray;
76 Assert.IsFalse (transparentcolor_prop.ShouldSerializeValue (il), "7");
77 Assert.IsFalse (transparentcolor_prop.CanResetValue (il), "8");
79 // test what happens when we set the depth to something other than the default
80 il.ColorDepth = ColorDepth.Depth16Bit;
81 Assert.IsTrue (colordepth_prop.ShouldSerializeValue (il), "9");
82 Assert.IsTrue (colordepth_prop.CanResetValue (il), "10");
83 // same test for ImageSize
84 il.ImageSize = new Size (32, 32);
85 Assert.IsTrue (imagesize_prop.ShouldSerializeValue (il), "11");
86 Assert.IsTrue (imagesize_prop.CanResetValue (il), "12");
88 // create an ImageList containing an image
89 il = new ImageList ();
90 il.Images.Add (Image.FromFile ("M.gif"));
92 Assert.IsFalse (colordepth_prop.ShouldSerializeValue (il), "13");
93 Assert.IsFalse (colordepth_prop.CanResetValue (il), "14");
94 Assert.IsFalse (imagesize_prop.ShouldSerializeValue (il), "15");
95 Assert.IsFalse (imagesize_prop.CanResetValue (il), "16");
96 Assert.IsTrue (transparentcolor_prop.ShouldSerializeValue (il), "17");
97 Assert.IsTrue (transparentcolor_prop.CanResetValue (il), "18");
99 // test what happens when we set the transparent color to LightGray
100 il.TransparentColor = Color.LightGray;
101 Assert.IsFalse (transparentcolor_prop.ShouldSerializeValue (il), "19");
102 Assert.IsFalse (transparentcolor_prop.CanResetValue (il), "20");
104 // test what happens when we set the depth to something other than the default
105 il.ColorDepth = ColorDepth.Depth16Bit;
106 Assert.IsFalse (colordepth_prop.ShouldSerializeValue (il), "21");
107 Assert.IsFalse (colordepth_prop.CanResetValue (il), "22");
109 // same test for ImageSize
110 il.ImageSize = new Size (32, 32);
111 Assert.IsFalse (imagesize_prop.ShouldSerializeValue (il), "23");
112 Assert.IsFalse (imagesize_prop.CanResetValue (il), "24");
115 Assert.IsFalse (colordepth_prop.ShouldSerializeValue (il), "1");
116 Assert.IsFalse (colordepth_prop.CanResetValue (il), "2");
117 Assert.IsFalse (imagesize_prop.ShouldSerializeValue (il), "3");
118 Assert.IsFalse (imagesize_prop.CanResetValue (il), "4");
119 Assert.IsTrue (transparentcolor_prop.ShouldSerializeValue (il), "5");
120 Assert.IsFalse (transparentcolor_prop.CanResetValue (il), "6");
122 // test what happens when we set the transparent color to LightGray
123 il.TransparentColor = Color.LightGray;
124 Assert.IsFalse (transparentcolor_prop.ShouldSerializeValue (il), "7");
125 Assert.IsFalse (transparentcolor_prop.CanResetValue (il), "8");
127 // test what happens when we set the depth to something other than the default
128 il.ColorDepth = ColorDepth.Depth16Bit;
129 Assert.IsTrue (colordepth_prop.ShouldSerializeValue (il), "9");
130 Assert.IsTrue (colordepth_prop.CanResetValue (il), "10");
132 // same test for ImageSize
133 il.ImageSize = new Size (32, 32);
134 Assert.IsTrue (imagesize_prop.ShouldSerializeValue (il), "11");
135 Assert.IsFalse (imagesize_prop.CanResetValue (il), "12");
137 // create an ImageList containing an image
138 il = new ImageList ();
139 il.Images.Add (Image.FromFile ("M.gif"));
141 Assert.IsFalse (colordepth_prop.ShouldSerializeValue (il), "13");
142 Assert.IsFalse (colordepth_prop.CanResetValue (il), "14");
143 Assert.IsFalse (imagesize_prop.ShouldSerializeValue (il), "15");
144 Assert.IsFalse (imagesize_prop.CanResetValue (il), "16");
145 Assert.IsTrue (transparentcolor_prop.ShouldSerializeValue (il), "17");
146 Assert.IsFalse (transparentcolor_prop.CanResetValue (il), "18");
148 // test what happens when we set the transparent color to LightGray
149 il.TransparentColor = Color.LightGray;
150 Assert.IsFalse (transparentcolor_prop.ShouldSerializeValue (il), "19");
151 Assert.IsFalse (transparentcolor_prop.CanResetValue (il), "20");
153 // test what happens when we set the depth to something other than the default
154 il.ColorDepth = ColorDepth.Depth16Bit;
155 Assert.IsTrue (colordepth_prop.ShouldSerializeValue (il), "21");
156 Assert.IsTrue (colordepth_prop.CanResetValue (il), "22");
158 // same test for ImageSize
159 il.ImageSize = new Size (32, 32);
160 Assert.IsTrue (imagesize_prop.ShouldSerializeValue (il), "23");
161 Assert.IsFalse (imagesize_prop.CanResetValue (il), "24");
166 public void ToStringMethodTest ()
168 ImageList myimagelist = new ImageList ();
169 Assert.AreEqual ("System.Windows.Forms.ImageList Images.Count: 0, ImageSize: {Width=16, Height=16}",
170 myimagelist.ToString (), "#T3");
173 [Test] // bug #409169
174 public void ICollection_CopyTo ()
176 ImageList imgList = new ImageList ();
177 ImageList.ImageCollection coll = imgList.Images;
179 Image gif = Image.FromFile ("M.gif");
181 Bitmap bmp = new Bitmap (10, 10);
184 const int dstOffset = 5;
185 object [] dst = new object [dstOffset + coll.Count + 1];
186 ((ICollection) coll).CopyTo (dst, dstOffset);
188 Assert.IsNull (dst [0], "#1");
189 Assert.IsNull (dst [1], "#2");
190 Assert.IsNull (dst [2], "#3");
191 Assert.IsNull (dst [3], "#4");
192 Assert.IsNull (dst [4], "#5");
193 Assert.IsNotNull (dst [5], "#6a");
194 Assert.IsFalse (object.ReferenceEquals (gif, dst [5]), "#6b");
195 Assert.AreEqual (typeof (Bitmap), dst [5].GetType (), "#6c");
196 Assert.IsNotNull (dst [6], "#7a");
197 Assert.IsFalse (object.ReferenceEquals (bmp, dst [6]), "#7b");
198 Assert.AreEqual (typeof (Bitmap), dst [6].GetType (), "#7c");
199 Assert.IsNull (dst [7], "#8");
201 ((Image) dst [5]).Dispose ();
202 ((Image) dst [6]).Dispose ();
204 coll [0].RotateFlip (RotateFlipType.Rotate90FlipY);
205 coll [1].RotateFlip (RotateFlipType.Rotate90FlipY);
209 public class ImageListRecreateHandleEventClass : TestHelper
211 static bool eventhandled = false;
212 public static void RecreateHandle_EventHandler (object sender, EventArgs e)
218 public void RecreateHandleEvenTest ()
220 Form myform = new Form ();
221 myform.ShowInTaskbar = false;
222 Graphics mygraphics = null;
223 ImageList myimagelist = new ImageList ();
224 Image myImage = Image.FromFile("M.gif");
225 myimagelist.Images.Add (myImage);
226 myimagelist.ColorDepth = ColorDepth.Depth8Bit;
227 myimagelist.ImageSize = new Size (50,50);
228 myimagelist.RecreateHandle += new EventHandler (RecreateHandle_EventHandler);
229 mygraphics = Graphics.FromHwnd(myform.Handle);
230 myimagelist.Draw(mygraphics, new Point(5, 5), 0);
231 myimagelist.ImageSize = new Size (100,100);
232 Assert.AreEqual (true, eventhandled, "#1");
233 eventhandled = false;
234 myimagelist.Images.Add (myImage);
235 myimagelist.ColorDepth = ColorDepth.Depth32Bit;
236 Assert.AreEqual (true, eventhandled, "#2");