Permalink
Browse files

2008-12-12 Rodrigo Kumpera <rkumpera@novell.com>

	* bug-389886-sre-generic-interface-instances.cs: New regression test.

	* Makefile.am: Test added.

svn path=/trunk/mono/; revision=121455
  • Loading branch information...
1 parent 65b615b commit 1aa1ddb0e8ef06ff831c67aad84c229c7dd1e713 @kumpera kumpera committed Dec 12, 2008
Showing with 124 additions and 1 deletion.
  1. +6 −0 mono/tests/ChangeLog
  2. +2 −1 mono/tests/Makefile.am
  3. +116 −0 mono/tests/bug-389886-sre-generic-interface-instances.cs
View
@@ -1,3 +1,9 @@
+2008-12-12 Rodrigo Kumpera <rkumpera@novell.com>
+
+ * bug-389886-sre-generic-interface-instances.cs: New regression test.
+
+ * Makefile.am: Test added.
+
2008-12-11 Mark Probst <mark.probst@gmail.com>
* generic-marshalbyref.2.cs: Test for calls to marshal-by-ref
View
@@ -324,7 +324,8 @@ BASE_TEST_CS_SRC= \
bug-80307.cs \
bug-415577.cs \
filter-stack.cs \
- vararg2.cs
+ vararg2.cs \
+ bug-389886-sre-generic-interface-instances.cs
if AMD64
TEST_CS_SRC = $(BASE_TEST_CS_SRC) async-exc-compilation.cs
@@ -0,0 +1,116 @@
+using System;
+using System.Threading;
+using System.Reflection;
+using System.Reflection.Emit;
+
+namespace TestApp
+{
+ class Program
+ {
+ static AssemblyBuilder assembly;
+ static ModuleBuilder module;
+ static string ASSEMBLY_NAME = "MonoTests.System.Reflection.Emit.TypeBuilderTest";
+
+ static void SetUp ()
+ {
+ AssemblyName assemblyName = new AssemblyName ();
+ assemblyName.Name = ASSEMBLY_NAME;
+
+ assembly =
+ Thread.GetDomain ().DefineDynamicAssembly (
+ assemblyName, AssemblyBuilderAccess.RunAndSave, ".");
+
+ module = assembly.DefineDynamicModule ("module1", "Module1.dll");
+ }
+
+ static int Main()
+ {
+ SetUp ();
+
+ TypeBuilder iface = module.DefineType ("IFace", TypeAttributes.Public | TypeAttributes.Interface | TypeAttributes.Abstract);
+ iface.DefineGenericParameters ("T");
+
+ TypeBuilder parent = module.DefineType ("Parent", TypeAttributes.Public);
+
+ TypeBuilder child = module.DefineType ("Child", TypeAttributes.Public, parent);
+
+ TypeBuilder main = module.DefineType ("Main", TypeAttributes.Public);
+
+ child.AddInterfaceImplementation (iface.MakeGenericType (new Type [] { typeof(int) }));
+
+ iface.DefineMethod ("Foo", MethodAttributes.Public | MethodAttributes.Abstract | MethodAttributes.Virtual, typeof(void), Type.EmptyTypes);
+
+ ConstructorBuilder parent_constructor = parent.DefineDefaultConstructor (MethodAttributes.Public);
+
+ ConstructorBuilder ctor = child.DefineConstructor (MethodAttributes.Public, CallingConventions.Standard, Type.EmptyTypes);
+ ILGenerator ig = ctor.GetILGenerator ();
+ ig.Emit (OpCodes.Ldarg_0);
+ ig.Emit (OpCodes.Call, parent_constructor);
+ ig.Emit (OpCodes.Ret);
+
+ MethodBuilder foo_mb = child.DefineMethod ("Foo", MethodAttributes.Public | MethodAttributes.Virtual, typeof (void), Type.EmptyTypes);
+ foo_mb.GetILGenerator ().Emit (OpCodes.Ret);
+
+
+ MethodBuilder main_mb = main.DefineMethod ("Main", MethodAttributes.Public | MethodAttributes.Static, typeof (void), Type.EmptyTypes);
+ ig = main_mb.GetILGenerator ();
+ ig.Emit (OpCodes.Newobj, ctor);
+ ig.Emit (OpCodes.Callvirt, foo_mb);
+ ig.Emit (OpCodes.Ret);
+
+ iface.CreateType ();
+
+ parent.CreateType ();
+
+ child.CreateType ();
+
+ Type t = main.CreateType ();
+
+ MethodInfo method = t.GetMethod ("Main");
+ method.Invoke (null, null);
+
+ /*Type gtd = typeof (A<>);
+ Type oi = gtd.MakeGenericType (gtd.GetGenericArguments ());
+
+ if (oi != gtd) {
+ Console.WriteLine ("fully open instantiation of static type not the same of the generic type definition");
+ return 1;
+ }
+
+ SetUp ();
+ TypeBuilder tb = module.DefineType ("Nullable`1", TypeAttributes.Public);
+ Type[] args = tb.DefineGenericParameters ("T");
+ Type type = tb.MakeGenericType (args);
+
+ if (type == tb) {
+ Console.WriteLine ("fully open instantiation of TypeBuilder is the same of the TypeBuilder");
+ return 2;
+ }
+
+ Type res = tb.CreateType ();
+ Type oires = res.MakeGenericType (res.GetGenericArguments ());
+
+ if (res != oires) {
+ Console.WriteLine ("fully open instantiation not the same of the generic type definition for the TypeBuilder created type");
+ return 3;
+ }
+
+ try {
+ type.GetConstructors ();
+ } catch (Exception e) {
+ Console.WriteLine ("fully open instantiation of TypeBuilder must have GetConstructors working {0}", e);
+ return 4;
+ }
+
+
+ try {
+ oires.GetConstructors ();
+ } catch (Exception e) {
+ Console.WriteLine ("fully open instantiation of the TypeBuilder created type must have GetConstructors working {0}", e);
+ return 5;
+ }*/
+
+ return 0;
+ }
+ }
+}

0 comments on commit 1aa1ddb

Please sign in to comment.