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

@@ -1216,6 +1216,15 @@ namespace MonoTests.System
DateTime.Parse ("Sat,,, 01,,, Oct,,, ,,,1994 03:00:00", CultureInfo.InvariantCulture);
}
[Test]
public void TryParse_Bug11630 ()
{
DateTime parsed;
Assert.IsTrue (DateTime.TryParse ("10Feb2013", out parsed));
Assert.AreEqual (new DateTime (2013, 2, 10), parsed);
}
[Test]
[ExpectedException (typeof (FormatException))]
public void Parse_CommaAfterHours ()

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) {

View File

@@ -740,6 +740,10 @@ namespace MonoTests.System
success = Enum.TryParse<TestingEnum> ("is", true, out result);
Assert.AreEqual (true, success, "#D1");
Assert.AreEqual (TestingEnum.Is, result, "#D2");
success = Enum.TryParse<TestingEnum> (" Is ", out result);
Assert.AreEqual (true, success, "#E1");
Assert.AreEqual (TestingEnum.Is, result, "#E2");
}
#endif

View File

@@ -273,6 +273,7 @@ namespace MonoTests.System
public void ConcurrentInitialization ()
{
var init = new AutoResetEvent (false);
var e1_set = new AutoResetEvent (false);
var lazy = new Lazy<string> (() => {
init.Set ();
@@ -286,6 +287,7 @@ namespace MonoTests.System
string value = lazy.Value;
} catch (Exception ex) {
e1 = ex;
e1_set.Set ();
}
});
thread.Start ();
@@ -306,8 +308,9 @@ namespace MonoTests.System
e3 = ex;
}
Assert.AreSame (e1, e2, "#2");
Assert.AreSame (e1, e3, "#3");
Assert.IsTrue (e1_set.WaitOne (3000), "#2");
Assert.AreSame (e1, e2, "#3");
Assert.AreSame (e1, e3, "#4");
}
}