You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
80 lines
1.0 KiB
80 lines
1.0 KiB
#include <cxxtest/TestSuite.h>
|
|
|
|
#include "Fixture.hpp"
|
|
|
|
// #define private public // reach TimerThread's private multimap
|
|
|
|
#include "Timer.hpp"
|
|
|
|
// #include <time.h>
|
|
|
|
|
|
|
|
|
|
class TestTimer : public CxxTest::TestSuite
|
|
{
|
|
|
|
private:
|
|
|
|
class DummyTimer : public Timer
|
|
{
|
|
public:
|
|
|
|
DummyTimer(int maxPeriodicCount = 5)
|
|
: m_counter(0)
|
|
, m_maxPeriodicCount(maxPeriodicCount)
|
|
{
|
|
TRACE;
|
|
}
|
|
|
|
void timerExpired()
|
|
{
|
|
TRACE;
|
|
m_counter += 100;
|
|
}
|
|
|
|
void periodicTimerExpired()
|
|
{
|
|
TRACE;
|
|
static int count = 0;
|
|
m_counter++;
|
|
count++;
|
|
if ( count >= m_maxPeriodicCount ) {
|
|
stopTimer();
|
|
}
|
|
}
|
|
|
|
int m_counter;
|
|
|
|
private:
|
|
|
|
int m_maxPeriodicCount;
|
|
|
|
};
|
|
|
|
|
|
public:
|
|
|
|
void testBasic( void )
|
|
{
|
|
TEST_HEADER;
|
|
|
|
DummyTimer t;
|
|
t.createTimer(2);
|
|
t.wait();
|
|
TS_ASSERT_EQUALS( t.m_counter, 100 );
|
|
}
|
|
|
|
void testBasicPeriodic( void )
|
|
{
|
|
TEST_HEADER;
|
|
|
|
DummyTimer t;
|
|
t.createTimer(2,0,1);
|
|
t.wait();
|
|
TS_ASSERT_EQUALS( t.m_counter, 105 );
|
|
}
|
|
|
|
|
|
};
|