diff --git a/ScStwLibraries/tests/scstwtestingtimer.cpp b/ScStwLibraries/tests/scstwtestingtimer.cpp new file mode 100644 index 0000000..84a29ba --- /dev/null +++ b/ScStwLibraries/tests/scstwtestingtimer.cpp @@ -0,0 +1,10 @@ +#include "scstwtestingtimer.h" + +ScStwTestingTimer::ScStwTestingTimer() +{ + +} + +void ScStwTestingTimer::handleClimberStart(double timeOfStart) { + ScStwTimer::handleClimberStart(timeOfStart); +} diff --git a/ScStwLibraries/tests/scstwtestingtimer.h b/ScStwLibraries/tests/scstwtestingtimer.h new file mode 100644 index 0000000..6b83ff6 --- /dev/null +++ b/ScStwLibraries/tests/scstwtestingtimer.h @@ -0,0 +1,14 @@ +#ifndef SCSTWTESTINGTIMER_H +#define SCSTWTESTINGTIMER_H + +#include +#include + +class ScStwTestingTimer : public ScStwTimer +{ +public: + ScStwTestingTimer(); + void handleClimberStart(double timeOfStart); +}; + +#endif // SCSTWTESTINGTIMER_H diff --git a/ScStwLibraries/tests/tests.pro b/ScStwLibraries/tests/tests.pro index 9708cdf..830e8a9 100644 --- a/ScStwLibraries/tests/tests.pro +++ b/ScStwLibraries/tests/tests.pro @@ -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 diff --git a/ScStwLibraries/tests/tst_scstwrace.cpp b/ScStwLibraries/tests/tst_scstwrace.cpp new file mode 100644 index 0000000..f855664 --- /dev/null +++ b/ScStwLibraries/tests/tst_scstwrace.cpp @@ -0,0 +1,49 @@ +#include +#include + +#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" diff --git a/ScStwLibraries/tests/tst_scstwtimertests.cpp b/ScStwLibraries/tests/tst_scstwtimertests.cpp index fda43ee..30c877f 100644 --- a/ScStwLibraries/tests/tst_scstwtimertests.cpp +++ b/ScStwLibraries/tests/tst_scstwtimertests.cpp @@ -1,5 +1,8 @@ #include -#include "scstwlibraries.h" +#include + +#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)