You've already forked linux-packaging-mono
Imported Upstream version 4.3.2.467
Former-commit-id: 9c2cb47f45fa221e661ab616387c9cda183f283d
This commit is contained in:
@@ -783,19 +783,8 @@ public class AssemblyBuilderTest
|
||||
try {
|
||||
ab.Save ("lib.dll");
|
||||
Assert.Fail ("#A1");
|
||||
#if NET_4_0
|
||||
} catch (CultureNotFoundException ex) {
|
||||
}
|
||||
#else
|
||||
} catch (ArgumentException ex) {
|
||||
// Culture name doesnotexist is not supported
|
||||
Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#A2");
|
||||
Assert.IsNull (ex.InnerException, "#A3");
|
||||
Assert.IsNotNull (ex.Message, "#A4");
|
||||
Assert.IsTrue (ex.Message.IndexOf ("doesnotexist") != -1, "#A5");
|
||||
Assert.AreEqual ("name", ex.ParamName, "#A6");
|
||||
}
|
||||
#endif
|
||||
|
||||
ab = AppDomain.CurrentDomain.DefineDynamicAssembly (aname,
|
||||
AssemblyBuilderAccess.RunAndSave, tempDir);
|
||||
@@ -811,19 +800,8 @@ public class AssemblyBuilderTest
|
||||
try {
|
||||
ab.Save ("lib.dll");
|
||||
Assert.Fail ("#B1");
|
||||
#if NET_4_0
|
||||
} catch (CultureNotFoundException ex) {
|
||||
}
|
||||
#else
|
||||
} catch (ArgumentException ex) {
|
||||
// Culture name neutral is not supported
|
||||
Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
|
||||
Assert.IsNull (ex.InnerException, "#B3");
|
||||
Assert.IsNotNull (ex.Message, "#B4");
|
||||
Assert.IsTrue (ex.Message.IndexOf ("neutral") != -1, "#B5");
|
||||
Assert.AreEqual ("name", ex.ParamName, "#B6");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
[Test] // DefineVersionInfoResource ()
|
||||
@@ -905,19 +883,8 @@ public class AssemblyBuilderTest
|
||||
try {
|
||||
ab.Save ("lib.dll");
|
||||
Assert.Fail ("#A1");
|
||||
#if NET_4_0
|
||||
} catch (CultureNotFoundException ex) {
|
||||
}
|
||||
#else
|
||||
} catch (ArgumentException ex) {
|
||||
// Culture name doesnotexist is not supported
|
||||
Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#A2");
|
||||
Assert.IsNull (ex.InnerException, "#A3");
|
||||
Assert.IsNotNull (ex.Message, "#A4");
|
||||
Assert.IsTrue (ex.Message.IndexOf ("doesnotexist") != -1, "#A5");
|
||||
Assert.AreEqual ("name", ex.ParamName, "#A6");
|
||||
}
|
||||
#endif
|
||||
|
||||
ab = AppDomain.CurrentDomain.DefineDynamicAssembly (aname,
|
||||
AssemblyBuilderAccess.RunAndSave, tempDir);
|
||||
@@ -933,19 +900,8 @@ public class AssemblyBuilderTest
|
||||
try {
|
||||
ab.Save ("lib.dll");
|
||||
Assert.Fail ("#B1");
|
||||
#if NET_4_0
|
||||
} catch (CultureNotFoundException ex) {
|
||||
}
|
||||
#else
|
||||
} catch (ArgumentException ex) {
|
||||
// Culture name neutral is not supported
|
||||
Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
|
||||
Assert.IsNull (ex.InnerException, "#B3");
|
||||
Assert.IsNotNull (ex.Message, "#B4");
|
||||
Assert.IsTrue (ex.Message.IndexOf ("neutral") != -1, "#B5");
|
||||
Assert.AreEqual ("name", ex.ParamName, "#B6");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
[Test] // DefineVersionInfoResource (String, String, String, String, String)
|
||||
@@ -1429,10 +1385,8 @@ public class AssemblyBuilderTest
|
||||
string FxVersion;
|
||||
#if MOBILE
|
||||
FxVersion = "2.0.5.0;";
|
||||
#elif NET_4_0
|
||||
FxVersion = "4.0.0.0;";
|
||||
#else
|
||||
FxVersion = "2.0.0.0;";
|
||||
FxVersion = "4.0.0.0;";
|
||||
#endif
|
||||
Assert.AreEqual (new Version (FxVersion), refs [0].Version, "#D2:Version");
|
||||
Assert.AreEqual (AssemblyVersionCompatibility.SameMachine,
|
||||
|
@@ -523,14 +523,7 @@ namespace MonoTests.System.Reflection.Emit
|
||||
Assert.IsFalse (ptr.IsGenericType, "#9");
|
||||
Assert.IsFalse (ptr.IsGenericTypeDefinition, "#10");
|
||||
|
||||
#if NET_4_0
|
||||
Assert.AreEqual (TypeAttributes.Public, ptr.Attributes, "#11");
|
||||
#else
|
||||
try {
|
||||
var x = ptr.Attributes; //This is because GenericTypeParameterBuilder doesn't support Attributes
|
||||
Assert.Fail ("#11");
|
||||
} catch (NotSupportedException) {}
|
||||
#endif
|
||||
|
||||
Assert.IsTrue (ptr.HasElementType, "#12");
|
||||
Assert.IsTrue (ptr.IsPointer, "#13");
|
||||
@@ -1034,14 +1027,7 @@ namespace MonoTests.System.Reflection.Emit
|
||||
Assert.IsFalse (byref.IsGenericTypeDefinition, "#10");
|
||||
|
||||
|
||||
#if NET_4_0
|
||||
Assert.AreEqual (TypeAttributes.Public, byref.Attributes, "#11");
|
||||
#else
|
||||
try {
|
||||
var x = byref.Attributes; //This is because GenericTypeParameterBuilder doesn't support Attributes
|
||||
Assert.Fail ("#11");
|
||||
} catch (NotSupportedException) {}
|
||||
#endif
|
||||
|
||||
Assert.IsTrue (byref.HasElementType, "#12");
|
||||
Assert.IsTrue (byref.IsByRef, "#13");
|
||||
@@ -1663,14 +1649,7 @@ namespace MonoTests.System.Reflection.Emit
|
||||
Assert.IsFalse (arr.IsGenericType, "#9");
|
||||
Assert.IsFalse (arr.IsGenericTypeDefinition, "#10");
|
||||
|
||||
#if NET_4_0
|
||||
Assert.AreEqual (TypeAttributes.Public, arr.Attributes, "#11");
|
||||
#else
|
||||
try {
|
||||
var x = arr.Attributes; //This is because GenericTypeParameterBuilder doesn't support Attributes
|
||||
Assert.Fail ("#11");
|
||||
} catch (NotSupportedException) {}
|
||||
#endif
|
||||
|
||||
Assert.IsTrue (arr.HasElementType, "#12");
|
||||
Assert.IsTrue (arr.IsArray, "#13");
|
||||
|
@@ -199,7 +199,6 @@ namespace MonoTests.System.Reflection.Emit
|
||||
_fieldName);
|
||||
}
|
||||
|
||||
#if NET_4_0
|
||||
[Test]
|
||||
public void GetEnumUnderlyingType ()
|
||||
{
|
||||
@@ -207,7 +206,6 @@ namespace MonoTests.System.Reflection.Emit
|
||||
|
||||
Assert.AreEqual (_enumType, @enum.GetEnumUnderlyingType ());
|
||||
}
|
||||
#endif
|
||||
|
||||
[Test]
|
||||
public void TestFindMembersComplete ()
|
||||
|
@@ -77,14 +77,7 @@ namespace MonoTests.System.Reflection.Emit
|
||||
Assert.Fail ("#11");
|
||||
} catch (NotSupportedException) {}
|
||||
|
||||
#if NET_4_0
|
||||
Assert.AreEqual (TypeAttributes.Public, gparam.Attributes, "#12");
|
||||
#else
|
||||
try {
|
||||
var x = gparam.Attributes;
|
||||
Assert.Fail ("#12");
|
||||
} catch (NotSupportedException) {}
|
||||
#endif
|
||||
Assert.IsFalse (gparam.HasElementType, "#13");
|
||||
Assert.IsFalse (gparam.IsArray, "#14");
|
||||
Assert.IsFalse (gparam.IsByRef, "#15");
|
||||
@@ -349,9 +342,6 @@ namespace MonoTests.System.Reflection.Emit
|
||||
Assert.IsFalse (gparam.IsGenericTypeDefinition, "#10");
|
||||
}
|
||||
|
||||
#if !NET_4_0
|
||||
[Category ("NotDotNet")]
|
||||
#endif
|
||||
[Test]
|
||||
// CompilerContext no longer supported
|
||||
[Category ("NotWorking")]
|
||||
|
@@ -0,0 +1,154 @@
|
||||
//
|
||||
// MethodBuilderTestIL.cs - NUnit Test Cases for MethodBuilder.CreateMethodBody and MethodBuilder.SetMethodBody
|
||||
//
|
||||
// Marcos Henrich (marcos.henrich@xamarin.com)
|
||||
//
|
||||
// (C) Xamarin, Inc.
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Reflection.Emit;
|
||||
using System.Threading;
|
||||
|
||||
using NUnit.Framework;
|
||||
using System.IO;
|
||||
|
||||
namespace MonoTests.System.Reflection.Emit
|
||||
{
|
||||
public abstract class MethodBuilderTestIL
|
||||
{
|
||||
protected abstract void SetIL (MethodBuilder methodBuilder, MemoryStream ilStream);
|
||||
|
||||
public static ModuleBuilder CreateModuleBuilder ()
|
||||
{
|
||||
AppDomain currentDom = Thread.GetDomain ();
|
||||
|
||||
AssemblyBuilder assemblyBuilder = currentDom.DefineDynamicAssembly (
|
||||
new AssemblyName ("NewDynamicAssembly"),
|
||||
AssemblyBuilderAccess.Run);
|
||||
|
||||
return assemblyBuilder.DefineDynamicModule ("NewModule");
|
||||
}
|
||||
|
||||
public static object Invoke (Type type, MethodBuilder methodBuilder, params object[] parameters)
|
||||
{
|
||||
var method = type.GetMethods ().First (m => {
|
||||
if (m.Name != methodBuilder.Name)
|
||||
return false;
|
||||
var params1 = m.GetParameters ();
|
||||
var params2 = methodBuilder.GetParameters ();
|
||||
if (params1.Length != params2.Length)
|
||||
return false;
|
||||
for (var i = 0; i < params1.Length; i++)
|
||||
if (params1 [i].ParameterType.FullName != params2 [i].ParameterType.FullName)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
object inst = Activator.CreateInstance (type, new object [0]);
|
||||
|
||||
return method.Invoke (inst, parameters);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CallMethodRef ()
|
||||
{
|
||||
var expected = "value";
|
||||
|
||||
var moduleBuilder = CreateModuleBuilder ();
|
||||
var typeBuilder = moduleBuilder.DefineType ("NewType");
|
||||
|
||||
var methodBuilder1 = typeBuilder.DefineMethod ("NewMethod1",
|
||||
MethodAttributes.Public | MethodAttributes.Static,
|
||||
typeof (string),
|
||||
Type.EmptyTypes);
|
||||
|
||||
var gen1 = methodBuilder1.GetILGenerator ();
|
||||
gen1.Emit (OpCodes.Ldstr, expected);
|
||||
gen1.Emit (OpCodes.Ret);
|
||||
|
||||
var methodBuilder2 = typeBuilder.DefineMethod ("NewMethod2",
|
||||
MethodAttributes.Public | MethodAttributes.Static,
|
||||
typeof (string),
|
||||
Type.EmptyTypes);
|
||||
|
||||
var ilStream = new MemoryStream ();
|
||||
var ilWriter = new BinaryWriter (ilStream);
|
||||
ilWriter.Write ((byte) 0x28); // call
|
||||
ilWriter.Write ((int) moduleBuilder.GetMethodToken (methodBuilder1).Token);
|
||||
ilWriter.Write ((byte) 0x2A); // ret
|
||||
|
||||
SetIL (methodBuilder2, ilStream);
|
||||
|
||||
var type = typeBuilder.CreateType ();
|
||||
|
||||
Assert.AreEqual (expected, Invoke (type, methodBuilder2));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CallMethodDef ()
|
||||
{
|
||||
var expected = "value";
|
||||
|
||||
var moduleBuilder1 = CreateModuleBuilder ();
|
||||
var typeBuilder1 = moduleBuilder1.DefineType ("NewType1", TypeAttributes.Public);
|
||||
|
||||
var methodBuilder1 = typeBuilder1.DefineMethod ("NewMethod1",
|
||||
MethodAttributes.Public | MethodAttributes.Static,
|
||||
typeof (string),
|
||||
Type.EmptyTypes);
|
||||
|
||||
var gen1 = methodBuilder1.GetILGenerator ();
|
||||
gen1.Emit (OpCodes.Ldstr, expected);
|
||||
gen1.Emit (OpCodes.Ret);
|
||||
|
||||
typeBuilder1.CreateType ();
|
||||
|
||||
var moduleBuilder2 = CreateModuleBuilder ();
|
||||
var typeBuilder2 = moduleBuilder2.DefineType ("NewType2");
|
||||
|
||||
var methodBuilder2 = typeBuilder2.DefineMethod ("NewMethod2",
|
||||
MethodAttributes.Public | MethodAttributes.Static,
|
||||
typeof (string),
|
||||
Type.EmptyTypes);
|
||||
|
||||
var ilStream = new MemoryStream ();
|
||||
var ilWriter = new BinaryWriter (ilStream);
|
||||
ilWriter.Write ((byte) 0x28); // call
|
||||
ilWriter.Write ((int) moduleBuilder2.GetMethodToken (methodBuilder1).Token);
|
||||
ilWriter.Write ((byte) 0x2A); // ret
|
||||
|
||||
SetIL (methodBuilder2, ilStream);
|
||||
|
||||
var type = typeBuilder2.CreateType ();
|
||||
|
||||
Assert.AreEqual (expected, Invoke (type, methodBuilder2));
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Tests MethodBuilder.CreateMethodBody
|
||||
*/
|
||||
[TestFixture]
|
||||
public class MethodBuilderTestIL_CreateMethodBody : MethodBuilderTestIL
|
||||
{
|
||||
protected override void SetIL (MethodBuilder methodBuilder, MemoryStream ilStream)
|
||||
{
|
||||
methodBuilder.CreateMethodBody (ilStream.ToArray (), (int) ilStream.Length);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Tests MethodBuilder.SetMethodBody
|
||||
*/
|
||||
[TestFixture]
|
||||
public class MethodBuilderTestIL_SetMethodBody : MethodBuilderTestIL
|
||||
{
|
||||
protected override void SetIL (MethodBuilder methodBuilder, MemoryStream ilStream)
|
||||
{
|
||||
methodBuilder.SetMethodBody (ilStream.ToArray (), 999, null, null, null);
|
||||
}
|
||||
}
|
||||
}
|
@@ -728,5 +728,71 @@ namespace MonoTests.System.Reflection.Emit
|
||||
catch (ArgumentException) {
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetType_Escaped_Chars ()
|
||||
{
|
||||
AssemblyName an = genAssemblyName ();
|
||||
AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly (an, AssemblyBuilderAccess.Run);
|
||||
ModuleBuilder module = ab.DefineDynamicModule ("mod");
|
||||
|
||||
var tb = module.DefineType ("NameSpace,+*&[]\\.Type,+*&[]\\",
|
||||
TypeAttributes.Class | TypeAttributes.Public);
|
||||
|
||||
var nestedTb = tb.DefineNestedType ("Nested,+*&[]\\",
|
||||
TypeAttributes.Class | TypeAttributes.NestedPublic);
|
||||
|
||||
var escapedOuterName =
|
||||
"NameSpace\\,\\+\\*\\&\\[\\]\\\\"
|
||||
+ "."
|
||||
+ "Type\\,\\+\\*\\&\\[\\]\\\\";
|
||||
|
||||
var escapedNestedName =
|
||||
escapedOuterName
|
||||
+ "+"
|
||||
+ "Nested\\,\\+\\*\\&\\[\\]\\\\";
|
||||
|
||||
Assert.AreEqual (escapedOuterName, tb.FullName);
|
||||
Assert.AreEqual (escapedNestedName, nestedTb.FullName);
|
||||
|
||||
Type outerCreatedTy = tb.CreateType ();
|
||||
Type nestedCreatedTy = nestedTb.CreateType ();
|
||||
Type outerTy = module.GetType (escapedOuterName);
|
||||
Type nestedTy = module.GetType (escapedNestedName);
|
||||
|
||||
Assert.IsNotNull (outerTy, "A");
|
||||
Assert.IsNotNull (nestedTy, "B");
|
||||
Assert.AreEqual (escapedNestedName, nestedTy.FullName);
|
||||
|
||||
|
||||
Assert.AreEqual (nestedCreatedTy, nestedTy);
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetMethodTokenNullParam ()
|
||||
{
|
||||
AssemblyName an = genAssemblyName ();
|
||||
AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly (an, AssemblyBuilderAccess.Run);
|
||||
ModuleBuilder module = ab.DefineDynamicModule ("mod");
|
||||
|
||||
var method = typeof (object).GetMethod ("GetType");
|
||||
|
||||
// ArgumentNullException should not occur.
|
||||
module.GetMethodToken (method, null);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetConstructorTokenNullParam ()
|
||||
{
|
||||
AssemblyName an = genAssemblyName ();
|
||||
AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly (an, AssemblyBuilderAccess.Run);
|
||||
ModuleBuilder module = ab.DefineDynamicModule ("mod");
|
||||
|
||||
var method = typeof (object).GetConstructor (Type.EmptyTypes);
|
||||
|
||||
// ArgumentNullException should not occur.
|
||||
module.GetConstructorToken (method, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user