Selaa lähdekoodia

* MonoCustomAttrs.cs: In IsDefined, throw ArgumentNullException if
attributeType is null to avoid a SIGSEGV (and match MS). Only partial
fix for bug #82431 on 1.0 profile; it fully fixes the problem for the
1.0 profile, but more changes (in the runtime) are required for the
2.0 profile. Added a FIXME explaining the problem.
* TypeTest.cs: Improved test for GetCustomAttributes, and avoid
dependency on order of attributes. Split IsDefined test and improved
part for bug #82431.
* AssemblyTest.cs: Added IsDefined test with null value for
attributeType argument.
* ModuleTest.cs: Same. Remove use of deprecated Assertion class, code
formatting and fixed line endings.
* ParameterInfoTest.cs: Same. Remove use of deprecated Assertion class
and code formatting.
* MethodInfoTest.cs: Same.
* EventInfoTest.cs: Same. Code formatting.
* FieldInfoTest.cs: Same. Code formatting.
* PropertyInfoTest.cs: Same. Improved coverage of GetAccessors.
Improved tests for GetCustomAttributes. Code formatting.
* TypeBuilderTest.cs: Added IsDefined test with null value for
attributeType argument.

svn path=/trunk/mcs/; revision=84239

Gert Driesen 18 vuotta sitten
vanhempi
sitoutus
165e7a7b5b

+ 8 - 0
mcs/class/corlib/System/ChangeLog

@@ -1,3 +1,11 @@
+2007-08-16  Gert Driesen  <[email protected]>
+
+	* MonoCustomAttrs.cs: In IsDefined, throw ArgumentNullException if
+	attributeType is null to avoid a SIGSEGV (and match MS). Only partial
+	fix for bug #82431 on 1.0 profile; it fully fixes the problem for the
+	1.0 profile, but more changes (in the runtime) are required for the
+	2.0 profile. Added a FIXME explaining the problem.
+
 2007-08-15  Gert Driesen  <[email protected]>
 
 	* MonoCustomAttrs.cs: In IsDefined, only walk inheritance chain if

+ 22 - 3
mcs/class/corlib/System/MonoCustomAttrs.cs

@@ -258,6 +258,9 @@ namespace System
 
 		internal static bool IsDefined (ICustomAttributeProvider obj, Type attributeType, bool inherit)
 		{
+			if (attributeType == null)
+				throw new ArgumentNullException ("attributeType");
+
 			if (obj.GetType ().Assembly != typeof (int).Assembly)
 				// User types might overwrite GetCustomAttributes () but not 
 				// IsDefined ().
@@ -273,11 +276,27 @@ namespace System
 						return true;
 			}
 
-			AttributeUsageAttribute usage = RetrieveAttributeUsage (
-				attributeType);
+#if ONLY_1_1
+			if (inherit) {
+				AttributeUsageAttribute usage = RetrieveAttributeUsage (attributeType);
+				if (!usage.Inherited)
+					inherit = false;
+			}
+#endif
+
+			// FIXME (bug #82431):
+			// on 2.0 profile we should always walk the inheritance
+			// chain and base the behavior on the inheritance level:
+			//
+			// 0  : return true if "attributeType" is assignable from
+			// any of the custom attributes
+			//
+			// > 0: return true if "attributeType" is assignable from
+			// any of the custom attributes and AttributeUsageAttribute
+			// .Inherited of the assignable attribute is true
 
 			ICustomAttributeProvider btype;
-			if (usage.Inherited && inherit && ((btype = GetBase (obj)) != null))
+			if (inherit && ((btype = GetBase (obj)) != null))
 				return IsDefined (btype, attributeType, inherit);
 
 			return false;

+ 5 - 0
mcs/class/corlib/Test/System.Reflection.Emit/ChangeLog

@@ -1,3 +1,8 @@
+2007-08-16  Gert Driesen  <[email protected]>
+
+	* TypeBuilderTest.cs: Added IsDefined test with null value for
+	attributeType argument.
+
 2007-07-14  Gert Driesen  <[email protected]>
 
 	* TypeBuilderTest.cs: Modified enum tests to use already constructed

+ 19 - 0
mcs/class/corlib/Test/System.Reflection.Emit/TypeBuilderTest.cs

@@ -1546,6 +1546,25 @@ namespace MonoTests.System.Reflection.Emit
 			Assert.IsTrue (tb.IsDefined (typeof (ObsoleteAttribute), false));
 		}
 
+		[Test]
+		[Category ("NotDotNet")] // https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=293659
+		public void IsDefined_AttributeType_Null ()
+		{
+			TypeBuilder tb = module.DefineType (genTypeName ());
+			tb.CreateType ();
+
+			try {
+				tb.IsDefined ((Type) null, false);
+				Assert.Fail ("#1");
+			} catch (ArgumentNullException ex) {
+				Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
+				Assert.IsNull (ex.InnerException, "#3");
+				Assert.IsNotNull (ex.Message, "#4");
+				Assert.IsNotNull (ex.ParamName, "#5");
+				Assert.AreEqual ("attributeType", ex.ParamName, "#6");
+			}
+		}
+
 		[Test]
 		[ExpectedException (typeof (NotSupportedException))]
 		public void TestGetCustomAttributesIncomplete ()

+ 17 - 0
mcs/class/corlib/Test/System.Reflection/AssemblyTest.cs

@@ -196,6 +196,23 @@ namespace MonoTests.System.Reflection
 			Assert.IsTrue (fss.Length <= corlib_test.GetFiles (true).Length, "test.GetFiles (true)");
 		}
 
+		[Test]
+		public void IsDefined_AttributeType_Null ()
+		{
+			Assembly corlib = typeof (int).Assembly;
+
+			try {
+				corlib.IsDefined ((Type) null, false);
+				Assert.Fail ("#1");
+			} catch (ArgumentNullException ex) {
+				Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
+				Assert.IsNull (ex.InnerException, "#3");
+				Assert.IsNotNull (ex.Message, "#4");
+				Assert.IsNotNull (ex.ParamName, "#5");
+				Assert.AreEqual ("attributeType", ex.ParamName, "#6");
+			}
+		}
+
 		[Test] // bug #78517
 #if ONLY_1_1
 		[Category ("NotDotNet")] // MS.NET 1.x throws FileLoadException

+ 14 - 0
mcs/class/corlib/Test/System.Reflection/ChangeLog

@@ -1,3 +1,17 @@
+2007-08-16  Gert Driesen  <[email protected]>
+
+	* AssemblyTest.cs: Added IsDefined test with null value for 
+	attributeType argument.
+	* ModuleTest.cs: Same. Remove use of deprecated Assertion class, code
+	formatting and fixed line endings.
+	* ParameterInfoTest.cs: Same. Remove use of deprecated Assertion class
+	and code formatting.
+	* MethodInfoTest.cs: Same.
+	* EventInfoTest.cs: Same. Code formatting.
+	* FieldInfoTest.cs: Same. Code formatting.
+	* PropertyInfoTest.cs: Same. Improved coverage of GetAccessors.
+	Improved tests for GetCustomAttributes. Code formatting.
+
 2007-08-03  Zoltan Varga  <[email protected]>
 
 	* MethodInfoTest.cs: Add another test.

+ 43 - 25
mcs/class/corlib/Test/System.Reflection/EventInfoTest.cs

@@ -35,34 +35,52 @@ using System.Runtime.InteropServices;
 
 using NUnit.Framework;
 
-namespace MonoTests.System.Reflection {
-
-[TestFixture]
-public class EventInfoTest
+namespace MonoTests.System.Reflection
 {
-	[Test]
-	public void TestGetXXXMethod ()
+	[TestFixture]
+	public class EventInfoTest
 	{
-		EventInfo priv = typeof (PrivateEvent).GetEvents (BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static) [0];
-		EventInfo pub = typeof (PublicEvent).GetEvents (BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static) [0];
+		[Test]
+		public void IsDefined_AttributeType_Null ()
+		{
+			EventInfo priv = typeof (PrivateEvent).GetEvents (
+				BindingFlags.Public | BindingFlags.NonPublic |
+				BindingFlags.Static) [0];
+
+			try {
+				priv.IsDefined ((Type) null, false);
+				Assert.Fail ("#1");
+			} catch (ArgumentNullException ex) {
+				Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
+				Assert.IsNull (ex.InnerException, "#3");
+				Assert.IsNotNull (ex.Message, "#4");
+				Assert.IsNotNull (ex.ParamName, "#5");
+				Assert.AreEqual ("attributeType", ex.ParamName, "#6");
+			}
+		}
+
+		[Test]
+		public void TestGetXXXMethod ()
+		{
+			EventInfo priv = typeof (PrivateEvent).GetEvents (BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static) [0];
+			Assert.IsNull (priv.GetAddMethod (), "#A1");
+			Assert.IsNull (priv.GetRaiseMethod (), "#A2");
+			Assert.IsNull (priv.GetRemoveMethod (), "#A3");
+
+			EventInfo pub = typeof (PublicEvent).GetEvents (BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static) [0];
+			Assert.IsNotNull (pub.GetAddMethod (), "#B1");
+			Assert.IsNull (pub.GetRaiseMethod (), "#B2");
+			Assert.IsNotNull (pub.GetRemoveMethod (), "#B3");
+		}
 		
-		Assert.IsNull    (priv.GetAddMethod ());
-		Assert.IsNull    (priv.GetRaiseMethod ());
-		Assert.IsNull    (priv.GetRemoveMethod ());
+		public class PrivateEvent
+		{
+			private static event EventHandler x;
+		}
 		
-		Assert.IsNotNull (pub.GetAddMethod ());
-		Assert.IsNull    (pub.GetRaiseMethod ());
-		Assert.IsNotNull (pub.GetRemoveMethod ());
+		public class PublicEvent
+		{
+			public static event EventHandler x;
+		}
 	}
-	
-	public class PrivateEvent
-	{
-		private static event EventHandler x;
-	}
-	
-	public class PublicEvent
-	{
-		public static event EventHandler x;
-	}
-}
 }

+ 136 - 117
mcs/class/corlib/Test/System.Reflection/FieldInfoTest.cs

