diff options
author | Yann Bodson <yann.bodson@nokia.com> | 2010-04-13 05:17:16 (GMT) |
---|---|---|
committer | Yann Bodson <yann.bodson@nokia.com> | 2010-04-13 05:17:16 (GMT) |
commit | 36e8506084f272a01cfdc50ab787e9d30da60360 (patch) | |
tree | 1fad119461ba379b14d52c04d0cbba13dd38fab9 /tests/auto | |
parent | ff0020481398e7c109973949260a42711c4cdcdc (diff) | |
download | Qt-36e8506084f272a01cfdc50ab787e9d30da60360.zip Qt-36e8506084f272a01cfdc50ab787e9d30da60360.tar.gz Qt-36e8506084f272a01cfdc50ab787e9d30da60360.tar.bz2 |
Optimize some autotests
Diffstat (limited to 'tests/auto')
3 files changed, 613 insertions, 715 deletions
diff --git a/tests/auto/declarative/qdeclarativebehaviors/tst_qdeclarativebehaviors.cpp b/tests/auto/declarative/qdeclarativebehaviors/tst_qdeclarativebehaviors.cpp index 4c9c9ca..b155c29 100644 --- a/tests/auto/declarative/qdeclarativebehaviors/tst_qdeclarativebehaviors.cpp +++ b/tests/auto/declarative/qdeclarativebehaviors/tst_qdeclarativebehaviors.cpp @@ -45,6 +45,7 @@ #include <private/qdeclarativerectangle_p.h> #include <private/qdeclarativebehavior_p.h> #include <private/qdeclarativeanimation_p.h> +#include "../../../shared/util.h" class tst_qdeclarativebehaviors : public QObject { @@ -76,13 +77,13 @@ void tst_qdeclarativebehaviors::simpleBehavior() QDeclarativeEngine engine; QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/simple.qml")); QDeclarativeRectangle *rect = qobject_cast<QDeclarativeRectangle*>(c.create()); - QVERIFY(rect); - QVERIFY(qobject_cast<QDeclarativeBehavior*>(rect->findChild<QDeclarativeBehavior*>("MyBehavior"))->animation()); + QTRY_VERIFY(rect); + QTRY_VERIFY(qobject_cast<QDeclarativeBehavior*>(rect->findChild<QDeclarativeBehavior*>("MyBehavior"))->animation()); rect->setState("moved"); - QTest::qWait(200); - qreal x = qobject_cast<QDeclarativeRectangle*>(rect->findChild<QDeclarativeRectangle*>("MyRect"))->x(); - QVERIFY(x > 0 && x < 200); //i.e. the behavior has been triggered + QTRY_VERIFY(qobject_cast<QDeclarativeRectangle*>(rect->findChild<QDeclarativeRectangle*>("MyRect"))->x() > 0); + QTRY_VERIFY(qobject_cast<QDeclarativeRectangle*>(rect->findChild<QDeclarativeRectangle*>("MyRect"))->x() < 200); + //i.e. the behavior has been triggered delete rect; } @@ -92,12 +93,12 @@ void tst_qdeclarativebehaviors::scriptTriggered() QDeclarativeEngine engine; QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/scripttrigger.qml")); QDeclarativeRectangle *rect = qobject_cast<QDeclarativeRectangle*>(c.create()); - QVERIFY(rect); + QTRY_VERIFY(rect); rect->setColor(QColor("red")); - QTest::qWait(200); - qreal x = qobject_cast<QDeclarativeRectangle*>(rect->findChild<QDeclarativeRectangle*>("MyRect"))->x(); - QVERIFY(x > 0 && x < 200); //i.e. the behavior has been triggered + QTRY_VERIFY(qobject_cast<QDeclarativeRectangle*>(rect->findChild<QDeclarativeRectangle*>("MyRect"))->x() > 0); + QTRY_VERIFY(qobject_cast<QDeclarativeRectangle*>(rect->findChild<QDeclarativeRectangle*>("MyRect"))->x() < 200); + //i.e. the behavior has been triggered delete rect; } @@ -107,15 +108,14 @@ void tst_qdeclarativebehaviors::cppTriggered() QDeclarativeEngine engine; QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/cpptrigger.qml")); QDeclarativeRectangle *rect = qobject_cast<QDeclarativeRectangle*>(c.create()); - QVERIFY(rect); + QTRY_VERIFY(rect); QDeclarativeRectangle *innerRect = qobject_cast<QDeclarativeRectangle*>(rect->findChild<QDeclarativeRectangle*>("MyRect")); - QVERIFY(innerRect); + QTRY_VERIFY(innerRect); innerRect->setProperty("x", 200); - QTest::qWait(200); - qreal x = innerRect->x(); - QVERIFY(x > 0 && x < 200); //i.e. the behavior has been triggered + QTRY_VERIFY(innerRect->x() > 0); + QTRY_VERIFY(innerRect->x() < 200); //i.e. the behavior has been triggered delete rect; } @@ -125,7 +125,7 @@ void tst_qdeclarativebehaviors::loop() QDeclarativeEngine engine; QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/loop.qml")); QDeclarativeRectangle *rect = qobject_cast<QDeclarativeRectangle*>(c.create()); - QVERIFY(rect); + QTRY_VERIFY(rect); //don't crash rect->setState("moved"); @@ -138,12 +138,12 @@ void tst_qdeclarativebehaviors::colorBehavior() QDeclarativeEngine engine; QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/color.qml")); QDeclarativeRectangle *rect = qobject_cast<QDeclarativeRectangle*>(c.create()); - QVERIFY(rect); + QTRY_VERIFY(rect); rect->setState("red"); - QTest::qWait(200); - QColor color = qobject_cast<QDeclarativeRectangle*>(rect->findChild<QDeclarativeRectangle*>("MyRect"))->color(); - QVERIFY(color != QColor("red") && color != QColor("green")); //i.e. the behavior has been triggered + QTRY_VERIFY(qobject_cast<QDeclarativeRectangle*>(rect->findChild<QDeclarativeRectangle*>("MyRect"))->color() != QColor("red")); + QTRY_VERIFY(qobject_cast<QDeclarativeRectangle*>(rect->findChild<QDeclarativeRectangle*>("MyRect"))->color() != QColor("green")); + //i.e. the behavior has been triggered delete rect; } @@ -153,16 +153,11 @@ void tst_qdeclarativebehaviors::parentBehavior() QDeclarativeEngine engine; QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/parent.qml")); QDeclarativeRectangle *rect = qobject_cast<QDeclarativeRectangle*>(c.create()); - QVERIFY(rect); + QTRY_VERIFY(rect); rect->setState("reparented"); - QTest::qWait(200); - QDeclarativeItem *newParent = rect->findChild<QDeclarativeItem*>("NewParent"); - QDeclarativeItem *parent = rect->findChild<QDeclarativeRectangle*>("MyRect")->parentItem(); - QVERIFY(parent != newParent); - QTest::qWait(600); - parent = rect->findChild<QDeclarativeRectangle*>("MyRect")->parentItem(); - QVERIFY(parent == newParent); + QTRY_VERIFY(rect->findChild<QDeclarativeRectangle*>("MyRect")->parentItem() != rect->findChild<QDeclarativeItem*>("NewParent")); + QTRY_VERIFY(rect->findChild<QDeclarativeRectangle*>("MyRect")->parentItem() == rect->findChild<QDeclarativeItem*>("NewParent")); delete rect; } @@ -172,33 +167,33 @@ void tst_qdeclarativebehaviors::replaceBinding() QDeclarativeEngine engine; QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/binding.qml")); QDeclarativeRectangle *rect = qobject_cast<QDeclarativeRectangle*>(c.create()); - QVERIFY(rect); + QTRY_VERIFY(rect); rect->setState("moved"); - QTest::qWait(200); + //QTest::qWait(200); QDeclarativeRectangle *innerRect = qobject_cast<QDeclarativeRectangle*>(rect->findChild<QDeclarativeRectangle*>("MyRect")); - QVERIFY(innerRect); - qreal x = innerRect->x(); - QVERIFY(x > 0 && x < 200); //i.e. the behavior has been triggered - QTest::qWait(600); - QCOMPARE(innerRect->x(), (qreal)200); + QTRY_VERIFY(innerRect); + QTRY_VERIFY(innerRect->x() > 0); + QTRY_VERIFY(innerRect->x() < 200); + //i.e. the behavior has been triggered + //QTest::qWait(600); + QTRY_COMPARE(innerRect->x(), (qreal)200); rect->setProperty("basex", 10); - QCOMPARE(innerRect->x(), (qreal)200); + QTRY_COMPARE(innerRect->x(), (qreal)200); rect->setProperty("movedx", 210); - QTest::qWait(600); - QCOMPARE(innerRect->x(), (qreal)210); + //QTest::qWait(600); + QTRY_COMPARE(innerRect->x(), (qreal)210); rect->setState(""); - QTest::qWait(200); - x = innerRect->x(); - QVERIFY(x > 10 && x < 210); //i.e. the behavior has been triggered - QTest::qWait(600); - QCOMPARE(innerRect->x(), (qreal)10); + QTRY_VERIFY(innerRect->x() > 10); + QTRY_VERIFY(innerRect->x() < 210); //i.e. the behavior has been triggered + //QTest::qWait(600); + QTRY_COMPARE(innerRect->x(), (qreal)10); rect->setProperty("movedx", 200); - QCOMPARE(innerRect->x(), (qreal)10); + QTRY_COMPARE(innerRect->x(), (qreal)10); rect->setProperty("basex", 20); - QTest::qWait(600); - QCOMPARE(innerRect->x(), (qreal)20); + //QTest::qWait(600); + QTRY_COMPARE(innerRect->x(), (qreal)20); delete rect; } @@ -209,12 +204,13 @@ void tst_qdeclarativebehaviors::group() QDeclarativeEngine engine; QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/groupProperty.qml")); QDeclarativeRectangle *rect = qobject_cast<QDeclarativeRectangle*>(c.create()); - QVERIFY(rect); + QTRY_VERIFY(rect); rect->setState("moved"); - QTest::qWait(200); - qreal x = qobject_cast<QDeclarativeRectangle*>(rect->findChild<QDeclarativeRectangle*>("MyRect"))->x(); - QVERIFY(x > 0 && x < 200); //i.e. the behavior has been triggered + //QTest::qWait(200); + QTRY_VERIFY(qobject_cast<QDeclarativeRectangle*>(rect->findChild<QDeclarativeRectangle*>("MyRect"))->x() > 0); + QTRY_VERIFY(qobject_cast<QDeclarativeRectangle*>(rect->findChild<QDeclarativeRectangle*>("MyRect"))->x() < 200); + //i.e. the behavior has been triggered delete rect; } @@ -223,12 +219,12 @@ void tst_qdeclarativebehaviors::group() QDeclarativeEngine engine; QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/groupProperty2.qml")); QDeclarativeRectangle *rect = qobject_cast<QDeclarativeRectangle*>(c.create()); - QVERIFY(rect); + QTRY_VERIFY(rect); rect->setState("moved"); - QTest::qWait(200); - qreal x = qobject_cast<QDeclarativeRectangle*>(rect->findChild<QDeclarativeRectangle*>("MyRect"))->x(); - QVERIFY(x > 0 && x < 200); //i.e. the behavior has been triggered + QTRY_VERIFY(qobject_cast<QDeclarativeRectangle*>(rect->findChild<QDeclarativeRectangle*>("MyRect"))->x() > 0); + QTRY_VERIFY(qobject_cast<QDeclarativeRectangle*>(rect->findChild<QDeclarativeRectangle*>("MyRect"))->x() < 200); + //i.e. the behavior has been triggered delete rect; } @@ -239,46 +235,42 @@ void tst_qdeclarativebehaviors::emptyBehavior() QDeclarativeEngine engine; QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/empty.qml")); QDeclarativeRectangle *rect = qobject_cast<QDeclarativeRectangle*>(c.create()); - QVERIFY(rect); + QTRY_VERIFY(rect); rect->setState("moved"); qreal x = qobject_cast<QDeclarativeRectangle*>(rect->findChild<QDeclarativeRectangle*>("MyRect"))->x(); - QCOMPARE(x, qreal(200)); //should change immediately + QTRY_COMPARE(x, qreal(200)); //should change immediately delete rect; } void tst_qdeclarativebehaviors::explicitSelection() { - { - QDeclarativeEngine engine; - QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/explicit.qml")); - QDeclarativeRectangle *rect = qobject_cast<QDeclarativeRectangle*>(c.create()); - QVERIFY(rect); + QDeclarativeEngine engine; + QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/explicit.qml")); + QDeclarativeRectangle *rect = qobject_cast<QDeclarativeRectangle*>(c.create()); + QTRY_VERIFY(rect); - rect->setState("moved"); - QTest::qWait(200); - qreal x = qobject_cast<QDeclarativeRectangle*>(rect->findChild<QDeclarativeRectangle*>("MyRect"))->x(); - QVERIFY(x > 0 && x < 200); //i.e. the behavior has been triggered + rect->setState("moved"); + QTRY_VERIFY(qobject_cast<QDeclarativeRectangle*>(rect->findChild<QDeclarativeRectangle*>("MyRect"))->x() > 0); + QTRY_VERIFY(qobject_cast<QDeclarativeRectangle*>(rect->findChild<QDeclarativeRectangle*>("MyRect"))->x() < 200); + //i.e. the behavior has been triggered - delete rect; - } + delete rect; } void tst_qdeclarativebehaviors::nonSelectingBehavior() { - { - QDeclarativeEngine engine; - QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/nonSelecting2.qml")); - QDeclarativeRectangle *rect = qobject_cast<QDeclarativeRectangle*>(c.create()); - QVERIFY(rect); + QDeclarativeEngine engine; + QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/nonSelecting2.qml")); + QDeclarativeRectangle *rect = qobject_cast<QDeclarativeRectangle*>(c.create()); + QTRY_VERIFY(rect); - rect->setState("moved"); - qreal x = qobject_cast<QDeclarativeRectangle*>(rect->findChild<QDeclarativeRectangle*>("MyRect"))->x(); - QCOMPARE(x, qreal(200)); //should change immediately + rect->setState("moved"); + qreal x = qobject_cast<QDeclarativeRectangle*>(rect->findChild<QDeclarativeRectangle*>("MyRect"))->x(); + QTRY_COMPARE(x, qreal(200)); //should change immediately - delete rect; - } + delete rect; } void tst_qdeclarativebehaviors::reassignedAnimation() @@ -287,8 +279,8 @@ void tst_qdeclarativebehaviors::reassignedAnimation() QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/reassignedAnimation.qml")); QTest::ignoreMessage(QtWarningMsg, QString("QML Behavior (" + QUrl::fromLocalFile(SRCDIR "/data/reassignedAnimation.qml").toString() + ":9:9) Cannot change the animation assigned to a Behavior.").toUtf8().constData()); QDeclarativeRectangle *rect = qobject_cast<QDeclarativeRectangle*>(c.create()); - QVERIFY(rect); - QCOMPARE(qobject_cast<QDeclarativeNumberAnimation*>( + QTRY_VERIFY(rect); + QTRY_COMPARE(qobject_cast<QDeclarativeNumberAnimation*>( qobject_cast<QDeclarativeBehavior*>( rect->findChild<QDeclarativeBehavior*>("MyBehavior"))->animation())->duration(), 200); @@ -300,12 +292,12 @@ void tst_qdeclarativebehaviors::disabled() QDeclarativeEngine engine; QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/disabled.qml")); QDeclarativeRectangle *rect = qobject_cast<QDeclarativeRectangle*>(c.create()); - QVERIFY(rect); - QCOMPARE(rect->findChild<QDeclarativeBehavior*>("MyBehavior")->enabled(), false); + QTRY_VERIFY(rect); + QTRY_COMPARE(rect->findChild<QDeclarativeBehavior*>("MyBehavior")->enabled(), false); rect->setState("moved"); qreal x = qobject_cast<QDeclarativeRectangle*>(rect->findChild<QDeclarativeRectangle*>("MyRect"))->x(); - QCOMPARE(x, qreal(200)); //should change immediately + QTRY_COMPARE(x, qreal(200)); //should change immediately delete rect; } @@ -318,11 +310,11 @@ void tst_qdeclarativebehaviors::dontStart() QTest::ignoreMessage(QtWarningMsg, "QDeclarativeAbstractAnimation: setRunning() cannot be used on non-root animation nodes"); QDeclarativeRectangle *rect = qobject_cast<QDeclarativeRectangle*>(c.create()); - QVERIFY(rect); + QTRY_VERIFY(rect); QDeclarativeAbstractAnimation *myAnim = rect->findChild<QDeclarativeAbstractAnimation*>("MyAnim"); - QVERIFY(myAnim && myAnim->qtAnimation()); - QVERIFY(myAnim->qtAnimation()->state() == QAbstractAnimation::Stopped); + QTRY_VERIFY(myAnim && myAnim->qtAnimation()); + QTRY_VERIFY(myAnim->qtAnimation()->state() == QAbstractAnimation::Stopped); delete rect; } @@ -332,12 +324,12 @@ void tst_qdeclarativebehaviors::startup() QDeclarativeEngine engine; QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/startup.qml")); QDeclarativeRectangle *rect = qobject_cast<QDeclarativeRectangle*>(c.create()); - QVERIFY(rect); + QTRY_VERIFY(rect); QDeclarativeRectangle *innerRect = rect->findChild<QDeclarativeRectangle*>("innerRect"); - QVERIFY(innerRect); + QTRY_VERIFY(innerRect); - QCOMPARE(innerRect->x(), qreal(100)); //should be set immediately + QTRY_COMPARE(innerRect->x(), qreal(100)); //should be set immediately delete rect; } diff --git a/tests/auto/declarative/qdeclarativegridview/tst_qdeclarativegridview.cpp b/tests/auto/declarative/qdeclarativegridview/tst_qdeclarativegridview.cpp index 7add9c6..07fc3aa 100644 --- a/tests/auto/declarative/qdeclarativegridview/tst_qdeclarativegridview.cpp +++ b/tests/auto/declarative/qdeclarativegridview/tst_qdeclarativegridview.cpp @@ -50,6 +50,7 @@ #include <QtDeclarative/private/qdeclarativegridview_p.h> #include <QtDeclarative/private/qdeclarativetext_p.h> #include <QtDeclarative/private/qdeclarativelistmodel_p.h> +#include "../../../shared/util.h" class tst_QDeclarativeGridView : public QObject { @@ -169,21 +170,21 @@ void tst_QDeclarativeGridView::items() qApp->processEvents(); QDeclarativeGridView *gridview = findItem<QDeclarativeGridView>(canvas->rootObject(), "grid"); - QVERIFY(gridview != 0); + QTRY_VERIFY(gridview != 0); QDeclarativeItem *viewport = gridview->viewport(); - QVERIFY(viewport != 0); + QTRY_VERIFY(viewport != 0); - QCOMPARE(gridview->count(), model.count()); - QCOMPARE(viewport->childItems().count(), model.count()+1); // assumes all are visible, +1 for the (default) highlight item + QTRY_COMPARE(gridview->count(), model.count()); + QTRY_COMPARE(viewport->childItems().count(), model.count()+1); // assumes all are visible, +1 for the (default) highlight item for (int i = 0; i < model.count(); ++i) { QDeclarativeText *name = findItem<QDeclarativeText>(viewport, "textName", i); - QVERIFY(name != 0); - QCOMPARE(name->text(), model.name(i)); + QTRY_VERIFY(name != 0); + QTRY_COMPARE(name->text(), model.name(i)); QDeclarativeText *number = findItem<QDeclarativeText>(viewport, "textNumber", i); - QVERIFY(number != 0); - QCOMPARE(number->text(), model.number(i)); + QTRY_VERIFY(number != 0); + QTRY_COMPARE(number->text(), model.number(i)); } // set an empty model and confirm that items are destroyed @@ -191,7 +192,7 @@ void tst_QDeclarativeGridView::items() ctxt->setContextProperty("testModel", &model2); int itemCount = findItems<QDeclarativeItem>(viewport, "wrapper").count(); - QVERIFY(itemCount == 0); + QTRY_VERIFY(itemCount == 0); delete canvas; } @@ -217,18 +218,18 @@ void tst_QDeclarativeGridView::changed() qApp->processEvents(); QDeclarativeFlickable *gridview = findItem<QDeclarativeFlickable>(canvas->rootObject(), "grid"); - QVERIFY(gridview != 0); + QTRY_VERIFY(gridview != 0); QDeclarativeItem *viewport = gridview->viewport(); - QVERIFY(viewport != 0); + QTRY_VERIFY(viewport != 0); model.modifyItem(1, "Will", "9876"); QDeclarativeText *name = findItem<QDeclarativeText>(viewport, "textName", 1); - QVERIFY(name != 0); - QCOMPARE(name->text(), model.name(1)); + QTRY_VERIFY(name != 0); + QTRY_COMPARE(name->text(), model.name(1)); QDeclarativeText *number = findItem<QDeclarativeText>(viewport, "textNumber", 1); - QVERIFY(number != 0); - QCOMPARE(number->text(), model.number(1)); + QTRY_VERIFY(number != 0); + QTRY_COMPARE(number->text(), model.number(1)); delete canvas; } @@ -250,71 +251,62 @@ void tst_QDeclarativeGridView::inserted() qApp->processEvents(); QDeclarativeGridView *gridview = findItem<QDeclarativeGridView>(canvas->rootObject(), "grid"); - QVERIFY(gridview != 0); + QTRY_VERIFY(gridview != 0); QDeclarativeItem *viewport = gridview->viewport(); - QVERIFY(viewport != 0); + QTRY_VERIFY(viewport != 0); model.insertItem(1, "Will", "9876"); - // let transitions settle. - QTest::qWait(100); - - QCOMPARE(viewport->childItems().count(), model.count()+1); // assumes all are visible, +1 for the (default) highlight item + QTRY_COMPARE(viewport->childItems().count(), model.count()+1); // assumes all are visible, +1 for the (default) highlight item QDeclarativeText *name = findItem<QDeclarativeText>(viewport, "textName", 1); - QVERIFY(name != 0); - QCOMPARE(name->text(), model.name(1)); + QTRY_VERIFY(name != 0); + QTRY_COMPARE(name->text(), model.name(1)); QDeclarativeText *number = findItem<QDeclarativeText>(viewport, "textNumber", 1); - QVERIFY(number != 0); - QCOMPARE(number->text(), model.number(1)); + QTRY_VERIFY(number != 0); + QTRY_COMPARE(number->text(), model.number(1)); // Checks that onAdd is called int added = canvas->rootObject()->property("added").toInt(); - QCOMPARE(added, 1); + QTRY_COMPARE(added, 1); // Confirm items positioned correctly for (int i = 0; i < model.count(); ++i) { QDeclarativeItem *item = findItem<QDeclarativeItem>(viewport, "wrapper", i); - QCOMPARE(item->x(), (i%3)*80.0); - QCOMPARE(item->y(), (i/3)*60.0); + QTRY_COMPARE(item->x(), (i%3)*80.0); + QTRY_COMPARE(item->y(), (i/3)*60.0); } model.insertItem(0, "Foo", "1111"); // zero index, and current item - // let transitions settle. - QTest::qWait(100); - - QCOMPARE(viewport->childItems().count(), model.count()+1); // assumes all are visible, +1 for the (default) highlight item + QTRY_COMPARE(viewport->childItems().count(), model.count()+1); // assumes all are visible, +1 for the (default) highlight item name = findItem<QDeclarativeText>(viewport, "textName", 0); - QVERIFY(name != 0); - QCOMPARE(name->text(), model.name(0)); + QTRY_VERIFY(name != 0); + QTRY_COMPARE(name->text(), model.name(0)); number = findItem<QDeclarativeText>(viewport, "textNumber", 0); - QVERIFY(number != 0); - QCOMPARE(number->text(), model.number(0)); + QTRY_VERIFY(number != 0); + QTRY_COMPARE(number->text(), model.number(0)); - QCOMPARE(gridview->currentIndex(), 1); + QTRY_COMPARE(gridview->currentIndex(), 1); // Confirm items positioned correctly for (int i = 0; i < model.count(); ++i) { QDeclarativeItem *item = findItem<QDeclarativeItem>(viewport, "wrapper", i); - QVERIFY(item->x() == (i%3)*80); - QVERIFY(item->y() == (i/3)*60); + QTRY_VERIFY(item->x() == (i%3)*80); + QTRY_VERIFY(item->y() == (i/3)*60); } for (int i = model.count(); i < 30; ++i) model.insertItem(i, "Hello", QString::number(i)); - QTest::qWait(100); gridview->setContentY(120); - QTest::qWait(100); // Insert item outside visible area model.insertItem(1, "Hello", "1324"); - QTest::qWait(100); - QVERIFY(gridview->contentY() == 120); + QTRY_VERIFY(gridview->contentY() == 120); delete canvas; } @@ -335,107 +327,91 @@ void tst_QDeclarativeGridView::removed() qApp->processEvents(); QDeclarativeGridView *gridview = findItem<QDeclarativeGridView>(canvas->rootObject(), "grid"); - QVERIFY(gridview != 0); + QTRY_VERIFY(gridview != 0); QDeclarativeItem *viewport = gridview->viewport(); - QVERIFY(viewport != 0); + QTRY_VERIFY(viewport != 0); model.removeItem(1); - // let transitions settle. - QTest::qWait(100); - QDeclarativeText *name = findItem<QDeclarativeText>(viewport, "textName", 1); - QVERIFY(name != 0); - QCOMPARE(name->text(), model.name(1)); + QTRY_VERIFY(name != 0); + QTRY_COMPARE(name->text(), model.name(1)); QDeclarativeText *number = findItem<QDeclarativeText>(viewport, "textNumber", 1); - QVERIFY(number != 0); - QCOMPARE(number->text(), model.number(1)); + QTRY_VERIFY(number != 0); + QTRY_COMPARE(number->text(), model.number(1)); // Checks that onRemove is called QString removed = canvas->rootObject()->property("removed").toString(); - QCOMPARE(removed, QString("Item1")); + QTRY_COMPARE(removed, QString("Item1")); // 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"; - QVERIFY(item); - QVERIFY(item->x() == (i%3)*80); - QVERIFY(item->y() == (i/3)*60); + QTRY_VERIFY(item); + QTRY_VERIFY(item->x() == (i%3)*80); + QTRY_VERIFY(item->y() == (i/3)*60); } // Remove first item (which is the current item); model.removeItem(0); - // let transitions settle. - QTest::qWait(100); - name = findItem<QDeclarativeText>(viewport, "textName", 0); - QVERIFY(name != 0); - QCOMPARE(name->text(), model.name(0)); + QTRY_VERIFY(name != 0); + QTRY_COMPARE(name->text(), model.name(0)); number = findItem<QDeclarativeText>(viewport, "textNumber", 0); - QVERIFY(number != 0); - QCOMPARE(number->text(), model.number(0)); + QTRY_VERIFY(number != 0); + QTRY_COMPARE(number->text(), model.number(0)); // Confirm items positioned correctly 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"; - QVERIFY(item); - QVERIFY(item->x() == (i%3)*80); - QVERIFY(item->y() == (i/3)*60); + QTRY_VERIFY(item); + QTRY_VERIFY(item->x() == (i%3)*80); + QTRY_VERIFY(item->y() == (i/3)*60); } // Remove items not visible model.removeItem(25); - // let transitions settle. - QTest::qWait(100); // Confirm items positioned correctly 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"; - QVERIFY(item); - QVERIFY(item->x() == (i%3)*80); - QVERIFY(item->y() == (i/3)*60); + QTRY_VERIFY(item); + QTRY_VERIFY(item->x() == (i%3)*80); + QTRY_VERIFY(item->y() == (i/3)*60); } // Remove items before visible gridview->setContentY(120); - QTest::qWait(100); gridview->setCurrentIndex(10); - // let transitions settle. - QTest::qWait(100); - // Setting currentIndex above shouldn't cause view to scroll - QCOMPARE(gridview->contentY(), 120.0); + QTRY_COMPARE(gridview->contentY(), 120.0); model.removeItem(1); - // let transitions settle. - QTest::qWait(100); - // Confirm items positioned correctly for (int i = 6; i < 18; ++i) { QDeclarativeItem *item = findItem<QDeclarativeItem>(viewport, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; - QVERIFY(item); - QVERIFY(item->x() == (i%3)*80); - QVERIFY(item->y() == (i/3)*60); + QTRY_VERIFY(item); + QTRY_VERIFY(item->x() == (i%3)*80); + QTRY_VERIFY(item->y() == (i/3)*60); } // Remove currentIndex QDeclarativeItem *oldCurrent = gridview->currentItem(); model.removeItem(9); - QTest::qWait(100); - QCOMPARE(gridview->currentIndex(), 9); - QVERIFY(gridview->currentItem() != oldCurrent); + QTRY_COMPARE(gridview->currentIndex(), 9); + QTRY_VERIFY(gridview->currentItem() != oldCurrent); gridview->setContentY(0); // let transitions settle. @@ -446,39 +422,34 @@ void tst_QDeclarativeGridView::removed() for (int i = 0; i < model.count() && i < itemCount; ++i) { QDeclarativeItem *item = findItem<QDeclarativeItem>(viewport, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; - QVERIFY(item); - QVERIFY(item->x() == (i%3)*80); - QVERIFY(item->y() == (i/3)*60); + QTRY_VERIFY(item); + QTRY_VERIFY(item->x() == (i%3)*80); + QTRY_VERIFY(item->y() == (i/3)*60); } // remove item outside current view. gridview->setCurrentIndex(32); - QTest::qWait(100); gridview->setContentY(240); model.removeItem(30); - QVERIFY(gridview->currentIndex() == 31); + QTRY_VERIFY(gridview->currentIndex() == 31); // remove current item beyond visible items. gridview->setCurrentIndex(20); - QTest::qWait(100); gridview->setContentY(0); model.removeItem(20); - QTest::qWait(100); - QCOMPARE(gridview->currentIndex(), 20); - QVERIFY(gridview->currentItem() != 0); + QTRY_COMPARE(gridview->currentIndex(), 20); + QTRY_VERIFY(gridview->currentItem() != 0); // remove item before current, but visible gridview->setCurrentIndex(8); - QTest::qWait(100); gridview->setContentY(240); oldCurrent = gridview->currentItem(); model.removeItem(6); - QTest::qWait(100); - QCOMPARE(gridview->currentIndex(), 7); - QVERIFY(gridview->currentItem() == oldCurrent); + QTRY_COMPARE(gridview->currentIndex(), 7); + QTRY_VERIFY(gridview->currentItem() == oldCurrent); delete canvas; } @@ -499,38 +470,35 @@ void tst_QDeclarativeGridView::moved() qApp->processEvents(); QDeclarativeGridView *gridview = findItem<QDeclarativeGridView>(canvas->rootObject(), "grid"); - QVERIFY(gridview != 0); + QTRY_VERIFY(gridview != 0); QDeclarativeItem *viewport = gridview->viewport(); - QVERIFY(viewport != 0); + QTRY_VERIFY(viewport != 0); model.moveItem(1, 8); - // let transitions settle. - QTest::qWait(100); - QDeclarativeText *name = findItem<QDeclarativeText>(viewport, "textName", 1); - QVERIFY(name != 0); - QCOMPARE(name->text(), model.name(1)); + QTRY_VERIFY(name != 0); + QTRY_COMPARE(name->text(), model.name(1)); QDeclarativeText *number = findItem<QDeclarativeText>(viewport, "textNumber", 1); - QVERIFY(number != 0); - QCOMPARE(number->text(), model.number(1)); + QTRY_VERIFY(number != 0); + QTRY_COMPARE(number->text(), model.number(1)); name = findItem<QDeclarativeText>(viewport, "textName", 8); - QVERIFY(name != 0); - QCOMPARE(name->text(), model.name(8)); + QTRY_VERIFY(name != 0); + QTRY_COMPARE(name->text(), model.name(8)); number = findItem<QDeclarativeText>(viewport, "textNumber", 8); - QVERIFY(number != 0); - QCOMPARE(number->text(), model.number(8)); + QTRY_VERIFY(number != 0); + QTRY_COMPARE(number->text(), model.number(8)); // 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"; - QVERIFY(item); - QVERIFY(item->x() == (i%3)*80); - QVERIFY(item->y() == (i/3)*60); + QTRY_VERIFY(item); + QTRY_VERIFY(item->x() == (i%3)*80); + QTRY_VERIFY(item->y() == (i/3)*60); } gridview->setContentY(120); @@ -538,50 +506,44 @@ void tst_QDeclarativeGridView::moved() // move outside visible area model.moveItem(1, 25); - // let transitions settle. - QTest::qWait(100); - // Confirm items positioned correctly and indexes correct itemCount = findItems<QDeclarativeItem>(viewport, "wrapper").count()-1; for (int i = 6; i < model.count()-6 && i < itemCount+6; ++i) { QDeclarativeItem *item = findItem<QDeclarativeItem>(viewport, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; - QVERIFY(item); - QCOMPARE(item->x(), qreal((i%3)*80)); - QCOMPARE(item->y(), qreal((i/3)*60)); + QTRY_VERIFY(item); + QTRY_COMPARE(item->x(), qreal((i%3)*80)); + QTRY_COMPARE(item->y(), qreal((i/3)*60)); name = findItem<QDeclarativeText>(viewport, "textName", i); - QVERIFY(name != 0); - QCOMPARE(name->text(), model.name(i)); + QTRY_VERIFY(name != 0); + QTRY_COMPARE(name->text(), model.name(i)); number = findItem<QDeclarativeText>(viewport, "textNumber", i); - QVERIFY(number != 0); - QCOMPARE(number->text(), model.number(i)); + QTRY_VERIFY(number != 0); + QTRY_COMPARE(number->text(), model.number(i)); } // move from outside visible into visible model.moveItem(28, 8); - // let transitions settle. - QTest::qWait(100); - // Confirm items positioned correctly and indexes correct for (int i = 6; i < model.count()-6 && i < itemCount+6; ++i) { QDeclarativeItem *item = findItem<QDeclarativeItem>(viewport, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; - QVERIFY(item); - QVERIFY(item->x() == (i%3)*80); - QVERIFY(item->y() == (i/3)*60); + QTRY_VERIFY(item); + QTRY_VERIFY(item->x() == (i%3)*80); + QTRY_VERIFY(item->y() == (i/3)*60); name = findItem<QDeclarativeText>(viewport, "textName", i); - QVERIFY(name != 0); - QCOMPARE(name->text(), model.name(i)); + QTRY_VERIFY(name != 0); + QTRY_COMPARE(name->text(), model.name(i)); number = findItem<QDeclarativeText>(viewport, "textNumber", i); - QVERIFY(number != 0); - QCOMPARE(number->text(), model.number(i)); + QTRY_VERIFY(number != 0); + QTRY_COMPARE(number->text(), model.number(i)); } // ensure content position is stable gridview->setContentY(0); model.moveItem(10, 0); - QVERIFY(gridview->contentY() == 0); + QTRY_VERIFY(gridview->contentY() == 0); delete canvas; } @@ -604,65 +566,59 @@ void tst_QDeclarativeGridView::currentIndex() qApp->processEvents(); QDeclarativeGridView *gridview = findItem<QDeclarativeGridView>(canvas->rootObject(), "grid"); - QVERIFY(gridview != 0); + QTRY_VERIFY(gridview != 0); QDeclarativeItem *viewport = gridview->viewport(); - QVERIFY(viewport != 0); - - QTest::qWait(300); + QTRY_VERIFY(viewport != 0); // current item should be third item - QCOMPARE(gridview->currentIndex(), 5); - QCOMPARE(gridview->currentItem(), findItem<QDeclarativeItem>(viewport, "wrapper", 5)); - QCOMPARE(gridview->currentItem()->y(), gridview->highlightItem()->y()); + QTRY_COMPARE(gridview->currentIndex(), 5); + QTRY_COMPARE(gridview->currentItem(), findItem<QDeclarativeItem>(viewport, "wrapper", 5)); + QTRY_COMPARE(gridview->currentItem()->y(), gridview->highlightItem()->y()); gridview->moveCurrentIndexRight(); - QCOMPARE(gridview->currentIndex(), 6); + QTRY_COMPARE(gridview->currentIndex(), 6); gridview->moveCurrentIndexDown(); - QCOMPARE(gridview->currentIndex(), 9); + QTRY_COMPARE(gridview->currentIndex(), 9); gridview->moveCurrentIndexUp(); - QCOMPARE(gridview->currentIndex(), 6); + QTRY_COMPARE(gridview->currentIndex(), 6); gridview->moveCurrentIndexLeft(); - QCOMPARE(gridview->currentIndex(), 5); + QTRY_COMPARE(gridview->currentIndex(), 5); // no wrap gridview->setCurrentIndex(0); - QCOMPARE(gridview->currentIndex(), 0); + QTRY_COMPARE(gridview->currentIndex(), 0); gridview->moveCurrentIndexUp(); - QCOMPARE(gridview->currentIndex(), 0); + QTRY_COMPARE(gridview->currentIndex(), 0); gridview->moveCurrentIndexLeft(); - QCOMPARE(gridview->currentIndex(), 0); + QTRY_COMPARE(gridview->currentIndex(), 0); gridview->setCurrentIndex(model.count()-1); - QTest::qWait(100); - QCOMPARE(gridview->currentIndex(), model.count()-1); + QTRY_COMPARE(gridview->currentIndex(), model.count()-1); gridview->moveCurrentIndexRight(); - QCOMPARE(gridview->currentIndex(), model.count()-1); + QTRY_COMPARE(gridview->currentIndex(), model.count()-1); gridview->moveCurrentIndexDown(); - QCOMPARE(gridview->currentIndex(), model.count()-1); + QTRY_COMPARE(gridview->currentIndex(), model.count()-1); // with wrap gridview->setWrapEnabled(true); gridview->setCurrentIndex(0); - QCOMPARE(gridview->currentIndex(), 0); - QTest::qWait(500); + QTRY_COMPARE(gridview->currentIndex(), 0); gridview->moveCurrentIndexLeft(); - QCOMPARE(gridview->currentIndex(), model.count()-1); + QTRY_COMPARE(gridview->currentIndex(), model.count()-1); - QTest::qWait(500); - QCOMPARE(gridview->contentY(), 279.0); + QTRY_COMPARE(gridview->contentY(), 279.0); gridview->moveCurrentIndexRight(); - QCOMPARE(gridview->currentIndex(), 0); + QTRY_COMPARE(gridview->currentIndex(), 0); - QTest::qWait(500); - QCOMPARE(gridview->contentY(), 0.0); + QTRY_COMPARE(gridview->contentY(), 0.0); // Test keys canvas->show(); @@ -671,47 +627,46 @@ void tst_QDeclarativeGridView::currentIndex() // to be safe and avoid failing setFocus with window managers qt_x11_wait_for_window_manager(canvas); #endif - QVERIFY(canvas->hasFocus()); - QVERIFY(canvas->scene()->hasFocus()); + QTRY_VERIFY(canvas->hasFocus()); + QTRY_VERIFY(canvas->scene()->hasFocus()); qApp->processEvents(); QTest::keyClick(canvas, Qt::Key_Down); - QCOMPARE(gridview->currentIndex(), 3); + QTRY_COMPARE(gridview->currentIndex(), 3); QTest::keyClick(canvas, Qt::Key_Up); - QCOMPARE(gridview->currentIndex(), 0); + QTRY_COMPARE(gridview->currentIndex(), 0); gridview->setFlow(QDeclarativeGridView::TopToBottom); QTest::keyClick(canvas, Qt::Key_Right); - QCOMPARE(gridview->currentIndex(), 5); + QTRY_COMPARE(gridview->currentIndex(), 5); QTest::keyClick(canvas, Qt::Key_Left); - QCOMPARE(gridview->currentIndex(), 0); + QTRY_COMPARE(gridview->currentIndex(), 0); QTest::keyClick(canvas, Qt::Key_Down); - QCOMPARE(gridview->currentIndex(), 1); + QTRY_COMPARE(gridview->currentIndex(), 1); QTest::keyClick(canvas, Qt::Key_Up); - QCOMPARE(gridview->currentIndex(), 0); + QTRY_COMPARE(gridview->currentIndex(), 0); // turn off auto highlight gridview->setHighlightFollowsCurrentItem(false); - QVERIFY(gridview->highlightFollowsCurrentItem() == false); - QVERIFY(gridview->highlightItem()); + QTRY_VERIFY(gridview->highlightFollowsCurrentItem() == false); + QTRY_VERIFY(gridview->highlightItem()); qreal hlPosX = gridview->highlightItem()->x(); qreal hlPosY = gridview->highlightItem()->y(); gridview->setCurrentIndex(5); - QTest::qWait(500); - QCOMPARE(gridview->highlightItem()->x(), hlPosX); - QCOMPARE(gridview->highlightItem()->y(), hlPosY); + QTRY_COMPARE(gridview->highlightItem()->x(), hlPosX); + QTRY_COMPARE(gridview->highlightItem()->y(), hlPosY); // insert item before currentIndex gridview->setCurrentIndex(28); model.insertItem(0, "Foo", "1111"); - QCOMPARE(canvas->rootObject()->property("current").toInt(), 29); + QTRY_COMPARE(canvas->rootObject()->property("current").toInt(), 29); delete canvas; } @@ -732,44 +687,43 @@ void tst_QDeclarativeGridView::changeFlow() qApp->processEvents(); QDeclarativeGridView *gridview = findItem<QDeclarativeGridView>(canvas->rootObject(), "grid"); - QVERIFY(gridview != 0); + QTRY_VERIFY(gridview != 0); QDeclarativeItem *viewport = gridview->viewport(); - QVERIFY(viewport != 0); + QTRY_VERIFY(viewport != 0); // Confirm items positioned correctly and indexes correct 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"; - QVERIFY(item); - QCOMPARE(item->x(), qreal((i%3)*80)); - QCOMPARE(item->y(), qreal((i/3)*60)); + QTRY_VERIFY(item); + QTRY_COMPARE(item->x(), qreal((i%3)*80)); + QTRY_COMPARE(item->y(), qreal((i/3)*60)); QDeclarativeText *name = findItem<QDeclarativeText>(viewport, "textName", i); - QVERIFY(name != 0); - QCOMPARE(name->text(), model.name(i)); + QTRY_VERIFY(name != 0); + QTRY_COMPARE(name->text(), model.name(i)); QDeclarativeText *number = findItem<QDeclarativeText>(viewport, "textNumber", i); - QVERIFY(number != 0); - QCOMPARE(number->text(), model.number(i)); + QTRY_VERIFY(number != 0); + QTRY_COMPARE(number->text(), model.number(i)); } ctxt->setContextProperty("testTopToBottom", QVariant(true)); - QTest::qWait(100); // Confirm items positioned correctly and indexes correct 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"; - QVERIFY(item); - QCOMPARE(item->x(), qreal((i/5)*80)); - QCOMPARE(item->y(), qreal((i%5)*60)); + QTRY_VERIFY(item); + QTRY_COMPARE(item->x(), qreal((i/5)*80)); + QTRY_COMPARE(item->y(), qreal((i%5)*60)); QDeclarativeText *name = findItem<QDeclarativeText>(viewport, "textName", i); - QVERIFY(name != 0); - QCOMPARE(name->text(), model.name(i)); + QTRY_VERIFY(name != 0); + QTRY_COMPARE(name->text(), model.name(i)); QDeclarativeText *number = findItem<QDeclarativeText>(viewport, "textNumber", i); - QVERIFY(number != 0); - QCOMPARE(number->text(), model.number(i)); + QTRY_VERIFY(number != 0); + QTRY_COMPARE(number->text(), model.number(i)); } delete canvas; @@ -781,20 +735,20 @@ void tst_QDeclarativeGridView::defaultValues() QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/gridview3.qml")); QDeclarativeGridView *obj = qobject_cast<QDeclarativeGridView*>(c.create()); - QVERIFY(obj != 0); - QVERIFY(obj->model() == QVariant()); - QVERIFY(obj->delegate() == 0); - QCOMPARE(obj->currentIndex(), -1); - QVERIFY(obj->currentItem() == 0); - QCOMPARE(obj->count(), 0); - QVERIFY(obj->highlight() == 0); - QVERIFY(obj->highlightItem() == 0); - QCOMPARE(obj->highlightFollowsCurrentItem(), true); - QVERIFY(obj->flow() == 0); - QCOMPARE(obj->isWrapEnabled(), false); - QCOMPARE(obj->cacheBuffer(), 0); - QCOMPARE(obj->cellWidth(), 100); //### Should 100 be the default? - QCOMPARE(obj->cellHeight(), 100); + QTRY_VERIFY(obj != 0); + QTRY_VERIFY(obj->model() == QVariant()); + QTRY_VERIFY(obj->delegate() == 0); + QTRY_COMPARE(obj->currentIndex(), -1); + QTRY_VERIFY(obj->currentItem() == 0); + QTRY_COMPARE(obj->count(), 0); + QTRY_VERIFY(obj->highlight() == 0); + QTRY_VERIFY(obj->highlightItem() == 0); + QTRY_COMPARE(obj->highlightFollowsCurrentItem(), true); + QTRY_VERIFY(obj->flow() == 0); + QTRY_COMPARE(obj->isWrapEnabled(), false); + QTRY_COMPARE(obj->cacheBuffer(), 0); + QTRY_COMPARE(obj->cellWidth(), 100); //### Should 100 be the default? + QTRY_COMPARE(obj->cellHeight(), 100); delete obj; } @@ -804,59 +758,59 @@ void tst_QDeclarativeGridView::properties() QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/gridview2.qml")); QDeclarativeGridView *obj = qobject_cast<QDeclarativeGridView*>(c.create()); - QVERIFY(obj != 0); - QVERIFY(obj->model() != QVariant()); - QVERIFY(obj->delegate() != 0); - QCOMPARE(obj->currentIndex(), 0); - QVERIFY(obj->currentItem() != 0); - QCOMPARE(obj->count(), 4); - QVERIFY(obj->highlight() != 0); - QVERIFY(obj->highlightItem() != 0); - QCOMPARE(obj->highlightFollowsCurrentItem(), false); - QVERIFY(obj->flow() == 0); - QCOMPARE(obj->isWrapEnabled(), true); - QCOMPARE(obj->cacheBuffer(), 200); - QCOMPARE(obj->cellWidth(), 100); - QCOMPARE(obj->cellHeight(), 100); + QTRY_VERIFY(obj != 0); + QTRY_VERIFY(obj->model() != QVariant()); + QTRY_VERIFY(obj->delegate() != 0); + QTRY_COMPARE(obj->currentIndex(), 0); + QTRY_VERIFY(obj->currentItem() != 0); + QTRY_COMPARE(obj->count(), 4); + QTRY_VERIFY(obj->highlight() != 0); + QTRY_VERIFY(obj->highlightItem() != 0); + QTRY_COMPARE(obj->highlightFollowsCurrentItem(), false); + QTRY_VERIFY(obj->flow() == 0); + QTRY_COMPARE(obj->isWrapEnabled(), true); + QTRY_COMPARE(obj->cacheBuffer(), 200); + QTRY_COMPARE(obj->cellWidth(), 100); + QTRY_COMPARE(obj->cellHeight(), 100); delete obj; } void tst_QDeclarativeGridView::propertyChanges() { QDeclarativeView *canvas = createView(); - QVERIFY(canvas); + QTRY_VERIFY(canvas); canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/propertychangestest.qml")); QDeclarativeGridView *gridView = canvas->rootObject()->findChild<QDeclarativeGridView*>("gridView"); - QVERIFY(gridView); + QTRY_VERIFY(gridView); QSignalSpy keyNavigationWrapsSpy(gridView, SIGNAL(keyNavigationWrapsChanged())); QSignalSpy cacheBufferSpy(gridView, SIGNAL(cacheBufferChanged())); QSignalSpy flowSpy(gridView, SIGNAL(flowChanged())); - QCOMPARE(gridView->isWrapEnabled(), true); - QCOMPARE(gridView->cacheBuffer(), 10); - QCOMPARE(gridView->flow(), QDeclarativeGridView::LeftToRight); + QTRY_COMPARE(gridView->isWrapEnabled(), true); + QTRY_COMPARE(gridView->cacheBuffer(), 10); + QTRY_COMPARE(gridView->flow(), QDeclarativeGridView::LeftToRight); gridView->setWrapEnabled(false); gridView->setCacheBuffer(3); gridView->setFlow(QDeclarativeGridView::TopToBottom); - QCOMPARE(gridView->isWrapEnabled(), false); - QCOMPARE(gridView->cacheBuffer(), 3); - QCOMPARE(gridView->flow(), QDeclarativeGridView::TopToBottom); + QTRY_COMPARE(gridView->isWrapEnabled(), false); + QTRY_COMPARE(gridView->cacheBuffer(), 3); + QTRY_COMPARE(gridView->flow(), QDeclarativeGridView::TopToBottom); - QCOMPARE(keyNavigationWrapsSpy.count(),1); - QCOMPARE(cacheBufferSpy.count(),1); - QCOMPARE(flowSpy.count(),1); + QTRY_COMPARE(keyNavigationWrapsSpy.count(),1); + QTRY_COMPARE(cacheBufferSpy.count(),1); + QTRY_COMPARE(flowSpy.count(),1); gridView->setWrapEnabled(false); gridView->setCacheBuffer(3); gridView->setFlow(QDeclarativeGridView::TopToBottom); - QCOMPARE(keyNavigationWrapsSpy.count(),1); - QCOMPARE(cacheBufferSpy.count(),1); - QCOMPARE(flowSpy.count(),1); + QTRY_COMPARE(keyNavigationWrapsSpy.count(),1); + QTRY_COMPARE(cacheBufferSpy.count(),1); + QTRY_COMPARE(flowSpy.count(),1); delete canvas; } @@ -864,11 +818,11 @@ void tst_QDeclarativeGridView::propertyChanges() void tst_QDeclarativeGridView::componentChanges() { QDeclarativeView *canvas = createView(); - QVERIFY(canvas); + QTRY_VERIFY(canvas); canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/propertychangestest.qml")); QDeclarativeGridView *gridView = canvas->rootObject()->findChild<QDeclarativeGridView*>("gridView"); - QVERIFY(gridView); + QTRY_VERIFY(gridView); QDeclarativeComponent component(canvas->engine()); component.setData("import Qt 4.6; Rectangle { color: \"blue\"; }", QUrl::fromLocalFile("")); @@ -882,43 +836,43 @@ void tst_QDeclarativeGridView::componentChanges() gridView->setHighlight(&component); gridView->setDelegate(&delegateComponent); - QCOMPARE(gridView->highlight(), &component); - QCOMPARE(gridView->delegate(), &delegateComponent); + QTRY_COMPARE(gridView->highlight(), &component); + QTRY_COMPARE(gridView->delegate(), &delegateComponent); - QCOMPARE(highlightSpy.count(),1); - QCOMPARE(delegateSpy.count(),1); + QTRY_COMPARE(highlightSpy.count(),1); + QTRY_COMPARE(delegateSpy.count(),1); gridView->setHighlight(&component); gridView->setDelegate(&delegateComponent); - QCOMPARE(highlightSpy.count(),1); - QCOMPARE(delegateSpy.count(),1); + QTRY_COMPARE(highlightSpy.count(),1); + QTRY_COMPARE(delegateSpy.count(),1); delete canvas; } void tst_QDeclarativeGridView::modelChanges() { QDeclarativeView *canvas = createView(); - QVERIFY(canvas); + QTRY_VERIFY(canvas); canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/propertychangestest.qml")); QDeclarativeGridView *gridView = canvas->rootObject()->findChild<QDeclarativeGridView*>("gridView"); - QVERIFY(gridView); + QTRY_VERIFY(gridView); QDeclarativeListModel *alternateModel = canvas->rootObject()->findChild<QDeclarativeListModel*>("alternateModel"); - QVERIFY(alternateModel); + QTRY_VERIFY(alternateModel); QVariant modelVariant = QVariant::fromValue(alternateModel); QSignalSpy modelSpy(gridView, SIGNAL(modelChanged())); gridView->setModel(modelVariant); - QCOMPARE(gridView->model(), modelVariant); - QCOMPARE(modelSpy.count(),1); + QTRY_COMPARE(gridView->model(), modelVariant); + QTRY_COMPARE(modelSpy.count(),1); gridView->setModel(modelVariant); - QCOMPARE(modelSpy.count(),1); + QTRY_COMPARE(modelSpy.count(),1); gridView->setModel(QVariant()); - QCOMPARE(modelSpy.count(),2); + QTRY_COMPARE(modelSpy.count(),2); delete canvas; } @@ -938,117 +892,117 @@ void tst_QDeclarativeGridView::positionViewAtIndex() qApp->processEvents(); QDeclarativeGridView *gridview = findItem<QDeclarativeGridView>(canvas->rootObject(), "grid"); - QVERIFY(gridview != 0); + QTRY_VERIFY(gridview != 0); QDeclarativeItem *viewport = gridview->viewport(); - QVERIFY(viewport != 0); + QTRY_VERIFY(viewport != 0); // Confirm items positioned correctly int itemCount = findItems<QDeclarativeItem>(viewport, "wrapper").count(); for (int i = 0; i < model.count() && i < itemCount-1; ++i) { QDeclarativeItem *item = findItem<QDeclarativeItem>(viewport, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; - QVERIFY(item); - QCOMPARE(item->x(), (i%3)*80.); - QCOMPARE(item->y(), (i/3)*60.); + QTRY_VERIFY(item); + QTRY_COMPARE(item->x(), (i%3)*80.); + QTRY_COMPARE(item->y(), (i/3)*60.); } // Position on a currently visible item gridview->positionViewAtIndex(4, QDeclarativeGridView::Beginning); - QCOMPARE(gridview->contentY(), 60.); + QTRY_COMPARE(gridview->contentY(), 60.); // Confirm items positioned correctly itemCount = findItems<QDeclarativeItem>(viewport, "wrapper").count(); for (int i = 3; i < model.count() && i < itemCount-3-1; ++i) { QDeclarativeItem *item = findItem<QDeclarativeItem>(viewport, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; - QVERIFY(item); - QCOMPARE(item->x(), (i%3)*80.); - QCOMPARE(item->y(), (i/3)*60.); + QTRY_VERIFY(item); + QTRY_COMPARE(item->x(), (i%3)*80.); + QTRY_COMPARE(item->y(), (i/3)*60.); } // Position on an item beyond the visible items gridview->positionViewAtIndex(21, QDeclarativeGridView::Beginning); - QCOMPARE(gridview->contentY(), 420.); + QTRY_COMPARE(gridview->contentY(), 420.); // Confirm items positioned correctly itemCount = findItems<QDeclarativeItem>(viewport, "wrapper").count(); for (int i = 22; i < model.count() && i < itemCount-22-1; ++i) { QDeclarativeItem *item = findItem<QDeclarativeItem>(viewport, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; - QVERIFY(item); - QCOMPARE(item->x(), (i%3)*80.); - QCOMPARE(item->y(), (i/3)*60.); + QTRY_VERIFY(item); + QTRY_COMPARE(item->x(), (i%3)*80.); + QTRY_COMPARE(item->y(), (i/3)*60.); } // Position on an item that would leave empty space if positioned at the top gridview->positionViewAtIndex(31, QDeclarativeGridView::Beginning); - QCOMPARE(gridview->contentY(), 520.); + QTRY_COMPARE(gridview->contentY(), 520.); // Confirm items positioned correctly itemCount = findItems<QDeclarativeItem>(viewport, "wrapper").count(); for (int i = 24; i < model.count() && i < itemCount-24-1; ++i) { QDeclarativeItem *item = findItem<QDeclarativeItem>(viewport, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; - QVERIFY(item); - QCOMPARE(item->x(), (i%3)*80.); - QCOMPARE(item->y(), (i/3)*60.); + QTRY_VERIFY(item); + QTRY_COMPARE(item->x(), (i%3)*80.); + QTRY_COMPARE(item->y(), (i/3)*60.); } // Position at the beginning again gridview->positionViewAtIndex(0, QDeclarativeGridView::Beginning); - QCOMPARE(gridview->contentY(), 0.); + QTRY_COMPARE(gridview->contentY(), 0.); // Confirm items positioned correctly itemCount = findItems<QDeclarativeItem>(viewport, "wrapper").count(); for (int i = 0; i < model.count() && i < itemCount-1; ++i) { QDeclarativeItem *item = findItem<QDeclarativeItem>(viewport, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; - QVERIFY(item); - QCOMPARE(item->x(), (i%3)*80.); - QCOMPARE(item->y(), (i/3)*60.); + QTRY_VERIFY(item); + QTRY_COMPARE(item->x(), (i%3)*80.); + QTRY_COMPARE(item->y(), (i/3)*60.); } // Position at End gridview->positionViewAtIndex(30, QDeclarativeGridView::End); - QCOMPARE(gridview->contentY(), 340.); + QTRY_COMPARE(gridview->contentY(), 340.); // Position in Center gridview->positionViewAtIndex(15, QDeclarativeGridView::Center); - QCOMPARE(gridview->contentY(), 170.); + QTRY_COMPARE(gridview->contentY(), 170.); // Ensure at least partially visible gridview->positionViewAtIndex(15, QDeclarativeGridView::Visible); - QCOMPARE(gridview->contentY(), 170.); + QTRY_COMPARE(gridview->contentY(), 170.); gridview->setContentY(302); gridview->positionViewAtIndex(15, QDeclarativeGridView::Visible); - QCOMPARE(gridview->contentY(), 302.); + QTRY_COMPARE(gridview->contentY(), 302.); gridview->setContentY(360); gridview->positionViewAtIndex(15, QDeclarativeGridView::Visible); - QCOMPARE(gridview->contentY(), 300.); + QTRY_COMPARE(gridview->contentY(), 300.); gridview->setContentY(60); gridview->positionViewAtIndex(20, QDeclarativeGridView::Visible); - QCOMPARE(gridview->contentY(), 60.); + QTRY_COMPARE(gridview->contentY(), 60.); gridview->setContentY(20); gridview->positionViewAtIndex(20, QDeclarativeGridView::Visible); - QCOMPARE(gridview->contentY(), 100.); + QTRY_COMPARE(gridview->contentY(), 100.); // Ensure completely visible gridview->setContentY(120); gridview->positionViewAtIndex(20, QDeclarativeGridView::Contain); - QCOMPARE(gridview->contentY(), 120.); + QTRY_COMPARE(gridview->contentY(), 120.); gridview->setContentY(302); gridview->positionViewAtIndex(15, QDeclarativeGridView::Contain); - QCOMPARE(gridview->contentY(), 300.); + QTRY_COMPARE(gridview->contentY(), 300.); gridview->setContentY(60); gridview->positionViewAtIndex(20, QDeclarativeGridView::Contain); - QCOMPARE(gridview->contentY(), 100.); + QTRY_COMPARE(gridview->contentY(), 100.); delete canvas; } @@ -1068,29 +1022,29 @@ void tst_QDeclarativeGridView::resetModel() qApp->processEvents(); QDeclarativeGridView *gridview = findItem<QDeclarativeGridView>(canvas->rootObject(), "grid"); - QVERIFY(gridview != 0); + QTRY_VERIFY(gridview != 0); QDeclarativeItem *viewport = gridview->viewport(); - QVERIFY(viewport != 0); + QTRY_VERIFY(viewport != 0); - QCOMPARE(gridview->count(), model.rowCount()); + QTRY_COMPARE(gridview->count(), model.rowCount()); for (int i = 0; i < model.rowCount(); ++i) { QDeclarativeText *display = findItem<QDeclarativeText>(viewport, "displayText", i); - QVERIFY(display != 0); - QCOMPARE(display->text(), strings.at(i)); + QTRY_VERIFY(display != 0); + QTRY_COMPARE(display->text(), strings.at(i)); } strings.clear(); strings << "four" << "five" << "six" << "seven"; model.setStringList(strings); - QCOMPARE(gridview->count(), model.rowCount()); + QTRY_COMPARE(gridview->count(), model.rowCount()); for (int i = 0; i < model.rowCount(); ++i) { QDeclarativeText *display = findItem<QDeclarativeText>(viewport, "displayText", i); - QVERIFY(display != 0); - QCOMPARE(display->text(), strings.at(i)); + QTRY_VERIFY(display != 0); + QTRY_COMPARE(display->text(), strings.at(i)); } } @@ -1109,34 +1063,33 @@ void tst_QDeclarativeGridView::enforceRange() qApp->processEvents(); QDeclarativeGridView *gridview = findItem<QDeclarativeGridView>(canvas->rootObject(), "grid"); - QVERIFY(gridview != 0); + QTRY_VERIFY(gridview != 0); - QCOMPARE(gridview->preferredHighlightBegin(), 100.0); - QCOMPARE(gridview->preferredHighlightEnd(), 100.0); - QCOMPARE(gridview->highlightRangeMode(), QDeclarativeGridView::StrictlyEnforceRange); + QTRY_COMPARE(gridview->preferredHighlightBegin(), 100.0); + QTRY_COMPARE(gridview->preferredHighlightEnd(), 100.0); + QTRY_COMPARE(gridview->highlightRangeMode(), QDeclarativeGridView::StrictlyEnforceRange); QDeclarativeItem *viewport = gridview->viewport(); - QVERIFY(viewport != 0); + QTRY_VERIFY(viewport != 0); // view should be positioned at the top of the range. QDeclarativeItem *item = findItem<QDeclarativeItem>(viewport, "wrapper", 0); - QVERIFY(item); - QCOMPARE(gridview->contentY(), -100.0); + QTRY_VERIFY(item); + QTRY_COMPARE(gridview->contentY(), -100.0); QDeclarativeText *name = findItem<QDeclarativeText>(viewport, "textName", 0); - QVERIFY(name != 0); - QCOMPARE(name->text(), model.name(0)); + QTRY_VERIFY(name != 0); + QTRY_COMPARE(name->text(), model.name(0)); QDeclarativeText *number = findItem<QDeclarativeText>(viewport, "textNumber", 0); - QVERIFY(number != 0); - QCOMPARE(number->text(), model.number(0)); + QTRY_VERIFY(number != 0); + QTRY_COMPARE(number->text(), model.number(0)); // Check currentIndex is updated when viewport moves gridview->setContentY(0); - QCOMPARE(gridview->currentIndex(), 2); + QTRY_COMPARE(gridview->currentIndex(), 2); gridview->setCurrentIndex(5); - QTest::qWait(500); - QCOMPARE(gridview->contentY(), 100.); + QTRY_COMPARE(gridview->contentY(), 100.); delete canvas; } @@ -1149,9 +1102,9 @@ void tst_QDeclarativeGridView::QTBUG_8456() qApp->processEvents(); QDeclarativeGridView *gridview = findItem<QDeclarativeGridView>(canvas->rootObject(), "grid"); - QVERIFY(gridview != 0); + QTRY_VERIFY(gridview != 0); - QCOMPARE(gridview->currentIndex(), 0); + QTRY_COMPARE(gridview->currentIndex(), 0); } QDeclarativeView *tst_QDeclarativeGridView::createView() diff --git a/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp b/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp index 8d94804..e76da42 100644 --- a/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp +++ b/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp @@ -50,6 +50,7 @@ #include <QtDeclarative/private/qdeclarativevisualitemmodel_p.h> #include <QtDeclarative/private/qdeclarativelistmodel_p.h> #include <QtDeclarative/private/qlistmodelinterface_p.h> +#include "../../../shared/util.h" class tst_QDeclarativeListView : public QObject { @@ -325,62 +326,59 @@ void tst_QDeclarativeListView::items() qApp->processEvents(); QDeclarativeListView *listview = findItem<QDeclarativeListView>(canvas->rootObject(), "list"); - QVERIFY(listview != 0); + QTRY_VERIFY(listview != 0); QDeclarativeItem *viewport = listview->viewport(); - QVERIFY(viewport != 0); + QTRY_VERIFY(viewport != 0); QMetaObject::invokeMethod(canvas->rootObject(), "checkProperties"); - QVERIFY(testObject->error() == false); + QTRY_VERIFY(testObject->error() == false); - QVERIFY(listview->highlightItem() != 0); - QCOMPARE(listview->count(), model.count()); - QCOMPARE(viewport->childItems().count(), model.count()+1); // assumes all are visible, +1 for the (default) highlight item + QTRY_VERIFY(listview->highlightItem() != 0); + QTRY_COMPARE(listview->count(), model.count()); + QTRY_COMPARE(viewport->childItems().count(), model.count()+1); // assumes all are visible, +1 for the (default) highlight item // current item should be first item - QCOMPARE(listview->currentItem(), findItem<QDeclarativeItem>(viewport, "wrapper", 0)); + QTRY_COMPARE(listview->currentItem(), findItem<QDeclarativeItem>(viewport, "wrapper", 0)); for (int i = 0; i < model.count(); ++i) { QDeclarativeText *name = findItem<QDeclarativeText>(viewport, "textName", i); - QVERIFY(name != 0); - QCOMPARE(name->text(), model.name(i)); + QTRY_VERIFY(name != 0); + QTRY_COMPARE(name->text(), model.name(i)); QDeclarativeText *number = findItem<QDeclarativeText>(viewport, "textNumber", i); - QVERIFY(number != 0); - QCOMPARE(number->text(), model.number(i)); + QTRY_VERIFY(number != 0); + QTRY_COMPARE(number->text(), model.number(i)); } // switch to other delegate testObject->setAnimate(true); QMetaObject::invokeMethod(canvas->rootObject(), "checkProperties"); - QVERIFY(testObject->error() == false); - QVERIFY(listview->currentItem()); + QTRY_VERIFY(testObject->error() == false); + QTRY_VERIFY(listview->currentItem()); // set invalid highlight testObject->setInvalidHighlight(true); QMetaObject::invokeMethod(canvas->rootObject(), "checkProperties"); - QVERIFY(testObject->error() == false); - QVERIFY(listview->currentItem()); - QVERIFY(listview->highlightItem() == 0); + QTRY_VERIFY(testObject->error() == false); + QTRY_VERIFY(listview->currentItem()); + QTRY_VERIFY(listview->highlightItem() == 0); // back to normal highlight testObject->setInvalidHighlight(false); QMetaObject::invokeMethod(canvas->rootObject(), "checkProperties"); - QVERIFY(testObject->error() == false); - QVERIFY(listview->currentItem()); - QVERIFY(listview->highlightItem() != 0); + QTRY_VERIFY(testObject->error() == false); + QTRY_VERIFY(listview->currentItem()); + QTRY_VERIFY(listview->highlightItem() != 0); // set an empty model and confirm that items are destroyed T model2; ctxt->setContextProperty("testModel", &model2); - // Allow deleteLaters to process - QTest::qWait(500); - int itemCount = findItems<QDeclarativeItem>(viewport, "wrapper").count(); - QVERIFY(itemCount == 0); + QTRY_VERIFY(itemCount == 0); - QCOMPARE(listview->highlightResizeSpeed(), 1000.0); - QCOMPARE(listview->highlightMoveSpeed(), 1000.0); + QTRY_COMPARE(listview->highlightResizeSpeed(), 1000.0); + QTRY_COMPARE(listview->highlightMoveSpeed(), 1000.0); delete canvas; } @@ -406,18 +404,18 @@ void tst_QDeclarativeListView::changed() qApp->processEvents(); QDeclarativeFlickable *listview = findItem<QDeclarativeFlickable>(canvas->rootObject(), "list"); - QVERIFY(listview != 0); + QTRY_VERIFY(listview != 0); QDeclarativeItem *viewport = listview->viewport(); - QVERIFY(viewport != 0); + QTRY_VERIFY(viewport != 0); model.modifyItem(1, "Will", "9876"); QDeclarativeText *name = findItem<QDeclarativeText>(viewport, "textName", 1); - QVERIFY(name != 0); - QCOMPARE(name->text(), model.name(1)); + QTRY_VERIFY(name != 0); + QTRY_COMPARE(name->text(), model.name(1)); QDeclarativeText *number = findItem<QDeclarativeText>(viewport, "textNumber", 1); - QVERIFY(number != 0); - QCOMPARE(number->text(), model.number(1)); + QTRY_VERIFY(number != 0); + QTRY_COMPARE(number->text(), model.number(1)); delete canvas; } @@ -442,75 +440,66 @@ void tst_QDeclarativeListView::inserted() qApp->processEvents(); QDeclarativeListView *listview = findItem<QDeclarativeListView>(canvas->rootObject(), "list"); - QVERIFY(listview != 0); + QTRY_VERIFY(listview != 0); QDeclarativeItem *viewport = listview->viewport(); - QVERIFY(viewport != 0); + QTRY_VERIFY(viewport != 0); model.insertItem(1, "Will", "9876"); - // let transitions settle. - QTest::qWait(300); - - QCOMPARE(viewport->childItems().count(), model.count()+1); // assumes all are visible, +1 for the (default) highlight item + QTRY_COMPARE(viewport->childItems().count(), model.count()+1); // assumes all are visible, +1 for the (default) highlight item QDeclarativeText *name = findItem<QDeclarativeText>(viewport, "textName", 1); - QVERIFY(name != 0); - QCOMPARE(name->text(), model.name(1)); + QTRY_VERIFY(name != 0); + QTRY_COMPARE(name->text(), model.name(1)); QDeclarativeText *number = findItem<QDeclarativeText>(viewport, "textNumber", 1); - QVERIFY(number != 0); - QCOMPARE(number->text(), model.number(1)); + QTRY_VERIFY(number != 0); + QTRY_COMPARE(number->text(), model.number(1)); // Confirm items positioned correctly for (int i = 0; i < model.count(); ++i) { QDeclarativeItem *item = findItem<QDeclarativeItem>(viewport, "wrapper", i); - QCOMPARE(item->y(), i*20.0); + QTRY_COMPARE(item->y(), i*20.0); } model.insertItem(0, "Foo", "1111"); // zero index, and current item - // let transitions settle. - QTest::qWait(300); - - QCOMPARE(viewport->childItems().count(), model.count()+1); // assumes all are visible, +1 for the (default) highlight item + QTRY_COMPARE(viewport->childItems().count(), model.count()+1); // assumes all are visible, +1 for the (default) highlight item name = findItem<QDeclarativeText>(viewport, "textName", 0); - QVERIFY(name != 0); - QCOMPARE(name->text(), model.name(0)); + QTRY_VERIFY(name != 0); + QTRY_COMPARE(name->text(), model.name(0)); number = findItem<QDeclarativeText>(viewport, "textNumber", 0); - QVERIFY(number != 0); - QCOMPARE(number->text(), model.number(0)); + QTRY_VERIFY(number != 0); + QTRY_COMPARE(number->text(), model.number(0)); - QCOMPARE(listview->currentIndex(), 1); + QTRY_COMPARE(listview->currentIndex(), 1); // Confirm items positioned correctly for (int i = 0; i < model.count(); ++i) { QDeclarativeItem *item = findItem<QDeclarativeItem>(viewport, "wrapper", i); - QCOMPARE(item->y(), i*20.0); + QTRY_COMPARE(item->y(), i*20.0); } for (int i = model.count(); i < 30; ++i) model.insertItem(i, "Hello", QString::number(i)); - QTest::qWait(300); listview->setContentY(80); - QTest::qWait(300); // Insert item outside visible area model.insertItem(1, "Hello", "1324"); - QTest::qWait(300); - QVERIFY(listview->contentY() == 80); + QTRY_VERIFY(listview->contentY() == 80); // Confirm items positioned correctly for (int i = 5; i < 5+15; ++i) { QDeclarativeItem *item = findItem<QDeclarativeItem>(viewport, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; - QVERIFY(item); - QCOMPARE(item->y(), i*20.0 - 20.0); + QTRY_VERIFY(item); + QTRY_COMPARE(item->y(), i*20.0 - 20.0); } -// QCOMPARE(listview->viewportHeight(), model.count() * 20.0); +// QTRY_COMPARE(listview->viewportHeight(), model.count() * 20.0); delete canvas; } @@ -535,66 +524,60 @@ void tst_QDeclarativeListView::removed(bool animated) qApp->processEvents(); QDeclarativeListView *listview = findItem<QDeclarativeListView>(canvas->rootObject(), "list"); - QVERIFY(listview != 0); + QTRY_VERIFY(listview != 0); QDeclarativeItem *viewport = listview->viewport(); - QVERIFY(viewport != 0); + QTRY_VERIFY(viewport != 0); model.removeItem(1); - // let transitions settle. - QTest::qWait(300); - QDeclarativeText *name = findItem<QDeclarativeText>(viewport, "textName", 1); - QVERIFY(name != 0); - QCOMPARE(name->text(), model.name(1)); + QTRY_VERIFY(name != 0); + QTRY_COMPARE(name->text(), model.name(1)); QDeclarativeText *number = findItem<QDeclarativeText>(viewport, "textNumber", 1); - QVERIFY(number != 0); - QCOMPARE(number->text(), model.number(1)); + QTRY_VERIFY(number != 0); + QTRY_COMPARE(number->text(), model.number(1)); // 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"; - QVERIFY(item); - QVERIFY(item->y() == i*20); + QTRY_VERIFY(item); + QTRY_VERIFY(item->y() == i*20); } // Remove first item (which is the current item); model.removeItem(0); // post: top item starts at 20 - // let transitions settle. QTest::qWait(300); name = findItem<QDeclarativeText>(viewport, "textName", 0); - QVERIFY(name != 0); - QCOMPARE(name->text(), model.name(0)); + QTRY_VERIFY(name != 0); + QTRY_COMPARE(name->text(), model.name(0)); number = findItem<QDeclarativeText>(viewport, "textNumber", 0); - QVERIFY(number != 0); - QCOMPARE(number->text(), model.number(0)); + QTRY_VERIFY(number != 0); + QTRY_COMPARE(number->text(), model.number(0)); // Confirm items positioned correctly 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"; - QVERIFY(item); - QCOMPARE(item->y(),i*20.0 + 20.0); + QTRY_VERIFY(item); + QTRY_COMPARE(item->y(),i*20.0 + 20.0); } // Remove items not visible model.removeItem(18); - // let transitions settle. - QTest::qWait(300); // Confirm items positioned correctly 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"; - QVERIFY(item); - QCOMPARE(item->y(),i*20.0+20.0); + QTRY_VERIFY(item); + QTRY_COMPARE(item->y(),i*20.0+20.0); } // Remove items before visible @@ -602,25 +585,22 @@ void tst_QDeclarativeListView::removed(bool animated) listview->setCurrentIndex(10); model.removeItem(1); // post: top item will be at 40 - // let transitions settle. - QTest::qWait(300); // Confirm items positioned correctly for (int i = 2; i < 18; ++i) { QDeclarativeItem *item = findItem<QDeclarativeItem>(viewport, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; - QVERIFY(item); - QCOMPARE(item->y(),40+i*20.0); + QTRY_VERIFY(item); + QTRY_COMPARE(item->y(),40+i*20.0); } // Remove current index - QVERIFY(listview->currentIndex() == 9); + QTRY_VERIFY(listview->currentIndex() == 9); QDeclarativeItem *oldCurrent = listview->currentItem(); model.removeItem(9); - QTest::qWait(300); - QCOMPARE(listview->currentIndex(), 9); - QVERIFY(listview->currentItem() != oldCurrent); + QTRY_COMPARE(listview->currentIndex(), 9); + QTRY_VERIFY(listview->currentItem() != oldCurrent); listview->setContentY(40); // That's the top now // let transitions settle. @@ -631,29 +611,25 @@ void tst_QDeclarativeListView::removed(bool animated) for (int i = 0; i < model.count() && i < itemCount; ++i) { QDeclarativeItem *item = findItem<QDeclarativeItem>(viewport, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; - QVERIFY(item); - QCOMPARE(item->y(),40+i*20.0); + QTRY_VERIFY(item); + QTRY_COMPARE(item->y(),40+i*20.0); } // remove current item beyond visible items. listview->setCurrentIndex(20); - QTest::qWait(300); listview->setContentY(40); model.removeItem(20); - QTest::qWait(300); - QCOMPARE(listview->currentIndex(), 20); - QVERIFY(listview->currentItem() != 0); + QTRY_COMPARE(listview->currentIndex(), 20); + QTRY_VERIFY(listview->currentItem() != 0); // remove item before current, but visible listview->setCurrentIndex(8); - QTest::qWait(300); oldCurrent = listview->currentItem(); model.removeItem(6); - QTest::qWait(300); - QCOMPARE(listview->currentIndex(), 7); - QVERIFY(listview->currentItem() == oldCurrent); + QTRY_COMPARE(listview->currentIndex(), 7); + QTRY_VERIFY(listview->currentItem() == oldCurrent); delete canvas; } @@ -677,19 +653,16 @@ void tst_QDeclarativeListView::clear() qApp->processEvents(); QDeclarativeListView *listview = findItem<QDeclarativeListView>(canvas->rootObject(), "list"); - QVERIFY(listview != 0); + QTRY_VERIFY(listview != 0); QDeclarativeItem *viewport = listview->viewport(); - QVERIFY(viewport != 0); + QTRY_VERIFY(viewport != 0); model.clear(); - // let transitions settle. - QTest::qWait(500); - - QVERIFY(listview->count() == 0); - QVERIFY(listview->currentItem() == 0); - QVERIFY(listview->contentY() == 0); + QTRY_VERIFY(listview->count() == 0); + QTRY_VERIFY(listview->currentItem() == 0); + QTRY_VERIFY(listview->contentY() == 0); delete canvas; } @@ -714,37 +687,34 @@ void tst_QDeclarativeListView::moved() qApp->processEvents(); QDeclarativeListView *listview = findItem<QDeclarativeListView>(canvas->rootObject(), "list"); - QVERIFY(listview != 0); + QTRY_VERIFY(listview != 0); QDeclarativeItem *viewport = listview->viewport(); - QVERIFY(viewport != 0); + QTRY_VERIFY(viewport != 0); model.moveItem(1, 4); - // let transitions settle. - QTest::qWait(500); - QDeclarativeText *name = findItem<QDeclarativeText>(viewport, "textName", 1); - QVERIFY(name != 0); - QCOMPARE(name->text(), model.name(1)); + QTRY_VERIFY(name != 0); + QTRY_COMPARE(name->text(), model.name(1)); QDeclarativeText *number = findItem<QDeclarativeText>(viewport, "textNumber", 1); - QVERIFY(number != 0); - QCOMPARE(number->text(), model.number(1)); + QTRY_VERIFY(number != 0); + QTRY_COMPARE(number->text(), model.number(1)); name = findItem<QDeclarativeText>(viewport, "textName", 4); - QVERIFY(name != 0); - QCOMPARE(name->text(), model.name(4)); + QTRY_VERIFY(name != 0); + QTRY_COMPARE(name->text(), model.name(4)); number = findItem<QDeclarativeText>(viewport, "textNumber", 4); - QVERIFY(number != 0); - QCOMPARE(number->text(), model.number(4)); + QTRY_VERIFY(number != 0); + QTRY_COMPARE(number->text(), model.number(4)); // 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"; - QVERIFY(item); - QVERIFY(item->y() == i*20); + QTRY_VERIFY(item); + QTRY_VERIFY(item->y() == i*20); } listview->setContentY(80); @@ -752,41 +722,35 @@ void tst_QDeclarativeListView::moved() // move outside visible area model.moveItem(1, 18); - // let transitions settle. - QTest::qWait(500); - // Confirm items positioned correctly and indexes correct for (int i = 3; i < model.count() && i < itemCount; ++i) { QDeclarativeItem *item = findItem<QDeclarativeItem>(viewport, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; - QVERIFY(item); - QCOMPARE(item->y(), i*20.0 + 20); + QTRY_VERIFY(item); + QTRY_COMPARE(item->y(), i*20.0 + 20); name = findItem<QDeclarativeText>(viewport, "textName", i); - QVERIFY(name != 0); - QCOMPARE(name->text(), model.name(i)); + QTRY_VERIFY(name != 0); + QTRY_COMPARE(name->text(), model.name(i)); number = findItem<QDeclarativeText>(viewport, "textNumber", i); - QVERIFY(number != 0); - QCOMPARE(number->text(), model.number(i)); + QTRY_VERIFY(number != 0); + QTRY_COMPARE(number->text(), model.number(i)); } // move from outside visible into visible model.moveItem(20, 4); - // let transitions settle. - QTest::qWait(500); - // Confirm items positioned correctly and indexes correct for (int i = 3; i < model.count() && i < itemCount; ++i) { QDeclarativeItem *item = findItem<QDeclarativeItem>(viewport, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; - QVERIFY(item); - QCOMPARE(item->y(), i*20.0 + 20); + QTRY_VERIFY(item); + QTRY_COMPARE(item->y(), i*20.0 + 20); name = findItem<QDeclarativeText>(viewport, "textName", i); - QVERIFY(name != 0); - QCOMPARE(name->text(), model.name(i)); + QTRY_VERIFY(name != 0); + QTRY_COMPARE(name->text(), model.name(i)); number = findItem<QDeclarativeText>(viewport, "textNumber", i); - QVERIFY(number != 0); - QCOMPARE(number->text(), model.number(i)); + QTRY_VERIFY(number != 0); + QTRY_COMPARE(number->text(), model.number(i)); } delete canvas; @@ -807,32 +771,31 @@ void tst_QDeclarativeListView::enforceRange() qApp->processEvents(); QDeclarativeListView *listview = findItem<QDeclarativeListView>(canvas->rootObject(), "list"); - QVERIFY(listview != 0); + QTRY_VERIFY(listview != 0); - QCOMPARE(listview->preferredHighlightBegin(), 100.0); - QCOMPARE(listview->preferredHighlightEnd(), 100.0); - QCOMPARE(listview->highlightRangeMode(), QDeclarativeListView::StrictlyEnforceRange); + QTRY_COMPARE(listview->preferredHighlightBegin(), 100.0); + QTRY_COMPARE(listview->preferredHighlightEnd(), 100.0); + QTRY_COMPARE(listview->highlightRangeMode(), QDeclarativeListView::StrictlyEnforceRange); QDeclarativeItem *viewport = listview->viewport(); - QVERIFY(viewport != 0); + QTRY_VERIFY(viewport != 0); // view should be positioned at the top of the range. QDeclarativeItem *item = findItem<QDeclarativeItem>(viewport, "wrapper", 0); - QVERIFY(item); - QCOMPARE(listview->contentY(), -100.0); + QTRY_VERIFY(item); + QTRY_COMPARE(listview->contentY(), -100.0); QDeclarativeText *name = findItem<QDeclarativeText>(viewport, "textName", 0); - QVERIFY(name != 0); - QCOMPARE(name->text(), model.name(0)); + QTRY_VERIFY(name != 0); + QTRY_COMPARE(name->text(), model.name(0)); QDeclarativeText *number = findItem<QDeclarativeText>(viewport, "textNumber", 0); - QVERIFY(number != 0); - QCOMPARE(number->text(), model.number(0)); + QTRY_VERIFY(number != 0); + QTRY_COMPARE(number->text(), model.number(0)); // Check currentIndex is updated when viewport moves listview->setContentY(20); - QTest::qWait(500); - QCOMPARE(listview->currentIndex(), 6); + QTRY_COMPARE(listview->currentIndex(), 6); delete canvas; } @@ -855,30 +818,30 @@ void tst_QDeclarativeListView::spacing() qApp->processEvents(); QDeclarativeListView *listview = findItem<QDeclarativeListView>(canvas->rootObject(), "list"); - QVERIFY(listview != 0); + QTRY_VERIFY(listview != 0); QDeclarativeItem *viewport = listview->viewport(); - QVERIFY(viewport != 0); + 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"; - QVERIFY(item); - QVERIFY(item->y() == i*20); + QTRY_VERIFY(item); + QTRY_VERIFY(item->y() == i*20); } listview->setSpacing(10); - QVERIFY(listview->spacing() == 10); + QTRY_VERIFY(listview->spacing() == 10); // Confirm items positioned correctly 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"; - QVERIFY(item); - QVERIFY(item->y() == i*30); + QTRY_VERIFY(item); + QTRY_VERIFY(item->y() == i*30); } listview->setSpacing(0); @@ -888,8 +851,8 @@ void tst_QDeclarativeListView::spacing() for (int i = 0; i < model.count() && i < itemCount; ++i) { QDeclarativeItem *item = findItem<QDeclarativeItem>(viewport, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; - QVERIFY(item); - QCOMPARE(item->y(), i*20.0); + QTRY_VERIFY(item); + QTRY_COMPARE(item->y(), i*20.0); } delete canvas; @@ -910,63 +873,60 @@ void tst_QDeclarativeListView::sections() qApp->processEvents(); QDeclarativeListView *listview = findItem<QDeclarativeListView>(canvas->rootObject(), "list"); - QVERIFY(listview != 0); + QTRY_VERIFY(listview != 0); QDeclarativeItem *viewport = listview->viewport(); - QVERIFY(viewport != 0); + 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); - QVERIFY(item); - QCOMPARE(item->y(), qreal(i*20 + ((i+4)/5) * 20)); + QTRY_VERIFY(item); + QTRY_COMPARE(item->y(), qreal(i*20 + ((i+4)/5) * 20)); } // Remove section boundary model.removeItem(5); - QTest::qWait(100); // New section header created QDeclarativeItem *item = findItem<QDeclarativeItem>(viewport, "wrapper", 5); - QVERIFY(item); - QCOMPARE(item->height(), 40.0); + QTRY_VERIFY(item); + QTRY_COMPARE(item->height(), 40.0); model.insertItem(3, "New Item", "0"); - QTest::qWait(100); // Section header moved item = findItem<QDeclarativeItem>(viewport, "wrapper", 5); - QVERIFY(item); - QCOMPARE(item->height(), 20.0); + QTRY_VERIFY(item); + QTRY_COMPARE(item->height(), 20.0); item = findItem<QDeclarativeItem>(viewport, "wrapper", 6); - QVERIFY(item); - QCOMPARE(item->height(), 40.0); + QTRY_VERIFY(item); + QTRY_COMPARE(item->height(), 40.0); // insert item which will become a section header model.insertItem(6, "Replace header", "1"); - QTest::qWait(100); item = findItem<QDeclarativeItem>(viewport, "wrapper", 6); - QVERIFY(item); - QCOMPARE(item->height(), 40.0); + QTRY_VERIFY(item); + QTRY_COMPARE(item->height(), 40.0); item = findItem<QDeclarativeItem>(viewport, "wrapper", 7); - QVERIFY(item); - QCOMPARE(item->height(), 20.0); + QTRY_VERIFY(item); + QTRY_COMPARE(item->height(), 20.0); - QCOMPARE(listview->currentSection(), QString("0")); + QTRY_COMPARE(listview->currentSection(), QString("0")); listview->setContentY(140); - QCOMPARE(listview->currentSection(), QString("1")); + QTRY_COMPARE(listview->currentSection(), QString("1")); listview->setContentY(20); - QCOMPARE(listview->currentSection(), QString("0")); + QTRY_COMPARE(listview->currentSection(), QString("0")); item = findItem<QDeclarativeItem>(viewport, "wrapper", 1); - QVERIFY(item); - QCOMPARE(item->height(), 20.0); + QTRY_VERIFY(item); + QTRY_COMPARE(item->height(), 20.0); delete canvas; } @@ -990,45 +950,41 @@ void tst_QDeclarativeListView::currentIndex() qApp->processEvents(); QDeclarativeListView *listview = findItem<QDeclarativeListView>(canvas->rootObject(), "list"); - QVERIFY(listview != 0); + QTRY_VERIFY(listview != 0); QDeclarativeItem *viewport = listview->viewport(); - QVERIFY(viewport != 0); - - QTest::qWait(500); + QTRY_VERIFY(viewport != 0); // current item should be third item - QCOMPARE(listview->currentIndex(), 3); - QCOMPARE(listview->currentItem(), findItem<QDeclarativeItem>(viewport, "wrapper", 3)); - QCOMPARE(listview->highlightItem()->y(), listview->currentItem()->y()); + QTRY_COMPARE(listview->currentIndex(), 3); + QTRY_COMPARE(listview->currentItem(), findItem<QDeclarativeItem>(viewport, "wrapper", 3)); + QTRY_COMPARE(listview->highlightItem()->y(), listview->currentItem()->y()); // no wrap listview->setCurrentIndex(0); - QCOMPARE(listview->currentIndex(), 0); + QTRY_COMPARE(listview->currentIndex(), 0); listview->incrementCurrentIndex(); - QCOMPARE(listview->currentIndex(), 1); + QTRY_COMPARE(listview->currentIndex(), 1); listview->decrementCurrentIndex(); - QCOMPARE(listview->currentIndex(), 0); + QTRY_COMPARE(listview->currentIndex(), 0); listview->decrementCurrentIndex(); - QCOMPARE(listview->currentIndex(), 0); + QTRY_COMPARE(listview->currentIndex(), 0); // with wrap ctxt->setContextProperty("testWrap", QVariant(true)); - QVERIFY(listview->isWrapEnabled()); + QTRY_VERIFY(listview->isWrapEnabled()); listview->decrementCurrentIndex(); - QCOMPARE(listview->currentIndex(), model.count()-1); + QTRY_COMPARE(listview->currentIndex(), model.count()-1); - QTest::qWait(1000); - QCOMPARE(listview->contentY(), 279.0); + QTRY_COMPARE(listview->contentY(), 279.0); listview->incrementCurrentIndex(); - QCOMPARE(listview->currentIndex(), 0); + QTRY_COMPARE(listview->currentIndex(), 0); - QTest::qWait(1000); - QCOMPARE(listview->contentY(), 0.0); + QTRY_COMPARE(listview->contentY(), 0.0); // Test keys canvas->show(); @@ -1037,32 +993,30 @@ void tst_QDeclarativeListView::currentIndex() // to be safe and avoid failing setFocus with window managers qt_x11_wait_for_window_manager(canvas); #endif - QVERIFY(canvas->hasFocus()); - QVERIFY(canvas->scene()->hasFocus()); + QTRY_VERIFY(canvas->hasFocus()); + QTRY_VERIFY(canvas->scene()->hasFocus()); qApp->processEvents(); QTest::keyClick(canvas, Qt::Key_Down); - QCOMPARE(listview->currentIndex(), 1); + QTRY_COMPARE(listview->currentIndex(), 1); QTest::keyClick(canvas, Qt::Key_Up); - QCOMPARE(listview->currentIndex(), 0); + QTRY_COMPARE(listview->currentIndex(), 0); // turn off auto highlight listview->setHighlightFollowsCurrentItem(false); - QVERIFY(listview->highlightFollowsCurrentItem() == false); + QTRY_VERIFY(listview->highlightFollowsCurrentItem() == false); - QTest::qWait(500); - QVERIFY(listview->highlightItem()); + QTRY_VERIFY(listview->highlightItem()); qreal hlPos = listview->highlightItem()->y(); listview->setCurrentIndex(4); - QTest::qWait(500); - QCOMPARE(listview->highlightItem()->y(), hlPos); + QTRY_COMPARE(listview->highlightItem()->y(), hlPos); // insert item before currentIndex listview->setCurrentIndex(28); model.insertItem(0, "Foo", "1111"); - QCOMPARE(canvas->rootObject()->property("current").toInt(), 29); + QTRY_COMPARE(canvas->rootObject()->property("current").toInt(), 29); delete canvas; } @@ -1075,35 +1029,34 @@ void tst_QDeclarativeListView::itemList() qApp->processEvents(); QDeclarativeListView *listview = findItem<QDeclarativeListView>(canvas->rootObject(), "view"); - QVERIFY(listview != 0); + QTRY_VERIFY(listview != 0); QDeclarativeItem *viewport = listview->viewport(); - QVERIFY(viewport != 0); + QTRY_VERIFY(viewport != 0); QDeclarativeVisualItemModel *model = canvas->rootObject()->findChild<QDeclarativeVisualItemModel*>("itemModel"); - QVERIFY(model != 0); + QTRY_VERIFY(model != 0); - QVERIFY(model->count() == 3); - QCOMPARE(listview->currentIndex(), 0); + QTRY_VERIFY(model->count() == 3); + QTRY_COMPARE(listview->currentIndex(), 0); QDeclarativeItem *item = findItem<QDeclarativeItem>(viewport, "item1"); - QVERIFY(item); - QCOMPARE(item->x(), 0.0); + QTRY_VERIFY(item); + QTRY_COMPARE(item->x(), 0.0); QDeclarativeText *text = findItem<QDeclarativeText>(viewport, "text1"); - QVERIFY(text); - QCOMPARE(text->text(), QLatin1String("index: 0")); + QTRY_VERIFY(text); + QTRY_COMPARE(text->text(), QLatin1String("index: 0")); listview->setCurrentIndex(2); - QTest::qWait(1000); item = findItem<QDeclarativeItem>(viewport, "item3"); - QVERIFY(item); - QCOMPARE(item->x(), 480.0); + QTRY_VERIFY(item); + QTRY_COMPARE(item->x(), 480.0); text = findItem<QDeclarativeText>(viewport, "text3"); - QVERIFY(text); - QCOMPARE(text->text(), QLatin1String("index: 2")); + QTRY_VERIFY(text); + QTRY_COMPARE(text->text(), QLatin1String("index: 2")); delete canvas; } @@ -1126,35 +1079,35 @@ void tst_QDeclarativeListView::cacheBuffer() qApp->processEvents(); QDeclarativeListView *listview = findItem<QDeclarativeListView>(canvas->rootObject(), "list"); - QVERIFY(listview != 0); + QTRY_VERIFY(listview != 0); QDeclarativeItem *viewport = listview->viewport(); - QVERIFY(viewport != 0); - QVERIFY(listview->delegate() != 0); - QVERIFY(listview->model() != 0); - QVERIFY(listview->highlight() != 0); + QTRY_VERIFY(viewport != 0); + QTRY_VERIFY(listview->delegate() != 0); + QTRY_VERIFY(listview->model() != 0); + QTRY_VERIFY(listview->highlight() != 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"; - QVERIFY(item); - QVERIFY(item->y() == i*20); + QTRY_VERIFY(item); + QTRY_VERIFY(item->y() == i*20); } testObject->setCacheBuffer(400); - QVERIFY(listview->cacheBuffer() == 400); + QTRY_VERIFY(listview->cacheBuffer() == 400); int newItemCount = findItems<QDeclarativeItem>(viewport, "wrapper").count(); - QVERIFY(newItemCount > itemCount); + QTRY_VERIFY(newItemCount > itemCount); // Confirm items positioned correctly for (int i = 0; i < model.count() && i < newItemCount; ++i) { QDeclarativeItem *item = findItem<QDeclarativeItem>(viewport, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; - QVERIFY(item); - QVERIFY(item->y() == i*20); + QTRY_VERIFY(item); + QTRY_VERIFY(item->y() == i*20); } delete canvas; @@ -1178,112 +1131,112 @@ void tst_QDeclarativeListView::positionViewAtIndex() qApp->processEvents(); QDeclarativeListView *listview = findItem<QDeclarativeListView>(canvas->rootObject(), "list"); - QVERIFY(listview != 0); + QTRY_VERIFY(listview != 0); QDeclarativeItem *viewport = listview->viewport(); - QVERIFY(viewport != 0); + 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"; - QVERIFY(item); - QCOMPARE(item->y(), i*20.); + QTRY_VERIFY(item); + QTRY_COMPARE(item->y(), i*20.); } // Position on a currently visible item listview->positionViewAtIndex(3, QDeclarativeListView::Beginning); - QCOMPARE(listview->contentY(), 60.); + QTRY_COMPARE(listview->contentY(), 60.); // Confirm items positioned correctly itemCount = findItems<QDeclarativeItem>(viewport, "wrapper").count(); for (int i = 3; i < model.count() && i < itemCount-3-1; ++i) { QDeclarativeItem *item = findItem<QDeclarativeItem>(viewport, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; - QVERIFY(item); - QCOMPARE(item->y(), i*20.); + QTRY_VERIFY(item); + QTRY_COMPARE(item->y(), i*20.); } // Position on an item beyond the visible items listview->positionViewAtIndex(22, QDeclarativeListView::Beginning); - QCOMPARE(listview->contentY(), 440.); + QTRY_COMPARE(listview->contentY(), 440.); // Confirm items positioned correctly itemCount = findItems<QDeclarativeItem>(viewport, "wrapper").count(); for (int i = 22; i < model.count() && i < itemCount-22-1; ++i) { QDeclarativeItem *item = findItem<QDeclarativeItem>(viewport, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; - QVERIFY(item); - QCOMPARE(item->y(), i*20.); + QTRY_VERIFY(item); + QTRY_COMPARE(item->y(), i*20.); } // Position on an item that would leave empty space if positioned at the top listview->positionViewAtIndex(28, QDeclarativeListView::Beginning); - QCOMPARE(listview->contentY(), 480.); + QTRY_COMPARE(listview->contentY(), 480.); // Confirm items positioned correctly itemCount = findItems<QDeclarativeItem>(viewport, "wrapper").count(); for (int i = 24; i < model.count() && i < itemCount-24-1; ++i) { QDeclarativeItem *item = findItem<QDeclarativeItem>(viewport, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; - QVERIFY(item); - QCOMPARE(item->y(), i*20.); + QTRY_VERIFY(item); + QTRY_COMPARE(item->y(), i*20.); } // Position at the beginning again listview->positionViewAtIndex(0, QDeclarativeListView::Beginning); - QCOMPARE(listview->contentY(), 0.); + QTRY_COMPARE(listview->contentY(), 0.); // Confirm items positioned correctly itemCount = findItems<QDeclarativeItem>(viewport, "wrapper").count(); for (int i = 0; i < model.count() && i < itemCount-1; ++i) { QDeclarativeItem *item = findItem<QDeclarativeItem>(viewport, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; - QVERIFY(item); - QCOMPARE(item->y(), i*20.); + QTRY_VERIFY(item); + QTRY_COMPARE(item->y(), i*20.); } // Position at End listview->positionViewAtIndex(20, QDeclarativeListView::End); - QCOMPARE(listview->contentY(), 100.); + QTRY_COMPARE(listview->contentY(), 100.); // Position in Center listview->positionViewAtIndex(15, QDeclarativeListView::Center); - QCOMPARE(listview->contentY(), 150.); + QTRY_COMPARE(listview->contentY(), 150.); // Ensure at least partially visible listview->positionViewAtIndex(15, QDeclarativeListView::Visible); - QCOMPARE(listview->contentY(), 150.); + QTRY_COMPARE(listview->contentY(), 150.); listview->setContentY(302); listview->positionViewAtIndex(15, QDeclarativeListView::Visible); - QCOMPARE(listview->contentY(), 302.); + QTRY_COMPARE(listview->contentY(), 302.); listview->setContentY(320); listview->positionViewAtIndex(15, QDeclarativeListView::Visible); - QCOMPARE(listview->contentY(), 300.); + QTRY_COMPARE(listview->contentY(), 300.); listview->setContentY(85); listview->positionViewAtIndex(20, QDeclarativeListView::Visible); - QCOMPARE(listview->contentY(), 85.); + QTRY_COMPARE(listview->contentY(), 85.); listview->setContentY(75); listview->positionViewAtIndex(20, QDeclarativeListView::Visible); - QCOMPARE(listview->contentY(), 100.); + QTRY_COMPARE(listview->contentY(), 100.); // Ensure completely visible listview->setContentY(120); listview->positionViewAtIndex(20, QDeclarativeListView::Contain); - QCOMPARE(listview->contentY(), 120.); + QTRY_COMPARE(listview->contentY(), 120.); listview->setContentY(302); listview->positionViewAtIndex(15, QDeclarativeListView::Contain); - QCOMPARE(listview->contentY(), 300.); + QTRY_COMPARE(listview->contentY(), 300.); listview->setContentY(85); listview->positionViewAtIndex(20, QDeclarativeListView::Contain); - QCOMPARE(listview->contentY(), 100.); + QTRY_COMPARE(listview->contentY(), 100.); delete canvas; } @@ -1303,40 +1256,40 @@ void tst_QDeclarativeListView::resetModel() qApp->processEvents(); QDeclarativeListView *listview = findItem<QDeclarativeListView>(canvas->rootObject(), "list"); - QVERIFY(listview != 0); + QTRY_VERIFY(listview != 0); QDeclarativeItem *viewport = listview->viewport(); - QVERIFY(viewport != 0); + QTRY_VERIFY(viewport != 0); - QCOMPARE(listview->count(), model.rowCount()); + QTRY_COMPARE(listview->count(), model.rowCount()); for (int i = 0; i < model.rowCount(); ++i) { QDeclarativeText *display = findItem<QDeclarativeText>(viewport, "displayText", i); - QVERIFY(display != 0); - QCOMPARE(display->text(), strings.at(i)); + QTRY_VERIFY(display != 0); + QTRY_COMPARE(display->text(), strings.at(i)); } strings.clear(); strings << "four" << "five" << "six" << "seven"; model.setStringList(strings); - QCOMPARE(listview->count(), model.rowCount()); + QTRY_COMPARE(listview->count(), model.rowCount()); for (int i = 0; i < model.rowCount(); ++i) { QDeclarativeText *display = findItem<QDeclarativeText>(viewport, "displayText", i); - QVERIFY(display != 0); - QCOMPARE(display->text(), strings.at(i)); + QTRY_VERIFY(display != 0); + QTRY_COMPARE(display->text(), strings.at(i)); } } void tst_QDeclarativeListView::propertyChanges() { QDeclarativeView *canvas = createView(); - QVERIFY(canvas); + QTRY_VERIFY(canvas); canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/propertychangestest.qml")); QDeclarativeListView *listView = canvas->rootObject()->findChild<QDeclarativeListView*>("listView"); - QVERIFY(listView); + QTRY_VERIFY(listView); QSignalSpy highlightFollowsCurrentItemSpy(listView, SIGNAL(highlightFollowsCurrentItemChanged())); QSignalSpy preferredHighlightBeginSpy(listView, SIGNAL(preferredHighlightBeginChanged())); @@ -1346,13 +1299,13 @@ void tst_QDeclarativeListView::propertyChanges() QSignalSpy cacheBufferSpy(listView, SIGNAL(cacheBufferChanged())); QSignalSpy snapModeSpy(listView, SIGNAL(snapModeChanged())); - QCOMPARE(listView->highlightFollowsCurrentItem(), true); - QCOMPARE(listView->preferredHighlightBegin(), 0.0); - QCOMPARE(listView->preferredHighlightEnd(), 0.0); - QCOMPARE(listView->highlightRangeMode(), QDeclarativeListView::ApplyRange); - QCOMPARE(listView->isWrapEnabled(), true); - QCOMPARE(listView->cacheBuffer(), 10); - QCOMPARE(listView->snapMode(), QDeclarativeListView::SnapToItem); + QTRY_COMPARE(listView->highlightFollowsCurrentItem(), true); + QTRY_COMPARE(listView->preferredHighlightBegin(), 0.0); + QTRY_COMPARE(listView->preferredHighlightEnd(), 0.0); + QTRY_COMPARE(listView->highlightRangeMode(), QDeclarativeListView::ApplyRange); + QTRY_COMPARE(listView->isWrapEnabled(), true); + QTRY_COMPARE(listView->cacheBuffer(), 10); + QTRY_COMPARE(listView->snapMode(), QDeclarativeListView::SnapToItem); listView->setHighlightFollowsCurrentItem(false); listView->setPreferredHighlightBegin(1.0); @@ -1362,21 +1315,21 @@ void tst_QDeclarativeListView::propertyChanges() listView->setCacheBuffer(3); listView->setSnapMode(QDeclarativeListView::SnapOneItem); - QCOMPARE(listView->highlightFollowsCurrentItem(), false); - QCOMPARE(listView->preferredHighlightBegin(), 1.0); - QCOMPARE(listView->preferredHighlightEnd(), 1.0); - QCOMPARE(listView->highlightRangeMode(), QDeclarativeListView::StrictlyEnforceRange); - QCOMPARE(listView->isWrapEnabled(), false); - QCOMPARE(listView->cacheBuffer(), 3); - QCOMPARE(listView->snapMode(), QDeclarativeListView::SnapOneItem); - - QCOMPARE(highlightFollowsCurrentItemSpy.count(),1); - QCOMPARE(preferredHighlightBeginSpy.count(),1); - QCOMPARE(preferredHighlightEndSpy.count(),1); - QCOMPARE(highlightRangeModeSpy.count(),1); - QCOMPARE(keyNavigationWrapsSpy.count(),1); - QCOMPARE(cacheBufferSpy.count(),1); - QCOMPARE(snapModeSpy.count(),1); + QTRY_COMPARE(listView->highlightFollowsCurrentItem(), false); + QTRY_COMPARE(listView->preferredHighlightBegin(), 1.0); + QTRY_COMPARE(listView->preferredHighlightEnd(), 1.0); + QTRY_COMPARE(listView->highlightRangeMode(), QDeclarativeListView::StrictlyEnforceRange); + QTRY_COMPARE(listView->isWrapEnabled(), false); + QTRY_COMPARE(listView->cacheBuffer(), 3); + QTRY_COMPARE(listView->snapMode(), QDeclarativeListView::SnapOneItem); + + QTRY_COMPARE(highlightFollowsCurrentItemSpy.count(),1); + QTRY_COMPARE(preferredHighlightBeginSpy.count(),1); + QTRY_COMPARE(preferredHighlightEndSpy.count(),1); + QTRY_COMPARE(highlightRangeModeSpy.count(),1); + QTRY_COMPARE(keyNavigationWrapsSpy.count(),1); + QTRY_COMPARE(cacheBufferSpy.count(),1); + QTRY_COMPARE(snapModeSpy.count(),1); listView->setHighlightFollowsCurrentItem(false); listView->setPreferredHighlightBegin(1.0); @@ -1386,13 +1339,13 @@ void tst_QDeclarativeListView::propertyChanges() listView->setCacheBuffer(3); listView->setSnapMode(QDeclarativeListView::SnapOneItem); - QCOMPARE(highlightFollowsCurrentItemSpy.count(),1); - QCOMPARE(preferredHighlightBeginSpy.count(),1); - QCOMPARE(preferredHighlightEndSpy.count(),1); - QCOMPARE(highlightRangeModeSpy.count(),1); - QCOMPARE(keyNavigationWrapsSpy.count(),1); - QCOMPARE(cacheBufferSpy.count(),1); - QCOMPARE(snapModeSpy.count(),1); + QTRY_COMPARE(highlightFollowsCurrentItemSpy.count(),1); + QTRY_COMPARE(preferredHighlightBeginSpy.count(),1); + QTRY_COMPARE(preferredHighlightEndSpy.count(),1); + QTRY_COMPARE(highlightRangeModeSpy.count(),1); + QTRY_COMPARE(keyNavigationWrapsSpy.count(),1); + QTRY_COMPARE(cacheBufferSpy.count(),1); + QTRY_COMPARE(snapModeSpy.count(),1); delete canvas; } @@ -1400,11 +1353,11 @@ void tst_QDeclarativeListView::propertyChanges() void tst_QDeclarativeListView::componentChanges() { QDeclarativeView *canvas = createView(); - QVERIFY(canvas); + QTRY_VERIFY(canvas); canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/propertychangestest.qml")); QDeclarativeListView *listView = canvas->rootObject()->findChild<QDeclarativeListView*>("listView"); - QVERIFY(listView); + QTRY_VERIFY(listView); QDeclarativeComponent component(canvas->engine()); component.setData("import Qt 4.6; Rectangle { color: \"blue\"; }", QUrl::fromLocalFile("")); @@ -1422,25 +1375,25 @@ void tst_QDeclarativeListView::componentChanges() listView->setFooter(&component); listView->setDelegate(&delegateComponent); - QCOMPARE(listView->highlight(), &component); - QCOMPARE(listView->header(), &component); - QCOMPARE(listView->footer(), &component); - QCOMPARE(listView->delegate(), &delegateComponent); + QTRY_COMPARE(listView->highlight(), &component); + QTRY_COMPARE(listView->header(), &component); + QTRY_COMPARE(listView->footer(), &component); + QTRY_COMPARE(listView->delegate(), &delegateComponent); - QCOMPARE(highlightSpy.count(),1); - QCOMPARE(delegateSpy.count(),1); - QCOMPARE(headerSpy.count(),1); - QCOMPARE(footerSpy.count(),1); + QTRY_COMPARE(highlightSpy.count(),1); + QTRY_COMPARE(delegateSpy.count(),1); + QTRY_COMPARE(headerSpy.count(),1); + QTRY_COMPARE(footerSpy.count(),1); listView->setHighlight(&component); listView->setHeader(&component); listView->setFooter(&component); listView->setDelegate(&delegateComponent); - QCOMPARE(highlightSpy.count(),1); - QCOMPARE(delegateSpy.count(),1); - QCOMPARE(headerSpy.count(),1); - QCOMPARE(footerSpy.count(),1); + QTRY_COMPARE(highlightSpy.count(),1); + QTRY_COMPARE(delegateSpy.count(),1); + QTRY_COMPARE(headerSpy.count(),1); + QTRY_COMPARE(footerSpy.count(),1); delete canvas; } @@ -1448,28 +1401,28 @@ void tst_QDeclarativeListView::componentChanges() void tst_QDeclarativeListView::modelChanges() { QDeclarativeView *canvas = createView(); - QVERIFY(canvas); + QTRY_VERIFY(canvas); canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/propertychangestest.qml")); QDeclarativeListView *listView = canvas->rootObject()->findChild<QDeclarativeListView*>("listView"); - QVERIFY(listView); + QTRY_VERIFY(listView); QDeclarativeListModel *alternateModel = canvas->rootObject()->findChild<QDeclarativeListModel*>("alternateModel"); - QVERIFY(alternateModel); + QTRY_VERIFY(alternateModel); QVariant modelVariant = QVariant::fromValue(alternateModel); QSignalSpy modelSpy(listView, SIGNAL(modelChanged())); listView->setModel(modelVariant); - QCOMPARE(listView->model(), modelVariant); - QCOMPARE(modelSpy.count(),1); + QTRY_COMPARE(listView->model(), modelVariant); + QTRY_COMPARE(modelSpy.count(),1); listView->setModel(modelVariant); - QCOMPARE(modelSpy.count(),1); + QTRY_COMPARE(modelSpy.count(),1); listView->setModel(QVariant()); - QCOMPARE(modelSpy.count(),2); + QTRY_COMPARE(modelSpy.count(),2); - delete canvas; + delete canvas; } void tst_QDeclarativeListView::qListModelInterface_items() |