2017-07-03 09:30:10 +02:00
|
|
|
/*!
|
2018-03-28 15:10:51 +02:00
|
|
|
* \copyright Copyright (c) 2014-2018 Governikus GmbH & Co. KG, Germany
|
2017-07-03 09:30:10 +02:00
|
|
|
*/
|
|
|
|
|
2017-12-20 14:54:05 +01:00
|
|
|
#include "ReaderManager.h"
|
2017-07-03 09:30:10 +02:00
|
|
|
|
|
|
|
#include "MockReaderManagerPlugIn.h"
|
|
|
|
|
2017-07-03 09:33:28 +02:00
|
|
|
#include <QCoreApplication>
|
2017-07-03 09:30:10 +02:00
|
|
|
#include <QSharedPointer>
|
|
|
|
#include <QSignalSpy>
|
2017-07-03 09:33:28 +02:00
|
|
|
#include <QtTest>
|
2017-07-03 09:30:10 +02:00
|
|
|
|
|
|
|
Q_IMPORT_PLUGIN(MockReaderManagerPlugIn)
|
|
|
|
|
|
|
|
using namespace governikus;
|
|
|
|
|
|
|
|
|
|
|
|
class CreateCardConnectionCommandSlot
|
|
|
|
: public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
QSharedPointer<CardConnection> mCardConnection;
|
|
|
|
bool mSlotCalled = false;
|
|
|
|
|
|
|
|
public Q_SLOTS:
|
|
|
|
void onCardCommandDone(QSharedPointer<CreateCardConnectionCommand> pCommand)
|
|
|
|
{
|
|
|
|
mSlotCalled = true;
|
|
|
|
mCardConnection = pCommand->getCardConnection();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class test_ReaderManager
|
|
|
|
: public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
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 fireReaderAdded()
|
|
|
|
{
|
2019-01-03 15:06:22 +01:00
|
|
|
QSignalSpy spy(Env::getSingleton<ReaderManager>(), &ReaderManager::fireReaderAdded);
|
2017-07-03 09:30:10 +02:00
|
|
|
|
|
|
|
MockReaderManagerPlugIn::getInstance().addReader("MockReader 4711");
|
|
|
|
|
2019-01-03 15:06:22 +01:00
|
|
|
QTRY_COMPARE(spy.count(), 1);
|
2017-07-03 09:30:10 +02:00
|
|
|
QCOMPARE(spy.takeFirst().at(0).toString(), QString("MockReader 4711"));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void fireReaderRemoved()
|
|
|
|
{
|
2019-01-03 15:06:22 +01:00
|
|
|
QSignalSpy spy(Env::getSingleton<ReaderManager>(), &ReaderManager::fireReaderRemoved);
|
2017-07-03 09:30:10 +02:00
|
|
|
MockReaderManagerPlugIn::getInstance().addReader("MockReader 4711");
|
|
|
|
|
|
|
|
MockReaderManagerPlugIn::getInstance().removeReader("MockReader 4711");
|
|
|
|
|
2019-01-03 15:06:22 +01:00
|
|
|
QTRY_COMPARE(spy.count(), 1);
|
2017-07-03 09:30:10 +02:00
|
|
|
QCOMPARE(spy.takeFirst().at(0).toString(), QString("MockReader 4711"));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void fireCreateCardConnection_forUnknownReader()
|
|
|
|
{
|
|
|
|
CreateCardConnectionCommandSlot commandSlot;
|
|
|
|
|
2019-01-03 15:06:22 +01:00
|
|
|
Env::getSingleton<ReaderManager>()->callCreateCardConnectionCommand("UnknownReader", &commandSlot, &CreateCardConnectionCommandSlot::onCardCommandDone);
|
2017-07-03 09:30:10 +02:00
|
|
|
|
2019-01-03 15:06:22 +01:00
|
|
|
QTRY_COMPARE(commandSlot.mSlotCalled, true);
|
2017-07-03 09:30:10 +02:00
|
|
|
QVERIFY(commandSlot.mCardConnection.isNull());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void fireCreateCardConnection_noCard()
|
|
|
|
{
|
|
|
|
CreateCardConnectionCommandSlot commandSlot;
|
|
|
|
MockReaderManagerPlugIn::getInstance().addReader("MockReader 4711");
|
|
|
|
|
2019-01-03 15:06:22 +01:00
|
|
|
Env::getSingleton<ReaderManager>()->callCreateCardConnectionCommand("UnknownReader", &commandSlot, &CreateCardConnectionCommandSlot::onCardCommandDone);
|
2017-07-03 09:30:10 +02:00
|
|
|
|
2019-01-03 15:06:22 +01:00
|
|
|
QTRY_COMPARE(commandSlot.mSlotCalled, true);
|
2017-07-03 09:30:10 +02:00
|
|
|
QVERIFY(commandSlot.mCardConnection.isNull());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void fireCreateCardConnection_cardConnectFail()
|
|
|
|
{
|
|
|
|
CreateCardConnectionCommandSlot commandSlot;
|
|
|
|
MockReader* reader = MockReaderManagerPlugIn::getInstance().addReader("MockReader 4711");
|
|
|
|
MockCardConfig cardConfig;
|
2017-07-03 09:33:28 +02:00
|
|
|
cardConfig.mConnect = CardReturnCode::COMMAND_FAILED;
|
2017-07-03 09:30:10 +02:00
|
|
|
reader->setCard(cardConfig);
|
|
|
|
|
2019-01-03 15:06:22 +01:00
|
|
|
Env::getSingleton<ReaderManager>()->callCreateCardConnectionCommand("MockReader 4711", &commandSlot, &CreateCardConnectionCommandSlot::onCardCommandDone);
|
2017-07-03 09:30:10 +02:00
|
|
|
|
2019-01-03 15:06:22 +01:00
|
|
|
QTRY_COMPARE(commandSlot.mSlotCalled, true);
|
2017-07-03 09:30:10 +02:00
|
|
|
QVERIFY(commandSlot.mCardConnection.isNull());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void fireCreateCardConnection()
|
|
|
|
{
|
|
|
|
CreateCardConnectionCommandSlot commandSlot;
|
|
|
|
MockReader* reader = MockReaderManagerPlugIn::getInstance().addReader("MockReader 4711");
|
|
|
|
MockCardConfig cardConfig;
|
2017-07-03 09:33:28 +02:00
|
|
|
cardConfig.mConnect = CardReturnCode::OK;
|
2017-07-03 09:30:10 +02:00
|
|
|
reader->setCard(cardConfig);
|
|
|
|
|
2019-01-03 15:06:22 +01:00
|
|
|
Env::getSingleton<ReaderManager>()->callCreateCardConnectionCommand("MockReader 4711", &commandSlot, &CreateCardConnectionCommandSlot::onCardCommandDone);
|
2017-07-03 09:30:10 +02:00
|
|
|
|
2019-01-03 15:06:22 +01:00
|
|
|
QTRY_COMPARE(commandSlot.mSlotCalled, true);
|
2017-07-03 09:30:10 +02:00
|
|
|
QVERIFY(!commandSlot.mCardConnection.isNull());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-20 14:54:05 +01:00
|
|
|
void getInvalidReaderInfoWithAndWithoutInitializedReaderManager()
|
|
|
|
{
|
|
|
|
{
|
2019-01-03 15:06:22 +01:00
|
|
|
const auto& readerInfo = Env::getSingleton<ReaderManager>()->getReaderInfo("test dummy");
|
2017-12-20 14:54:05 +01:00
|
|
|
QCOMPARE(readerInfo.getPlugInType(), ReaderManagerPlugInType::UNKNOWN);
|
|
|
|
QCOMPARE(readerInfo.getName(), QStringLiteral("test dummy"));
|
|
|
|
}
|
|
|
|
|
|
|
|
cleanupTestCase();
|
|
|
|
{
|
2019-01-03 15:06:22 +01:00
|
|
|
const auto& readerInfo = Env::getSingleton<ReaderManager>()->getReaderInfo("test dummy");
|
2017-12-20 14:54:05 +01:00
|
|
|
QCOMPARE(readerInfo.getPlugInType(), ReaderManagerPlugInType::UNKNOWN);
|
|
|
|
QCOMPARE(readerInfo.getName(), QStringLiteral("test dummy"));
|
|
|
|
}
|
|
|
|
initTestCase();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-07-03 09:30:10 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
QTEST_GUILESS_MAIN(test_ReaderManager)
|
|
|
|
#include "test_ReaderManager.moc"
|