]> git.saurik.com Git - wxWidgets.git/blobdiff - tests/events/stopwatch.cpp
proper default for iphone
[wxWidgets.git] / tests / events / stopwatch.cpp
index 251a859c63170094950dcb451182635d1811b4e0..1650484039bb62e81fd6f4fe760575bd548d2e0f 100644 (file)
@@ -3,7 +3,6 @@
 // Purpose:     Test wxStopWatch class
 // Author:      Francesco Montorsi (extracted from console sample)
 // Created:     2010-05-16
 // Purpose:     Test wxStopWatch class
 // Author:      Francesco Montorsi (extracted from console sample)
 // Created:     2010-05-16
-// RCS-ID:      $Id$
 // Copyright:   (c) 2010 wxWidgets team
 ///////////////////////////////////////////////////////////////////////////////
 
 // Copyright:   (c) 2010 wxWidgets team
 ///////////////////////////////////////////////////////////////////////////////
 
 #include "wx/stopwatch.h"
 #include "wx/utils.h"
 
 #include "wx/stopwatch.h"
 #include "wx/utils.h"
 
+namespace
+{
+
+const long tolerance = 50;  // in ms
+const int sleepTime = 500;
+
+} // anonymous namespace
+
 // --------------------------------------------------------------------------
 // test class
 // --------------------------------------------------------------------------
 // --------------------------------------------------------------------------
 // test class
 // --------------------------------------------------------------------------
@@ -39,10 +46,12 @@ private:
     CPPUNIT_TEST_SUITE( StopWatchTestCase );
         CPPUNIT_TEST( Misc );
         CPPUNIT_TEST( BackwardsClockBug );
     CPPUNIT_TEST_SUITE( StopWatchTestCase );
         CPPUNIT_TEST( Misc );
         CPPUNIT_TEST( BackwardsClockBug );
+        CPPUNIT_TEST( RestartBug );
     CPPUNIT_TEST_SUITE_END();
 
     void Misc();
     void BackwardsClockBug();
     CPPUNIT_TEST_SUITE_END();
 
     void Misc();
     void BackwardsClockBug();
+    void RestartBug();
 
     DECLARE_NO_COPY_CLASS(StopWatchTestCase)
 };
 
     DECLARE_NO_COPY_CLASS(StopWatchTestCase)
 };
@@ -55,13 +64,20 @@ CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( StopWatchTestCase, "StopWatchTestCase" );
 
 void StopWatchTestCase::Misc()
 {
 
 void StopWatchTestCase::Misc()
 {
-    static const long tolerance = 100;  // in ms
-
     wxStopWatch sw;
     long t;
     wxStopWatch sw;
     long t;
+    wxLongLong usec;
 
     sw.Pause();         // pause it immediately
 
 
     sw.Pause();         // pause it immediately
 
+    // verify that almost no time elapsed
+    usec = sw.TimeInMicro();
+    WX_ASSERT_MESSAGE
+    (
+        ("Elapsed time was %" wxLongLongFmtSpec "dus", usec),
+        usec < tolerance*1000
+    );
+
     wxSleep(1);
     t = sw.Time();
 
     wxSleep(1);
     t = sw.Time();
 
@@ -72,7 +88,6 @@ void StopWatchTestCase::Misc()
         t >= 0 && t < tolerance
     );
 
         t >= 0 && t < tolerance
     );
 
-    static const int sleepTime = 500;
     sw.Resume();
     wxMilliSleep(sleepTime);
     t = sw.Time();
     sw.Resume();
     wxMilliSleep(sleepTime);
     t = sw.Time();
@@ -115,3 +130,22 @@ void StopWatchTestCase::BackwardsClockBug()
         }
     }
 }
         }
     }
 }
+
+void StopWatchTestCase::RestartBug()
+{
+    wxStopWatch sw;
+    sw.Pause();
+
+    // Calling Start() should resume the stopwatch if it was paused.
+    static const int offset = 5000;
+    sw.Start(offset);
+    wxMilliSleep(sleepTime);
+
+    long t = sw.Time();
+    WX_ASSERT_MESSAGE
+    (
+        ("Actual time value is %ld", t),
+        t > offset + sleepTime - tolerance &&
+            t < offset + sleepTime + tolerance
+    );
+}