| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- //
- // Copyright (c) 2007 Novell, Inc.
- //
- // Authors:
- // Rolf Bjarne Kvinge ([email protected])
- //
- using System;
- using System.Drawing;
- using System.Reflection;
- using System.Windows.Forms;
- using Sys_Threading=System.Threading;
- using NUnit.Framework;
- namespace MonoTests.System.Windows.Forms
- {
- [TestFixture]
- public class TimerTest
- {
- bool Ticked;
-
- [Test ()]
- [ExpectedException (typeof (ArgumentException))]
- public void IntervalException1 ()
- {
- Timer timer = new Timer ();
- timer.Interval = 0;
- }
- [Test ()]
- [ExpectedException (typeof (ArgumentException), "'-1' is not a valid value for Interval. Interval must be greater than 0.")]
- public void IntervalException2 ()
- {
- Timer timer = new Timer ();
- timer.Interval = -1;
- }
- [Test ()]
- public void IntervalException3 ()
- {
- Timer timer = new Timer ();
- timer.Interval = int.MaxValue;
- }
- [Test ()]
- [ExpectedException (typeof (ArgumentException), "'-2147483648' is not a valid value for Interval. Interval must be greater than 0.")]
- public void IntervalException4 ()
- {
- Timer timer = new Timer ();
- timer.Interval = int.MinValue;
- }
-
- [Test]
- public void StartTest ()
- {
- Ticked = false;
- using (Timer timer = new Timer ()) {
- timer.Tick += new EventHandler (TickHandler);
- timer.Start ();
- Sys_Threading.Thread.Sleep (150);
- Application.DoEvents ();
- Assert.AreEqual (true, timer.Enabled, "1");
- Assert.AreEqual (true, Ticked, "2");
- }
- }
- [Test]
- public void StopTest ()
- {
- Ticked = false;
- using (Timer timer = new Timer ()) {
- timer.Tick += new EventHandler (TickHandler);
- timer.Interval = 200;
- timer.Start ();
- Assert.AreEqual (true, timer.Enabled, "1");
- Assert.AreEqual (false, Ticked, "2");
- timer.Stop ();
- Assert.AreEqual (false, Ticked, "3"); // This may fail if we are running on a very slow machine...
- Assert.AreEqual (false, timer.Enabled, "4");
- Sys_Threading.Thread.Sleep (500);
- Assert.AreEqual (false, Ticked, "5");
- }
- }
-
- #if NET_2_0
- [Test]
- public void TagTest ()
- {
- Timer timer = new Timer ();
- timer.Tag = "a";
- Assert.AreEqual ("a", timer.Tag, "1");
- }
- #endif
- [Test]
- public void EnabledTest ()
- {
- Ticked = false;
- using (Timer timer = new Timer ()) {
- timer.Tick += new EventHandler (TickHandler);
- timer.Enabled = true;
- Sys_Threading.Thread.Sleep (150);
- Application.DoEvents ();
- Assert.AreEqual (true, timer.Enabled, "1");
- Assert.AreEqual (true, Ticked, "2");
- }
-
- Ticked = false;
- using (Timer timer = new Timer ()) {
- timer.Tick += new EventHandler (TickHandler);
- timer.Interval = 1000;
- timer.Enabled = true;
- Assert.AreEqual (true, timer.Enabled, "1");
- Assert.AreEqual (false, Ticked, "2");
- timer.Enabled = false;
- Assert.AreEqual (false, Ticked, "3"); // This may fail if we are running on a very slow machine...
- Assert.AreEqual (false, timer.Enabled, "4");
- }
- }
- void TickHandler (object sender, EventArgs e)
- {
- Ticked = true;
- }
-
- [Test]
- public void DefaultProperties ()
- {
- Timer timer = new Timer ();
- Assert.AreEqual (null, timer.Container, "C1");
- Assert.AreEqual (false, timer.Enabled, "E1");
- Assert.AreEqual (100, timer.Interval, "I1");
- Assert.AreEqual (null, timer.Site, "S1");
- #if NET_2_0
- Assert.AreEqual (null, timer.Tag, "T1");
- #endif
- }
- }
- }
|