Switch to compiler-tester
[mono.git] / mcs / class / corlib / Test / System.Reflection.Emit / MethodRentalTest.cs
1 //
2 // MethodRentalTest.cs - NUnit Test Cases for the MethodRental class
3 //
4 // Zoltan Varga (vargaz@freemail.hu)
5 //
6 // (C) Ximian, Inc.  http://www.ximian.com
7
8 using System;
9 using System.Threading;
10 using System.Reflection;
11 using System.Reflection.Emit;
12
13 using NUnit.Framework;
14
15 namespace MonoTests.System.Reflection.Emit
16 {
17         [TestFixture]
18         public class MethodRentalTest : Assertion
19         {       
20                 private TypeBuilder genClass;
21                 private ModuleBuilder module;
22                 private static int methodIndexer = 0;
23                 private static int typeIndexer = 0;
24
25                 [SetUp]
26                 protected void SetUp ()
27                 {
28                         AssemblyName assemblyName = new AssemblyName();
29                         assemblyName.Name = "MonoTests.System.Reflection.Emit.MethodRentalTest";
30
31                         AssemblyBuilder assembly = Thread.GetDomain().DefineDynamicAssembly(
32                                 assemblyName, AssemblyBuilderAccess.Run);
33
34                         module = assembly.DefineDynamicModule("module1");
35                 
36                         genClass = module.DefineType(genTypeName (), 
37                                  TypeAttributes.Public);
38                 }
39
40                 [Test]
41                 [ExpectedException (typeof (ArgumentException))]
42                 public void SwapMethodBodyInvalidMethodSize ()
43                 {
44                         MethodRental.SwapMethodBody (null, 0, IntPtr.Zero, 0, 0);
45                 }
46
47                 [Test]
48                 [ExpectedException (typeof (ArgumentNullException))]
49                 public void SwapMethodBodyNullType ()
50                 {
51                         MethodRental.SwapMethodBody (null, 0, IntPtr.Zero, 1, 0);
52                 }
53
54                 [Test]
55                 [ExpectedException (typeof (NotSupportedException))]
56                 public void SwapMethodBodyUnfinishedType ()
57                 {
58                         MethodRental.SwapMethodBody (genClass, 0, IntPtr.Zero, 1, 0);
59                 }
60
61                 // Return a unique method name
62                 private string genMethodName ()
63                 {
64                         return "m" + (methodIndexer++);
65                 }
66
67                 // Return a unique type name
68                 private string genTypeName ()
69                 {
70                         return "class" + (typeIndexer++);
71                 }
72         }
73 }