2
0
Эх сурвалжийг харах

* AssemblyAlgorithmIdAttributeTest.cs:
* AssemblyConfigurationAttributeTest.cs:
* AssemblyCopyrightAttributeTest.cs:
* AssemblyCultureAttributeTest.cs:
* AssemblyDelaySignAttributeTest.cs:
* AssemblyDescriptionAttributeTest.cs:
* AssemblyFileVersionAttributeTest.cs:
* AssemblyInformationalVersionAttributeTest.cs: New test cases
from [email protected].

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

Jackson Harper 22 жил өмнө
parent
commit
248dccce2b

+ 87 - 0
mcs/class/corlib/Test/System.Reflection/AssemblyAlgorithmIdAttributeTest.cs

@@ -0,0 +1,87 @@
+// AssemblyAlgorithmIdAttributeTest.cs
+//
+// Author: Vineeth N <[email protected]>
+//
+// (C) 2004 Ximian, Inc. http://www.ximian.com
+//
+using System;
+using System.Threading;
+using System.Reflection;
+using System.Reflection.Emit;
+using System.Configuration.Assemblies;
+using NUnit.Framework;
+
+namespace MonoTests.System.Reflection {
+
+	/// <summary>
+	/// Test Fixture for AssemblyAlgorithmIdAttribute class
+	/// </summary>
+	[TestFixture]
+	public class AssemblyAlgorithmIdAttributeTest : Assertion
+	{
+		private AssemblyBuilder dynAssembly;
+		AssemblyName dynAsmName = new AssemblyName ();
+		AssemblyAlgorithmIdAttribute attr;
+
+		public AssemblyAlgorithmIdAttributeTest ()
+		{
+			//create a dynamic assembly with the required attribute
+			//and check for the validity
+
+			dynAsmName.Name = "TestAssembly";
+
+			dynAssembly = Thread.GetDomain ().DefineDynamicAssembly (
+				dynAsmName,AssemblyBuilderAccess.Run
+				);
+
+			// Set the required Attribute of the assembly.
+			Type attribute = typeof (AssemblyAlgorithmIdAttribute);
+			ConstructorInfo ctrInfo = attribute.GetConstructor (
+				new Type [] { typeof (AssemblyHashAlgorithm) }
+				);
+			CustomAttributeBuilder attrBuilder =
+				new CustomAttributeBuilder (
+				ctrInfo,
+				new object [1] { AssemblyHashAlgorithm.MD5 }
+				);
+			dynAssembly.SetCustomAttribute (attrBuilder);
+			object [] attributes = dynAssembly.GetCustomAttributes (true);
+			attr = attributes [0] as AssemblyAlgorithmIdAttribute;
+		}
+		
+		[Test]
+		[CLSCompliant (false)] // because we are using uint
+		public void AlgorithmIdTest()
+		{
+			AssertEquals ("#Testing AlgorithmId",
+				attr.AlgorithmId,
+				(uint) AssemblyHashAlgorithm.MD5);
+		}
+
+		[Test]
+		public void TypeIdTest ()
+		{
+			AssertEquals ("#testing Typeid",
+				attr.TypeId,
+				typeof (AssemblyAlgorithmIdAttribute)
+				);
+
+		}
+
+		[Test]
+		public void MatchTestForTrue ()
+		{
+			AssertEquals ("#testing Match method-- for true",
+				attr.Match (attr),
+				true);
+		}
+		[Test]
+		public void MatchTestForFalse ()
+		{			
+			AssertEquals ("#testing Match method-- for false",
+				attr.Match (new AssemblyAlgorithmIdAttribute (AssemblyHashAlgorithm.SHA1)),
+				false);
+		}
+	}
+}
+

+ 83 - 0
mcs/class/corlib/Test/System.Reflection/AssemblyConfigurationAttributeTest.cs

