#include "cardreader-t.h"
#include <QSignalSpy>

const QString TEST_CARDNUMBER = "1234_testcard";

void CardReaderTest::initTestCase()
{
	widget.installEventFilter(&cardReader);
}

void CardReaderTest::simulateRFIDReader()
{
	QSignalSpy spy(&cardReader, SIGNAL(newCardNumber(QString)));
	QVERIFY(spy.isValid());

	QTest::keyClicks(&widget, TEST_CARDNUMBER);
	QTest::keyClick(&widget, Qt::Key_Return);

	QCOMPARE(spy.count(), 1);

	QList<QVariant> arguments = spy.takeFirst();
	QCOMPARE(arguments.at(0).toString(), TEST_CARDNUMBER);
}

void CardReaderTest::simulateKeyboardInput()
{
	QSignalSpy spy(&cardReader, SIGNAL(newCardNumber(QString)));
	QVERIFY(spy.isValid());

	int keyTypingTime = 50;
	QTest::keyClicks(&widget, TEST_CARDNUMBER, Qt::NoModifier, keyTypingTime);
	QTest::keyClick(&widget, Qt::Key_Return);

	QCOMPARE(spy.count(), 0);
}

void CardReaderTest::simulateSecondRFIDReader()
{
	simulateRFIDReader();
}

QTEST_MAIN(CardReaderTest)

#include "cardreader-t.h"
#include <QSignalSpy>

const QString TEST_CARDNUMBER = "1234_testcard";

void CardReaderTest::initTestCase()
{
	widget.installEventFilter(&cardReader);
}

void CardReaderTest::simulateRFIDReader()
{
	QSignalSpy spy(&cardReader, SIGNAL(newCardNumber(QString)));
	QVERIFY(spy.isValid());

	QTest::keyClicks(&widget, TEST_CARDNUMBER);
	QTest::keyClick(&widget, Qt::Key_Return);

	QCOMPARE(spy.count(), 1);

	QList<QVariant> arguments = spy.takeFirst();
	QCOMPARE(arguments.at(0).toString(), TEST_CARDNUMBER);
}

void CardReaderTest::simulateKeyboardInput()
{
	QSignalSpy spy(&cardReader, SIGNAL(newCardNumber(QString)));
	QVERIFY(spy.isValid());

	int keyTypingTime = CARDREADER_TIME_LIMIT_MS*1.0/((TEST_CARDNUMBER.size())*1.0);
	QTest::keyClicks(&widget, TEST_CARDNUMBER, Qt::NoModifier, keyTypingTime);
	QTest::keyClick(&widget, Qt::Key_Return);

	QCOMPARE(spy.count(), 0);
}

void CardReaderTest::simulateSecondRFIDReader()
{
	simulateRFIDReader();
}

QTEST_MAIN(CardReaderTest)

--- 
+++ 
@@ -27,7 +27,7 @@
 	QSignalSpy spy(&cardReader, SIGNAL(newCardNumber(QString)));
 	QVERIFY(spy.isValid());
 
-	int keyTypingTime = CARDREADER_TIME_LIMIT_MS*1.0/((TEST_CARDNUMBER.size())*1.0);
+	int keyTypingTime = 50;
 	QTest::keyClicks(&widget, TEST_CARDNUMBER, Qt::NoModifier, keyTypingTime);
 	QTest::keyClick(&widget, Qt::Key_Return);
 
Use 50 ms for key typing time in the card reader test instead of something based on the card reader limit constant, in order to detect that the card reader constant is mis-set.
