Merge pull request #1048 from DavidKarlas/cacheThreadsAndBulkFetch
[mono.git] / mono / tests / custom-attr-errors.cs
1 using System;
2 using System.Reflection;
3
4 public sealed class MyAttribute : Attribute
5 {
6         public Type Type { get; set; }
7         public MyAttribute (Type t) {
8                 Type = t;
9                 // throw new Exception ();
10         }
11
12         public override string ToString () {
13                 return "my " + Type;
14         }
15 }
16
17 public sealed class My2Attribute : Attribute
18 {
19         public object Obj { get; set; }
20         public My2Attribute (object t) {
21                 Obj = t;
22                 // throw new Exception ();
23         }
24
25         public override string ToString () {
26                 return "my2 " + Obj;
27         }
28 }
29
30 public sealed class My3Attribute : Attribute
31 {
32         public My3Attribute (object[] arr) {
33         }
34 }
35
36 public class MyException : Exception {}
37 public sealed class ExceptionOnCtor : Attribute
38 {
39         public ExceptionOnCtor () {
40                 throw new MyException ();
41         }
42 }
43
44 public class Bar {}
45
46 class Tests {
47
48         [My3 (new object[] { DisappearingEnum.V0 })]
49         public static int test_0_missing_enum_arg_alt3 () {
50                 try {
51                         MethodBase.GetCurrentMethod ().GetCustomAttributes (false);
52                         return 1;
53                 } catch (TypeLoadException) {
54                         return 0;
55                 }
56         }
57
58         [My2 (new DisappearingEnum[] { DisappearingEnum.V0 })]
59         public static int test_0_missing_enum_arg_alt2 () {
60                 try {
61                         MethodBase.GetCurrentMethod ().GetCustomAttributes (false);
62                         return 1;
63                 } catch (TypeLoadException) {
64                         return 0;
65                 }
66         }
67
68         [My2 (new object[] { DisappearingEnum.V0 })]
69         public static int test_0_missing_enum_arg_alt () {
70                 try {
71                         MethodBase.GetCurrentMethod ().GetCustomAttributes (false);
72                         return 1;
73                 } catch (TypeLoadException) {
74                         return 0;
75                 }
76         }
77
78         [My2 (DisappearingEnum.V0)]
79         public static int test_0_missing_enum_arg () {
80                 try {
81                         MethodBase.GetCurrentMethod ().GetCustomAttributes (false);
82                         return 1;
83                 } catch (TypeLoadException) {
84                         return 0;
85                 }
86         }
87
88         [My3 (new object[] { typeof (DisappearingType)})] 
89         public static int test_0_array_of_missing_type_alt2 () {
90                 try {
91                         MethodBase.GetCurrentMethod ().GetCustomAttributes (false);
92                         return 1;
93                 } catch (TypeLoadException) {
94                         return 0;
95                 }
96         }
97         [My2 (new Type[] { typeof (DisappearingType)})] 
98         public static int test_0_array_of_missing_type () {
99                 try {
100                         MethodBase.GetCurrentMethod ().GetCustomAttributes (false);
101                         return 1;
102                 } catch (TypeLoadException) {
103                         return 0;
104                 }
105         }
106
107
108
109         [My2 (typeof (DisappearingType))]
110         public static int test_0_missing_type_arg_alt () {
111                 try {
112                         MethodBase.GetCurrentMethod ().GetCustomAttributes (false);
113                         return 1;
114                 } catch (TypeLoadException) {
115                         return 0;
116                 }
117         }
118
119         [My (typeof (DisappearingType))]
120         public static int test_0_missing_type_arg () {
121                 try {
122                         MethodBase.GetCurrentMethod ().GetCustomAttributes (false);
123                         return 1;
124                 } catch (TypeLoadException) {
125                         return 0;
126                 }
127         }
128
129
130         [MissingCtor (1)]
131         public static int test_0_missing_ctor () {
132                 try {
133                         MethodBase.GetCurrentMethod ().GetCustomAttributes (false);
134                         return 1;
135                 } catch (MissingMethodException) {
136                         return 0;
137                 }
138         }
139
140         [BadAttr (Field = 1)]
141         public static int test_0_missing_field () {
142                 try {
143                         MethodBase.GetCurrentMethod ().GetCustomAttributes (false);
144                         return 1;
145                 } catch (CustomAttributeFormatException) {
146                         return 0;
147                 }
148         }
149
150         [BadAttr (Property = 1)]
151         public static int test_0_missing_property () {
152                 try {
153                         MethodBase.GetCurrentMethod ().GetCustomAttributes (false);
154                         return 1;
155                 } catch (CustomAttributeFormatException) {
156                         return 0;
157                 }
158         }
159
160         /* FIXME Verify the type of the cattr with the one on the field/property
161         [BadAttr (Field2 = 1)]
162         public static int test_0_bad_field () {
163                 try {
164                         MethodBase.GetCurrentMethod ().GetCustomAttributes (false);
165                         return 1;
166                 } catch (CustomAttributeFormatException) {
167                         return 0;
168                 }
169         }
170
171         [BadAttr (Property2 = 1)]
172         public static int test_0_bad_property () {
173                 try {
174                         MethodBase.GetCurrentMethod ().GetCustomAttributes (false);
175                         return 1;
176                 } catch (CustomAttributeFormatException) {
177                         return 0;
178                 }
179         }
180         */
181
182         [BadAttr (Property3 = 1)]
183         public static int test_0_bad_property_no_setter () {
184                 try {
185                         MethodBase.GetCurrentMethod ().GetCustomAttributes (false);
186                         return 1;
187                 } catch (CustomAttributeFormatException) {
188                         return 0;
189                 }
190         }
191
192         [ExceptionOnCtor]
193         public static int test_0_cattr_ctor_throws () {
194                 try {
195                         MethodBase.GetCurrentMethod ().GetCustomAttributes (false);
196                         return 1;
197                 } catch (MyException) {
198                         return 0;
199                 }
200         }
201
202
203     static int Main (String[] args) {
204             return TestDriver.RunTests (typeof (Tests), args);
205     }
206
207 }