@@ -38,157 +38,176 @@ using NUnit.Framework;
 
 namespace MonoTests.System.Reflection
 {
+	[StructLayout(LayoutKind.Explicit, Pack = 4, Size = 64)]
+	public class Class1
+	{
+		[FieldOffset (32)]
+		public int i;
+	}
 
-[StructLayout(LayoutKind.Explicit, Pack = 4, Size = 64)]
-public class Class1 {
-	[FieldOffset (32)]
-	public int i;
-}
-
-[StructLayout(LayoutKind.Sequential)]
-public class Class2 {
-	[MarshalAsAttribute(UnmanagedType.Bool)]
-	public int f0;
+	[StructLayout(LayoutKind.Sequential)]
+	public class Class2
+	{
+		[MarshalAsAttribute(UnmanagedType.Bool)]
+		public int f0;
 
-	[MarshalAs(UnmanagedType.LPArray, ArraySubType=UnmanagedType.LPStr)]
-	public string[] f1;
+		[MarshalAs(UnmanagedType.LPArray, ArraySubType=UnmanagedType.LPStr)]
+		public string[] f1;
 
-	[MarshalAs(UnmanagedType.ByValTStr, SizeConst=100)]
-	public string f2;
+		[MarshalAs(UnmanagedType.ByValTStr, SizeConst=100)]
+		public string f2;
 
-	// This doesn't work under mono
-	//[MarshalAs( UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof (Marshal1), MarshalCookie = "5")]
-	//public object f3;
-}
+		// This doesn't work under mono
+		//[MarshalAs( UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof (Marshal1), MarshalCookie = "5")]
+		//public object f3;
+	}
 
-[TestFixture]
-public class FieldInfoTest : Assertion
-{
-	[NonSerialized]
-	public int i;
+	[TestFixture]
+	public class FieldInfoTest
+	{
+		[NonSerialized]
+		public int i;
+
+		[Test]
+		public void IsDefined_AttributeType_Null ()
+		{
+			Type type = typeof (FieldInfoTest);
+			FieldInfo field = type.GetField ("i");
+
+			try {
+				field.IsDefined ((Type) null, false);
+				Assert.Fail ("#1");
+			} catch (ArgumentNullException ex) {
+				Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
+				Assert.IsNull (ex.InnerException, "#3");
+				Assert.IsNotNull (ex.Message, "#4");
+				Assert.IsNotNull (ex.ParamName, "#5");
+				Assert.AreEqual ("attributeType", ex.ParamName, "#6");
+			}
+		}
 
 #if NET_2_0
-	[Test]
-	public void PseudoCustomAttributes () {
-		Type t = typeof (FieldInfoTest);
+		[Test]
+		public void PseudoCustomAttributes ()
+		{
+			Type t = typeof (FieldInfoTest);
 
-		AssertEquals (1, t.GetField ("i").GetCustomAttributes (typeof (NonSerializedAttribute), true).Length);
+			Assert.AreEqual (1, t.GetField ("i").GetCustomAttributes (typeof (NonSerializedAttribute), true).Length);
 
-		FieldOffsetAttribute field_attr = (FieldOffsetAttribute)(typeof (Class1).GetField ("i").GetCustomAttributes (true) [0]);
-		AssertEquals (32, field_attr.Value);
+			FieldOffsetAttribute field_attr = (FieldOffsetAttribute)(typeof (Class1).GetField ("i").GetCustomAttributes (true) [0]);
+			Assert.AreEqual (32, field_attr.Value);
 
-		MarshalAsAttribute attr;
+			MarshalAsAttribute attr;
 
-		attr = (MarshalAsAttribute)typeof (Class2).GetField ("f0").GetCustomAttributes (true) [0];
-		AssertEquals (UnmanagedType.Bool, attr.Value);
+			attr = (MarshalAsAttribute)typeof (Class2).GetField ("f0").GetCustomAttributes (true) [0];
+			Assert.AreEqual (UnmanagedType.Bool, attr.Value);
 
-		attr = (MarshalAsAttribute)typeof (Class2).GetField ("f1").GetCustomAttributes (true) [0];
-		AssertEquals (UnmanagedType.LPArray, attr.Value);
-		AssertEquals (UnmanagedType.LPStr, attr.ArraySubType);
+			attr = (MarshalAsAttribute)typeof (Class2).GetField ("f1").GetCustomAttributes (true) [0];
+			Assert.AreEqual (UnmanagedType.LPArray, attr.Value);
+			Assert.AreEqual (UnmanagedType.LPStr, attr.ArraySubType);
 
-		attr = (MarshalAsAttribute)typeof (Class2).GetField ("f2").GetCustomAttributes (true) [0];
-		AssertEquals (UnmanagedType.ByValTStr, attr.Value);
-		AssertEquals (100, attr.SizeConst);
+			attr = (MarshalAsAttribute)typeof (Class2).GetField ("f2").GetCustomAttributes (true) [0];
+			Assert.AreEqual (UnmanagedType.ByValTStr, attr.Value);
+			Assert.AreEqual (100, attr.SizeConst);
 
-		/*
-		attr = (MarshalAsAttribute)typeof (Class2).GetField ("f3").GetCustomAttributes (true) [0];
-		AssertEquals (UnmanagedType.CustomMarshaler, attr.Value);
-		AssertEquals ("5", attr.MarshalCookie);
-		AssertEquals (typeof (Marshal1), Type.GetType (attr.MarshalType));
-		*/
-	}
+			/*
+			attr = (MarshalAsAttribute)typeof (Class2).GetField ("f3").GetCustomAttributes (true) [0];
+			Assert.AreEqual (UnmanagedType.CustomMarshaler, attr.Value);
+			Assert.AreEqual ("5", attr.MarshalCookie);
+			Assert.AreEqual (typeof (Marshal1), Type.GetType (attr.MarshalType));
+			*/
+		}
 
 #if !TARGET_JVM // ReflectionOnlyLoad not supported for TARGET_JVM
-	[Test]
-	[ExpectedException (typeof (InvalidOperationException))]
-	public void GetValueOnRefOnlyAssembly ()
-	{
-		Assembly assembly = Assembly.ReflectionOnlyLoad (typeof (FieldInfoTest).Assembly.FullName);
-		Type t = assembly.GetType (typeof (RefOnlyFieldClass).FullName);
-		FieldInfo f = t.GetField ("RefOnlyField", BindingFlags.Static | BindingFlags.NonPublic);
-
-		f.GetValue (null);
-	}
+		[Test]
+		[ExpectedException (typeof (InvalidOperationException))]
+		public void GetValueOnRefOnlyAssembly ()
+		{
+			Assembly assembly = Assembly.ReflectionOnlyLoad (typeof (FieldInfoTest).Assembly.FullName);
+			Type t = assembly.GetType (typeof (RefOnlyFieldClass).FullName);
+			FieldInfo f = t.GetField ("RefOnlyField", BindingFlags.Static | BindingFlags.NonPublic);
+			f.GetValue (null);
+		}
 	
-	[Test]
-	[ExpectedException (typeof (InvalidOperationException))]
-	public void SetValueOnRefOnlyAssembly ()
-	{
-		Assembly assembly = Assembly.ReflectionOnlyLoad (typeof (FieldInfoTest).Assembly.FullName);
-		Type t = assembly.GetType (typeof (RefOnlyFieldClass).FullName);
-		FieldInfo f = t.GetField ("RefOnlyField", BindingFlags.Static | BindingFlags.NonPublic);
-
-		f.SetValue (null, 8);
-	}
+		[Test]
+		[ExpectedException (typeof (InvalidOperationException))]
+		public void SetValueOnRefOnlyAssembly ()
+		{
+			Assembly assembly = Assembly.ReflectionOnlyLoad (typeof (FieldInfoTest).Assembly.FullName);
+			Type t = assembly.GetType (typeof (RefOnlyFieldClass).FullName);
+			FieldInfo f = t.GetField ("RefOnlyField", BindingFlags.Static | BindingFlags.NonPublic);
+			f.SetValue (null, 8);
+		}
 #endif // TARGET_JVM
 
-	const int literal = 42;
+		const int literal = 42;
 
-	[Test]
-	[ExpectedException (typeof (FieldAccessException))]
-	public void SetValueOnLiteralField ()
-	{
-		FieldInfo f = typeof (FieldInfoTest).GetField ("literal", BindingFlags.Static | BindingFlags.NonPublic);
-		f.SetValue (null, 0);
-	}
+		[Test]
+		[ExpectedException (typeof (FieldAccessException))]
+		public void SetValueOnLiteralField ()
+		{
+			FieldInfo f = typeof (FieldInfoTest).GetField ("literal", BindingFlags.Static | BindingFlags.NonPublic);
+			f.SetValue (null, 0);
+		}
 
-	public int? nullable_field;
+		public int? nullable_field;
 
-	public static int? static_nullable_field;
+		public static int? static_nullable_field;
 
-	[Test]
-	public void NullableTests ()
-	{
-		FieldInfoTest t = new FieldInfoTest ();
+		[Test]
+		public void NullableTests ()
+		{
+			FieldInfoTest t = new FieldInfoTest ();
 
-		FieldInfo fi = typeof (FieldInfoTest).GetField ("nullable_field");
+			FieldInfo fi = typeof (FieldInfoTest).GetField ("nullable_field");
 
-		fi.SetValue (t, 101);
-		AssertEquals (101, fi.GetValue (t));
-		fi.SetValue (t, null);
-		AssertEquals (null, fi.GetValue (t));
+			fi.SetValue (t, 101);
+			Assert.AreEqual (101, fi.GetValue (t));
+			fi.SetValue (t, null);
+			Assert.AreEqual (null, fi.GetValue (t));
 
-		FieldInfo fi2 = typeof (FieldInfoTest).GetField ("static_nullable_field");
+			FieldInfo fi2 = typeof (FieldInfoTest).GetField ("static_nullable_field");
 
-		fi2.SetValue (t, 101);
-		AssertEquals (101, fi2.GetValue (t));
-		fi2.SetValue (t, null);
-		AssertEquals (null, fi2.GetValue (t));
-	}
+			fi2.SetValue (t, 101);
+			Assert.AreEqual (101, fi2.GetValue (t));
+			fi2.SetValue (t, null);
+			Assert.AreEqual (null, fi2.GetValue (t));
+		}
 	
 #if !TARGET_JVM // TypeBuilder not supported for TARGET_JVM
-	[Test]
-	public void NonPublicTests ()
-	{		
-		Assembly assembly = Assembly.ReflectionOnlyLoad (typeof (FieldInfoTest).Assembly.FullName);
+		[Test]
+		public void NonPublicTests ()
+		{
+			Assembly assembly = Assembly.ReflectionOnlyLoad (typeof (FieldInfoTest).Assembly.FullName);
 		
-		Type t = assembly.GetType (typeof (NonPublicFieldClass).FullName);
-
-		// try to get non-public field
-		FieldInfo fi = t.GetField ("protectedField");
-		AssertNull (fi);
-		// get it for real
-		fi = t.GetField ("protectedField", BindingFlags.NonPublic | BindingFlags.Instance);
-		AssertNotNull (fi);		
-		// get via typebuilder		
-		FieldInfo f = TypeBuilder.GetField (t, fi);
-		AssertNotNull (f);	
-	}
+			Type t = assembly.GetType (typeof (NonPublicFieldClass).FullName);
+
+			// try to get non-public field
+			FieldInfo fi = t.GetField ("protectedField");
+			Assert.IsNull (fi);
+			// get it for real
+			fi = t.GetField ("protectedField", BindingFlags.NonPublic | BindingFlags.Instance);
+			Assert.IsNotNull (fi);
+			// get via typebuilder
+			FieldInfo f = TypeBuilder.GetField (t, fi);
+			Assert.IsNotNull (f);
+		}
 #endif // TARGET_JVM
 	
 #endif
-}		
+	}
+
 #if NET_2_0
-// Helper classes
-class RefOnlyFieldClass 
-{
-	// Helper property
-	static int RefOnlyField;
-}
+	// Helper classes
+	class RefOnlyFieldClass 
+	{
+		// Helper property
+		static int RefOnlyField;
+	}
 
-class NonPublicFieldClass
-{
-	protected int protectedField;
-}
+	class NonPublicFieldClass
+	{
+		protected int protectedField;
+	}
 #endif
 }

