[System] Tweak socket test
[mono-project.git] / mono / tests / custom-attr-errors.cs
blob7d0c812357d15c0c999445db9baeca94b97cb31f
1 using System;
2 using System.Reflection;
4 // this for test_0_missing_attr_on_assembly
5 [assembly: MissingAttribute]
7 public sealed class MyAttribute : Attribute
9 public Type Type { get; set; }
10 public MyAttribute (Type t) {
11 Type = t;
12 // throw new Exception ();
15 public override string ToString () {
16 return "my " + Type;
20 public sealed class My2Attribute : Attribute
22 public object Obj { get; set; }
23 public My2Attribute (object t) {
24 Obj = t;
25 // throw new Exception ();
28 public override string ToString () {
29 return "my2 " + Obj;
33 public sealed class My3Attribute : Attribute
35 public My3Attribute (object[] arr) {
39 public class MyException : Exception {}
40 public sealed class ExceptionOnCtor : Attribute
42 public ExceptionOnCtor () {
43 throw new MyException ();
47 public class Bar {}
49 class Tests {
51 public static int test_0_missing_attr_on_assembly () {
52 try {
53 Assembly.GetExecutingAssembly().GetCustomAttributes (false);
54 return 1;
55 } catch (TypeLoadException exn) {
56 return 0;
60 [My3 (new object[] { DisappearingEnum.V0 })]
61 public static int test_0_missing_enum_arg_alt3 () {
62 try {
63 MethodBase.GetCurrentMethod ().GetCustomAttributes (false);
64 return 1;
65 } catch (TypeLoadException) {
66 return 0;
70 [My2 (new DisappearingEnum[] { DisappearingEnum.V0 })]
71 public static int test_0_missing_enum_arg_alt2 () {
72 try {
73 MethodBase.GetCurrentMethod ().GetCustomAttributes (false);
74 return 1;
75 } catch (TypeLoadException) {
76 return 0;
80 [My2 (new object[] { DisappearingEnum.V0 })]
81 public static int test_0_missing_enum_arg_alt () {
82 try {
83 MethodBase.GetCurrentMethod ().GetCustomAttributes (false);
84 return 1;
85 } catch (TypeLoadException) {
86 return 0;
90 [My2 (DisappearingEnum.V0)]
91 public static int test_0_missing_enum_arg () {
92 try {
93 MethodBase.GetCurrentMethod ().GetCustomAttributes (false);
94 return 1;
95 } catch (TypeLoadException) {
96 return 0;
100 [My3 (new object[] { typeof (DisappearingType)})]
101 public static int test_0_array_of_missing_type_alt2 () {
102 try {
103 MethodBase.GetCurrentMethod ().GetCustomAttributes (false);
104 return 1;
105 } catch (TypeLoadException) {
106 return 0;
109 [My2 (new Type[] { typeof (DisappearingType)})]
110 public static int test_0_array_of_missing_type () {
111 try {
112 MethodBase.GetCurrentMethod ().GetCustomAttributes (false);
113 return 1;
114 } catch (TypeLoadException) {
115 return 0;
121 [My2 (typeof (DisappearingType))]
122 public static int test_0_missing_type_arg_alt () {
123 try {
124 MethodBase.GetCurrentMethod ().GetCustomAttributes (false);
125 return 1;
126 } catch (TypeLoadException) {
127 return 0;
131 [My (typeof (DisappearingType))]
132 public static int test_0_missing_type_arg () {
133 try {
134 MethodBase.GetCurrentMethod ().GetCustomAttributes (false);
135 return 1;
136 } catch (TypeLoadException) {
137 return 0;
142 [MissingCtor (1)]
143 public static int test_0_missing_ctor () {
144 try {
145 MethodBase.GetCurrentMethod ().GetCustomAttributes (false);
146 return 1;
147 } catch (MissingMethodException) {
148 return 0;
152 [BadAttr (Field = 1)]
153 public static int test_0_missing_field () {
154 try {
155 MethodBase.GetCurrentMethod ().GetCustomAttributes (false);
156 return 1;
157 } catch (CustomAttributeFormatException) {
158 return 0;
162 [BadAttr (Property = 1)]
163 public static int test_0_missing_property () {
164 try {
165 MethodBase.GetCurrentMethod ().GetCustomAttributes (false);
166 return 1;
167 } catch (CustomAttributeFormatException) {
168 return 0;
172 /* FIXME Verify the type of the cattr with the one on the field/property
173 [BadAttr (Field2 = 1)]
174 public static int test_0_bad_field () {
175 try {
176 MethodBase.GetCurrentMethod ().GetCustomAttributes (false);
177 return 1;
178 } catch (CustomAttributeFormatException) {
179 return 0;
183 [BadAttr (Property2 = 1)]
184 public static int test_0_bad_property () {
185 try {
186 MethodBase.GetCurrentMethod ().GetCustomAttributes (false);
187 return 1;
188 } catch (CustomAttributeFormatException) {
189 return 0;
194 [BadAttr (Property3 = 1)]
195 public static int test_0_bad_property_no_setter () {
196 try {
197 MethodBase.GetCurrentMethod ().GetCustomAttributes (false);
198 return 1;
199 } catch (CustomAttributeFormatException) {
200 return 0;
204 [ExceptionOnCtor]
205 public static int test_0_cattr_ctor_throws () {
206 try {
207 MethodBase.GetCurrentMethod ().GetCustomAttributes (false);
208 return 1;
209 } catch (MyException) {
210 return 0;
215 static int Main (String[] args) {
216 return TestDriver.RunTests (typeof (Tests), args);