@@ -0,0 +1,83 @@
+// AssemblyConfigurationAttributeTest.cs
+//
+// Author: Vineeth N <[email protected]>
+//
+// (C) 2004 Ximian, Inc. http://www.ximian.com
+//
+
+using System;
+using System.Threading;
+using System.Reflection;
+using System.Reflection.Emit;
+using NUnit.Framework;
+
+namespace MonoTests.System.Reflection {
+
+	/// <summary>
+	/// Test Fixture for AssemblyConfigurationAttribute class
+	/// </summary>
+	[TestFixture]
+	public class AssemblyConfigurationAttributeTest : Assertion
+	{
+		private AssemblyBuilder dynAssembly;
+		AssemblyName dynAsmName = new AssemblyName ();
+		AssemblyConfigurationAttribute attr;
+
+		public AssemblyConfigurationAttributeTest ()
+		{
+			//create a dynamic assembly with the required attribute
+			//and check for the validity
+
+			dynAsmName.Name = "TestAssembly";
+
+			dynAssembly = Thread.GetDomain ().DefineDynamicAssembly (
+				dynAsmName,AssemblyBuilderAccess.Run
+				);
+
+			// Set the required Attribute of the assembly.
+			Type attribute = typeof (AssemblyConfigurationAttribute);
+			ConstructorInfo ctrInfo = attribute.GetConstructor (
+				new Type [] { typeof (string) }
+				);
+			CustomAttributeBuilder attrBuilder =
+				new CustomAttributeBuilder (ctrInfo, new object [1] { "Config" } );
+			dynAssembly.SetCustomAttribute (attrBuilder);
+			object [] attributes = dynAssembly.GetCustomAttributes (true);
+			attr = attributes [0] as AssemblyConfigurationAttribute;
+		}
+		
+		[Test]
+		public void ConfigurationTest ()
+		{
+			AssertEquals ("#Testing Configuration",
+				attr.Configuration,
+				"Config");
+		}
+
+		[Test]
+		public void TypeIdTest ()
+		{
+			AssertEquals ("#testing Typeid",
+				attr.TypeId,
+				typeof (AssemblyConfigurationAttribute)
+				);
+		}
+
+		[Test]
+		public void MatchTestForTrue ()
+		{
+			AssertEquals ("#testing Match method-- for true",
+				attr.Match (attr),
+				true);
+		}
+
+		[Test]
+		public void MatchTestForFalse ()
+		{
+			AssertEquals ("#testing Match method-- for false",
+				attr.Match (new AssemblyConfigurationAttribute ("abcd")),
+				false);
+		}
+	}
+}
+

+ 83 - 0
mcs/class/corlib/Test/System.Reflection/AssemblyCopyrightAttributeTest.cs

@@ -0,0 +1,83 @@
+// AssemblyCopyrightAttributeTest.cs
+//
+// Author: Vineeth N <[email protected]>
+//
+// (C) 2004 Ximian, Inc. http://www.ximian.com
+//
+
+using System;
+using System.Threading;
+using System.Reflection;
+using System.Reflection.Emit;
+using NUnit.Framework;
+
+namespace MonoTests.System.Reflection {
+
+	/// <summary>
+	/// Test Fixture for AssemblyCopyrightAttribute
+	/// </summary>
+	[TestFixture]
+	public class AssemblyCopyrightAttributeTest : Assertion
+	{
+		private AssemblyBuilder dynAssembly;
+		AssemblyName dynAsmName = new AssemblyName ();
+		AssemblyCopyrightAttribute attr;
+
+		public AssemblyCopyrightAttributeTest ()
+		{
+			//create a dynamic assembly with the required attribute
+			//and check for the validity
+
+			dynAsmName.Name = "TestAssembly";
+
+			dynAssembly = Thread.GetDomain().DefineDynamicAssembly (
+				dynAsmName,AssemblyBuilderAccess.Run
+				);
+
+			// Set the required Attribute of the assembly.
+			Type attribute = typeof (AssemblyCopyrightAttribute);
+			ConstructorInfo ctrInfo = attribute.GetConstructor (
+				new Type []{ typeof (string) }
+				);
+			CustomAttributeBuilder attrBuilder =
+				new CustomAttributeBuilder (ctrInfo, new object [1] {"Ximian"} );
+			dynAssembly.SetCustomAttribute(attrBuilder);
+			object [] attributes = dynAssembly.GetCustomAttributes (true);
+			attr = attributes [0] as AssemblyCopyrightAttribute;
+		}
+		
+		[Test]
+		public void CopyrightTest ()
+		{
+			AssertEquals ("#Testing Copyright",
+				attr.Copyright,
+				"Ximian");
+		}
+
+		[Test]
+		public void TypeIdTest ()
+		{
+			AssertEquals ("#testing Typeid",
+				attr.TypeId,
+				typeof (AssemblyCopyrightAttribute)
+				);
+		}
+
+		[Test]
+		public void MatchTestForTrue ()
+		{
+			AssertEquals ("#testing Match method-- for true",
+				attr.Match (attr),
+				true);
+		}
+
+		[Test]
+		public void MatchTestForFalse ()
+		{	
+			AssertEquals ("#testing Match method-- for false",
+				attr.Match (new AssemblyCopyrightAttribute ("imian")),
+				false);
+		}
+	}
+}
+

