Imported Upstream version 3.6.0

Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
This commit is contained in:
Jo Shields
2014-08-13 10:39:27 +01:00
commit a575963da9
50588 changed files with 8155799 additions and 0 deletions

View File

@@ -0,0 +1,42 @@
2008-08-03 Zoltan Varga <vargaz@gmail.com>
* TimerTest.cs: Simplify the EnabledInElapsed test to prevent various races.
2007-10-30 Robert Jordan <robertj@gmx.net>
* TimerTest.cs: Enable test for bug #82701/#325368.
2007-09-06 Robert Jordan <robertj@gmx.net>
* TimerTest.cs: Factored our more test cases from bug #82701.
2007-09-05 Gert Driesen <drieseng@users.sourceforge.net>
* TimerTest.cs: Added NotWorking test for bug #82701. Added ctor
and trivial property tests.
2006-12-18 Robert Jordan <robertj@gmx.net>
* TimerTest.cs: Add NotWorking test case for bug #77847.
2005-11-16 Sebastien Pouliot <sebastien@ximian.com>
* TimersDescriptionAttributeCas.cs: Updated comments (thanks to Gert
Driesen for the solution).
* TimersDescriptionAttributeTest.cs: New. Unit tests to show that the
description string is a resource name (and not the description itself)
2005-11-16 Sebastien Pouliot <sebastien@ximian.com>
* TimersDescriptionAttributeCas.cs: Fixed test as the Description
property doesn't always returns null (exact conditions unknown).
2005-11-16 Sebastien Pouliot <sebastien@ximian.com>
* ElapsedEventArgsCas.cs: New. CAS unit tests.
* TimerCas.cs: New. CAS unit tests.
* TimersDescriptionAttributeCas.cs: New. CAS unit tests.
2005-05-28 Kornél Pál <kornelpal@hotmail.com>
* TimerTest.cs: New test file for System.Timers.Timer.

View File

