diff options
author | Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com> | 2010-06-01 12:05:08 (GMT) |
---|---|---|
committer | Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com> | 2010-06-01 12:05:08 (GMT) |
commit | 08952f6c261d6bac27810b3f11420f0f2c513f22 (patch) | |
tree | 433b68ad931741eb9df3f2cadabbdf25f66b2f9c /tests | |
parent | ff57057bc6844eb3c10ab0eadff292a10ef493f8 (diff) | |
parent | 0b034e816994f3c6ad5ba5e0e9f7c0c60ab9440d (diff) | |
download | Qt-08952f6c261d6bac27810b3f11420f0f2c513f22.zip Qt-08952f6c261d6bac27810b3f11420f0f2c513f22.tar.gz Qt-08952f6c261d6bac27810b3f11420f0f2c513f22.tar.bz2 |
Merge branch '4.7' of git@scm.dev.nokia.troll.no:qt/oslo-staging-2 into 4.7
Diffstat (limited to 'tests')
6 files changed, 130 insertions, 69 deletions
diff --git a/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp b/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp index 203760e..2aef9bb 100644 --- a/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp +++ b/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp @@ -91,6 +91,7 @@ private slots: void modelChanges(); void QTBUG_9791(); void manualHighlight(); + void QTBUG_11105(); private: template <class T> void items(); @@ -1493,6 +1494,53 @@ void tst_QDeclarativeListView::manualHighlight() QTRY_COMPARE(listview->highlightItem()->y(), listview->currentItem()->y()); } +void tst_QDeclarativeListView::QTBUG_11105() +{ + QDeclarativeView *canvas = createView(); + + TestModel model; + for (int i = 0; i < 30; i++) + model.addItem("Item" + QString::number(i), ""); + + QDeclarativeContext *ctxt = canvas->rootContext(); + ctxt->setContextProperty("testModel", &model); + + TestObject *testObject = new TestObject; + ctxt->setContextProperty("testObject", testObject); + + canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/listviewtest.qml")); + qApp->processEvents(); + + QDeclarativeListView *listview = findItem<QDeclarativeListView>(canvas->rootObject(), "list"); + QTRY_VERIFY(listview != 0); + + QDeclarativeItem *viewport = listview->viewport(); + QTRY_VERIFY(viewport != 0); + + // Confirm items positioned correctly + int itemCount = findItems<QDeclarativeItem>(viewport, "wrapper").count(); + for (int i = 0; i < model.count() && i < itemCount; ++i) { + QDeclarativeItem *item = findItem<QDeclarativeItem>(viewport, "wrapper", i); + if (!item) qWarning() << "Item" << i << "not found"; + QTRY_VERIFY(item); + QTRY_VERIFY(item->y() == i*20); + } + + listview->positionViewAtIndex(20, QDeclarativeListView::Beginning); + QCOMPARE(listview->contentY(), 280.); + + TestModel model2; + for (int i = 0; i < 5; i++) + model2.addItem("Item" + QString::number(i), ""); + + ctxt->setContextProperty("testModel", &model2); + + itemCount = findItems<QDeclarativeItem>(viewport, "wrapper").count(); + QCOMPARE(itemCount, 5); + + delete canvas; +} + void tst_QDeclarativeListView::qListModelInterface_items() { items<TestModel>(); diff --git a/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp b/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp index d3e3c3a..47c5b63 100644 --- a/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp +++ b/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp @@ -551,11 +551,11 @@ void tst_qdeclarativetextedit::selection() //Test selection for(int i=0; i<= testStr.size(); i++) { - textEditObject->setSelectionEnd(i); + textEditObject->select(0,i); QCOMPARE(testStr.mid(0,i), textEditObject->selectedText()); } for(int i=0; i<= testStr.size(); i++) { - textEditObject->setSelectionStart(i); + textEditObject->select(i,testStr.size()); QCOMPARE(testStr.mid(i,testStr.size()-i), textEditObject->selectedText()); } @@ -565,43 +565,26 @@ void tst_qdeclarativetextedit::selection() QVERIFY(textEditObject->selectionEnd() == 0); QVERIFY(textEditObject->selectedText().isNull()); - for(int i=0; i< testStr.size(); i++) { - textEditObject->setSelectionStart(i); - QCOMPARE(textEditObject->selectionEnd(), i); - QCOMPARE(testStr.mid(i,0), textEditObject->selectedText()); - textEditObject->setSelectionEnd(i+1); - QCOMPARE(textEditObject->selectionStart(), i); - QCOMPARE(testStr.mid(i,1), textEditObject->selectedText()); - } - - for(int i= testStr.size() - 1; i>0; i--) { - textEditObject->setSelectionEnd(i); - QCOMPARE(testStr.mid(i,0), textEditObject->selectedText()); - textEditObject->setSelectionStart(i-1); - QCOMPARE(testStr.mid(i-1,1), textEditObject->selectedText()); - } - //Test Error Ignoring behaviour textEditObject->setCursorPosition(0); QVERIFY(textEditObject->selectedText().isNull()); - textEditObject->setSelectionStart(-10); + textEditObject->select(-10,0); QVERIFY(textEditObject->selectedText().isNull()); - textEditObject->setSelectionStart(100); + textEditObject->select(100,101); QVERIFY(textEditObject->selectedText().isNull()); - textEditObject->setSelectionEnd(-10); + textEditObject->select(0,-10); QVERIFY(textEditObject->selectedText().isNull()); - textEditObject->setSelectionEnd(100); + textEditObject->select(0,100); QVERIFY(textEditObject->selectedText().isNull()); - textEditObject->setSelectionStart(0); - textEditObject->setSelectionEnd(10); + textEditObject->select(0,10); QVERIFY(textEditObject->selectedText().size() == 10); - textEditObject->setSelectionStart(-10); + textEditObject->select(-10,0); QVERIFY(textEditObject->selectedText().size() == 10); - textEditObject->setSelectionStart(100); + textEditObject->select(100,101); QVERIFY(textEditObject->selectedText().size() == 10); - textEditObject->setSelectionEnd(-10); + textEditObject->select(0,-10); QVERIFY(textEditObject->selectedText().size() == 10); - textEditObject->setSelectionEnd(100); + textEditObject->select(0,100); QVERIFY(textEditObject->selectedText().size() == 10); } diff --git a/tests/auto/declarative/qdeclarativetextinput/data/positionAt.qml b/tests/auto/declarative/qdeclarativetextinput/data/positionAt.qml new file mode 100644 index 0000000..2800351 --- /dev/null +++ b/tests/auto/declarative/qdeclarativetextinput/data/positionAt.qml @@ -0,0 +1,8 @@ +import Qt 4.7 + +TextInput{ + focus: true + objectName: "myInput" + width: 50 + text: "This is a long piece of text" +} diff --git a/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp b/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp index c01cfa5..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(); @@ -322,11 +324,11 @@ void tst_qdeclarativetextinput::selection() //Test selection for(int i=0; i<= testStr.size(); i++) { - textinputObject->setSelectionEnd(i); + textinputObject->select(0,i); QCOMPARE(testStr.mid(0,i), textinputObject->selectedText()); } for(int i=0; i<= testStr.size(); i++) { - textinputObject->setSelectionStart(i); + textinputObject->select(i,testStr.size()); QCOMPARE(testStr.mid(i,testStr.size()-i), textinputObject->selectedText()); } @@ -336,48 +338,72 @@ void tst_qdeclarativetextinput::selection() QVERIFY(textinputObject->selectionEnd() == 0); QVERIFY(textinputObject->selectedText().isNull()); - for(int i=0; i< testStr.size(); i++) { - textinputObject->setSelectionStart(i); - QCOMPARE(textinputObject->selectionEnd(), i); - QCOMPARE(testStr.mid(i,0), textinputObject->selectedText()); - textinputObject->setSelectionEnd(i+1); - QCOMPARE(textinputObject->selectionStart(), i); - QCOMPARE(testStr.mid(i,1), textinputObject->selectedText()); - } - - for(int i= testStr.size() - 1; i>0; i--) { - textinputObject->setSelectionEnd(i); - QCOMPARE(testStr.mid(i,0), textinputObject->selectedText()); - textinputObject->setSelectionStart(i-1); - QCOMPARE(testStr.mid(i-1,1), textinputObject->selectedText()); - } - //Test Error Ignoring behaviour textinputObject->setCursorPosition(0); QVERIFY(textinputObject->selectedText().isNull()); - textinputObject->setSelectionStart(-10); + textinputObject->select(-10,0); QVERIFY(textinputObject->selectedText().isNull()); - textinputObject->setSelectionStart(100); + textinputObject->select(100,110); QVERIFY(textinputObject->selectedText().isNull()); - textinputObject->setSelectionEnd(-10); + textinputObject->select(0,-10); QVERIFY(textinputObject->selectedText().isNull()); - textinputObject->setSelectionEnd(100); + textinputObject->select(0,100); QVERIFY(textinputObject->selectedText().isNull()); - textinputObject->setSelectionStart(0); - textinputObject->setSelectionEnd(10); + textinputObject->select(0,10); QVERIFY(textinputObject->selectedText().size() == 10); - textinputObject->setSelectionStart(-10); + textinputObject->select(-10,10); QVERIFY(textinputObject->selectedText().size() == 10); - textinputObject->setSelectionStart(100); + textinputObject->select(100,101); QVERIFY(textinputObject->selectedText().size() == 10); - textinputObject->setSelectionEnd(-10); + textinputObject->select(0,-10); QVERIFY(textinputObject->selectedText().size() == 10); - textinputObject->setSelectionEnd(100); + textinputObject->select(0,100); QVERIFY(textinputObject->selectedText().size() == 10); 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; }"; @@ -565,8 +591,7 @@ void tst_qdeclarativetextinput::navigation() QVERIFY(input->hasFocus() == true); //QT-2944: If text is selected, ensure we deselect upon cursor motion input->setCursorPosition(input->text().length()); - input->setSelectionStart(0); - input->setSelectionEnd(input->text().length()); + input->select(0,input->text().length()); QVERIFY(input->selectionStart() != input->selectionEnd()); simulateKey(canvas, Qt::Key_Right); QVERIFY(input->selectionStart() == input->selectionEnd()); @@ -603,13 +628,13 @@ void tst_qdeclarativetextinput::cursorDelegate() //Test Delegate gets moved for(int i=0; i<= textInputObject->text().length(); i++){ textInputObject->setCursorPosition(i); - //+5 is because the TextInput cursorRect is just a 10xHeight area centered on cursor position - QCOMPARE(textInputObject->cursorRect().x() + 5, qRound(delegateObject->x())); - QCOMPARE(textInputObject->cursorRect().y(), qRound(delegateObject->y())); + //+5 is because the TextInput cursorRectangle is just a 10xHeight area centered on cursor position + QCOMPARE(textInputObject->cursorRectangle().x() + 5, qRound(delegateObject->x())); + QCOMPARE(textInputObject->cursorRectangle().y(), qRound(delegateObject->y())); } textInputObject->setCursorPosition(0); - QCOMPARE(textInputObject->cursorRect().x()+5, qRound(delegateObject->x())); - QCOMPARE(textInputObject->cursorRect().y(), qRound(delegateObject->y())); + QCOMPARE(textInputObject->cursorRectangle().x()+5, qRound(delegateObject->x())); + QCOMPARE(textInputObject->cursorRectangle().y(), qRound(delegateObject->y())); //Test Delegate gets deleted textInputObject->setCursorDelegate(0); QVERIFY(!textInputObject->findChild<QDeclarativeItem*>("cursorInstance")); @@ -881,8 +906,7 @@ void tst_qdeclarativetextinput::focusOutClearSelection() view.show(); QApplication::setActiveWindow(&view); QTest::qWaitForWindowShown(&view); - input.setSelectionStart(2); - input.setSelectionEnd(5); + input.select(2,5); //The selection should work QTRY_COMPARE(input.selectedText(), QLatin1String("llo")); input2.setFocus(true); diff --git a/tests/auto/declarative/qmlvisual/qdeclarativetextedit/MultilineEdit.qml b/tests/auto/declarative/qmlvisual/qdeclarativetextedit/MultilineEdit.qml index 0273282..53538cb 100644 --- a/tests/auto/declarative/qmlvisual/qdeclarativetextedit/MultilineEdit.qml +++ b/tests/auto/declarative/qmlvisual/qdeclarativetextedit/MultilineEdit.qml @@ -65,8 +65,7 @@ Item { onReleased: { } onDoubleClicked: { - textEdit.selectionStart=0; - textEdit.selectionEnd=textEdit.text.length; + textEdit.selectAll() } z: textEdit.z + 1 } diff --git a/tests/auto/declarative/qmlvisual/qdeclarativetextinput/LineEdit.qml b/tests/auto/declarative/qmlvisual/qdeclarativetextinput/LineEdit.qml index cc0ad3c..69f57c6 100644 --- a/tests/auto/declarative/qmlvisual/qdeclarativetextinput/LineEdit.qml +++ b/tests/auto/declarative/qmlvisual/qdeclarativetextinput/LineEdit.qml @@ -58,8 +58,7 @@ Item { onReleased: { } onDoubleClicked: { - textInp.selectionStart=0; - textInp.selectionEnd=textInp.text.length; + textInp.selectAll() } z: textInp.z + 1 } |