Excluded tests which are not working in Grasshopper.
[mono.git] / mcs / class / System / Test / System.ComponentModel / TypeConverterTests.cs
1 //
2 // System.ComponentModel.TypeConverter test cases
3 //
4 // Authors:
5 //      Gert Driesen (drieseng@users.sourceforge.net)
6 //
7 // (c) 2005 Novell, Inc. (http://www.ximian.com)
8 //
9
10 using System;
11 using System.ComponentModel;
12 using System.ComponentModel.Design.Serialization;
13
14 using NUnit.Framework;
15
16 namespace MonoTests.System.ComponentModel
17 {
18         [TestFixture]
19         public class TypeConverterTests
20         {
21                 [Test]
22                 public void DefaultImplementation ()
23                 {
24                         BConverter converter = new BConverter ();
25                         C c = new C ();
26
27                         Assert.IsNull (converter.GetProperties (c), "#1");
28                         Assert.IsNull (converter.GetProperties (null, c), "#2");
29                         Assert.IsNull (converter.GetProperties (null, c, null), "#3");
30
31                         Assert.IsNull (converter.GetProperties (null), "#4");
32                         Assert.IsNull (converter.GetProperties (null, null), "#5");
33                         Assert.IsNull (converter.GetProperties (null, null, null), "#6");
34                         Assert.IsFalse (converter.GetCreateInstanceSupported (), "#7");
35                         Assert.IsFalse (converter.GetCreateInstanceSupported (null), "#8");
36                         Assert.IsFalse (converter.GetPropertiesSupported (), "#9");
37                         Assert.IsFalse (converter.GetPropertiesSupported (null), "#10");
38
39                         Assert.IsTrue (converter.CanConvertFrom (typeof (InstanceDescriptor)), "#11");
40                         Assert.IsTrue (converter.CanConvertFrom (null, typeof (InstanceDescriptor)), "#12");
41                         Assert.IsTrue (converter.CanConvertTo (typeof (string)), "#13");
42                         Assert.IsTrue (converter.CanConvertTo (null, typeof (string)), "#14");
43                 }
44
45                 [Test]
46 #if TARGET_JVM
47                 [Ignore ("TD BUG ID: 7229")]
48 #endif
49                 public void GetProperties ()
50                 {
51                         PropertyDescriptorCollection properties = null;
52                         C c = new C ();
53                         TypeConverter converter = TypeDescriptor.GetConverter (c);
54
55                         Assert.AreEqual (typeof (AConverter).FullName, converter.GetType ().FullName, "#1");
56
57                         properties = converter.GetProperties (c);
58                         Assert.AreEqual (1, properties.Count, "#2");
59                         Assert.AreEqual ("A", properties[0].Name, "#3");
60
61                         // ensure collection is read-only
62                         try {
63                                 properties.Clear ();
64                                 Assert.Fail ("#4");
65                         } catch (NotSupportedException) {
66                                 // read-only collection cannot be modified
67                         }
68
69                         properties = converter.GetProperties (null, c);
70                         Assert.AreEqual (1, properties.Count, "#5");
71                         Assert.AreEqual ("A", properties[0].Name, "#6");
72
73
74                         // ensure collection is read-only
75                         try {
76                                 properties.Clear ();
77                                 Assert.Fail ("#7");
78                         } catch (NotSupportedException) {
79                                 // read-only collection cannot be modified
80                         }
81
82                         properties = converter.GetProperties (null, c, null);
83                         Assert.AreEqual (2, properties.Count, "#8");
84
85                         // ensure collection is read-only
86                         try {
87                                 properties.Clear ();
88                                 Assert.Fail ("#9");
89                         } catch (NotSupportedException) {
90                                 // read-only collection cannot be modified
91                         }
92
93                         properties = converter.GetProperties (null);
94                         Assert.IsNull (properties, "#10");
95
96                         properties = converter.GetProperties (null, null);
97                         Assert.IsNull (properties, "#11");
98
99                         properties = converter.GetProperties (null, null, null);
100                         Assert.IsNull (properties, "#12");
101                 }
102         }
103
104         [TypeConverter (typeof (AConverter))]
105         public class C
106         {
107                 [Browsable (true)]
108                 public int A {
109                         get { return 0; }
110                 }
111
112                 [Browsable (false)]
113                 public int B {
114                         get { return 0; }
115                 }
116         }
117
118         public class AConverter : TypeConverter
119         {
120                 public override PropertyDescriptorCollection GetProperties (ITypeDescriptorContext context, object value, Attribute[] attributes)
121                 {
122                         if (value is C) {
123                                 return TypeDescriptor.GetProperties (value, attributes);
124                         }
125                         return base.GetProperties (context, value, attributes);
126                 }
127
128                 public override bool GetPropertiesSupported (ITypeDescriptorContext context)
129                 {
130                         return true;
131                 }
132         }
133
134         public class BConverter : TypeConverter
135         {
136         }
137 }