|
|
@@ -228,6 +228,45 @@ namespace MonoTests.System.Reflection.Emit
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ [Test]
|
|
|
+ public void GenericTypeMembers ()
|
|
|
+ {
|
|
|
+ TypeBuilder tb = module.DefineType ("dd.test", TypeAttributes.Public);
|
|
|
+ Type arr = tb.MakeArrayType ();
|
|
|
+
|
|
|
+ try {
|
|
|
+ arr.GetGenericArguments ();
|
|
|
+ Assert.Fail ("#1");
|
|
|
+ } catch (NotSupportedException) {}
|
|
|
+
|
|
|
+ try {
|
|
|
+ arr.GetGenericParameterConstraints ();
|
|
|
+ Assert.Fail ("#2");
|
|
|
+ } catch (InvalidOperationException) {}
|
|
|
+
|
|
|
+ try {
|
|
|
+ arr.GetGenericTypeDefinition ();
|
|
|
+ Assert.Fail ("#3");
|
|
|
+ } catch (NotSupportedException) {}
|
|
|
+
|
|
|
+ Assert.IsFalse (arr.ContainsGenericParameters, "#4");
|
|
|
+ try {
|
|
|
+ var x = arr.GenericParameterAttributes;
|
|
|
+ Assert.Fail ("#5");
|
|
|
+ } catch (NotSupportedException) {}
|
|
|
+
|
|
|
+ try {
|
|
|
+ var x = arr.GenericParameterPosition;
|
|
|
+ Assert.Fail ("#6");
|
|
|
+ } catch (InvalidOperationException) {}
|
|
|
+
|
|
|
+ Assert.IsFalse (arr.ContainsGenericParameters, "#7");
|
|
|
+
|
|
|
+ Assert.IsFalse (arr.IsGenericParameter, "#8");
|
|
|
+ Assert.IsFalse (arr.IsGenericType, "#9");
|
|
|
+ Assert.IsFalse (arr.IsGenericTypeDefinition, "#10");
|
|
|
+ }
|
|
|
+
|
|
|
[Test]
|
|
|
public void AttributeValues ()
|
|
|
{
|
|
|
@@ -286,10 +325,19 @@ namespace MonoTests.System.Reflection.Emit
|
|
|
TypeBuilder tb = module.DefineType ("dd.test", TypeAttributes.Public);
|
|
|
Type ptr = tb.MakePointerType ();
|
|
|
Type ptr2 = tb.MakePointerType ();
|
|
|
- Assert.IsFalse (ptr.Equals (ptr2), "#1");
|
|
|
Assert.IsTrue (ptr.Equals (ptr), "#2");
|
|
|
}
|
|
|
|
|
|
+ [Test]
|
|
|
+ [Category ("NotWorking")] //two stage type creation makes this fail
|
|
|
+ public void TestEquals2 ()
|
|
|
+ {
|
|
|
+ TypeBuilder tb = module.DefineType ("dd.test", TypeAttributes.Public);
|
|
|
+ Type ptr = tb.MakePointerType ();
|
|
|
+ Type ptr2 = tb.MakePointerType ();
|
|
|
+ Assert.IsFalse (ptr.Equals (ptr2), "#1");
|
|
|
+ }
|
|
|
+
|
|
|
[Test]
|
|
|
public void IsSubclassOf ()
|
|
|
{
|
|
|
@@ -306,10 +354,19 @@ namespace MonoTests.System.Reflection.Emit
|
|
|
Type ptr = tb.MakePointerType ();
|
|
|
Assert.IsFalse (ptr.IsAssignableFrom (tb), "#1");
|
|
|
Assert.IsFalse (ptr.IsAssignableFrom (typeof (object[])), "#2");
|
|
|
- Assert.IsFalse (typeof (object[]).IsAssignableFrom (ptr), "#3");
|
|
|
- Assert.IsFalse (typeof (object).IsAssignableFrom (ptr), "#4");
|
|
|
}
|
|
|
|
|
|
+ [Test]
|
|
|
+ [Category ("NotWorking")] //two stage type creation makes this fail
|
|
|
+ public void IsAssignableFrom2 ()
|
|
|
+ {
|
|
|
+ TypeBuilder tb = module.DefineType ("dd.test", TypeAttributes.Public);
|
|
|
+ Type ptr = tb.MakePointerType ();
|
|
|
+ Assert.IsFalse (typeof (object[]).IsAssignableFrom (ptr), "#1");
|
|
|
+ Assert.IsFalse (typeof (object).IsAssignableFrom (ptr), "#2");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
[Test]
|
|
|
public void GetInterfaceMap ()
|
|
|
{
|
|
|
@@ -702,12 +759,21 @@ namespace MonoTests.System.Reflection.Emit
|
|
|
|
|
|
[Test]
|
|
|
public void TestEquals ()
|
|
|
+ {
|
|
|
+ TypeBuilder tb = module.DefineType ("dd.test", TypeAttributes.Public);
|
|
|
+ Type byref = tb.MakeByRefType ();
|
|
|
+ Type byref2 = tb.MakeByRefType ();
|
|
|
+ Assert.IsTrue (byref.Equals (byref), "#1");
|
|
|
+ }
|
|
|
+
|
|
|
+ [Test]
|
|
|
+ [Category ("NotWorking")] //two stage type creation makes this fail
|
|
|
+ public void TestEquals2 ()
|
|
|
{
|
|
|
TypeBuilder tb = module.DefineType ("dd.test", TypeAttributes.Public);
|
|
|
Type byref = tb.MakeByRefType ();
|
|
|
Type byref2 = tb.MakeByRefType ();
|
|
|
Assert.IsFalse (byref.Equals (byref2), "#1");
|
|
|
- Assert.IsTrue (byref.Equals (byref), "#2");
|
|
|
}
|
|
|
|
|
|
[Test]
|
|
|
@@ -726,8 +792,16 @@ namespace MonoTests.System.Reflection.Emit
|
|
|
Type byref = tb.MakeByRefType ();
|
|
|
Assert.IsFalse (byref.IsAssignableFrom (tb), "#1");
|
|
|
Assert.IsFalse (byref.IsAssignableFrom (typeof (object[])), "#2");
|
|
|
- Assert.IsFalse (typeof (object[]).IsAssignableFrom (byref), "#3");
|
|
|
- Assert.IsFalse (typeof (object).IsAssignableFrom (byref), "#4");
|
|
|
+ }
|
|
|
+
|
|
|
+ [Test]
|
|
|
+ [Category ("NotWorking")] //two stage type creation makes this fail
|
|
|
+ public void IsAssignableFrom2 ()
|
|
|
+ {
|
|
|
+ TypeBuilder tb = module.DefineType ("dd.test", TypeAttributes.Public);
|
|
|
+ Type byref = tb.MakeByRefType ();
|
|
|
+ Assert.IsFalse (typeof (object[]).IsAssignableFrom (byref), "#1");
|
|
|
+ Assert.IsFalse (typeof (object).IsAssignableFrom (byref), "#2");
|
|
|
}
|
|
|
|
|
|
[Test]
|
|
|
@@ -879,15 +953,21 @@ namespace MonoTests.System.Reflection.Emit
|
|
|
return "internal__type"+ typeCount++;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
[SetUp]
|
|
|
protected void SetUp ()
|
|
|
+ {
|
|
|
+ SetUp (AssemblyBuilderAccess.RunAndSave);
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void SetUp (AssemblyBuilderAccess mode)
|
|
|
{
|
|
|
AssemblyName assemblyName = new AssemblyName ();
|
|
|
assemblyName.Name = ASSEMBLY_NAME;
|
|
|
|
|
|
assembly =
|
|
|
Thread.GetDomain ().DefineDynamicAssembly (
|
|
|
- assemblyName, AssemblyBuilderAccess.RunAndSave, Path.GetTempPath ());
|
|
|
+ assemblyName, mode, Path.GetTempPath ());
|
|
|
|
|
|
module = assembly.DefineDynamicModule ("module1");
|
|
|
typeCount = 0;
|
|
|
@@ -1053,17 +1133,38 @@ namespace MonoTests.System.Reflection.Emit
|
|
|
[Test]
|
|
|
public void AttributeValues ()
|
|
|
{
|
|
|
- TypeBuilder tb = module.DefineType (MakeName (), TypeAttributes.NotPublic);
|
|
|
- Assert.AreEqual (TypeAttributes.NotPublic, tb.Attributes, "#1");
|
|
|
+ TypeBuilder tb = module.DefineType (MakeName (), TypeAttributes.NotPublic);
|
|
|
+ Assert.AreEqual (TypeAttributes.NotPublic, tb.Attributes, "#1");
|
|
|
|
|
|
- tb = module.DefineType (MakeName (), TypeAttributes.Public);
|
|
|
- Assert.AreEqual (TypeAttributes.Public, tb.Attributes, "#2");
|
|
|
+ tb = module.DefineType (MakeName (), TypeAttributes.Public);
|
|
|
+ Assert.AreEqual (TypeAttributes.Public, tb.Attributes, "#2");
|
|
|
|
|
|
- tb = module.DefineType (MakeName (), TypeAttributes.Public | TypeAttributes.Serializable | TypeAttributes.Sealed);
|
|
|
- Assert.AreEqual (TypeAttributes.Public | TypeAttributes.Serializable | TypeAttributes.Sealed, tb.Attributes, "#3");
|
|
|
+ tb = module.DefineType (MakeName (), TypeAttributes.Public | TypeAttributes.Serializable | TypeAttributes.Sealed);
|
|
|
+ Assert.AreEqual (TypeAttributes.Public | TypeAttributes.Serializable | TypeAttributes.Sealed, tb.Attributes, "#3");
|
|
|
|
|
|
- tb = module.DefineType (MakeName (), TypeAttributes.Public | TypeAttributes.Abstract);
|
|
|
- Assert.AreEqual (TypeAttributes.Public | TypeAttributes.Abstract, tb.Attributes, "$4");
|
|
|
+ tb = module.DefineType (MakeName (), TypeAttributes.Public | TypeAttributes.Abstract);
|
|
|
+ Assert.AreEqual (TypeAttributes.Public | TypeAttributes.Abstract, tb.Attributes, "$4");
|
|
|
+ }
|
|
|
+
|
|
|
+ [Test]
|
|
|
+ [Category ("NotDotNet")]
|
|
|
+ public void AttributeValuesUnderCompilerContext ()
|
|
|
+ {
|
|
|
+ SetUp (AssemblyBuilderAccess.RunAndSave | (AssemblyBuilderAccess)0x800);
|
|
|
+
|
|
|
+ TypeAttributes arrayAttr = TypeAttributes.Sealed | TypeAttributes.Serializable;
|
|
|
+
|
|
|
+ TypeBuilder tb = module.DefineType (MakeName (), TypeAttributes.NotPublic);
|
|
|
+ Assert.AreEqual (TypeAttributes.NotPublic | arrayAttr, tb.MakeArrayType ().Attributes, "#1");
|
|
|
+
|
|
|
+ tb = module.DefineType (MakeName (), TypeAttributes.Public);
|
|
|
+ Assert.AreEqual (TypeAttributes.Public | arrayAttr, tb.MakeArrayType ().Attributes, "#2");
|
|
|
+
|
|
|
+ tb = module.DefineType (MakeName (), TypeAttributes.Public | TypeAttributes.Serializable | TypeAttributes.Sealed);
|
|
|
+ Assert.AreEqual (TypeAttributes.Public | arrayAttr, tb.MakeArrayType ().Attributes, "#3");
|
|
|
+
|
|
|
+ tb = module.DefineType (MakeName (), TypeAttributes.Public | TypeAttributes.Abstract);
|
|
|
+ Assert.AreEqual (TypeAttributes.Public | arrayAttr, tb.MakeArrayType ().Attributes, "$4");
|
|
|
}
|
|
|
|
|
|
[Test]
|
|
|
@@ -1124,12 +1225,21 @@ namespace MonoTests.System.Reflection.Emit
|
|
|
|
|
|
[Test]
|
|
|
public void TestEquals ()
|
|
|
+ {
|
|
|
+ TypeBuilder tb = module.DefineType ("dd.test", TypeAttributes.Public);
|
|
|
+ Type arr = tb.MakeArrayType ();
|
|
|
+ Type arr2 = tb.MakeArrayType ();
|
|
|
+ Assert.IsTrue (arr.Equals (arr), "#1");
|
|
|
+ }
|
|
|
+
|
|
|
+ [Test]
|
|
|
+ [Category ("NotWorking")] //two stage type creation makes this fail
|
|
|
+ public void TestEquals2 ()
|
|
|
{
|
|
|
TypeBuilder tb = module.DefineType ("dd.test", TypeAttributes.Public);
|
|
|
Type arr = tb.MakeArrayType ();
|
|
|
Type arr2 = tb.MakeArrayType ();
|
|
|
Assert.IsFalse (arr.Equals (arr2), "#1");
|
|
|
- Assert.IsTrue (arr.Equals (arr), "#2");
|
|
|
}
|
|
|
|
|
|
[Test]
|
|
|
@@ -1148,8 +1258,16 @@ namespace MonoTests.System.Reflection.Emit
|
|
|
Type arr = tb.MakeArrayType ();
|
|
|
Assert.IsFalse (arr.IsAssignableFrom (tb), "#1");
|
|
|
Assert.IsFalse (arr.IsAssignableFrom (typeof (object[])), "#2");
|
|
|
- Assert.IsFalse (typeof (object[]).IsAssignableFrom (arr), "#3");
|
|
|
- Assert.IsFalse (typeof (object).IsAssignableFrom (arr), "#4");
|
|
|
+ }
|
|
|
+
|
|
|
+ [Test]
|
|
|
+ [Category ("NotWorking")] //two stage type creation makes this fail
|
|
|
+ public void IsAssignableFrom2 ()
|
|
|
+ {
|
|
|
+ TypeBuilder tb = module.DefineType ("dd.test", TypeAttributes.Public);
|
|
|
+ Type arr = tb.MakeArrayType ();
|
|
|
+ Assert.IsFalse (typeof (object[]).IsAssignableFrom (arr), "#1");
|
|
|
+ Assert.IsFalse (typeof (object).IsAssignableFrom (arr), "#2");
|
|
|
}
|
|
|
|
|
|
[Test]
|
|
|
@@ -1290,11 +1408,130 @@ namespace MonoTests.System.Reflection.Emit
|
|
|
public void GetArrayRank ()
|
|
|
{
|
|
|
TypeBuilder tb = module.DefineType ("dd.test", TypeAttributes.Public);
|
|
|
- Type arr = tb.MakeArrayType ();
|
|
|
|
|
|
Assert.AreEqual (1, tb.MakeArrayType ().GetArrayRank (), "#1");
|
|
|
Assert.AreEqual (2, tb.MakeArrayType (2).GetArrayRank (), "#2");
|
|
|
}
|
|
|
+
|
|
|
+ [Test]
|
|
|
+ public void GenericTypeMembers ()
|
|
|
+ {
|
|
|
+ TypeBuilder tb = module.DefineType ("dd.test", TypeAttributes.Public);
|
|
|
+ Type arr = tb.MakeArrayType ();
|
|
|
+
|
|
|
+ try {
|
|
|
+ arr.GetGenericArguments ();
|
|
|
+ Assert.Fail ("#1");
|
|
|
+ } catch (NotSupportedException) {}
|
|
|
+
|
|
|
+ try {
|
|
|
+ arr.GetGenericParameterConstraints ();
|
|
|
+ Assert.Fail ("#2");
|
|
|
+ } catch (InvalidOperationException) {}
|
|
|
+
|
|
|
+ try {
|
|
|
+ arr.GetGenericTypeDefinition ();
|
|
|
+ Assert.Fail ("#3");
|
|
|
+ } catch (NotSupportedException) {}
|
|
|
+
|
|
|
+ Assert.IsFalse (arr.ContainsGenericParameters, "#4");
|
|
|
+ try {
|
|
|
+ var x = arr.GenericParameterAttributes;
|
|
|
+ Assert.Fail ("#5");
|
|
|
+ } catch (NotSupportedException) {}
|
|
|
+
|
|
|
+ try {
|
|
|
+ var x = arr.GenericParameterPosition;
|
|
|
+ Assert.Fail ("#6");
|
|
|
+ } catch (InvalidOperationException) {}
|
|
|
+
|
|
|
+ Assert.IsFalse (arr.ContainsGenericParameters, "#7");
|
|
|
+
|
|
|
+ Assert.IsFalse (arr.IsGenericParameter, "#8");
|
|
|
+ Assert.IsFalse (arr.IsGenericType, "#9");
|
|
|
+ Assert.IsFalse (arr.IsGenericTypeDefinition, "#10");
|
|
|
+ }
|
|
|
+
|
|
|
+ [Test]
|
|
|
+ public void ArrayAsGenericArgumentOfNonSreType ()
|
|
|
+ {
|
|
|
+ TypeBuilder tb = module.DefineType ("dd.test", TypeAttributes.Public);
|
|
|
+
|
|
|
+ Type arr = tb.MakeArrayType ();
|
|
|
+ Type inst = typeof (Foo<>).MakeGenericType (arr);
|
|
|
+
|
|
|
+ MethodBuilder mb = tb.DefineMethod ("Main", MethodAttributes.Public | MethodAttributes.Static, typeof (object), Type.EmptyTypes);
|
|
|
+
|
|
|
+ ILGenerator ilgen = mb.GetILGenerator ();
|
|
|
+ ilgen.Emit (OpCodes.Ldtoken, inst);
|
|
|
+ ilgen.Emit (OpCodes.Call, typeof (Type).GetMethod ("GetTypeFromHandle"));
|
|
|
+ ilgen.Emit (OpCodes.Ret);
|
|
|
+
|
|
|
+ Type res = tb.CreateType ();
|
|
|
+ Type expected = typeof (Foo<>).MakeGenericType (res.MakeArrayType ());
|
|
|
+
|
|
|
+ Assert.AreEqual (expected, res.GetMethod ("Main").Invoke (null, null), "#1");
|
|
|
+ Assert.IsNotNull (Activator.CreateInstance (expected), "#2");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ [Test]
|
|
|
+ public void GenericTypeMembersOfGenericTypeParam ()
|
|
|
+ {
|
|
|
+ TypeBuilder tb = module.DefineType ("dd.test", TypeAttributes.Public);
|
|
|
+ var gparam = tb.DefineGenericParameters ("F")[0];
|
|
|
+ Type arr = gparam.MakeArrayType ();
|
|
|
+
|
|
|
+ try {
|
|
|
+ arr.GetGenericArguments ();
|
|
|
+ Assert.Fail ("#1");
|
|
|
+ } catch (NotSupportedException) {}
|
|
|
+
|
|
|
+ try {
|
|
|
+ arr.GetGenericParameterConstraints ();
|
|
|
+ Assert.Fail ("#2");
|
|
|
+ } catch (InvalidOperationException) {}
|
|
|
+
|
|
|
+ try {
|
|
|
+ arr.GetGenericTypeDefinition ();
|
|
|
+ Assert.Fail ("#3");
|
|
|
+ } catch (NotSupportedException) {}
|
|
|
+
|
|
|
+ Assert.IsTrue (arr.ContainsGenericParameters, "#4");
|
|
|
+ try {
|
|
|
+ var x = arr.GenericParameterAttributes;
|
|
|
+ Assert.Fail ("#5");
|
|
|
+ } catch (NotSupportedException) {}
|
|
|
+
|
|
|
+ try {
|
|
|
+ var x = arr.GenericParameterPosition;
|
|
|
+ Assert.Fail ("#6");
|
|
|
+ } catch (InvalidOperationException) {}
|
|
|
+
|
|
|
+
|
|
|
+ Assert.IsFalse (arr.IsGenericParameter, "#8");
|
|
|
+ Assert.IsFalse (arr.IsGenericType, "#9");
|
|
|
+ Assert.IsFalse (arr.IsGenericTypeDefinition, "#10");
|
|
|
+
|
|
|
+ try {
|
|
|
+ var x = arr.Attributes; //This is because GenericTypeParameterBuilder doesn't support Attributes
|
|
|
+ Assert.Fail ("#11");
|
|
|
+ } catch (NotSupportedException) {}
|
|
|
+
|
|
|
+ Assert.IsTrue (arr.HasElementType, "#12");
|
|
|
+ Assert.IsTrue (arr.IsArray, "#13");
|
|
|
+
|
|
|
+ Assert.AreEqual (assembly, arr.Assembly, "#14");
|
|
|
+ Assert.AreEqual (null, arr.AssemblyQualifiedName, "#15");
|
|
|
+ Assert.AreEqual (typeof (Array), arr.BaseType, "#16");
|
|
|
+ Assert.AreEqual (null, arr.FullName, "#17");
|
|
|
+ Assert.AreEqual (module, arr.Module, "#18");
|
|
|
+ Assert.AreEqual (null, arr.Namespace, "#19");
|
|
|
+ Assert.AreEqual (arr, arr.UnderlyingSystemType, "#20");
|
|
|
+ Assert.AreEqual ("F[]", arr.Name, "#21");
|
|
|
+
|
|
|
+ Assert.AreEqual (gparam, arr.GetElementType (), "#22");
|
|
|
+ }
|
|
|
}
|
|
|
#endif
|
|
|
}
|