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

@@ -353,6 +353,19 @@ namespace MonoTests.System.Collections.Concurrent
} catch (ArgumentNullException ex) {
}
}
[Test]
public void ContainsKeyPairTest ()
{
var validKeyPair = new KeyValuePair<string, string> ("key", "validValue");
var wrongKeyPair = new KeyValuePair<string, string> ("key", "wrongValue");
IDictionary<string, string> dict = new ConcurrentDictionary<string, string> ();
dict.Add (validKeyPair);
Assert.IsTrue (dict.Contains (validKeyPair));
Assert.IsFalse (dict.Contains (wrongKeyPair));
}
}
}
#endif

View File

@@ -30,6 +30,7 @@ using System.Collections.Generic;
using System.Collections.Concurrent;
using NUnit.Framework;
using MonoTests.System.Threading.Tasks;
namespace MonoTests.System.Collections.Concurrent
{
@@ -115,6 +116,34 @@ namespace MonoTests.System.Collections.Concurrent
CollectionStressTestHelper.RemoveStressTest (new ConcurrentQueue<int> (), CheckOrderingType.InOrder);
}
[Test]
public void StressTryPeekTestCase ()
{
ParallelTestHelper.Repeat (delegate {
var queue = new ConcurrentQueue<object> ();
queue.Enqueue (new object());
const int threads = 10;
int threadCounter = 0;
bool success = true;
ParallelTestHelper.ParallelStressTest (queue, (q) => {
int threadId = Interlocked.Increment (ref threadCounter);
object temp;
if (threadId < threads)
{
while (queue.TryPeek (out temp))
if (temp == null)
success = false;
} else {
queue.TryDequeue (out temp);
}
}, threads);
Assert.IsTrue (success, "TryPeek returned unexpected null value.");
}, 10);
}
[Test]
public void CountTestCase()
{
@@ -215,6 +244,30 @@ namespace MonoTests.System.Collections.Concurrent
{
queue.CopyTo (new int[3], 0);
}
static WeakReference CreateWeakReference (object obj)
{
return new WeakReference (obj);
}
[Test]
// This depends on precise stack scanning
[Category ("NotWorking")]
public void TryDequeueReferenceTest ()
{
var obj = new Object ();
var weakReference = CreateWeakReference(obj);
var queue = new ConcurrentQueue<object> ();
queue.Enqueue (obj);
queue.TryDequeue (out obj);
obj = null;
GC.Collect ();
GC.WaitForPendingFinalizers ();
Assert.IsFalse (weakReference.IsAlive);
}
}
}
#endif

View File

@@ -783,6 +783,51 @@ namespace MonoTests.System.Reflection
var m = GetType ().GetMethod ("Bug12856");
Assert.AreEqual ("System.Nullable`1[System.Int32] Bug12856()", m.ToString (), "#1");
}
#if !MONOTOUCH
class GenericClass<T>
{
public void Method ()
{
T lv = default(T);
Console.WriteLine(lv);
}
public void Method2<K> (T a0, K a1)
{
T var0 = a0;
K var1 = a1;
Console.WriteLine (var0);
Console.WriteLine (var1);
}
}
[Test]
public void TestLocalVariableTypes ()
{
var typeofT = typeof (GenericClass<>).GetGenericArguments () [0];
var typeofK = typeof (GenericClass<>).GetMethod ("Method2").GetGenericArguments () [0];
var type = typeof (GenericClass<>).GetMethod("Method").GetMethodBody().LocalVariables[0].LocalType;
Assert.AreEqual (typeofT, type);
Assert.AreEqual (typeof (GenericClass<>), type.DeclaringType);
type = typeof (GenericClass<>).GetMethod("Method2").GetMethodBody().LocalVariables[0].LocalType;
Assert.AreEqual (typeofT, type);
Assert.AreEqual (typeof (GenericClass<>), type.DeclaringType);
type = typeof (GenericClass<>).GetMethod("Method2").GetMethodBody().LocalVariables[1].LocalType;
Assert.AreEqual (typeofK, type);
Assert.AreEqual (typeof (GenericClass<>), type.DeclaringType);
type = typeof (GenericClass<int>).GetMethod("Method2").GetMethodBody().LocalVariables[0].LocalType;
Assert.AreEqual (typeof (int), type);
type = typeof (GenericClass<int>).GetMethod("Method2").GetMethodBody().LocalVariables[1].LocalType;
Assert.AreEqual (typeofK, type);
Assert.AreEqual (typeof (GenericClass<>), type.DeclaringType);
}
#endif
}
#if NET_2_0

