(DISTFILES): Comment out a few missing files.
[mono-project.git] / mcs / class / System.Drawing / Test / System.Drawing / TestPointConverter.cs
blob7f10268aa4afc5fdc9f363f1ee4ff81a323784e6
1 //
2 // Tests for System.Drawing.PointConverter.cs
3 //
4 // Author:
5 // Ravindra (rkumar@novell.com)
6 //
8 //
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:
18 //
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 //
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;
33 using System;
34 using System.Drawing;
35 using System.Collections;
36 using System.ComponentModel;
37 using System.Globalization;
39 namespace MonoTests.System.Drawing
41 [TestFixture]
42 public class PointConverterTest : Assertion
44 Point pt;
45 Point ptneg;
46 PointConverter ptconv;
47 String ptStr;
48 String ptnegStr;
50 [TearDown]
51 public void TearDown () {}
53 [SetUp]
54 public void SetUp ()
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);
65 [Test]
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)));
80 [Test]
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)));
95 [Test]
96 public void TestConvertFrom ()
98 AssertEquals ("CF#1", pt, (Point) ptconv.ConvertFrom (null,
99 CultureInfo.InvariantCulture,
100 "1, 2"));
101 AssertEquals ("CF#2", ptneg, (Point) ptconv.ConvertFrom (null,
102 CultureInfo.InvariantCulture,
103 "-2, -3"));
104 try {
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);
111 try {
112 ptconv.ConvertFrom ("1");
113 Fail ("CF#3a: must throw ArgumentException");
114 } catch (Exception e) {
115 Assert ("CF#3a", e is ArgumentException);
118 try {
119 ptconv.ConvertFrom (null, CultureInfo.InvariantCulture,
120 "1, 1, 1");
121 Fail ("CF#4: must throw ArgumentException");
122 } catch (Exception e) {
123 Assert ("CF#4", e is ArgumentException);
126 try {
127 ptconv.ConvertFrom (null, CultureInfo.InvariantCulture,
128 "*1, 1");
129 Fail ("CF#5: must throw Exception");
130 } catch {
133 try {
134 ptconv.ConvertFrom (null, CultureInfo.InvariantCulture,
135 new Point (1, 1));
136 Fail ("CF#6: must throw NotSupportedException");
137 } catch (Exception e) {
138 Assert ("CF#6", e is NotSupportedException);
141 try {
142 ptconv.ConvertFrom (null, CultureInfo.InvariantCulture,
143 new PointF (1, 1));
144 Fail ("CF#7: must throw NotSupportedException");
145 } catch (Exception e) {
146 Assert ("CF#7", e is NotSupportedException);
149 try {
150 ptconv.ConvertFrom (null, CultureInfo.InvariantCulture,
151 new Size (1, 1));
152 Fail ("CF#8: must throw NotSupportedException");
153 } catch (Exception e) {
154 Assert ("CF#8", e is NotSupportedException);
157 try {
158 ptconv.ConvertFrom (null, CultureInfo.InvariantCulture,
159 new SizeF (1, 1));
160 Fail ("CF#9: must throw NotSupportedException");
161 } catch (Exception e) {
162 Assert ("CF#9", e is NotSupportedException);
165 try {
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);
173 [Test]
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)));
182 try {
183 ptconv.ConvertTo (null, CultureInfo.InvariantCulture, pt,
184 typeof (Size));
185 Fail ("CT#3: must throw NotSupportedException");
186 } catch (Exception e) {
187 Assert ("CT#3", e is NotSupportedException);
190 try {
191 ptconv.ConvertTo (null, CultureInfo.InvariantCulture, pt,
192 typeof (SizeF));
193 Fail ("CT#4: must throw NotSupportedException");
194 } catch (Exception e) {
195 Assert ("CT#4", e is NotSupportedException);
198 try {
199 ptconv.ConvertTo (null, CultureInfo.InvariantCulture, pt,
200 typeof (Point));
201 Fail ("CT#5: must throw NotSupportedException");
202 } catch (Exception e) {
203 Assert ("CT#5", e is NotSupportedException);
206 try {
207 ptconv.ConvertTo (null, CultureInfo.InvariantCulture, pt,
208 typeof (PointF));
209 Fail ("CT#6: must throw NotSupportedException");
210 } catch (Exception e) {
211 Assert ("CT#6", e is NotSupportedException);
214 try {
215 ptconv.ConvertTo (null, CultureInfo.InvariantCulture, pt,
216 typeof (int));
217 Fail ("CT#7: must throw NotSupportedException");
218 } catch (Exception e) {
219 Assert ("CT#7", e is NotSupportedException);
223 [Test]
224 public void TestGetCreateInstanceSupported ()
226 Assert ("GCIS#1", ptconv.GetCreateInstanceSupported ());
227 Assert ("GCIS#2", ptconv.GetCreateInstanceSupported (null));
230 [Test]
231 public void TestCreateInstance ()
233 Point ptInstance;
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);
241 ht.Clear ();
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
249 ht.Clear ();
250 ht.Add ("x", 2); ht.Add ("Y", 3);
251 try {
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);
259 [Test]
260 public void TestGetPropertiesSupported ()
262 Assert ("GPS#1", ptconv.GetPropertiesSupported ());
263 Assert ("GPS#2", ptconv.GetPropertiesSupported (null));
266 [Test]
267 [Ignore ("This test fails because of bug #58435")]
268 public void TestGetProperties ()
270 Attribute [] attrs;
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);