ChangeLog: Updated ChangeLog.
[mono.git] / mcs / class / System.Drawing / Test / System.Drawing / TestPointConverter.cs
1 //
2 // Tests for System.Drawing.PointConverter.cs 
3 //
4 // Author:
5 //      Ravindra (rkumar@novell.com)
6 //
7 // Copyright (C) 2004 Novell, Inc. http://www.novell.com
8 //
9
10 using NUnit.Framework;
11 using System;
12 using System.Drawing;
13 using System.Collections;
14 using System.ComponentModel;
15 using System.Globalization;
16
17 namespace MonoTests.System.Drawing
18 {
19         [TestFixture]   
20         public class PointConverterTest : Assertion
21         {
22                 Point pt;
23                 Point ptneg;
24                 PointConverter ptconv;
25                 String ptStr;
26                 String ptnegStr;
27
28                 [TearDown]
29                 public void TearDown () {}
30
31                 [SetUp]
32                 public void SetUp ()            
33                 {
34                         pt = new Point (1, 2);
35                         ptStr = pt.X + ", " + pt.Y;
36
37                         ptneg = new Point (-2, -3);
38                         ptnegStr = ptneg.X + ", " + ptneg.Y;
39
40                         ptconv = (PointConverter) TypeDescriptor.GetConverter (pt);
41                 }
42
43                 [Test]
44                 public void TestCanConvertFrom ()
45                 {
46                         Assert ("CCF#1", ptconv.CanConvertFrom (typeof (String)));
47                         Assert ("CCF#1a", ptconv.CanConvertFrom (null, typeof (String)));
48                         Assert ("CCF#2", ! ptconv.CanConvertFrom (null, typeof (Rectangle)));
49                         Assert ("CCF#3", ! ptconv.CanConvertFrom (null, typeof (RectangleF)));
50                         Assert ("CCF#4", ! ptconv.CanConvertFrom (null, typeof (Point)));
51                         Assert ("CCF#5", ! ptconv.CanConvertFrom (null, typeof (PointF)));
52                         Assert ("CCF#6", ! ptconv.CanConvertFrom (null, typeof (Size)));
53                         Assert ("CCF#7", ! ptconv.CanConvertFrom (null, typeof (SizeF)));
54                         Assert ("CCF#8", ! ptconv.CanConvertFrom (null, typeof (Object)));
55                         Assert ("CCF#9", ! ptconv.CanConvertFrom (null, typeof (int)));
56                 }
57
58                 [Test]
59                 public void TestCanConvertTo ()
60                 {
61                         Assert ("CCT#1", ptconv.CanConvertTo (typeof (String)));
62                         Assert ("CCT#1a", ptconv.CanConvertTo (null, typeof (String)));
63                         Assert ("CCT#2", ! ptconv.CanConvertTo (null, typeof (Rectangle)));
64                         Assert ("CCT#3", ! ptconv.CanConvertTo (null, typeof (RectangleF)));
65                         Assert ("CCT#4", ! ptconv.CanConvertTo (null, typeof (Point)));
66                         Assert ("CCT#5", ! ptconv.CanConvertTo (null, typeof (PointF)));
67                         Assert ("CCT#6", ! ptconv.CanConvertTo (null, typeof (Size)));
68                         Assert ("CCT#7", ! ptconv.CanConvertTo (null, typeof (SizeF)));
69                         Assert ("CCT#8", ! ptconv.CanConvertTo (null, typeof (Object)));
70                         Assert ("CCT#9", ! ptconv.CanConvertTo (null, typeof (int)));
71                 }
72
73                 [Test]
74                 public void TestConvertFrom ()
75                 {
76                         AssertEquals ("CF#1", pt, (Point) ptconv.ConvertFrom (null,
77                                                                 CultureInfo.InvariantCulture,
78                                                                 "1, 2"));
79                         AssertEquals ("CF#2", ptneg, (Point) ptconv.ConvertFrom (null,
80                                                                 CultureInfo.InvariantCulture,
81                                                                 "-2, -3"));
82                         try {
83                                 ptconv.ConvertFrom (null, CultureInfo.InvariantCulture, "1");
84                                 Fail ("CF#3: must throw ArgumentException");
85                         } catch (Exception e) {
86                                 Assert ("CF#3", e is ArgumentException);
87                         }
88
89                         try {
90                                 ptconv.ConvertFrom ("1");
91                                 Fail ("CF#3a: must throw ArgumentException");
92                         } catch (Exception e) {
93                                 Assert ("CF#3a", e is ArgumentException);
94                         }
95
96                         try {
97                                 ptconv.ConvertFrom (null, CultureInfo.InvariantCulture,
98                                                     "1, 1, 1");
99                                 Fail ("CF#4: must throw ArgumentException");
100                         } catch (Exception e) {
101                                 Assert ("CF#4", e is ArgumentException);
102                         }
103
104                         try {
105                                 ptconv.ConvertFrom (null, CultureInfo.InvariantCulture,
106                                                     "*1, 1");
107                                 Fail ("CF#5: must throw Exception");
108                         } catch {
109                         }
110
111                         try {
112                                 ptconv.ConvertFrom (null, CultureInfo.InvariantCulture,
113                                                     new Point (1, 1));
114                                 Fail ("CF#6: must throw NotSupportedException");
115                         } catch (Exception e) {
116                                 Assert ("CF#6", e is NotSupportedException);
117                         }
118
119                         try {
120                                 ptconv.ConvertFrom (null, CultureInfo.InvariantCulture,
121                                                     new PointF (1, 1));
122                                 Fail ("CF#7: must throw NotSupportedException");
123                         } catch (Exception e) {
124                                 Assert ("CF#7", e is NotSupportedException);
125                         }
126
127                         try {
128                                 ptconv.ConvertFrom (null, CultureInfo.InvariantCulture,
129                                                     new Size (1, 1));
130                                 Fail ("CF#8: must throw NotSupportedException");
131                         } catch (Exception e) {
132                                 Assert ("CF#8", e is NotSupportedException);
133                         }
134
135                         try {
136                                 ptconv.ConvertFrom (null, CultureInfo.InvariantCulture,
137                                                     new SizeF (1, 1));
138                                 Fail ("CF#9: must throw NotSupportedException");
139                         } catch (Exception e) {
140                                 Assert ("CF#9", e is NotSupportedException);
141                         }
142
143                         try {
144                                 ptconv.ConvertFrom (null, CultureInfo.InvariantCulture, 0x10);
145                                 Fail ("CF#10: must throw NotSupportedException");
146                         } catch (Exception e) {
147                                 Assert ("CF#10", e is NotSupportedException);
148                         }
149                 }
150
151                 [Test]
152                 public void TestConvertTo ()
153                 {
154                         AssertEquals ("CT#1", ptStr, (String) ptconv.ConvertTo (null,
155                                                                 CultureInfo.InvariantCulture,
156                                                                 pt, typeof (String)));
157                         AssertEquals ("CT#2", ptnegStr, (String) ptconv.ConvertTo (null,
158                                                                 CultureInfo.InvariantCulture,
159                                                                 ptneg, typeof (String)));
160                         try {
161                                 ptconv.ConvertTo (null, CultureInfo.InvariantCulture, pt,
162                                                   typeof (Size));
163                                 Fail ("CT#3: must throw NotSupportedException");
164                         } catch (Exception e) {
165                                 Assert ("CT#3", e is NotSupportedException);
166                         }
167
168                         try {
169                                 ptconv.ConvertTo (null, CultureInfo.InvariantCulture, pt,
170                                                   typeof (SizeF));
171                                 Fail ("CT#4: must throw NotSupportedException");
172                         } catch (Exception e) {
173                                 Assert ("CT#4", e is NotSupportedException);
174                         }
175
176                         try {
177                                 ptconv.ConvertTo (null, CultureInfo.InvariantCulture, pt,
178                                                   typeof (Point));
179                                 Fail ("CT#5: must throw NotSupportedException");
180                         } catch (Exception e) {
181                                 Assert ("CT#5", e is NotSupportedException);
182                         }
183
184                         try {
185                                 ptconv.ConvertTo (null, CultureInfo.InvariantCulture, pt,
186                                                   typeof (PointF));
187                                 Fail ("CT#6: must throw NotSupportedException");
188                         } catch (Exception e) {
189                                 Assert ("CT#6", e is NotSupportedException);
190                         }
191
192                         try {
193                                 ptconv.ConvertTo (null, CultureInfo.InvariantCulture, pt,
194                                                   typeof (int));
195                                 Fail ("CT#7: must throw NotSupportedException");
196                         } catch (Exception e) {
197                                 Assert ("CT#7", e is NotSupportedException);
198                         }
199                 }
200
201                 [Test]
202                 public void TestGetCreateInstanceSupported ()
203                 {
204                         Assert ("GCIS#1", ptconv.GetCreateInstanceSupported ());
205                         Assert ("GCIS#2", ptconv.GetCreateInstanceSupported (null));
206                 }
207
208                 [Test]
209                 public void TestCreateInstance ()
210                 {
211                         Point ptInstance;
212
213                         Hashtable ht = new Hashtable ();
214                         ht.Add ("X", 1); ht.Add ("Y", 2);
215
216                         ptInstance = (Point) ptconv.CreateInstance (ht);
217                         AssertEquals ("CI#1", pt, ptInstance);
218
219                         ht.Clear ();
220                         ht.Add ("X", -2); ht.Add ("Y", -3);
221
222                         ptInstance = (Point) ptconv.CreateInstance (null, ht);
223                         AssertEquals ("CI#2", ptneg, ptInstance);
224
225                         // Property names are case-sensitive. It should throw 
226                         // NullRefExc if any of the property names does not match
227                         ht.Clear ();
228                         ht.Add ("x", 2); ht.Add ("Y", 3);
229                         try {
230                                 ptInstance = (Point) ptconv.CreateInstance (null, ht);
231                                 Fail ("CI#3: must throw NullReferenceException");
232                         } catch (Exception e) {
233                                 Assert ("CI#3", e is NullReferenceException);
234                         }
235                 }
236
237                 [Test]
238                 public void TestGetPropertiesSupported ()
239                 {
240                         Assert ("GPS#1", ptconv.GetPropertiesSupported ());
241                         Assert ("GPS#2", ptconv.GetPropertiesSupported (null));
242                 }
243
244                 [Test]
245                 [Ignore ("This test fails because of bug #58435")]
246                 public void TestGetProperties ()
247                 {
248                         Attribute [] attrs;
249                         PropertyDescriptorCollection propsColl;
250
251                         propsColl = ptconv.GetProperties (pt);
252                         AssertEquals ("GP1#1", 2, propsColl.Count);
253                         AssertEquals ("GP1#2", pt.X, propsColl ["X"].GetValue (pt));
254                         AssertEquals ("GP1#3", pt.Y, propsColl ["Y"].GetValue (pt));
255
256                         propsColl = ptconv.GetProperties (null, ptneg);
257                         AssertEquals ("GP2#1", 2, propsColl.Count);
258                         AssertEquals ("GP2#2", ptneg.X, propsColl ["X"].GetValue (ptneg));
259                         AssertEquals ("GP2#3", ptneg.Y, propsColl ["Y"].GetValue (ptneg));
260
261                         propsColl = ptconv.GetProperties (null, pt, null);
262                         AssertEquals ("GP3#1", 3, propsColl.Count);
263                         AssertEquals ("GP3#2", pt.X, propsColl ["X"].GetValue (pt));
264                         AssertEquals ("GP3#3", pt.Y, propsColl ["Y"].GetValue (pt));
265                         AssertEquals ("GP3#4", pt.IsEmpty, propsColl ["IsEmpty"].GetValue (pt));
266
267                         Type type = typeof (Point);
268                         attrs = Attribute.GetCustomAttributes (type, true);
269                         propsColl = ptconv.GetProperties (null, pt, attrs);
270                         AssertEquals ("GP3#5", 0, propsColl.Count);
271                 }
272         }
273 }