Fixed HttpWebRequestTest to compile with mobile NUnit.
[mono.git] / mcs / class / System / Test / System.Diagnostics / StopwatchTest.cs
1 //
2 // StopwatchTest.cs
3 //
4 // Author:
5 //      Atsushi Enomoto  <atsushi@ximian.com>
6 //
7 // Copyright (C) 2006 Novell, Inc.
8 //
9 using System;
10 using System.Diagnostics;
11 using System.Threading;
12 using NUnit.Framework;
13
14 namespace MonoTests.System.Diagnostics
15 {
16         [TestFixture]
17         public class StopwatchTest
18         {
19                 [Test]
20                 public void TestSimple ()
21                 {
22                         // It starts at started state.
23                         Stopwatch sw = Stopwatch.StartNew ();
24                         Thread.Sleep (1000);
25                         sw.Stop ();
26                         long ticks = sw.ElapsedTicks;
27                         Assert.IsTrue (sw.ElapsedMilliseconds > 100, "#1");
28                         Thread.Sleep (1000);
29                         // do not increment resuts
30                         Assert.AreEqual (ticks, sw.ElapsedTicks, "#2");
31                         sw.Start ();
32                         Thread.Sleep (1000);
33                         // increment results
34                         Assert.IsTrue (sw.ElapsedTicks > ticks, "#3");
35                         ticks = sw.ElapsedTicks;
36                         sw.Stop ();
37                         Assert.IsTrue (sw.ElapsedTicks >= ticks, "#4");
38                         sw.Reset ();
39                         Assert.AreEqual (0, sw.ElapsedTicks, "#5");
40                         sw.Start ();
41                         Thread.Sleep (1000);
42                         Assert.IsTrue (sw.ElapsedTicks > 100, "#5");
43                         // This test is not strict but would mostly work.
44                         Assert.IsTrue (ticks > sw.ElapsedTicks, "#6");
45                         sw.Stop ();
46                 }
47         }
48 }