[runtime] Add regression tests for custom attribute loader errors.
authorRodrigo Kumpera <kumpera@gmail.com>
Fri, 23 May 2014 21:30:51 +0000 (17:30 -0400)
committerRodrigo Kumpera <kumpera@gmail.com>
Fri, 23 May 2014 21:34:31 +0000 (17:34 -0400)
mono/tests/Makefile.am
mono/tests/custom-attr-errors-lib.cs [new file with mode: 0644]
mono/tests/custom-attr-errors.cs [new file with mode: 0644]

index e09aebf45796ecac9f8cae526e5b24c28fae52db..79c6f9193240873966208cd91bf95f04661d2572 100644 (file)
@@ -1,6 +1,6 @@
 SUBDIRS = cas assemblyresolve gc-descriptors
 
-check-local: assemblyresolve/test/asm.dll testjit test-generic-sharing test-type-load test_platform test-process-exit test-messages rm-empty-logs
+check-local: assemblyresolve/test/asm.dll testjit test-generic-sharing test-type-load test-cattr-type-load test_platform test-process-exit test-messages rm-empty-logs
 check-full: test-sgen check-local
 check-parallel: compile-tests check-full
 
@@ -884,6 +884,15 @@ test-type-load: TestDriver.dll
        @echo "Testing load-exception.exe..."
        @$(RUNTIME) load-exceptions.exe > load-exceptions.exe.stdout 2> load-exceptions.exe.stderr
 
+EXTRA_DIST += custom-attr-errors.cs custom-attr-errors-lib.cs
+test-cattr-type-load: TestDriver.dll custom-attr-errors.cs custom-attr-errors-lib.cs
+       $(MCS) -D:WITH_MEMBERS /t:library $(srcdir)/custom-attr-errors-lib.cs
+       $(MCS) -r:TestDriver.dll -r:custom-attr-errors-lib.dll  $(srcdir)/custom-attr-errors.cs
+       $(MCS) /t:library $(srcdir)/custom-attr-errors-lib.cs
+       @echo "Testing custom-attribute-load-exceptions.exe..."
+       @$(RUNTIME) custom-attr-errors.exe > custom-attr-errors.exe.stdout 2> custom-attr-errors.exe.stderr
+
+
 EXTRA_DIST += debug-casts.cs
 # This depends on TLS, so its not ran by default
 debug-casts:
