Add some more tests
This commit is contained in:
parent
d5d8f5cffc
commit
b25a70a96c
5 changed files with 161 additions and 30 deletions
10
ScStwLibraries/tests/scstwtestingtimer.cpp
Normal file
10
ScStwLibraries/tests/scstwtestingtimer.cpp
Normal file
|
@ -0,0 +1,10 @@
|
|||
#include "scstwtestingtimer.h"
|
||||
|
||||
ScStwTestingTimer::ScStwTestingTimer()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void ScStwTestingTimer::handleClimberStart(double timeOfStart) {
|
||||
ScStwTimer::handleClimberStart(timeOfStart);
|
||||
}
|
14
ScStwLibraries/tests/scstwtestingtimer.h
Normal file
14
ScStwLibraries/tests/scstwtestingtimer.h
Normal file
|
@ -0,0 +1,14 @@
|
|||
#ifndef SCSTWTESTINGTIMER_H
|
||||
#define SCSTWTESTINGTIMER_H
|
||||
|
||||
#include <scstwtimer.h>
|
||||
#include <QObject>
|
||||
|
||||
class ScStwTestingTimer : public ScStwTimer
|
||||
{
|
||||
public:
|
||||
ScStwTestingTimer();
|
||||
void handleClimberStart(double timeOfStart);
|
||||
};
|
||||
|
||||
#endif // SCSTWTESTINGTIMER_H
|
|
@ -7,8 +7,13 @@ CONFIG -= app_bundle
|
|||
TEMPLATE = app
|
||||
|
||||
SOURCES += \
|
||||
scstwtestingtimer.cpp \
|
||||
tst_scstwrace.cpp \
|
||||
tst_scstwtimertests.cpp
|
||||
|
||||
# include submodules
|
||||
CONFIG += ScStwLibraries_QML ScStwLibraries_Styling ScStwLibraries_ClientLibs
|
||||
include($$PWD/../ScStwLibraries.pri)
|
||||
|
||||
HEADERS += \
|
||||
scstwtestingtimer.h
|
||||
|
|
49
ScStwLibraries/tests/tst_scstwrace.cpp
Normal file
49
ScStwLibraries/tests/tst_scstwrace.cpp
Normal file
|
@ -0,0 +1,49 @@
|
|||
#include <QtTest>
|
||||
#include <QDateTime>
|
||||
|
||||
#include "scstwrace.h"
|
||||
|
||||
// add necessary includes here
|
||||
|
||||
class ScStwRaceTests : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ScStwRaceTests();
|
||||
~ScStwRaceTests();
|
||||
|
||||
private slots:
|
||||
void initTestCase();
|
||||
void cleanupTestCase();
|
||||
|
||||
void basic_cycle();
|
||||
|
||||
};
|
||||
|
||||
ScStwRaceTests::ScStwRaceTests()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
ScStwRaceTests::~ScStwRaceTests()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void ScStwRaceTests::initTestCase()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void ScStwRaceTests::cleanupTestCase()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void ScStwRaceTests::basic_cycle()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
#include "tst_scstwrace.moc"
|
|
@ -1,5 +1,8 @@
|
|||
#include <QtTest>
|
||||
#include "scstwlibraries.h"
|
||||
#include <QDateTime>
|
||||
|
||||
#include "scstwtimer.h"
|
||||
#include "scstwtestingtimer.h"
|
||||
|
||||
// add necessary includes here
|
||||
|
||||
|
@ -15,9 +18,12 @@ 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();
|
||||
|
||||
};
|
||||
|
||||
|
@ -41,46 +47,93 @@ 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 = new ScStwTimer();
|
||||
QCOMPARE(timer->getState(), ScStwTimer::IDLE);
|
||||
timer->start();
|
||||
QCOMPARE(timer->getState(), ScStwTimer::RUNNING);
|
||||
timer->stop();
|
||||
QCOMPARE(timer->getState(), ScStwTimer::WAITING);
|
||||
timer->setResult(ScStwTimer::WON);
|
||||
QCOMPARE(timer->getState(), ScStwTimer::WON);
|
||||
timer->reset();
|
||||
QCOMPARE(timer->getState(), ScStwTimer::IDLE);
|
||||
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 = new ScStwTimer();
|
||||
QCOMPARE(timer->getState(), ScStwTimer::IDLE);
|
||||
timer->start();
|
||||
QCOMPARE(timer->getState(), ScStwTimer::RUNNING);
|
||||
timer->stop();
|
||||
QCOMPARE(timer->getState(), ScStwTimer::WAITING);
|
||||
timer->setResult(ScStwTimer::LOST);
|
||||
QCOMPARE(timer->getState(), ScStwTimer::LOST);
|
||||
timer->reset();
|
||||
QCOMPARE(timer->getState(), ScStwTimer::IDLE);
|
||||
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()
|
||||
{
|
||||
ScStwTimer * timer = new ScStwTimer();
|
||||
QCOMPARE(timer->getState(), ScStwTimer::IDLE);
|
||||
timer->start();
|
||||
QCOMPARE(timer->getState(), ScStwTimer::RUNNING);
|
||||
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);
|
||||
|
||||
QCOMPARE(timer->getState(), ScStwTimer::WAITING);
|
||||
timer->setResult(ScStwTimer::WON);
|
||||
QCOMPARE(timer->getState(), ScStwTimer::WON);
|
||||
timer->reset();
|
||||
QCOMPARE(timer->getState(), ScStwTimer::IDLE);
|
||||
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)
|
||||
|
|
Reference in a new issue