141 lines
3.7 KiB
C++
141 lines
3.7 KiB
C++
#include <QtTest>
|
|
#include <QDateTime>
|
|
|
|
#include "scstwtimer.h"
|
|
#include "scstwtestingtimer.h"
|
|
|
|
// add necessary includes here
|
|
|
|
class ScStwTimerTests : public QObject
|
|
{
|
|
Q_OBJECT
|
|
|
|
public:
|
|
ScStwTimerTests();
|
|
~ScStwTimerTests();
|
|
|
|
private slots:
|
|
void initTestCase();
|
|
void cleanupTestCase();
|
|
|
|
void basic_cycle_cancelled();
|
|
void basic_cycle_won();
|
|
void basic_cycle_lost();
|
|
|
|
void basic_cycle_failed();
|
|
void basic_cycle_wildcard();
|
|
|
|
};
|
|
|
|
ScStwTimerTests::ScStwTimerTests()
|
|
{
|
|
|
|
}
|
|
|
|
ScStwTimerTests::~ScStwTimerTests()
|
|
{
|
|
|
|
}
|
|
|
|
void ScStwTimerTests::initTestCase()
|
|
{
|
|
|
|
}
|
|
|
|
void ScStwTimerTests::cleanupTestCase()
|
|
{
|
|
|
|
}
|
|
|
|
void ScStwTimerTests::basic_cycle_cancelled()
|
|
{
|
|
ScStwTimer timer;
|
|
QCOMPARE(timer.getState(), ScStwTimer::IDLE);
|
|
QCOMPARE(timer.getReadyState(), ScStwTimer::IsReady);
|
|
timer.start();
|
|
QCOMPARE(timer.getState(), ScStwTimer::RUNNING);
|
|
QCOMPARE(timer.isRunning(), true);
|
|
timer.cancel();
|
|
QCOMPARE(timer.getState(), ScStwTimer::CANCELLED);
|
|
timer.reset();
|
|
QCOMPARE(timer.getState(), ScStwTimer::IDLE);
|
|
QCOMPARE(timer.getReadyState(), ScStwTimer::IsReady);
|
|
}
|
|
|
|
void ScStwTimerTests::basic_cycle_won()
|
|
{
|
|
ScStwTimer timer;
|
|
QCOMPARE(timer.getState(), ScStwTimer::IDLE);
|
|
QCOMPARE(timer.getReadyState(), ScStwTimer::IsReady);
|
|
timer.start();
|
|
QCOMPARE(timer.getState(), ScStwTimer::RUNNING);
|
|
QCOMPARE(timer.isRunning(), true);
|
|
timer.stop();
|
|
QCOMPARE(timer.getState(), ScStwTimer::WAITING);
|
|
timer.setResult(ScStwTimer::WON);
|
|
QCOMPARE(timer.getState(), ScStwTimer::WON);
|
|
timer.reset();
|
|
QCOMPARE(timer.getState(), ScStwTimer::IDLE);
|
|
QCOMPARE(timer.getReadyState(), ScStwTimer::IsReady);
|
|
}
|
|
|
|
void ScStwTimerTests::basic_cycle_lost()
|
|
{
|
|
ScStwTimer timer;
|
|
QCOMPARE(timer.getState(), ScStwTimer::IDLE);
|
|
QCOMPARE(timer.getReadyState(), ScStwTimer::IsReady);
|
|
timer.start();
|
|
QCOMPARE(timer.getState(), ScStwTimer::RUNNING);
|
|
QCOMPARE(timer.isRunning(), true);
|
|
timer.stop();
|
|
QCOMPARE(timer.getState(), ScStwTimer::WAITING);
|
|
timer.setResult(ScStwTimer::LOST);
|
|
QCOMPARE(timer.getState(), ScStwTimer::LOST);
|
|
timer.reset();
|
|
QCOMPARE(timer.getState(), ScStwTimer::IDLE);
|
|
QCOMPARE(timer.getReadyState(), ScStwTimer::IsReady);
|
|
}
|
|
|
|
void ScStwTimerTests::basic_cycle_failed()
|
|
{
|
|
double startTime = QDateTime::currentMSecsSinceEpoch() + 1000;
|
|
ScStwTestingTimer timer;
|
|
QCOMPARE(timer.getState(), ScStwTimer::IDLE);
|
|
QCOMPARE(timer.getReadyState(), ScStwTimer::IsReady);
|
|
timer.start(startTime);
|
|
QCOMPARE(timer.getState(), ScStwTimer::STARTING);
|
|
timer.handleClimberStart(startTime - 1000);
|
|
QCOMPARE(timer.getState(), ScStwTimer::FAILING);
|
|
|
|
timer.setResult(ScStwTimer::FAILED);
|
|
QCOMPARE(timer.getState(), ScStwTimer::FAILED);
|
|
QCOMPARE(timer.getReactionTime(), -1000);
|
|
|
|
timer.reset();
|
|
QCOMPARE(timer.getState(), ScStwTimer::IDLE);
|
|
QCOMPARE(timer.getReadyState(), ScStwTimer::IsReady);
|
|
}
|
|
|
|
void ScStwTimerTests::basic_cycle_wildcard()
|
|
{
|
|
double startTime = QDateTime::currentMSecsSinceEpoch() + 1000;
|
|
ScStwTestingTimer timer;
|
|
QCOMPARE(timer.getState(), ScStwTimer::IDLE);
|
|
QCOMPARE(timer.getReadyState(), ScStwTimer::IsReady);
|
|
timer.start(startTime);
|
|
QCOMPARE(timer.getState(), ScStwTimer::STARTING);
|
|
timer.handleClimberStart(startTime - 1000);
|
|
QCOMPARE(timer.getState(), ScStwTimer::FAILING);
|
|
|
|
timer.setResult(ScStwTimer::WILDCARD);
|
|
QCOMPARE(timer.getState(), ScStwTimer::WILDCARD);
|
|
QCOMPARE(timer.getReactionTime(), -1000);
|
|
|
|
timer.reset();
|
|
QCOMPARE(timer.getState(), ScStwTimer::IDLE);
|
|
QCOMPARE(timer.getReadyState(), ScStwTimer::IsReady);
|
|
}
|
|
|
|
QTEST_APPLESS_MAIN(ScStwTimerTests)
|
|
|
|
#include "tst_scstwtimertests.moc"
|