// this makes fair for the "DueTime" test since it
// doesn't have to wait for the scheduler thread to be
// created.
- new Timer (null, null, Timeout.Infinite, 0);
+ new Timer (new TimerCallback (DoNothing), null, Timeout.Infinite, 0);
}
-
+
+ void DoNothing (object foo)
+ {
+ }
+
[Test]
public void TestDueTime ()
{
public void TestChange ()
{
Bucket bucket = new Bucket();
- Timer t = new Timer (new TimerCallback (Callback), bucket, 1, 1);
+ Timer t = new Timer (new TimerCallback (Callback), bucket, 10, 10);
Thread.Sleep (500);
int c = bucket.count;
- Assert.IsTrue(c > 20, "#1");
+ Assert.IsTrue (c > 20, "#1 " + c.ToString ());
t.Change (100, 100);
+ c = bucket.count;
Thread.Sleep (500);
- Assert.IsTrue(bucket.count <= c + 20, "#2");
+ Assert.IsTrue (bucket.count <= c + 20, "#2 " + c.ToString ());
t.Dispose ();
}
Thread.Sleep(100);
t.Change (int.MaxValue, Timeout.Infinite);
// since period is 0 the callback should happen once (bug #340212)
- Assert.IsTrue(b.count == 1);
-
+ Assert.AreEqual (1, b.count, "only once");
}
[Test]
+ [Ignore ()]
public void TestDisposeOnCallback ()
{
+ // this test is bad, as the provided `state` (t1) is null and will throw an NRE inside the callback
+ // that was ignored before 238785a3e3d510528228fc551625975bc508c2f3 and most unit test runner won't
+ // report it since the NRE will not happen on the main thread (but Touch.Unit will)
Timer t1 = null;
t1 = new Timer (new TimerCallback (CallbackTestDisposeOnCallback), t1, 0, 10);
Thread.Sleep (200);
{
((Timer) foo).Dispose ();
}
-
+
private void Callback (object foo)
{
Bucket b = foo as Bucket;
Interlocked.Increment (ref b.count);
}
+
+ [Test]
+ [ExpectedException (typeof (ArgumentNullException))]
+ public void DisposeNullWaitHandle ()
+ {
+ using (Timer t = new Timer (DoNothing, null, 0, 0)) {
+ t.Dispose (null);
+ }
+ }
+
+ [Test]
+ public void Change_IntInt_Infinite ()
+ {
+ using (Timer t = new Timer (DoNothing, null, 0, 0)) {
+ t.Change ((int)Timeout.Infinite, (int)Timeout.Infinite);
+ }
+ }
+
+ [Test]
+ public void Change_IntInt_MaxValue ()
+ {
+ using (Timer t = new Timer (DoNothing, null, 0, 0)) {
+ t.Change (Int32.MaxValue, Int32.MaxValue);
+ }
+ }
+
+ [Test]
+ public void Change_UIntUInt_Infinite ()
+ {
+ using (Timer t = new Timer (DoNothing, null, 0, 0)) {
+ t.Change (unchecked ((uint) Timeout.Infinite), unchecked ((uint) Timeout.Infinite));
+ }
+ }
+
+ [Test]
+ public void Change_UIntUInt_MaxValue ()
+ {
+ using (Timer t = new Timer (DoNothing, null, 0, 0)) {
+ // UInt32.MaxValue == Timeout.Infinite == 0xffffffff
+ t.Change (UInt32.MaxValue, UInt32.MaxValue);
+ }
+ }
+
+ [Test]
+ public void Change_LongLong_Infinite ()
+ {
+ using (Timer t = new Timer (DoNothing, null, 0, 0)) {
+ t.Change ((long) Timeout.Infinite, (long) Timeout.Infinite);
+ }
+ }
+
+ [Test]
+ [ExpectedException (typeof (ArgumentOutOfRangeException))]
+ public void Change_LongLong_MaxValue ()
+ {
+ using (Timer t = new Timer (DoNothing, null, 0, 0)) {
+ t.Change (Int64.MaxValue, Int64.MaxValue);
+ }
+ }
+
+ [Test]
+ [ExpectedException (typeof (ArgumentOutOfRangeException))]
+ public void Change_LongLong_UInt32MaxValue ()
+ {
+ using (Timer t = new Timer (DoNothing, null, 0, 0)) {
+ // not identical to (long)-1
+ t.Change ((long)UInt32.MaxValue, (long)UInt32.MaxValue);
+ }
+ }
+
+ [Test]
+ public void Change_LongLong_UInt32MaxValueMinusOne ()
+ {
+ using (Timer t = new Timer (DoNothing, null, 0, 0)) {
+ // not identical to (long)-1
+ t.Change ((long) UInt32.MaxValue - 1, (long) UInt32.MaxValue -1);
+ }
+ }
+
+ [Test]
+ public void Change_TimeSpanTimeSpan_Infinite ()
+ {
+ using (Timer t = new Timer (DoNothing, null, 0, 0)) {
+ t.Change (new TimeSpan (-1), new TimeSpan (-1));
+ }
+ }
+
+ [Test]
+ [ExpectedException (typeof (ArgumentOutOfRangeException))]
+ public void Change_TimeSpanTimeSpan_MaxValue ()
+ {
+ using (Timer t = new Timer (DoNothing, null, 0, 0)) {
+ t.Change (TimeSpan.MaxValue, TimeSpan.MaxValue);
+ }
+ }
+
+ [Test]
+ public void Change_TimeSpanTimeSpan_UInt32MaxValue ()
+ {
+ using (Timer t = new Timer (DoNothing, null, 0, 0)) {
+ t.Change (new TimeSpan (UInt32.MaxValue), new TimeSpan (UInt32.MaxValue));
+ }
+ }
}
}