summaryrefslogtreecommitdiffstats
path: root/tests/auto/declarative/qdeclarativetextinput
diff options
context:
space:
mode:
authorWarwick Allison <warwick.allison@nokia.com>2010-06-01 02:39:15 (GMT)
committerWarwick Allison <warwick.allison@nokia.com>2010-06-01 02:39:15 (GMT)
commit5f6b50f99a6457c208c7f186db45a2dba690bace (patch)
treeef07d9ab881ddcebdf331c1a810fc50564bc940d /tests/auto/declarative/qdeclarativetextinput
parent06df53baf46ea7968b23f8b325990d047b5a67a5 (diff)
downloadQt-5f6b50f99a6457c208c7f186db45a2dba690bace.zip
Qt-5f6b50f99a6457c208c7f186db45a2dba690bace.tar.gz
Qt-5f6b50f99a6457c208c7f186db45a2dba690bace.tar.bz2
Test positionAt.
Task-number: QTBUG-11127 Task-number: QTBUG-11054
Diffstat (limited to 'tests/auto/declarative/qdeclarativetextinput')
-rw-r--r--tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp43
1 files changed, 43 insertions, 0 deletions
diff --git a/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp b/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp
index 54bb9c1..c943c89 100644
--- a/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp
+++ b/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp
@@ -63,6 +63,8 @@ private slots:
void color();
void selection();
+ void positionAt();
+
void maxLength();
void masks();
void validators();
@@ -361,6 +363,47 @@ void tst_qdeclarativetextinput::selection()
delete textinputObject;
}
+void tst_qdeclarativetextinput::positionAt()
+{
+ QDeclarativeView *canvas = createView(SRCDIR "/data/positionAt.qml");
+ QVERIFY(canvas->rootObject() != 0);
+ canvas->show();
+ canvas->setFocus();
+ QApplication::setActiveWindow(canvas);
+ QTest::qWaitForWindowShown(canvas);
+
+ QDeclarativeTextInput *textinputObject = qobject_cast<QDeclarativeTextInput *>(canvas->rootObject());
+ QVERIFY(textinputObject != 0);
+
+ // Check autoscrolled...
+ QFontMetrics fm(textinputObject->font());
+
+ int pos = textinputObject->positionAt(textinputObject->width()/2);
+ int diff = abs(fm.width(textinputObject->text()) - (fm.width(textinputObject->text().left(pos))+textinputObject->width()/2));
+
+ // some tollerance for different fonts.
+#ifdef Q_OS_LINUX
+ QVERIFY(diff < 2);
+#else
+ QVERIFY(diff < 5);
+#endif
+
+ // Check without autoscroll...
+ QEXPECT_FAIL("", "QTBUG-11127", Abort);
+ textinputObject->setAutoScroll(false);
+ pos = textinputObject->positionAt(textinputObject->width()/2);
+ diff = abs(fm.width(textinputObject->text().left(pos))-textinputObject->width()/2);
+
+ // some tollerance for different fonts.
+#ifdef Q_OS_LINUX
+ QVERIFY(diff < 2);
+#else
+ QVERIFY(diff < 5);
+#endif
+
+ delete canvas;
+}
+
void tst_qdeclarativetextinput::maxLength()
{
//QString componentStr = "import Qt 4.7\nTextInput { maximumLength: 10; }";