2 // Tests for System.Drawing.IconConverter.cs
5 // Sanjay Gupta (gsanjay@novell.com)
9 // Copyright (C) 2004 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.
32 using NUnit.Framework;
35 using System.Drawing.Imaging;
36 using System.Collections;
37 using System.ComponentModel;
38 using System.Globalization;
40 using System.Security.Permissions;
42 namespace MonoTests.System.Drawing
45 [SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
46 public class IconConverterTest
49 IconConverter icoConv;
50 IconConverter icoConvFrmTD;
55 public void TearDown () {}
60 icon = new Icon (TestBitmap.getInFile ("bitmaps/VisualPng.ico"));
61 iconStr = icon.ToString ();
63 icoConv = new IconConverter();
64 icoConvFrmTD = (IconConverter) TypeDescriptor.GetConverter (icon);
66 Stream stream = new FileStream (TestBitmap.getInFile ("bitmaps/VisualPng1.ico"), FileMode.Open);
67 int length = (int) stream.Length;
68 iconBytes = new byte [length];
71 if (stream.Read (iconBytes, 0, length) != length)
72 Assert.Fail ("SU#1: Read Failure");
73 } catch (Exception e) {
74 Assert.Fail ("SU#2 Exception thrown while reading. Exception is: "+e.Message);
85 [NUnit.Framework.Category ("NotWorking")]
87 public void TestCanConvertFrom ()
89 Assert.IsTrue (icoConv.CanConvertFrom (typeof (byte [])), "CCF#1");
90 Assert.IsTrue (icoConv.CanConvertFrom (null, typeof (byte [])), "CCF#1a");
91 Assert.IsTrue (icoConv.CanConvertFrom (null, iconBytes.GetType ()), "CCF#1b");
92 Assert.IsTrue (! icoConv.CanConvertFrom (null, typeof (String)), "CCF#2");
93 Assert.IsTrue (! icoConv.CanConvertFrom (null, typeof (Rectangle)), "CCF#3");
94 Assert.IsTrue (! icoConv.CanConvertFrom (null, typeof (Point)), "CCF#4");
95 Assert.IsTrue (! icoConv.CanConvertFrom (null, typeof (PointF)), "CCF#5");
96 Assert.IsTrue (! icoConv.CanConvertFrom (null, typeof (Size)), "CCF#6");
97 Assert.IsTrue (! icoConv.CanConvertFrom (null, typeof (SizeF)), "CCF#7");
98 Assert.IsTrue (! icoConv.CanConvertFrom (null, typeof (Object)), "CCF#8");
99 Assert.IsTrue (! icoConv.CanConvertFrom (null, typeof (int)), "CCF#9");
100 Assert.IsTrue (! icoConv.CanConvertFrom (null, typeof (Metafile)), "CCF#10");
102 Assert.IsTrue (icoConvFrmTD.CanConvertFrom (typeof (byte [])), "CCF#1A");
103 Assert.IsTrue (icoConvFrmTD.CanConvertFrom (null, typeof (byte [])), "CCF#1aA");
104 Assert.IsTrue (icoConvFrmTD.CanConvertFrom (null, iconBytes.GetType ()), "CCF#1bA");
105 Assert.IsTrue (! icoConvFrmTD.CanConvertFrom (null, typeof (String)), "CCF#2A");
106 Assert.IsTrue (! icoConvFrmTD.CanConvertFrom (null, typeof (Rectangle)), "CCF#3A");
107 Assert.IsTrue (! icoConvFrmTD.CanConvertFrom (null, typeof (Point)), "CCF#4A");
108 Assert.IsTrue (! icoConvFrmTD.CanConvertFrom (null, typeof (PointF)), "CCF#5A");
109 Assert.IsTrue (! icoConvFrmTD.CanConvertFrom (null, typeof (Size)), "CCF#6A");
110 Assert.IsTrue (! icoConvFrmTD.CanConvertFrom (null, typeof (SizeF)), "CCF#7A");
111 Assert.IsTrue (! icoConvFrmTD.CanConvertFrom (null, typeof (Object)), "CCF#8A");
112 Assert.IsTrue (! icoConvFrmTD.CanConvertFrom (null, typeof (int)), "CCF#9A");
113 Assert.IsTrue (! icoConvFrmTD.CanConvertFrom (null, typeof (Metafile)), "CCF#10A");
119 [NUnit.Framework.Category ("NotWorking")]
121 public void TestCanConvertTo ()
123 Assert.IsTrue (icoConv.CanConvertTo (typeof (String)), "CCT#1");
124 Assert.IsTrue (icoConv.CanConvertTo (null, typeof (String)), "CCT#1a");
125 Assert.IsTrue (icoConv.CanConvertTo (null, iconStr.GetType ()), "CCT#1b");
126 Assert.IsTrue (icoConv.CanConvertTo (typeof (byte [])), "CCT#2");
127 Assert.IsTrue (icoConv.CanConvertTo (null, typeof (byte [])), "CCT#2a");
128 Assert.IsTrue (icoConv.CanConvertTo (null, iconBytes.GetType ()), "CCT#2b");
129 Assert.IsTrue (! icoConv.CanConvertTo (null, typeof (Rectangle)), "CCT#3");
130 Assert.IsTrue (! icoConv.CanConvertTo (null, typeof (Point)), "CCT#4");
131 Assert.IsTrue (! icoConv.CanConvertTo (null, typeof (PointF)), "CCT#5");
132 Assert.IsTrue (! icoConv.CanConvertTo (null, typeof (Size)), "CCT#6");
133 Assert.IsTrue (! icoConv.CanConvertTo (null, typeof (SizeF)), "CCT#7");
134 Assert.IsTrue (! icoConv.CanConvertTo (null, typeof (Object)), "CCT#8");
135 Assert.IsTrue (! icoConv.CanConvertTo (null, typeof (int)), "CCT#9");
137 Assert.IsTrue (icoConvFrmTD.CanConvertTo (typeof (String)), "CCT#1A");
138 Assert.IsTrue (icoConvFrmTD.CanConvertTo (null, typeof (String)), "CCT#1aA");
139 Assert.IsTrue (icoConvFrmTD.CanConvertTo (null, iconStr.GetType ()), "CCT#1bA");
140 Assert.IsTrue (icoConvFrmTD.CanConvertTo (typeof (byte [])), "CCT#2A");
141 Assert.IsTrue (icoConvFrmTD.CanConvertTo (null, typeof (byte [])), "CCT#2aA");
142 Assert.IsTrue (icoConvFrmTD.CanConvertTo (null, iconBytes.GetType ()), "CCT#2bA");
143 Assert.IsTrue (! icoConvFrmTD.CanConvertTo (null, typeof (Rectangle)), "CCT#3A");
144 Assert.IsTrue (! icoConvFrmTD.CanConvertTo (null, typeof (Point)), "CCT#4A");
145 Assert.IsTrue (! icoConvFrmTD.CanConvertTo (null, typeof (PointF)), "CCT#5A");
146 Assert.IsTrue (! icoConvFrmTD.CanConvertTo (null, typeof (Size)), "CCT#6A");
147 Assert.IsTrue (! icoConvFrmTD.CanConvertTo (null, typeof (SizeF)), "CCT#7A");
148 Assert.IsTrue (! icoConvFrmTD.CanConvertTo (null, typeof (Object)), "CCT#8A");
149 Assert.IsTrue (! icoConvFrmTD.CanConvertTo (null, typeof (int)), "CCT#9A");
155 [NUnit.Framework.Category ("NotWorking")]
157 public void TestConvertFrom ()
159 Icon newIcon = (Icon) icoConv.ConvertFrom (null, CultureInfo.InvariantCulture, iconBytes);
161 Assert.AreEqual (icon.Height, newIcon.Height, "CF#1");
162 Assert.AreEqual (icon.Width, newIcon.Width, "CF#1a" );
165 icoConv.ConvertFrom ("System.Drawing.String");
166 Assert.Fail ("CF#2: must throw NotSupportedException");
167 } catch (Exception e) {
168 Assert.IsTrue (e is NotSupportedException, "CF#2");
172 icoConv.ConvertFrom (null, CultureInfo.InvariantCulture,
173 "System.Drawing.String");
174 Assert.Fail ("CF#2a: must throw NotSupportedException");
175 } catch (Exception e) {
176 Assert.IsTrue (e is NotSupportedException, "CF#2a");
180 icoConv.ConvertFrom (null, CultureInfo.InvariantCulture,
181 new Bitmap (20, 20));
182 Assert.Fail ("CF#3: must throw NotSupportedException");
183 } catch (Exception e) {
184 Assert.IsTrue (e is NotSupportedException, "CF#3");
188 icoConv.ConvertFrom (null, CultureInfo.InvariantCulture,
190 Assert.Fail ("CF#4: must throw NotSupportedException");
191 } catch (Exception e) {
192 Assert.IsTrue (e is NotSupportedException, "CF#4");
196 icoConv.ConvertFrom (null, CultureInfo.InvariantCulture,
198 Assert.Fail ("CF#5: must throw NotSupportedException");
199 } catch (Exception e) {
200 Assert.IsTrue (e is NotSupportedException, "CF#5");
204 icoConv.ConvertFrom (null, CultureInfo.InvariantCulture,
206 Assert.Fail ("CF#6: must throw NotSupportedException");
207 } catch (Exception e) {
208 Assert.IsTrue (e is NotSupportedException, "CF#6");
212 newIcon = (Icon) icoConvFrmTD.ConvertFrom (null, CultureInfo.InvariantCulture, iconBytes);
214 Assert.AreEqual (icon.Height, newIcon.Height, "CF#1A");
215 Assert.AreEqual (icon.Width, newIcon.Width, "CF#1Aa");
218 icoConvFrmTD.ConvertFrom ("System.Drawing.String");
219 Assert.Fail ("CF#2A: must throw NotSupportedException");
220 } catch (Exception e) {
221 Assert.IsTrue (e is NotSupportedException, "CF#2A");
225 icoConvFrmTD.ConvertFrom (null, CultureInfo.InvariantCulture,
226 "System.Drawing.String");
227 Assert.Fail ("CF#2aA: must throw NotSupportedException");
228 } catch (Exception e) {
229 Assert.IsTrue (e is NotSupportedException, "CF#2aA");
233 icoConvFrmTD.ConvertFrom (null, CultureInfo.InvariantCulture,
234 new Bitmap (20, 20));
235 Assert.Fail ("CF#3A: must throw NotSupportedException");
236 } catch (Exception e) {
237 Assert.IsTrue (e is NotSupportedException, "CF#3A");
241 icoConvFrmTD.ConvertFrom (null, CultureInfo.InvariantCulture,
243 Assert.Fail ("CF#4A: must throw NotSupportedException");
244 } catch (Exception e) {
245 Assert.IsTrue (e is NotSupportedException, "CF#4A");
249 icoConvFrmTD.ConvertFrom (null, CultureInfo.InvariantCulture,
251 Assert.Fail ("CF#5A: must throw NotSupportedException");
252 } catch (Exception e) {
253 Assert.IsTrue (e is NotSupportedException, "CF#5A");
257 icoConvFrmTD.ConvertFrom (null, CultureInfo.InvariantCulture,
259 Assert.Fail ("CF#6A: must throw NotSupportedException");
260 } catch (Exception e) {
261 Assert.IsTrue (e is NotSupportedException, "CF#6A");
268 [NUnit.Framework.Category ("NotWorking")]
270 public void TestConvertTo ()
272 Assert.AreEqual (iconStr, (String) icoConv.ConvertTo (null,
273 CultureInfo.InvariantCulture,
274 icon, typeof (String)), "CT#1");
276 Assert.AreEqual (iconStr, (String) icoConv.ConvertTo (icon,
277 typeof (String)), "CT#1a");
279 /*byte [] newIconBytes = (byte []) icoConv.ConvertTo (null, CultureInfo.InvariantCulture,
280 icon, iconBytes.GetType ());
282 Assert.AreEqual (iconBytes.Length, newIconBytes.Length, "CT#2");
284 newIconBytes = (byte []) icoConv.ConvertTo (icon, iconBytes.GetType ());
286 Assert.AreEqual (iconBytes.Length, newIconBytes.Length, "CT#2a");
290 icoConv.ConvertTo (null, CultureInfo.InvariantCulture,
291 icon, typeof (Rectangle));
292 Assert.Fail ("CT#3: must throw NotSupportedException");
293 } catch (Exception e) {
294 Assert.IsTrue ( e is NotSupportedException, "CT#3");
298 icoConv.ConvertTo (null, CultureInfo.InvariantCulture,
299 icon, icon.GetType ());
300 Assert.Fail ("CT#4: must throw NotSupportedException");
301 } catch (Exception e) {
302 Assert.IsTrue (e is NotSupportedException, "CT#4");
306 icoConv.ConvertTo (null, CultureInfo.InvariantCulture,
307 icon, typeof (Size));
308 Assert.Fail ("CT#5: must throw NotSupportedException");
309 } catch (Exception e) {
310 Assert.IsTrue (e is NotSupportedException, "CT#5");
314 icoConv.ConvertTo (null, CultureInfo.InvariantCulture,
315 icon, typeof (Bitmap));
316 Assert.Fail ("CT#6: must throw NotSupportedException");
317 } catch (Exception e) {
318 Assert.IsTrue ( e is NotSupportedException, "CT#6");
322 icoConv.ConvertTo (null, CultureInfo.InvariantCulture,
323 icon, typeof (Point));
324 Assert.Fail ("CT#7: must throw NotSupportedException");
325 } catch (Exception e) {
326 Assert.IsTrue (e is NotSupportedException, "CT#7");
330 icoConv.ConvertTo (null, CultureInfo.InvariantCulture,
331 icon, typeof (Metafile));
332 Assert.Fail ("CT#8: must throw NotSupportedException");
333 } catch (Exception e) {
334 Assert.IsTrue (e is NotSupportedException, "CT#8");
338 icoConv.ConvertTo (null, CultureInfo.InvariantCulture,
339 icon, typeof (Object));
340 Assert.Fail ("CT#9: must throw NotSupportedException");
341 } catch (Exception e) {
342 Assert.IsTrue (e is NotSupportedException, "CT#9");
346 icoConv.ConvertTo (null, CultureInfo.InvariantCulture,
348 Assert.Fail ("CT#10: must throw NotSupportedException");
349 } catch (Exception e) {
350 Assert.IsTrue (e is NotSupportedException, "CT#10");
354 Assert.AreEqual (iconStr, (String) icoConvFrmTD.ConvertTo (null,
355 CultureInfo.InvariantCulture,
356 icon, typeof (String)), "CT#1A");
358 Assert.AreEqual (iconStr, (String) icoConvFrmTD.ConvertTo (icon,
359 typeof (String)), "CT#1aA");
361 /*newIconBytes = (byte []) icoConvFrmTD.ConvertTo (null, CultureInfo.InvariantCulture,
362 icon, iconBytes.GetType ());
364 Assert.AreEqual (iconBytes.Length, newIconBytes.Length, "CT#2A");
366 newIconBytes = (byte []) icoConvFrmTD.ConvertTo (icon, iconBytes.GetType ());
368 Assert.AreEqual (iconBytes.Length, newIconBytes.Length, "CT#2aA");
371 icoConvFrmTD.ConvertTo (null, CultureInfo.InvariantCulture,
372 icon, typeof (Rectangle));
373 Assert.Fail ("CT#3A: must throw NotSupportedException");
374 } catch (Exception e) {
375 Assert.IsTrue (e is NotSupportedException, "CT#3A");
379 icoConvFrmTD.ConvertTo (null, CultureInfo.InvariantCulture,
380 icon, icon.GetType ());
381 Assert.Fail ("CT#4A: must throw NotSupportedException");
382 } catch (Exception e) {
383 Assert.IsTrue (e is NotSupportedException, "CT#4A");
387 icoConvFrmTD.ConvertTo (null, CultureInfo.InvariantCulture,
388 icon, typeof (Size));
389 Assert.Fail ("CT#5A: must throw NotSupportedException");
390 } catch (Exception e) {
391 Assert.IsTrue (e is NotSupportedException, "CT#5A");
395 icoConvFrmTD.ConvertTo (null, CultureInfo.InvariantCulture,
396 icon, typeof (Bitmap));
397 Assert.Fail ("CT#6A: must throw NotSupportedException");
398 } catch (Exception e) {
399 Assert.IsTrue (e is NotSupportedException, "CT#6A");
403 icoConvFrmTD.ConvertTo (null, CultureInfo.InvariantCulture,
404 icon, typeof (Point));
405 Assert.Fail ("CT#7A: must throw NotSupportedException");
406 } catch (Exception e) {
407 Assert.IsTrue (e is NotSupportedException, "CT#7A");
411 icoConvFrmTD.ConvertTo (null, CultureInfo.InvariantCulture,
412 icon, typeof (Metafile));
413 Assert.Fail ("CT#8A: must throw NotSupportedException");
414 } catch (Exception e) {
415 Assert.IsTrue (e is NotSupportedException, "CT#8A");
419 icoConvFrmTD.ConvertTo (null, CultureInfo.InvariantCulture,
420 icon, typeof (Object));
421 Assert.Fail ("CT#9A: must throw NotSupportedException");
422 } catch (Exception e) {
423 Assert.IsTrue (e is NotSupportedException, "CT#9A");
427 icoConvFrmTD.ConvertTo (null, CultureInfo.InvariantCulture,
429 Assert.Fail ("CT#10A: must throw NotSupportedException");
430 } catch (Exception e) {
431 Assert.IsTrue (e is NotSupportedException, "CT#10A");