+ 83 - 0
mcs/class/corlib/Test/System.Reflection/AssemblyCultureAttributeTest.cs

@@ -0,0 +1,83 @@
+// AssemblyCultureAttributeTest.cs
+//
+// Author: Vineeth N <[email protected]>
+//
+// (C) 2004 Ximian, Inc. http://www.ximian.com
+//
+
+using System;
+using System.Threading;
+using System.Reflection;
+using System.Reflection.Emit;
+using NUnit.Framework;
+
+namespace MonoTests.System.Reflection {
+
+	/// <summary>
+	/// Test Fixture for AssemblyCultureAttribute
+	/// </summary>
+	[TestFixture]
+	public class AssemblyCultureAttributeTest : Assertion
+	{
+		private AssemblyBuilder dynAssembly;
+		AssemblyName dynAsmName = new AssemblyName ();
+		AssemblyCultureAttribute attr;
+
+		public AssemblyCultureAttributeTest ()
+		{
+			//create a dynamic assembly with the required attribute
+			//and check for the validity
+
+			dynAsmName.Name = "TestAssembly";
+
+			dynAssembly = Thread.GetDomain ().DefineDynamicAssembly (
+				dynAsmName,AssemblyBuilderAccess.Run
+				);
+
+			// Set the required Attribute of the assembly.
+			Type attribute = typeof (AssemblyCultureAttribute);
+			ConstructorInfo ctrInfo = attribute.GetConstructor (
+				new Type [] { typeof (string) }
+				);
+			CustomAttributeBuilder attrBuilder =
+				new CustomAttributeBuilder (ctrInfo, new object [1] { "India" });
+			dynAssembly.SetCustomAttribute (attrBuilder);
+			object [] attributes = dynAssembly.GetCustomAttributes(true);
+			attr = attributes [0] as AssemblyCultureAttribute;
+		}
+		
+		[Test]
+		public void CultureTest ()
+		{
+			AssertEquals ("#Testing Culture",
+				attr.Culture,
+				"India");
+		}
+
+		[Test]
+		public void TypeIdTest ()
+		{
+			AssertEquals ("#testing Typeid",
+				attr.TypeId,
+				typeof (AssemblyCultureAttribute)
+				);
+		}
+
+		[Test]
+		public void MatchTestForTrue ()
+		{
+			AssertEquals ("#testing Match method-- for true",
+				attr.Match (attr),
+				true);
+		}
+
+		[Test]
+		public void MatchTestForFalse ()
+		{	
+			AssertEquals ("#testing Match method-- for false",
+				attr.Match (new AssemblyCultureAttribute ("Spanish")),
+				false);
+		}
+	}
+}
+

+ 81 - 0
mcs/class/corlib/Test/System.Reflection/AssemblyDelaySignAttributeTest.cs

