summaryrefslogtreecommitdiffstats
path: root/tests/auto/declarative/qfxtextedit
diff options
context:
space:
mode:
authorAlan Alpert <alan.alpert@nokia.com>2009-07-09 07:06:22 (GMT)
committerAlan Alpert <alan.alpert@nokia.com>2009-07-09 07:06:22 (GMT)
commit3399066881c42d1dd6fda6b3ae8cf3fc8961929b (patch)
tree57f623a4bb541ed0c7499a7fa6205b87f40c0312 /tests/auto/declarative/qfxtextedit
parentce0ff6de3d6f8715f6b7d18cdcb2f4b6a3a0c548 (diff)
downloadQt-3399066881c42d1dd6fda6b3ae8cf3fc8961929b.zip
Qt-3399066881c42d1dd6fda6b3ae8cf3fc8961929b.tar.gz
Qt-3399066881c42d1dd6fda6b3ae8cf3fc8961929b.tar.bz2
Fix QFxTextEdit cursorDelegate auto test properly
Also fixes the minor bug that it found.
Diffstat (limited to 'tests/auto/declarative/qfxtextedit')
-rw-r--r--tests/auto/declarative/qfxtextedit/data/cursorTest.qml6
-rw-r--r--tests/auto/declarative/qfxtextedit/tst_qfxtextedit.cpp51
2 files changed, 16 insertions, 41 deletions
diff --git a/tests/auto/declarative/qfxtextedit/data/cursorTest.qml b/tests/auto/declarative/qfxtextedit/data/cursorTest.qml
new file mode 100644
index 0000000..10ac2fd
--- /dev/null
+++ b/tests/auto/declarative/qfxtextedit/data/cursorTest.qml
@@ -0,0 +1,6 @@
+Rect { width: 300; height: 300; color: "white"
+ TextEdit { text: "Hello world!"; focusable: true; id: textEditObject
+ resources: [ Component { id:cursor; Item { id:cursorInstance } } ]
+ cursorDelegate: cursor
+ }
+}
diff --git a/tests/auto/declarative/qfxtextedit/tst_qfxtextedit.cpp b/tests/auto/declarative/qfxtextedit/tst_qfxtextedit.cpp
index 809ed5b..241dbad 100644
--- a/tests/auto/declarative/qfxtextedit/tst_qfxtextedit.cpp
+++ b/tests/auto/declarative/qfxtextedit/tst_qfxtextedit.cpp
@@ -43,38 +43,6 @@ private:
QmlEngine engine;
};
-/*
- Find an item with the specified id. If index is supplied then the
- item must also evaluate the {index} expression equal to index
-
- Copied from ListView test
-*/
-template<typename T>
-T *findItem(QFxItem *parent, const QString &id, int index=0)
-{
- const QMetaObject &mo = T::staticMetaObject;
- qDebug() << parent->children()->count() << "children";
- for (int i = 0; i < parent->children()->count(); ++i) {
- QFxItem *item = parent->children()->at(i);
- qDebug() << "try" << item;
- if (mo.cast(item) && (id.isEmpty() || item->id() == id)) {
- if (index != -1) {
- QmlExpression e(qmlContext(item), "index", item);
- e.setTrackChange(false);
- if (e.value().toInt() == index)
- return static_cast<T*>(item);
- } else {
- return static_cast<T*>(item);
- }
- }
- item = findItem<T>(item, id, index);
- if (item)
- return static_cast<T*>(item);
- }
-
- return 0;
-}
-
tst_qfxtextedit::tst_qfxtextedit()
{
standard << "the quick brown fox jumped over the lazy dog"
@@ -456,21 +424,22 @@ void tst_qfxtextedit::selection()
QVERIFY(textEditObject->selectedText().size() == 10);
}
+#include <QFxView>
void tst_qfxtextedit::cursorDelegate()
{
- QString componentStr = "TextEdit { text: \""+ standard[1] +"\"; focusable: true; resources: [ Component { id:cursor; Item { id:cursorInstance } } ] cursorDelegate: cursor}";
- QmlComponent texteditComponent(&engine, componentStr.toLatin1(), QUrl());
- QFxTextEdit *textEditObject = qobject_cast<QFxTextEdit*>(texteditComponent.create());
+ QFxView* view = new QFxView(0);
+ view->show();
+ view->setUrl(QUrl("data/cursorTest.qml"));
+ view->execute();
+ QFxTextEdit *textEditObject = view->root()->findChild<QFxTextEdit*>("textEditObject");
QVERIFY(textEditObject != 0);
- QVERIFY(!findItem<QFxItem>(textEditObject, "cursorInstance"));
+ QVERIFY(textEditObject->findChild<QFxItem*>("cursorInstance"));
//Test Delegate gets created
textEditObject->setFocus(true);
- //TODO:To get focus you also need to be in a focused window - switch this to a QFxView
- return;
- QFxItem* delegateObject = findItem<QFxItem>(textEditObject, "cursorInstance");
+ QFxItem* delegateObject = textEditObject->findChild<QFxItem*>("cursorInstance");
QVERIFY(delegateObject);
//Test Delegate gets moved
- for(int i=0; i<= standard[1].size(); i++){
+ for(int i=0; i<= textEditObject->text().length(); i++){
textEditObject->setCursorPosition(i);
QCOMPARE(textEditObject->cursorRect().x(), qRound(delegateObject->x()));
QCOMPARE(textEditObject->cursorRect().y(), qRound(delegateObject->y()));
@@ -480,7 +449,7 @@ void tst_qfxtextedit::cursorDelegate()
QCOMPARE(textEditObject->cursorRect().y(), qRound(delegateObject->y()));
//Test Delegate gets deleted
textEditObject->setCursorDelegate(0);
- QVERIFY(!findItem<QFxItem>(textEditObject, "cursorInstance"));
+ QVERIFY(!textEditObject->findChild<QFxItem*>("cursorInstance"));
}
QTEST_MAIN(tst_qfxtextedit)