From 7b52e7cf44e95d936181159d92e8b5e2ebbe2434 Mon Sep 17 00:00:00 2001 From: Dorian Zedler Date: Tue, 11 May 2021 19:35:43 +0200 Subject: [PATCH 1/3] add multimedia in pri file --- ScStwLibraries/ScStwLibraries.pri | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ScStwLibraries/ScStwLibraries.pri b/ScStwLibraries/ScStwLibraries.pri index 1c8b0cf..387dcd5 100644 --- a/ScStwLibraries/ScStwLibraries.pri +++ b/ScStwLibraries/ScStwLibraries.pri @@ -1,6 +1,8 @@ !isEmpty(SCSTWLIBRARIES_LIB):error("ScStwLibraries.pri already included") SCSTWLIBRARIES_LIB = 1 +QT += multimedia + ScStwLibraries_QML { QT += qml quickcontrols2 DEFINES += ScStwLibraries_QML From 6bfcd9be4764e7d46b607bbc3b29c76fe6cb8622 Mon Sep 17 00:00:00 2001 From: Dorian Zedler Date: Tue, 11 May 2021 19:36:15 +0200 Subject: [PATCH 2/3] add some tests --- ScStwLibraries/tests/.gitignore | 73 ++++++++++++++++ ScStwLibraries/tests/tests.pro | 14 ++++ ScStwLibraries/tests/tst_scstwtimertests.cpp | 88 ++++++++++++++++++++ 3 files changed, 175 insertions(+) create mode 100644 ScStwLibraries/tests/.gitignore create mode 100644 ScStwLibraries/tests/tests.pro create mode 100644 ScStwLibraries/tests/tst_scstwtimertests.cpp diff --git a/ScStwLibraries/tests/.gitignore b/ScStwLibraries/tests/.gitignore new file mode 100644 index 0000000..fab7372 --- /dev/null +++ b/ScStwLibraries/tests/.gitignore @@ -0,0 +1,73 @@ +# This file is used to ignore files which are generated +# ---------------------------------------------------------------------------- + +*~ +*.autosave +*.a +*.core +*.moc +*.o +*.obj +*.orig +*.rej +*.so +*.so.* +*_pch.h.cpp +*_resource.rc +*.qm +.#* +*.*# +core +!core/ +tags +.DS_Store +.directory +*.debug +Makefile* +*.prl +*.app +moc_*.cpp +ui_*.h +qrc_*.cpp +Thumbs.db +*.res +*.rc +/.qmake.cache +/.qmake.stash + +# qtcreator generated files +*.pro.user* + +# xemacs temporary files +*.flc + +# Vim temporary files +.*.swp + +# Visual Studio generated files +*.ib_pdb_index +*.idb +*.ilk +*.pdb +*.sln +*.suo +*.vcproj +*vcproj.*.*.user +*.ncb +*.sdf +*.opensdf +*.vcxproj +*vcxproj.* + +# MinGW generated files +*.Debug +*.Release + +# Python byte code +*.pyc + +# Binaries +# -------- +*.dll +*.exe + diff --git a/ScStwLibraries/tests/tests.pro b/ScStwLibraries/tests/tests.pro new file mode 100644 index 0000000..9708cdf --- /dev/null +++ b/ScStwLibraries/tests/tests.pro @@ -0,0 +1,14 @@ +QT += testlib +QT -= gui + +CONFIG += qt console warn_on depend_includepath testcase +CONFIG -= app_bundle + +TEMPLATE = app + +SOURCES += \ + tst_scstwtimertests.cpp + +# include submodules +CONFIG += ScStwLibraries_QML ScStwLibraries_Styling ScStwLibraries_ClientLibs +include($$PWD/../ScStwLibraries.pri) diff --git a/ScStwLibraries/tests/tst_scstwtimertests.cpp b/ScStwLibraries/tests/tst_scstwtimertests.cpp new file mode 100644 index 0000000..fda43ee --- /dev/null +++ b/ScStwLibraries/tests/tst_scstwtimertests.cpp @@ -0,0 +1,88 @@ +#include +#include "scstwlibraries.h" + +// add necessary includes here + +class ScStwTimerTests : public QObject +{ + Q_OBJECT + +public: + ScStwTimerTests(); + ~ScStwTimerTests(); + +private slots: + void initTestCase(); + void cleanupTestCase(); + + void basic_cycle_won(); + void basic_cycle_lost(); + void basic_cycle_failed(); + +}; + +ScStwTimerTests::ScStwTimerTests() +{ + +} + +ScStwTimerTests::~ScStwTimerTests() +{ + +} + +void ScStwTimerTests::initTestCase() +{ + +} + +void ScStwTimerTests::cleanupTestCase() +{ + +} + +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); +} + +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); +} + +void ScStwTimerTests::basic_cycle_failed() +{ + ScStwTimer * timer = new ScStwTimer(); + QCOMPARE(timer->getState(), ScStwTimer::IDLE); + timer->start(); + QCOMPARE(timer->getState(), ScStwTimer::RUNNING); + + QCOMPARE(timer->getState(), ScStwTimer::WAITING); + timer->setResult(ScStwTimer::WON); + QCOMPARE(timer->getState(), ScStwTimer::WON); + timer->reset(); + QCOMPARE(timer->getState(), ScStwTimer::IDLE); +} + +QTEST_APPLESS_MAIN(ScStwTimerTests) + +#include "tst_scstwtimertests.moc" From b25a70a96cd837c1f2a5c20f553baede507fd2fe Mon Sep 17 00:00:00 2001 From: Dorian Zedler Date: Tue, 11 May 2021 20:08:36 +0200 Subject: [PATCH 3/3] Add some more tests --- ScStwLibraries/tests/scstwtestingtimer.cpp | 10 ++ ScStwLibraries/tests/scstwtestingtimer.h | 14 +++ ScStwLibraries/tests/tests.pro | 5 + ScStwLibraries/tests/tst_scstwrace.cpp | 49 ++++++++ ScStwLibraries/tests/tst_scstwtimertests.cpp | 113 ++++++++++++++----- 5 files changed, 161 insertions(+), 30 deletions(-) create mode 100644 ScStwLibraries/tests/scstwtestingtimer.cpp create mode 100644 ScStwLibraries/tests/scstwtestingtimer.h create mode 100644 ScStwLibraries/tests/tst_scstwrace.cpp 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)