2017-07-03 09:30:10 +02:00
|
|
|
/*!
|
|
|
|
* \brief Unit tests for \ref BaseCardCommand
|
|
|
|
*
|
|
|
|
* \copyright Copyright (c) 2015 Governikus GmbH & Co. KG
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "command/BaseCardCommand.h"
|
|
|
|
|
|
|
|
#include "MockReader.h"
|
|
|
|
|
|
|
|
#include <QtCore>
|
|
|
|
#include <QtTest>
|
|
|
|
|
|
|
|
using namespace governikus;
|
|
|
|
|
|
|
|
class BaseCardCommandDummy
|
|
|
|
: public BaseCardCommand
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
BaseCardCommandDummy(Reader* pReader)
|
|
|
|
: BaseCardCommand(CardConnectionWorker::create(pReader))
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
virtual void internalExecute()
|
|
|
|
{
|
2017-07-03 09:33:28 +02:00
|
|
|
mReturnCode = CardReturnCode::OK;
|
2017-07-03 09:30:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
class test_BaseCardCommand
|
|
|
|
: public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
private Q_SLOTS:
|
|
|
|
void commandDone()
|
|
|
|
{
|
|
|
|
MockReader reader("dummy reader");
|
|
|
|
BaseCardCommandDummy command(&reader);
|
2017-07-03 09:33:28 +02:00
|
|
|
QCOMPARE(command.getReturnCode(), CardReturnCode::UNKNOWN);
|
2017-07-03 09:30:10 +02:00
|
|
|
|
|
|
|
QSignalSpy spy(&command, &BaseCardCommand::commandDone);
|
|
|
|
QMetaObject::invokeMethod(&command, "execute");
|
|
|
|
|
|
|
|
QCOMPARE(spy.count(), 1);
|
|
|
|
auto param = spy.takeFirst();
|
|
|
|
QSharedPointer<BaseCardCommand> sharedCommand = param.at(0).value<QSharedPointer<BaseCardCommand> >();
|
|
|
|
QCOMPARE(sharedCommand.data(), &command);
|
2017-07-03 09:33:28 +02:00
|
|
|
QCOMPARE(command.getReturnCode(), CardReturnCode::OK);
|
2017-07-03 09:30:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void checkRetryCounterAndPrepareForPaceNoCard()
|
|
|
|
{
|
|
|
|
MockReader reader("dummy reader");
|
|
|
|
BaseCardCommandDummy command(&reader);
|
2017-07-03 09:33:28 +02:00
|
|
|
QCOMPARE(command.checkRetryCounterAndPrepareForPace("test"), CardReturnCode::CARD_NOT_FOUND);
|
2017-07-03 09:30:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
QTEST_GUILESS_MAIN(test_BaseCardCommand)
|
|
|
|
#include "test_BaseCardCommand.moc"
|