+ 17 - 0
mcs/class/corlib/Test/System.Reflection/MethodInfoTest.cs

@@ -57,6 +57,23 @@ namespace MonoTests.System.Reflection
 		{
 		}
 
+		[Test]
+		public void IsDefined_AttributeType_Null ()
+		{
+			MethodInfo mi = typeof (MethodInfoTest).GetMethod ("foo");
+
+			try {
+				mi.IsDefined ((Type) null, false);
+				Assert.Fail ("#1");
+			} catch (ArgumentNullException ex) {
+				Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
+				Assert.IsNull (ex.InnerException, "#3");
+				Assert.IsNotNull (ex.Message, "#4");
+				Assert.IsNotNull (ex.ParamName, "#5");
+				Assert.AreEqual ("attributeType", ex.ParamName, "#6");
+			}
+		}
+
 #if NET_2_0
 		[Test]
 		public void PseudoCustomAttributes ()

+ 335 - 304
mcs/class/corlib/Test/System.Reflection/ModuleTest.cs

@@ -1,311 +1,342 @@
-//
-// ModuleTest - NUnit Test Cases for the Module class
-//
-// Zoltan Varga ([email protected])
-//
-// (C) Ximian, Inc.  http://www.ximian.com
+//
+// ModuleTest - NUnit Test Cases for the Module class
+//
+// Zoltan Varga ([email protected])
+//
+// (C) Ximian, Inc.  http://www.ximian.com
 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
-//
-
-using System;
-using System.Threading;
-using System.Reflection;
-using System.Reflection.Emit;
+//
+
+using System;
+using System.Threading;
+using System.Reflection;
+using System.Reflection.Emit;
 using System.Runtime.Serialization;
