Imported Upstream version 3.8.0

Former-commit-id: 6a76a29bd07d86e57c6c8da45c65ed5447d38a61
This commit is contained in:
Jo Shields
2014-09-04 09:07:35 +01:00
parent a575963da9
commit fe777c5c82
1062 changed files with 12460 additions and 5983 deletions

View File

@@ -1116,20 +1116,68 @@ namespace MonoTests.System
typeof (Action),
this.GetType ().GetMethod ("Banga"));
}
#if !MONOTOUCH
[Test] // #664205
public void DynamicInvokeNullTarget ()
public void DynamicInvokeClosedStatic ()
{
var method = new DynamicMethod ("test", typeof (int), new [] { typeof (object) }, true);
var il = method.GetILGenerator ();
il.Emit (OpCodes.Ldc_I4, 42);
il.Emit (OpCodes.Ret);
var d1 = Delegate.CreateDelegate (typeof(Func<int>), null, typeof(DelegateTest).GetMethod ("DynamicInvokeClosedStaticDelegate_CB"));
Assert.AreEqual (1, d1.DynamicInvoke (), "#1");
var @delegate = method.CreateDelegate (typeof (Func<int>), null);
Assert.AreEqual (42, (int) @delegate.DynamicInvoke ());
var d2 = Delegate.CreateDelegate (typeof(Func<int>), "arg", typeof(DelegateTest).GetMethod ("DynamicInvokeClosedStaticDelegate_CB"));
Assert.AreEqual (2, d2.DynamicInvoke (), "#2");
}
#endif
public static int DynamicInvokeClosedStaticDelegate_CB (string instance)
{
switch (instance) {
case null:
return 1;
case "arg":
return 2;
default:
Assert.Fail ();
return -1;
}
}
[Test]
public void DynamicInvokeOpenInstanceDelegate ()
{
var d1 = Delegate.CreateDelegate (typeof (Func<DelegateTest, int>), typeof(DelegateTest).GetMethod ("DynamicInvokeOpenInstanceDelegate_CB"));
Assert.AreEqual (5, d1.DynamicInvoke (new DelegateTest ()), "#1");
var d3 = (Func<DelegateTest, int>) d1;
Assert.AreEqual (5, d3 (null), "#2");
}
public int DynamicInvokeOpenInstanceDelegate_CB ()
{
return 5;
}
[Test]
public void DynamicInvoke_InvalidArguments ()
{
Delegate d = new Func<int, int> (TestMethod);
try {
d.DynamicInvoke (null);
Assert.Fail ("#1");
} catch (TargetParameterCountException) {
}
try {
d.DynamicInvoke (new object [0]);
Assert.Fail ("#2");
} catch (TargetParameterCountException) {
}
}
public static int TestMethod (int i)
{
throw new NotSupportedException ();
}
#endif
public static void CreateDelegateOfStaticMethodBoundToNull_Helper (object[] args) {}
@@ -1329,17 +1377,56 @@ namespace MonoTests.System
} catch (ArgumentException) {}
}
private static Func<Int32, Int32, bool> Int32D = (x, y) => (x & y) == y;
[Test]
public void EnumBaseTypeConversion () {
Func<int, int, bool> dm = Int32D2;
var d =
Delegate.CreateDelegate(typeof (Func<StringComparison,
StringComparison, bool>), Int32D.Method) as
Delegate.CreateDelegate(typeof (Func<StringComparison, StringComparison, bool>), dm.Method) as
Func<StringComparison, StringComparison, bool>;
Assert.IsTrue (d (0, 0));
}
#if !MONOTOUCH
public static void DynInvokeWithClosedFirstArg (object a, object b)
{
}
[Test]
public void DynamicInvokeClosedOverNullDelegate () {
var dm = new DynamicMethod ("test", typeof (Delegate), null);
var il = dm.GetILGenerator ();
il.Emit (OpCodes.Ldnull);
il.Emit (OpCodes.Ldftn, GetType ().GetMethod ("DynInvokeWithClosedFirstArg"));
il.Emit (OpCodes.Newobj, typeof (Action<object>).GetConstructors ()[0]);
il.Emit (OpCodes.Ret);
var f = (Func <object>) dm.CreateDelegate (typeof (Func <object>));
Action<object> ac = (Action<object>)f();
ac.DynamicInvoke (new object[] { "oi" });
ac.DynamicInvoke (new object[] { null });
}
[Test]
public void DynamicInvokeFirstArgBoundDelegate () {
var dm = new DynamicMethod ("test", typeof (Delegate), null);
var il = dm.GetILGenerator ();
il.Emit (OpCodes.Ldstr, "test");
il.Emit (OpCodes.Ldftn, GetType ().GetMethod ("DynInvokeWithClosedFirstArg"));
il.Emit (OpCodes.Newobj, typeof (Action<object>).GetConstructors ()[0]);
il.Emit (OpCodes.Ret);
var f = (Func <object>) dm.CreateDelegate (typeof (Func <object>));
Action<object> ac = (Action<object>)f();
ac.DynamicInvoke (new object[] { "oi" });
ac.DynamicInvoke (new object[] { null });
}
#endif
static bool Int32D2 (int x, int y)
{
return (x & y) == y;
}
public class B {
public virtual string retarg3 (string s) {