| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517 |
- //
- // AssemblyBuilderTest.cs - NUnit Test Cases for the AssemblyBuilder class
- //
- // Zoltan Varga ([email protected])
- //
- // (C) Ximian, Inc. http://www.ximian.com
- //
- //
- using System;
- using System.Threading;
- using System.Reflection;
- using System.Reflection.Emit;
- using System.IO;
- using System.Configuration.Assemblies;
- using NUnit.Framework;
- namespace MonoTests.System.Reflection.Emit
- {
- [TestFixture]
- public class AssemblyBuilderTest : Assertion
- {
- [AttributeUsage (AttributeTargets.Assembly)]
- public sealed class FooAttribute : Attribute
- {
- public FooAttribute (string arg)
- {
- }
- public FooAttribute ()
- {
- }
- }
- static int nameIndex = 0;
- static AppDomain domain;
- static AssemblyBuilder ab;
- string tempDir = Path.Combine (Path.GetTempPath (), "MonoTests.System.Reflection.Emit.AssemblyBuilderTest");
- [SetUp]
- protected void SetUp () {
- if (Directory.Exists (tempDir))
- Directory.Delete (tempDir, true);
- Directory.CreateDirectory (tempDir);
- for (int i = 1; i < 3; ++i) {
- string resFile = Path.Combine (tempDir, "res" + i + ".txt");
- using (StreamWriter sw = new StreamWriter (resFile)) {
- sw.WriteLine ("FOO");
- }
- }
- domain = Thread.GetDomain ();
- ab = genAssembly ();
- ab.DefineDynamicModule ("def_module");
- }
- [TearDown]
- protected void TearDown () {
- if (Directory.Exists (tempDir))
- Directory.Delete (tempDir, true);
- }
- private AssemblyName genAssemblyName () {
- AssemblyName assemblyName = new AssemblyName();
- assemblyName.Name = "MonoTests.System.Reflection.Emit.AssemblyBuilderTest" + (nameIndex ++);
- return assemblyName;
- }
- private AssemblyBuilder genAssembly () {
- return domain.DefineDynamicAssembly (genAssemblyName (),
- AssemblyBuilderAccess.RunAndSave,
- tempDir);
- }
- private MethodInfo genEntryFunction (AssemblyBuilder assembly) {
- ModuleBuilder module = assembly.DefineDynamicModule("module1");
- TypeBuilder tb = module.DefineType ("A");
- MethodBuilder mb = tb.DefineMethod ("A",
- MethodAttributes.Static, typeof (void), new Type [0]);
- mb.GetILGenerator ().Emit (OpCodes.Ret);
- return mb;
- }
- [ExpectedException (typeof (NotSupportedException))]
- public void TestCodeBase () {
- string codebase = ab.CodeBase;
- }
- [ExpectedException (typeof (NotSupportedException))]
- public void TestLocation () {
- string location = ab.Location;
- }
- public void TestEntryPoint () {
- AssertEquals ("EntryPoint defaults to null",
- null, ab.EntryPoint);
- MethodInfo mi = genEntryFunction (ab);
- ab.SetEntryPoint (mi);
- AssertEquals ("EntryPoint works", mi, ab.EntryPoint);
- }
- public void TestSetEntryPoint () {
- // Check invalid arguments
- try {
- ab.SetEntryPoint (null);
- Fail ();
- }
- catch (ArgumentNullException) {
- }
- // Check method from other assembly
- try {
- ab.SetEntryPoint (typeof (AssemblyBuilderTest).GetMethod ("TestSetEntryPoint"));
- Fail ();
- }
- catch (InvalidOperationException) {
- }
- }
- public void TestIsDefined () {
- CustomAttributeBuilder cab = new CustomAttributeBuilder (typeof (FooAttribute).GetConstructor (new Type [1] {typeof (string)}), new object [1] { "A" });
- ab.SetCustomAttribute (cab);
- AssertEquals ("IsDefined works",
- true, ab.IsDefined (typeof (FooAttribute), false));
- AssertEquals ("IsDefined works",
- false, ab.IsDefined (typeof (AssemblyVersionAttribute), false));
- }
- [ExpectedException (typeof (NotSupportedException))]
- public void TestGetManifestResourceNames () {
- ab.GetManifestResourceNames ();
- }
- [ExpectedException (typeof (NotSupportedException))]
- public void TestGetManifestResourceInfo () {
- ab.GetManifestResourceInfo ("foo");
- }
- [ExpectedException (typeof (NotSupportedException))]
- public void TestGetManifestResourceStream1 () {
- ab.GetManifestResourceStream ("foo");
- }
- [ExpectedException (typeof (NotSupportedException))]
- public void TestGetManifestResourceStream2 () {
- ab.GetManifestResourceStream (typeof (int), "foo");
- }
- [ExpectedException (typeof (NotSupportedException))]
- public void TestGetFiles1 () {
- ab.GetFiles ();
- }
- [ExpectedException (typeof (NotSupportedException))]
- public void TestGetFiles2 () {
- ab.GetFiles (true);
- }
- [ExpectedException (typeof (NotSupportedException))]
- public void TestGetFile () {
- ab.GetFile ("foo");
- }
- [ExpectedException (typeof (NotSupportedException))]
- public void TestGetExportedTypes () {
- ab.GetExportedTypes ();
- }
- [ExpectedException (typeof (ArgumentNullException))]
- public void TestGetDynamicModule1 () {
- ab.GetDynamicModule (null);
- }
- [ExpectedException (typeof (ArgumentException))]
- public void TestGetDynamicModule2 () {
- ab.GetDynamicModule ("");
- }
- public void TestGetDynamicModule3 () {
- AssertNull (ab.GetDynamicModule ("FOO2"));
- ModuleBuilder mb = ab.DefineDynamicModule ("FOO");
- AssertEquals (mb, ab.GetDynamicModule ("FOO"));
- AssertNull (ab.GetDynamicModule ("FOO4"));
- }
- #if NET_1_1
- public void TestImageRuntimeVersion () {
- string version = ab.ImageRuntimeVersion;
- Assert (version.Length > 0);
- }
- #endif
- [ExpectedException (typeof (ArgumentNullException))]
- public void TestAddResourceFileNullName () {
- ab.AddResourceFile (null, "foo.txt");
- }
- [ExpectedException (typeof (ArgumentNullException))]
- public void TestAddResourceFileNullFilename () {
- ab.AddResourceFile ("foo", null);
- }
- [ExpectedException (typeof (ArgumentException))]
- public void TestAddResourceFileEmptyName () {
- ab.AddResourceFile ("", "foo.txt");
- }
- [ExpectedException (typeof (ArgumentException))]
- public void TestAddResourceFileEmptyFilename () {
- ab.AddResourceFile ("foo", "");
- }
- [ExpectedException (typeof (FileNotFoundException))]
- public void TestAddResourceFileNonexistentFile () {
- ab.AddResourceFile ("foo", "not-existent.txt");
- }
- [ExpectedException (typeof (ArgumentException))]
- public void TestAddResourceFileDuplicateFileName () {
- ab.AddResourceFile ("foo", "res1.txt");
- ab.AddResourceFile ("foo2", "res1.txt");
- }
- [ExpectedException (typeof (ArgumentException))]
- public void TestAddResourceFileDuplicateName () {
- ab.AddResourceFile ("foo", "res1.txt");
- ab.AddResourceFile ("foo", "res2.txt");
- }
- [ExpectedException (typeof (ArgumentException))]
- public void TestAddResourceFileFilenameIncludesPath () {
- ab.AddResourceFile ("foo", "/tmp/res1.txt");
- }
- public void TestAddResourceFile () {
- ab.AddResourceFile ("foo", "res2.txt", ResourceAttributes.Public);
- ab.Save ("TestAddResourceFile.dll");
- // TODO: Test reading back
- }
- public void TestDefineResource () {
- ab.DefineResource ("foo", "FOO", "foo.txt", ResourceAttributes.Public);
- ab.DefineResource ("foo2", "FOO", "foo2.txt");
- ab.Save ("TestDefineResource.dll");
- }
- [ExpectedException (typeof (ArgumentNullException))]
- public void TestDefineDynamicModuleNullName () {
- ab.DefineDynamicModule (null, "foo.txt");
- }
- [ExpectedException (typeof (ArgumentNullException))]
- public void TestDefineDynamicModuleNullFilename () {
- ab.DefineDynamicModule ("foo", null);
- }
- [ExpectedException (typeof (ArgumentException))]
- public void TestDefineDynamicModuleEmptyName () {
- ab.DefineDynamicModule ("", "foo.txt");
- }
- [ExpectedException (typeof (ArgumentException))]
- public void TestDefineDynamicModuleEmptyFilename () {
- ab.DefineDynamicModule ("foo", "");
- }
- [ExpectedException (typeof (ArgumentException))]
- public void TestDefineDynamicModuleDuplicateFileName () {
- ab.DefineDynamicModule ("foo", "res1.txt");
- ab.DefineDynamicModule ("foo2", "res1.txt");
- }
- [ExpectedException (typeof (ArgumentException))]
- public void TestDefineDynamicModuleDuplicateName () {
- ab.DefineDynamicModule ("foo", "res1.txt");
- ab.DefineDynamicModule ("foo", "res2.txt");
- }
- [ExpectedException (typeof (ArgumentException))]
- public void TestDefineDynamicModuleFilenameIncludesPath () {
- ab.DefineDynamicModule ("foo", "/tmp/res1.txt");
- }
- [ExpectedException (typeof (ArgumentException))]
- public void TestDefineDynamicModule5 () {
- // Filename without extension
- ab.DefineDynamicModule ("foo", "foo");
- }
- /*
- [ExpectedException (typeof (ArgumentException))]
- public void TestDefineDynamicModule6 () {
- // Name too long
- string name = "";
- for (int i = 0; i < 259; ++i)
- name = name + "A";
- try {
- ab.DefineDynamicModule (name);
- }
- catch (Exception) {
- Fail ();
- }
- name = name + "A";
- // LAMESPEC: According to MSDN, this should throw an ArgumentException
- ab.DefineDynamicModule (name);
- }
- */
- [ExpectedException (typeof (InvalidOperationException))]
- public void TestDefineDynamicModule7 () {
- // Called when assembly was already saved
- ab.Save ("TestDefineDynamicModule7.dll");
- ab.DefineDynamicModule ("foo", "foo.dll");
- }
- [ExpectedException (typeof (NotSupportedException))]
- public void TestDefineDynamicModule8 () {
- // Called on an assembly defined with the Run attribute
- AssemblyBuilder ab =
- domain.DefineDynamicAssembly (genAssemblyName (),
- AssemblyBuilderAccess.Run,
- tempDir);
- ab.DefineDynamicModule ("foo", "foo.dll");
- }
- public void TestDefineDynamicModule () {
- ab.DefineDynamicModule ("foo", "foo.dll");
- ab.DefineDynamicModule ("foo2", true);
- ab.DefineDynamicModule ("foo3", "foo3.dll");
- ab.DefineDynamicModule ("foo4", "foo4.dll", true);
- }
- [ExpectedException (typeof (ArgumentNullException))]
- public void TestDefineUnmanagedResource1 () {
- // Null argument
- ab.DefineUnmanagedResource ((byte[])null);
- }
- [ExpectedException (typeof (ArgumentNullException))]
- public void TestDefineUnmanagedResource2 () {
- // Null argument
- ab.DefineUnmanagedResource ((string)null);
- }
- [ExpectedException (typeof (ArgumentException))]
- public void TestDefineUnmanagedResource3 () {
- // Empty filename
- ab.DefineUnmanagedResource ("");
- }
- [ExpectedException (typeof (FileNotFoundException))]
- public void TestDefineUnmanagedResource4 () {
- // Nonexistent file
- ab.DefineUnmanagedResource ("not-exists.txt");
- }
- [ExpectedException (typeof (ArgumentNullException))]
- public void TestSetCustomAttribute1 () {
- // Null argument
- ab.SetCustomAttribute (null);
- }
- [ExpectedException (typeof (ArgumentNullException))]
- public void TestSetCustomAttribute2 () {
- // Null constructor
- ab.SetCustomAttribute (null, new byte [0]);
- }
- [ExpectedException (typeof (ArgumentNullException))]
- public void TestSetCustomAttribute3 () {
- // Null blob
- ab.SetCustomAttribute (typeof(AssemblyCompanyAttribute).GetConstructor (new Type [] { typeof (String) }), null);
- }
- public void TestSetCustomAttribute () {
- // Test common custom attributes
- ab.SetCustomAttribute (new CustomAttributeBuilder (typeof (AssemblyVersionAttribute).GetConstructor (new Type [] { typeof (string) }), new object [] { "1.2.3.4"}));
- ab.SetCustomAttribute (new CustomAttributeBuilder (typeof (AssemblyCultureAttribute).GetConstructor (new Type [] { typeof (string) }), new object [] { "bar"}));
- ab.SetCustomAttribute (new CustomAttributeBuilder (typeof (AssemblyAlgorithmIdAttribute).GetConstructor (new Type [] { typeof (AssemblyHashAlgorithm) }), new object [] { AssemblyHashAlgorithm.MD5 }));
- ab.SetCustomAttribute (new CustomAttributeBuilder (typeof (AssemblyFlagsAttribute).GetConstructor (new Type [] { typeof (uint) }), new object [] { (uint)0x0100 }));
- ab.SetCustomAttribute (new CustomAttributeBuilder (typeof (AssemblyDelaySignAttribute).GetConstructor (new Type [] { typeof (bool) }), new object [] { true }));
- ab.SetCustomAttribute (typeof (FooAttribute).GetConstructor (new Type [] {}), new byte [0]);
- ab.Save ("TestSetCustomAttribute.dll");
- /* We should read back the assembly and check the attributes ... */
- }
- // strongname generated using "sn -k unit.snk"
- static byte[] strongName = {
- 0x07, 0x02, 0x00, 0x00, 0x00, 0x24,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CD, 0x3B, 0x23, 0x87, 0x49, 0x7E, 0x40, 0x32, 0x6A, 0xD3, 0x96,
- 0x4A, 0xE5, 0x5E, 0x6E, 0x26, 0xFD, 0x8A, 0xCF, 0x7E, 0xFC, 0x37, 0xDE,
- 0x39, 0x0C, 0x53, 0x81, 0x75, 0x08, 0xAF, 0x6B, 0x39, 0x6C, 0xFB, 0xC9,
- 0x79, 0xC0, 0x9B, 0x5F, 0x34, 0x86, 0xB2, 0xDE, 0xC4, 0x19, 0x84, 0x5F,
- 0x0E, 0xED, 0x9B, 0xB8, 0xD3, 0x17, 0xDA, 0x78 };
- [Test]
- public void StrongName_MissingKeyFile_NoDelay ()
- {
- ab.SetCustomAttribute (new CustomAttributeBuilder (typeof (AssemblyKeyFileAttribute).GetConstructor (new Type [] { typeof (string) }), new object [] { "missing.snk" }));
- ab.SetCustomAttribute (new CustomAttributeBuilder (typeof (AssemblyDelaySignAttribute).GetConstructor (new Type [] { typeof (bool) }), new object [] { false }));
- ab.Save ("StrongName_MissingKeyFile_NoDelay.dll");
- string filename = Path.Combine (tempDir, "StrongName_MissingKeyFile_NoDelay.dll");
- AssemblyName check = AssemblyName.GetAssemblyName (filename);
- // no exception is thrown (file not found)
- // because it's not AssemblyBuilder.Save job to do the signing :-/
- AssertNull ("Token", check.GetPublicKeyToken ());
- }
- [Test]
- public void StrongName_KeyFile_Delay ()
- {
- string strongfile = Path.Combine (tempDir, "strongname.snk");
- using (FileStream fs = File.OpenWrite (strongfile)) {
- fs.Write (strongName, 0, strongName.Length);
- fs.Close ();
- }
- ab.SetCustomAttribute (new CustomAttributeBuilder (typeof (AssemblyKeyFileAttribute).GetConstructor (new Type [] { typeof (string) }), new object [] { strongfile }));
- ab.SetCustomAttribute (new CustomAttributeBuilder (typeof (AssemblyDelaySignAttribute).GetConstructor (new Type [] { typeof (bool) }), new object [] { true }));
- ab.Save ("StrongName_KeyFile_Delay.dll");
- string filename = Path.Combine (tempDir, "StrongName_KeyFile_Delay.dll");
- AssemblyName check = AssemblyName.GetAssemblyName (filename);
- // no public key is inserted into the assembly
- // because it's not AssemblyBuilder.Save job to do the signing :-/
- AssertNull ("Token", check.GetPublicKeyToken ());
- }
- [Test]
- public void StrongName_WithoutAttributes ()
- {
- // this demonstrate that AssemblyKeyFileAttribute (or AssemblyKeyNameAttribute)
- // aren't required to sign an assembly.
- AssemblyName an = genAssemblyName ();
- an.KeyPair = new StrongNameKeyPair (strongName);
- AssemblyBuilder ab = domain.DefineDynamicAssembly (an, AssemblyBuilderAccess.RunAndSave, tempDir);
- ab.Save ("StrongName_WithoutAttributes.dll");
- string filename = Path.Combine (tempDir, "StrongName_WithoutAttributes.dll");
- AssemblyName check = AssemblyName.GetAssemblyName (filename);
- AssertEquals ("Token", "0E-EA-7C-E6-5F-35-F2-D8", BitConverter.ToString (check.GetPublicKeyToken ()));
- }
- }
- }
|