@@ -0,0 +1,81 @@
+// AssemblyDelaySignAttributeTest.cs
+//
+// Author: Vineeth N <[email protected]>
+//
+// (C) 2004 Ximian, Inc. http://www.ximian.com
+//
+using System;
+using System.Threading;
+using System.Reflection;
+using System.Reflection.Emit;
+using NUnit.Framework;
+
+namespace MonoTests.System.Reflection {
+
+	/// <summary>
+	/// Summary description for AssemblyDelaySignAttributeTest.
+	/// </summary>
+	[TestFixture]
+	public class AssemblyDelaySignAttributeTest:Assertion
+	{
+		private AssemblyBuilder dynAssembly;
+		AssemblyName dynAsmName = new AssemblyName ();
+		AssemblyDelaySignAttribute attr;
+		
+		public AssemblyDelaySignAttributeTest ()
+		{
+			//create a dynamic assembly with the required attribute
+			//and check for the validity
+
+			dynAsmName.Name = "TestAssembly";
+
+			dynAssembly = Thread.GetDomain ().DefineDynamicAssembly (
+				dynAsmName,AssemblyBuilderAccess.Run
+				);
+
+			// Set the required Attribute of the assembly.
+			Type attribute = typeof (AssemblyDelaySignAttribute);
+			ConstructorInfo ctrInfo = attribute.GetConstructor (
+				new Type [] { typeof (bool) }
+				);
+			CustomAttributeBuilder attrBuilder =
+				new CustomAttributeBuilder (ctrInfo, new object [1] { false });
+			dynAssembly.SetCustomAttribute (attrBuilder);
+			object [] attributes = dynAssembly.GetCustomAttributes (true);
+			attr = attributes [0] as AssemblyDelaySignAttribute;
+		}
+		
+		[Test]
+		public void DelaySignTest ()
+		{
+			AssertEquals ("#Testing DelaySign",
+				attr.DelaySign,
+				false);
+		}
+
+		[Test]
+		public void TypeIdTest ()
+		{
+			AssertEquals ("#testing Typeid",
+				attr.TypeId,
+				typeof (AssemblyDelaySignAttribute)
+				);
+		}
+
+		[Test]
+		public void MatchTestForTrue ()
+		{
+			AssertEquals ("#testing Match method-- for true",
+				attr.Match (attr),
+				true);
+		}
+		[Test]
+		public void MatchTestForFalse ()
+		{
+			AssertEquals ("#testing Match method-- for false",
+				attr.Match (new AssemblyDelaySignAttribute (true)),
+				false);
+		}
+	}
+}
+

+ 82 - 0
mcs/class/corlib/Test/System.Reflection/AssemblyDescriptionAttributeTest.cs