-using System.IO;
-using System.Collections;
-
-using NUnit.Framework;
-
-namespace MonoTests.System.Reflection
-{
-
-[TestFixture]
-public class ModuleTest : Assertion
-{	
-	static string TempFolder = Path.Combine (Path.GetTempPath (), "MonoTests.System.Reflection.ModuleTest");
-
-	[SetUp]
-	public void SetUp () {
-		while (Directory.Exists (TempFolder))
-			TempFolder = Path.Combine (TempFolder, "2");
-		Directory.CreateDirectory (TempFolder);
-	}		
-
-	[TearDown]
-	public void TearDown () {
-		try {
-			// This throws an exception under MS.NET, since the directory contains loaded
-			// assemblies.
-			Directory.Delete (TempFolder, true);
-		}
-		catch (Exception) {
-		}
-	}
-
-	// Some of these tests overlap with the tests for ModuleBuilder
-
-	[Test]
-	[Category("NotDotNet")] // path length can cause suprious failures
-	public void TestGlobalData () {
-
-		string name = "moduletest-assembly";
-		string fileName = name + ".dll";
-
-		AssemblyName assemblyName = new AssemblyName();
-		assemblyName.Name = name;
-
-		AssemblyBuilder ab
-			= Thread.GetDomain().DefineDynamicAssembly(
-				assemblyName, AssemblyBuilderAccess.RunAndSave, TempFolder);
-
-		string resfile = Path.Combine (TempFolder, "res");
-		using (StreamWriter sw = new StreamWriter (resfile)) {
-			sw.WriteLine ("FOO");
-		}
-
-		ab.AddResourceFile ("res", "res");
-
-		ModuleBuilder mb = ab.DefineDynamicModule(fileName, fileName);
-
-		mb.DefineInitializedData ("DATA", new byte [100], FieldAttributes.Public);
-		mb.DefineInitializedData ("DATA2", new byte [100], FieldAttributes.Public);
-		mb.DefineInitializedData ("DATA3", new byte [99], FieldAttributes.Public);
-		mb.DefineUninitializedData ("DATA4", 101, FieldAttributes.Public);
-		mb.DefineInitializedData ("DATA_PRIVATE", new byte [100], 0);
-		mb.CreateGlobalFunctions ();
-
-		ab.Save (fileName);
-
-		Assembly assembly = Assembly.LoadFrom (Path.Combine (TempFolder, fileName));
-
-		Module module = assembly.GetLoadedModules ()[0];
-
-		string[] expectedFieldNames = new string [] {
-			"DATA", "DATA2", "DATA3", "DATA4"
-		};
-		ArrayList fieldNames = new ArrayList ();
-		foreach (FieldInfo fi in module.GetFields ()) {
-			fieldNames.Add (fi.Name);
-		}
-		AssertArrayEqualsSorted (expectedFieldNames, fieldNames.ToArray (typeof (string)));
-
-		try {
-			module.GetField (null);
-			Fail ();
-		}
-		catch (ArgumentNullException) {
-		}
-
-		try {
-			module.GetField (null, 0);
-			Fail ();
-		}
-		catch (ArgumentNullException) {
-		}
-
-		AssertEquals (module.GetField ("DATA") != null, true);
-		AssertEquals (module.GetField ("DATA2") != null, true);
-		AssertEquals (module.GetField ("DATA3") != null, true);
-		AssertEquals (module.GetField ("DATA4") != null, true);
-		AssertEquals (module.GetField ("DATA_PRIVATE"), null);
-		AssertEquals (module.GetField ("DATA_PRIVATE", BindingFlags.NonPublic | BindingFlags.Static) != null, true);
-
-		// Check that these methods work correctly on resource modules
-		Module m2 = assembly.GetModule ("res");
-		AssertEquals (m2 != null, true);
-		AssertEquals (m2.GetFields ().Length, 0);
-		AssertEquals (m2.GetField ("DATA"), null);
-		AssertEquals (m2.GetField ("DATA", BindingFlags.Public), null);
-	}
-
-#if NET_2_0
-
-	[Test]
-	public void ResolveType () {
-		Type t = typeof (ModuleTest);
-		Module module = t.Module;
-
-		AssertEquals (t, module.ResolveType (t.MetadataToken));
-
-		/* We currently throw ArgumentException for this one */
-		try {
-			module.ResolveType (1234);
-			Fail ();
-		}
-		catch (ArgumentException) {
-		}
-
-		try {
-			module.ResolveType (t.GetMethod ("ResolveType").MetadataToken);
-			Fail ();
-		}
-		catch (ArgumentException) {
-		}
-
-		try {
-			module.ResolveType (t.MetadataToken + 10000);
-			Fail ();
-		}
-		catch (ArgumentOutOfRangeException) {
-		}
-	}
-
-	[Test]
-	public void ResolveMethod () {
-		Type t = typeof (ModuleTest);
-		Module module = t.Module;
-
-		AssertEquals (t.GetMethod ("ResolveMethod"), module.ResolveMethod (t.GetMethod ("ResolveMethod").MetadataToken));
-
-		try {
-			module.ResolveMethod (1234);
-			Fail ();
-		}
-		catch (ArgumentException) {
-		}
-
-		try {
-			module.ResolveMethod (t.MetadataToken);
-			Fail ();
-		}
-		catch (ArgumentException) {
-		}
-
-		try {
-			module.ResolveMethod (t.GetMethod ("ResolveMethod").MetadataToken + 10000);
-			Fail ();
-		}
-		catch (ArgumentOutOfRangeException) {
-		}
-	}
-
-	public int aField;
-
-	[Test]
-	public void ResolveField () {
-		Type t = typeof (ModuleTest);
-		Module module = t.Module;
-
-		AssertEquals (t.GetField ("aField"), module.ResolveField (t.GetField ("aField").MetadataToken));
-
-		try {
-			module.ResolveField (1234);
-			Fail ();
-		}
-		catch (ArgumentException) {
-		}
-
-		try {
-			module.ResolveField (t.MetadataToken);
-			Fail ();
-		}
-		catch (ArgumentException) {
-		}
-
-		try {
-			module.ResolveField (t.GetField ("aField").MetadataToken + 10000);
-			Fail ();
-		}
-		catch (ArgumentOutOfRangeException) {
-		}
-	}
-
-	[Ignore ("it breaks nunit-console.exe execution under .NET 2.0")]
-	[Test]
-	public void ResolveString () {
-		Type t = typeof (ModuleTest);
-		Module module = t.Module;
-
-		for (int i = 1; i < 10000; ++i) {
-			try {
-				module.ResolveString (0x70000000 + i);
-			}
-			catch (Exception) {
-			}
-		}
-
-		try {
-			module.ResolveString (1234);
-			Fail ();
-		}
-		catch (ArgumentException) {
-		}
-
-		try {
-			module.ResolveString (t.MetadataToken);
-			Fail ();
-		}
-		catch (ArgumentException) {
-		}
-
-		try {
-			module.ResolveString (0x70000000 | 10000);
-			Fail ();
-		}
-		catch (ArgumentOutOfRangeException) {
-		}
-	}
-
-
-	[Test]
-	public void ResolveMember () {
-		Type t = typeof (ModuleTest);
-		Module module = t.Module;
-
-		AssertEquals (t, module.ResolveMember (t.MetadataToken));
-		AssertEquals (t.GetField ("aField"), module.ResolveMember (t.GetField ("aField").MetadataToken));
-		AssertEquals (t.GetMethod ("ResolveMember"), module.ResolveMember (t.GetMethod ("ResolveMember").MetadataToken));
-
-		try {
-			module.ResolveMember (module.MetadataToken);
-		}
-		catch (ArgumentException) {
-		}
-	}
-#endif
-
-	[Test]
-	public void FindTypes () {
-		Module m = typeof (ModuleTest).Module;
-
-		Type[] t;
-
-		t = m.FindTypes (Module.FilterTypeName, "FindTypesTest*");
-		AssertEquals (2, t.Length);
-		AssertEquals ("FindTypesTestFirstClass", t [0].Name);
-		AssertEquals ("FindTypesTestSecondClass", t [1].Name);
-		t = m.FindTypes (Module.FilterTypeNameIgnoreCase, "findtypestest*");
-		AssertEquals (2, t.Length);
-		AssertEquals ("FindTypesTestFirstClass", t [0].Name);
-		AssertEquals ("FindTypesTestSecondClass", t [1].Name);
-	}
+using System.IO;
+using System.Collections;
+
+using NUnit.Framework;
+
+namespace MonoTests.System.Reflection
+{
+[TestFixture]
+public class ModuleTest
+{
+	static string TempFolder = Path.Combine (Path.GetTempPath (), "MonoTests.System.Reflection.ModuleTest");
+
+	[SetUp]
+	public void SetUp ()
+	{
+		while (Directory.Exists (TempFolder))
+			TempFolder = Path.Combine (TempFolder, "2");
+		Directory.CreateDirectory (TempFolder);
+	}
+
+	[TearDown]
+	public void TearDown ()
+	{
+		try {
+			// This throws an exception under MS.NET, since the directory contains loaded
+			// assemblies.
+			Directory.Delete (TempFolder, true);
+		} catch (Exception) {
+		}
+	}
+
+	[Test]
+	public void IsDefined_AttributeType_Null ()
+	{
+		Type t = typeof (ModuleTest);
+		Module module = t.Module;
+
+		try {
+			module.IsDefined ((Type) null, false);
+			Assert.Fail ("#1");
+		} catch (ArgumentNullException ex) {
+			Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
+			Assert.IsNull (ex.InnerException, "#3");
+			Assert.IsNotNull (ex.Message, "#4");
+			Assert.IsNotNull (ex.ParamName, "#5");
+			Assert.AreEqual ("attributeType", ex.ParamName, "#6");
+		}
+	}
+
+	[Test]
+	public void GetField_Name_Null ()
+	{
+		Type t = typeof (ModuleTest);
+		Module module = t.Module;
+
+		try {
+			module.GetField (null);
+			Assert.Fail ("#A1");
+		} catch (ArgumentNullException ex) {
+			Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
+			Assert.IsNull (ex.InnerException, "#A3");
+			Assert.IsNotNull (ex.Message, "#A4");
+			// bug #82459
+#if ONLY_1_1
+			Assert.IsNotNull (ex.ParamName, "#A5");
+			Assert.AreEqual ("name", ex.ParamName, "#A6");
+#endif
+		}
+
+		try {
+			module.GetField (null, 0);
+			Assert.Fail ("#B1");
+		} catch (ArgumentNullException ex) {
+			Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#B2");
+			Assert.IsNull (ex.InnerException, "#B3");
+			Assert.IsNotNull (ex.Message, "#B4");
+			// bug #82459
+#if ONLY_1_1
+			Assert.IsNotNull (ex.ParamName, "#B5");
+			Assert.AreEqual ("name", ex.ParamName, "#B6");
+#endif
+		}
+	}
+
+	// Some of these tests overlap with the tests for ModuleBuilder
+
+	[Test]
+	[Category("NotDotNet")] // path length can cause suprious failures
+	public void TestGlobalData () {
+
+		string name = "moduletest-assembly";
+		string fileName = name + ".dll";
+
+		AssemblyName assemblyName = new AssemblyName();
+		assemblyName.Name = name;
+
+		AssemblyBuilder ab
+			= Thread.GetDomain().DefineDynamicAssembly(
+				assemblyName, AssemblyBuilderAccess.RunAndSave, TempFolder);
+
+		string resfile = Path.Combine (TempFolder, "res");
+		using (StreamWriter sw = new StreamWriter (resfile)) {
+			sw.WriteLine ("FOO");
+		}
+
+		ab.AddResourceFile ("res", "res");
+
+		ModuleBuilder mb = ab.DefineDynamicModule(fileName, fileName);
+
+		mb.DefineInitializedData ("DATA", new byte [100], FieldAttributes.Public);
+		mb.DefineInitializedData ("DATA2", new byte [100], FieldAttributes.Public);
+		mb.DefineInitializedData ("DATA3", new byte [99], FieldAttributes.Public);
+		mb.DefineUninitializedData ("DATA4", 101, FieldAttributes.Public);
+		mb.DefineInitializedData ("DATA_PRIVATE", new byte [100], 0);
+		mb.CreateGlobalFunctions ();
+
+		ab.Save (fileName);
+
+		Assembly assembly = Assembly.LoadFrom (Path.Combine (TempFolder, fileName));
+
+		Module module = assembly.GetLoadedModules ()[0];
+
+		string[] expectedFieldNames = new string [] {
+			"DATA", "DATA2", "DATA3", "DATA4"
+		};
+		ArrayList fieldNames = new ArrayList ();
+		foreach (FieldInfo fi in module.GetFields ()) {
+			fieldNames.Add (fi.Name);
+		}
+		AssertArrayEqualsSorted (expectedFieldNames, fieldNames.ToArray (typeof (string)));
+
+		Assert.IsNotNull (module.GetField ("DATA"), "#A1");
+		Assert.IsNotNull (module.GetField ("DATA2"), "#A2");
+		Assert.IsNotNull (module.GetField ("DATA3"), "#A3");
+		Assert.IsNotNull (module.GetField ("DATA4"), "#A4");
+		Assert.IsNull (module.GetField ("DATA_PRIVATE"), "#A5");
+		Assert.IsNotNull (module.GetField ("DATA_PRIVATE", BindingFlags.NonPublic | BindingFlags.Static), "#A6");
+
+		// Check that these methods work correctly on resource modules
+		Module m2 = assembly.GetModule ("res");
+		Assert.IsNotNull (m2, "#B1");
+		Assert.AreEqual (0, m2.GetFields ().Length, "#B2");
+		Assert.IsNull (m2.GetField ("DATA"), "#B3");
+		Assert.IsNull (m2.GetField ("DATA", BindingFlags.Public), "#B4");
+	}
+
+#if NET_2_0
+	[Test]
+	public void ResolveType ()
+	{
+		Type t = typeof (ModuleTest);
+		Module module = t.Module;
+
+		Assert.AreEqual (t, module.ResolveType (t.MetadataToken), "#1");
+
+		/* We currently throw ArgumentException for this one */
+		try {
+			module.ResolveType (1234);
+			Assert.Fail ("#2");
+		} catch (ArgumentException) {
+		}
+
+		try {
+			module.ResolveType (t.GetMethod ("ResolveType").MetadataToken);
+			Assert.Fail ("#3");
+		} catch (ArgumentException) {
+		}
+
+		try {
+			module.ResolveType (t.MetadataToken + 10000);
+			Assert.Fail ("#4");
+		} catch (ArgumentOutOfRangeException) {
+		}
+	}
+
+	[Test]
+	public void ResolveMethod ()
+	{
+		Type t = typeof (ModuleTest);
+		Module module = t.Module;
+
+		Assert.AreEqual (t.GetMethod ("ResolveMethod"), module.ResolveMethod (t.GetMethod ("ResolveMethod").MetadataToken));
+
+		try {
+			module.ResolveMethod (1234);
+			Assert.Fail ();
+		} catch (ArgumentException) {
+		}
+
+		try {
+			module.ResolveMethod (t.MetadataToken);
+			Assert.Fail ();
+		} catch (ArgumentException) {
+		}
+
+		try {
+			module.ResolveMethod (t.GetMethod ("ResolveMethod").MetadataToken + 10000);
+			Assert.Fail ();
+		} catch (ArgumentOutOfRangeException) {
+		}
+	}
+
+	public int aField;
+
+	[Test]
+	public void ResolveField ()
+	{
+		Type t = typeof (ModuleTest);
+		Module module = t.Module;
+
+		Assert.AreEqual (t.GetField ("aField"), module.ResolveField (t.GetField ("aField").MetadataToken));
+
+		try {
+			module.ResolveField (1234);
+			Assert.Fail ();
+		} catch (ArgumentException) {
+		}
+
+		try {
+			module.ResolveField (t.MetadataToken);
+			Assert.Fail ();
+		} catch (ArgumentException) {
+		}
+
+		try {
+			module.ResolveField (t.GetField ("aField").MetadataToken + 10000);
+			Assert.Fail ();
+		} catch (ArgumentOutOfRangeException) {
+		}
+	}
+
+	[Ignore ("it breaks nunit-console.exe execution under .NET 2.0")]
+	[Test]
+	public void ResolveString ()
+	{
+		Type t = typeof (ModuleTest);
+		Module module = t.Module;
+
+		for (int i = 1; i < 10000; ++i) {
+			try {
+				module.ResolveString (0x70000000 + i);
+			} catch (Exception) {
+			}
+		}
+
+		try {
+			module.ResolveString (1234);
+			Assert.Fail ();
+		} catch (ArgumentException) {
+		}
+
+		try {
+			module.ResolveString (t.MetadataToken);
+			Assert.Fail ();
+		} catch (ArgumentException) {
+		}
+
+		try {
+			module.ResolveString (0x70000000 | 10000);
+			Assert.Fail ();
+		} catch (ArgumentOutOfRangeException) {
+		}
+	}
+
+
+	[Test]
+	public void ResolveMember ()
+	{
+		Type t = typeof (ModuleTest);
+		Module module = t.Module;
+
+		Assert.AreEqual (t, module.ResolveMember (t.MetadataToken), "#1");
+		Assert.AreEqual (t.GetField ("aField"), module.ResolveMember (t.GetField ("aField").MetadataToken), "#2");
+		Assert.AreEqual (t.GetMethod ("ResolveMember"), module.ResolveMember (t.GetMethod ("ResolveMember").MetadataToken), "#3");
+
+		try {
+			module.ResolveMember (module.MetadataToken);
+			Assert.Fail ("#4");
+		} catch (ArgumentException) {
+		}
+	}
+#endif
+
+	[Test]
+	public void FindTypes ()
+	{
+		Module m = typeof (ModuleTest).Module;
+
+		Type[] t;
+
+		t = m.FindTypes (Module.FilterTypeName, "FindTypesTest*");
+		Assert.AreEqual (2, t.Length, "#A1");
+		Assert.AreEqual ("FindTypesTestFirstClass", t [0].Name, "#A2");
+		Assert.AreEqual ("FindTypesTestSecondClass", t [1].Name, "#A3");
+		t = m.FindTypes (Module.FilterTypeNameIgnoreCase, "findtypestest*");
+		Assert.AreEqual (2, t.Length, "#B1");
+		Assert.AreEqual ("FindTypesTestFirstClass", t [0].Name, "#B2");
+		Assert.AreEqual ("FindTypesTestSecondClass", t [1].Name, "#B3");
+	}
 
 	[Test]
 	[ExpectedException (typeof (ArgumentNullException))]
 	public void GetObjectData_Null ()
 	{
-		Module m = typeof (ModuleTest).Module;
-		m.GetObjectData (null, new StreamingContext (StreamingContextStates.All));
-	}
-
-	class FindTypesTestFirstClass { 
-	}
-
-	class FindTypesTestSecondClass {
-	}
-
-    private static void AssertArrayEqualsSorted (Array o1, Array o2) {
-		Array s1 = (Array)o1.Clone ();
-		Array s2 = (Array)o2.Clone ();
-
-		Array.Sort (s1);
-		Array.Sort (s2);
-
-		AssertEquals (s1.Length, s2.Length);
-		for (int i = 0; i < s1.Length; ++i)
-			AssertEquals (s1.GetValue (i), s2.GetValue (i));
-	}
-}
-}
-
+		Module m = typeof (ModuleTest).Module;
+		m.GetObjectData (null, new StreamingContext (StreamingContextStates.All));
+	}
+
+	class FindTypesTestFirstClass {
+	}
+
+	class FindTypesTestSecondClass {
+	}
+
+	private static void AssertArrayEqualsSorted (Array o1, Array o2) {
+		Array s1 = (Array)o1.Clone ();
+		Array s2 = (Array)o2.Clone ();
+
+		Array.Sort (s1);
+		Array.Sort (s2);
+
+		Assert.AreEqual (s1.Length, s2.Length);
+		for (int i = 0; i < s1.Length; ++i)
+			Assert.AreEqual (s1.GetValue (i), s2.GetValue (i));
+	}
+}
+}
+

