2021-05-11 19:36:15 +02:00
|
|
|
#include <QtTest>
|
2021-05-11 20:08:36 +02:00
|
|
|
#include <QDateTime>
|
|
|
|
|
|
|
|
#include "scstwtimer.h"
|
|
|
|
#include "scstwtestingtimer.h"
|
2021-05-11 19:36:15 +02:00
|
|
|
|
|
|
|
// add necessary includes here
|
|
|
|
|
|
|
|
class ScStwTimerTests : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
ScStwTimerTests();
|
|
|
|
~ScStwTimerTests();
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
void initTestCase();
|
|
|
|
void cleanupTestCase();
|
|
|
|
|
2021-05-11 20:08:36 +02:00
|
|
|
void basic_cycle_cancelled();
|
2021-05-11 19:36:15 +02:00
|
|
|
void basic_cycle_won();
|
|
|
|
void basic_cycle_lost();
|
2021-05-11 20:08:36 +02:00
|
|
|
|
2021-05-11 19:36:15 +02:00
|
|
|
void basic_cycle_failed();
|
2021-05-11 20:08:36 +02:00
|
|
|
void basic_cycle_wildcard();
|
2021-05-11 19:36:15 +02:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
ScStwTimerTests::ScStwTimerTests()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ScStwTimerTests::~ScStwTimerTests()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScStwTimerTests::initTestCase()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScStwTimerTests::cleanupTestCase()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-05-11 20:08:36 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2021-05-11 19:36:15 +02:00
|
|
|
void ScStwTimerTests::basic_cycle_won()
|
|
|
|
{
|
2021-05-11 20:08:36 +02:00
|
|
|
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);
|
2021-05-11 19:36:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ScStwTimerTests::basic_cycle_lost()
|
|
|
|
{
|
2021-05-11 20:08:36 +02:00
|
|
|
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);
|
2021-05-11 19:36:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ScStwTimerTests::basic_cycle_failed()
|
|
|
|
{
|
2021-05-11 20:08:36 +02:00
|
|
|
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);
|
2021-05-11 19:36:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QTEST_APPLESS_MAIN(ScStwTimerTests)
|
|
|
|
|
|
|
|
#include "tst_scstwtimertests.moc"
|