dotgnu-pnet-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[dotgnu-pnet-commits] pnetlib ChangeLog tests/System/TestSystem.cs Sy...


From: Klaus Treichel
Subject: [dotgnu-pnet-commits] pnetlib ChangeLog tests/System/TestSystem.cs Sy...
Date: Mon, 29 Sep 2008 13:03:14 +0000

CVSROOT:        /cvsroot/dotgnu-pnet
Module name:    pnetlib
Changes by:     Klaus Treichel <ktreichel>      08/09/29 13:03:13

Modified files:
        .              : ChangeLog 
        tests/System   : TestSystem.cs 
Added files:
        System/Diagnostics: Stopwatch.cs 
        tests/System/Diagnostics: SuiteDiagnostics.cs TestStopwatch.cs 

Log message:
        Add the System.Diagnostics.Stopwatch class and some tests for it.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/pnetlib/ChangeLog?cvsroot=dotgnu-pnet&r1=1.2539&r2=1.2540
http://cvs.savannah.gnu.org/viewcvs/pnetlib/System/Diagnostics/Stopwatch.cs?cvsroot=dotgnu-pnet&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/pnetlib/tests/System/TestSystem.cs?cvsroot=dotgnu-pnet&r1=1.7&r2=1.8
http://cvs.savannah.gnu.org/viewcvs/pnetlib/tests/System/Diagnostics/SuiteDiagnostics.cs?cvsroot=dotgnu-pnet&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/pnetlib/tests/System/Diagnostics/TestStopwatch.cs?cvsroot=dotgnu-pnet&rev=1.1

Patches:
Index: ChangeLog
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/ChangeLog,v
retrieving revision 1.2539
retrieving revision 1.2540
diff -u -b -r1.2539 -r1.2540
--- ChangeLog   17 Aug 2008 16:43:42 -0000      1.2539
+++ ChangeLog   29 Sep 2008 13:03:12 -0000      1.2540
@@ -1,3 +1,14 @@
+2008-09-29  Klaus Treichel  <address@hidden>
+
+       * System/Diagnostics/Stopwatch.cs: Add Stopwatch class.
+
+       * tests/System/Diagnostics/SuiteDiagnostics.cs,
+       tests/System/Diagnostics/TestStopwatch.cs: Add some tests for the
+       Stopwatch class.
+
+       * tests/System/SuiteSystem.cs: Add the new tests for System.Diagnostics 
to
+       the suite.
+
 2008-08-17  Klaus Treichel  <address@hidden>
 
        * resources/en_US/runtime/Arg.txt: Add Arg_NotNullName=Argument.

Index: tests/System/TestSystem.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/tests/System/TestSystem.cs,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -b -r1.7 -r1.8
--- tests/System/TestSystem.cs  30 Nov 2002 17:12:41 -0000      1.7
+++ tests/System/TestSystem.cs  29 Sep 2008 13:03:13 -0000      1.8
@@ -36,6 +36,7 @@
                                suite = new TestSuite("Network Tests");
                                suite.AddTests(typeof(TestIPAddress));
                                suite.AddTests(typeof(TestWebHeaderCollection));
+                               suite.AddTest(SuiteDiagnostics.Suite());
                                fullSuite.AddTest(suite);
 
                                return fullSuite;

