From: Jackson Harper Date: Wed, 10 Mar 2004 00:03:00 +0000 (-0000) Subject: * AssemblyAlgorithmIdAttributeTest.cs: X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=commitdiff_plain;ds=sidebyside;h=248dccce2beab2fcb2ca9ad56cf6b94094795801;p=mono.git * AssemblyAlgorithmIdAttributeTest.cs: * AssemblyConfigurationAttributeTest.cs: * AssemblyCopyrightAttributeTest.cs: * AssemblyCultureAttributeTest.cs: * AssemblyDelaySignAttributeTest.cs: * AssemblyDescriptionAttributeTest.cs: * AssemblyFileVersionAttributeTest.cs: * AssemblyInformationalVersionAttributeTest.cs: New test cases from nvineeth_mono@yahoo.com. svn path=/trunk/mcs/; revision=23857 --- diff --git a/mcs/class/corlib/Test/System.Reflection/AssemblyAlgorithmIdAttributeTest.cs b/mcs/class/corlib/Test/System.Reflection/AssemblyAlgorithmIdAttributeTest.cs new file mode 100644 index 00000000000..c7e91af28f0 --- /dev/null +++ b/mcs/class/corlib/Test/System.Reflection/AssemblyAlgorithmIdAttributeTest.cs @@ -0,0 +1,87 @@ +// AssemblyAlgorithmIdAttributeTest.cs +// +// Author: Vineeth N +// +// (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 { + + /// + /// Test Fixture for AssemblyAlgorithmIdAttribute class + /// + [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); + } + } +} + diff --git a/mcs/class/corlib/Test/System.Reflection/AssemblyConfigurationAttributeTest.cs b/mcs/class/corlib/Test/System.Reflection/AssemblyConfigurationAttributeTest.cs new file mode 100644 index 00000000000..cd8e320b0d2 --- /dev/null +++ b/mcs/class/corlib/Test/System.Reflection/AssemblyConfigurationAttributeTest.cs @@ -0,0 +1,83 @@ +// AssemblyConfigurationAttributeTest.cs +// +// Author: Vineeth N +// +// (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 { + + /// + /// Test Fixture for AssemblyConfigurationAttribute class + /// + [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); + } + } +} + diff --git a/mcs/class/corlib/Test/System.Reflection/AssemblyCopyrightAttributeTest.cs b/mcs/class/corlib/Test/System.Reflection/AssemblyCopyrightAttributeTest.cs new file mode 100644 index 00000000000..851b78d4413 --- /dev/null +++ b/mcs/class/corlib/Test/System.Reflection/AssemblyCopyrightAttributeTest.cs @@ -0,0 +1,83 @@ +// AssemblyCopyrightAttributeTest.cs +// +// Author: Vineeth N +// +// (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 { + + /// + /// Test Fixture for AssemblyCopyrightAttribute + /// + [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); + } + } +} + diff --git a/mcs/class/corlib/Test/System.Reflection/AssemblyCultureAttributeTest.cs b/mcs/class/corlib/Test/System.Reflection/AssemblyCultureAttributeTest.cs new file mode 100644 index 00000000000..c6e00f73d2e --- /dev/null +++ b/mcs/class/corlib/Test/System.Reflection/AssemblyCultureAttributeTest.cs @@ -0,0 +1,83 @@ +// AssemblyCultureAttributeTest.cs +// +// Author: Vineeth N +// +// (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 { + + /// + /// Test Fixture for AssemblyCultureAttribute + /// + [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); + } + } +} + diff --git a/mcs/class/corlib/Test/System.Reflection/AssemblyDelaySignAttributeTest.cs b/mcs/class/corlib/Test/System.Reflection/AssemblyDelaySignAttributeTest.cs new file mode 100644 index 00000000000..90df55373ad --- /dev/null +++ b/mcs/class/corlib/Test/System.Reflection/AssemblyDelaySignAttributeTest.cs @@ -0,0 +1,81 @@ +// AssemblyDelaySignAttributeTest.cs +// +// Author: Vineeth N +// +// (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 description for AssemblyDelaySignAttributeTest. + /// + [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); + } + } +} + diff --git a/mcs/class/corlib/Test/System.Reflection/AssemblyDescriptionAttributeTest.cs b/mcs/class/corlib/Test/System.Reflection/AssemblyDescriptionAttributeTest.cs new file mode 100644 index 00000000000..fe0d9c6824d --- /dev/null +++ b/mcs/class/corlib/Test/System.Reflection/AssemblyDescriptionAttributeTest.cs @@ -0,0 +1,82 @@ +// AssemblyDescriptionAttributeTest.cs +// +// Author: Vineeth N +// +// (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 description for AssemblyDescriptionAttributeTest. + /// + [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); + } + } +} + diff --git a/mcs/class/corlib/Test/System.Reflection/AssemblyFileVersionAttributeTest.cs b/mcs/class/corlib/Test/System.Reflection/AssemblyFileVersionAttributeTest.cs new file mode 100644 index 00000000000..7e66d1cd36b --- /dev/null +++ b/mcs/class/corlib/Test/System.Reflection/AssemblyFileVersionAttributeTest.cs @@ -0,0 +1,90 @@ +// AssemblyFileVersionAttributeTest.cs +// +// Author: Vineeth N +// +// (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 description for AssemblyFileVersionAttributeTest. + /// + [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); + } + } +} + diff --git a/mcs/class/corlib/Test/System.Reflection/AssemblyInformationalVersionAttributeTest.cs b/mcs/class/corlib/Test/System.Reflection/AssemblyInformationalVersionAttributeTest.cs new file mode 100644 index 00000000000..19661974066 --- /dev/null +++ b/mcs/class/corlib/Test/System.Reflection/AssemblyInformationalVersionAttributeTest.cs @@ -0,0 +1,83 @@ +// AssemblyInformationalVersionAttributeTest.cs +// +// Author: Vineeth N +// +// (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 { + + /// + /// Test Fixture for AssemblyInformationalVersionAttribute. + /// + [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); + } + } +} + diff --git a/mcs/class/corlib/Test/System.Reflection/ChangeLog b/mcs/class/corlib/Test/System.Reflection/ChangeLog index d82f5dad5b4..6bee1a9745d 100644 --- a/mcs/class/corlib/Test/System.Reflection/ChangeLog +++ b/mcs/class/corlib/Test/System.Reflection/ChangeLog @@ -1,3 +1,15 @@ +2003-03-09 Jackson Harper + + * AssemblyAlgorithmIdAttributeTest.cs: + * AssemblyConfigurationAttributeTest.cs: + * AssemblyCopyrightAttributeTest.cs: + * AssemblyCultureAttributeTest.cs: + * AssemblyDelaySignAttributeTest.cs: + * AssemblyDescriptionAttributeTest.cs: + * AssemblyFileVersionAttributeTest.cs: + * AssemblyInformationalVersionAttributeTest.cs: New test cases + from nvineeth_mono@yahoo.com. + 2003-11-24 Zoltan Varga * ModuleTest.cs: Make the assembly name unique to fix the GlobalData