Since r69835 the stop watch remained paused even when Start() was called. Do
resume it when restarting it both for backwards compatibility and because it
makes more sense and also document this behaviour.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@69921
c3d73ce0-8a6f-49c7-b76d-
6d57e0e08775
/**
(Re)starts the stop watch with a given initial value.
/**
(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);
*/
void Start(long milliseconds = 0);
void wxStopWatch::Start(long t0)
{
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;
DoStart();
m_t0 -= (wxLongLong(t0)*GetClockFreq())/MILLISECONDS_PER_SECOND;
#include "wx/stopwatch.h"
#include "wx/utils.h"
#include "wx/stopwatch.h"
#include "wx/utils.h"
+namespace
+{
+
+const long tolerance = 10; // in ms
+const int sleepTime = 500;
+
+} // anonymous namespace
+
// --------------------------------------------------------------------------
// test class
// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
// test class
// --------------------------------------------------------------------------
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();
DECLARE_NO_COPY_CLASS(StopWatchTestCase)
};
DECLARE_NO_COPY_CLASS(StopWatchTestCase)
};
void StopWatchTestCase::Misc()
{
void StopWatchTestCase::Misc()
{
- static const long tolerance = 10; // in ms
-
wxStopWatch sw;
long t;
wxLongLong usec;
wxStopWatch sw;
long t;
wxLongLong usec;
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();
+
+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
+ );
+}