diff --git a/interface/wx/stopwatch.h b/interface/wx/stopwatch.h index 644db85d36..d67fa9ab9e 100644 --- a/interface/wx/stopwatch.h +++ b/interface/wx/stopwatch.h @@ -61,6 +61,10 @@ public: /** (Re)starts the stop watch with a given initial value. + + The stopwatch will always be running after calling Start(), even if + Pause() had been called before and even if it had been called multiple + times. */ void Start(long milliseconds = 0); diff --git a/src/common/stopwatch.cpp b/src/common/stopwatch.cpp index f077378b3a..59997c4b4e 100644 --- a/src/common/stopwatch.cpp +++ b/src/common/stopwatch.cpp @@ -125,6 +125,10 @@ wxLongLong wxStopWatch::GetClockFreq() const void wxStopWatch::Start(long t0) { + // Calling Start() makes the stop watch run however many times it was + // paused before. + m_pauseCount = 0; + DoStart(); m_t0 -= (wxLongLong(t0)*GetClockFreq())/MILLISECONDS_PER_SECOND; diff --git a/tests/events/stopwatch.cpp b/tests/events/stopwatch.cpp index f50da74306..3150fde719 100644 --- a/tests/events/stopwatch.cpp +++ b/tests/events/stopwatch.cpp @@ -26,6 +26,14 @@ #include "wx/stopwatch.h" #include "wx/utils.h" +namespace +{ + +const long tolerance = 10; // in ms +const int sleepTime = 500; + +} // anonymous namespace + // -------------------------------------------------------------------------- // test class // -------------------------------------------------------------------------- @@ -39,10 +47,12 @@ private: CPPUNIT_TEST_SUITE( StopWatchTestCase ); CPPUNIT_TEST( Misc ); CPPUNIT_TEST( BackwardsClockBug ); + CPPUNIT_TEST( RestartBug ); CPPUNIT_TEST_SUITE_END(); void Misc(); void BackwardsClockBug(); + void RestartBug(); DECLARE_NO_COPY_CLASS(StopWatchTestCase) }; @@ -55,8 +65,6 @@ CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( StopWatchTestCase, "StopWatchTestCase" ); void StopWatchTestCase::Misc() { - static const long tolerance = 10; // in ms - wxStopWatch sw; long t; wxLongLong usec; @@ -81,7 +89,6 @@ void StopWatchTestCase::Misc() t >= 0 && t < tolerance ); - static const int sleepTime = 500; sw.Resume(); wxMilliSleep(sleepTime); t = sw.Time(); @@ -124,3 +131,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 + ); +}