From 275d62f364da0eee08726d95888bca2a8e0fb6e6 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Tue, 29 Sep 2009 16:34:58 +1000 Subject: TextEdit navigation testcase --- .../declarative/qfxtextedit/data/navigation.qml | 23 +++++++++ tests/auto/declarative/qfxtextedit/qfxtextedit.pro | 3 ++ .../declarative/qfxtextedit/tst_qfxtextedit.cpp | 56 +++++++++++++++++++++- 3 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 tests/auto/declarative/qfxtextedit/data/navigation.qml diff --git a/tests/auto/declarative/qfxtextedit/data/navigation.qml b/tests/auto/declarative/qfxtextedit/data/navigation.qml new file mode 100644 index 0000000..5b8613f --- /dev/null +++ b/tests/auto/declarative/qfxtextedit/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 + } + + TextEdit { 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/qfxtextedit/qfxtextedit.pro b/tests/auto/declarative/qfxtextedit/qfxtextedit.pro index 59ab6e5..90546a4 100644 --- a/tests/auto/declarative/qfxtextedit/qfxtextedit.pro +++ b/tests/auto/declarative/qfxtextedit/qfxtextedit.pro @@ -1,3 +1,6 @@ load(qttest_p4) contains(QT_CONFIG,declarative): QT += declarative gui SOURCES += tst_qfxtextedit.cpp + +# Define SRCDIR equal to test's source directory +DEFINES += SRCDIR=\\\"$$PWD\\\" diff --git a/tests/auto/declarative/qfxtextedit/tst_qfxtextedit.cpp b/tests/auto/declarative/qfxtextedit/tst_qfxtextedit.cpp index e38e0e7..7ab598f 100644 --- a/tests/auto/declarative/qfxtextedit/tst_qfxtextedit.cpp +++ b/tests/auto/declarative/qfxtextedit/tst_qfxtextedit.cpp @@ -1,4 +1,6 @@ #include +#include "../../../shared/util.h" +#include #include #include #include @@ -6,6 +8,7 @@ #include #include #include +#include class tst_qfxtextedit : public QObject @@ -27,8 +30,12 @@ private slots: void selection(); void cursorDelegate(); + void navigation(); private: + void simulateKey(QmlView *, int key); + QmlView *createView(const QString &filename); + QStringList standard; QStringList richText; @@ -424,7 +431,6 @@ void tst_qfxtextedit::selection() QVERIFY(textEditObject->selectedText().size() == 10); } -#include void tst_qfxtextedit::cursorDelegate() { QmlView* view = new QmlView(0); @@ -452,6 +458,54 @@ void tst_qfxtextedit::cursorDelegate() QVERIFY(!textEditObject->findChild("cursorInstance")); } +/* +TextEdit element should only handle left/right keys until the cursor reaches +the extent of the text, then they should ignore the keys. +*/ +void tst_qfxtextedit::navigation() +{ + QmlView *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); + QTRY_VERIFY(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_qfxtextedit::simulateKey(QmlView *view, int key) +{ + QKeyEvent press(QKeyEvent::KeyPress, key, 0); + QKeyEvent release(QKeyEvent::KeyRelease, key, 0); + + QApplication::sendEvent(view, &press); + QApplication::sendEvent(view, &release); +} + +QmlView *tst_qfxtextedit::createView(const QString &filename) +{ + QmlView *canvas = new QmlView(0); + + QFile file(filename); + file.open(QFile::ReadOnly); + QString xml = file.readAll(); + canvas->setQml(xml, filename); + + return canvas; +} + + QTEST_MAIN(tst_qfxtextedit) #include "tst_qfxtextedit.moc" -- cgit v0.12