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
;
19 namespace MonoTests
.System
.Windows
.Forms
23 public class ImageListTest
26 public void ImageListPropertyTest ()
28 ImageList myimagelist
= new ImageList ();
31 Assert
.AreEqual (ColorDepth
.Depth8Bit
, myimagelist
.ColorDepth
, "#C1");
32 myimagelist
.ColorDepth
= ColorDepth
.Depth32Bit
;
33 Assert
.AreEqual (ColorDepth
.Depth32Bit
, myimagelist
.ColorDepth
, "#C2");
34 Assert
.AreEqual (0, myimagelist
.Images
.Count
, "#C3");
36 Assert
.AreEqual (false, myimagelist
.HandleCreated
, "#H1");
37 myimagelist
.Handle
.ToInt32 ();
38 Assert
.AreEqual (true, myimagelist
.HandleCreated
, "#H2");
39 Assert
.AreEqual ("System.IntPtr", myimagelist
.Handle
.GetType ().FullName
, "#H3");
42 Image myImage
= Image
.FromFile("M.gif");
43 myimagelist
.Images
.Add (myImage
);
44 Assert
.AreEqual (1, myimagelist
.Images
.Count
, "#I1");
45 Assert
.AreEqual (16, myimagelist
.ImageSize
.Height
, "#I2");
46 Assert
.AreEqual (16, myimagelist
.ImageSize
.Width
, "#I3");
47 // [MonoTODO ("Add test for ImageStream")]
48 // [MonoTODO ("Test for Draw Method (visual test)")]
51 Assert
.AreEqual (Color
.Transparent
, myimagelist
.TransparentColor
, "#T1");
55 public void ImageListComponentModelTest ()
57 PropertyDescriptor colordepth_prop
= TypeDescriptor
.GetProperties (typeof (ImageList
))["ColorDepth"];
58 PropertyDescriptor imagesize_prop
= TypeDescriptor
.GetProperties (typeof (ImageList
))["ImageSize"];
59 PropertyDescriptor transparentcolor_prop
= TypeDescriptor
.GetProperties (typeof (ImageList
))["TransparentColor"];
61 // create a blank ImageList
62 ImageList il
= new ImageList ();
66 Assert
.IsTrue (colordepth_prop
.ShouldSerializeValue (il
), "1");
67 Assert
.IsTrue (colordepth_prop
.CanResetValue (il
), "2");
68 Assert
.IsTrue (imagesize_prop
.ShouldSerializeValue (il
), "3");
69 Assert
.IsTrue (imagesize_prop
.CanResetValue (il
), "4");
70 Assert
.IsTrue (transparentcolor_prop
.ShouldSerializeValue (il
), "5");
71 Assert
.IsTrue (transparentcolor_prop
.CanResetValue (il
), "6");
73 // test what happens when we set the transparent color to LightGray
74 il
.TransparentColor
= Color
.LightGray
;
75 Assert
.IsFalse (transparentcolor_prop
.ShouldSerializeValue (il
), "7");
76 Assert
.IsFalse (transparentcolor_prop
.CanResetValue (il
), "8");
78 // test what happens when we set the depth to something other than the default
79 il
.ColorDepth
= ColorDepth
.Depth16Bit
;
80 Assert
.IsTrue (colordepth_prop
.ShouldSerializeValue (il
), "9");
81 Assert
.IsTrue (colordepth_prop
.CanResetValue (il
), "10");
82 // same test for ImageSize
83 il
.ImageSize
= new Size (32, 32);
84 Assert
.IsTrue (imagesize_prop
.ShouldSerializeValue (il
), "11");
85 Assert
.IsTrue (imagesize_prop
.CanResetValue (il
), "12");
87 // create an ImageList containing an image
88 il
= new ImageList ();
89 il
.Images
.Add (Image
.FromFile ("M.gif"));
91 Assert
.IsFalse (colordepth_prop
.ShouldSerializeValue (il
), "13");
92 Assert
.IsFalse (colordepth_prop
.CanResetValue (il
), "14");
93 Assert
.IsFalse (imagesize_prop
.ShouldSerializeValue (il
), "15");
94 Assert
.IsFalse (imagesize_prop
.CanResetValue (il
), "16");
95 Assert
.IsTrue (transparentcolor_prop
.ShouldSerializeValue (il
), "17");
96 Assert
.IsTrue (transparentcolor_prop
.CanResetValue (il
), "18");
98 // test what happens when we set the transparent color to LightGray
99 il
.TransparentColor
= Color
.LightGray
;
100 Assert
.IsFalse (transparentcolor_prop
.ShouldSerializeValue (il
), "19");
101 Assert
.IsFalse (transparentcolor_prop
.CanResetValue (il
), "20");
103 // test what happens when we set the depth to something other than the default
104 il
.ColorDepth
= ColorDepth
.Depth16Bit
;
105 Assert
.IsFalse (colordepth_prop
.ShouldSerializeValue (il
), "21");
106 Assert
.IsFalse (colordepth_prop
.CanResetValue (il
), "22");
108 // same test for ImageSize
109 il
.ImageSize
= new Size (32, 32);
110 Assert
.IsFalse (imagesize_prop
.ShouldSerializeValue (il
), "23");
111 Assert
.IsFalse (imagesize_prop
.CanResetValue (il
), "24");
114 Assert
.IsFalse (colordepth_prop
.ShouldSerializeValue (il
), "1");
115 Assert
.IsFalse (colordepth_prop
.CanResetValue (il
), "2");
116 Assert
.IsFalse (imagesize_prop
.ShouldSerializeValue (il
), "3");
117 Assert
.IsFalse (imagesize_prop
.CanResetValue (il
), "4");
118 Assert
.IsTrue (transparentcolor_prop
.ShouldSerializeValue (il
), "5");
119 Assert
.IsFalse (transparentcolor_prop
.CanResetValue (il
), "6");
121 // test what happens when we set the transparent color to LightGray
122 il
.TransparentColor
= Color
.LightGray
;
123 Assert
.IsFalse (transparentcolor_prop
.ShouldSerializeValue (il
), "7");
124 Assert
.IsFalse (transparentcolor_prop
.CanResetValue (il
), "8");
126 // test what happens when we set the depth to something other than the default
127 il
.ColorDepth
= ColorDepth
.Depth16Bit
;
128 Assert
.IsTrue (colordepth_prop
.ShouldSerializeValue (il
), "9");
129 Assert
.IsTrue (colordepth_prop
.CanResetValue (il
), "10");
131 // same test for ImageSize
132 il
.ImageSize
= new Size (32, 32);
133 Assert
.IsTrue (imagesize_prop
.ShouldSerializeValue (il
), "11");
134 Assert
.IsFalse (imagesize_prop
.CanResetValue (il
), "12");
136 // create an ImageList containing an image
137 il
= new ImageList ();
138 il
.Images
.Add (Image
.FromFile ("M.gif"));
140 Assert
.IsFalse (colordepth_prop
.ShouldSerializeValue (il
), "13");
141 Assert
.IsFalse (colordepth_prop
.CanResetValue (il
), "14");
142 Assert
.IsFalse (imagesize_prop
.ShouldSerializeValue (il
), "15");
143 Assert
.IsFalse (imagesize_prop
.CanResetValue (il
), "16");
144 Assert
.IsTrue (transparentcolor_prop
.ShouldSerializeValue (il
), "17");
145 Assert
.IsFalse (transparentcolor_prop
.CanResetValue (il
), "18");
147 // test what happens when we set the transparent color to LightGray
148 il
.TransparentColor
= Color
.LightGray
;
149 Assert
.IsFalse (transparentcolor_prop
.ShouldSerializeValue (il
), "19");
150 Assert
.IsFalse (transparentcolor_prop
.CanResetValue (il
), "20");
152 // test what happens when we set the depth to something other than the default
153 il
.ColorDepth
= ColorDepth
.Depth16Bit
;
154 Assert
.IsTrue (colordepth_prop
.ShouldSerializeValue (il
), "21");
155 Assert
.IsTrue (colordepth_prop
.CanResetValue (il
), "22");
157 // same test for ImageSize
158 il
.ImageSize
= new Size (32, 32);
159 Assert
.IsTrue (imagesize_prop
.ShouldSerializeValue (il
), "23");
160 Assert
.IsFalse (imagesize_prop
.CanResetValue (il
), "24");
165 public void ToStringMethodTest ()
167 ImageList myimagelist
= new ImageList ();
168 Assert
.AreEqual ("System.Windows.Forms.ImageList Images.Count: 0, ImageSize: {Width=16, Height=16}",
169 myimagelist
.ToString (), "#T3");
173 public class ImageListRecreateHandleEventClass
175 static bool eventhandled
= false;
176 public static void RecreateHandle_EventHandler (object sender
, EventArgs e
)
182 public void RecreateHandleEvenTest ()
184 Form myform
= new Form ();
185 myform
.ShowInTaskbar
= false;
186 Graphics mygraphics
= null;
187 ImageList myimagelist
= new ImageList ();
188 Image myImage
= Image
.FromFile("M.gif");
189 myimagelist
.Images
.Add (myImage
);
190 myimagelist
.ColorDepth
= ColorDepth
.Depth8Bit
;
191 myimagelist
.ImageSize
= new Size (50,50);
192 myimagelist
.RecreateHandle
+= new EventHandler (RecreateHandle_EventHandler
);
193 mygraphics
= Graphics
.FromHwnd(myform
.Handle
);
194 myimagelist
.Draw(mygraphics
, new Point(5, 5), 0);
195 myimagelist
.ImageSize
= new Size (100,100);
196 Assert
.AreEqual (true, eventhandled
, "#1");
197 eventhandled
= false;
198 myimagelist
.Images
.Add (myImage
);
199 myimagelist
.ColorDepth
= ColorDepth
.Depth32Bit
;
200 Assert
.AreEqual (true, eventhandled
, "#2");