2 // Tests for System.Drawing.PointConverter.cs
5 // Ravindra (rkumar@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
.Collections
;
36 using System
.ComponentModel
;
37 using System
.Globalization
;
39 namespace MonoTests
.System
.Drawing
42 public class PointConverterTest
: Assertion
46 PointConverter ptconv
;
51 public void TearDown () {}
56 pt
= new Point (1, 2);
57 ptStr
= pt
.X
+ ", " + pt
.Y
;
59 ptneg
= new Point (-2, -3);
60 ptnegStr
= ptneg
.X
+ ", " + ptneg
.Y
;
62 ptconv
= (PointConverter
) TypeDescriptor
.GetConverter (pt
);
66 public void TestCanConvertFrom ()
68 Assert ("CCF#1", ptconv
.CanConvertFrom (typeof (String
)));
69 Assert ("CCF#1a", ptconv
.CanConvertFrom (null, typeof (String
)));
70 Assert ("CCF#2", ! ptconv
.CanConvertFrom (null, typeof (Rectangle
)));
71 Assert ("CCF#3", ! ptconv
.CanConvertFrom (null, typeof (RectangleF
)));
72 Assert ("CCF#4", ! ptconv
.CanConvertFrom (null, typeof (Point
)));
73 Assert ("CCF#5", ! ptconv
.CanConvertFrom (null, typeof (PointF
)));
74 Assert ("CCF#6", ! ptconv
.CanConvertFrom (null, typeof (Size
)));
75 Assert ("CCF#7", ! ptconv
.CanConvertFrom (null, typeof (SizeF
)));
76 Assert ("CCF#8", ! ptconv
.CanConvertFrom (null, typeof (Object
)));
77 Assert ("CCF#9", ! ptconv
.CanConvertFrom (null, typeof (int)));
81 public void TestCanConvertTo ()
83 Assert ("CCT#1", ptconv
.CanConvertTo (typeof (String
)));
84 Assert ("CCT#1a", ptconv
.CanConvertTo (null, typeof (String
)));
85 Assert ("CCT#2", ! ptconv
.CanConvertTo (null, typeof (Rectangle
)));
86 Assert ("CCT#3", ! ptconv
.CanConvertTo (null, typeof (RectangleF
)));
87 Assert ("CCT#4", ! ptconv
.CanConvertTo (null, typeof (Point
)));
88 Assert ("CCT#5", ! ptconv
.CanConvertTo (null, typeof (PointF
)));
89 Assert ("CCT#6", ! ptconv
.CanConvertTo (null, typeof (Size
)));
90 Assert ("CCT#7", ! ptconv
.CanConvertTo (null, typeof (SizeF
)));
91 Assert ("CCT#8", ! ptconv
.CanConvertTo (null, typeof (Object
)));
92 Assert ("CCT#9", ! ptconv
.CanConvertTo (null, typeof (int)));
96 public void TestConvertFrom ()
98 AssertEquals ("CF#1", pt
, (Point
) ptconv
.ConvertFrom (null,
99 CultureInfo
.InvariantCulture
,
101 AssertEquals ("CF#2", ptneg
, (Point
) ptconv
.ConvertFrom (null,
102 CultureInfo
.InvariantCulture
,
105 ptconv
.ConvertFrom (null, CultureInfo
.InvariantCulture
, "1");
106 Fail ("CF#3: must throw ArgumentException");
107 } catch (Exception e
) {
108 Assert ("CF#3", e
is ArgumentException
);
112 ptconv
.ConvertFrom ("1");
113 Fail ("CF#3a: must throw ArgumentException");
114 } catch (Exception e
) {
115 Assert ("CF#3a", e
is ArgumentException
);
119 ptconv
.ConvertFrom (null, CultureInfo
.InvariantCulture
,
121 Fail ("CF#4: must throw ArgumentException");
122 } catch (Exception e
) {
123 Assert ("CF#4", e
is ArgumentException
);
127 ptconv
.ConvertFrom (null, CultureInfo
.InvariantCulture
,
129 Fail ("CF#5: must throw Exception");
134 ptconv
.ConvertFrom (null, CultureInfo
.InvariantCulture
,
136 Fail ("CF#6: must throw NotSupportedException");
137 } catch (Exception e
) {
138 Assert ("CF#6", e
is NotSupportedException
);
142 ptconv
.ConvertFrom (null, CultureInfo
.InvariantCulture
,
144 Fail ("CF#7: must throw NotSupportedException");
145 } catch (Exception e
) {
146 Assert ("CF#7", e
is NotSupportedException
);
150 ptconv
.ConvertFrom (null, CultureInfo
.InvariantCulture
,
152 Fail ("CF#8: must throw NotSupportedException");
153 } catch (Exception e
) {
154 Assert ("CF#8", e
is NotSupportedException
);
158 ptconv
.ConvertFrom (null, CultureInfo
.InvariantCulture
,
160 Fail ("CF#9: must throw NotSupportedException");
161 } catch (Exception e
) {
162 Assert ("CF#9", e
is NotSupportedException
);
166 ptconv
.ConvertFrom (null, CultureInfo
.InvariantCulture
, 0x10);
167 Fail ("CF#10: must throw NotSupportedException");
168 } catch (Exception e
) {
169 Assert ("CF#10", e
is NotSupportedException
);
174 public void TestConvertTo ()
176 AssertEquals ("CT#1", ptStr
, (String
) ptconv
.ConvertTo (null,
177 CultureInfo
.InvariantCulture
,
178 pt
, typeof (String
)));
179 AssertEquals ("CT#2", ptnegStr
, (String
) ptconv
.ConvertTo (null,
180 CultureInfo
.InvariantCulture
,
181 ptneg
, typeof (String
)));
183 ptconv
.ConvertTo (null, CultureInfo
.InvariantCulture
, pt
,
185 Fail ("CT#3: must throw NotSupportedException");
186 } catch (Exception e
) {
187 Assert ("CT#3", e
is NotSupportedException
);
191 ptconv
.ConvertTo (null, CultureInfo
.InvariantCulture
, pt
,
193 Fail ("CT#4: must throw NotSupportedException");
194 } catch (Exception e
) {
195 Assert ("CT#4", e
is NotSupportedException
);
199 ptconv
.ConvertTo (null, CultureInfo
.InvariantCulture
, pt
,
201 Fail ("CT#5: must throw NotSupportedException");
202 } catch (Exception e
) {
203 Assert ("CT#5", e
is NotSupportedException
);
207 ptconv
.ConvertTo (null, CultureInfo
.InvariantCulture
, pt
,
209 Fail ("CT#6: must throw NotSupportedException");
210 } catch (Exception e
) {
211 Assert ("CT#6", e
is NotSupportedException
);
215 ptconv
.ConvertTo (null, CultureInfo
.InvariantCulture
, pt
,
217 Fail ("CT#7: must throw NotSupportedException");
218 } catch (Exception e
) {
219 Assert ("CT#7", e
is NotSupportedException
);
224 public void TestGetCreateInstanceSupported ()
226 Assert ("GCIS#1", ptconv
.GetCreateInstanceSupported ());
227 Assert ("GCIS#2", ptconv
.GetCreateInstanceSupported (null));
231 public void TestCreateInstance ()
235 Hashtable ht
= new Hashtable ();
236 ht
.Add ("X", 1); ht
.Add ("Y", 2);
238 ptInstance
= (Point
) ptconv
.CreateInstance (ht
);
239 AssertEquals ("CI#1", pt
, ptInstance
);
242 ht
.Add ("X", -2); ht
.Add ("Y", -3);
244 ptInstance
= (Point
) ptconv
.CreateInstance (null, ht
);
245 AssertEquals ("CI#2", ptneg
, ptInstance
);
247 // Property names are case-sensitive. It should throw
248 // NullRefExc if any of the property names does not match
250 ht
.Add ("x", 2); ht
.Add ("Y", 3);
252 ptInstance
= (Point
) ptconv
.CreateInstance (null, ht
);
253 Fail ("CI#3: must throw NullReferenceException");
254 } catch (Exception e
) {
255 Assert ("CI#3", e
is NullReferenceException
);
260 public void TestGetPropertiesSupported ()
262 Assert ("GPS#1", ptconv
.GetPropertiesSupported ());
263 Assert ("GPS#2", ptconv
.GetPropertiesSupported (null));
267 [Ignore ("This test fails because of bug #58435")]
268 public void TestGetProperties ()
271 PropertyDescriptorCollection propsColl
;
273 propsColl
= ptconv
.GetProperties (pt
);
274 AssertEquals ("GP1#1", 2, propsColl
.Count
);
275 AssertEquals ("GP1#2", pt
.X
, propsColl
["X"].GetValue (pt
));
276 AssertEquals ("GP1#3", pt
.Y
, propsColl
["Y"].GetValue (pt
));
278 propsColl
= ptconv
.GetProperties (null, ptneg
);
279 AssertEquals ("GP2#1", 2, propsColl
.Count
);
280 AssertEquals ("GP2#2", ptneg
.X
, propsColl
["X"].GetValue (ptneg
));
281 AssertEquals ("GP2#3", ptneg
.Y
, propsColl
["Y"].GetValue (ptneg
));
283 propsColl
= ptconv
.GetProperties (null, pt
, null);
284 AssertEquals ("GP3#1", 3, propsColl
.Count
);
285 AssertEquals ("GP3#2", pt
.X
, propsColl
["X"].GetValue (pt
));
286 AssertEquals ("GP3#3", pt
.Y
, propsColl
["Y"].GetValue (pt
));
287 AssertEquals ("GP3#4", pt
.IsEmpty
, propsColl
["IsEmpty"].GetValue (pt
));
289 Type type
= typeof (Point
);
290 attrs
= Attribute
.GetCustomAttributes (type
, true);
291 propsColl
= ptconv
.GetProperties (null, pt
, attrs
);
292 AssertEquals ("GP3#5", 0, propsColl
.Count
);