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.Windows.Forms;
13 using System.Reflection;
14 using System.ComponentModel;
15 using NUnit.Framework;
16 using System.Threading;
17 using System.Collections;
20 namespace MonoTests.System.Windows.Forms
24 public class ImageListTest
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");
174 public void Bug409169 ()
176 ImageList imgList = new ImageList ();
177 ImageList.ImageCollection coll = imgList.Images;
178 Bitmap img1 = new Bitmap (10, 10);
181 const int dstOffset = 5;
182 object[] dst = new object[dstOffset + coll.Count];
183 ((IList)coll).CopyTo (dst, dstOffset);
185 Assert.IsNotNull (dst[dstOffset], "A1");
189 public class ImageListRecreateHandleEventClass
191 static bool eventhandled = false;
192 public static void RecreateHandle_EventHandler (object sender, EventArgs e)
198 public void RecreateHandleEvenTest ()
200 Form myform = new Form ();
201 myform.ShowInTaskbar = false;
202 Graphics mygraphics = null;
203 ImageList myimagelist = new ImageList ();
204 Image myImage = Image.FromFile("M.gif");
205 myimagelist.Images.Add (myImage);
206 myimagelist.ColorDepth = ColorDepth.Depth8Bit;
207 myimagelist.ImageSize = new Size (50,50);
208 myimagelist.RecreateHandle += new EventHandler (RecreateHandle_EventHandler);
209 mygraphics = Graphics.FromHwnd(myform.Handle);
210 myimagelist.Draw(mygraphics, new Point(5, 5), 0);
211 myimagelist.ImageSize = new Size (100,100);
212 Assert.AreEqual (true, eventhandled, "#1");
213 eventhandled = false;
214 myimagelist.Images.Add (myImage);
215 myimagelist.ColorDepth = ColorDepth.Depth32Bit;
216 Assert.AreEqual (true, eventhandled, "#2");