]>
git.saurik.com Git - wxWidgets.git/blob - tests/events/stopwatch.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/events/stopwatch.cpp
3 // Purpose: Test wxStopWatch class
4 // Author: Francesco Montorsi (extracted from console sample)
7 // Copyright: (c) 2010 wxWidgets team
8 ///////////////////////////////////////////////////////////////////////////////
11 // ----------------------------------------------------------------------------
13 // ----------------------------------------------------------------------------
26 #include "wx/stopwatch.h"
29 // --------------------------------------------------------------------------
31 // --------------------------------------------------------------------------
33 class StopWatchTestCase
: public CppUnit::TestCase
36 StopWatchTestCase() {}
39 CPPUNIT_TEST_SUITE( StopWatchTestCase
);
41 CPPUNIT_TEST( BackwardsClockBug
);
42 CPPUNIT_TEST_SUITE_END();
45 void BackwardsClockBug();
47 DECLARE_NO_COPY_CLASS(StopWatchTestCase
)
50 // register in the unnamed registry so that these tests are run by default
51 CPPUNIT_TEST_SUITE_REGISTRATION( StopWatchTestCase
);
53 // also include in its own registry so that these tests can be run alone
54 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( StopWatchTestCase
, "StopWatchTestCase" );
56 void StopWatchTestCase::Misc()
58 static const long tolerance
= 10; // in ms
64 sw
.Pause(); // pause it immediately
66 // verify that almost no time elapsed
67 usec
= sw
.TimeInMicro();
70 ("Elapsed time was %" wxLongLongFmtSpec
"dus", usec
),
77 // check that the stop watch doesn't advance while paused
80 ("Actual time value is %ld", t
),
81 t
>= 0 && t
< tolerance
84 static const int sleepTime
= 500;
86 wxMilliSleep(sleepTime
);
88 // check that it did advance now by ~1.5s
91 ("Actual time value is %ld", t
),
92 t
> sleepTime
- tolerance
&& t
< sleepTime
+ tolerance
97 // check that this sleep won't be taken into account below
98 wxMilliSleep(sleepTime
);
101 wxMilliSleep(sleepTime
);
104 // and it should advance again
107 ("Actual time value is %ld", t
),
108 t
> 2*sleepTime
- tolerance
&& t
< 2*sleepTime
+ tolerance
112 void StopWatchTestCase::BackwardsClockBug()
117 for ( size_t n
= 0; n
< 10; n
++ )
121 for ( size_t m
= 0; m
< 10000; m
++ )
123 CPPUNIT_ASSERT ( sw
.Time() >= 0 && sw2
.Time() >= 0 );