+ 91 - 72
mcs/class/corlib/Test/System.Reflection/ParameterInfoTest.cs

@@ -19,91 +19,110 @@ using NUnit.Framework;
 
 namespace MonoTests.System.Reflection
 {
-
-
-public class Marshal1 : ICustomMarshaler
-{
-	public static ICustomMarshaler GetInstance (string s) {
-		return new Marshal1 ();
-	}
-
-	public void CleanUpManagedData (object managedObj)
-	{
-	}
-
-	public void CleanUpNativeData (IntPtr pNativeData)
-	{
-	}
-
-	public int GetNativeDataSize ()
+	public class Marshal1 : ICustomMarshaler
 	{
-		return 4;
-	}
+		public static ICustomMarshaler GetInstance (string s)
+		{
+			return new Marshal1 ();
+		}
+
+		public void CleanUpManagedData (object managedObj)
+		{
+		}
+
+		public void CleanUpNativeData (IntPtr pNativeData)
+		{
+		}
+
+		public int GetNativeDataSize ()
+		{
+			return 4;
+		}
+
+		public IntPtr MarshalManagedToNative (object managedObj)
+		{
+			return IntPtr.Zero;
+	 	}
+
+		public object MarshalNativeToManaged (IntPtr pNativeData)
+		{
+			return null;
+		}
+}
 
-	public IntPtr MarshalManagedToNative (object managedObj)
+	[TestFixture]
+	public class ParameterInfoTest
 	{
-		return IntPtr.Zero;
- 	}
+		[Test]
+		public void IsDefined_AttributeType_Null ()
+		{
+			MethodInfo mi = typeof (object).GetMethod ("Equals", 
+				new Type [1] { typeof (object) });
+			ParameterInfo pi = mi.GetParameters () [0];
+
+			try {
+				pi.IsDefined ((Type) null, false);
+				Assert.Fail ("#1");
+			} catch (ArgumentNullException ex) {
+				Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
+				Assert.IsNull (ex.InnerException, "#3");
+				Assert.IsNotNull (ex.Message, "#4");
+				Assert.IsNotNull (ex.ParamName, "#5");
+				Assert.AreEqual ("attributeType", ex.ParamName, "#6");
+			}
+		}
 
-	public object MarshalNativeToManaged (IntPtr pNativeData)
-	{
-		return null;
-	}
-}
 
-[TestFixture]
-public class ParameterInfoTest : Assertion
-{
 #if NET_2_0
-	public enum ParamEnum {
-		None = 0,
-		Foo = 1,
-		Bar = 2
-	};
-
-	public static void paramMethod (int i, [In] int j, [Out] int k, [Optional] int l, [In,Out] int m, [DefaultParameterValue (ParamEnum.Foo)] ParamEnum n) {
-	}
+		public enum ParamEnum {
+			None = 0,
+			Foo = 1,
+			Bar = 2
+		};
+
+		public static void paramMethod (int i, [In] int j, [Out] int k, [Optional] int l, [In,Out] int m, [DefaultParameterValue (ParamEnum.Foo)] ParamEnum n) {
+		}
 #if !TARGET_JVM // No support for extern methods in TARGET_JVM
-	[DllImport ("foo")]
-	public extern static void marshalAsMethod (
-		[MarshalAs(UnmanagedType.Bool)]int p0, 
-		[MarshalAs(UnmanagedType.LPArray, ArraySubType=UnmanagedType.LPStr)] string [] p1,
-		[MarshalAs( UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof (Marshal1), MarshalCookie = "5")] object p2);
+		[DllImport ("foo")]
+		public extern static void marshalAsMethod (
+			[MarshalAs(UnmanagedType.Bool)]int p0, 
+			[MarshalAs(UnmanagedType.LPArray, ArraySubType=UnmanagedType.LPStr)] string [] p1,
+			[MarshalAs( UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof (Marshal1), MarshalCookie = "5")] object p2);
 #endif
-	[Test]
-	public void DefaultValueEnum () {
-		ParameterInfo[] info = typeof (ParameterInfoTest).GetMethod ("paramMethod").GetParameters ();
-
-		AssertEquals (typeof (ParamEnum), info [5].DefaultValue.GetType ());
-		AssertEquals (ParamEnum.Foo, info [5].DefaultValue);
-	}
-
-	[Test]
-	public void PseudoCustomAttributes () {
-		ParameterInfo[] info = typeof (ParameterInfoTest).GetMethod ("paramMethod").GetParameters ();
-		AssertEquals (0, info[0].GetCustomAttributes (true).Length);
-		AssertEquals (1, info[1].GetCustomAttributes (typeof (InAttribute), true).Length);
-		AssertEquals (1, info[2].GetCustomAttributes (typeof (OutAttribute), true).Length);
-		AssertEquals (1, info[3].GetCustomAttributes (typeof (OptionalAttribute), true).Length);
-		AssertEquals (2, info[4].GetCustomAttributes (true).Length);
+		[Test]
+		public void DefaultValueEnum () {
+			ParameterInfo[] info = typeof (ParameterInfoTest).GetMethod ("paramMethod").GetParameters ();
+
+			Assert.AreEqual (typeof (ParamEnum), info [5].DefaultValue.GetType (), "#1");
+			Assert.AreEqual (ParamEnum.Foo, info [5].DefaultValue, "#2");
+		}
+
+		[Test]
+		public void PseudoCustomAttributes () {
+			ParameterInfo[] info = typeof (ParameterInfoTest).GetMethod ("paramMethod").GetParameters ();
+			Assert.AreEqual (0, info[0].GetCustomAttributes (true).Length, "#A1");
+			Assert.AreEqual (1, info[1].GetCustomAttributes (typeof (InAttribute), true).Length, "#A2");
+			Assert.AreEqual (1, info[2].GetCustomAttributes (typeof (OutAttribute), true).Length, "#A3");
+			Assert.AreEqual (1, info[3].GetCustomAttributes (typeof (OptionalAttribute), true).Length, "#A4");
+			Assert.AreEqual (2, info[4].GetCustomAttributes (true).Length, "#A5");
 
 #if !TARGET_JVM // No support for extern methods in TARGET_JVM
-		ParameterInfo[] pi = typeof (ParameterInfoTest).GetMethod ("marshalAsMethod").GetParameters ();
-		MarshalAsAttribute attr;
+			ParameterInfo[] pi = typeof (ParameterInfoTest).GetMethod ("marshalAsMethod").GetParameters ();
+			MarshalAsAttribute attr;
 
-		attr = (MarshalAsAttribute)(pi [0].GetCustomAttributes (true) [0]);
-		AssertEquals (UnmanagedType.Bool, attr.Value);
+			attr = (MarshalAsAttribute)(pi [0].GetCustomAttributes (true) [0]);
+			Assert.AreEqual (UnmanagedType.Bool, attr.Value, "#B");
 
-		attr = (MarshalAsAttribute)(pi [1].GetCustomAttributes (true) [0]);
-		AssertEquals (UnmanagedType.LPArray, attr.Value);
-		AssertEquals (UnmanagedType.LPStr, attr.ArraySubType);
+			attr = (MarshalAsAttribute)(pi [1].GetCustomAttributes (true) [0]);
+			Assert.AreEqual (UnmanagedType.LPArray, attr.Value, "#C1");
+			Assert.AreEqual (UnmanagedType.LPStr, attr.ArraySubType, "#C2");
 
-		attr = (MarshalAsAttribute)(pi [2].GetCustomAttributes (true) [0]);
-		AssertEquals (UnmanagedType.CustomMarshaler, attr.Value);
-		AssertEquals ("5", attr.MarshalCookie);
-		AssertEquals (typeof (Marshal1), Type.GetType (attr.MarshalType));
+			attr = (MarshalAsAttribute)(pi [2].GetCustomAttributes (true) [0]);
+			Assert.AreEqual (UnmanagedType.CustomMarshaler, attr.Value, "#D1");
+			Assert.AreEqual ("5", attr.MarshalCookie, "#D2");
+			Assert.AreEqual (typeof (Marshal1), Type.GetType (attr.MarshalType), "#D3");
 #endif
-	}
+		}
 #endif
-}		
+	}
 }

+ 216 - 19
mcs/class/corlib/Test/System.Reflection/PropertyInfoTest.cs

@@ -4,11 +4,32 @@
 // Author:
 //	Gert Driesen ([email protected])
 //
-// (C) 2004 Novell 
+// (C) 2004-2007 Gert Driesen
 //
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
 
 using System;
-using System.Reflection; 
+using System.Reflection;
+using System.Runtime.InteropServices;
 
 using NUnit.Framework;
 
