1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2024-11-14 19:57:17 +01:00
SqMod/vendor/POCO/Foundation/testsuite/src/TimerTest.cpp
Sandu Liviu Catalin 4a6bfc086c Major plugin refactor and cleanup.
Switched to POCO library for unified platform/library interface.
Deprecated the external module API. It was creating more problems than solving.
Removed most built-in libraries in favor of system libraries for easier maintenance.
Cleaned and secured code with help from static analyzers.
2021-01-30 08:51:39 +02:00

97 lines
1.6 KiB
C++

//
// TimerTest.cpp
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#include "TimerTest.h"
#include "CppUnit/TestCaller.h"
#include "CppUnit/TestSuite.h"
#include "Poco/Thread.h"
#include "Poco/Stopwatch.h"
using Poco::Timer;
using Poco::TimerCallback;
using Poco::Thread;
using Poco::Stopwatch;
TimerTest::TimerTest(const std::string& name): CppUnit::TestCase(name)
{
}
TimerTest::~TimerTest()
{
}
void TimerTest::testTimer()
{
Timer t(100, 200);
assertTrue (t.getStartInterval() == 100);
assertTrue (t.getPeriodicInterval() == 200);
Stopwatch sw;
TimerCallback<TimerTest> tc(*this, &TimerTest::onTimer);
sw.start();
t.start(tc);
_event.wait();
sw.stop();
assertTrue (sw.elapsed() >= 80000 && sw.elapsed() < 120000);
sw.restart();
_event.wait();
sw.stop();
assertTrue (sw.elapsed() >= 180000 && sw.elapsed() < 250000);
sw.restart();
_event.wait();
sw.stop();
assertTrue (sw.elapsed() >= 180000 && sw.elapsed() < 250000);
t.stop();
}
void TimerTest::testDuplicateStop()
{
Timer t(100, 200);
t.stop();
t.stop();
TimerCallback<TimerTest> tc(*this, &TimerTest::onTimer);
t.start(tc);
_event.wait();
t.stop();
t.stop();
}
void TimerTest::setUp()
{
}
void TimerTest::tearDown()
{
}
void TimerTest::onTimer(Timer& timer)
{
_event.set();
}
CppUnit::Test* TimerTest::suite()
{
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("TimerTest");
CppUnit_addTest(pSuite, TimerTest, testTimer);
CppUnit_addTest(pSuite, TimerTest, testDuplicateStop);
return pSuite;
}