/**
(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);
#include "wx/stopwatch.h"
#include "wx/utils.h"
+namespace
+{
+
+const long tolerance = 10; // in ms
+const int sleepTime = 500;
+
+} // anonymous namespace
+
// --------------------------------------------------------------------------
// test class
// --------------------------------------------------------------------------
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)
};
void StopWatchTestCase::Misc()
{
- static const long tolerance = 10; // in ms
-
wxStopWatch sw;
long t;
wxLongLong usec;
t >= 0 && t < tolerance
);
- static const int sleepTime = 500;
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
+ );
+}