Extend auto-type test.

This commit is contained in:
Florian Geyer 2012-10-28 18:13:49 +01:00
parent d7cbec1a02
commit ac56ac98f7
5 changed files with 60 additions and 4 deletions

View file

@ -17,6 +17,11 @@
#include "AutoTypeTest.h" #include "AutoTypeTest.h"
QString AutoTypePlatformTest::keyToString(Qt::Key key)
{
return QString("[Key0x%1]").arg(key, 0, 16);
}
QStringList AutoTypePlatformTest::windowTitles() QStringList AutoTypePlatformTest::windowTitles()
{ {
return QStringList(); return QStringList();
@ -68,9 +73,9 @@ QString AutoTypePlatformTest::actionChars()
return m_actionChars; return m_actionChars;
} }
QList<AutoTypeAction*> AutoTypePlatformTest::actionList() int AutoTypePlatformTest::actionCount()
{ {
return m_actionList; return m_actionList.size();
} }
void AutoTypePlatformTest::clearActions() void AutoTypePlatformTest::clearActions()
@ -90,6 +95,7 @@ void AutoTypePlatformTest::addActionChar(AutoTypeChar* action)
void AutoTypePlatformTest::addActionKey(AutoTypeKey* action) void AutoTypePlatformTest::addActionKey(AutoTypeKey* action)
{ {
m_actionList.append(action->clone()); m_actionList.append(action->clone());
m_actionChars.append(keyToString(action->key));
} }

View file

@ -33,6 +33,8 @@ class AutoTypePlatformTest : public QObject,
Q_INTERFACES(AutoTypePlatformInterface AutoTypeTestInterface) Q_INTERFACES(AutoTypePlatformInterface AutoTypeTestInterface)
public: public:
QString keyToString(Qt::Key key);
QStringList windowTitles(); QStringList windowTitles();
WId activeWindow(); WId activeWindow();
QString activeWindowTitle(); QString activeWindowTitle();
@ -44,7 +46,7 @@ public:
void setActiveWindowTitle(const QString& title); void setActiveWindowTitle(const QString& title);
QString actionChars(); QString actionChars();
QList<AutoTypeAction*> actionList(); int actionCount();
void clearActions(); void clearActions();
void addActionChar(AutoTypeChar* action); void addActionChar(AutoTypeChar* action);

View file

@ -27,8 +27,10 @@ public:
virtual void setActiveWindowTitle(const QString& title) = 0; virtual void setActiveWindowTitle(const QString& title) = 0;
virtual QString actionChars() = 0; virtual QString actionChars() = 0;
virtual QList<AutoTypeAction*> actionList() = 0; virtual int actionCount() = 0;
virtual void clearActions() = 0; virtual void clearActions() = 0;
virtual QString keyToString(Qt::Key key) = 0;
}; };
Q_DECLARE_INTERFACE(AutoTypeTestInterface, "org.keepassx.AutoTypeTestInterface/1") Q_DECLARE_INTERFACE(AutoTypeTestInterface, "org.keepassx.AutoTypeTestInterface/1")

View file

@ -22,6 +22,8 @@
#include "tests.h" #include "tests.h"
#include "core/FilePath.h" #include "core/FilePath.h"
#include "core/Entry.h"
#include "core/Group.h"
#include "crypto/Crypto.h" #include "crypto/Crypto.h"
#include "autotype/AutoType.h" #include "autotype/AutoType.h"
#include "autotype/AutoTypePlatformPlugin.h" #include "autotype/AutoTypePlatformPlugin.h"
@ -42,6 +44,19 @@ void TestAutoType::initTestCase()
m_test = qobject_cast<AutoTypeTestInterface*>(loader.instance()); m_test = qobject_cast<AutoTypeTestInterface*>(loader.instance());
QVERIFY(m_test); QVERIFY(m_test);
m_autoType = AutoType::instance();
}
void TestAutoType::init()
{
m_test->clearActions();
m_group = new Group();
m_entry = new Entry();
m_entry->setGroup(m_group);
m_entry->setUsername("myuser");
m_entry->setPassword("mypass");
} }
void TestAutoType::testInternal() void TestAutoType::testInternal()
@ -52,4 +67,26 @@ void TestAutoType::testInternal()
QCOMPARE(m_platform->activeWindowTitle(), QString("Test")); QCOMPARE(m_platform->activeWindowTitle(), QString("Test"));
} }
void TestAutoType::testAutoTypeWithoutSequence()
{
m_autoType->performAutoType(m_entry, Q_NULLPTR);
QCOMPARE(m_test->actionCount(), 14);
QCOMPARE(m_test->actionChars(),
QString("myuser%1mypass%2")
.arg(m_test->keyToString(Qt::Key_Tab))
.arg(m_test->keyToString(Qt::Key_Enter)));
}
void TestAutoType::testAutoTypeWithSequence()
{
m_autoType->performAutoType(m_entry, Q_NULLPTR, "{Username}abc{PaSsWoRd}");
QCOMPARE(m_test->actionCount(), 15);
QCOMPARE(m_test->actionChars(),
QString("%1abc%2")
.arg(m_entry->username())
.arg(m_entry->password()));
}
QTEST_GUILESS_MAIN(TestAutoType) QTEST_GUILESS_MAIN(TestAutoType)

View file

@ -20,8 +20,11 @@
#include <QtCore/QObject> #include <QtCore/QObject>
class AutoType;
class AutoTypePlatformInterface; class AutoTypePlatformInterface;
class AutoTypeTestInterface; class AutoTypeTestInterface;
class Entry;
class Group;
class TestAutoType : public QObject class TestAutoType : public QObject
{ {
@ -29,11 +32,17 @@ class TestAutoType : public QObject
private Q_SLOTS: private Q_SLOTS:
void initTestCase(); void initTestCase();
void init();
void testInternal(); void testInternal();
void testAutoTypeWithoutSequence();
void testAutoTypeWithSequence();
private: private:
AutoTypePlatformInterface* m_platform; AutoTypePlatformInterface* m_platform;
AutoTypeTestInterface* m_test; AutoTypeTestInterface* m_test;
AutoType* m_autoType;
Group* m_group;
Entry* m_entry;
}; };
#endif // KEEPASSX_TESTAUTOTYPE_H #endif // KEEPASSX_TESTAUTOTYPE_H