Ver código fonte

2004-09-09 Zoltan Varga <[email protected]>

	* ModuleBuilderTest.cs: Add test for lookup of global methods.

svn path=/trunk/mcs/; revision=33635
Zoltan Varga 21 anos atrás
pai
commit
150819ceea

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

@@ -1,3 +1,7 @@
+2004-09-09  Zoltan Varga  <[email protected]>
+
+	* ModuleBuilderTest.cs: Add test for lookup of global methods.
+
 2004-08-29  Nick Drochak <[email protected]>
 
 	* TypeBuilderTestTest.cs: Call EnumBuilder.CreateType()	before you call

+ 19 - 0
mcs/class/corlib/Test/System.Reflection.Emit/ModuleBuilderTest.cs

@@ -15,6 +15,7 @@ using System.Reflection.Emit;
 using System.IO;
 using System.Collections;
 using System.Diagnostics.SymbolStore;
+using System.Runtime.InteropServices;
 
 using NUnit.Framework;
 
@@ -107,6 +108,24 @@ public class ModuleBuilderTest : Assertion
 		AssertEquals (module.GetField ("DATA_PRIVATE", BindingFlags.NonPublic | BindingFlags.Static) != null, true);
 	}
 
+	[Test]
+	public void TestGlobalMethods () {
+		AssemblyName an = new AssemblyName();
+		an.Name = "TestGlobalMethods";
+		AssemblyBuilder builder = 
+			AppDomain.CurrentDomain.DefineDynamicAssembly(an, AssemblyBuilderAccess.Run);
+		ModuleBuilder module = builder.DefineDynamicModule("MessageModule");
+		MethodBuilder method = module.DefinePInvokeMethod("printf", "libc.so",
+														  MethodAttributes.PinvokeImpl | MethodAttributes.Static | MethodAttributes.Public, 
+														  CallingConventions.Standard, typeof(void), new Type[]{typeof(string)}, CallingConvention.Winapi, 
+														  CharSet.Auto);
+		method.SetImplementationFlags (MethodImplAttributes.PreserveSig | 
+									   method.GetMethodImplementationFlags());
+		module.CreateGlobalFunctions();
+
+		Assert (module.GetMethod ("printf") != null);
+	}
+
 	[Test]
 	public void DuplicateSymbolDocument () {
 		AssemblyName assemblyName = new AssemblyName();