Add test
authorMiguel de Icaza <miguel@gnome.org>
Sat, 17 Nov 2007 21:28:16 +0000 (21:28 -0000)
committerMiguel de Icaza <miguel@gnome.org>
Sat, 17 Nov 2007 21:28:16 +0000 (21:28 -0000)
svn path=/trunk/mono/; revision=89876

mono/tests/sighelpermod.cs [new file with mode: 0644]

diff --git a/mono/tests/sighelpermod.cs b/mono/tests/sighelpermod.cs
new file mode 100644 (file)
index 0000000..261a9a1
--- /dev/null
@@ -0,0 +1,53 @@
+//
+// Not sure how we could automate this test, for now you have to look at the
+// generated output (b.dll) and see that the signature for the method called
+// (the one with no name :-) looks like this:
+//
+//  call       instance int32 (bool,
+//             class System.String modreq([mscorlib]System.Runtime.CompilerServices.IsBoxed),
+//             unsigned int8 modopt([mscorlib]System.Runtime.CompilerServices.IsConst),
+//             int32 modopt([mscorlib]System.Runtime.CompilerServices.IsConst),
+//             int64 modopt([mscorlib]System.Runtime.CompilerServices.IsConst))
+
+    
+using System;
+using System.Reflection;
+using System.Reflection.Emit;
+using System.Threading;
+
+public class EmitHelloWorld{
+    static void Main(string[] args)
+    {
+        AssemblyName an = new AssemblyName();
+        an.Name = "HelloWorld";
+        AssemblyBuilder ab = Thread.GetDomain().DefineDynamicAssembly(an, AssemblyBuilderAccess.RunAndSave);
+        ModuleBuilder module = ab.DefineDynamicModule("b.dll");
+        TypeBuilder tb = module.DefineType("type", TypeAttributes.Public | TypeAttributes.Class);
+        MethodBuilder mb = tb.DefineMethod("test",
+                                          MethodAttributes.HideBySig | MethodAttributes.Static |
+                                          MethodAttributes.Public, typeof(void), null);
+        ILGenerator ig = mb.GetILGenerator();
+
+       //
+       // This is the actual test:
+       //   Generate a method signature that contains modopts and modreqs
+       //   and call that.  It has no name or anything, not sure how this
+       //   is actually used, but we at least generate the stuff
+       //
+       SignatureHelper sh = SignatureHelper.GetMethodSigHelper (module, CallingConventions.HasThis, typeof(int));
+       sh.AddArgument (typeof (bool));
+       Type [] req = new Type [] { typeof (System.Runtime.CompilerServices.IsBoxed) };
+       sh.AddArgument (typeof (string), req, null);
+       Type [] opt = new Type [] { typeof (System.Runtime.CompilerServices.IsConst) };
+       sh.AddArgument (typeof (byte), null, opt);
+       sh.AddArgument (typeof (int), null, opt);
+       sh.AddArgument (typeof (long), null, opt);
+       ig.Emit (OpCodes.Call, sh);
+
+        ig.Emit(OpCodes.Ret);
+
+        tb.CreateType();
+
+       ab.Save ("b.dll");
+     }
+}
\ No newline at end of file