@@ -0,0 +1,90 @@
//
// ElapsedEventArgsCas.cs - CAS unit tests for System.Timers.ElapsedEventArgs
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using NUnit.Framework;
using System;
using System.Reflection;
using System.Security;
using System.Security.Permissions;
using System.Timers;
using ST = System.Threading;
namespace MonoCasTests.System.Timers {
[TestFixture]
[Category ("CAS")]
public class ElapsedEventArgsCas {
Timer t;
ElapsedEventArgs eea;
private void SetElapsedEventArgs (object sender, ElapsedEventArgs e)
{
eea = e;
}
[TestFixtureSetUp]
public void FixtureSetUp ()
{
// fulltrust
t = new Timer (1);
t.Elapsed += new ElapsedEventHandler (SetElapsedEventArgs);
t.Enabled = true;
ST.Thread.Sleep (100);
}
[SetUp]
public void SetUp ()
{
if (!SecurityManager.SecurityEnabled)
Assert.Ignore ("SecurityManager.SecurityEnabled is OFF");
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void Deny_Unrestricted ()
{
Assert.IsNotNull (eea, "ElapsedEventArgs");
DateTime dt = eea.SignalTime;
DateTime now = DateTime.Now;
Assert.IsTrue (dt > now.AddSeconds (-2), ">");
Assert.IsTrue (dt < now.AddSeconds (2), "<");
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void LinkDemand_Deny_Unrestricted ()
{
MethodInfo mi = typeof (ElapsedEventArgs).GetProperty ("SignalTime").GetGetMethod ();
Assert.IsNotNull (mi, "SignalTime");
Assert.IsNotNull (mi.Invoke (eea, null), "invoke");
}
}
}

View File

@@ -0,0 +1,129 @@
//
// TimerCas.cs - CAS unit tests for System.Timers.Timer
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using NUnit.Framework;
using System;
using System.ComponentModel;
using System.Reflection;
using System.Security;
using System.Security.Permissions;
using System.Timers;
namespace MonoCasTests.System.Timers {
class TestSyncInvoke: ISynchronizeInvoke {
public IAsyncResult BeginInvoke (Delegate method, object[] args)
{
return null;
}
public object EndInvoke (IAsyncResult result)
{
return null;
}
public object Invoke (Delegate method, object[] args)
{
return EndInvoke (BeginInvoke (method, args));
}
public bool InvokeRequired {
get { return true; }
}
}
[TestFixture]
[NUnit.Framework.Category ("CAS")]
public class TimerCas {
[SetUp]
public void SetUp ()
{
if (!SecurityManager.SecurityEnabled)
Assert.Ignore ("SecurityManager.SecurityEnabled is OFF");
}
private void Callback (object sender, ElapsedEventArgs e)
{
}
private void CommonTests (Timer t)
{
Assert.IsTrue (t.AutoReset, "AutoReset");
t.AutoReset = false;
Assert.IsFalse (t.Enabled, "Enabled");
t.Enabled = true;
Assert.IsNull (t.Site, "Site");
t.Site = null;
Assert.IsNull (t.SynchronizingObject, "SynchronizingObject");
t.SynchronizingObject = new TestSyncInvoke ();
t.Elapsed += new ElapsedEventHandler (Callback);
t.Elapsed -= new ElapsedEventHandler (Callback);
t.BeginInit ();
t.EndInit ();
t.Start ();
t.Stop ();
t.Close ();
(t as IDisposable).Dispose ();
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void Constructor_Deny_Unrestricted ()
{
Timer t = new Timer ();
Assert.AreEqual (100.0, t.Interval, "Interval");
t.Interval = 200.0;
CommonTests (t);
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void ConstructorDouble_Deny_Unrestricted ()
{
Timer t = new Timer (200.0);
Assert.AreEqual (200.0, t.Interval, "Interval");
t.Interval = 100.0;
CommonTests (t);
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void LinkDemand_Deny_Unrestricted ()
{
ConstructorInfo ci = typeof (Timer).GetConstructor (new Type [0]);
Assert.IsNotNull (ci, "default .ctor");
Assert.IsNotNull (ci.Invoke (null), "invoke");
}
}
}

View File

@@ -0,0 +1,295 @@
//
// TimerTest.cs - NUnit Test Cases for System.Timers.Timer
//
// Author:
// Kornél Pál <http://www.kornelpal.hu/>
// Robert Jordan <robertj@gmx.net>
//
// Copyright (C) 2005 Kornél Pál
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using NUnit.Framework;
using System;
using System.Timers;
using ST = System.Threading;
namespace MonoTests.System.Timers
{
[TestFixture]
public class TimerTest
{
Timer timer;
int _elapsedCount;
[SetUp]
public void SetUp ()
{
timer = new Timer ();
}
[TearDown]
public void TearDown ()
{
timer.Close ();
}
[Test]
public void Constructor0 ()
{
Assert.IsTrue (timer.AutoReset, "#1");
Assert.IsFalse (timer.Enabled, "#2");
Assert.AreEqual (100, timer.Interval, "#3");
Assert.IsNull (timer.SynchronizingObject, "#4");
}
[Test]
public void Constructor1 ()
{
timer = new Timer (1);
Assert.IsTrue (timer.AutoReset, "#A1");
Assert.IsFalse (timer.Enabled, "#A2");
Assert.AreEqual (1, timer.Interval, "#A3");
Assert.IsNull (timer.SynchronizingObject, "#A4");
timer = new Timer (int.MaxValue);
Assert.IsTrue (timer.AutoReset, "#B1");
Assert.IsFalse (timer.Enabled, "#B2");
Assert.AreEqual (int.MaxValue, timer.Interval, "#B3");
Assert.IsNull (timer.SynchronizingObject, "#B4");
}
[Test]
public void Constructor1_Interval_Negative ()
{
try {
new Timer (-1);
Assert.Fail ("#1");
} catch (ArgumentException ex) {
// Invalid value -1 for parameter interval
Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
Assert.IsNull (ex.InnerException, "#3");
Assert.IsNotNull (ex.Message, "#4");
}
}
[Test]
public void Constructor1_Interval_Zero ()
{
try {
new Timer (0);
Assert.Fail ("#1");
} catch (ArgumentException ex) {
// Invalid value 0 for parameter interval
Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
Assert.IsNull (ex.InnerException, "#3");
Assert.IsNotNull (ex.Message, "#4");
}
}
[Test]
public void Constructor1_Interval_Max ()
{
#if NET_2_0
try {
new Timer (0x80000000);
Assert.Fail ("#A1");
} catch (ArgumentException ex) {
// Invalid value 2147483648 for parameter interval
Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#A2");
Assert.IsNull (ex.InnerException, "#A3");
Assert.IsNotNull (ex.Message, "#A4");
}
try {
new Timer (double.MaxValue);
Assert.Fail ("#B1");
} catch (ArgumentException ex) {
// Invalid value 1.79769313486232E+308 for parameter interval
Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
Assert.IsNull (ex.InnerException, "#B3");
Assert.IsNotNull (ex.Message, "#B4");
}
#else
timer = new Timer (0x80000000);
Assert.AreEqual (0x80000000, timer.Interval, "#1");
timer = new Timer (double.MaxValue);
Assert.AreEqual (double.MaxValue, timer.Interval, "#2");
#endif
}
[Test]
public void AutoReset ()
{
Assert.IsTrue (timer.AutoReset, "#1");
timer.AutoReset = false;
Assert.IsFalse (timer.AutoReset, "#2");
}
[Test]
public void Interval ()
{
timer.Interval = 1;
Assert.AreEqual (1, timer.Interval, "#1");
timer.Interval = 500;
Assert.AreEqual (500, timer.Interval, "#2");
timer.Interval = double.MaxValue;
Assert.AreEqual (double.MaxValue, timer.Interval, "#3");
}
[Test]
public void Interval_Negative ()
{
try {
timer.Interval = -1;
Assert.Fail ("#1");
} catch (ArgumentException ex) {
// '0' is not a valid value for 'Interval'. 'Interval' must be greater than 0
Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
Assert.IsNull (ex.InnerException, "#3");
Assert.IsNotNull (ex.Message, "#4");
}
}
[Test]
public void Interval_Zero ()
{
try {
timer.Interval = 0;
Assert.Fail ("#1");
} catch (ArgumentException ex) {
// '0' is not a valid value for 'Interval'. 'Interval' must be greater than 0
Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
Assert.IsNull (ex.InnerException, "#3");
Assert.IsNotNull (ex.Message, "#4");
}
}
[Test]
public void StartStopEnabled ()
{
timer.Start ();
Assert.IsTrue (timer.Enabled, "#1");
timer.Stop ();
Assert.IsFalse (timer.Enabled, "#2");
}
[Test]
public void CloseEnabled ()
{
Assert.IsFalse (timer.Enabled, "#1");
timer.Enabled = true;
Assert.IsTrue (timer.Enabled, "#2");
timer.Close ();
Assert.IsFalse (timer.Enabled, "#3");
}
[Test] // bug #325368
public void EnabledInElapsed ()
{
_elapsedCount = 0;
timer = new Timer (50);
timer.AutoReset = false;
timer.Elapsed += new ElapsedEventHandler (EnabledInElapsed_Elapsed);
timer.Start ();
ST.Thread.Sleep (200);
timer.Stop ();
Assert.IsTrue (_elapsedCount == 2, "#1 loss of events");
}
[Test]
public void TestRaceCondition ()
{
Assert.IsTrue (new RaceTest (true).Success, "#1");
Assert.IsTrue (new RaceTest (false).Success, "#2");
}
void EnabledInElapsed_Elapsed (object sender, ElapsedEventArgs e)
{
_elapsedCount++;
Timer t = sender as Timer;
if (_elapsedCount == 1)
t.Enabled = true;
}
}
class RaceTest
{
const int Threads = 2;
const int Loops = 100;
object locker = new object ();
Timer timer;
int counter;
public bool Success {
get { return counter > Loops * Threads; }
}
public RaceTest (bool autoReset)
{
timer = new Timer ();
timer.AutoReset = autoReset;
timer.Interval = 100;
timer.Elapsed += new ElapsedEventHandler (Tick);
timer.Start ();
ST.Thread[] tl = new ST.Thread [Threads];
for (int i = 0; i < Threads; i++) {
tl [i] = new ST.Thread (new ST.ThreadStart (Run));
tl [i].Start ();
}
for (int i = 0; i < Threads; i++) {
tl [i].Join ();
}
ST.Thread.Sleep (1000);
}
void Restart ()
{
lock (locker) {
timer.Stop ();
timer.Start ();
}
ST.Interlocked.Increment (ref counter);
}
void Tick (object sender, ElapsedEventArgs e)
{
Restart ();
}
void Run ()
{
for (int i = 0; i < Loops; i++) {
ST.Thread.Sleep (0);
Restart ();
}
}
}
}

View File

@@ -0,0 +1,72 @@
//
// TimersDescriptionAttributeCas.cs
// - CAS unit tests for System.Timers.TimersDescriptionAttributeCas
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using NUnit.Framework;
using System;
using System.Reflection;
using System.Security;
using System.Security.Permissions;
using System.Timers;
namespace MonoCasTests.System.Timers {
[TestFixture]
[Category ("CAS")]
public class TimersDescriptionAttributeCas {
[SetUp]
public void SetUp ()
{
if (!SecurityManager.SecurityEnabled)
Assert.Ignore ("SecurityManager.SecurityEnabled is OFF");
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void Constructor_Deny_Unrestricted ()
{
TimersDescriptionAttribute tda = new TimersDescriptionAttribute ("Mono");
// Note: see unit tests for why we're not expecting "Mono" as the value
Assert.AreEqual (tda.Description, tda.Description, "Description");
// this assert doesn't do anything (except removing warning) but we know,
// for CAS, that nothing protects the property getter
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void LinkDemand_Deny_Unrestricted ()
{
Type[] types = new Type[1] { typeof (string) };
ConstructorInfo ci = typeof (TimersDescriptionAttribute).GetConstructor (types);
Assert.IsNotNull (ci, ".ctor(string)");
Assert.IsNotNull (ci.Invoke (new object[1] { "Mono" }), "invoke");
}
}
}

View File

@@ -0,0 +1,57 @@
//
// TimersDescriptionAttributeTest.cs
// - Unit tests for System.Timers.TimersDescriptionAttribute
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using NUnit.Framework;
using System;
using System.Timers;
namespace MonoTests.System.Timers {
[TestFixture]
public class TimersDescriptionAttributeTest {
[Test]
[Category ("NotWorking")]
public void AnyString ()
{
TimersDescriptionAttribute tda = new TimersDescriptionAttribute ("Mono");
Assert.IsNull (tda.Description, "Description");
}
[Test]
[Category ("NotWorking")]
public void ExistingResourceName ()
{
TimersDescriptionAttribute tda = new TimersDescriptionAttribute ("TimerEnabled");
Assert.IsNotNull (tda.Description, "Description");
Assert.IsFalse ("TimerEnabled" == tda.Description, "!Equal");
}
}
}