2017-07-03 09:30:10 +02:00
|
|
|
/*!
|
|
|
|
* \brief Unit tests for \ref BaseCardCommand
|
|
|
|
*
|
2019-05-22 10:08:38 +02:00
|
|
|
* \copyright Copyright (c) 2015-2019 Governikus GmbH & Co. KG, Germany
|
2017-07-03 09:30:10 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "command/BaseCardCommand.h"
|
|
|
|
|
2019-01-03 15:06:22 +01:00
|
|
|
#include "LogHandler.h"
|
|
|
|
#include "MockCardConnectionWorker.h"
|
2017-07-03 09:30:10 +02:00
|
|
|
|
|
|
|
#include <QtCore>
|
|
|
|
#include <QtTest>
|
|
|
|
|
|
|
|
using namespace governikus;
|
|
|
|
|
|
|
|
class BaseCardCommandDummy
|
|
|
|
: public BaseCardCommand
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
BaseCardCommandDummy(Reader* pReader)
|
|
|
|
: BaseCardCommand(CardConnectionWorker::create(pReader))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-20 14:54:05 +01:00
|
|
|
virtual void internalExecute() override
|
2017-07-03 09:30:10 +02:00
|
|
|
{
|
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:
|
2019-01-03 15:06:22 +01:00
|
|
|
void initTestCase()
|
|
|
|
{
|
|
|
|
Env::getSingleton<LogHandler>()->init();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void cleanup()
|
|
|
|
{
|
|
|
|
Env::getSingleton<LogHandler>()->resetBacklog();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-07-03 09:30:10 +02:00
|
|
|
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);
|
2019-01-03 15:06:22 +01:00
|
|
|
command.run();
|
2017-07-03 09:30:10 +02:00
|
|
|
|
2019-01-03 15:06:22 +01:00
|
|
|
QTRY_COMPARE(spy.count(), 1);
|
2017-07-03 09:30:10 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
QTEST_GUILESS_MAIN(test_BaseCardCommand)
|
|
|
|
#include "test_BaseCardCommand.moc"
|