2017-07-03 09:30:10 +02:00
|
|
|
/*!
|
|
|
|
* \brief Unit tests for \ref MsgHandlerInsertCard
|
|
|
|
*
|
2018-03-28 15:10:51 +02:00
|
|
|
* \copyright Copyright (c) 2016-2018 Governikus GmbH & Co. KG, Germany
|
2017-07-03 09:30:10 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "messages/MsgHandlerInsertCard.h"
|
|
|
|
|
|
|
|
#include "MessageDispatcher.h"
|
|
|
|
#include "MockReaderManagerPlugIn.h"
|
|
|
|
#include "ReaderManager.h"
|
|
|
|
|
|
|
|
#include <QtPlugin>
|
2017-09-15 10:23:30 +02:00
|
|
|
#include <QTest>
|
2017-07-03 09:30:10 +02:00
|
|
|
|
|
|
|
Q_IMPORT_PLUGIN(MockReaderManagerPlugIn)
|
|
|
|
|
|
|
|
using namespace governikus;
|
|
|
|
|
|
|
|
class test_MsgHandlerInsertCard
|
|
|
|
: public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
static void setContext(MessageDispatcher& pDispatcher)
|
|
|
|
{
|
|
|
|
QSharedPointer<WorkflowContext> context(new WorkflowContext());
|
|
|
|
pDispatcher.init(context);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private Q_SLOTS:
|
|
|
|
void initTestCase()
|
|
|
|
{
|
2019-01-03 15:06:22 +01:00
|
|
|
const auto readerManager = Env::getSingleton<ReaderManager>();
|
|
|
|
readerManager->init();
|
|
|
|
readerManager->getPlugInInfos(); // just to wait until initialization finished
|
2017-07-03 09:30:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void cleanupTestCase()
|
|
|
|
{
|
2019-01-03 15:06:22 +01:00
|
|
|
Env::getSingleton<ReaderManager>()->shutdown();
|
2017-07-03 09:30:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ctor()
|
|
|
|
{
|
|
|
|
const QSharedPointer<WorkflowContext> context(new WorkflowContext());
|
|
|
|
QCOMPARE(context->isStateApproved(), false);
|
|
|
|
|
|
|
|
MsgDispatcherContext ctx;
|
|
|
|
ctx.setWorkflowContext(context);
|
|
|
|
MsgHandlerInsertCard msg(ctx);
|
|
|
|
|
|
|
|
QCOMPARE(msg.toJson(), QByteArray("{\"msg\":\"INSERT_CARD\"}"));
|
|
|
|
QCOMPARE(context->isStateApproved(), true);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void noReader()
|
|
|
|
{
|
|
|
|
MessageDispatcher dispatcher;
|
|
|
|
setContext(dispatcher);
|
|
|
|
|
2017-12-20 14:54:05 +01:00
|
|
|
QCOMPARE(dispatcher.processStateChange(QStringLiteral("StateSelectReader")), QByteArray("{\"msg\":\"INSERT_CARD\"}"));
|
2017-07-03 09:30:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void readerWithoutCard()
|
|
|
|
{
|
|
|
|
MockReaderManagerPlugIn::getInstance().addReader("MockReader 1");
|
|
|
|
MockReaderManagerPlugIn::getInstance().addReader("MockReader 2");
|
|
|
|
MockReaderManagerPlugIn::getInstance().addReader("MockReader 3");
|
|
|
|
|
|
|
|
MessageDispatcher dispatcher;
|
|
|
|
setContext(dispatcher);
|
|
|
|
|
2017-12-20 14:54:05 +01:00
|
|
|
QCOMPARE(dispatcher.processStateChange(QStringLiteral("StateSelectReader")), QByteArray("{\"msg\":\"INSERT_CARD\"}"));
|
2017-07-03 09:30:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void readerWithCard()
|
|
|
|
{
|
|
|
|
MockReaderManagerPlugIn::getInstance().addReader("MockReader 1");
|
|
|
|
MockReader* reader = MockReaderManagerPlugIn::getInstance().addReader("MockReader CARD");
|
|
|
|
reader->setCard(MockCardConfig());
|
|
|
|
|
|
|
|
MessageDispatcher dispatcher;
|
|
|
|
setContext(dispatcher);
|
|
|
|
|
2017-12-20 14:54:05 +01:00
|
|
|
QCOMPARE(dispatcher.processStateChange(QStringLiteral("StateSelectReader")), QByteArray());
|
2017-07-03 09:30:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
QTEST_GUILESS_MAIN(test_MsgHandlerInsertCard)
|
|
|
|
#include "test_MsgHandlerInsertCard.moc"
|