@@ -0,0 +1,82 @@
+// AssemblyDescriptionAttributeTest.cs
+//
+// Author: Vineeth N <[email protected]>
+//
+// (C) 2004 Ximian, Inc. http://www.ximian.com
+//
+using System;
+using System.Threading;
+using System.Reflection;
+using System.Reflection.Emit;
+using NUnit.Framework;
+
+namespace MonoTests.System.Reflection {
+
+	/// <summary>
+	/// Summary description for AssemblyDescriptionAttributeTest.
+	/// </summary>
+	[TestFixture]
+	public class AssemblyDescriptionAttributeTest : Assertion
+	{
+		private AssemblyBuilder dynAssembly;
+		AssemblyName dynAsmName = new AssemblyName ();
+		AssemblyDescriptionAttribute attr;
+		
+		public AssemblyDescriptionAttributeTest ()
+		{
+			//create a dynamic assembly with the required attribute
+			//and check for the validity
+
+			dynAsmName.Name = "TestAssembly";
+
+			dynAssembly = Thread.GetDomain ().DefineDynamicAssembly (
+				dynAsmName,AssemblyBuilderAccess.Run
+				);
+
+			// Set the required Attribute of the assembly.
+			Type attribute = typeof (AssemblyDescriptionAttribute);
+			ConstructorInfo ctrInfo = attribute.GetConstructor (
+				new Type [] { typeof (string) }
+				);
+			CustomAttributeBuilder attrBuilder =
+				new CustomAttributeBuilder (ctrInfo, new object [1] { "Emitted Assembly" });
+			dynAssembly.SetCustomAttribute (attrBuilder);
+			object [] attributes = dynAssembly.GetCustomAttributes (true);
+			attr = attributes [0] as AssemblyDescriptionAttribute;
+		}
+
+		[Test]
+		public void DescriptionTest ()
+		{
+			AssertEquals ("#Testing Description",
+				attr.Description,
+				"Emitted Assembly");
+		}
+
+		[Test]
+		public void TypeIdTest ()
+		{
+			AssertEquals ("#testing Typeid",
+				attr.TypeId,
+				typeof (AssemblyDescriptionAttribute)
+				);
+		}
+
+		[Test]
+		public void MatchTestForTrue ()
+		{
+			AssertEquals ("#testing Match method-- for true",
+				attr.Match (attr),
+				true);
+		}
+
+		[Test]
+		public void MatchTestForFalse ()
+		{
+			AssertEquals ("#testing Match method-- for false",
+				attr.Match (new AssemblyDescriptionAttribute ("Descrptn")),
+				false);
+		}
+	}
+}
+

+ 90 - 0
mcs/class/corlib/Test/System.Reflection/AssemblyFileVersionAttributeTest.cs

@@ -0,0 +1,90 @@
+// AssemblyFileVersionAttributeTest.cs
+//
+// Author: Vineeth N <[email protected]>
+//
+// (C) 2004 Ximian, Inc. http://www.ximian.com
+//
+using System;
+using System.Threading;
+using System.Reflection;
+using System.Reflection.Emit;
+using NUnit.Framework;
+
+namespace MonoTests.System.Reflection {
+
+	/// <summary>
+	/// Summary description for AssemblyFileVersionAttributeTest.
+	/// </summary>
+	[TestFixture]
+	public class AssemblyFileVersionAttributeTest : Assertion {
+
+		private AssemblyBuilder dynAssembly;
+		AssemblyName dynAsmName = new AssemblyName ();
+		AssemblyFileVersionAttribute attr;
+		
+		public AssemblyFileVersionAttributeTest ()
+		{
+			//create a dynamic assembly with the required attribute
+			//and check for the validity
+
+			dynAsmName.Name = "TestAssembly";
+
+			dynAssembly = Thread.GetDomain ().DefineDynamicAssembly (
+				dynAsmName,AssemblyBuilderAccess.Run
+				);
+
+			// Set the required Attribute of the assembly.
+			Type attribute = typeof (AssemblyFileVersionAttribute);
+			ConstructorInfo ctrInfo = attribute.GetConstructor (
+				new Type [] { typeof(string) }
+				);
+			CustomAttributeBuilder attrBuilder =
+				new CustomAttributeBuilder(ctrInfo, new object [1] { "1.0.0.0" });
+			dynAssembly.SetCustomAttribute (attrBuilder);
+			object [] attributes = dynAssembly.GetCustomAttributes (true);
+			attr = attributes [0] as AssemblyFileVersionAttribute;
+		}
+
+		[Test]
+		[ExpectedException (typeof (ArgumentNullException))]
+		public void ArgumentNullExceptionTest()
+		{
+			string version = null;
+			new AssemblyFileVersionAttribute (version);
+		}
+		
+		[Test]
+		public void FileVersionTest ()
+		{
+			AssertEquals ("#Testing FileVersion",
+				attr.Version,
+				"1.0.0.0");
+		}
+
+		[Test]
+		public void TypeIdTest ()
+		{
+			AssertEquals ("#testing Typeid",
+				attr.TypeId,
+				typeof (AssemblyFileVersionAttribute)
+				);
+		}
+
+		[Test]
+		public void MatchTestForTrue ()
+		{
+			AssertEquals ("#testing Match method-- for true",
+				attr.Match (attr),
+				true);
+		}
+
+		[Test]
+		public void MatchTestForFalse ()
+		{
+			AssertEquals ("#testing Match method-- for false",
+				attr.Match (new AssemblyFileVersionAttribute ("Descrptn")),
+				false);
+		}
+	}
+}
+

