From 5f6b50f99a6457c208c7f186db45a2dba690bace Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Tue, 1 Jun 2010 12:39:15 +1000 Subject: Test positionAt. Task-number: QTBUG-11127 Task-number: QTBUG-11054 --- .../tst_qdeclarativetextinput.cpp | 43 ++++++++++++++++++++++ 1 file changed, 43 insertions(+) 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(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; }"; -- cgit v0.12