Index: System/Diagnostics/Stopwatch.cs
===================================================================
RCS file: System/Diagnostics/Stopwatch.cs
diff -N System/Diagnostics/Stopwatch.cs
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ System/Diagnostics/Stopwatch.cs     29 Sep 2008 13:03:13 -0000      1.1
@@ -0,0 +1,169 @@
+/*
+ * Stopwatch.cs - Implementation of the
+ *                     "System.Diagnostics.Stopwatch" class.
+ *
+ * Copyright (C) 2008  Southern Storm Software, Pty Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+namespace System.Diagnostics
+{
+
+using System;
+using System.Runtime.CompilerServices;
+
+#if CONFIG_FRAMEWORK_2_0 && CONFIG_EXTENDED_DIAGNOSTICS
+
+public class Stopwatch
+{
+       // static members
+       public static readonly bool IsHighResolution;
+       public static readonly long Frequency;
+
+       // instance members
+       private bool isRunning;
+       private long elapsed;
+       private long start;
+
+       // Get the frequency of the performance counter.
+       // If a high resolution timer is supported this function returns true.
+       [MethodImpl(MethodImplOptions.InternalCall)]
+       extern private static bool GetPerformanceFrequency(out long frequency);
+
+       // Get the value of the high resolution timer.
+       [MethodImpl(MethodImplOptions.InternalCall)]
+       extern private static long GetPerformanceCounter();
+       
+       static Stopwatch()
+                       {
+                               IsHighResolution = GetPerformanceFrequency(out 
Frequency);
+                       }
+
+
+       public static long GetTimestamp()
+                       {
+                               return GetPerformanceCounter();
+                       }
+
+       public static Stopwatch StartNew()
+                       {
+                               Stopwatch stopwatch = new Stopwatch();
+
+                               stopwatch.Start();
+
+                               return stopwatch;
+                       }
+
+       public Stopwatch()
+                       {
+                               isRunning = false;
+                               elapsed = 0;
+                               start = 0;
+                       }
+
+       public void Reset()
+                       {
+                               isRunning = false;
+                               elapsed = 0;
+                               start = 0;
+                       }
+
+       public void Start()
+                       {
+                               if(!isRunning)
+                               {
+                                       start = GetPerformanceCounter();
+                                       isRunning = true;
+                               }
+                       }
+
+       public void Stop()
+                       {
+                               if(isRunning)
+                               {
+                                       isRunning = false;
+                                       elapsed += (GetPerformanceCounter() - 
start);
+                               }
+                       }
+
+       public TimeSpan Elapsed
+                       {
+                               get
+                               {
+                                       long ticks = elapsed;
+
+                                       if(isRunning)
+                                       {
+                                               ticks += 
(GetPerformanceCounter() - start);
+                                       }
+
+                                       if(IsHighResolution)
+                                       {
+                                               return new TimeSpan(ticks / 
(Frequency / 10000000L));
+                                       }
+                                       else
+                                       {
+                                               return new TimeSpan(ticks);
+                                       }
+                               }
+                       }
+
+       public long ElapsedMilliseconds
+                       {
+                               get
+                               {
+                                       long ticks = elapsed;
+
+                                       if(isRunning)
+                                       {
+                                               ticks += 
(GetPerformanceCounter() - start);
+                                       }
+
+                                       // We assume Frequency >= 1000
+                                       return ticks / (Frequency / 1000);
+
+                               }
+                       }
+
+       public long ElapsedTicks
+                       {
+                               get
+                               {
+                                       long ticks = elapsed;
+
+                                       if(isRunning)
+                                       {
+                                               ticks += 
(GetPerformanceCounter() - start);
+                                       }
+
+                                       return ticks;
+                               }
+
+                       }
+
+       public bool IsRunning
+                       {
+                               get
+                               {
+                                       return isRunning;
+                               }
+                       }
+
+}; // class Stopwatch
+
+#endif  // CONFIG_FRAMEWORK_2_0 && CONFIG_EXTENDED_DIAGNOSTICS
+
+}; // namespace System.Diagnostics

Index: tests/System/Diagnostics/SuiteDiagnostics.cs
===================================================================
RCS file: tests/System/Diagnostics/SuiteDiagnostics.cs
diff -N tests/System/Diagnostics/SuiteDiagnostics.cs
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ tests/System/Diagnostics/SuiteDiagnostics.cs        29 Sep 2008 13:03:13 
-0000      1.1
@@ -0,0 +1,36 @@
+/*
+ * SuiteDiagnostics.cs - Tests for the "System.Diagnostics" namespace.
+ *
+ * Copyright (C) 2008  Southern Storm Software, Pty Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+using CSUnit;
+using System;
+
+public class SuiteDiagnostics
+{
+
+       public static TestSuite Suite()
+                       {
+                               TestSuite suite = new TestSuite("Diagnostics 
Tests");
+#if CONFIG_FRAMEWORK_2_0 && CONFIG_EXTENDED_DIAGNOSTICS
+                               suite.AddTests(typeof(TestStopwatch));
+#endif // CONFIG_FRAMEWORK_2_0 && CONFIG_EXTENDED_DIAGNOSTICS
+                               return suite;
+                       }
+
+}; // class SuiteDiagnostics

Index: tests/System/Diagnostics/TestStopwatch.cs
===================================================================
RCS file: tests/System/Diagnostics/TestStopwatch.cs
diff -N tests/System/Diagnostics/TestStopwatch.cs
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ tests/System/Diagnostics/TestStopwatch.cs   29 Sep 2008 13:03:13 -0000      
1.1
@@ -0,0 +1,138 @@
+/*
+ * TestStopwatch.cs - Tests for the "Stopwatch" class.
+ *
+ * Copyright (C) 2008  Southern Storm Software, Pty Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+using CSUnit;
+using System;
+using System.Diagnostics;
+
+#if CONFIG_FRAMEWORK_2_0 && CONFIG_EXTENDED_DIAGNOSTICS
+
+public class TestStopwatch : TestCase
+{
+       // Constructor.
+       public TestStopwatch(String name)
+                       : base(name)
+                       {
+                               // Nothing to do here.
+                       }
+
+       // Set up for the tests.
+       protected override void Setup()
+                       {
+                               // Nothing to do here.
+                       }
+
+       // Clean up after the tests.
+       protected override void Cleanup()
+                       {
+                               // Nothing to do here.
+                       }
+
+       // test static constructor
+       public void TestStopwatchCCtor ()
+                       {
+                               bool isHighResolution = 
Stopwatch.IsHighResolution;
+                               long timestamp;
+
+                               if(isHighResolution)
+                               {
+                                       Assert("Frequency >= 10000000", 
Stopwatch.Frequency >= 10000000);
+                               }
+                               else
+                               {
+                                       AssertEquals( "Frequency", 10000000, 
Stopwatch.Frequency );
+                               }
+
+                               timestamp = Stopwatch.GetTimestamp();
+                               Assert("Timestamp increases", 
Stopwatch.GetTimestamp() > timestamp);
+
+                       }
+
+       // test constructor
+       public void TestStopwatchCtor ()
+                       {
+                               Stopwatch stopwatch;
+
+                               stopwatch = new Stopwatch();
+
+                               Assert("Not Running", !stopwatch.IsRunning);
+                               AssertEquals( "ElapsedTicks == 0", 0, 
stopwatch.ElapsedTicks );
+                               AssertEquals( "ElapsedMilliseconds == 0", 0, 
stopwatch.ElapsedMilliseconds );
+                               AssertEquals( "Elapsed == 0", new TimeSpan(0), 
stopwatch.Elapsed );
+
+                       }
+
+       // test creating a running stopwatch
+       public void TestStopwatchStartNew ()
+                       {
+                               Stopwatch stopwatch;
+                               long ticks;
+
+                               stopwatch = Stopwatch.StartNew();
+
+                               Assert("Running", stopwatch.IsRunning);
+
+                               stopwatch.Stop();
+
+                               Assert("Not Running", !stopwatch.IsRunning);
+
+                               ticks = stopwatch.ElapsedTicks;
+                               Assert( "ElapsedTicks > 0", ticks > 0 );
+                               // On fast systems less than one millisecond is 
elapsed
+                               if(ticks / (Stopwatch.Frequency / 1000) > 0)
+                               {
+                                       Assert( "ElapsedMilliseconds > 0", 
stopwatch.ElapsedMilliseconds > 0 );
+                               }
+                               else
+                               {
+                                       Assert( "ElapsedMilliseconds == 0", 
stopwatch.ElapsedMilliseconds == 0 );
+                               }
+                               Assert( "Elapsed > 0", stopwatch.Elapsed.Ticks 
> 0 );
+
+                       }
+
+       public void TestStopwatch ()
+                       {
+                               Stopwatch stopwatch;
+                               long ticks;
+                               long ticks1;
+
+                               stopwatch = Stopwatch.StartNew();
+
+                               ticks = stopwatch.ElapsedTicks;
+                               Assert( "ElapsedTicks > ticks", 
stopwatch.ElapsedTicks > ticks );
+
+                               stopwatch.Stop();
+                               ticks = stopwatch.ElapsedTicks;
+                               AssertEquals( "ElapsedTicks == ticks", ticks, 
stopwatch.ElapsedTicks );
+
+                               stopwatch.Start();
+                               Assert( "ElapsedTicks > ticks after restart", 
stopwatch.ElapsedTicks > ticks );
+
+                               stopwatch.Reset();
+                               Assert("Not Running after Reset", 
!stopwatch.IsRunning);
+                               AssertEquals( "ElapsedTicks == 0 after Reset", 
0, stopwatch.ElapsedTicks );
+                               AssertEquals( "ElapsedMilliseconds == 0 after 
Reset", 0, stopwatch.ElapsedMilliseconds );
+                               AssertEquals( "Elapsed == 0 after Reset", new 
TimeSpan(0), stopwatch.Elapsed );
+                       }
+
+}; // class TestStopwatch
+
+#endif // CONFIG_FRAMEWORK_2_0 && CONFIG_EXTENDED_DIAGNOSTICS




reply via email to

[Prev in Thread] Current Thread [Next in Thread]