From 5ef36ea88e15bb4a12575c6639b1d9e6c3be9de6 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Wed, 2 Sep 2009 10:57:30 +1000 Subject: Add TextInput key handling test --- .../declarative/qfxtextinput/data/navigation.qml | 23 +++++++ .../auto/declarative/qfxtextinput/qfxtextinput.pro | 6 ++ .../declarative/qfxtextinput/tst_qfxtextinput.cpp | 78 ++++++++++++++++++++++ 3 files changed, 107 insertions(+) create mode 100644 tests/auto/declarative/qfxtextinput/data/navigation.qml create mode 100644 tests/auto/declarative/qfxtextinput/qfxtextinput.pro create mode 100644 tests/auto/declarative/qfxtextinput/tst_qfxtextinput.cpp diff --git a/tests/auto/declarative/qfxtextinput/data/navigation.qml b/tests/auto/declarative/qfxtextinput/data/navigation.qml new file mode 100644 index 0000000..c1a6162 --- /dev/null +++ b/tests/auto/declarative/qfxtextinput/data/navigation.qml @@ -0,0 +1,23 @@ +import Qt 4.6 + +Rectangle { + property var myInput: Input + + width: 800; height: 600; color: "blue" + + Item { + id: FirstItem + KeyNavigation.right: Input + } + + TextInput { id: Input; focus: true; + KeyNavigation.left: FirstItem + KeyNavigation.right: LastItem + KeyNavigation.up: FirstItem + KeyNavigation.down: LastItem + } + Item { + id: LastItem + KeyNavigation.left: Input + } +} diff --git a/tests/auto/declarative/qfxtextinput/qfxtextinput.pro b/tests/auto/declarative/qfxtextinput/qfxtextinput.pro new file mode 100644 index 0000000..396e66d --- /dev/null +++ b/tests/auto/declarative/qfxtextinput/qfxtextinput.pro @@ -0,0 +1,6 @@ +load(qttest_p4) +contains(QT_CONFIG,declarative): QT += declarative gui +SOURCES += tst_qfxtextinput.cpp + +# Define SRCDIR equal to test's source directory +DEFINES += SRCDIR=\\\"$$PWD\\\" diff --git a/tests/auto/declarative/qfxtextinput/tst_qfxtextinput.cpp b/tests/auto/declarative/qfxtextinput/tst_qfxtextinput.cpp new file mode 100644 index 0000000..852a868 --- /dev/null +++ b/tests/auto/declarative/qfxtextinput/tst_qfxtextinput.cpp @@ -0,0 +1,78 @@ +#include +#include +#include +#include +#include +#include + +class tst_qfxtextinput : public QObject + +{ + Q_OBJECT +public: + tst_qfxtextinput(); + +private slots: + void navigation(); + +private: + void simulateKey(QFxView *, int key); + QFxView *createView(const QString &filename); + + QmlEngine engine; +}; + +tst_qfxtextinput::tst_qfxtextinput() +{ +} + +/* +TextInput element should only handle left/right keys until the cursor reaches +the extent of the text, then they should ignore the keys. +*/ +void tst_qfxtextinput::navigation() +{ + QFxView *canvas = createView(SRCDIR "/data/navigation.qml"); + canvas->execute(); + canvas->show(); + + QVERIFY(canvas->root() != 0); + + QFxItem *input = qobject_cast(qvariant_cast(canvas->root()->property("myInput"))); + + QVERIFY(input != 0); + QVERIFY(input->hasFocus() == true); + simulateKey(canvas, Qt::Key_Left); + QVERIFY(input->hasFocus() == false); + simulateKey(canvas, Qt::Key_Right); + QVERIFY(input->hasFocus() == true); + simulateKey(canvas, Qt::Key_Right); + QVERIFY(input->hasFocus() == false); + simulateKey(canvas, Qt::Key_Left); + QVERIFY(input->hasFocus() == true); +} + +void tst_qfxtextinput::simulateKey(QFxView *view, int key) +{ + QKeyEvent press(QKeyEvent::KeyPress, key, 0); + QKeyEvent release(QKeyEvent::KeyRelease, key, 0); + + QApplication::sendEvent(view, &press); + QApplication::sendEvent(view, &release); +} + +QFxView *tst_qfxtextinput::createView(const QString &filename) +{ + QFxView *canvas = new QFxView(0); + + QFile file(filename); + file.open(QFile::ReadOnly); + QString xml = file.readAll(); + canvas->setQml(xml, filename); + + return canvas; +} + +QTEST_MAIN(tst_qfxtextinput) + +#include "tst_qfxtextinput.moc" -- cgit v0.12