diff --git a/mono/tests/custom-attr-errors-lib.cs b/mono/tests/custom-attr-errors-lib.cs
new file mode 100644 (file)
index 0000000..986a3f6
--- /dev/null
@@ -0,0 +1,32 @@
+using System;
+
+#if WITH_MEMBERS
+public class DisappearingType { }
+
+public sealed class MissingAttribute : Attribute {}
+
+public enum DisappearingEnum {
+       V0
+}
+#endif
+
+
+public sealed class MissingCtorAttribute : Attribute {
+#if WITH_MEMBERS
+       public MissingCtorAttribute (int i) {}
+#endif
+}
+
+public sealed class BadAttrAttribute : Attribute {
+#if WITH_MEMBERS
+       public int Field, Field2;
+       public int Property { get; set; }
+       public int Property2 { get; set; }
+       public int Property3 { get; set; }
+#else
+       public string Field2;
+       public double Property2 { get; set; }
+       public int Property3 { get { return 0; } }
+#endif
+
+}
diff --git a/mono/tests/custom-attr-errors.cs b/mono/tests/custom-attr-errors.cs
new file mode 100644 (file)
index 0000000..83f3ff7
--- /dev/null
@@ -0,0 +1,207 @@
+using System;
+using System.Reflection;
+
+public sealed class MyAttribute : Attribute
+{
+       public Type Type { get; set; }
+       public MyAttribute (Type t) {
+               Type = t;
+               // throw new Exception ();
+       }
+
+       public override string ToString () {
+               return "my " + Type;
+       }
+}
+
+public sealed class My2Attribute : Attribute
+{
+       public object Obj { get; set; }
+       public My2Attribute (object t) {
+               Obj = t;
+               // throw new Exception ();
+       }
+
+       public override string ToString () {
+               return "my2 " + Obj;
+       }
+}
+
+public sealed class My3Attribute : Attribute
+{
+       public My3Attribute (object[] arr) {
+       }
+}
+
+public class MyException : Exception {}
+public sealed class ExceptionOnCtor : Attribute
+{
+       public ExceptionOnCtor () {
+               throw new MyException ();
+       }
+}
+
+public class Bar {}
+
+class Tests {
+
+       [My3 (new object[] { DisappearingEnum.V0 })]
+       public static int test_0_missing_enum_arg_alt3 () {
+               try {
+                       MethodBase.GetCurrentMethod ().GetCustomAttributes (false);
+                       return 1;
+               } catch (TypeLoadException) {
+                       return 0;
+               }
+       }
+
+       [My2 (new DisappearingEnum[] { DisappearingEnum.V0 })]
+       public static int test_0_missing_enum_arg_alt2 () {
+               try {
+                       MethodBase.GetCurrentMethod ().GetCustomAttributes (false);
+                       return 1;
+               } catch (TypeLoadException) {
+                       return 0;
+               }
+       }
+
+       [My2 (new object[] { DisappearingEnum.V0 })]
+       public static int test_0_missing_enum_arg_alt () {
+               try {
+                       MethodBase.GetCurrentMethod ().GetCustomAttributes (false);
+                       return 1;
+               } catch (TypeLoadException) {
+                       return 0;
+               }
+       }
+
+       [My2 (DisappearingEnum.V0)]
+       public static int test_0_missing_enum_arg () {
+               try {
+                       MethodBase.GetCurrentMethod ().GetCustomAttributes (false);
+                       return 1;
+               } catch (TypeLoadException) {
+                       return 0;
+               }
+       }
+
+       [My3 (new object[] { typeof (DisappearingType)})] 
+       public static int test_0_array_of_missing_type_alt2 () {
+               try {
+                       MethodBase.GetCurrentMethod ().GetCustomAttributes (false);
+                       return 1;
+               } catch (TypeLoadException) {
+                       return 0;
+               }
+       }
+       [My2 (new Type[] { typeof (DisappearingType)})] 
+       public static int test_0_array_of_missing_type () {
+               try {
+                       MethodBase.GetCurrentMethod ().GetCustomAttributes (false);
+                       return 1;
+               } catch (TypeLoadException) {
+                       return 0;
+               }
+       }
+
+
+
+       [My2 (typeof (DisappearingType))]
+       public static int test_0_missing_type_arg_alt () {
+               try {
+                       MethodBase.GetCurrentMethod ().GetCustomAttributes (false);
+                       return 1;
+               } catch (TypeLoadException) {
+                       return 0;
+               }
+       }
+
+       [My (typeof (DisappearingType))]
+       public static int test_0_missing_type_arg () {
+               try {
+                       MethodBase.GetCurrentMethod ().GetCustomAttributes (false);
+                       return 1;
+               } catch (TypeLoadException) {
+                       return 0;
+               }
+       }
+
+
+       [MissingCtor (1)]
+       public static int test_0_missing_ctor () {
+               try {
+                       MethodBase.GetCurrentMethod ().GetCustomAttributes (false);
+                       return 1;
+               } catch (MissingMethodException) {
+                       return 0;
+               }
+       }
+
+       [BadAttr (Field = 1)]
+       public static int test_0_missing_field () {
+               try {
+                       MethodBase.GetCurrentMethod ().GetCustomAttributes (false);
+                       return 1;
+               } catch (CustomAttributeFormatException) {
+                       return 0;
+               }
+       }
+
+       [BadAttr (Property = 1)]
+       public static int test_0_missing_property () {
+               try {
+                       MethodBase.GetCurrentMethod ().GetCustomAttributes (false);
+                       return 1;
+               } catch (CustomAttributeFormatException) {
+                       return 0;
+               }
+       }
+
+       /* FIXME Verify the type of the cattr with the one on the field/property
+       [BadAttr (Field2 = 1)]
+       public static int test_0_bad_field () {
+               try {
+                       MethodBase.GetCurrentMethod ().GetCustomAttributes (false);
+                       return 1;
+               } catch (CustomAttributeFormatException) {
+                       return 0;
+               }
+       }
+
+       [BadAttr (Property2 = 1)]
+       public static int test_0_bad_property () {
+               try {
+                       MethodBase.GetCurrentMethod ().GetCustomAttributes (false);
+                       return 1;
+               } catch (CustomAttributeFormatException) {
+                       return 0;
+               }
+       }
+       */
+
+       [BadAttr (Property3 = 1)]
+       public static int test_0_bad_property_no_setter () {
+               try {
+                       MethodBase.GetCurrentMethod ().GetCustomAttributes (false);
+                       return 1;
+               } catch (CustomAttributeFormatException) {
+                       return 0;
+               }
+       }
+
+       [ExceptionOnCtor]
+       public static int test_0_cattr_ctor_throws () {
+               try {
+                       MethodBase.GetCurrentMethod ().GetCustomAttributes (false);
+                       return 1;
+               } catch (MyException) {
+                       return 0;
+               }
+       }
+
+
+    static int Main (String[] args) {
+            return TestDriver.RunTests (typeof (Tests), args);
+    }
+
+}