@@ -18,39 +39,189 @@ namespace MonoTests.System.Reflection
 	public class PropertyInfoTest
 	{
 		[Test]
-		public void GetAccessorsTest()
+		public void GetAccessorsTest ()
 		{
-			Type type = typeof(TestClass);
+			Type type = typeof (TestClass);
 			PropertyInfo property = type.GetProperty ("ReadOnlyProperty");
-        		MethodInfo[] methods = property.GetAccessors (true);
 
-			Assert.AreEqual (1, methods.Length, "GetAccessors#1");
-			Assert.IsNotNull (methods[0], "GetAccessors#2");
-						
+			MethodInfo [] methods = property.GetAccessors (true);
+			Assert.AreEqual (1, methods.Length, "#A1");
+			Assert.IsNotNull (methods [0], "#A2");
+			Assert.AreEqual ("get_ReadOnlyProperty", methods [0].Name, "#A3");
+
+			methods = property.GetAccessors (false);
+			Assert.AreEqual (1, methods.Length, "#B1");
+			Assert.IsNotNull (methods [0], "#B2");
+			Assert.AreEqual ("get_ReadOnlyProperty", methods [0].Name, "#B3");
+
+			property = typeof (Base).GetProperty ("P");
+
+			methods = property.GetAccessors (true);
+			Assert.AreEqual (2, methods.Length, "#C1");
+			Assert.IsNotNull (methods [0], "#C2");
+			Assert.IsNotNull (methods [1], "#C3");
+			Assert.IsTrue (HasMethod (methods, "get_P"), "#C4");
+			Assert.IsTrue (HasMethod (methods, "set_P"), "#C5");
+
+			methods = property.GetAccessors (false);
+			Assert.AreEqual (2, methods.Length, "#D1");
+			Assert.IsNotNull (methods [0], "#D2");
+			Assert.IsNotNull (methods [1], "#D3");
+			Assert.IsTrue (HasMethod (methods, "get_P"), "#D4");
+			Assert.IsTrue (HasMethod (methods, "set_P"), "#D5");
+
+			methods = property.GetAccessors ();
+			Assert.AreEqual (2, methods.Length, "#E1");
+			Assert.IsNotNull (methods [0], "#E2");
+			Assert.IsNotNull (methods [1], "#E3");
+			Assert.IsTrue (HasMethod (methods, "get_P"), "#E4");
+			Assert.IsTrue (HasMethod (methods, "set_P"), "#E5");
+
+			property = typeof (TestClass).GetProperty ("Private",
+				BindingFlags.NonPublic | BindingFlags.Instance);
+
+			methods = property.GetAccessors (true);
+			Assert.AreEqual (2, methods.Length, "#F1");
+			Assert.IsNotNull (methods [0], "#F2");
+			Assert.IsNotNull (methods [1], "#F3");
+			Assert.IsTrue (HasMethod (methods, "get_Private"), "#F4");
+			Assert.IsTrue (HasMethod (methods, "set_Private"), "#F5");
+
+			methods = property.GetAccessors (false);
+			Assert.AreEqual (0, methods.Length, "#G");
+
+			methods = property.GetAccessors ();
+			Assert.AreEqual (0, methods.Length, "#H");
+
+#if NET_2_0
+			property = typeof (TestClass).GetProperty ("PrivateSetter");
+
+			methods = property.GetAccessors (true);
+			Assert.AreEqual (2, methods.Length, "#H1");
+			Assert.IsNotNull (methods [0], "#H2");
+			Assert.IsNotNull (methods [1], "#H3");
+			Assert.IsTrue (HasMethod (methods, "get_PrivateSetter"), "#H4");
+			Assert.IsTrue (HasMethod (methods, "set_PrivateSetter"), "#H5");
+
+			methods = property.GetAccessors (false);
+			Assert.AreEqual (1, methods.Length, "#I1");
+			Assert.IsNotNull (methods [0], "#I2");
+			Assert.AreEqual ("get_PrivateSetter", methods [0].Name, "#I3");
+
+			methods = property.GetAccessors ();
+			Assert.AreEqual (1, methods.Length, "#J1");
+			Assert.IsNotNull (methods [0], "#J2");
+			Assert.AreEqual ("get_PrivateSetter", methods [0].Name, "#J3");
+#endif
+		}
+
+		[Test]
+		public void GetCustomAttributes ()
+		{
+			object [] attrs;
+			PropertyInfo p = typeof (Base).GetProperty ("P");
+
+			attrs = p.GetCustomAttributes (false);
+			Assert.AreEqual (1, attrs.Length, "#A1");
+			Assert.AreEqual (typeof (ThisAttribute), attrs [0].GetType (), "#A2");
+			attrs = p.GetCustomAttributes (true);
+			Assert.AreEqual (1, attrs.Length, "#A3");
+			Assert.AreEqual (typeof (ThisAttribute), attrs [0].GetType (), "#A4");
+
+			p = typeof (Base).GetProperty ("T");
+
+			attrs = p.GetCustomAttributes (false);
+			Assert.AreEqual (2, attrs.Length, "#B1");
+			Assert.IsTrue (HasAttribute (attrs, typeof (ThisAttribute)), "#B2");
+			Assert.IsTrue (HasAttribute (attrs, typeof (ComVisibleAttribute)), "#B3");
+			attrs = p.GetCustomAttributes (true);
+			Assert.AreEqual (2, attrs.Length, "#B41");
+			Assert.IsTrue (HasAttribute (attrs, typeof (ThisAttribute)), "#B5");
+			Assert.IsTrue (HasAttribute (attrs, typeof (ComVisibleAttribute)), "#B6");
+
+			p = typeof (Base).GetProperty ("Z");
+
+			attrs = p.GetCustomAttributes (false);
+			Assert.AreEqual (0, attrs.Length, "#C1");
+			attrs = p.GetCustomAttributes (true);
+			Assert.AreEqual (0, attrs.Length, "#C2");
+		}
+
+		[Test]
+		public void GetCustomAttributes_Inherited ()
+		{
+			object [] attrs;
+			PropertyInfo p = typeof (Derived).GetProperty ("P");
+
+			attrs = p.GetCustomAttributes (false);
+			Assert.AreEqual (0, attrs.Length, "#A1");
+			attrs = p.GetCustomAttributes (true);
+			Assert.AreEqual (0, attrs.Length, "#A3");
+
+			p = typeof (Derived).GetProperty ("T");
+
+			attrs = p.GetCustomAttributes (false);
+			Assert.AreEqual (2, attrs.Length, "#B1");
+			Assert.IsTrue (HasAttribute (attrs, typeof (ThisAttribute)), "#B2");
+			Assert.IsTrue (HasAttribute (attrs, typeof (ComVisibleAttribute)), "#B3");
+			attrs = p.GetCustomAttributes (true);
+			Assert.AreEqual (2, attrs.Length, "#B41");
+			Assert.IsTrue (HasAttribute (attrs, typeof (ThisAttribute)), "#B5");
+			Assert.IsTrue (HasAttribute (attrs, typeof (ComVisibleAttribute)), "#B6");
+
+			p = typeof (Derived).GetProperty ("Z");
+
+			attrs = p.GetCustomAttributes (false);
+			Assert.AreEqual (0, attrs.Length, "#C1");
+			attrs = p.GetCustomAttributes (true);
+			Assert.AreEqual (0, attrs.Length, "#C2");
 		}
 
 		[Test]
-		[Category ("NotWorking")]
-		public void GetCustomAttributesInherited ()
+		public void IsDefined_AttributeType_Null ()
 		{
 			Type derived = typeof (Derived);
-			PropertyInfo p = derived.GetProperty ("P");
+			PropertyInfo pi = derived.GetProperty ("P");
 
-			Assert.AreEqual (1, p.GetCustomAttributes (true).Length);
+			try {
+				pi.IsDefined ((Type) null, false);
+				Assert.Fail ("#1");
+			} catch (ArgumentNullException ex) {
+				Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
+				Assert.IsNull (ex.InnerException, "#3");
+				Assert.IsNotNull (ex.Message, "#4");
+				Assert.IsNotNull (ex.ParamName, "#5");
+				Assert.AreEqual ("attributeType", ex.ParamName, "#6");
+			}
 		}
 
-		public class ThisAttribute : Attribute {
+		public class ThisAttribute : Attribute
+		{
 		}
 
-		class Base {
+		class Base
+		{
 			[ThisAttribute]
 			public virtual string P {
 				get { return null; }
 				set { }
 			}
+
+			[ThisAttribute]
+			[ComVisible (false)]
+			public virtual string T {
+				get { return null; }
+				set { }
+			}
+
+			public virtual string Z {
+				get { return null; }
+				set { }
+			}
 		}
 
-		class Derived : Base {
+		class Derived : Base
+		{
 			public override string P {
 				get { return null; }
 				set { }
@@ -58,8 +229,7 @@ namespace MonoTests.System.Reflection
 		}
 
 #if NET_2_0
-
-		public class A<T> 
+		public class A<T>
 		{
 			public string Property {
 				get { return typeof (T).FullName; }
@@ -96,12 +266,39 @@ namespace MonoTests.System.Reflection
 		}
 #endif
 
+		static bool HasAttribute (object [] attrs, Type attributeType)
+		{
+			foreach (object attr in attrs)
+				if (attr.GetType () == attributeType)
+					return true;
+			return false;
+		}
+
+		static bool HasMethod (MethodInfo [] methods, string name)
+		{
+			foreach (MethodInfo method in methods)
+				if (method.Name == name)
+					return true;
+			return false;
+		}
+
 		private class TestClass 
 		{
-			public string ReadOnlyProperty 
-			{
+			public string ReadOnlyProperty {
 				get { return string.Empty; }
 			}
+
+			private string Private {
+				get { return null; }
+				set { }
+			}
+
+#if NET_2_0
+			public string PrivateSetter {
+				get { return null; }
+				private set { }
+			}
+#endif
 		}
 	}
 }

+ 6 - 0
mcs/class/corlib/Test/System/ChangeLog

@@ -1,3 +1,9 @@
+2007-08-16  Gert Driesen  <[email protected]>
+
+	* TypeTest.cs: Improved test for GetCustomAttributes, and avoid
+	dependency on order of attributes. Split IsDefined test and improved
+	part for bug #82431.
+
 2007-08-15  Gert Driesen  <[email protected]>
 
 	* TypeTest.cs: Added IsDefined tests for bug #82431. Added tests for

+ 276 - 24
mcs/class/corlib/Test/System/TypeTest.cs

@@ -594,8 +594,8 @@ PublicKeyToken=b77a5c561934e089"));
 		{
 			object [] attrs = typeof (A).GetCustomAttributes (false);
 			Assert.AreEqual (2, attrs.Length, "#A1");
-			Assert.AreEqual (typeof (FooAttribute), attrs [0].GetType (), "#A2");
-			Assert.AreEqual (typeof (VolatileModifier), attrs [1].GetType (), "#A3");
+			Assert.IsTrue (HasAttribute (attrs, typeof (FooAttribute)), "#A2");
+			Assert.IsTrue (HasAttribute (attrs, typeof (VolatileModifier)), "#A3");
 
 			attrs = typeof (BA).GetCustomAttributes (false);
 			Assert.AreEqual (1, attrs.Length, "#B1");
@@ -603,8 +603,8 @@ PublicKeyToken=b77a5c561934e089"));
 
 			attrs = typeof (BA).GetCustomAttributes (true);
 			Assert.AreEqual (2, attrs.Length, "#C1");
-			Assert.AreEqual (typeof (BarAttribute), attrs [0].GetType (), "#C2");
-			Assert.AreEqual (typeof (VolatileModifier), attrs [1].GetType (), "#C3");
+			Assert.IsTrue (HasAttribute (attrs, typeof (BarAttribute)), "#C2");
+			Assert.IsTrue (HasAttribute (attrs, typeof (VolatileModifier)), "#C3");
 
 			attrs = typeof (CA).GetCustomAttributes (false);
 			Assert.AreEqual (0, attrs.Length, "#D");
@@ -614,58 +614,197 @@ PublicKeyToken=b77a5c561934e089"));
 			Assert.AreEqual (typeof (VolatileModifier), attrs [0].GetType (), "#E2");
 		}
 
+		static bool HasAttribute (object [] attrs, Type attributeType)
+		{
+			foreach (object attr in attrs)
+				if (attr.GetType () == attributeType)
+					return true;
+			return false;
+		}
+
 		[Test]
 		public void GetCustomAttributes_Type ()
 		{
-			object [] attrs = typeof (A).GetCustomAttributes (
+			object [] attrs = null;
+
+			attrs = typeof (A).GetCustomAttributes (
 				typeof (VolatileModifier), false);
 			Assert.AreEqual (1, attrs.Length, "#A1");
 			Assert.AreEqual (typeof (VolatileModifier), attrs [0].GetType (), "#A2");
+			attrs = typeof (A).GetCustomAttributes (
+				typeof (VolatileModifier), true);
+			Assert.AreEqual (1, attrs.Length, "#A3");
+			Assert.AreEqual (typeof (VolatileModifier), attrs [0].GetType (), "#A4");
 
 			attrs = typeof (A).GetCustomAttributes (
 				typeof (NemerleAttribute), false);
 			Assert.AreEqual (1, attrs.Length, "#B1");
 			Assert.AreEqual (typeof (VolatileModifier), attrs [0].GetType (), "#B2");
+			attrs = typeof (A).GetCustomAttributes (
+				typeof (NemerleAttribute), true);
+			Assert.AreEqual (1, attrs.Length, "#B3");
+			Assert.AreEqual (typeof (VolatileModifier), attrs [0].GetType (), "#B4");
 
 			attrs = typeof (A).GetCustomAttributes (
 				typeof (FooAttribute), false);
 			Assert.AreEqual (1, attrs.Length, "#C1");
 			Assert.AreEqual (typeof (FooAttribute), attrs [0].GetType (), "#C2");
+			attrs = typeof (A).GetCustomAttributes (
+				typeof (FooAttribute), false);
+			Assert.AreEqual (1, attrs.Length, "#C3");
+			Assert.AreEqual (typeof (FooAttribute), attrs [0].GetType (), "#C4");
 
 			attrs = typeof (BA).GetCustomAttributes (
 				typeof (VolatileModifier), false);
-			Assert.AreEqual (0, attrs.Length, "#D");
-
+			Assert.AreEqual (0, attrs.Length, "#D1");
 			attrs = typeof (BA).GetCustomAttributes (
 				typeof (VolatileModifier), true);
-			Assert.AreEqual (1, attrs.Length, "#E1");
-			Assert.AreEqual (typeof (VolatileModifier), attrs [0].GetType (), "#E2");
+			Assert.AreEqual (1, attrs.Length, "#D2");
+			Assert.AreEqual (typeof (VolatileModifier), attrs [0].GetType (), "#D3");
 
 			attrs = typeof (BA).GetCustomAttributes (
 				typeof (NemerleAttribute), false);
-			Assert.AreEqual (0, attrs.Length, "#F");
-
+			Assert.AreEqual (0, attrs.Length, "#E1");
 			attrs = typeof (BA).GetCustomAttributes (
 				typeof (NemerleAttribute), true);
-			Assert.AreEqual (1, attrs.Length, "#G1");
-			Assert.AreEqual (typeof (VolatileModifier), attrs [0].GetType (), "#G2");
+			Assert.AreEqual (1, attrs.Length, "#E2");
+			Assert.AreEqual (typeof (VolatileModifier), attrs [0].GetType (), "#E3");
 
 			attrs = typeof (BA).GetCustomAttributes (
 				typeof (FooAttribute), false);
-			Assert.AreEqual (1, attrs.Length, "#H1");
-			Assert.AreEqual (typeof (BarAttribute), attrs [0].GetType (), "#H2");
-
+			Assert.AreEqual (1, attrs.Length, "#F1");
+			Assert.AreEqual (typeof (BarAttribute), attrs [0].GetType (), "#F2");
 			attrs = typeof (BA).GetCustomAttributes (
 				typeof (FooAttribute), true);
-			Assert.AreEqual (1, attrs.Length, "#I1");
-			Assert.AreEqual (typeof (BarAttribute), attrs [0].GetType (), "#I2");
+			Assert.AreEqual (1, attrs.Length, "#F3");
+			Assert.AreEqual (typeof (BarAttribute), attrs [0].GetType (), "#F4");
+
+			attrs = typeof (bug82431A1).GetCustomAttributes (
+				typeof (InheritAttribute), false);
+			Assert.AreEqual (1, attrs.Length, "#G1");
+			Assert.AreEqual (typeof (NotInheritAttribute), attrs [0].GetType (), "#G2");
+			attrs = typeof (bug82431A1).GetCustomAttributes (
+				typeof (InheritAttribute), true);
+			Assert.AreEqual (1, attrs.Length, "#G3");
+			Assert.AreEqual (typeof (NotInheritAttribute), attrs [0].GetType (), "#G4");
+
+			attrs = typeof (bug82431A1).GetCustomAttributes (
+				typeof (NotInheritAttribute), false);
+			Assert.AreEqual (1, attrs.Length, "#H1");
+			Assert.AreEqual (typeof (NotInheritAttribute), attrs [0].GetType (), "#H2");
+			attrs = typeof (bug82431A1).GetCustomAttributes (
+				typeof (InheritAttribute), true);
+			Assert.AreEqual (1, attrs.Length, "#H3");
+			Assert.AreEqual (typeof (NotInheritAttribute), attrs [0].GetType (), "#H4");
+
+			attrs = typeof (bug82431A2).GetCustomAttributes (
+				typeof (InheritAttribute), false);
+			Assert.AreEqual (0, attrs.Length, "#I1");
+			attrs = typeof (bug82431A2).GetCustomAttributes (
+				typeof (InheritAttribute), true);
+			Assert.AreEqual (0, attrs.Length, "#I2");
+
+			attrs = typeof (bug82431A2).GetCustomAttributes (
+				typeof (NotInheritAttribute), false);
+			Assert.AreEqual (0, attrs.Length, "#J1");
+			attrs = typeof (bug82431A2).GetCustomAttributes (
+				typeof (NotInheritAttribute), true);
+			Assert.AreEqual (0, attrs.Length, "#J2");
+
+			attrs = typeof (bug82431A3).GetCustomAttributes (
+				typeof (InheritAttribute), false);
+			Assert.AreEqual (2, attrs.Length, "#K1");
+			Assert.IsTrue (HasAttribute (attrs, typeof (InheritAttribute)), "#K2");
+			Assert.IsTrue (HasAttribute (attrs, typeof (NotInheritAttribute)), "#K3");
+			attrs = typeof (bug82431A3).GetCustomAttributes (
+				typeof (InheritAttribute), true);
+			Assert.AreEqual (2, attrs.Length, "#K4");
+			Assert.IsTrue (HasAttribute (attrs, typeof (InheritAttribute)), "#K5");
+			Assert.IsTrue (HasAttribute (attrs, typeof (NotInheritAttribute)), "#K6");
+
+			attrs = typeof (bug82431A3).GetCustomAttributes (
+				typeof (NotInheritAttribute), false);
+			Assert.AreEqual (1, attrs.Length, "#L1");
+			Assert.AreEqual (typeof (NotInheritAttribute), attrs [0].GetType (), "#L2");
+			attrs = typeof (bug82431A3).GetCustomAttributes (
+				typeof (NotInheritAttribute), true);
+			Assert.AreEqual (1, attrs.Length, "#L3");
+			Assert.AreEqual (typeof (NotInheritAttribute), attrs [0].GetType (), "#L4");
+
+			attrs = typeof (bug82431B1).GetCustomAttributes (
+				typeof (InheritAttribute), false);
+			Assert.AreEqual (1, attrs.Length, "#M1");
+			Assert.AreEqual (typeof (InheritAttribute), attrs [0].GetType (), "#M2");
+			attrs = typeof (bug82431B1).GetCustomAttributes (
+				typeof (InheritAttribute), true);
+			Assert.AreEqual (1, attrs.Length, "#M3");
+			Assert.AreEqual (typeof (InheritAttribute), attrs [0].GetType (), "#M4");
+
+			attrs = typeof (bug82431B1).GetCustomAttributes (
+				typeof (NotInheritAttribute), false);
+			Assert.AreEqual (0, attrs.Length, "#N1");
+			attrs = typeof (bug82431B1).GetCustomAttributes (
+				typeof (NotInheritAttribute), true);
+			Assert.AreEqual (0, attrs.Length, "#N2");
+
+			attrs = typeof (bug82431B2).GetCustomAttributes (
+				typeof (InheritAttribute), false);
+			Assert.AreEqual (0, attrs.Length, "#O1");
+			attrs = typeof (bug82431B2).GetCustomAttributes (
+				typeof (InheritAttribute), true);
+			Assert.AreEqual (1, attrs.Length, "#O2");
+			Assert.AreEqual (typeof (InheritAttribute), attrs [0].GetType (), "#O3");
+
+			attrs = typeof (bug82431B2).GetCustomAttributes (
+				typeof (NotInheritAttribute), false);
+			Assert.AreEqual (0, attrs.Length, "#P1");
+			attrs = typeof (bug82431B2).GetCustomAttributes (
+				typeof (NotInheritAttribute), true);
+			Assert.AreEqual (0, attrs.Length, "#P2");
+
+			attrs = typeof (bug82431B3).GetCustomAttributes (
+				typeof (InheritAttribute), false);
+			Assert.AreEqual (1, attrs.Length, "#Q1");
+			Assert.AreEqual (typeof (NotInheritAttribute), attrs [0].GetType (), "#Q2");
+			attrs = typeof (bug82431B3).GetCustomAttributes (
+				typeof (InheritAttribute), true);
+			Assert.AreEqual (2, attrs.Length, "#Q3");
+			Assert.AreEqual (typeof (NotInheritAttribute), attrs [0].GetType (), "#Q4");
+			Assert.AreEqual (typeof (InheritAttribute), attrs [1].GetType (), "#Q5");
+
+			attrs = typeof (bug82431B3).GetCustomAttributes (
+				typeof (NotInheritAttribute), false);
+			Assert.AreEqual (1, attrs.Length, "#R1");
+			Assert.AreEqual (typeof (NotInheritAttribute), attrs [0].GetType (), "#R2");
+			attrs = typeof (bug82431B3).GetCustomAttributes (
+				typeof (NotInheritAttribute), true);
+			Assert.AreEqual (1, attrs.Length, "#R3");
+			Assert.AreEqual (typeof (NotInheritAttribute), attrs [0].GetType (), "#R4");
+
+			attrs = typeof (bug82431B4).GetCustomAttributes (
+				typeof (InheritAttribute), false);
+			Assert.AreEqual (0, attrs.Length, "#S1");
+			attrs = typeof (bug82431B4).GetCustomAttributes (
+				typeof (InheritAttribute), true);
+			Assert.AreEqual (1, attrs.Length, "#S2");
+			Assert.AreEqual (typeof (InheritAttribute), attrs [0].GetType (), "#S3");
+
+			attrs = typeof (bug82431B4).GetCustomAttributes (
+				typeof (NotInheritAttribute), false);
+			Assert.AreEqual (0, attrs.Length, "#T1");
+			attrs = typeof (bug82431B4).GetCustomAttributes (
+				typeof (NotInheritAttribute), true);
+			Assert.AreEqual (0, attrs.Length, "#T2");
 
 			attrs = typeof (A).GetCustomAttributes (
 				typeof (string), false);
-			Assert.AreEqual (0, attrs.Length, "#J");
+			Assert.AreEqual (0, attrs.Length, "#U1");
+			attrs = typeof (A).GetCustomAttributes (
+				typeof (string), true);
+			Assert.AreEqual (0, attrs.Length, "#U2");
 		}
 
-		[Test] // bug #76150 and #82431
+		[Test] // bug #76150
 		public void IsDefined ()
 		{
 			Assert.IsTrue (typeof (A).IsDefined (typeof (NemerleAttribute), false), "#A1");
@@ -677,11 +816,37 @@ PublicKeyToken=b77a5c561934e089"));
 			Assert.IsFalse (typeof (BA).IsDefined (typeof (VolatileModifier), false), "#B2");
 			Assert.IsTrue (typeof (BA).IsDefined (typeof (FooAttribute), false), "#B3");
 			Assert.IsTrue (typeof (BA).IsDefined (typeof (BarAttribute), false), "#B4");
-			Assert.IsTrue (typeof (BA).IsDefined (typeof (NemerleAttribute), true), "#B5");
-			Assert.IsTrue (typeof (BA).IsDefined (typeof (VolatileModifier), true), "#B6");
-			Assert.IsTrue (typeof (BA).IsDefined (typeof (FooAttribute), true), "#B7");
-			Assert.IsTrue (typeof (BA).IsDefined (typeof (BarAttribute), true), "#B8");
+			Assert.IsFalse (typeof (BA).IsDefined (typeof (string), false), "#B5");
+			Assert.IsFalse (typeof (BA).IsDefined (typeof (int), false), "#B6");
+			Assert.IsTrue (typeof (BA).IsDefined (typeof (NemerleAttribute), true), "#B7");
+			Assert.IsTrue (typeof (BA).IsDefined (typeof (VolatileModifier), true), "#B8");
+			Assert.IsTrue (typeof (BA).IsDefined (typeof (FooAttribute), true), "#B9");
+			Assert.IsTrue (typeof (BA).IsDefined (typeof (BarAttribute), true), "#B10");
+			Assert.IsFalse (typeof (BA).IsDefined (typeof (string), true), "#B11");
+			Assert.IsFalse (typeof (BA).IsDefined (typeof (int), true), "#B12");
+		}
+
+		[Test]
+		public void IsDefined_AttributeType_Null ()
+		{
+			try {
+				typeof (BA).IsDefined ((Type) null, false);
+				Assert.Fail ("#1");
+			} catch (ArgumentNullException ex) {
+				Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
+				Assert.IsNull (ex.InnerException, "#3");
+				Assert.IsNotNull (ex.Message, "#4");
+				Assert.IsNotNull (ex.ParamName, "#5");
+				Assert.AreEqual ("attributeType", ex.ParamName, "#6");
+			}
+		}
 
+		[Test] // bug #82431
+#if NET_2_0
+		[Category ("NotWorking")]
+#endif
+		public void IsDefined_Inherited ()
+		{
 			Assert.IsFalse (typeof (CA).IsDefined (typeof (NemerleAttribute), false), "#C1");
 			Assert.IsFalse (typeof (CA).IsDefined (typeof (VolatileModifier), false), "#C2");
 			Assert.IsFalse (typeof (CA).IsDefined (typeof (FooAttribute), false), "#C3");
@@ -697,8 +862,52 @@ PublicKeyToken=b77a5c561934e089"));
 			Assert.IsFalse (typeof (BBA).IsDefined (typeof (BarAttribute), false), "#D4");
 			Assert.IsTrue (typeof (BBA).IsDefined (typeof (NemerleAttribute), true), "#D5");
 			Assert.IsTrue (typeof (BBA).IsDefined (typeof (VolatileModifier), true), "#D6");
+#if NET_2_0
+			Assert.IsTrue (typeof (BBA).IsDefined (typeof (FooAttribute), true), "#D7");
+			Assert.IsTrue (typeof (BBA).IsDefined (typeof (BarAttribute), true), "#D8");
+#else
 			Assert.IsFalse (typeof (BBA).IsDefined (typeof (FooAttribute), true), "#D7");
 			Assert.IsFalse (typeof (BBA).IsDefined (typeof (BarAttribute), true), "#D8");
+#endif
+
+			Assert.IsTrue (typeof (bug82431A1).IsDefined (typeof (InheritAttribute), false), "#E1");
+			Assert.IsTrue (typeof (bug82431A1).IsDefined (typeof (NotInheritAttribute), false), "#E2");
+			Assert.IsTrue (typeof (bug82431A1).IsDefined (typeof (InheritAttribute), true), "#E3");
+			Assert.IsTrue (typeof (bug82431A1).IsDefined (typeof (NotInheritAttribute), true), "#E4");
+
+			Assert.IsFalse (typeof (bug82431A2).IsDefined (typeof (InheritAttribute), false), "#F1");
+			Assert.IsFalse (typeof (bug82431A2).IsDefined (typeof (NotInheritAttribute), false), "#F2");
+#if NET_2_0
+			Assert.IsFalse (typeof (bug82431A2).IsDefined (typeof (InheritAttribute), true), "#F3");
+#else
+			Assert.IsTrue (typeof (bug82431A2).IsDefined (typeof (InheritAttribute), true), "#F3");
+#endif
+			Assert.IsFalse (typeof (bug82431A2).IsDefined (typeof (NotInheritAttribute), true), "#F4");
+
+			Assert.IsTrue (typeof (bug82431A3).IsDefined (typeof (InheritAttribute), false), "#G1");
+			Assert.IsTrue (typeof (bug82431A3).IsDefined (typeof (NotInheritAttribute), false), "#G2");
+			Assert.IsTrue (typeof (bug82431A3).IsDefined (typeof (InheritAttribute), true), "#G3");
+			Assert.IsTrue (typeof (bug82431A3).IsDefined (typeof (NotInheritAttribute), true), "#G4");
+
+			Assert.IsTrue (typeof (bug82431B1).IsDefined (typeof (InheritAttribute), false), "#H1");
+			Assert.IsFalse (typeof (bug82431B1).IsDefined (typeof (NotInheritAttribute), false), "#H2");
+			Assert.IsTrue (typeof (bug82431B1).IsDefined (typeof (InheritAttribute), true), "#H3");
+			Assert.IsFalse (typeof (bug82431B1).IsDefined (typeof (NotInheritAttribute), true), "#H4");
+
+			Assert.IsFalse (typeof (bug82431B2).IsDefined (typeof (InheritAttribute), false), "#I1");
+			Assert.IsFalse (typeof (bug82431B2).IsDefined (typeof (NotInheritAttribute), false), "#I2");
+			Assert.IsTrue (typeof (bug82431B2).IsDefined (typeof (InheritAttribute), true), "#I3");
+			Assert.IsFalse (typeof (bug82431B2).IsDefined (typeof (NotInheritAttribute), true), "#I4");
+
+			Assert.IsTrue (typeof (bug82431B3).IsDefined (typeof (InheritAttribute), false), "#J1");
+			Assert.IsTrue (typeof (bug82431B3).IsDefined (typeof (NotInheritAttribute), false), "#J2");
+			Assert.IsTrue (typeof (bug82431B3).IsDefined (typeof (InheritAttribute), true), "#J3");
+			Assert.IsTrue (typeof (bug82431B3).IsDefined (typeof (NotInheritAttribute), true), "#J4");
+
+			Assert.IsFalse (typeof (bug82431B4).IsDefined (typeof (InheritAttribute), false), "#K2");
+			Assert.IsFalse (typeof (bug82431B4).IsDefined (typeof (NotInheritAttribute), false), "#K2");
+			Assert.IsTrue (typeof (bug82431B4).IsDefined (typeof (InheritAttribute), true), "#K3");
+			Assert.IsFalse (typeof (bug82431B4).IsDefined (typeof (NotInheritAttribute), true), "#K4");
 		}
 
 		[Test]
@@ -996,6 +1205,49 @@ PublicKeyToken=b77a5c561934e089"));
 		{
 		}
 
+		[AttributeUsage (AttributeTargets.Class, Inherited=true)]
+		public class InheritAttribute : Attribute
+		{
+		}
+
+		[AttributeUsage (AttributeTargets.Class, Inherited=false)]
+		public class NotInheritAttribute : InheritAttribute
+		{
+		}
+
+		[NotInheritAttribute]
+		public class bug82431A1
+		{
+		}
+
+		public class bug82431A2 : bug82431A1
+		{
+		}
+
+		[NotInheritAttribute]
+		[InheritAttribute]
+		public class bug82431A3 : bug82431A1
+		{
+		}
+
+		[InheritAttribute]
+		public class bug82431B1
+		{
+		}
+
+		public class bug82431B2 : bug82431B1
+		{
+		}
+
+		[NotInheritAttribute]
+		public class bug82431B3 : bug82431B2
+		{
+		}
+
+		public class bug82431B4 : bug82431B3
+		{
+		}
+
 		struct FooStruct {
 		}