Add additional test for Poco::Util::Timer
Test scheduling with Timestamp and Clock Signed-off-by: Pascal Bach <pascal.bach@siemens.com>
This commit is contained in:
Родитель
33998a2156
Коммит
e2538ac6e2
|
@ -21,6 +21,7 @@ using Poco::Util::Timer;
|
|||
using Poco::Util::TimerTask;
|
||||
using Poco::Util::TimerTaskAdapter;
|
||||
using Poco::Timestamp;
|
||||
using Poco::Clock;
|
||||
|
||||
|
||||
TimerTest::TimerTest(const std::string& name): CppUnit::TestCase(name)
|
||||
|
@ -33,7 +34,7 @@ TimerTest::~TimerTest()
|
|||
}
|
||||
|
||||
|
||||
void TimerTest::testSchedule()
|
||||
void TimerTest::testScheduleTimestamp()
|
||||
{
|
||||
Timer timer;
|
||||
|
||||
|
@ -51,6 +52,28 @@ void TimerTest::testSchedule()
|
|||
}
|
||||
|
||||
|
||||
void TimerTest::testScheduleClock()
|
||||
{
|
||||
Timer timer;
|
||||
|
||||
// As reference
|
||||
Timestamp time;
|
||||
time += 1000000;
|
||||
|
||||
Clock clock;
|
||||
clock += 1000000;
|
||||
|
||||
TimerTask::Ptr pTask = new TimerTaskAdapter<TimerTest>(*this, &TimerTest::onTimer);
|
||||
|
||||
assert (pTask->lastExecution() == 0);
|
||||
|
||||
timer.schedule(pTask, clock);
|
||||
|
||||
_event.wait();
|
||||
assert (pTask->lastExecution() >= time);
|
||||
}
|
||||
|
||||
|
||||
void TimerTest::testScheduleInterval()
|
||||
{
|
||||
Timer timer;
|
||||
|
@ -80,6 +103,70 @@ void TimerTest::testScheduleInterval()
|
|||
}
|
||||
|
||||
|
||||
void TimerTest::testScheduleIntervalTimestamp()
|
||||
{
|
||||
Timer timer;
|
||||
|
||||
Timestamp time;
|
||||
|
||||
TimerTask::Ptr pTask = new TimerTaskAdapter<TimerTest>(*this, &TimerTest::onTimer);
|
||||
|
||||
assert (pTask->lastExecution() == 0);
|
||||
|
||||
Timestamp scheduleTime;
|
||||
scheduleTime += 500 * 1000;
|
||||
|
||||
timer.schedule(pTask, scheduleTime, 500);
|
||||
|
||||
_event.wait();
|
||||
assert (time.elapsed() >= 590000);
|
||||
assert (pTask->lastExecution().elapsed() < 130000);
|
||||
|
||||
_event.wait();
|
||||
assert (time.elapsed() >= 1190000);
|
||||
assert (pTask->lastExecution().elapsed() < 130000);
|
||||
|
||||
_event.wait();
|
||||
assert (time.elapsed() >= 1790000);
|
||||
assert (pTask->lastExecution().elapsed() < 130000);
|
||||
|
||||
pTask->cancel();
|
||||
assert (pTask->isCancelled());
|
||||
}
|
||||
|
||||
|
||||
void TimerTest::testScheduleIntervalClock()
|
||||
{
|
||||
Timer timer;
|
||||
|
||||
Timestamp time;
|
||||
|
||||
TimerTask::Ptr pTask = new TimerTaskAdapter<TimerTest>(*this, &TimerTest::onTimer);
|
||||
|
||||
assert (pTask->lastExecution() == 0);
|
||||
|
||||
Clock scheduleClock;
|
||||
scheduleClock += 500 * 1000;
|
||||
|
||||
timer.schedule(pTask, scheduleClock, 500);
|
||||
|
||||
_event.wait();
|
||||
assert (time.elapsed() >= 590000);
|
||||
assert (pTask->lastExecution().elapsed() < 130000);
|
||||
|
||||
_event.wait();
|
||||
assert (time.elapsed() >= 1190000);
|
||||
assert (pTask->lastExecution().elapsed() < 130000);
|
||||
|
||||
_event.wait();
|
||||
assert (time.elapsed() >= 1790000);
|
||||
assert (pTask->lastExecution().elapsed() < 130000);
|
||||
|
||||
pTask->cancel();
|
||||
assert (pTask->isCancelled());
|
||||
}
|
||||
|
||||
|
||||
void TimerTest::testScheduleAtFixedRate()
|
||||
{
|
||||
Timer timer;
|
||||
|
@ -160,8 +247,11 @@ CppUnit::Test* TimerTest::suite()
|
|||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("TimerTest");
|
||||
|
||||
CppUnit_addTest(pSuite, TimerTest, testSchedule);
|
||||
CppUnit_addTest(pSuite, TimerTest, testScheduleTimestamp);
|
||||
CppUnit_addTest(pSuite, TimerTest, testScheduleClock);
|
||||
CppUnit_addTest(pSuite, TimerTest, testScheduleInterval);
|
||||
CppUnit_addTest(pSuite, TimerTest, testScheduleIntervalTimestamp);
|
||||
CppUnit_addTest(pSuite, TimerTest, testScheduleIntervalClock);
|
||||
CppUnit_addTest(pSuite, TimerTest, testScheduleAtFixedRate);
|
||||
CppUnit_addTest(pSuite, TimerTest, testCancel);
|
||||
|
||||
|
|
|
@ -28,9 +28,12 @@ public:
|
|||
TimerTest(const std::string& name);
|
||||
~TimerTest();
|
||||
|
||||
void testSchedule();
|
||||
void testScheduleTimestamp();
|
||||
void testScheduleClock();
|
||||
void testScheduleInterval();
|
||||
void testScheduleAtFixedRate();
|
||||
void testScheduleIntervalTimestamp();
|
||||
void testScheduleIntervalClock();
|
||||
void testCancel();
|
||||
|
||||
void setUp();
|
||||
|
|
Загрузка…
Ссылка в новой задаче