+ 83 - 0
mcs/class/corlib/Test/System.Reflection/AssemblyInformationalVersionAttributeTest.cs

@@ -0,0 +1,83 @@
+// AssemblyInformationalVersionAttributeTest.cs
+//
+// Author: Vineeth N <[email protected]>
+//
+// (C) 2004 Ximian, Inc. http://www.ximian.com
+//
+using System;
+using System.Threading;
+using System.Reflection;
+using System.Reflection.Emit;
+using NUnit.Framework;
+
+namespace MonoTests.System.Reflection {
+
+	/// <summary>
+	/// Test Fixture for AssemblyInformationalVersionAttribute.
+	/// </summary>
+	[TestFixture]
+	public class AssemblyInformationalVersionAttributeTest : Assertion {
+
+		private AssemblyBuilder dynAssembly;
+		AssemblyName dynAsmName = new AssemblyName ();
+		AssemblyInformationalVersionAttribute attr;
+		
+		public AssemblyInformationalVersionAttributeTest ()
+		{
+			//create a dynamic assembly with the required attribute
+			//and check for the validity
+
+			dynAsmName.Name = "TestAssembly";
+
+			dynAssembly = Thread.GetDomain ().DefineDynamicAssembly (
+				dynAsmName,AssemblyBuilderAccess.Run
+				);
+
+			// Set the required Attribute of the assembly.
+			Type attribute = typeof (AssemblyInformationalVersionAttribute);
+			ConstructorInfo ctrInfo = attribute.GetConstructor (
+				new Type [] { typeof (string) }
+				);
+			CustomAttributeBuilder attrBuilder =
+				new CustomAttributeBuilder (ctrInfo, new object [1] { "2.0.0.0" });
+			dynAssembly.SetCustomAttribute (attrBuilder);
+			object [] attributes = dynAssembly.GetCustomAttributes (true);
+			attr = attributes [0] as AssemblyInformationalVersionAttribute;
+		}
+
+		[Test]
+		public void InformationalVersionTest ()
+		{
+			AssertEquals ("#Testing InformationalVersion",
+				attr.InformationalVersion,
+				"2.0.0.0");
+		}
+
+		[Test]
+		public void TypeIdTest ()
+		{
+			AssertEquals ("#testing Typeid",
+				attr.TypeId,
+				typeof (AssemblyInformationalVersionAttribute)
+				);
+
+		}
+
+		[Test]
+		public void MatchTestForTrue ()
+		{
+			AssertEquals ("#testing Match method-- for true",
+				attr.Match (attr),
+				true);
+		}
+		[Test]
+		public void MatchTestForFalse ()
+		{
+			
+			AssertEquals ("#testing Match method-- for false",
+				attr.Match (new AssemblyInformationalVersionAttribute ("Descrptn")),
+				false);
+		}
+	}
+}
+

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

@@ -1,3 +1,15 @@
+2003-03-09  Jackson Harper  <[email protected]>
+
+	* AssemblyAlgorithmIdAttributeTest.cs:
+	* AssemblyConfigurationAttributeTest.cs:
+	* AssemblyCopyrightAttributeTest.cs:
+	* AssemblyCultureAttributeTest.cs:
+	* AssemblyDelaySignAttributeTest.cs:
+	* AssemblyDescriptionAttributeTest.cs:
+	* AssemblyFileVersionAttributeTest.cs:
+	* AssemblyInformationalVersionAttributeTest.cs: New test cases
+	from [email protected].
+
 2003-11-24  Zoltan Varga  <[email protected]>
 
 	* ModuleTest.cs: Make the assembly name unique to fix the GlobalData