2 // Tests for System.Drawing.PointConverter.cs
5 // Ravindra (rkumar@novell.com)
7 // Copyright (C) 2004 Novell, Inc. http://www.novell.com
10 using NUnit.Framework;
13 using System.Collections;
14 using System.ComponentModel;
15 using System.Globalization;
17 namespace MonoTests.System.Drawing
20 public class PointConverterTest : Assertion
24 PointConverter ptconv;
29 public void TearDown () {}
34 pt = new Point (1, 2);
35 ptStr = pt.X + ", " + pt.Y;
37 ptneg = new Point (-2, -3);
38 ptnegStr = ptneg.X + ", " + ptneg.Y;
40 ptconv = (PointConverter) TypeDescriptor.GetConverter (pt);
44 public void TestCanConvertFrom ()
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)));
59 public void TestCanConvertTo ()
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)));
74 public void TestConvertFrom ()
76 AssertEquals ("CF#1", pt, (Point) ptconv.ConvertFrom (null,
77 CultureInfo.InvariantCulture,
79 AssertEquals ("CF#2", ptneg, (Point) ptconv.ConvertFrom (null,
80 CultureInfo.InvariantCulture,
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);
90 ptconv.ConvertFrom ("1");
91 Fail ("CF#3a: must throw ArgumentException");
92 } catch (Exception e) {
93 Assert ("CF#3a", e is ArgumentException);
97 ptconv.ConvertFrom (null, CultureInfo.InvariantCulture,
99 Fail ("CF#4: must throw ArgumentException");
100 } catch (Exception e) {
101 Assert ("CF#4", e is ArgumentException);
105 ptconv.ConvertFrom (null, CultureInfo.InvariantCulture,
107 Fail ("CF#5: must throw Exception");
112 ptconv.ConvertFrom (null, CultureInfo.InvariantCulture,
114 Fail ("CF#6: must throw NotSupportedException");
115 } catch (Exception e) {
116 Assert ("CF#6", e is NotSupportedException);
120 ptconv.ConvertFrom (null, CultureInfo.InvariantCulture,
122 Fail ("CF#7: must throw NotSupportedException");
123 } catch (Exception e) {
124 Assert ("CF#7", e is NotSupportedException);
128 ptconv.ConvertFrom (null, CultureInfo.InvariantCulture,
130 Fail ("CF#8: must throw NotSupportedException");
131 } catch (Exception e) {
132 Assert ("CF#8", e is NotSupportedException);
136 ptconv.ConvertFrom (null, CultureInfo.InvariantCulture,
138 Fail ("CF#9: must throw NotSupportedException");
139 } catch (Exception e) {
140 Assert ("CF#9", e is NotSupportedException);
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);
152 public void TestConvertTo ()
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)));
161 ptconv.ConvertTo (null, CultureInfo.InvariantCulture, pt,
163 Fail ("CT#3: must throw NotSupportedException");
164 } catch (Exception e) {
165 Assert ("CT#3", e is NotSupportedException);
169 ptconv.ConvertTo (null, CultureInfo.InvariantCulture, pt,
171 Fail ("CT#4: must throw NotSupportedException");
172 } catch (Exception e) {
173 Assert ("CT#4", e is NotSupportedException);
177 ptconv.ConvertTo (null, CultureInfo.InvariantCulture, pt,
179 Fail ("CT#5: must throw NotSupportedException");
180 } catch (Exception e) {
181 Assert ("CT#5", e is NotSupportedException);
185 ptconv.ConvertTo (null, CultureInfo.InvariantCulture, pt,
187 Fail ("CT#6: must throw NotSupportedException");
188 } catch (Exception e) {
189 Assert ("CT#6", e is NotSupportedException);
193 ptconv.ConvertTo (null, CultureInfo.InvariantCulture, pt,
195 Fail ("CT#7: must throw NotSupportedException");
196 } catch (Exception e) {
197 Assert ("CT#7", e is NotSupportedException);
202 public void TestGetCreateInstanceSupported ()
204 Assert ("GCIS#1", ptconv.GetCreateInstanceSupported ());
205 Assert ("GCIS#2", ptconv.GetCreateInstanceSupported (null));
209 public void TestCreateInstance ()
213 Hashtable ht = new Hashtable ();
214 ht.Add ("X", 1); ht.Add ("Y", 2);
216 ptInstance = (Point) ptconv.CreateInstance (ht);
217 AssertEquals ("CI#1", pt, ptInstance);
220 ht.Add ("X", -2); ht.Add ("Y", -3);
222 ptInstance = (Point) ptconv.CreateInstance (null, ht);
223 AssertEquals ("CI#2", ptneg, ptInstance);
225 // Property names are case-sensitive. It should throw
226 // NullRefExc if any of the property names does not match
228 ht.Add ("x", 2); ht.Add ("Y", 3);
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);
238 public void TestGetPropertiesSupported ()
240 Assert ("GPS#1", ptconv.GetPropertiesSupported ());
241 Assert ("GPS#2", ptconv.GetPropertiesSupported (null));
245 [Ignore ("This test fails because of bug #58435")]
246 public void TestGetProperties ()
249 PropertyDescriptorCollection propsColl;
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));
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));
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));
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);