Initial commit
This commit is contained in:
commit
b7d90b9afe
16245 files changed
+3396666
No files matched your search
@@ -0,0 +1,150 @@
|
||||
/**
|
||||
* Unittest for testing the statemachine for aes objects
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
*/
|
||||
|
||||
#include "aes_statemachine_test.h"
|
||||
#include <QDebug>
|
||||
#include <QSignalSpy>
|
||||
#include <QTest>
|
||||
#include <nglapplication/nglcoreapplication.h>
|
||||
|
||||
using namespace AreaEffectSimulation;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
NGLCoreApplication app(argc, argv);
|
||||
app.createLogger("StateMachineTest", "log4cxx_AreaEffectSimulation.props");
|
||||
|
||||
StateMachineTest *test = new StateMachineTest;
|
||||
int retCode = QTest::qExec(test, argc, argv);
|
||||
delete test;
|
||||
|
||||
return retCode;
|
||||
}
|
||||
|
||||
namespace QTest
|
||||
{
|
||||
template<>
|
||||
char *toString(const AesEffectState &s) { std::ostringstream str; str << s; return strdup(str.str().c_str()); }
|
||||
}
|
||||
|
||||
DummyAesObject::DummyAesObject(QObject *parent)
|
||||
: ObjectBaseTmpl(nullptr, QStringLiteral("DummyAesObject"), parent)
|
||||
{}
|
||||
|
||||
QPolygonF DummyAesObject::generateForm()
|
||||
{
|
||||
return QPolygonF();
|
||||
}
|
||||
|
||||
StateMachineTest::StateMachineTest()
|
||||
: m_dummyAesObject(new DummyAesObject(this))
|
||||
{}
|
||||
|
||||
StateMachineTest::~StateMachineTest()
|
||||
{
|
||||
delete m_dummyAesObject;
|
||||
}
|
||||
|
||||
void StateMachineTest::staticTests()
|
||||
{
|
||||
const time_t tNow = time(nullptr);
|
||||
|
||||
// newly created, nothing set -> checkEnterNewState() should switch to created
|
||||
QCOMPARE(m_dummyAesObject->checkEnterNewState().underlying(), AesEffectState::EsCreated);
|
||||
|
||||
// now we set a activation time -> Prepared
|
||||
m_dummyAesObject->setActivationTime(tNow + 5);
|
||||
QCOMPARE(m_dummyAesObject->checkEnterNewState().underlying(), AesEffectState::EsPrepared);
|
||||
|
||||
// now back to created
|
||||
m_dummyAesObject->setActivationTime(0);
|
||||
QCOMPARE(m_dummyAesObject->checkEnterNewState().underlying(), AesEffectState::EsCreated);
|
||||
|
||||
// directly to activated
|
||||
m_dummyAesObject->setActivationTime(tNow);
|
||||
QCOMPARE(m_dummyAesObject->checkEnterNewState().underlying(), AesEffectState::EsActivated);
|
||||
|
||||
// pause not possible
|
||||
m_dummyAesObject->setSupportsPausing(false);
|
||||
QCOMPARE(m_dummyAesObject->trySwitchToPaused(), false);
|
||||
|
||||
// now possible
|
||||
m_dummyAesObject->setSupportsPausing(true);
|
||||
QCOMPARE(m_dummyAesObject->trySwitchToPaused(), true);
|
||||
|
||||
// and back to activated
|
||||
QCOMPARE(m_dummyAesObject->isActivationTimeReached(), true); // sanity
|
||||
QCOMPARE(m_dummyAesObject->trySwitchToActivated(), true);
|
||||
|
||||
// set end time
|
||||
m_dummyAesObject->setActivationTime(tNow);
|
||||
m_dummyAesObject->setDurationSec(1);
|
||||
|
||||
// wait 1.5sec (100 * QTest::qWait(15))
|
||||
for (int i = 0; i < 100; ++i)
|
||||
{
|
||||
QTest::qWait(15);
|
||||
}
|
||||
QCOMPARE(m_dummyAesObject->checkEnterNewState().underlying(), AesEffectState::EsExpired);
|
||||
|
||||
// try to delete it
|
||||
QCOMPARE(m_dummyAesObject->trySwitchToRemoved(), false);
|
||||
m_dummyAesObject->setActivationTime(0);
|
||||
m_dummyAesObject->setDurationSec(0);
|
||||
m_dummyAesObject->setAesEffectState(AesEffectState::EsUnknown);
|
||||
QCOMPARE(m_dummyAesObject->trySwitchToRemoved(), false);
|
||||
m_dummyAesObject->setAesEffectState(AesEffectState::EsCreated);
|
||||
QCOMPARE(m_dummyAesObject->trySwitchToRemoved(), true);
|
||||
m_dummyAesObject->setAesEffectState(AesEffectState::EsPaused);
|
||||
QCOMPARE(m_dummyAesObject->trySwitchToRemoved(), true);
|
||||
// an active/paused object must not set to deleted but to expired
|
||||
QCOMPARE(m_dummyAesObject->effectState().underlying(), AesEffectState::EsExpired);
|
||||
QCOMPARE(m_dummyAesObject->trySwitchToCreated(), false);
|
||||
}
|
||||
|
||||
void StateMachineTest::dynamicTests()
|
||||
{
|
||||
const time_t tNow = time(nullptr);
|
||||
|
||||
QSignalSpy spy(m_dummyAesObject, &DummyAesObject::effectStateChanged);
|
||||
|
||||
m_dummyAesObject->setAesEffectState(AesEffectState::EsUnknown);
|
||||
// set activation time
|
||||
m_dummyAesObject->setActivationTime(tNow + 1);
|
||||
QCOMPARE(m_dummyAesObject->isActivationTimeSet(), true);
|
||||
|
||||
// set end time
|
||||
m_dummyAesObject->setDurationSec(2);
|
||||
QCOMPARE(m_dummyAesObject->isEndTimeSet(), true);
|
||||
|
||||
QCOMPARE(m_dummyAesObject->checkEnterNewState().underlying(), AesEffectState::EsPrepared);
|
||||
QCOMPARE(spy.count(), 2); // Created, Prepared
|
||||
spy.clear();
|
||||
|
||||
qDebug() << "Waiting for activation time";
|
||||
for (int i = 0; i < 100; ++i)
|
||||
{
|
||||
QTest::qWait(15); // wait until the object is Activated
|
||||
if (m_dummyAesObject->effectState() == AesEffectState::EsActivated)
|
||||
break;
|
||||
}
|
||||
QCOMPARE(m_dummyAesObject->effectState().underlying(), AesEffectState::EsActivated);
|
||||
|
||||
qDebug() << "Waiting for end time";
|
||||
for (int i = 0; i < 200; ++i)
|
||||
{
|
||||
QTest::qWait(15); // wait until the object is Expired
|
||||
if (m_dummyAesObject->effectState() == AesEffectState::EsExpired)
|
||||
break;
|
||||
}
|
||||
AreaEffectSimulation::AesEffectState state = m_dummyAesObject->effectState();
|
||||
QCOMPARE(state.underlying(), AesEffectState::EsExpired);
|
||||
|
||||
QCOMPARE(spy.count(), 2); // Activated, Done
|
||||
spy.clear();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user