View File

@@ -196,9 +196,13 @@ namespace MonoTests.System.Runtime.CompilerServices {
if (GC.MaxGeneration == 0) /*Boehm doesn't handle ephemerons */
Assert.Ignore ("Not working on Boehm.");
var cwt = new ConditionalWeakTable <object,object> ();
List<object> keepAlive;
List<WeakReference> keys;
FillStuff (cwt, out keepAlive, out keys);
List<object> keepAlive = null;
List<WeakReference> keys = null;
Thread t = new Thread (delegate () {
FillStuff (cwt, out keepAlive, out keys);
});
t.Start ();
t.Join ();
GC.Collect ();

View File

@@ -44,14 +44,15 @@ namespace MonoTests.System.Runtime.CompilerServices
class Scheduler : TaskScheduler
{
string name;
int ic, qc;
public Scheduler (string name)
{
this.name = name;
}
public int InlineCalls { get; set; }
public int QueueCalls { get; set; }
public int InlineCalls { get { return ic; } }
public int QueueCalls { get { return qc; } }
protected override IEnumerable<Task> GetScheduledTasks ()
{
@@ -60,7 +61,7 @@ namespace MonoTests.System.Runtime.CompilerServices
protected override void QueueTask (Task task)
{
++QueueCalls;
Interlocked.Increment (ref qc);
ThreadPool.QueueUserWorkItem (o => {
TryExecuteTask (task);
});
@@ -68,7 +69,7 @@ namespace MonoTests.System.Runtime.CompilerServices
protected override bool TryExecuteTaskInline (Task task, bool taskWasPreviouslyQueued)
{
++InlineCalls;
Interlocked.Increment (ref ic);
return false;
}
}
@@ -102,6 +103,7 @@ namespace MonoTests.System.Runtime.CompilerServices
string progress;
SynchronizationContext sc;
ManualResetEvent mre;
[SetUp]
public void Setup ()
@@ -176,7 +178,7 @@ namespace MonoTests.System.Runtime.CompilerServices
Assert.IsTrue (t.Wait (3000), "#0");
Assert.AreEqual (0, t.Result, "#1");
Assert.AreEqual (0, b.InlineCalls, "#2b");
Assert.AreEqual (2, a.QueueCalls, "#3a");
Assert.IsTrue (a.QueueCalls == 1 || a.QueueCalls == 2, "#3a");
Assert.AreEqual (1, b.QueueCalls, "#3b");
}
@@ -270,12 +272,15 @@ namespace MonoTests.System.Runtime.CompilerServices
[Test]
public void CompletionOnDifferentCustomSynchronizationContext ()
{
mre = new ManualResetEvent (false);
progress = "";
var syncContext = new SingleThreadSynchronizationContext ();
SynchronizationContext.SetSynchronizationContext (syncContext);
syncContext.Post (delegate {
Go2 (syncContext);
Task t = new Task (delegate() { });
Go2 (syncContext, t);
t.Start ();
}, null);
// Custom message loop
@@ -286,21 +291,30 @@ namespace MonoTests.System.Runtime.CompilerServices
Thread.Sleep (0);
}
Assert.AreEqual ("132", progress);
Assert.AreEqual ("13xa2", progress);
}
async void Go2 (SynchronizationContext ctx)
async void Go2 (SynchronizationContext ctx, Task t)
{
await Wait2 (ctx);
await Wait2 (ctx, t);
progress += "2";
progress += "a";
if (mre.WaitOne (5000))
progress += "2";
else
progress += "b";
}
async Task Wait2 (SynchronizationContext ctx)
async Task Wait2 (SynchronizationContext ctx, Task t)
{
await Task.Delay (10); // Force block suspend/return
await t; // Force block suspend/return
ctx.Post (l => progress += "3", null);
ctx.Post (l => {
progress += "3";
mre.Set ();
progress += "x";
}, null);
progress += "1";

View File

@@ -18,6 +18,7 @@ using System.Runtime.Remoting.Proxies;
using System.Runtime.Remoting.Messaging;
using System.Collections;
using NUnit.Framework;
using System.Text;
namespace MonoTests.System.Runtime.Serialization
{
@@ -41,6 +42,41 @@ namespace MonoTests.System.Runtime.Serialization
RemotingServices.Disconnect (mt);
}
#if !MONOTOUCH
[Test]
public void DelegateSerializationTest ()
{
var a = new DelegateSerialization ();
a.E += HandleE1;
var d2 = Delegate.CreateDelegate (typeof(Func<StringBuilder, int>), "val", typeof(SerializationTest).GetMethod ("HandleE2"));
a.E += (Func<StringBuilder, int>) d2;
using (var ms = new MemoryStream ()) {
var fmt = new BinaryFormatter ();
fmt.Serialize (ms, a);
ms.Flush ();
ms.Seek (0, SeekOrigin.Begin);
var a2 = (DelegateSerialization) fmt.Deserialize (ms);
a2.Test ();
}
}
#endif
static int HandleE1 (StringBuilder arg)
{
arg.Append ("E1");
return 1;
}
public static int HandleE2 (object o, StringBuilder arg)
{
arg.Append ("E2|");
arg.Append (o);
return 2;
}
void WriteData ()
{
StreamingContext context = new StreamingContext (StreamingContextStates.Other);
@@ -814,5 +850,17 @@ namespace MonoTests.System.Runtime.Serialization
public int x;
}
[Serializable]
class DelegateSerialization
{
public event Func<StringBuilder, int> E;
public void Test ()
{
var sb = new StringBuilder ();
Assert.AreEqual (2, E (sb), "#1");
Assert.AreEqual ("E1E2|val", sb.ToString (), "#2");
}
}
}

View File

@@ -276,7 +276,7 @@ namespace MonoTests.System.Threading.Tasks
tasks[i] = Task.Factory.StartNew (delegate { Thread.Sleep (0); });
}
Assert.IsTrue (Task.WaitAll (tasks, 2000));
Assert.IsTrue (Task.WaitAll (tasks, 5000));
}
}
@@ -904,7 +904,11 @@ namespace MonoTests.System.Threading.Tasks
args.SetObserved ();
};
var inner = new ApplicationException ();
Task.Factory.StartNew (() => { throw inner; });
Thread t = new Thread (delegate () {
Task.Factory.StartNew (() => { Console.WriteLine ("HIT!"); throw inner; });
});
t.Start ();
t.Join ();
Thread.Sleep (1000);
GC.Collect ();
Thread.Sleep (1000);
@@ -1928,7 +1932,7 @@ namespace MonoTests.System.Threading.Tasks
}
[Test]
[Category("MobileNotWorking")]
[Category("NotWorking")]
public void TaskContinuationChainLeak()
{
// Start cranking out tasks, starting each new task upon completion of and from inside the prior task.

View File

@@ -90,9 +90,9 @@ namespace MonoTests.System.Threading
int called = 0;
var cts = new CancellationTokenSource ();
cts.Token.Register (() => called++);
cts.CancelAfter (20);
cts.CancelAfter (50);
cts.Dispose ();
Thread.Sleep (50);
Thread.Sleep (100);
Assert.AreEqual (0, called, "#1");
}

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");
}
}