diff options
Diffstat (limited to 'tests/auto/quick')
81 files changed, 5571 insertions, 1004 deletions
diff --git a/tests/auto/quick/geometry/tst_geometry.cpp b/tests/auto/quick/geometry/tst_geometry.cpp index 1cc9b112cc..bdd6f1a394 100644 --- a/tests/auto/quick/geometry/tst_geometry.cpp +++ b/tests/auto/quick/geometry/tst_geometry.cpp @@ -58,7 +58,7 @@ void GeometryTest::testPoint2D() QCOMPARE(geometry.sizeOfVertex(), (int) sizeof(float) * 2); QCOMPARE(geometry.vertexCount(), 4); QCOMPARE(geometry.indexCount(), 0); - QVERIFY(geometry.indexData() == 0); + QVERIFY(!geometry.indexData()); QSGGeometry::updateRectGeometry(&geometry, QRectF(1, 2, 3, 4)); @@ -91,7 +91,7 @@ void GeometryTest::testTexturedPoint2D() QCOMPARE(geometry.sizeOfVertex(), (int) sizeof(float) * 4); QCOMPARE(geometry.vertexCount(), 4); QCOMPARE(geometry.indexCount(), 0); - QVERIFY(geometry.indexData() == 0); + QVERIFY(!geometry.indexData()); QSGGeometry::updateTexturedRectGeometry(&geometry, QRectF(1, 2, 3, 4), QRectF(5, 6, 7, 8)); @@ -163,7 +163,7 @@ void GeometryTest::testCustomGeometry() for (int i=0; i<4000; ++i) QCOMPARE(ii[i], (quint16) i); for (int i=0; i<1000; ++i) - QVERIFY(v[i].v1 == 6); + QCOMPARE(v[i].v1, float(6)); } diff --git a/tests/auto/quick/nokeywords/tst_nokeywords.cpp b/tests/auto/quick/nokeywords/tst_nokeywords.cpp index 378af7ea90..58746447f0 100644 --- a/tests/auto/quick/nokeywords/tst_nokeywords.cpp +++ b/tests/auto/quick/nokeywords/tst_nokeywords.cpp @@ -67,7 +67,6 @@ #include <QtQuick/private/qsgrenderer_p.h> #include <QtQuick/private/qsgrenderloop_p.h> #include <QtQuick/private/qsgrendernode_p.h> -#include <QtQuick/private/qsgshareddistancefieldglyphcache_p.h> #include <QtQuick/private/qsgtexturematerial_p.h> #include <QtQuick/private/qsgtexture_p.h> #include <QtQuick/private/qsgthreadedrenderloop_p.h> diff --git a/tests/auto/quick/qquickanchors/tst_qquickanchors.cpp b/tests/auto/quick/qquickanchors/tst_qquickanchors.cpp index 6591d84504..597ea87feb 100644 --- a/tests/auto/quick/qquickanchors/tst_qquickanchors.cpp +++ b/tests/auto/quick/qquickanchors/tst_qquickanchors.cpp @@ -405,15 +405,15 @@ void tst_qquickanchors::resetConvenience() //fill itemPrivate->anchors()->setFill(baseItem); - QVERIFY(itemPrivate->anchors()->fill() == baseItem); + QCOMPARE(itemPrivate->anchors()->fill(), baseItem); itemPrivate->anchors()->resetFill(); - QVERIFY(itemPrivate->anchors()->fill() == 0); + QVERIFY(!itemPrivate->anchors()->fill()); //centerIn itemPrivate->anchors()->setCenterIn(baseItem); - QVERIFY(itemPrivate->anchors()->centerIn() == baseItem); + QCOMPARE(itemPrivate->anchors()->centerIn(), baseItem); itemPrivate->anchors()->resetCenterIn(); - QVERIFY(itemPrivate->anchors()->centerIn() == 0); + QVERIFY(!itemPrivate->anchors()->centerIn()); delete item; delete baseItem; diff --git a/tests/auto/quick/qquickanimatedimage/tst_qquickanimatedimage.cpp b/tests/auto/quick/qquickanimatedimage/tst_qquickanimatedimage.cpp index a0accfcd58..45694f38dd 100644 --- a/tests/auto/quick/qquickanimatedimage/tst_qquickanimatedimage.cpp +++ b/tests/auto/quick/qquickanimatedimage/tst_qquickanimatedimage.cpp @@ -335,48 +335,48 @@ void tst_qquickanimatedimage::sourceSizeChanges() // Local ctxt->setContextProperty("srcImage", QUrl("")); QTRY_COMPARE(anim->status(), QQuickAnimatedImage::Null); - QTRY_VERIFY(sourceSizeSpy.count() == 0); + QTRY_COMPARE(sourceSizeSpy.count(), 0); ctxt->setContextProperty("srcImage", testFileUrl("hearts.gif")); QTRY_COMPARE(anim->status(), QQuickAnimatedImage::Ready); - QTRY_VERIFY(sourceSizeSpy.count() == 1); + QTRY_COMPARE(sourceSizeSpy.count(), 1); ctxt->setContextProperty("srcImage", testFileUrl("hearts.gif")); QTRY_COMPARE(anim->status(), QQuickAnimatedImage::Ready); - QTRY_VERIFY(sourceSizeSpy.count() == 1); + QTRY_COMPARE(sourceSizeSpy.count(), 1); ctxt->setContextProperty("srcImage", testFileUrl("hearts_copy.gif")); QTRY_COMPARE(anim->status(), QQuickAnimatedImage::Ready); - QTRY_VERIFY(sourceSizeSpy.count() == 1); + QTRY_COMPARE(sourceSizeSpy.count(), 1); ctxt->setContextProperty("srcImage", testFileUrl("colors.gif")); QTRY_COMPARE(anim->status(), QQuickAnimatedImage::Ready); - QTRY_VERIFY(sourceSizeSpy.count() == 2); + QTRY_COMPARE(sourceSizeSpy.count(), 2); ctxt->setContextProperty("srcImage", QUrl("")); QTRY_COMPARE(anim->status(), QQuickAnimatedImage::Null); - QTRY_VERIFY(sourceSizeSpy.count() == 3); + QTRY_COMPARE(sourceSizeSpy.count(), 3); // Remote ctxt->setContextProperty("srcImage", server.url("/hearts.gif")); QTRY_COMPARE(anim->status(), QQuickAnimatedImage::Ready); - QTRY_VERIFY(sourceSizeSpy.count() == 4); + QTRY_COMPARE(sourceSizeSpy.count(), 4); ctxt->setContextProperty("srcImage", server.url("/hearts.gif")); QTRY_COMPARE(anim->status(), QQuickAnimatedImage::Ready); - QTRY_VERIFY(sourceSizeSpy.count() == 4); + QTRY_COMPARE(sourceSizeSpy.count(), 4); ctxt->setContextProperty("srcImage", server.url("/hearts_copy.gif")); QTRY_COMPARE(anim->status(), QQuickAnimatedImage::Ready); - QTRY_VERIFY(sourceSizeSpy.count() == 4); + QTRY_COMPARE(sourceSizeSpy.count(), 4); ctxt->setContextProperty("srcImage", server.url("/colors.gif")); QTRY_COMPARE(anim->status(), QQuickAnimatedImage::Ready); - QTRY_VERIFY(sourceSizeSpy.count() == 5); + QTRY_COMPARE(sourceSizeSpy.count(), 5); ctxt->setContextProperty("srcImage", QUrl("")); QTRY_COMPARE(anim->status(), QQuickAnimatedImage::Null); - QTRY_VERIFY(sourceSizeSpy.count() == 6); + QTRY_COMPARE(sourceSizeSpy.count(), 6); delete anim; } @@ -397,8 +397,8 @@ void tst_qquickanimatedimage::qtbug_16520() QVERIFY(anim != 0); anim->setProperty("source", server.urlString("/stickman.gif")); - QTRY_VERIFY(anim->opacity() == 0); - QTRY_VERIFY(anim->opacity() == 1); + QTRY_COMPARE(anim->opacity(), qreal(0)); + QTRY_COMPARE(anim->opacity(), qreal(1)); delete anim; delete root; @@ -418,8 +418,8 @@ void tst_qquickanimatedimage::progressAndStatusChanges() component.setData(componentStr.toLatin1(), QUrl::fromLocalFile("")); QQuickImage *obj = qobject_cast<QQuickImage*>(component.create()); QVERIFY(obj != 0); - QVERIFY(obj->status() == QQuickImage::Ready); - QTRY_VERIFY(obj->progress() == 1.0); + QCOMPARE(obj->status(), QQuickImage::Ready); + QTRY_COMPARE(obj->progress(), 1.0); qRegisterMetaType<QQuickImageBase::Status>(); QSignalSpy sourceSpy(obj, SIGNAL(sourceChanged(QUrl))); @@ -428,33 +428,33 @@ void tst_qquickanimatedimage::progressAndStatusChanges() // Same image ctxt->setContextProperty("srcImage", testFileUrl("stickman.gif")); - QTRY_VERIFY(obj->status() == QQuickImage::Ready); - QTRY_VERIFY(obj->progress() == 1.0); + QTRY_COMPARE(obj->status(), QQuickImage::Ready); + QTRY_COMPARE(obj->progress(), 1.0); QTRY_COMPARE(sourceSpy.count(), 0); QTRY_COMPARE(progressSpy.count(), 0); QTRY_COMPARE(statusSpy.count(), 0); // Loading local file ctxt->setContextProperty("srcImage", testFileUrl("colors.gif")); - QTRY_VERIFY(obj->status() == QQuickImage::Ready); - QTRY_VERIFY(obj->progress() == 1.0); + QTRY_COMPARE(obj->status(), QQuickImage::Ready); + QTRY_COMPARE(obj->progress(), 1.0); QTRY_COMPARE(sourceSpy.count(), 1); QTRY_COMPARE(progressSpy.count(), 0); QTRY_COMPARE(statusSpy.count(), 1); // Loading remote file ctxt->setContextProperty("srcImage", server.url("/stickman.gif")); - QTRY_VERIFY(obj->status() == QQuickImage::Loading); - QTRY_VERIFY(obj->progress() == 0.0); - QTRY_VERIFY(obj->status() == QQuickImage::Ready); - QTRY_VERIFY(obj->progress() == 1.0); + QTRY_COMPARE(obj->status(), QQuickImage::Loading); + QTRY_COMPARE(obj->progress(), 0.0); + QTRY_COMPARE(obj->status(), QQuickImage::Ready); + QTRY_COMPARE(obj->progress(), 1.0); QTRY_COMPARE(sourceSpy.count(), 2); QTRY_VERIFY(progressSpy.count() > 1); QTRY_COMPARE(statusSpy.count(), 3); ctxt->setContextProperty("srcImage", ""); - QTRY_VERIFY(obj->status() == QQuickImage::Null); - QTRY_VERIFY(obj->progress() == 0.0); + QTRY_COMPARE(obj->status(), QQuickImage::Null); + QTRY_COMPARE(obj->progress(), 0.0); QTRY_COMPARE(sourceSpy.count(), 3); QTRY_VERIFY(progressSpy.count() > 2); QTRY_COMPARE(statusSpy.count(), 4); @@ -472,7 +472,7 @@ void tst_qquickanimatedimage::playingAndPausedChanges() component.setData(componentStr.toLatin1(), QUrl::fromLocalFile("")); QQuickAnimatedImage *obj = qobject_cast<QQuickAnimatedImage*>(component.create()); QVERIFY(obj != 0); - QVERIFY(obj->status() == QQuickAnimatedImage::Null); + QCOMPARE(obj->status(), QQuickAnimatedImage::Null); QTRY_VERIFY(obj->isPlaying()); QTRY_VERIFY(!obj->isPaused()); QSignalSpy playingSpy(obj, SIGNAL(playingChanged())); diff --git a/tests/auto/quick/qquickanimations/tst_qquickanimations.cpp b/tests/auto/quick/qquickanimations/tst_qquickanimations.cpp index 45cfe4f334..2b805e9eeb 100644 --- a/tests/auto/quick/qquickanimations/tst_qquickanimations.cpp +++ b/tests/auto/quick/qquickanimations/tst_qquickanimations.cpp @@ -122,9 +122,9 @@ void tst_qquickanimations::simpleProperty() animation.setTargetObject(&rect); animation.setProperty("x"); animation.setTo(200); - QVERIFY(animation.target() == &rect); - QVERIFY(animation.property() == "x"); - QVERIFY(animation.to().toReal() == 200.0); + QCOMPARE(animation.target(), &rect); + QCOMPARE(animation.property(), QLatin1String("x")); + QCOMPARE(animation.to().toReal(), 200.0); animation.start(); QVERIFY(animation.isRunning()); QTest::qWait(animation.duration()); @@ -136,7 +136,7 @@ void tst_qquickanimations::simpleProperty() animation.pause(); QVERIFY(animation.isPaused()); animation.setCurrentTime(125); - QVERIFY(animation.currentTime() == 125); + QCOMPARE(animation.currentTime(), 125); QCOMPARE(rect.x(),100.0); } @@ -147,9 +147,9 @@ void tst_qquickanimations::simpleNumber() animation.setTargetObject(&rect); animation.setProperty("x"); animation.setTo(200); - QVERIFY(animation.target() == &rect); - QVERIFY(animation.property() == "x"); - QVERIFY(animation.to() == 200); + QCOMPARE(animation.target(), &rect); + QCOMPARE(animation.property(), QLatin1String("x")); + QCOMPARE(animation.to(), qreal(200)); animation.start(); QVERIFY(animation.isRunning()); QTest::qWait(animation.duration()); @@ -161,7 +161,7 @@ void tst_qquickanimations::simpleNumber() QVERIFY(animation.isRunning()); QVERIFY(animation.isPaused()); animation.setCurrentTime(125); - QVERIFY(animation.currentTime() == 125); + QCOMPARE(animation.currentTime(), 125); QCOMPARE(rect.x(), qreal(100)); } @@ -172,9 +172,9 @@ void tst_qquickanimations::simpleColor() animation.setTargetObject(&rect); animation.setProperty("color"); animation.setTo(QColor("red")); - QVERIFY(animation.target() == &rect); - QVERIFY(animation.property() == "color"); - QVERIFY(animation.to() == QColor("red")); + QCOMPARE(animation.target(), &rect); + QCOMPARE(animation.property(), QLatin1String("color")); + QCOMPARE(animation.to(), QColor("red")); animation.start(); QVERIFY(animation.isRunning()); QTest::qWait(animation.duration()); @@ -186,12 +186,12 @@ void tst_qquickanimations::simpleColor() QVERIFY(animation.isRunning()); QVERIFY(animation.isPaused()); animation.setCurrentTime(125); - QVERIFY(animation.currentTime() == 125); + QCOMPARE(animation.currentTime(), 125); QCOMPARE(rect.color(), QColor::fromRgbF(0.498039, 0, 0.498039, 1)); rect.setColor(QColor("green")); animation.setFrom(QColor("blue")); - QVERIFY(animation.from() == QColor("blue")); + QCOMPARE(animation.from(), QColor("blue")); animation.restart(); QCOMPARE(rect.color(), QColor("blue")); QVERIFY(animation.isRunning()); @@ -206,10 +206,10 @@ void tst_qquickanimations::simpleRotation() animation.setTargetObject(&rect); animation.setProperty("rotation"); animation.setTo(270); - QVERIFY(animation.target() == &rect); - QVERIFY(animation.property() == "rotation"); - QVERIFY(animation.to() == 270); - QVERIFY(animation.direction() == QQuickRotationAnimation::Numerical); + QCOMPARE(animation.target(), &rect); + QCOMPARE(animation.property(), QLatin1String("rotation")); + QCOMPARE(animation.to(), qreal(270)); + QCOMPARE(animation.direction(), QQuickRotationAnimation::Numerical); animation.start(); QVERIFY(animation.isRunning()); QTest::qWait(animation.duration()); @@ -221,7 +221,7 @@ void tst_qquickanimations::simpleRotation() QVERIFY(animation.isRunning()); QVERIFY(animation.isPaused()); animation.setCurrentTime(125); - QVERIFY(animation.currentTime() == 125); + QCOMPARE(animation.currentTime(), 125); QCOMPARE(rect.rotation(), qreal(135)); } @@ -567,8 +567,8 @@ void tst_qquickanimations::alwaysRunToEnd() animation.setDuration(1000); animation.setLoops(-1); animation.setAlwaysRunToEnd(true); - QVERIFY(animation.loops() == -1); - QVERIFY(animation.alwaysRunToEnd() == true); + QCOMPARE(animation.loops(), -1); + QVERIFY(animation.alwaysRunToEnd()); QElapsedTimer timer; timer.start(); @@ -600,7 +600,7 @@ void tst_qquickanimations::complete() animation.setFrom(1); animation.setTo(200); animation.setDuration(500); - QVERIFY(animation.from() == 1); + QCOMPARE(animation.from().toInt(), 1); animation.start(); QTest::qWait(50); animation.stop(); @@ -620,7 +620,7 @@ void tst_qquickanimations::resume() animation.setFrom(10); animation.setTo(200); animation.setDuration(1000); - QVERIFY(animation.from() == 10); + QCOMPARE(animation.from().toInt(), 10); animation.start(); QTest::qWait(400); @@ -685,7 +685,7 @@ void tst_qquickanimations::dotProperty() animation.start(); animation.pause(); animation.setCurrentTime(125); - QVERIFY(animation.currentTime() == 125); + QCOMPARE(animation.currentTime(), 125); QCOMPARE(rect.border()->width(), 5.0); } @@ -708,7 +708,7 @@ void tst_qquickanimations::badTypes() QTest::ignoreMessage(QtWarningMsg, "QQmlComponent: Component is not ready"); c.create(); - QVERIFY(c.errors().count() == 1); + QCOMPARE(c.errors().count(), 1); QCOMPARE(c.errors().at(0).description(), QLatin1String("Invalid property assignment: number expected")); } @@ -719,7 +719,7 @@ void tst_qquickanimations::badTypes() QTest::ignoreMessage(QtWarningMsg, "QQmlComponent: Component is not ready"); c.create(); - QVERIFY(c.errors().count() == 1); + QCOMPARE(c.errors().count(), 1); QCOMPARE(c.errors().at(0).description(), QLatin1String("Invalid property assignment: color expected")); } @@ -1065,7 +1065,7 @@ void tst_qquickanimations::propertyValueSourceDefaultStart() QQuickAbstractAnimation *myAnim = rect->findChild<QQuickAbstractAnimation*>("MyAnim"); QVERIFY(myAnim); - QVERIFY(myAnim->isRunning() == false); + QVERIFY(!myAnim->isRunning()); } { @@ -1078,7 +1078,7 @@ void tst_qquickanimations::propertyValueSourceDefaultStart() QQuickAbstractAnimation *myAnim = rect->findChild<QQuickAbstractAnimation*>("MyAnim"); QVERIFY(myAnim && !myAnim->qtAnimation()); - //QVERIFY(myAnim->qtAnimation()->state() == QAbstractAnimationJob::Stopped); + //QCOMPARE(myAnim->qtAnimation()->state(), QAbstractAnimationJob::Stopped); } } @@ -1097,7 +1097,7 @@ void tst_qquickanimations::dontStart() QQuickAbstractAnimation *myAnim = rect->findChild<QQuickAbstractAnimation*>("MyAnim"); QVERIFY(myAnim && !myAnim->qtAnimation()); - //QVERIFY(myAnim->qtAnimation()->state() == QAbstractAnimationJob::Stopped); + //QCOMPARE(myAnim->qtAnimation()->state(), QAbstractAnimationJob::Stopped); } { @@ -1112,7 +1112,7 @@ void tst_qquickanimations::dontStart() QQuickAbstractAnimation *myAnim = rect->findChild<QQuickAbstractAnimation*>("MyAnim"); QVERIFY(myAnim && !myAnim->qtAnimation()); - //QVERIFY(myAnim->qtAnimation()->state() == QAbstractAnimationJob::Stopped); + //QCOMPARE(myAnim->qtAnimation()->state(), QAbstractAnimationJob::Stopped); } } @@ -1350,8 +1350,8 @@ void tst_qquickanimations::alwaysRunToEndRestartBug() animation.setDuration(1000); animation.setLoops(-1); animation.setAlwaysRunToEnd(true); - QVERIFY(animation.loops() == -1); - QVERIFY(animation.alwaysRunToEnd() == true); + QCOMPARE(animation.loops(), -1); + QVERIFY(animation.alwaysRunToEnd()); animation.start(); animation.stop(); animation.start(); @@ -1387,7 +1387,7 @@ void tst_qquickanimations::pauseBindingBug() QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create()); QVERIFY(rect != 0); QQuickAbstractAnimation *anim = rect->findChild<QQuickAbstractAnimation*>("animation"); - QVERIFY(anim->qtAnimation()->state() == QAbstractAnimationJob::Paused); + QCOMPARE(anim->qtAnimation()->state(), QAbstractAnimationJob::Paused); delete rect; } diff --git a/tests/auto/quick/qquickapplication/tst_qquickapplication.cpp b/tests/auto/quick/qquickapplication/tst_qquickapplication.cpp index 7df020405f..1d8fc430b8 100644 --- a/tests/auto/quick/qquickapplication/tst_qquickapplication.cpp +++ b/tests/auto/quick/qquickapplication/tst_qquickapplication.cpp @@ -97,7 +97,7 @@ void tst_qquickapplication::active() window.show(); window.requestActivate(); QTest::qWaitForWindowActive(&window); - QVERIFY(QGuiApplication::focusWindow() == &window); + QCOMPARE(QGuiApplication::focusWindow(), &window); QVERIFY(item->property("active").toBool()); QVERIFY(item->property("active2").toBool()); @@ -167,7 +167,7 @@ void tst_qquickapplication::state() window.show(); window.requestActivate(); QTest::qWaitForWindowActive(&window); - QVERIFY(QGuiApplication::focusWindow() == &window); + QCOMPARE(QGuiApplication::focusWindow(), &window); QCOMPARE(Qt::ApplicationState(item->property("state").toInt()), Qt::ApplicationActive); QCOMPARE(Qt::ApplicationState(item->property("state2").toInt()), Qt::ApplicationActive); diff --git a/tests/auto/quick/qquickbehaviors/BLACKLIST b/tests/auto/quick/qquickbehaviors/BLACKLIST new file mode 100644 index 0000000000..9be4da176d --- /dev/null +++ b/tests/auto/quick/qquickbehaviors/BLACKLIST @@ -0,0 +1,2 @@ +[currentValue] +windows diff --git a/tests/auto/quick/qquickbehaviors/tst_qquickbehaviors.cpp b/tests/auto/quick/qquickbehaviors/tst_qquickbehaviors.cpp index b96f1de930..643bed4376 100644 --- a/tests/auto/quick/qquickbehaviors/tst_qquickbehaviors.cpp +++ b/tests/auto/quick/qquickbehaviors/tst_qquickbehaviors.cpp @@ -82,39 +82,35 @@ void tst_qquickbehaviors::simpleBehavior() { QQmlEngine engine; QQmlComponent c(&engine, testFileUrl("simple.qml")); - QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create()); - QTRY_VERIFY(rect); + QScopedPointer<QQuickRectangle> rect(qobject_cast<QQuickRectangle*>(c.create()));; + QVERIFY2(!rect.isNull(), qPrintable(c.errorString())); QTRY_VERIFY(qobject_cast<QQuickBehavior*>(rect->findChild<QQuickBehavior*>("MyBehavior"))->animation()); - QQuickItemPrivate::get(rect)->setState("moved"); + QQuickItemPrivate::get(rect.data())->setState("moved"); QTRY_VERIFY(qobject_cast<QQuickRectangle*>(rect->findChild<QQuickRectangle*>("MyRect"))->x() > 0); QTRY_VERIFY(qobject_cast<QQuickRectangle*>(rect->findChild<QQuickRectangle*>("MyRect"))->x() < 200); //i.e. the behavior has been triggered - - delete rect; } void tst_qquickbehaviors::scriptTriggered() { QQmlEngine engine; QQmlComponent c(&engine, testFileUrl("scripttrigger.qml")); - QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create()); - QTRY_VERIFY(rect); + QScopedPointer<QQuickRectangle> rect(qobject_cast<QQuickRectangle*>(c.create()));; + QVERIFY2(!rect.isNull(), qPrintable(c.errorString())); rect->setColor(QColor("red")); QTRY_VERIFY(qobject_cast<QQuickRectangle*>(rect->findChild<QQuickRectangle*>("MyRect"))->x() > 0); QTRY_VERIFY(qobject_cast<QQuickRectangle*>(rect->findChild<QQuickRectangle*>("MyRect"))->x() < 200); //i.e. the behavior has been triggered - - delete rect; } void tst_qquickbehaviors::cppTriggered() { QQmlEngine engine; QQmlComponent c(&engine, testFileUrl("cpptrigger.qml")); - QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create()); - QTRY_VERIFY(rect); + QScopedPointer<QQuickRectangle> rect(qobject_cast<QQuickRectangle*>(c.create()));; + QVERIFY2(!rect.isNull(), qPrintable(c.errorString())); QQuickRectangle *innerRect = qobject_cast<QQuickRectangle*>(rect->findChild<QQuickRectangle*>("MyRect")); QTRY_VERIFY(innerRect); @@ -122,60 +118,52 @@ void tst_qquickbehaviors::cppTriggered() innerRect->setProperty("x", 200); QTRY_VERIFY(innerRect->x() > 0); QTRY_VERIFY(innerRect->x() < 200); //i.e. the behavior has been triggered - - delete rect; } void tst_qquickbehaviors::loop() { QQmlEngine engine; QQmlComponent c(&engine, testFileUrl("loop.qml")); - QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create()); - QTRY_VERIFY(rect); + QScopedPointer<QQuickRectangle> rect(qobject_cast<QQuickRectangle*>(c.create()));; + QVERIFY2(!rect.isNull(), qPrintable(c.errorString())); //don't crash - QQuickItemPrivate::get(rect)->setState("moved"); - - delete rect; + QQuickItemPrivate::get(rect.data())->setState("moved"); } void tst_qquickbehaviors::colorBehavior() { QQmlEngine engine; QQmlComponent c(&engine, testFileUrl("color.qml")); - QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create()); - QTRY_VERIFY(rect); + QScopedPointer<QQuickRectangle> rect(qobject_cast<QQuickRectangle*>(c.create()));; + QVERIFY2(!rect.isNull(), qPrintable(c.errorString())); - QQuickItemPrivate::get(rect)->setState("red"); + QQuickItemPrivate::get(rect.data())->setState("red"); QTRY_VERIFY(qobject_cast<QQuickRectangle*>(rect->findChild<QQuickRectangle*>("MyRect"))->color() != QColor("red")); QTRY_VERIFY(qobject_cast<QQuickRectangle*>(rect->findChild<QQuickRectangle*>("MyRect"))->color() != QColor("green")); //i.e. the behavior has been triggered - - delete rect; } void tst_qquickbehaviors::parentBehavior() { QQmlEngine engine; QQmlComponent c(&engine, testFileUrl("parent.qml")); - QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create()); - QTRY_VERIFY(rect); + QScopedPointer<QQuickRectangle> rect(qobject_cast<QQuickRectangle*>(c.create()));; + QVERIFY2(!rect.isNull(), qPrintable(c.errorString())); - QQuickItemPrivate::get(rect)->setState("reparented"); + QQuickItemPrivate::get(rect.data())->setState("reparented"); QTRY_VERIFY(rect->findChild<QQuickRectangle*>("MyRect")->parentItem() != rect->findChild<QQuickItem*>("NewParent")); QTRY_VERIFY(rect->findChild<QQuickRectangle*>("MyRect")->parentItem() == rect->findChild<QQuickItem*>("NewParent")); - - delete rect; } void tst_qquickbehaviors::replaceBinding() { QQmlEngine engine; QQmlComponent c(&engine, testFileUrl("binding.qml")); - QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create()); - QTRY_VERIFY(rect); + QScopedPointer<QQuickRectangle> rect(qobject_cast<QQuickRectangle*>(c.create()));; + QVERIFY2(!rect.isNull(), qPrintable(c.errorString())); - QQuickItemPrivate::get(rect)->setState("moved"); + QQuickItemPrivate::get(rect.data())->setState("moved"); QQuickRectangle *innerRect = qobject_cast<QQuickRectangle*>(rect->findChild<QQuickRectangle*>("MyRect")); QTRY_VERIFY(innerRect); QTRY_VERIFY(innerRect->x() > 0); @@ -187,7 +175,7 @@ void tst_qquickbehaviors::replaceBinding() rect->setProperty("movedx", 210); QTRY_COMPARE(innerRect->x(), (qreal)210); - QQuickItemPrivate::get(rect)->setState(""); + QQuickItemPrivate::get(rect.data())->setState(""); QTRY_VERIFY(innerRect->x() > 10); QTRY_VERIFY(innerRect->x() < 210); //i.e. the behavior has been triggered QTRY_COMPARE(innerRect->x(), (qreal)10); @@ -195,8 +183,6 @@ void tst_qquickbehaviors::replaceBinding() QTRY_COMPARE(innerRect->x(), (qreal)10); rect->setProperty("basex", 20); QTRY_COMPARE(innerRect->x(), (qreal)20); - - delete rect; } void tst_qquickbehaviors::group() @@ -205,32 +191,27 @@ void tst_qquickbehaviors::group() { QQmlEngine engine; QQmlComponent c(&engine, testFileUrl("groupProperty.qml"))); - QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create()); - qDebug() << c.errorString(); - QTRY_VERIFY(rect); + QScopedPointer<QQuickRectangle> rect(qobject_cast<QQuickRectangle*>(c.create()));; + QVERIFY2(!rect.isNull(), qPrintable(c.errorString())); - QQuickItemPrivate::get(rect)->setState("moved"); + QQuickItemPrivate::get(rect.data())->setState("moved"); //QTest::qWait(200); QTRY_VERIFY(qobject_cast<QQuickRectangle*>(rect->findChild<QQuickRectangle*>("MyRect"))->x() > 0); QTRY_VERIFY(qobject_cast<QQuickRectangle*>(rect->findChild<QQuickRectangle*>("MyRect"))->x() < 200); //i.e. the behavior has been triggered - - delete rect; } */ { QQmlEngine engine; QQmlComponent c(&engine, testFileUrl("groupProperty2.qml")); - QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create()); - QTRY_VERIFY(rect); + QScopedPointer<QQuickRectangle> rect(qobject_cast<QQuickRectangle*>(c.create()));; + QVERIFY2(!rect.isNull(), qPrintable(c.errorString())); - QQuickItemPrivate::get(rect)->setState("moved"); + QQuickItemPrivate::get(rect.data())->setState("moved"); QTRY_VERIFY(qobject_cast<QQuickRectangle*>(rect->findChild<QQuickRectangle*>("MyRect"))->border()->width() > 0); QTRY_VERIFY(qobject_cast<QQuickRectangle*>(rect->findChild<QQuickRectangle*>("MyRect"))->border()->width() < 4); //i.e. the behavior has been triggered - - delete rect; } } @@ -238,56 +219,48 @@ void tst_qquickbehaviors::valueType() { QQmlEngine engine; QQmlComponent c(&engine, testFileUrl("valueType.qml")); - QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create()); - QVERIFY(rect); + QScopedPointer<QQuickRectangle> rect(qobject_cast<QQuickRectangle*>(c.create()));; + QVERIFY2(!rect.isNull(), qPrintable(c.errorString())); //QTBUG-20827 QCOMPARE(rect->color(), QColor::fromRgb(255,0,255)); - - delete rect; } void tst_qquickbehaviors::emptyBehavior() { QQmlEngine engine; QQmlComponent c(&engine, testFileUrl("empty.qml")); - QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create()); - QVERIFY(rect); + QScopedPointer<QQuickRectangle> rect(qobject_cast<QQuickRectangle*>(c.create()));; + QVERIFY2(!rect.isNull(), qPrintable(c.errorString())); - QQuickItemPrivate::get(rect)->setState("moved"); + QQuickItemPrivate::get(rect.data())->setState("moved"); qreal x = qobject_cast<QQuickRectangle*>(rect->findChild<QQuickRectangle*>("MyRect"))->x(); QCOMPARE(x, qreal(200)); //should change immediately - - delete rect; } void tst_qquickbehaviors::explicitSelection() { QQmlEngine engine; QQmlComponent c(&engine, testFileUrl("explicit.qml")); - QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create()); - QVERIFY(rect); + QScopedPointer<QQuickRectangle> rect(qobject_cast<QQuickRectangle*>(c.create()));; + QVERIFY2(!rect.isNull(), qPrintable(c.errorString())); - QQuickItemPrivate::get(rect)->setState("moved"); + QQuickItemPrivate::get(rect.data())->setState("moved"); QTRY_VERIFY(qobject_cast<QQuickRectangle*>(rect->findChild<QQuickRectangle*>("MyRect"))->x() > 0); QTRY_VERIFY(qobject_cast<QQuickRectangle*>(rect->findChild<QQuickRectangle*>("MyRect"))->x() < 200); //i.e. the behavior has been triggered - - delete rect; } void tst_qquickbehaviors::nonSelectingBehavior() { QQmlEngine engine; QQmlComponent c(&engine, testFileUrl("nonSelecting2.qml")); - QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create()); - QVERIFY(rect); + QScopedPointer<QQuickRectangle> rect(qobject_cast<QQuickRectangle*>(c.create()));; + QVERIFY2(!rect.isNull(), qPrintable(c.errorString())); - QQuickItemPrivate::get(rect)->setState("moved"); + QQuickItemPrivate::get(rect.data())->setState("moved"); qreal x = qobject_cast<QQuickRectangle*>(rect->findChild<QQuickRectangle*>("MyRect"))->x(); QCOMPARE(x, qreal(200)); //should change immediately - - delete rect; } void tst_qquickbehaviors::reassignedAnimation() @@ -296,27 +269,23 @@ void tst_qquickbehaviors::reassignedAnimation() QQmlComponent c(&engine, testFileUrl("reassignedAnimation.qml")); QString warning = testFileUrl("reassignedAnimation.qml").toString() + ":9:9: QML Behavior: Cannot change the animation assigned to a Behavior."; QTest::ignoreMessage(QtWarningMsg, qPrintable(warning)); - QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create()); - QVERIFY(rect); + QScopedPointer<QQuickRectangle> rect(qobject_cast<QQuickRectangle*>(c.create()));; + QVERIFY2(!rect.isNull(), qPrintable(c.errorString())); QCOMPARE(qobject_cast<QQuickNumberAnimation*>( rect->findChild<QQuickBehavior*>("MyBehavior")->animation())->duration(), 200); - - delete rect; } void tst_qquickbehaviors::disabled() { QQmlEngine engine; QQmlComponent c(&engine, testFileUrl("disabled.qml")); - QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create()); - QVERIFY(rect); + QScopedPointer<QQuickRectangle> rect(qobject_cast<QQuickRectangle*>(c.create()));; + QVERIFY2(!rect.isNull(), qPrintable(c.errorString())); QCOMPARE(rect->findChild<QQuickBehavior*>("MyBehavior")->enabled(), false); - QQuickItemPrivate::get(rect)->setState("moved"); + QQuickItemPrivate::get(rect.data())->setState("moved"); qreal x = qobject_cast<QQuickRectangle*>(rect->findChild<QQuickRectangle*>("MyRect"))->x(); QCOMPARE(x, qreal(200)); //should change immediately - - delete rect; } void tst_qquickbehaviors::dontStart() @@ -327,13 +296,12 @@ void tst_qquickbehaviors::dontStart() QString warning = c.url().toString() + ":13:13: QML NumberAnimation: setRunning() cannot be used on non-root animation nodes."; QTest::ignoreMessage(QtWarningMsg, qPrintable(warning)); - QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create()); - QVERIFY(rect); + QScopedPointer<QQuickRectangle> rect(qobject_cast<QQuickRectangle*>(c.create()));; + QVERIFY2(!rect.isNull(), qPrintable(c.errorString())); QQuickAbstractAnimation *myAnim = rect->findChild<QQuickAbstractAnimation*>("MyAnim"); - QVERIFY(myAnim && !myAnim->qtAnimation()); - - delete rect; + QVERIFY(myAnim); + QVERIFY(!myAnim->qtAnimation()); } void tst_qquickbehaviors::startup() @@ -341,22 +309,20 @@ void tst_qquickbehaviors::startup() { QQmlEngine engine; QQmlComponent c(&engine, testFileUrl("startup.qml")); - QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create()); - QVERIFY(rect); + QScopedPointer<QQuickRectangle> rect(qobject_cast<QQuickRectangle*>(c.create()));; + QVERIFY2(!rect.isNull(), qPrintable(c.errorString())); QQuickRectangle *innerRect = rect->findChild<QQuickRectangle*>("innerRect"); QVERIFY(innerRect); QCOMPARE(innerRect->x(), qreal(100)); //should be set immediately - - delete rect; } { QQmlEngine engine; QQmlComponent c(&engine, testFileUrl("startup2.qml")); - QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create()); - QVERIFY(rect); + QScopedPointer<QQuickRectangle> rect(qobject_cast<QQuickRectangle*>(c.create()));; + QVERIFY2(!rect.isNull(), qPrintable(c.errorString())); QQuickRectangle *innerRect = rect->findChild<QQuickRectangle*>("innerRect"); QVERIFY(innerRect); @@ -365,8 +331,6 @@ void tst_qquickbehaviors::startup() QVERIFY(text); QCOMPARE(innerRect->x(), text->width()); //should be set immediately - - delete rect; } } @@ -375,10 +339,8 @@ void tst_qquickbehaviors::groupedPropertyCrash() { QQmlEngine engine; QQmlComponent c(&engine, testFileUrl("groupedPropertyCrash.qml")); - QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create()); - QVERIFY(rect); //don't crash - - delete rect; + QScopedPointer<QQuickRectangle> rect(qobject_cast<QQuickRectangle*>(c.create()));; + QVERIFY2(!rect.isNull(), qPrintable(c.errorString())); //don't crash } //QTBUG-5491 @@ -386,8 +348,8 @@ void tst_qquickbehaviors::runningTrue() { QQmlEngine engine; QQmlComponent c(&engine, testFileUrl("runningTrue.qml")); - QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create()); - QVERIFY(rect); + QScopedPointer<QQuickRectangle> rect(qobject_cast<QQuickRectangle*>(c.create()));; + QVERIFY2(!rect.isNull(), qPrintable(c.errorString())); QQuickAbstractAnimation *animation = rect->findChild<QQuickAbstractAnimation*>("rotAnim"); QVERIFY(animation); @@ -395,8 +357,6 @@ void tst_qquickbehaviors::runningTrue() QSignalSpy runningSpy(animation, SIGNAL(runningChanged(bool))); rect->setProperty("myValue", 180); QTRY_VERIFY(runningSpy.count() > 0); - - delete rect; } //QTBUG-12295 @@ -404,8 +364,8 @@ void tst_qquickbehaviors::sameValue() { QQmlEngine engine; QQmlComponent c(&engine, testFileUrl("qtbug12295.qml")); - QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create()); - QVERIFY(rect); + QScopedPointer<QQuickRectangle> rect(qobject_cast<QQuickRectangle*>(c.create()));; + QVERIFY2(!rect.isNull(), qPrintable(c.errorString())); QQuickRectangle *target = rect->findChild<QQuickRectangle*>("myRect"); QVERIFY(target); @@ -424,8 +384,6 @@ void tst_qquickbehaviors::sameValue() //even though we set 0 twice in a row. target->setProperty("x", 0); QTRY_VERIFY(target->x() != qreal(0) && target->x() != qreal(100)); - - delete rect; } //QTBUG-18362 @@ -434,8 +392,8 @@ void tst_qquickbehaviors::delayedRegistration() QQmlEngine engine; QQmlComponent c(&engine, testFileUrl("delayedRegistration.qml")); - QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create()); - QVERIFY(rect != 0); + QScopedPointer<QQuickRectangle> rect(qobject_cast<QQuickRectangle*>(c.create()));; + QVERIFY2(!rect.isNull(), qPrintable(c.errorString())); QQuickItem *innerRect = rect->property("myItem").value<QQuickItem*>(); QVERIFY(innerRect != 0); @@ -451,8 +409,8 @@ void tst_qquickbehaviors::startOnCompleted() QQmlEngine engine; QQmlComponent c(&engine, testFileUrl("startOnCompleted.qml")); - QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create()); - QVERIFY(rect != 0); + QScopedPointer<QQuickRectangle> rect(qobject_cast<QQuickRectangle*>(c.create()));; + QVERIFY2(!rect.isNull(), qPrintable(c.errorString())); QQuickItem *innerRect = rect->findChild<QQuickRectangle*>(); QVERIFY(innerRect != 0); @@ -460,8 +418,6 @@ void tst_qquickbehaviors::startOnCompleted() QCOMPARE(innerRect->property("x").toInt(), int(0)); QTRY_COMPARE(innerRect->property("x").toInt(), int(100)); - - delete rect; } //QTBUG-25139 @@ -471,7 +427,7 @@ void tst_qquickbehaviors::multipleChangesToValueType() QQmlComponent c(&engine, testFileUrl("multipleChangesToValueType.qml")); QScopedPointer<QQuickRectangle> rect(qobject_cast<QQuickRectangle *>(c.create())); - QVERIFY(rect != 0); + QVERIFY2(!rect.isNull(), qPrintable(c.errorString())); QQuickText *text = rect->findChild<QQuickText *>(); QVERIFY(text != 0); @@ -496,8 +452,8 @@ void tst_qquickbehaviors::currentValue() { QQmlEngine engine; QQmlComponent c(&engine, testFileUrl("qtbug21549.qml")); - QQuickItem *item = qobject_cast<QQuickItem*>(c.create()); - QVERIFY(item); + QScopedPointer<QQuickItem> item(qobject_cast<QQuickItem*>(c.create())); + QVERIFY2(!item.isNull(), qPrintable(c.errorString())); QQuickRectangle *target = item->findChild<QQuickRectangle*>("myRect"); QVERIFY(target); @@ -516,15 +472,13 @@ void tst_qquickbehaviors::currentValue() target->setProperty("x", 100); QCOMPARE(item->property("behaviorCount").toInt(), 1); QCOMPARE(target->x(), qreal(100)); - - delete item; } { QQmlEngine engine; QQmlComponent c(&engine, testFileUrl("qtbug21549-2.qml")); - QQuickItem *item = qobject_cast<QQuickItem*>(c.create()); - QVERIFY(item); + QScopedPointer<QQuickItem> item(qobject_cast<QQuickItem*>(c.create())); + QVERIFY2(!item.isNull(), qPrintable(c.errorString())); QQuickRectangle *target = item->findChild<QQuickRectangle*>("myRect"); QVERIFY(target); @@ -537,9 +491,7 @@ void tst_qquickbehaviors::currentValue() // in the QML (which should be between 50 and 80); QTRY_COMPARE(item->property("animRunning").toBool(), true); QTRY_COMPARE(item->property("animRunning").toBool(), false); - QVERIFY(target->x() > qreal(50) && target->x() < qreal(80)); - - delete item; + QVERIFY2(target->x() > qreal(50) && target->x() < qreal(80), QByteArray::number(target->x())); } } @@ -548,8 +500,8 @@ void tst_qquickbehaviors::disabledWriteWhileRunning() { QQmlEngine engine; QQmlComponent c(&engine, testFileUrl("disabledWriteWhileRunning.qml")); - QQuickItem *root = qobject_cast<QQuickItem*>(c.create()); - QVERIFY(root); + QScopedPointer<QQuickItem> root(qobject_cast<QQuickItem*>(c.create())); + QVERIFY2(!root.isNull(), qPrintable(c.errorString())); QQuickRectangle *myRect = qobject_cast<QQuickRectangle*>(root->findChild<QQuickRectangle*>("MyRect")); QQuickBehavior *myBehavior = qobject_cast<QQuickBehavior*>(root->findChild<QQuickBehavior*>("MyBehavior")); @@ -579,16 +531,14 @@ void tst_qquickbehaviors::disabledWriteWhileRunning() QCOMPARE(myRect->x(), qreal(100)); QTest::qWait(200); QCOMPARE(myRect->x(), qreal(100)); - - delete root; } //test additional complications with SmoothedAnimation { QQmlEngine engine; QQmlComponent c(&engine, testFileUrl("disabledWriteWhileRunning2.qml")); - QQuickItem *root = qobject_cast<QQuickItem*>(c.create()); - QVERIFY(root); + QScopedPointer<QQuickItem> root(qobject_cast<QQuickItem*>(c.create())); + QVERIFY2(!root.isNull(), qPrintable(c.errorString())); QQuickRectangle *myRect = qobject_cast<QQuickRectangle*>(root->findChild<QQuickRectangle*>("MyRect")); QQuickBehavior *myBehavior = qobject_cast<QQuickBehavior*>(root->findChild<QQuickBehavior*>("MyBehavior")); @@ -623,8 +573,6 @@ void tst_qquickbehaviors::disabledWriteWhileRunning() QCOMPARE(myRect->x(), qreal(100)); QTest::qWait(200); QCOMPARE(myRect->x(), qreal(100)); - - delete root; } } diff --git a/tests/auto/quick/qquickborderimage/tst_qquickborderimage.cpp b/tests/auto/quick/qquickborderimage/tst_qquickborderimage.cpp index efe2ca8b18..071ea0b494 100644 --- a/tests/auto/quick/qquickborderimage/tst_qquickborderimage.cpp +++ b/tests/auto/quick/qquickborderimage/tst_qquickborderimage.cpp @@ -132,6 +132,13 @@ void tst_qquickborderimage::imageSource() QFETCH(bool, remote); QFETCH(QString, error); +#if defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID) + if (qstrcmp(QTest::currentDataTag(), "remote") == 0 + || qstrcmp(QTest::currentDataTag(), "remote not found") == 0) { + QSKIP("Remote tests cause occasional hangs in the CI system -- QTBUG-45655"); + } +#endif + TestHTTPServer server; if (remote) { QVERIFY2(server.listen(), qPrintable(server.errorString())); @@ -150,12 +157,12 @@ void tst_qquickborderimage::imageSource() QVERIFY(obj != 0); if (remote) - QTRY_VERIFY(obj->status() == QQuickBorderImage::Loading); + QTRY_COMPARE(obj->status(), QQuickBorderImage::Loading); QCOMPARE(obj->source(), remote ? source : QUrl(source)); if (error.isEmpty()) { - QTRY_VERIFY(obj->status() == QQuickBorderImage::Ready); + QTRY_COMPARE(obj->status(), QQuickBorderImage::Ready); QCOMPARE(obj->width(), 120.); QCOMPARE(obj->height(), 120.); QCOMPARE(obj->sourceSize().width(), 120); @@ -163,7 +170,7 @@ void tst_qquickborderimage::imageSource() QCOMPARE(obj->horizontalTileMode(), QQuickBorderImage::Stretch); QCOMPARE(obj->verticalTileMode(), QQuickBorderImage::Stretch); } else { - QTRY_VERIFY(obj->status() == QQuickBorderImage::Error); + QTRY_COMPARE(obj->status(), QQuickBorderImage::Error); } delete obj; @@ -178,13 +185,13 @@ void tst_qquickborderimage::clearSource() component.setData(componentStr.toLatin1(), QUrl::fromLocalFile("")); QQuickBorderImage *obj = qobject_cast<QQuickBorderImage*>(component.create()); QVERIFY(obj != 0); - QVERIFY(obj->status() == QQuickBorderImage::Ready); + QCOMPARE(obj->status(), QQuickBorderImage::Ready); QCOMPARE(obj->width(), 120.); QCOMPARE(obj->height(), 120.); ctxt->setContextProperty("srcImage", ""); QVERIFY(obj->source().isEmpty()); - QVERIFY(obj->status() == QQuickBorderImage::Null); + QCOMPARE(obj->status(), QQuickBorderImage::Null); QCOMPARE(obj->width(), 0.); QCOMPARE(obj->height(), 0.); @@ -296,14 +303,14 @@ void tst_qquickborderimage::sciSource() QVERIFY(obj != 0); if (remote) - QTRY_VERIFY(obj->status() == QQuickBorderImage::Loading); + QTRY_COMPARE(obj->status(), QQuickBorderImage::Loading); QCOMPARE(obj->source(), remote ? source : QUrl(source)); QCOMPARE(obj->width(), 300.); QCOMPARE(obj->height(), 300.); if (valid) { - QTRY_VERIFY(obj->status() == QQuickBorderImage::Ready); + QTRY_COMPARE(obj->status(), QQuickBorderImage::Ready); QCOMPARE(obj->border()->left(), 10); QCOMPARE(obj->border()->top(), 20); QCOMPARE(obj->border()->right(), 30); @@ -311,7 +318,7 @@ void tst_qquickborderimage::sciSource() QCOMPARE(obj->horizontalTileMode(), QQuickBorderImage::Round); QCOMPARE(obj->verticalTileMode(), QQuickBorderImage::Repeat); } else { - QTRY_VERIFY(obj->status() == QQuickBorderImage::Error); + QTRY_COMPARE(obj->status(), QQuickBorderImage::Error); } delete obj; @@ -443,7 +450,7 @@ void tst_qquickborderimage::statusChanges() obj->setSource(source); if (remote) server.sendDelayedItem(); - QTRY_VERIFY(obj->status() == finalStatus); + QTRY_COMPARE(obj->status(), finalStatus); QCOMPARE(spy.count(), emissions); delete obj; @@ -529,8 +536,8 @@ void tst_qquickborderimage::progressAndStatusChanges() component.setData(componentStr.toLatin1(), QUrl::fromLocalFile("")); QQuickBorderImage *obj = qobject_cast<QQuickBorderImage*>(component.create()); QVERIFY(obj != 0); - QVERIFY(obj->status() == QQuickBorderImage::Ready); - QTRY_VERIFY(obj->progress() == 1.0); + QCOMPARE(obj->status(), QQuickBorderImage::Ready); + QTRY_COMPARE(obj->progress(), 1.0); qRegisterMetaType<QQuickBorderImage::Status>(); QSignalSpy sourceSpy(obj, SIGNAL(sourceChanged(QUrl))); @@ -539,33 +546,33 @@ void tst_qquickborderimage::progressAndStatusChanges() // Same file ctxt->setContextProperty("srcImage", testFileUrl("heart200.png")); - QTRY_VERIFY(obj->status() == QQuickBorderImage::Ready); - QTRY_VERIFY(obj->progress() == 1.0); + QTRY_COMPARE(obj->status(), QQuickBorderImage::Ready); + QTRY_COMPARE(obj->progress(), 1.0); QTRY_COMPARE(sourceSpy.count(), 0); QTRY_COMPARE(progressSpy.count(), 0); QTRY_COMPARE(statusSpy.count(), 0); // Loading local file ctxt->setContextProperty("srcImage", testFileUrl("colors.png")); - QTRY_VERIFY(obj->status() == QQuickBorderImage::Ready); - QTRY_VERIFY(obj->progress() == 1.0); + QTRY_COMPARE(obj->status(), QQuickBorderImage::Ready); + QTRY_COMPARE(obj->progress(), 1.0); QTRY_COMPARE(sourceSpy.count(), 1); QTRY_COMPARE(progressSpy.count(), 0); QTRY_COMPARE(statusSpy.count(), 1); // Loading remote file ctxt->setContextProperty("srcImage", server.url("/heart200.png")); - QTRY_VERIFY(obj->status() == QQuickBorderImage::Loading); - QTRY_VERIFY(obj->progress() == 0.0); - QTRY_VERIFY(obj->status() == QQuickBorderImage::Ready); - QTRY_VERIFY(obj->progress() == 1.0); + QTRY_COMPARE(obj->status(), QQuickBorderImage::Loading); + QTRY_COMPARE(obj->progress(), 0.0); + QTRY_COMPARE(obj->status(), QQuickBorderImage::Ready); + QTRY_COMPARE(obj->progress(), 1.0); QTRY_COMPARE(sourceSpy.count(), 2); QTRY_VERIFY(progressSpy.count() > 1); QTRY_COMPARE(statusSpy.count(), 3); ctxt->setContextProperty("srcImage", ""); - QTRY_VERIFY(obj->status() == QQuickBorderImage::Null); - QTRY_VERIFY(obj->progress() == 0.0); + QTRY_COMPARE(obj->status(), QQuickBorderImage::Null); + QTRY_COMPARE(obj->progress(), 0.0); QTRY_COMPARE(sourceSpy.count(), 3); QTRY_VERIFY(progressSpy.count() > 2); QTRY_COMPARE(statusSpy.count(), 4); diff --git a/tests/auto/quick/qquickdesignersupport/data/TestComponent.qml b/tests/auto/quick/qquickdesignersupport/data/TestComponent.qml new file mode 100644 index 0000000000..68f456af99 --- /dev/null +++ b/tests/auto/quick/qquickdesignersupport/data/TestComponent.qml @@ -0,0 +1,9 @@ +import QtQuick 2.0 + +Item { + width: 100 + height: 62 + + x: Math.max(0, 200) +} + diff --git a/tests/auto/quick/qquickdesignersupport/data/test.qml b/tests/auto/quick/qquickdesignersupport/data/test.qml new file mode 100644 index 0000000000..1d43cb3b7e --- /dev/null +++ b/tests/auto/quick/qquickdesignersupport/data/test.qml @@ -0,0 +1,39 @@ +import QtQuick 2.0 + +Rectangle { + objectName: "rootItem" + color: "white" + width: 800 + height: 600 + + TestComponent { + objectName: "testComponent" + + } + + Rectangle { + objectName: "rectangleItem" + gradient: Gradient { + + } + } + + Item { + id: item + objectName: "simpleItem" + property string testProperty: dynamicProperty + } + + states: [ + State { + name: "state01" + PropertyChanges { + target: item + width: 10 + } + }, + State { + name: "state02" + } + ] +} diff --git a/tests/auto/quick/qquickdesignersupport/qquickdesignersupport.pro b/tests/auto/quick/qquickdesignersupport/qquickdesignersupport.pro new file mode 100644 index 0000000000..af932d834b --- /dev/null +++ b/tests/auto/quick/qquickdesignersupport/qquickdesignersupport.pro @@ -0,0 +1,16 @@ +CONFIG += testcase +TARGET = tst_qquickdesignersupport +SOURCES += tst_qquickdesignersupport.cpp + +include (../../shared/util.pri) +include (../shared/util.pri) + +osx:CONFIG -= app_bundle + +TESTDATA = data/* + +QT += core-private gui-private qml-private quick-private testlib +DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 + +DISTFILES += \ + data/TestComponent.qml diff --git a/tests/auto/quick/qquickdesignersupport/tst_qquickdesignersupport.cpp b/tests/auto/quick/qquickdesignersupport/tst_qquickdesignersupport.cpp new file mode 100644 index 0000000000..49535783c1 --- /dev/null +++ b/tests/auto/quick/qquickdesignersupport/tst_qquickdesignersupport.cpp @@ -0,0 +1,500 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL21$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include <qtest.h> +#include <QtQml/qqmlengine.h> +#include <QtQml/qqmlcomponent.h> +#include <QtQuick/qquickview.h> +#include <private/qquickdesignersupportitems_p.h> +#include <private/qquickdesignersupportmetainfo_p.h> +#include <private/qquickdesignersupportproperties_p.h> +#include <private/qquickdesignersupportstates_p.h> +#include <private/qquickdesignersupportpropertychanges_p.h> +#include <private/qquickitem_p.h> +#include <private/qquickstate_p.h> +#include <private/qquickstate_p_p.h> +#include <private/qquickstategroup_p.h> +#include <private/qquickpropertychanges_p.h> +#include <private/qquickrectangle_p.h> +#include "../../shared/util.h" +#include "../shared/visualtestutil.h" + +using namespace QQuickVisualTestUtil; + +class tst_qquickdesignersupport : public QQmlDataTest +{ + Q_OBJECT +public: + tst_qquickdesignersupport() {} + +private slots: + void customData(); + void customDataBindings(); + void objectProperties(); + void dynamicProperty(); + void createComponent(); + void basicStates(); + void statesPropertyChanges(); + void testNotifyPropertyChangeCallBack(); + void testFixResourcePathsForObjectCallBack(); +}; + +void tst_qquickdesignersupport::customData() +{ + QScopedPointer<QQuickView> view(new QQuickView); + view->engine()->setOutputWarningsToStandardError(false); + view->setSource(testFileUrl("test.qml")); + + QVERIFY(view->errors().isEmpty()); + + QQuickItem *rootItem = view->rootObject(); + + QVERIFY(rootItem); + + QScopedPointer<QObject> newItemScopedPointer(QQuickDesignerSupportItems::createPrimitive(QLatin1String("QtQuick/Item"), 2, 6, view->rootContext())); + QObject *newItem = newItemScopedPointer.data(); + + QVERIFY(newItem); + QVERIFY(qobject_cast<QQuickItem*>(newItem)); + + QQuickDesignerSupportProperties::registerCustomData(newItem); + QVERIFY(QQuickDesignerSupportProperties::getResetValue(newItem, "width").isValid()); + int defaultWidth = QQuickDesignerSupportProperties::getResetValue(newItem, "width").toInt(); + QCOMPARE(defaultWidth, 0); + + newItem->setProperty("width", 200); + QCOMPARE(newItem->property("width").toInt(), 200); + + //Check if reseting property does work + QQuickDesignerSupportProperties::doResetProperty(newItem, view->rootContext(), "width"); + QCOMPARE(newItem->property("width").toInt(), 0); + + //Setting a binding on width + QQuickDesignerSupportProperties::setPropertyBinding(newItem, + view->engine()->contextForObject(newItem), + "width", + QLatin1String("Math.max(0, 200)")); + QCOMPARE(newItem->property("width").toInt(), 200); + QVERIFY(QQuickDesignerSupportProperties::hasBindingForProperty(newItem, + view->engine()->contextForObject(newItem), + "width", + 0)); + + //Check if reseting property does work after setting binding + QQuickDesignerSupportProperties::doResetProperty(newItem, view->rootContext(), "width"); + QCOMPARE(newItem->property("width").toInt(), 0); + + //No custom data available for the rootItem, because not registered by QQuickDesignerSupportProperties::registerCustomData + QVERIFY(!QQuickDesignerSupportProperties::getResetValue(rootItem, "width").isValid()); + + newItemScopedPointer.reset(); //Delete the item and check if item gets removed from the hash and an invalid QVariant is returned. + + QVERIFY(!QQuickDesignerSupportProperties::getResetValue(newItem, "width").isValid()); +} + +void tst_qquickdesignersupport::customDataBindings() +{ + QScopedPointer<QQuickView> view(new QQuickView); + view->engine()->setOutputWarningsToStandardError(false); + view->setSource(testFileUrl("test.qml")); + + QVERIFY(view->errors().isEmpty()); + + QQuickItem *rootItem = view->rootObject(); + + QVERIFY(rootItem); + + QQuickItem *testComponent = findItem<QQuickItem>(view->rootObject(), QLatin1String("testComponent")); + + QVERIFY(testComponent); + QQuickDesignerSupportProperties::registerCustomData(testComponent); + QQuickDesignerSupportProperties::hasValidResetBinding(testComponent, "x"); + QVERIFY(QQuickDesignerSupportProperties::hasBindingForProperty(testComponent, + view->engine()->contextForObject(testComponent), + "x", + 0)); + + QCOMPARE(testComponent->property("x").toInt(), 200); + + + //Set property to 100 and ovveride the default binding + QQmlProperty property(testComponent, "x", view->engine()->contextForObject(testComponent)); + QVERIFY(property.write(100)); + QCOMPARE(testComponent->property("x").toInt(), 100); + + QVERIFY(!QQuickDesignerSupportProperties::hasBindingForProperty(testComponent, + view->engine()->contextForObject(testComponent), + "x", + 0)); + + //Reset the binding to the default + QQuickDesignerSupportProperties::doResetProperty(testComponent, + view->engine()->contextForObject(testComponent), + "x"); + + QVERIFY(QQuickDesignerSupportProperties::hasBindingForProperty(testComponent, + view->engine()->contextForObject(testComponent), + "x", + 0)); + QCOMPARE(testComponent->property("x").toInt(), 200); + + + + //Set a different binding/expression + QQuickDesignerSupportProperties::setPropertyBinding(testComponent, + view->engine()->contextForObject(testComponent), + "x", + QLatin1String("Math.max(0, 300)")); + + QVERIFY(QQuickDesignerSupportProperties::hasBindingForProperty(testComponent, + view->engine()->contextForObject(testComponent), + "x", + 0)); + + QCOMPARE(testComponent->property("x").toInt(), 300); + + + + //Reset the binding to the default + QQuickDesignerSupportProperties::doResetProperty(testComponent, + view->engine()->contextForObject(testComponent), + "x"); + + + QVERIFY(QQuickDesignerSupportProperties::hasBindingForProperty(testComponent, + view->engine()->contextForObject(testComponent), + "x", + 0)); + QCOMPARE(testComponent->property("x").toInt(), 200); +} + +void tst_qquickdesignersupport::objectProperties() +{ + QScopedPointer<QQuickView> view(new QQuickView); + view->engine()->setOutputWarningsToStandardError(false); + view->setSource(testFileUrl("test.qml")); + + QVERIFY(view->errors().isEmpty()); + + QQuickItem *rootItem = view->rootObject(); + + QVERIFY(rootItem); + + QQuickItem *rectangleItem = findItem<QQuickItem>(view->rootObject(), QLatin1String("rectangleItem")); + QVERIFY(rectangleItem); + + + //Read gradient property as QObject + int propertyIndex = rectangleItem->metaObject()->indexOfProperty("gradient"); + QVERIFY(propertyIndex > 0); + QMetaProperty metaProperty = rectangleItem->metaObject()->property(propertyIndex); + QVERIFY(metaProperty.isValid()); + + QVERIFY(QQuickDesignerSupportProperties::isPropertyQObject(metaProperty)); + + QObject*gradient = QQuickDesignerSupportProperties::readQObjectProperty(metaProperty, rectangleItem); + QVERIFY(gradient); + + + //The width property is not a QObject + propertyIndex = rectangleItem->metaObject()->indexOfProperty("width"); + QVERIFY(propertyIndex > 0); + metaProperty = rectangleItem->metaObject()->property(propertyIndex); + QVERIFY(metaProperty.isValid()); + QVERIFY(!QQuickDesignerSupportProperties::isPropertyQObject(metaProperty)); +} + +void tst_qquickdesignersupport::dynamicProperty() +{ + QScopedPointer<QQuickView> view(new QQuickView); + view->engine()->setOutputWarningsToStandardError(false); + view->setSource(testFileUrl("test.qml")); + + QVERIFY(view->errors().isEmpty()); + + QQuickItem *rootItem = view->rootObject(); + + QVERIFY(rootItem); + + QQuickItem *simpleItem = findItem<QQuickItem>(view->rootObject(), QLatin1String("simpleItem")); + + QVERIFY(simpleItem); + + QQuickDesignerSupportProperties::registerNodeInstanceMetaObject(simpleItem, view->engine()); + QQuickDesignerSupportProperties::getPropertyCache(simpleItem, view->engine()); + + QQuickDesignerSupportProperties::createNewDynamicProperty(simpleItem, view->engine(), QLatin1String("dynamicProperty")); + + QQmlProperty property(simpleItem, "dynamicProperty", view->engine()->contextForObject(simpleItem)); + QVERIFY(property.isValid()); + QVERIFY(property.write(QLatin1String("test"))); + + + QCOMPARE(property.read().toString(), QLatin1String("test")); + + //Force evalutation of all bindings + QQuickDesignerSupport::refreshExpressions(view->rootContext()); + + //Check if expression to dynamic property gets properly resolved + property = QQmlProperty(simpleItem, "testProperty", view->engine()->contextForObject(simpleItem)); + QVERIFY(property.isValid()); + QCOMPARE(property.read().toString(), QLatin1String("test")); +} + +void tst_qquickdesignersupport::createComponent() +{ + QScopedPointer<QQuickView> view(new QQuickView); + view->engine()->setOutputWarningsToStandardError(false); + view->setSource(testFileUrl("test.qml")); + + QVERIFY(view->errors().isEmpty()); + + QQuickItem *rootItem = view->rootObject(); + + QVERIFY(rootItem); + + QObject *testComponentObject = QQuickDesignerSupportItems::createComponent(testFileUrl("TestComponent.qml"), view->rootContext()); + QVERIFY(testComponentObject); + + QVERIFY(QQuickDesignerSupportMetaInfo::isSubclassOf(testComponentObject, "QtQuick/Item")); +} + +void tst_qquickdesignersupport::basicStates() +{ + QScopedPointer<QQuickView> view(new QQuickView); + view->engine()->setOutputWarningsToStandardError(false); + view->setSource(testFileUrl("test.qml")); + + QVERIFY(view->errors().isEmpty()); + + QQuickItem *rootItem = view->rootObject(); + + QVERIFY(rootItem); + + QQuickStateGroup *stateGroup = QQuickItemPrivate::get(rootItem)->_states(); + + QVERIFY(stateGroup); + + QCOMPARE(stateGroup->states().count(), 2 ); + + QQuickState *state01 = stateGroup->states().first(); + QQuickState *state02 = stateGroup->states().last(); + + QVERIFY(state01); + QVERIFY(state02); + + QCOMPARE(state01->property("name").toString(), QLatin1String("state01")); + QCOMPARE(state02->property("name").toString(), QLatin1String("state02")); + + QVERIFY(!QQuickDesignerSupportStates::isStateActive(state01, view->rootContext())); + QVERIFY(!QQuickDesignerSupportStates::isStateActive(state01, view->rootContext())); + + QQuickDesignerSupportStates::activateState(state01, view->rootContext()); + QVERIFY(QQuickDesignerSupportStates::isStateActive(state01, view->rootContext())); + + QQuickDesignerSupportStates::activateState(state02, view->rootContext()); + QVERIFY(QQuickDesignerSupportStates::isStateActive(state02, view->rootContext())); + QVERIFY(!QQuickDesignerSupportStates::isStateActive(state01, view->rootContext())); + + QQuickDesignerSupportStates::deactivateState(state02); + QVERIFY(!QQuickDesignerSupportStates::isStateActive(state01, view->rootContext())); + QVERIFY(!QQuickDesignerSupportStates::isStateActive(state01, view->rootContext())); +} + +void tst_qquickdesignersupport::statesPropertyChanges() +{ + QScopedPointer<QQuickView> view(new QQuickView); + view->engine()->setOutputWarningsToStandardError(false); + view->setSource(testFileUrl("test.qml")); + + QVERIFY(view->errors().isEmpty()); + + QQuickItem *rootItem = view->rootObject(); + + QVERIFY(rootItem); + + QQuickItem *simpleItem = findItem<QQuickItem>(view->rootObject(), QLatin1String("simpleItem")); + + QVERIFY(simpleItem); + + QQuickStateGroup *stateGroup = QQuickItemPrivate::get(rootItem)->_states(); + + QVERIFY(stateGroup); + + QCOMPARE(stateGroup->states().count(), 2 ); + + QQuickState *state01 = stateGroup->states().first(); + QQuickState *state02 = stateGroup->states().last(); + + QVERIFY(state01); + QVERIFY(state02); + + QCOMPARE(state01->property("name").toString(), QLatin1String("state01")); + QCOMPARE(state02->property("name").toString(), QLatin1String("state02")); + + //PropertyChanges are parsed lazily + QQuickDesignerSupportStates::activateState(state01, view->rootContext()); + QQuickDesignerSupportStates::deactivateState(state01); + + QQuickStatePrivate *statePrivate01 = static_cast<QQuickStatePrivate *>(QQuickStatePrivate::get(state01)); + + QCOMPARE(state01->operationCount(), 1); + + QCOMPARE(statePrivate01->operations.count(), 1); + + QQuickStateOperation *propertyChange = statePrivate01->operations.at(0).data(); + + QCOMPARE(QQuickDesignerSupportPropertyChanges::stateObject(propertyChange), state01); + + QQuickDesignerSupportPropertyChanges::changeValue(propertyChange, "width", 300); + + QCOMPARE(simpleItem->property("width").toInt(), 0); + QQuickDesignerSupportStates::activateState(state01, view->rootContext()); + QCOMPARE(simpleItem->property("width").toInt(), 300); + QQuickDesignerSupportStates::deactivateState(state01); + QCOMPARE(simpleItem->property("width").toInt(), 0); + + //Set "base state value" in state1 using the revert list + QQuickDesignerSupportStates::activateState(state01, view->rootContext()); + QQuickDesignerSupportStates::changeValueInRevertList(state01, simpleItem, "width", 200); + QCOMPARE(simpleItem->property("width").toInt(), 300); + QQuickDesignerSupportStates::deactivateState(state01); + QCOMPARE(simpleItem->property("width").toInt(), 200); + + + //Create new PropertyChanges + QQuickPropertyChanges *newPropertyChange = new QQuickPropertyChanges(); + newPropertyChange->setParent(state01); + QQuickStatePrivate::operations_append(&state01->changes(), newPropertyChange); + + newPropertyChange->setObject(rootItem); + + QQuickDesignerSupportPropertyChanges::attachToState(newPropertyChange); + + QCOMPARE(rootItem, QQuickDesignerSupportPropertyChanges::targetObject(newPropertyChange)); + + QCOMPARE(state01->operationCount(), 2); + QCOMPARE(statePrivate01->operations.count(), 2); + + QCOMPARE(QQuickDesignerSupportPropertyChanges::stateObject(newPropertyChange), state01); + + //Set color for rootItem in state1 + QQuickDesignerSupportPropertyChanges::changeValue(newPropertyChange, "color", QColor(Qt::red)); + + QQuickDesignerSupportStates::activateState(state01, view->rootContext()); + QCOMPARE(rootItem->property("color").value<QColor>(), QColor(Qt::red)); + QQuickDesignerSupportStates::deactivateState(state01); + QCOMPARE(rootItem->property("color").value<QColor>(), QColor(Qt::white)); + + QQuickDesignerSupportPropertyChanges::removeProperty(newPropertyChange, "color"); + QQuickDesignerSupportStates::activateState(state01, view->rootContext()); + QCOMPARE(rootItem->property("color").value<QColor>(), QColor(Qt::white)); + +} + +static QObject * s_object = 0; +static QQuickDesignerSupport::PropertyName s_propertyName; + +static void notifyPropertyChangeCallBackFunction(QObject *object, const QQuickDesignerSupport::PropertyName &propertyName) +{ + s_object = object; + s_propertyName = propertyName; +} + +static void (*notifyPropertyChangeCallBackPointer)(QObject *, const QQuickDesignerSupport::PropertyName &) = ¬ifyPropertyChangeCallBackFunction; + + +void tst_qquickdesignersupport::testNotifyPropertyChangeCallBack() +{ + QScopedPointer<QQuickView> view(new QQuickView); + view->engine()->setOutputWarningsToStandardError(false); + view->setSource(testFileUrl("test.qml")); + + QVERIFY(view->errors().isEmpty()); + + QQuickItem *rootItem = view->rootObject(); + + QVERIFY(rootItem); + + QQuickRectangle *rectangle = static_cast<QQuickRectangle *>(rootItem); + QVERIFY(rectangle); + + QQuickDesignerSupportProperties::registerNodeInstanceMetaObject(rectangle, view->engine()); + + QQuickGradient *gradient = new QQuickGradient(rectangle); + + QQuickDesignerSupportMetaInfo::registerNotifyPropertyChangeCallBack(notifyPropertyChangeCallBackPointer); + + rectangle->setProperty("gradient", QVariant::fromValue<QQuickGradient *>(gradient)); + + QVERIFY(s_object); + QCOMPARE(s_object, rootItem); + QCOMPARE(s_propertyName, QQuickDesignerSupport::PropertyName("gradient")); +} + +static void fixResourcePathsForObjectCallBackFunction(QObject *object) +{ + s_object = object; +} + +static void (*fixResourcePathsForObjectCallBackPointer)(QObject *) = &fixResourcePathsForObjectCallBackFunction; + +void tst_qquickdesignersupport::testFixResourcePathsForObjectCallBack() +{ + QScopedPointer<QQuickView> view(new QQuickView); + view->engine()->setOutputWarningsToStandardError(false); + view->setSource(testFileUrl("test.qml")); + + QVERIFY(view->errors().isEmpty()); + + QQuickItem *rootItem = view->rootObject(); + + QVERIFY(rootItem); + + s_object = 0; + + QQuickDesignerSupportItems::registerFixResourcePathsForObjectCallBack(fixResourcePathsForObjectCallBackPointer); + + QQuickItem *simpleItem = findItem<QQuickItem>(view->rootObject(), QLatin1String("simpleItem")); + + QVERIFY(simpleItem); + + QQuickDesignerSupportItems::tweakObjects(simpleItem); + + //Check that the fixResourcePathsForObjectCallBack was called on simpleItem + QCOMPARE(simpleItem , s_object); +} + + +QTEST_MAIN(tst_qquickdesignersupport) + +#include "tst_qquickdesignersupport.moc" diff --git a/tests/auto/quick/qquickdynamicpropertyanimation/tst_qquickdynamicpropertyanimation.cpp b/tests/auto/quick/qquickdynamicpropertyanimation/tst_qquickdynamicpropertyanimation.cpp index 40bd6624f0..3656bb8aab 100644 --- a/tests/auto/quick/qquickdynamicpropertyanimation/tst_qquickdynamicpropertyanimation.cpp +++ b/tests/auto/quick/qquickdynamicpropertyanimation/tst_qquickdynamicpropertyanimation.cpp @@ -59,11 +59,11 @@ private: QQmlProperty testProp(item, propertyName); QPropertyAnimation animation(item, propertyName, this); animation.setEndValue(toValue); - QVERIFY(animation.targetObject() == item); - QVERIFY(animation.propertyName() == propertyName); - QVERIFY(animation.endValue().value<T>() == toValue); + QCOMPARE(animation.targetObject(), item); + QCOMPARE(animation.propertyName(), propertyName); + QCOMPARE(animation.endValue().value<T>(), toValue); animation.start(); - QVERIFY(animation.state() == QAbstractAnimation::Running); + QCOMPARE(animation.state(), QAbstractAnimation::Running); QTest::qWait(animation.duration()); QTRY_COMPARE(testProp.read().value<T>(), toValue); } diff --git a/tests/auto/quick/qquickflickable/BLACKLIST b/tests/auto/quick/qquickflickable/BLACKLIST index 92ed8708de..647bf819a5 100644 --- a/tests/auto/quick/qquickflickable/BLACKLIST +++ b/tests/auto/quick/qquickflickable/BLACKLIST @@ -10,7 +10,7 @@ osx-10.10 osx-10.10 [stopAtBounds] osx-10.10 -windows 32bit developer-build +windows developer-build [returnToBounds] osx [pressWhileFlicking] diff --git a/tests/auto/quick/qquickflickable/data/movementSignals.qml b/tests/auto/quick/qquickflickable/data/movementSignals.qml new file mode 100644 index 0000000000..581e882139 --- /dev/null +++ b/tests/auto/quick/qquickflickable/data/movementSignals.qml @@ -0,0 +1,26 @@ +import QtQuick 2.0 + +Flickable { + width: 400; height: 400 + contentWidth: 400; contentHeight: 1200 + + property string signalString + + Rectangle { + width: 400; height: 400 + color: "red" + } + Rectangle { + y: 400; width: 400; height: 400 + color: "yellow" + } + Rectangle { + y: 800; width: 400; height: 400 + color: "green" + } + + onMovementStarted: signalString += "ms" + onMovementEnded: signalString += "me" + onFlickStarted: signalString += "fs" + onFlickEnded: signalString += "fe" +} diff --git a/tests/auto/quick/qquickflickable/tst_qquickflickable.cpp b/tests/auto/quick/qquickflickable/tst_qquickflickable.cpp index 7d08c3c81e..eee7ffe560 100644 --- a/tests/auto/quick/qquickflickable/tst_qquickflickable.cpp +++ b/tests/auto/quick/qquickflickable/tst_qquickflickable.cpp @@ -91,6 +91,7 @@ private slots: void stopAtBounds_data(); void nestedMouseAreaUsingTouch(); void pressDelayWithLoader(); + void movementFromProgrammaticFlick(); void cleanup(); private: @@ -195,9 +196,9 @@ void tst_qquickflickable::properties() QCOMPARE(obj->pressDelay(), 200); QCOMPARE(obj->maximumFlickVelocity(), 2000.); - QVERIFY(obj->property("ok").toBool() == false); + QVERIFY(!obj->property("ok").toBool()); QMetaObject::invokeMethod(obj, "check"); - QVERIFY(obj->property("ok").toBool() == true); + QVERIFY(obj->property("ok").toBool()); delete obj; } @@ -211,28 +212,28 @@ void tst_qquickflickable::boundsBehavior() QSignalSpy spy(flickable, SIGNAL(boundsBehaviorChanged())); QVERIFY(flickable); - QVERIFY(flickable->boundsBehavior() == QQuickFlickable::StopAtBounds); + QCOMPARE(flickable->boundsBehavior(), QQuickFlickable::StopAtBounds); flickable->setBoundsBehavior(QQuickFlickable::DragAndOvershootBounds); - QVERIFY(flickable->boundsBehavior() == QQuickFlickable::DragAndOvershootBounds); + QCOMPARE(flickable->boundsBehavior(), QQuickFlickable::DragAndOvershootBounds); QCOMPARE(spy.count(),1); flickable->setBoundsBehavior(QQuickFlickable::DragAndOvershootBounds); QCOMPARE(spy.count(),1); flickable->setBoundsBehavior(QQuickFlickable::DragOverBounds); - QVERIFY(flickable->boundsBehavior() == QQuickFlickable::DragOverBounds); + QCOMPARE(flickable->boundsBehavior(), QQuickFlickable::DragOverBounds); QCOMPARE(spy.count(),2); flickable->setBoundsBehavior(QQuickFlickable::DragOverBounds); QCOMPARE(spy.count(),2); flickable->setBoundsBehavior(QQuickFlickable::StopAtBounds); - QVERIFY(flickable->boundsBehavior() == QQuickFlickable::StopAtBounds); + QCOMPARE(flickable->boundsBehavior(), QQuickFlickable::StopAtBounds); QCOMPARE(spy.count(),3); flickable->setBoundsBehavior(QQuickFlickable::StopAtBounds); QCOMPARE(spy.count(),3); flickable->setBoundsBehavior(QQuickFlickable::OvershootBounds); - QVERIFY(flickable->boundsBehavior() == QQuickFlickable::OvershootBounds); + QCOMPARE(flickable->boundsBehavior(), QQuickFlickable::OvershootBounds); QCOMPARE(spy.count(),4); flickable->setBoundsBehavior(QQuickFlickable::OvershootBounds); QCOMPARE(spy.count(),4); @@ -249,7 +250,7 @@ void tst_qquickflickable::rebound() QQuickViewTestUtil::moveMouseAway(window.data()); window->show(); - QVERIFY(QTest::qWaitForWindowExposed(window.data())); + QVERIFY(QTest::qWaitForWindowActive(window.data())); QVERIFY(window->rootObject() != 0); QQuickFlickable *flickable = qobject_cast<QQuickFlickable*>(window->rootObject()); @@ -295,11 +296,11 @@ void tst_qquickflickable::rebound() // flick and trigger the transition multiple times // (moving signals are emitted as soon as the first transition starts) - flick(window.data(), QPoint(20,20), QPoint(120,120), 200); // both x and y will bounce back - flick(window.data(), QPoint(20,120), QPoint(120,20), 200); // only x will bounce back + flick(window.data(), QPoint(20,20), QPoint(120,120), 50); // both x and y will bounce back + flick(window.data(), QPoint(20,120), QPoint(120,20), 50); // only x will bounce back QVERIFY(flickable->isMoving()); - QVERIFY(window->rootObject()->property("transitionsStarted").toInt() >= 1); + QTRY_VERIFY(window->rootObject()->property("transitionsStarted").toInt() >= 1); QCOMPARE(hMoveSpy.count(), 1); QCOMPARE(vMoveSpy.count(), 1); QCOMPARE(movementStartedSpy.count(), 1); @@ -388,7 +389,7 @@ void tst_qquickflickable::pressDelay() QQuickViewTestUtil::centerOnScreen(window.data()); QQuickViewTestUtil::moveMouseAway(window.data()); window->show(); - QVERIFY(QTest::qWaitForWindowExposed(window.data())); + QVERIFY(QTest::qWaitForWindowActive(window.data())); QVERIFY(window->rootObject() != 0); QQuickFlickable *flickable = qobject_cast<QQuickFlickable*>(window->rootObject()); @@ -406,13 +407,13 @@ void tst_qquickflickable::pressDelay() QQuickItem *mouseArea = window->rootObject()->findChild<QQuickItem*>("mouseArea"); QSignalSpy clickedSpy(mouseArea, SIGNAL(clicked(QQuickMouseEvent*))); - QTest::mousePress(window.data(), Qt::LeftButton, 0, QPoint(150, 150)); + moveAndPress(window.data(), QPoint(150, 150)); // The press should not occur immediately - QVERIFY(mouseArea->property("pressed").toBool() == false); + QVERIFY(!mouseArea->property("pressed").toBool()); // But, it should occur eventually - QTRY_VERIFY(mouseArea->property("pressed").toBool() == true); + QTRY_VERIFY(mouseArea->property("pressed").toBool()); QCOMPARE(clickedSpy.count(),0); @@ -427,10 +428,10 @@ void tst_qquickflickable::pressDelay() // Test a quick tap within the pressDelay timeout clickedSpy.clear(); - QTest::mousePress(window.data(), Qt::LeftButton, 0, QPoint(180, 180)); + moveAndPress(window.data(), QPoint(180, 180)); // The press should not occur immediately - QVERIFY(mouseArea->property("pressed").toBool() == false); + QVERIFY(!mouseArea->property("pressed").toBool()); QCOMPARE(clickedSpy.count(),0); @@ -444,16 +445,16 @@ void tst_qquickflickable::pressDelay() // QTBUG-31168 - QTest::mousePress(window.data(), Qt::LeftButton, 0, QPoint(150, 110)); + moveAndPress(window.data(), QPoint(150, 110)); // The press should not occur immediately - QVERIFY(mouseArea->property("pressed").toBool() == false); + QVERIFY(!mouseArea->property("pressed").toBool()); QTest::mouseMove(window.data(), QPoint(150, 190)); // As we moved pass the drag threshold, we should never receive the press - QVERIFY(mouseArea->property("pressed").toBool() == false); - QTRY_VERIFY(mouseArea->property("pressed").toBool() == false); + QVERIFY(!mouseArea->property("pressed").toBool()); + QTRY_VERIFY(!mouseArea->property("pressed").toBool()); // On release the clicked signal should *not* be emitted QTest::mouseRelease(window.data(), Qt::LeftButton, 0, QPoint(150, 190)); @@ -469,7 +470,7 @@ void tst_qquickflickable::nestedPressDelay() QQuickViewTestUtil::centerOnScreen(window.data()); QQuickViewTestUtil::moveMouseAway(window.data()); window->show(); - QVERIFY(QTest::qWaitForWindowExposed(window.data())); + QVERIFY(QTest::qWaitForWindowActive(window.data())); QVERIFY(window->rootObject() != 0); QQuickFlickable *outer = qobject_cast<QQuickFlickable*>(window->rootObject()); @@ -478,44 +479,44 @@ void tst_qquickflickable::nestedPressDelay() QQuickFlickable *inner = window->rootObject()->findChild<QQuickFlickable*>("innerFlickable"); QVERIFY(inner != 0); - QTest::mousePress(window.data(), Qt::LeftButton, 0, QPoint(150, 150)); + moveAndPress(window.data(), QPoint(150, 150)); // the MouseArea is not pressed immediately - QVERIFY(outer->property("pressed").toBool() == false); - QVERIFY(inner->property("pressed").toBool() == false); + QVERIFY(!outer->property("pressed").toBool()); + QVERIFY(!inner->property("pressed").toBool()); // The inner pressDelay will prevail (50ms, vs. 10sec) // QTRY_VERIFY() has 5sec timeout, so will timeout well within 10sec. - QTRY_VERIFY(outer->property("pressed").toBool() == true); + QTRY_VERIFY(outer->property("pressed").toBool()); QTest::mouseRelease(window.data(), Qt::LeftButton, 0, QPoint(150, 150)); // Dragging inner Flickable should work - QTest::mousePress(window.data(), Qt::LeftButton, 0, QPoint(80, 150)); + moveAndPress(window.data(), QPoint(80, 150)); // the MouseArea is not pressed immediately - QVERIFY(outer->property("pressed").toBool() == false); - QVERIFY(inner->property("pressed").toBool() == false); + QVERIFY(!outer->property("pressed").toBool()); + QVERIFY(!inner->property("pressed").toBool()); QTest::mouseMove(window.data(), QPoint(60, 150)); QTest::mouseMove(window.data(), QPoint(40, 150)); QTest::mouseMove(window.data(), QPoint(20, 150)); - QVERIFY(inner->property("moving").toBool() == true); - QVERIFY(outer->property("moving").toBool() == false); + QVERIFY(inner->property("moving").toBool()); + QVERIFY(!outer->property("moving").toBool()); QTest::mouseRelease(window.data(), Qt::LeftButton, 0, QPoint(20, 150)); // Dragging the MouseArea in the inner Flickable should move the inner Flickable - QTest::mousePress(window.data(), Qt::LeftButton, 0, QPoint(150, 150)); + moveAndPress(window.data(), QPoint(150, 150)); // the MouseArea is not pressed immediately - QVERIFY(outer->property("pressed").toBool() == false); + QVERIFY(!outer->property("pressed").toBool()); QTest::mouseMove(window.data(), QPoint(130, 150)); QTest::mouseMove(window.data(), QPoint(110, 150)); QTest::mouseMove(window.data(), QPoint(90, 150)); - QVERIFY(outer->property("moving").toBool() == false); - QVERIFY(inner->property("moving").toBool() == true); + QVERIFY(!outer->property("moving").toBool()); + QVERIFY(inner->property("moving").toBool()); QTest::mouseRelease(window.data(), Qt::LeftButton, 0, QPoint(90, 150)); } @@ -529,7 +530,7 @@ void tst_qquickflickable::nestedClickThenFlick() QQuickViewTestUtil::centerOnScreen(window.data()); QQuickViewTestUtil::moveMouseAway(window.data()); window->show(); - QVERIFY(QTest::qWaitForWindowExposed(window.data())); + QVERIFY(QTest::qWaitForWindowActive(window.data())); QVERIFY(window->rootObject() != 0); QQuickFlickable *outer = qobject_cast<QQuickFlickable*>(window->rootObject()); @@ -538,29 +539,29 @@ void tst_qquickflickable::nestedClickThenFlick() QQuickFlickable *inner = window->rootObject()->findChild<QQuickFlickable*>("innerFlickable"); QVERIFY(inner != 0); - QTest::mousePress(window.data(), Qt::LeftButton, 0, QPoint(150, 150)); + moveAndPress(window.data(), QPoint(150, 150)); // the MouseArea is not pressed immediately - QVERIFY(outer->property("pressed").toBool() == false); - QTRY_VERIFY(outer->property("pressed").toBool() == true); + QVERIFY(!outer->property("pressed").toBool()); + QTRY_VERIFY(outer->property("pressed").toBool()); QTest::mouseRelease(window.data(), Qt::LeftButton, 0, QPoint(150, 150)); - QVERIFY(outer->property("pressed").toBool() == false); + QVERIFY(!outer->property("pressed").toBool()); // Dragging inner Flickable should work - QTest::mousePress(window.data(), Qt::LeftButton, 0, QPoint(80, 150)); + moveAndPress(window.data(), QPoint(80, 150)); // the MouseArea is not pressed immediately - QVERIFY(outer->property("pressed").toBool() == false); + QVERIFY(!outer->property("pressed").toBool()); QTest::mouseMove(window.data(), QPoint(80, 148)); QTest::mouseMove(window.data(), QPoint(80, 140)); QTest::mouseMove(window.data(), QPoint(80, 120)); QTest::mouseMove(window.data(), QPoint(80, 100)); - QVERIFY(outer->property("moving").toBool() == false); - QVERIFY(inner->property("moving").toBool() == true); + QVERIFY(!outer->property("moving").toBool()); + QVERIFY(inner->property("moving").toBool()); QTest::mouseRelease(window.data(), Qt::LeftButton, 0, QPoint(80, 100)); } @@ -628,6 +629,8 @@ void tst_qquickflickable::returnToBounds() window->rootContext()->setContextProperty("setRebound", setRebound); window->setSource(testFileUrl("resize.qml")); + window->show(); + QTest::qWaitForWindowActive(window.data()); QVERIFY(window->rootObject() != 0); QQuickFlickable *obj = findItem<QQuickFlickable>(window->rootObject(), "flick"); @@ -671,7 +674,7 @@ void tst_qquickflickable::wheel() QScopedPointer<QQuickView> window(new QQuickView); window->setSource(testFileUrl("wheel.qml")); window->show(); - QVERIFY(QTest::qWaitForWindowExposed(window.data())); + QVERIFY(QTest::qWaitForWindowActive(window.data())); QVERIFY(window->rootObject() != 0); QQuickFlickable *flick = window->rootObject()->findChild<QQuickFlickable*>("flick"); @@ -685,10 +688,10 @@ void tst_qquickflickable::wheel() } QTRY_VERIFY(flick->contentY() > 0); - QVERIFY(flick->contentX() == 0); + QCOMPARE(flick->contentX(), qreal(0)); flick->setContentY(0); - QVERIFY(flick->contentY() == 0); + QCOMPARE(flick->contentY(), qreal(0)); { QPoint pos(200, 200); @@ -699,7 +702,7 @@ void tst_qquickflickable::wheel() } QTRY_VERIFY(flick->contentX() > 0); - QVERIFY(flick->contentY() == 0); + QCOMPARE(flick->contentY(), qreal(0)); } void tst_qquickflickable::movingAndFlicking_data() @@ -740,7 +743,7 @@ void tst_qquickflickable::movingAndFlicking() QQuickViewTestUtil::centerOnScreen(window.data()); QQuickViewTestUtil::moveMouseAway(window.data()); window->show(); - QVERIFY(QTest::qWaitForWindowExposed(window.data())); + QVERIFY(QTest::qWaitForWindowActive(window.data())); QVERIFY(window->rootObject() != 0); QQuickFlickable *flickable = qobject_cast<QQuickFlickable*>(window->rootObject()); @@ -903,7 +906,7 @@ void tst_qquickflickable::movingAndDragging() QQuickViewTestUtil::centerOnScreen(window.data()); QQuickViewTestUtil::moveMouseAway(window.data()); window->show(); - QVERIFY(QTest::qWaitForWindowExposed(window.data())); + QVERIFY(QTest::qWaitForWindowActive(window.data())); QVERIFY(window->rootObject() != 0); QQuickFlickable *flickable = qobject_cast<QQuickFlickable*>(window->rootObject()); @@ -922,7 +925,7 @@ void tst_qquickflickable::movingAndDragging() QSignalSpy moveEndSpy(flickable, SIGNAL(movementEnded())); // start the drag - QTest::mousePress(window.data(), Qt::LeftButton, 0, moveFrom); + moveAndPress(window.data(), moveFrom); QTest::mouseMove(window.data(), moveFrom + moveByWithoutSnapBack); QTest::mouseMove(window.data(), moveFrom + moveByWithoutSnapBack*2); QTest::mouseMove(window.data(), moveFrom + moveByWithoutSnapBack*3); @@ -962,7 +965,7 @@ void tst_qquickflickable::movingAndDragging() // Don't test whether moving finished because a flick could occur // wait for any motion to end - QTRY_VERIFY(flickable->isMoving() == false); + QTRY_VERIFY(!flickable->isMoving()); QVERIFY(!flickable->isMovingHorizontally()); QVERIFY(!flickable->isMovingVertically()); @@ -998,7 +1001,7 @@ void tst_qquickflickable::movingAndDragging() flickable->setContentX(0); flickable->setContentY(0); QTRY_VERIFY(!flickable->isMoving()); - QTest::mousePress(window.data(), Qt::LeftButton, 0, moveFrom); + moveAndPress(window.data(), moveFrom); QTest::mouseMove(window.data(), moveFrom + moveByWithSnapBack); QTest::mouseMove(window.data(), moveFrom + moveByWithSnapBack*2); QTest::mouseMove(window.data(), moveFrom + moveByWithSnapBack*3); @@ -1072,7 +1075,7 @@ void tst_qquickflickable::flickOnRelease() QScopedPointer<QQuickView> window(new QQuickView); window->setSource(testFileUrl("flickable03.qml")); window->show(); - QVERIFY(QTest::qWaitForWindowExposed(window.data())); + QVERIFY(QTest::qWaitForWindowActive(window.data())); QVERIFY(window->rootObject() != 0); QQuickFlickable *flickable = qobject_cast<QQuickFlickable*>(window->rootObject()); @@ -1085,14 +1088,14 @@ void tst_qquickflickable::flickOnRelease() // underlying drivers will hopefully provide a pre-calculated velocity // (based on more data than what the UI gets), thus making this use case // working even with small movements. - QTest::mousePress(window.data(), Qt::LeftButton, 0, QPoint(50, 300)); + moveAndPress(window.data(), QPoint(50, 300)); QTest::mouseMove(window.data(), QPoint(50, 10), 10); QTest::mouseRelease(window.data(), Qt::LeftButton, 0, QPoint(50, 10), 10); QCOMPARE(vFlickSpy.count(), 1); // wait for any motion to end - QTRY_VERIFY(flickable->isMoving() == false); + QTRY_VERIFY(!flickable->isMoving()); #ifdef Q_OS_MAC QEXPECT_FAIL("", "QTBUG-26094 stopping on a full pixel doesn't work on OS X", Continue); @@ -1109,7 +1112,7 @@ void tst_qquickflickable::pressWhileFlicking() QQuickViewTestUtil::centerOnScreen(window.data()); QQuickViewTestUtil::moveMouseAway(window.data()); window->show(); - QVERIFY(QTest::qWaitForWindowExposed(window.data())); + QVERIFY(QTest::qWaitForWindowActive(window.data())); QVERIFY(window->rootObject() != 0); QQuickFlickable *flickable = qobject_cast<QQuickFlickable*>(window->rootObject()); @@ -1159,27 +1162,27 @@ void tst_qquickflickable::disabled() QScopedPointer<QQuickView> window(new QQuickView); window->setSource(testFileUrl("disabled.qml")); window->show(); - QVERIFY(QTest::qWaitForWindowExposed(window.data())); + QVERIFY(QTest::qWaitForWindowActive(window.data())); QVERIFY(window->rootObject() != 0); QQuickFlickable *flick = window->rootObject()->findChild<QQuickFlickable*>("flickable"); QVERIFY(flick != 0); - QTest::mousePress(window.data(), Qt::LeftButton, 0, QPoint(50, 90)); + moveAndPress(window.data(), QPoint(50, 90)); QTest::mouseMove(window.data(), QPoint(50, 80)); QTest::mouseMove(window.data(), QPoint(50, 70)); QTest::mouseMove(window.data(), QPoint(50, 60)); - QVERIFY(flick->isMoving() == false); + QVERIFY(!flick->isMoving()); QTest::mouseRelease(window.data(), Qt::LeftButton, 0, QPoint(50, 60)); // verify that mouse clicks on other elements still work (QTBUG-20584) - QTest::mousePress(window.data(), Qt::LeftButton, 0, QPoint(50, 10)); + moveAndPress(window.data(), QPoint(50, 10)); QTest::mouseRelease(window.data(), Qt::LeftButton, 0, QPoint(50, 10)); - QTRY_VERIFY(window->rootObject()->property("clicked").toBool() == true); + QTRY_VERIFY(window->rootObject()->property("clicked").toBool()); } void tst_qquickflickable::flickVelocity() @@ -1190,7 +1193,7 @@ void tst_qquickflickable::flickVelocity() QQuickViewTestUtil::centerOnScreen(window.data()); QQuickViewTestUtil::moveMouseAway(window.data()); window->show(); - QVERIFY(QTest::qWaitForWindowExposed(window.data())); + QVERIFY(QTest::qWaitForWindowActive(window.data())); QVERIFY(window->rootObject() != 0); QQuickFlickable *flickable = qobject_cast<QQuickFlickable*>(window->rootObject()); @@ -1199,12 +1202,12 @@ void tst_qquickflickable::flickVelocity() // flick up flick(window.data(), QPoint(20,190), QPoint(20, 50), 200); QVERIFY(flickable->verticalVelocity() > 0.0); - QTRY_VERIFY(flickable->verticalVelocity() == 0.0); + QTRY_COMPARE(flickable->verticalVelocity(), 0.0); // flick down flick(window.data(), QPoint(20,10), QPoint(20, 140), 200); QTRY_VERIFY(flickable->verticalVelocity() < 0.0); - QTRY_VERIFY(flickable->verticalVelocity() == 0.0); + QTRY_COMPARE(flickable->verticalVelocity(), 0.0); #ifdef Q_OS_MAC QSKIP("boost doesn't work on OS X"); @@ -1223,7 +1226,7 @@ void tst_qquickflickable::flickVelocity() // Flick in opposite direction -> boost cancelled. flick(window.data(), QPoint(20,10), QPoint(20, 340), 200); QTRY_VERIFY(flickable->verticalVelocity() < 0.0); - QVERIFY(fp->flickBoost == 1.0); + QCOMPARE(fp->flickBoost, 1.0); } void tst_qquickflickable::margins() @@ -1235,7 +1238,7 @@ void tst_qquickflickable::margins() QQuickViewTestUtil::moveMouseAway(window.data()); window->setTitle(QTest::currentTestFunction()); window->show(); - QVERIFY(QTest::qWaitForWindowExposed(window.data())); + QVERIFY(QTest::qWaitForWindowActive(window.data())); QQuickItem *root = window->rootObject(); QVERIFY(root); QQuickFlickable *obj = qobject_cast<QQuickFlickable*>(root); @@ -1298,13 +1301,13 @@ void tst_qquickflickable::cancelOnMouseGrab() QQuickViewTestUtil::centerOnScreen(window.data()); QQuickViewTestUtil::moveMouseAway(window.data()); window->show(); - QVERIFY(QTest::qWaitForWindowExposed(window.data())); + QVERIFY(QTest::qWaitForWindowActive(window.data())); QVERIFY(window->rootObject() != 0); QQuickFlickable *flickable = qobject_cast<QQuickFlickable*>(window->rootObject()); QVERIFY(flickable != 0); - QTest::mousePress(window.data(), Qt::LeftButton, 0, QPoint(10, 10)); + moveAndPress(window.data(), QPoint(10, 10)); // drag out of bounds QTest::mouseMove(window.data(), QPoint(50, 50)); QTest::mouseMove(window.data(), QPoint(100, 100)); @@ -1324,7 +1327,7 @@ void tst_qquickflickable::cancelOnMouseGrab() QTRY_VERIFY(!flickable->isMoving()); QTRY_VERIFY(!flickable->isDragging()); - QTest::mouseRelease(window.data(), Qt::LeftButton, 0, QPoint(50, 10)); + moveAndRelease(window.data(), QPoint(50, 10)); } @@ -1336,41 +1339,41 @@ void tst_qquickflickable::clickAndDragWhenTransformed() QQuickViewTestUtil::centerOnScreen(view.data()); QQuickViewTestUtil::moveMouseAway(view.data()); view->show(); - QVERIFY(QTest::qWaitForWindowExposed(view.data())); + QVERIFY(QTest::qWaitForWindowActive(view.data())); QVERIFY(view->rootObject() != 0); QQuickFlickable *flickable = view->rootObject()->findChild<QQuickFlickable*>("flickable"); QVERIFY(flickable != 0); // click outside child rect - QTest::mousePress(view.data(), Qt::LeftButton, 0, QPoint(190, 190)); + moveAndPress(view.data(), QPoint(190, 190)); QTRY_COMPARE(flickable->property("itemPressed").toBool(), false); QTest::mouseRelease(view.data(), Qt::LeftButton, 0, QPoint(190, 190)); // click inside child rect - QTest::mousePress(view.data(), Qt::LeftButton, 0, QPoint(200, 200)); + moveAndPress(view.data(), QPoint(200, 200)); QTRY_COMPARE(flickable->property("itemPressed").toBool(), true); QTest::mouseRelease(view.data(), Qt::LeftButton, 0, QPoint(200, 200)); const int threshold = qApp->styleHints()->startDragDistance(); // drag outside bounds - QTest::mousePress(view.data(), Qt::LeftButton, 0, QPoint(160, 160)); + moveAndPress(view.data(), QPoint(160, 160)); QTest::qWait(10); QTest::mouseMove(view.data(), QPoint(160 + threshold * 2, 160)); QTest::mouseMove(view.data(), QPoint(160 + threshold * 3, 160)); QCOMPARE(flickable->isDragging(), false); QCOMPARE(flickable->property("itemPressed").toBool(), false); - QTest::mouseRelease(view.data(), Qt::LeftButton, 0, QPoint(180, 160)); + moveAndRelease(view.data(), QPoint(180, 160)); // drag inside bounds - QTest::mousePress(view.data(), Qt::LeftButton, 0, QPoint(200, 140)); + moveAndPress(view.data(), QPoint(200, 140)); QTest::qWait(10); QTest::mouseMove(view.data(), QPoint(200 + threshold * 2, 140)); QTest::mouseMove(view.data(), QPoint(200 + threshold * 3, 140)); QCOMPARE(flickable->isDragging(), true); QCOMPARE(flickable->property("itemPressed").toBool(), false); - QTest::mouseRelease(view.data(), Qt::LeftButton, 0, QPoint(220, 140)); + moveAndRelease(view.data(), QPoint(220, 140)); } void tst_qquickflickable::flickTwiceUsingTouches() @@ -1459,7 +1462,7 @@ void tst_qquickflickable::nestedStopAtBounds() QQuickViewTestUtil::moveMouseAway(&view); view.show(); view.requestActivate(); - QVERIFY(QTest::qWaitForWindowExposed(&view)); + QVERIFY(QTest::qWaitForWindowActive(&view)); QVERIFY(view.rootObject()); QQuickFlickable *outer = qobject_cast<QQuickFlickable*>(view.rootObject()); @@ -1489,7 +1492,7 @@ void tst_qquickflickable::nestedStopAtBounds() int &axis = transpose ? position.ry() : position.rx(); // drag toward the aligned boundary. Outer flickable dragged. - QTest::mousePress(&view, Qt::LeftButton, 0, position); + moveAndPress(&view, position); QTest::qWait(10); axis += invert ? threshold * 2 : -threshold * 2; QTest::mouseMove(&view, position); @@ -1507,7 +1510,7 @@ void tst_qquickflickable::nestedStopAtBounds() outer->setContentY(50); // drag away from the aligned boundary. Inner flickable dragged. - QTest::mousePress(&view, Qt::LeftButton, 0, position); + moveAndPress(&view, position); QTest::qWait(10); axis += invert ? -threshold * 2 : threshold * 2; QTest::mouseMove(&view, position); @@ -1526,7 +1529,7 @@ void tst_qquickflickable::nestedStopAtBounds() inner->setContentHeight(inner->height() - margin); // Drag inner with equal size and contentSize - QTest::mousePress(&view, Qt::LeftButton, 0, position); + moveAndPress(&view, position); QTest::qWait(10); axis += invert ? -threshold * 2 : threshold * 2; QTest::mouseMove(&view, position); @@ -1543,7 +1546,7 @@ void tst_qquickflickable::nestedStopAtBounds() inner->setContentHeight(inner->height() - 100); // Drag inner with size greater than contentSize - QTest::mousePress(&view, Qt::LeftButton, 0, position); + moveAndPress(&view, position); QTest::qWait(10); axis += invert ? -threshold * 2 : threshold * 2; QTest::mouseMove(&view, position); @@ -1583,7 +1586,7 @@ void tst_qquickflickable::stopAtBounds() QQuickViewTestUtil::moveMouseAway(&view); view.show(); view.requestActivate(); - QVERIFY(QTest::qWaitForWindowExposed(&view)); + QVERIFY(QTest::qWaitForWindowActive(&view)); QVERIFY(view.rootObject()); QQuickFlickable *flickable = qobject_cast<QQuickFlickable*>(view.rootObject()); @@ -1601,7 +1604,7 @@ void tst_qquickflickable::stopAtBounds() int &axis = transpose ? position.ry() : position.rx(); // drag away from the aligned boundary. View should not move - QTest::mousePress(&view, Qt::LeftButton, 0, position); + moveAndPress(&view, position); QTest::qWait(10); for (int i = 0; i < 3; ++i) { axis += invert ? -threshold : threshold; @@ -1649,12 +1652,14 @@ void tst_qquickflickable::stopAtBounds() } else { flickable->setContentX(invert ? 100 : 0); } + + QSignalSpy flickSignal(flickable, SIGNAL(flickingChanged())); if (invert) flick(&view, QPoint(20,20), QPoint(120,120), 100); else flick(&view, QPoint(120,120), QPoint(20,20), 100); - QVERIFY(flickable->isFlicking()); + QVERIFY(flickSignal.count() > 0); if (transpose) { if (invert) QTRY_COMPARE(flickable->isAtYBeginning(), true); @@ -1707,14 +1712,33 @@ void tst_qquickflickable::pressDelayWithLoader() QQuickViewTestUtil::centerOnScreen(window.data()); QQuickViewTestUtil::moveMouseAway(window.data()); window->show(); - QVERIFY(QTest::qWaitForWindowExposed(window.data())); + QVERIFY(QTest::qWaitForWindowActive(window.data())); QVERIFY(window->rootObject() != 0); // do not crash - QTest::mousePress(window.data(), Qt::LeftButton, 0, QPoint(150, 150)); + moveAndPress(window.data(), QPoint(150, 150)); QTest::mouseRelease(window.data(), Qt::LeftButton, 0, QPoint(150, 150)); } +// QTBUG-34507 +void tst_qquickflickable::movementFromProgrammaticFlick() +{ + QScopedPointer<QQuickView> window(new QQuickView); + window->setSource(testFileUrl("movementSignals.qml")); + QTRY_COMPARE(window->status(), QQuickView::Ready); + QQuickViewTestUtil::centerOnScreen(window.data()); + QQuickViewTestUtil::moveMouseAway(window.data()); + window->show(); + QVERIFY(QTest::qWaitForWindowActive(window.data())); + + QQuickFlickable *flickable = qobject_cast<QQuickFlickable*>(window->rootObject()); + QVERIFY(flickable != 0); + + // verify that the signals for movement and flicking are called in the right order + flickable->flick(0, -1000); + QTRY_COMPARE(flickable->property("signalString").toString(), QString("msfsfeme")); +} + QTEST_MAIN(tst_qquickflickable) #include "tst_qquickflickable.moc" diff --git a/tests/auto/quick/qquickflipable/tst_qquickflipable.cpp b/tests/auto/quick/qquickflipable/tst_qquickflipable.cpp index 76bf509cf0..2eb8942eee 100644 --- a/tests/auto/quick/qquickflipable/tst_qquickflipable.cpp +++ b/tests/auto/quick/qquickflipable/tst_qquickflipable.cpp @@ -108,11 +108,11 @@ void tst_qquickflipable::flipFlipable() QQmlComponent c(&engine, testFileUrl("flip-flipable.qml")); QQuickFlipable *obj = qobject_cast<QQuickFlipable*>(c.create()); QVERIFY(obj != 0); - QVERIFY(obj->side() == QQuickFlipable::Front); + QCOMPARE(obj->side(), QQuickFlipable::Front); obj->setProperty("flipped", QVariant(true)); - QTRY_VERIFY(obj->side() == QQuickFlipable::Back); - QTRY_VERIFY(obj->side() == QQuickFlipable::Front); - QTRY_VERIFY(obj->side() == QQuickFlipable::Back); + QTRY_COMPARE(obj->side(), QQuickFlipable::Back); + QTRY_COMPARE(obj->side(), QQuickFlipable::Front); + QTRY_COMPARE(obj->side(), QQuickFlipable::Back); delete obj; } diff --git a/tests/auto/quick/qquickfocusscope/tst_qquickfocusscope.cpp b/tests/auto/quick/qquickfocusscope/tst_qquickfocusscope.cpp index 98f85af92e..4b377f92d6 100644 --- a/tests/auto/quick/qquickfocusscope/tst_qquickfocusscope.cpp +++ b/tests/auto/quick/qquickfocusscope/tst_qquickfocusscope.cpp @@ -81,27 +81,27 @@ void tst_qquickfocusscope::basic() view->requestActivate(); QTest::qWaitForWindowActive(view); - QTRY_VERIFY(view == qGuiApp->focusWindow()); + QTRY_COMPARE(view, qGuiApp->focusWindow()); QVERIFY(view->isTopLevel()); - QVERIFY(item0->hasActiveFocus() == true); - QVERIFY(item1->hasActiveFocus() == true); - QVERIFY(item2->hasActiveFocus() == false); - QVERIFY(item3->hasActiveFocus() == false); + QVERIFY(item0->hasActiveFocus()); + QVERIFY(item1->hasActiveFocus()); + QVERIFY(!item2->hasActiveFocus()); + QVERIFY(!item3->hasActiveFocus()); QTest::keyClick(view, Qt::Key_Right); QTest::qWait(50); - QVERIFY(item0->hasActiveFocus() == true); - QVERIFY(item1->hasActiveFocus() == false); - QVERIFY(item2->hasActiveFocus() == true); - QVERIFY(item3->hasActiveFocus() == false); + QVERIFY(item0->hasActiveFocus()); + QVERIFY(!item1->hasActiveFocus()); + QVERIFY(item2->hasActiveFocus()); + QVERIFY(!item3->hasActiveFocus()); QTest::keyClick(view, Qt::Key_Down); QTest::qWait(50); - QVERIFY(item0->hasActiveFocus() == false); - QVERIFY(item1->hasActiveFocus() == false); - QVERIFY(item2->hasActiveFocus() == false); - QVERIFY(item3->hasActiveFocus() == true); + QVERIFY(!item0->hasActiveFocus()); + QVERIFY(!item1->hasActiveFocus()); + QVERIFY(!item2->hasActiveFocus()); + QVERIFY(item3->hasActiveFocus()); delete view; } @@ -126,13 +126,13 @@ void tst_qquickfocusscope::nested() view->requestActivate(); QTest::qWaitForWindowActive(view); - QTRY_VERIFY(view == qGuiApp->focusWindow()); + QTRY_COMPARE(view, qGuiApp->focusWindow()); - QVERIFY(item1->hasActiveFocus() == true); - QVERIFY(item2->hasActiveFocus() == true); - QVERIFY(item3->hasActiveFocus() == true); - QVERIFY(item4->hasActiveFocus() == true); - QVERIFY(item5->hasActiveFocus() == true); + QVERIFY(item1->hasActiveFocus()); + QVERIFY(item2->hasActiveFocus()); + QVERIFY(item3->hasActiveFocus()); + QVERIFY(item4->hasActiveFocus()); + QVERIFY(item5->hasActiveFocus()); delete view; } @@ -153,24 +153,24 @@ void tst_qquickfocusscope::noFocus() view->show(); view->requestActivate(); QVERIFY(QTest::qWaitForWindowActive(view)); - QVERIFY(view == qGuiApp->focusWindow()); + QCOMPARE(view, qGuiApp->focusWindow()); - QVERIFY(item0->hasActiveFocus() == false); - QVERIFY(item1->hasActiveFocus() == false); - QVERIFY(item2->hasActiveFocus() == false); - QVERIFY(item3->hasActiveFocus() == false); + QVERIFY(!item0->hasActiveFocus()); + QVERIFY(!item1->hasActiveFocus()); + QVERIFY(!item2->hasActiveFocus()); + QVERIFY(!item3->hasActiveFocus()); QTest::keyClick(view, Qt::Key_Right); - QVERIFY(item0->hasActiveFocus() == false); - QVERIFY(item1->hasActiveFocus() == false); - QVERIFY(item2->hasActiveFocus() == false); - QVERIFY(item3->hasActiveFocus() == false); + QVERIFY(!item0->hasActiveFocus()); + QVERIFY(!item1->hasActiveFocus()); + QVERIFY(!item2->hasActiveFocus()); + QVERIFY(!item3->hasActiveFocus()); QTest::keyClick(view, Qt::Key_Down); - QVERIFY(item0->hasActiveFocus() == false); - QVERIFY(item1->hasActiveFocus() == false); - QVERIFY(item2->hasActiveFocus() == false); - QVERIFY(item3->hasActiveFocus() == false); + QVERIFY(!item0->hasActiveFocus()); + QVERIFY(!item1->hasActiveFocus()); + QVERIFY(!item2->hasActiveFocus()); + QVERIFY(!item3->hasActiveFocus()); delete view; } @@ -194,33 +194,33 @@ void tst_qquickfocusscope::textEdit() QTest::qWaitForWindowActive(view); - QTRY_VERIFY(view == qGuiApp->focusWindow()); - QVERIFY(item0->hasActiveFocus() == true); - QVERIFY(item1->hasActiveFocus() == true); - QVERIFY(item2->hasActiveFocus() == false); - QVERIFY(item3->hasActiveFocus() == false); + QTRY_COMPARE(view, qGuiApp->focusWindow()); + QVERIFY(item0->hasActiveFocus()); + QVERIFY(item1->hasActiveFocus()); + QVERIFY(!item2->hasActiveFocus()); + QVERIFY(!item3->hasActiveFocus()); QTest::keyClick(view, Qt::Key_Right); - QVERIFY(item0->hasActiveFocus() == true); - QVERIFY(item1->hasActiveFocus() == true); - QVERIFY(item2->hasActiveFocus() == false); - QVERIFY(item3->hasActiveFocus() == false); + QVERIFY(item0->hasActiveFocus()); + QVERIFY(item1->hasActiveFocus()); + QVERIFY(!item2->hasActiveFocus()); + QVERIFY(!item3->hasActiveFocus()); QTest::keyClick(view, Qt::Key_Right); QTest::keyClick(view, Qt::Key_Right); QTest::keyClick(view, Qt::Key_Right); QTest::keyClick(view, Qt::Key_Right); QTest::keyClick(view, Qt::Key_Right); - QVERIFY(item0->hasActiveFocus() == true); - QVERIFY(item1->hasActiveFocus() == false); - QVERIFY(item2->hasActiveFocus() == true); - QVERIFY(item3->hasActiveFocus() == false); + QVERIFY(item0->hasActiveFocus()); + QVERIFY(!item1->hasActiveFocus()); + QVERIFY(item2->hasActiveFocus()); + QVERIFY(!item3->hasActiveFocus()); QTest::keyClick(view, Qt::Key_Down); - QVERIFY(item0->hasActiveFocus() == false); - QVERIFY(item1->hasActiveFocus() == false); - QVERIFY(item2->hasActiveFocus() == false); - QVERIFY(item3->hasActiveFocus() == true); + QVERIFY(!item0->hasActiveFocus()); + QVERIFY(!item1->hasActiveFocus()); + QVERIFY(!item2->hasActiveFocus()); + QVERIFY(item3->hasActiveFocus()); delete view; } @@ -246,30 +246,30 @@ void tst_qquickfocusscope::forceFocus() view->show(); view->requestActivate(); QTest::qWaitForWindowActive(view); - QTRY_VERIFY(view == qGuiApp->focusWindow()); + QTRY_COMPARE(view, qGuiApp->focusWindow()); - QVERIFY(item0->hasActiveFocus() == true); - QVERIFY(item1->hasActiveFocus() == true); - QVERIFY(item2->hasActiveFocus() == false); - QVERIFY(item3->hasActiveFocus() == false); - QVERIFY(item4->hasActiveFocus() == false); - QVERIFY(item5->hasActiveFocus() == false); + QVERIFY(item0->hasActiveFocus()); + QVERIFY(item1->hasActiveFocus()); + QVERIFY(!item2->hasActiveFocus()); + QVERIFY(!item3->hasActiveFocus()); + QVERIFY(!item4->hasActiveFocus()); + QVERIFY(!item5->hasActiveFocus()); QTest::keyClick(view, Qt::Key_4); - QVERIFY(item0->hasActiveFocus() == true); - QVERIFY(item1->hasActiveFocus() == true); - QVERIFY(item2->hasActiveFocus() == false); - QVERIFY(item3->hasActiveFocus() == false); - QVERIFY(item4->hasActiveFocus() == false); - QVERIFY(item5->hasActiveFocus() == false); + QVERIFY(item0->hasActiveFocus()); + QVERIFY(item1->hasActiveFocus()); + QVERIFY(!item2->hasActiveFocus()); + QVERIFY(!item3->hasActiveFocus()); + QVERIFY(!item4->hasActiveFocus()); + QVERIFY(!item5->hasActiveFocus()); QTest::keyClick(view, Qt::Key_5); - QVERIFY(item0->hasActiveFocus() == false); - QVERIFY(item1->hasActiveFocus() == false); - QVERIFY(item2->hasActiveFocus() == false); - QVERIFY(item3->hasActiveFocus() == true); - QVERIFY(item4->hasActiveFocus() == false); - QVERIFY(item5->hasActiveFocus() == true); + QVERIFY(!item0->hasActiveFocus()); + QVERIFY(!item1->hasActiveFocus()); + QVERIFY(!item2->hasActiveFocus()); + QVERIFY(item3->hasActiveFocus()); + QVERIFY(!item4->hasActiveFocus()); + QVERIFY(item5->hasActiveFocus()); delete view; } @@ -283,13 +283,13 @@ void tst_qquickfocusscope::noParentFocus() view->show(); view->requestActivate(); QTest::qWaitForWindowActive(view); - QTRY_VERIFY(view == qGuiApp->focusWindow()); + QTRY_COMPARE(view, qGuiApp->focusWindow()); - QVERIFY(view->rootObject()->property("focus1") == false); - QVERIFY(view->rootObject()->property("focus2") == false); - QVERIFY(view->rootObject()->property("focus3") == true); - QVERIFY(view->rootObject()->property("focus4") == true); - QVERIFY(view->rootObject()->property("focus5") == true); + QVERIFY(!view->rootObject()->property("focus1").toBool()); + QVERIFY(!view->rootObject()->property("focus2").toBool()); + QVERIFY(view->rootObject()->property("focus3").toBool()); + QVERIFY(view->rootObject()->property("focus4").toBool()); + QVERIFY(view->rootObject()->property("focus5").toBool()); delete view; } @@ -312,7 +312,7 @@ void tst_qquickfocusscope::signalEmission() view->requestActivate(); QTest::qWaitForWindowActive(view); - QTRY_VERIFY(view == qGuiApp->focusWindow()); + QTRY_COMPARE(view, qGuiApp->focusWindow()); QVariant blue(QColor("blue")); QVariant red(QColor("red")); @@ -362,7 +362,7 @@ void tst_qquickfocusscope::qtBug13380() QVERIFY(QTest::qWaitForWindowExposed(view)); - QTRY_VERIFY(view == qGuiApp->focusWindow()); + QTRY_COMPARE(view, qGuiApp->focusWindow()); QVERIFY(view->rootObject()->property("noFocus").toBool()); view->rootObject()->setProperty("showRect", true); @@ -379,7 +379,7 @@ void tst_qquickfocusscope::forceActiveFocus() view->show(); view->requestActivate(); QVERIFY(QTest::qWaitForWindowExposed(view)); - QTRY_VERIFY(view == qGuiApp->focusWindow()); + QTRY_COMPARE(view, qGuiApp->focusWindow()); QQuickItem *rootObject = view->rootObject(); QVERIFY(rootObject); @@ -532,7 +532,7 @@ void tst_qquickfocusscope::canvasFocus() view->requestActivate(); QVERIFY(QTest::qWaitForWindowActive(view)); - QVERIFY(view == qGuiApp->focusWindow()); + QCOMPARE(view, qGuiApp->focusWindow()); // Now the window has focus, active focus given to item1 QCOMPARE(rootItem->hasFocus(), true); @@ -558,7 +558,7 @@ void tst_qquickfocusscope::canvasFocus() alternateView.show(); alternateView.requestActivate(); QVERIFY(QTest::qWaitForWindowActive(&alternateView)); - QVERIFY(QGuiApplication::focusWindow() == &alternateView); + QCOMPARE(QGuiApplication::focusWindow(), &alternateView); QCOMPARE(rootItem->hasFocus(), false); QCOMPARE(rootItem->hasActiveFocus(), false); @@ -604,7 +604,7 @@ void tst_qquickfocusscope::canvasFocus() view->show(); view->requestActivate(); QVERIFY(QTest::qWaitForWindowActive(view)); - QVERIFY(QGuiApplication::focusWindow() == view); + QCOMPARE(QGuiApplication::focusWindow(), view); QCOMPARE(rootItem->hasFocus(), true); QCOMPARE(rootItem->hasActiveFocus(), true); diff --git a/tests/auto/quick/qquickfontloader/tst_qquickfontloader.cpp b/tests/auto/quick/qquickfontloader/tst_qquickfontloader.cpp index a084c86a95..f4f1e290c1 100644 --- a/tests/auto/quick/qquickfontloader/tst_qquickfontloader.cpp +++ b/tests/auto/quick/qquickfontloader/tst_qquickfontloader.cpp @@ -85,7 +85,7 @@ void tst_qquickfontloader::noFont() QVERIFY(fontObject != 0); QCOMPARE(fontObject->name(), QString("")); QCOMPARE(fontObject->source(), QUrl("")); - QTRY_VERIFY(fontObject->status() == QQuickFontLoader::Null); + QTRY_COMPARE(fontObject->status(), QQuickFontLoader::Null); delete fontObject; } @@ -100,7 +100,7 @@ void tst_qquickfontloader::namedFont() QVERIFY(fontObject != 0); QCOMPARE(fontObject->source(), QUrl("")); QCOMPARE(fontObject->name(), QString("Helvetica")); - QTRY_VERIFY(fontObject->status() == QQuickFontLoader::Ready); + QTRY_COMPARE(fontObject->status(), QQuickFontLoader::Ready); } void tst_qquickfontloader::localFont() @@ -113,7 +113,7 @@ void tst_qquickfontloader::localFont() QVERIFY(fontObject != 0); QVERIFY(fontObject->source() != QUrl("")); QTRY_COMPARE(fontObject->name(), QString("OCRA")); - QTRY_VERIFY(fontObject->status() == QQuickFontLoader::Ready); + QTRY_COMPARE(fontObject->status(), QQuickFontLoader::Ready); } void tst_qquickfontloader::failLocalFont() @@ -127,7 +127,7 @@ void tst_qquickfontloader::failLocalFont() QVERIFY(fontObject != 0); QVERIFY(fontObject->source() != QUrl("")); QTRY_COMPARE(fontObject->name(), QString("")); - QTRY_VERIFY(fontObject->status() == QQuickFontLoader::Error); + QTRY_COMPARE(fontObject->status(), QQuickFontLoader::Error); } void tst_qquickfontloader::webFont() @@ -141,7 +141,7 @@ void tst_qquickfontloader::webFont() QVERIFY(fontObject != 0); QVERIFY(fontObject->source() != QUrl("")); QTRY_COMPARE(fontObject->name(), QString("OCRA")); - QTRY_VERIFY(fontObject->status() == QQuickFontLoader::Ready); + QTRY_COMPARE(fontObject->status(), QQuickFontLoader::Ready); } void tst_qquickfontloader::redirWebFont() @@ -157,7 +157,7 @@ void tst_qquickfontloader::redirWebFont() QVERIFY(fontObject != 0); QVERIFY(fontObject->source() != QUrl("")); QTRY_COMPARE(fontObject->name(), QString("OCRA")); - QTRY_VERIFY(fontObject->status() == QQuickFontLoader::Ready); + QTRY_COMPARE(fontObject->status(), QQuickFontLoader::Ready); } void tst_qquickfontloader::failWebFont() @@ -172,7 +172,7 @@ void tst_qquickfontloader::failWebFont() QVERIFY(fontObject != 0); QVERIFY(fontObject->source() != QUrl("")); QTRY_COMPARE(fontObject->name(), QString("")); - QTRY_VERIFY(fontObject->status() == QQuickFontLoader::Error); + QTRY_COMPARE(fontObject->status(), QQuickFontLoader::Error); } void tst_qquickfontloader::changeFont() @@ -189,26 +189,26 @@ void tst_qquickfontloader::changeFont() QSignalSpy nameSpy(fontObject, SIGNAL(nameChanged())); QSignalSpy statusSpy(fontObject, SIGNAL(statusChanged())); - QTRY_VERIFY(fontObject->status() == QQuickFontLoader::Ready); + QTRY_COMPARE(fontObject->status(), QQuickFontLoader::Ready); QCOMPARE(nameSpy.count(), 0); QCOMPARE(statusSpy.count(), 0); QTRY_COMPARE(fontObject->name(), QString("OCRA")); ctxt->setContextProperty("font", server.urlString("/daniel.ttf")); - QTRY_VERIFY(fontObject->status() == QQuickFontLoader::Loading); - QTRY_VERIFY(fontObject->status() == QQuickFontLoader::Ready); + QTRY_COMPARE(fontObject->status(), QQuickFontLoader::Loading); + QTRY_COMPARE(fontObject->status(), QQuickFontLoader::Ready); QCOMPARE(nameSpy.count(), 1); QCOMPARE(statusSpy.count(), 2); QTRY_COMPARE(fontObject->name(), QString("Daniel")); ctxt->setContextProperty("font", testFileUrl("tarzeau_ocr_a.ttf")); - QTRY_VERIFY(fontObject->status() == QQuickFontLoader::Ready); + QTRY_COMPARE(fontObject->status(), QQuickFontLoader::Ready); QCOMPARE(nameSpy.count(), 2); QCOMPARE(statusSpy.count(), 2); QTRY_COMPARE(fontObject->name(), QString("OCRA")); ctxt->setContextProperty("font", server.urlString("/daniel.ttf")); - QTRY_VERIFY(fontObject->status() == QQuickFontLoader::Ready); + QTRY_COMPARE(fontObject->status(), QQuickFontLoader::Ready); QCOMPARE(nameSpy.count(), 3); QCOMPARE(statusSpy.count(), 2); QTRY_COMPARE(fontObject->name(), QString("Daniel")); @@ -224,7 +224,7 @@ void tst_qquickfontloader::changeFontSourceViaState() QQuickFontLoader *fontObject = qobject_cast<QQuickFontLoader*>(qvariant_cast<QObject *>(window.rootObject()->property("fontloader"))); QVERIFY(fontObject != 0); - QTRY_VERIFY(fontObject->status() == QQuickFontLoader::Ready); + QTRY_COMPARE(fontObject->status(), QQuickFontLoader::Ready); QVERIFY(fontObject->source() != QUrl("")); QTRY_COMPARE(fontObject->name(), QString("OCRA")); @@ -236,7 +236,7 @@ void tst_qquickfontloader::changeFontSourceViaState() QTest::ignoreMessage(QtWarningMsg, qPrintable(warning)); QEXPECT_FAIL("", "QTBUG-20268", Abort); - QTRY_VERIFY(fontObject->status() == QQuickFontLoader::Ready); + QTRY_COMPARE(fontObject->status(), QQuickFontLoader::Ready); QCOMPARE(window.rootObject()->property("name").toString(), QString("Tahoma")); } diff --git a/tests/auto/quick/qquickgridview/BLACKLIST b/tests/auto/quick/qquickgridview/BLACKLIST new file mode 100644 index 0000000000..9eb9940aa5 --- /dev/null +++ b/tests/auto/quick/qquickgridview/BLACKLIST @@ -0,0 +1,2 @@ +[snapOneRow:horizontal, right to left] +windows diff --git a/tests/auto/quick/qquickgridview/data/contentHeightWithDelayRemove.qml b/tests/auto/quick/qquickgridview/data/contentHeightWithDelayRemove.qml new file mode 100644 index 0000000000..3f8246bafc --- /dev/null +++ b/tests/auto/quick/qquickgridview/data/contentHeightWithDelayRemove.qml @@ -0,0 +1,47 @@ +import QtQuick 2.1 + +Item { + width: 400 + height: 600 + function takeOne() + { + gridView.model.remove(2) + } + function takeThree() + { + gridView.model.remove(4) + gridView.model.remove(2) + gridView.model.remove(0) + } + function takeAll() + { + gridView.model.clear() + } + + GridView { + id: gridView + + property bool useDelayRemove + + height: parent.height + width: 400 + cellWidth: width/2 + model: ListModel { + ListElement { name: "A" } + ListElement { name: "B" } + ListElement { name: "C" } + ListElement { name: "D" } + ListElement { name: "E" } + } + delegate: Text { + id: wrapper + height: 100 + text: index + gridView.count + GridView.delayRemove: gridView.useDelayRemove + GridView.onRemove: SequentialAnimation { + PauseAnimation { duration: wrapper.GridView.delayRemove ? 100 : 0 } + PropertyAction { target: wrapper; property: "GridView.delayRemove"; value: false } + } + } + } +} diff --git a/tests/auto/quick/qquickgridview/data/qtbug45640.qml b/tests/auto/quick/qquickgridview/data/qtbug45640.qml new file mode 100644 index 0000000000..6973773432 --- /dev/null +++ b/tests/auto/quick/qquickgridview/data/qtbug45640.qml @@ -0,0 +1,24 @@ +import QtQuick 2.0 + +GridView { + id: gridView + width: 400; height: 400 + cellHeight: 100 + cellWidth: 100 + model: 32 + + topMargin: 50 + snapMode: GridView.SnapToRow + preferredHighlightBegin: 50 + preferredHighlightEnd: 50 + highlightRangeMode: GridView.ApplyRange + + delegate: Rectangle { + width: 100 + height: 100 + color: index % 2 == 0 ? "#FFFF00" : "#0000FF" + } + + highlight: Rectangle { color: "red"; z: 2 } + highlightMoveDuration: 1000 +} diff --git a/tests/auto/quick/qquickgridview/tst_qquickgridview.cpp b/tests/auto/quick/qquickgridview/tst_qquickgridview.cpp index 9472407e01..87042ca7ba 100644 --- a/tests/auto/quick/qquickgridview/tst_qquickgridview.cpp +++ b/tests/auto/quick/qquickgridview/tst_qquickgridview.cpp @@ -206,6 +206,11 @@ private slots: void jsArrayChange(); + void contentHeightWithDelayRemove_data(); + void contentHeightWithDelayRemove(); + + void QTBUG_45640(); + private: QList<int> toIntList(const QVariantList &list); void matchIndexLists(const QVariantList &indexLists, const QList<int> &expectedIndexes); @@ -373,7 +378,7 @@ void tst_QQuickGridView::items() ctxt->setContextProperty("testModel", &model2); int itemCount = findItems<QQuickItem>(contentItem, "wrapper").count(); - QTRY_VERIFY(itemCount == 0); + QTRY_COMPARE(itemCount, 0); delete window; } @@ -473,8 +478,8 @@ void tst_QQuickGridView::inserted_basic() // Confirm items positioned correctly for (int i = 0; i < model.count(); ++i) { QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i); - QTRY_VERIFY(item->x() == (i%3)*80); - QTRY_VERIFY(item->y() == (i/3)*60); + QTRY_COMPARE(item->x(), qreal((i%3)*80)); + QTRY_COMPARE(item->y(), qreal((i/3)*60)); } for (int i = model.count(); i < 30; ++i) @@ -485,7 +490,7 @@ void tst_QQuickGridView::inserted_basic() // Insert item outside visible area model.insertItem(1, "Hello", "1324"); - QTRY_VERIFY(gridview->contentY() == 120); + QTRY_COMPARE(gridview->contentY(), qreal(120)); delete window; } @@ -815,8 +820,8 @@ void tst_QQuickGridView::removed_basic() for (int i = 0; i < model.count() && i < itemCount; ++i) { QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; - QTRY_VERIFY(item->x() == (i%3)*80); - QTRY_VERIFY(item->y() == (i/3)*60); + QTRY_COMPARE(item->x(), qreal((i%3)*80)); + QTRY_COMPARE(item->y(), qreal((i/3)*60)); } // Remove first item (which is the current item); @@ -836,8 +841,8 @@ void tst_QQuickGridView::removed_basic() for (int i = 0; i < model.count() && i < itemCount; ++i) { QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; - QTRY_VERIFY(item->x() == (i%3)*80); - QTRY_VERIFY(item->y() == (i/3)*60); + QTRY_COMPARE(item->x(), qreal((i%3)*80)); + QTRY_COMPARE(item->y(), qreal((i/3)*60)); } // Remove items not visible @@ -849,8 +854,8 @@ void tst_QQuickGridView::removed_basic() for (int i = 0; i < model.count() && i < itemCount; ++i) { QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; - QTRY_VERIFY(item->x() == (i%3)*80); - QTRY_VERIFY(item->y() == (i/3)*60); + QTRY_COMPARE(item->x(), qreal((i%3)*80)); + QTRY_COMPARE(item->y(), qreal((i/3)*60)); } // Remove items before visible @@ -867,8 +872,8 @@ void tst_QQuickGridView::removed_basic() for (int i = 6; i < 18; ++i) { QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; - QTRY_VERIFY(item->x() == (i%3)*80); - QTRY_VERIFY(item->y() == (i/3)*60); + QTRY_COMPARE(item->x(), qreal((i%3)*80)); + QTRY_COMPARE(item->y(), qreal((i/3)*60)); } // Remove currentIndex @@ -886,8 +891,8 @@ void tst_QQuickGridView::removed_basic() itemCount = findItems<QQuickItem>(contentItem, "wrapper").count(); for (int i = 0; i < model.count() && i < itemCount; ++i) { QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i); - QTRY_VERIFY(item->x() == (i%3)*80); - QTRY_VERIFY(item->y() == (i/3)*60); + QTRY_COMPARE(item->x(), qreal((i%3)*80)); + QTRY_COMPARE(item->y(), qreal((i/3)*60)); } // remove item outside current view. @@ -895,7 +900,7 @@ void tst_QQuickGridView::removed_basic() gridview->setContentY(240); model.removeItem(30); - QTRY_VERIFY(gridview->currentIndex() == 31); + QTRY_COMPARE(gridview->currentIndex(), 31); // remove current item beyond visible items. gridview->setCurrentIndex(20); @@ -912,7 +917,7 @@ void tst_QQuickGridView::removed_basic() model.removeItem(6); QTRY_COMPARE(gridview->currentIndex(), 7); - QTRY_VERIFY(gridview->currentItem() == oldCurrent); + QTRY_COMPARE(gridview->currentItem(), oldCurrent); delete window; } @@ -1211,7 +1216,7 @@ void tst_QQuickGridView::addOrRemoveBeforeVisible() for (int i = 0; i < model.count() && i < itemCount; ++i) { QTRY_VERIFY(findItem<QQuickItem>(contentItem, "wrapper", i)); QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i); - QTRY_VERIFY(item->x() == (i%3)*80); + QTRY_COMPARE(item->x(), qreal((i%3)*80)); QTRY_VERIFY(item->y() == (i/3)*60 + newTopContentY); } @@ -1249,10 +1254,10 @@ void tst_QQuickGridView::clear() model.clear(); gridview->forceLayout(); - QVERIFY(gridview->count() == 0); - QVERIFY(gridview->currentItem() == 0); - QVERIFY(gridview->contentY() == 0); - QVERIFY(gridview->currentIndex() == -1); + QCOMPARE(gridview->count(), 0); + QVERIFY(!gridview->currentItem()); + QCOMPARE(gridview->contentY(), qreal(0)); + QCOMPARE(gridview->currentIndex(), -1); QCOMPARE(gridview->contentHeight(), 0.0); // confirm sanity when adding an item to cleared list @@ -1260,7 +1265,7 @@ void tst_QQuickGridView::clear() gridview->forceLayout(); QTRY_COMPARE(gridview->count(), 1); QVERIFY(gridview->currentItem() != 0); - QVERIFY(gridview->currentIndex() == 0); + QCOMPARE(gridview->currentIndex(), 0); delete window; } @@ -1799,7 +1804,7 @@ void tst_QQuickGridView::swapWithFirstItem() // ensure content position is stable gridview->setContentY(0); model.moveItem(10, 0); - QTRY_VERIFY(gridview->contentY() == 0); + QTRY_COMPARE(gridview->contentY(), qreal(0)); delete window; } @@ -1849,7 +1854,7 @@ void tst_QQuickGridView::currentIndex() gridview->setCurrentIndex(35); QTRY_VERIFY(gridview->verticalVelocity() != 0.0); gridview->setCurrentIndex(0); - QTRY_VERIFY(gridview->verticalVelocity() == 0.0); + QTRY_COMPARE(gridview->verticalVelocity(), 0.0); // footer should become visible if it is out of view, and then current index moves to the first row window->rootObject()->setProperty("showFooter", true); @@ -1871,7 +1876,7 @@ void tst_QQuickGridView::currentIndex() // turn off auto highlight gridview->setHighlightFollowsCurrentItem(false); - QVERIFY(gridview->highlightFollowsCurrentItem() == false); + QVERIFY(!gridview->highlightFollowsCurrentItem()); QVERIFY(gridview->highlightItem()); qreal hlPosX = gridview->highlightItem()->x(); qreal hlPosY = gridview->highlightItem()->y(); @@ -1971,7 +1976,7 @@ void tst_QQuickGridView::keyNavigation() window->requestActivate(); QTest::qWaitForWindowActive(window); - QTRY_VERIFY(qGuiApp->focusWindow() == window); + QTRY_COMPARE(qGuiApp->focusWindow(), window); QCOMPARE(gridview->currentIndex(), 0); QTest::keyClick(window, forwardsKey); @@ -2256,15 +2261,15 @@ void tst_QQuickGridView::defaultValues() QQuickGridView *obj = qobject_cast<QQuickGridView*>(c.create()); QTRY_VERIFY(obj != 0); - QTRY_VERIFY(obj->model() == QVariant()); - QTRY_VERIFY(obj->delegate() == 0); + QTRY_COMPARE(obj->model(), QVariant()); + QTRY_VERIFY(!obj->delegate()); QTRY_COMPARE(obj->currentIndex(), -1); - QTRY_VERIFY(obj->currentItem() == 0); + QTRY_VERIFY(!obj->currentItem()); QTRY_COMPARE(obj->count(), 0); - QTRY_VERIFY(obj->highlight() == 0); - QTRY_VERIFY(obj->highlightItem() == 0); + QTRY_VERIFY(!obj->highlight()); + QTRY_VERIFY(!obj->highlightItem()); QTRY_COMPARE(obj->highlightFollowsCurrentItem(), true); - QTRY_VERIFY(obj->flow() == 0); + QTRY_COMPARE(obj->flow(), QQuickGridView::FlowLeftToRight); QTRY_COMPARE(obj->isWrapEnabled(), false); #ifdef QML_VIEW_DEFAULTCACHEBUFFER QTRY_COMPARE(obj->cacheBuffer(), QML_VIEW_DEFAULTCACHEBUFFER); @@ -2291,7 +2296,7 @@ void tst_QQuickGridView::properties() QTRY_VERIFY(obj->highlight() != 0); QTRY_VERIFY(obj->highlightItem() != 0); QTRY_COMPARE(obj->highlightFollowsCurrentItem(), false); - QTRY_VERIFY(obj->flow() == 0); + QTRY_COMPARE(obj->flow(), QQuickGridView::FlowLeftToRight); QTRY_COMPARE(obj->isWrapEnabled(), true); QTRY_COMPARE(obj->cacheBuffer(), 200); QTRY_COMPARE(obj->cellWidth(), qreal(100)); @@ -2728,7 +2733,7 @@ void tst_QQuickGridView::mirroring() foreach (const QString objectName, objectNames) QCOMPARE(findItem<QQuickItem>(gridviewA, objectName)->x(), findItem<QQuickItem>(gridviewB, objectName)->x()); - QVERIFY(gridviewB->layoutDirection() == gridviewB->effectiveLayoutDirection()); + QCOMPARE(gridviewB->layoutDirection(), gridviewB->effectiveLayoutDirection()); QQuickItemPrivate::get(gridviewB)->setLayoutMirror(true); QVERIFY(gridviewB->layoutDirection() != gridviewB->effectiveLayoutDirection()); @@ -3016,7 +3021,7 @@ void tst_QQuickGridView::footer() QQuickText *footer = findItem<QQuickText>(contentItem, "footer"); QVERIFY(footer); - QVERIFY(footer == gridview->footerItem()); + QCOMPARE(footer, gridview->footerItem()); QCOMPARE(footer->position(), initialFooterPos); QCOMPARE(footer->width(), 100.); @@ -3082,7 +3087,7 @@ void tst_QQuickGridView::footer() QVERIFY(!footer); footer = findItem<QQuickText>(contentItem, "footer2"); QVERIFY(footer); - QVERIFY(footer == gridview->footerItem()); + QCOMPARE(footer, gridview->footerItem()); QCOMPARE(footer->position(), changedFooterPos); QCOMPARE(footer->width(), 50.); @@ -3265,7 +3270,7 @@ void tst_QQuickGridView::header() QQuickText *header = findItem<QQuickText>(contentItem, "header"); QVERIFY(header); - QVERIFY(header == gridview->headerItem()); + QCOMPARE(header, gridview->headerItem()); QCOMPARE(header->position(), initialHeaderPos); QCOMPARE(header->width(), 100.); @@ -3302,7 +3307,7 @@ void tst_QQuickGridView::header() header = findItem<QQuickText>(contentItem, "header2"); QVERIFY(header); - QVERIFY(header == gridview->headerItem()); + QCOMPARE(header, gridview->headerItem()); QCOMPARE(header->position(), changedHeaderPos); QCOMPARE(header->width(), 50.); @@ -3609,11 +3614,11 @@ void tst_QQuickGridView::resetModel_headerFooter() // A reset should not force a new header or footer to be created. QQuickItem *newHeader = findItem<QQuickItem>(contentItem, "header"); - QVERIFY(newHeader == header); + QCOMPARE(newHeader, header); QCOMPARE(header->y(), -header->height()); QQuickItem *newFooter = findItem<QQuickItem>(contentItem, "footer"); - QVERIFY(newFooter == footer); + QCOMPARE(newFooter, footer); QCOMPARE(footer->y(), 60.*2); delete window; @@ -4315,8 +4320,19 @@ void tst_QQuickGridView::snapToRow() QQuickItem *contentItem = gridview->contentItem(); QTRY_VERIFY(contentItem != 0); + qreal origContentY = gridview->contentY(); + qreal origContentX = gridview->contentX(); // confirm that a flick hits an item boundary flick(window, flickStart, flickEnd, 180); + + // wait until it's at least one cell further + QTRY_VERIFY(qAbs(gridview->contentX() - origContentX) > 80 || + qAbs(gridview->contentY() - origContentY) > 80); + + // click to stop it. Otherwise we wouldn't know how much further it will go. We don't want to it + // to hit the endExtent, yet. + QTest::mouseClick(window, Qt::LeftButton, 0, flickEnd); + QTRY_VERIFY(gridview->isMoving() == false); // wait until it stops if (flow == QQuickGridView::FlowLeftToRight) QCOMPARE(qreal(fmod(gridview->contentY(),80.0)), snapAlignment); @@ -5810,7 +5826,7 @@ void tst_QQuickGridView::cacheBuffer() window->engine()->setIncubationController(&controller); window->rootObject()->setProperty("cacheBuffer", 200); - QTRY_VERIFY(gridview->cacheBuffer() == 200); + QTRY_COMPARE(gridview->cacheBuffer(), 200); // items will be created one at a time for (int i = itemCount; i < qMin(itemCount+9,model.count()); ++i) { @@ -5910,8 +5926,8 @@ void tst_QQuickGridView::asynchronous() for (int i = 0; i < 12; ++i) { QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; - QVERIFY(item->x() == (i%3)*100); - QVERIFY(item->y() == (i/3)*100); + QCOMPARE(item->x(), qreal((i%3)*100)); + QCOMPARE(item->y(), qreal((i/3)*100)); } delete window; @@ -6329,7 +6345,7 @@ void tst_QQuickGridView::matchIndexLists(const QVariantList &indexLists, const Q void tst_QQuickGridView::matchItemsAndIndexes(const QVariantMap &items, const QaimModel &model, const QList<int> &expectedIndexes) { for (QVariantMap::const_iterator it = items.begin(); it != items.end(); ++it) { - QVERIFY(it.value().type() == QVariant::Int); + QCOMPARE(it.value().type(), QVariant::Int); QString name = it.key(); int itemIndex = it.value().toInt(); QVERIFY2(expectedIndexes.contains(itemIndex), QTest::toString(QString("Index %1 not found in expectedIndexes").arg(itemIndex))); @@ -6460,6 +6476,93 @@ void tst_QQuickGridView::jsArrayChange() QCOMPARE(spy.count(), 1); } +void tst_QQuickGridView::contentHeightWithDelayRemove_data() +{ + QTest::addColumn<bool>("useDelayRemove"); + QTest::addColumn<QByteArray>("removeFunc"); + QTest::addColumn<int>("countDelta"); + QTest::addColumn<qreal>("contentHeightDelta"); + + QTest::newRow("remove without delayRemove") + << false + << QByteArray("takeOne") + << -1 + << qreal(-1 * 100.0); + + QTest::newRow("remove with delayRemove") + << true + << QByteArray("takeOne") + << -1 + << qreal(-1 * 100.0); + + QTest::newRow("remove with multiple delayRemove") + << true + << QByteArray("takeThree") + << -3 + << qreal(-2 * 100.0); + + QTest::newRow("clear with delayRemove") + << true + << QByteArray("takeAll") + << -5 + << qreal(-3 * 100.0); +} + +void tst_QQuickGridView::contentHeightWithDelayRemove() +{ + QFETCH(bool, useDelayRemove); + QFETCH(QByteArray, removeFunc); + QFETCH(int, countDelta); + QFETCH(qreal, contentHeightDelta); + + QQuickView *window = createView(); + window->setSource(testFileUrl("contentHeightWithDelayRemove.qml")); + window->show(); + QVERIFY(QTest::qWaitForWindowExposed(window)); + + QQuickGridView *gridview = window->rootObject()->findChild<QQuickGridView*>(); + QTRY_VERIFY(gridview != 0); + + const int initialCount(gridview->count()); + const int eventualCount(initialCount + countDelta); + + const qreal initialContentHeight(gridview->contentHeight()); + const int eventualContentHeight(qRound(initialContentHeight + contentHeightDelta)); + + gridview->setProperty("useDelayRemove", useDelayRemove); + QMetaObject::invokeMethod(window->rootObject(), removeFunc.constData()); + QTest::qWait(50); + QCOMPARE(gridview->count(), eventualCount); + + if (useDelayRemove) { + QCOMPARE(qRound(gridview->contentHeight()), qRound(initialContentHeight)); + QTRY_COMPARE(qRound(gridview->contentHeight()), eventualContentHeight); + } else { + QCOMPARE(qRound(gridview->contentHeight()), eventualContentHeight); + } + + delete window; +} + +void tst_QQuickGridView::QTBUG_45640() +{ + QQuickView *window = createView(); + window->setSource(testFileUrl("qtbug45640.qml")); + window->show(); + QVERIFY(QTest::qWaitForWindowExposed(window)); + + QQuickGridView *gridview = qobject_cast<QQuickGridView*>(window->rootObject()); + QVERIFY(gridview != 0); + + QCOMPARE(gridview->contentY(), qreal(-50.0)); + + gridview->moveCurrentIndexDown(); + + QTRY_VERIFY(gridview->contentY() > qreal(-50.0) && gridview->contentY() < qreal(0.0)); + + delete window; +} + QTEST_MAIN(tst_QQuickGridView) #include "tst_qquickgridview.moc" diff --git a/tests/auto/quick/qquickimage/tst_qquickimage.cpp b/tests/auto/quick/qquickimage/tst_qquickimage.cpp index ce8b52222d..71e9d747f4 100644 --- a/tests/auto/quick/qquickimage/tst_qquickimage.cpp +++ b/tests/auto/quick/qquickimage/tst_qquickimage.cpp @@ -121,7 +121,7 @@ void tst_qquickimage::noSource() QQuickImage *obj = qobject_cast<QQuickImage*>(component.create()); QVERIFY(obj != 0); QCOMPARE(obj->source(), QUrl()); - QVERIFY(obj->status() == QQuickImage::Null); + QCOMPARE(obj->status(), QQuickImage::Null); QCOMPARE(obj->width(), 0.); QCOMPARE(obj->height(), 0.); QCOMPARE(obj->fillMode(), QQuickImage::Stretch); @@ -168,6 +168,18 @@ void tst_qquickimage::imageSource() QFETCH(bool, cache); QFETCH(QString, error); + +#if defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID) + if (qstrcmp(QTest::currentDataTag(), "remote") == 0 + || qstrcmp(QTest::currentDataTag(), "remote redirected") == 0 + || qstrcmp(QTest::currentDataTag(), "remote svg") == 0 + || qstrcmp(QTest::currentDataTag(), "remote svgz") == 0 + || qstrcmp(QTest::currentDataTag(), "remote not found") == 0 + ) { + QSKIP("Remote tests cause occasional hangs in the CI system -- QTBUG-45655"); + } +#endif + TestHTTPServer server; if (remote) { QVERIFY2(server.listen(), qPrintable(server.errorString())); @@ -189,28 +201,28 @@ void tst_qquickimage::imageSource() QVERIFY(obj != 0); if (async) - QVERIFY(obj->asynchronous() == true); + QVERIFY(obj->asynchronous()); else - QVERIFY(obj->asynchronous() == false); + QVERIFY(!obj->asynchronous()); if (cache) - QVERIFY(obj->cache() == true); + QVERIFY(obj->cache()); else - QVERIFY(obj->cache() == false); + QVERIFY(!obj->cache()); if (remote || async) - QTRY_VERIFY(obj->status() == QQuickImage::Loading); + QTRY_COMPARE(obj->status(), QQuickImage::Loading); QCOMPARE(obj->source(), remote ? source : QUrl(source)); if (error.isEmpty()) { - QTRY_VERIFY(obj->status() == QQuickImage::Ready); + QTRY_COMPARE(obj->status(), QQuickImage::Ready); QCOMPARE(obj->width(), qreal(width)); QCOMPARE(obj->height(), qreal(height)); QCOMPARE(obj->fillMode(), QQuickImage::Stretch); QCOMPARE(obj->progress(), 1.0); } else { - QTRY_VERIFY(obj->status() == QQuickImage::Error); + QTRY_COMPARE(obj->status(), QQuickImage::Error); } delete obj; @@ -225,14 +237,14 @@ void tst_qquickimage::clearSource() component.setData(componentStr.toLatin1(), QUrl::fromLocalFile("")); QQuickImage *obj = qobject_cast<QQuickImage*>(component.create()); QVERIFY(obj != 0); - QVERIFY(obj->status() == QQuickImage::Ready); + QCOMPARE(obj->status(), QQuickImage::Ready); QCOMPARE(obj->width(), 120.); QCOMPARE(obj->height(), 120.); QCOMPARE(obj->progress(), 1.0); ctxt->setContextProperty("srcImage", ""); QVERIFY(obj->source().isEmpty()); - QVERIFY(obj->status() == QQuickImage::Null); + QCOMPARE(obj->status(), QQuickImage::Null); QCOMPARE(obj->width(), 0.); QCOMPARE(obj->height(), 0.); QCOMPARE(obj->progress(), 0.0); @@ -533,7 +545,7 @@ void tst_qquickimage::noLoading() component.setData(componentStr.toLatin1(), QUrl::fromLocalFile("")); QQuickImage *obj = qobject_cast<QQuickImage*>(component.create()); QVERIFY(obj != 0); - QVERIFY(obj->status() == QQuickImage::Ready); + QCOMPARE(obj->status(), QQuickImage::Ready); QSignalSpy sourceSpy(obj, SIGNAL(sourceChanged(QUrl))); QSignalSpy progressSpy(obj, SIGNAL(progressChanged(qreal))); @@ -541,29 +553,30 @@ void tst_qquickimage::noLoading() // Loading local file ctxt->setContextProperty("srcImage", testFileUrl("green.png")); - QTRY_VERIFY(obj->status() == QQuickImage::Ready); - QTRY_VERIFY(obj->progress() == 1.0); + QTRY_COMPARE(obj->status(), QQuickImage::Ready); + QTRY_COMPARE(obj->progress(), 1.0); QTRY_COMPARE(sourceSpy.count(), 1); QTRY_COMPARE(progressSpy.count(), 0); QTRY_COMPARE(statusSpy.count(), 1); // Loading remote file ctxt->setContextProperty("srcImage", server.url("/rect.png")); - QTRY_VERIFY(obj->status() == QQuickImage::Loading); - QTRY_VERIFY(obj->progress() == 0.0); - QTRY_VERIFY(obj->status() == QQuickImage::Ready); - QTRY_VERIFY(obj->progress() == 1.0); + QTRY_COMPARE(obj->status(), QQuickImage::Loading); + QTRY_COMPARE(obj->progress(), 0.0); + QTRY_COMPARE(obj->status(), QQuickImage::Ready); + QTRY_COMPARE(obj->progress(), 1.0); QTRY_COMPARE(sourceSpy.count(), 2); - QTRY_COMPARE(progressSpy.count(), 2); + QTRY_VERIFY(progressSpy.count() >= 2); QTRY_COMPARE(statusSpy.count(), 3); // Loading remote file again - should not go through 'Loading' state. + progressSpy.clear(); ctxt->setContextProperty("srcImage", testFileUrl("green.png")); ctxt->setContextProperty("srcImage", server.url("/rect.png")); - QTRY_VERIFY(obj->status() == QQuickImage::Ready); - QTRY_VERIFY(obj->progress() == 1.0); + QTRY_COMPARE(obj->status(), QQuickImage::Ready); + QTRY_COMPARE(obj->progress(), 1.0); QTRY_COMPARE(sourceSpy.count(), 4); - QTRY_COMPARE(progressSpy.count(), 2); + QTRY_COMPARE(progressSpy.count(), 0); QTRY_COMPARE(statusSpy.count(), 5); delete obj; @@ -615,7 +628,7 @@ void tst_qquickimage::sourceSize_QTBUG_14303() QSignalSpy sourceSizeSpy(obj, SIGNAL(sourceSizeChanged())); QTRY_VERIFY(obj != 0); - QTRY_VERIFY(obj->status() == QQuickImage::Ready); + QTRY_COMPARE(obj->status(), QQuickImage::Ready); QTRY_COMPARE(obj->sourceSize().width(), 200); QTRY_COMPARE(obj->sourceSize().height(), 200); @@ -831,8 +844,8 @@ void tst_qquickimage::progressAndStatusChanges() component.setData(componentStr.toLatin1(), QUrl::fromLocalFile("")); QQuickImage *obj = qobject_cast<QQuickImage*>(component.create()); QVERIFY(obj != 0); - QVERIFY(obj->status() == QQuickImage::Ready); - QTRY_VERIFY(obj->progress() == 1.0); + QCOMPARE(obj->status(), QQuickImage::Ready); + QTRY_COMPARE(obj->progress(), 1.0); qRegisterMetaType<QQuickImageBase::Status>(); QSignalSpy sourceSpy(obj, SIGNAL(sourceChanged(QUrl))); @@ -841,33 +854,33 @@ void tst_qquickimage::progressAndStatusChanges() // Same image ctxt->setContextProperty("srcImage", testFileUrl("heart.png")); - QTRY_VERIFY(obj->status() == QQuickImage::Ready); - QTRY_VERIFY(obj->progress() == 1.0); + QTRY_COMPARE(obj->status(), QQuickImage::Ready); + QTRY_COMPARE(obj->progress(), 1.0); QTRY_COMPARE(sourceSpy.count(), 0); QTRY_COMPARE(progressSpy.count(), 0); QTRY_COMPARE(statusSpy.count(), 0); // Loading local file ctxt->setContextProperty("srcImage", testFileUrl("colors.png")); - QTRY_VERIFY(obj->status() == QQuickImage::Ready); - QTRY_VERIFY(obj->progress() == 1.0); + QTRY_COMPARE(obj->status(), QQuickImage::Ready); + QTRY_COMPARE(obj->progress(), 1.0); QTRY_COMPARE(sourceSpy.count(), 1); QTRY_COMPARE(progressSpy.count(), 0); QTRY_COMPARE(statusSpy.count(), 1); // Loading remote file ctxt->setContextProperty("srcImage", server.url("/heart.png")); - QTRY_VERIFY(obj->status() == QQuickImage::Loading); - QTRY_VERIFY(obj->progress() == 0.0); - QTRY_VERIFY(obj->status() == QQuickImage::Ready); - QTRY_VERIFY(obj->progress() == 1.0); + QTRY_COMPARE(obj->status(), QQuickImage::Loading); + QTRY_COMPARE(obj->progress(), 0.0); + QTRY_COMPARE(obj->status(), QQuickImage::Ready); + QTRY_COMPARE(obj->progress(), 1.0); QTRY_COMPARE(sourceSpy.count(), 2); QTRY_VERIFY(progressSpy.count() > 1); QTRY_COMPARE(statusSpy.count(), 3); ctxt->setContextProperty("srcImage", ""); - QTRY_VERIFY(obj->status() == QQuickImage::Null); - QTRY_VERIFY(obj->progress() == 0.0); + QTRY_COMPARE(obj->status(), QQuickImage::Null); + QTRY_COMPARE(obj->progress(), 0.0); QTRY_COMPARE(sourceSpy.count(), 3); QTRY_VERIFY(progressSpy.count() > 2); QTRY_COMPARE(statusSpy.count(), 4); diff --git a/tests/auto/quick/qquickimageprovider/tst_qquickimageprovider.cpp b/tests/auto/quick/qquickimageprovider/tst_qquickimageprovider.cpp index dae46b5c3d..644f2be129 100644 --- a/tests/auto/quick/qquickimageprovider/tst_qquickimageprovider.cpp +++ b/tests/auto/quick/qquickimageprovider/tst_qquickimageprovider.cpp @@ -37,6 +37,7 @@ #include <private/qquickimage_p.h> #include <QImageReader> #include <QWaitCondition> +#include <QThreadPool> Q_DECLARE_METATYPE(QQuickImageProvider*); @@ -68,6 +69,8 @@ private slots: void threadTest(); + void asyncTextureTest(); + private: QString newImageFileName() const; void fillRequestTestsData(const QString &id); @@ -234,15 +237,15 @@ void tst_qquickimageprovider::runTest(bool async, QQuickImageProvider *provider) async |= (provider->flags() & QQuickImageProvider::ForceAsynchronousImageLoading) != 0; if (async) - QTRY_VERIFY(obj->status() == QQuickImage::Loading); + QTRY_COMPARE(obj->status(), QQuickImage::Loading); QCOMPARE(obj->source(), QUrl(source)); if (error.isEmpty()) { if (async) - QTRY_VERIFY(obj->status() == QQuickImage::Ready); + QTRY_COMPARE(obj->status(), QQuickImage::Ready); else - QVERIFY(obj->status() == QQuickImage::Ready); + QCOMPARE(obj->status(), QQuickImage::Ready); if (QByteArray(QTest::currentDataTag()).startsWith("qimage")) QCOMPARE(static_cast<TestQImageProvider*>(provider)->lastImageId, imageId); else @@ -254,9 +257,9 @@ void tst_qquickimageprovider::runTest(bool async, QQuickImageProvider *provider) QCOMPARE(obj->progress(), 1.0); } else { if (async) - QTRY_VERIFY(obj->status() == QQuickImage::Error); + QTRY_COMPARE(obj->status(), QQuickImage::Error); else - QVERIFY(obj->status() == QQuickImage::Error); + QCOMPARE(obj->status(), QQuickImage::Error); } delete obj; @@ -453,7 +456,102 @@ void tst_qquickimageprovider::threadTest() provider->cond.wakeAll(); QTest::qWait(250); foreach (QQuickImage *img, images) { - QTRY_VERIFY(img->status() == QQuickImage::Ready); + QTRY_COMPARE(img->status(), QQuickImage::Ready); + } +} + +class TestImageResponse : public QQuickImageResponse, public QRunnable +{ + public: + TestImageResponse(QMutex *lock, QWaitCondition *condition, bool *ok, const QString &id, const QSize &requestedSize) + : m_lock(lock), m_condition(condition), m_ok(ok), m_id(id), m_requestedSize(requestedSize), m_texture(0) + { + setAutoDelete(false); + } + + QQuickTextureFactory *textureFactory() const + { + return m_texture; + } + + void run() + { + m_lock->lock(); + if (!(*m_ok)) { + m_condition->wait(m_lock); + } + m_lock->unlock(); + QImage image(50, 50, QImage::Format_RGB32); + image.fill(QColor(m_id).rgb()); + if (m_requestedSize.isValid()) + image = image.scaled(m_requestedSize); + m_texture = QQuickTextureFactory::textureFactoryForImage(image); + emit finished(); + } + + QMutex *m_lock; + QWaitCondition *m_condition; + bool *m_ok; + QString m_id; + QSize m_requestedSize; + QQuickTextureFactory *m_texture; +}; + +class TestAsyncProvider : public QQuickAsyncImageProvider +{ + public: + TestAsyncProvider() : ok(false) + { + pool.setMaxThreadCount(4); + } + + ~TestAsyncProvider() {} + + QQuickImageResponse *requestImageResponse(const QString &id, const QSize &requestedSize) + { + TestImageResponse *response = new TestImageResponse(&lock, &condition, &ok, id, requestedSize); + pool.start(response); + return response; + } + + QThreadPool pool; + QMutex lock; + QWaitCondition condition; + bool ok; +}; + + +void tst_qquickimageprovider::asyncTextureTest() +{ + QQmlEngine engine; + + TestAsyncProvider *provider = new TestAsyncProvider; + + engine.addImageProvider("test_async", provider); + QVERIFY(engine.imageProvider("test_async") != 0); + + QString componentStr = "import QtQuick 2.0\nItem { \n" + "Image { source: \"image://test_async/blue\"; }\n" + "Image { source: \"image://test_async/red\"; }\n" + "Image { source: \"image://test_async/green\"; }\n" + "Image { source: \"image://test_async/yellow\"; }\n" + " }"; + QQmlComponent component(&engine); + component.setData(componentStr.toLatin1(), QUrl::fromLocalFile("")); + QObject *obj = component.create(); + //MUST not deadlock + QVERIFY(obj != 0); + QList<QQuickImage *> images = obj->findChildren<QQuickImage *>(); + QCOMPARE(images.count(), 4); + + QTRY_COMPARE(provider->pool.activeThreadCount(), 4); + foreach (QQuickImage *img, images) { + QTRY_COMPARE(img->status(), QQuickImage::Loading); + } + provider->ok = true; + provider->condition.wakeAll(); + foreach (QQuickImage *img, images) { + QTRY_COMPARE(img->status(), QQuickImage::Ready); } } diff --git a/tests/auto/quick/qquickitem/BLACKLIST b/tests/auto/quick/qquickitem/BLACKLIST new file mode 100644 index 0000000000..d94a3ef102 --- /dev/null +++ b/tests/auto/quick/qquickitem/BLACKLIST @@ -0,0 +1,2 @@ +[contains:hollow square: testing points inside] +xcb diff --git a/tests/auto/quick/qquickitem/tst_qquickitem.cpp b/tests/auto/quick/qquickitem/tst_qquickitem.cpp index c79af91747..73e691b08c 100644 --- a/tests/auto/quick/qquickitem/tst_qquickitem.cpp +++ b/tests/auto/quick/qquickitem/tst_qquickitem.cpp @@ -276,7 +276,7 @@ void tst_qquickitem::simpleFocus() QQuickWindow window; ensureFocus(&window); - QTRY_VERIFY(QGuiApplication::focusWindow() == &window); + QTRY_COMPARE(QGuiApplication::focusWindow(), &window); QQuickItem *l1c1 = new TestItem(window.contentItem()); QQuickItem *l1c2 = new TestItem(window.contentItem()); @@ -327,7 +327,7 @@ void tst_qquickitem::scopedFocus() { QQuickWindow window; ensureFocus(&window); - QTRY_VERIFY(QGuiApplication::focusWindow() == &window); + QTRY_COMPARE(QGuiApplication::focusWindow(), &window); QQuickItem *l1c1 = new TestItem(window.contentItem()); QQuickItem *l1c2 = new TestItem(window.contentItem()); @@ -407,7 +407,7 @@ void tst_qquickitem::addedToWindow() { QQuickWindow window; ensureFocus(&window); - QTRY_VERIFY(QGuiApplication::focusWindow() == &window); + QTRY_COMPARE(QGuiApplication::focusWindow(), &window); QQuickItem *item = new TestItem; @@ -427,7 +427,7 @@ void tst_qquickitem::addedToWindow() { QQuickWindow window; ensureFocus(&window); - QTRY_VERIFY(QGuiApplication::focusWindow() == &window); + QTRY_COMPARE(QGuiApplication::focusWindow(), &window); QQuickItem *item = new TestItem(window.contentItem()); @@ -456,7 +456,7 @@ void tst_qquickitem::addedToWindow() { QQuickWindow window; ensureFocus(&window); - QTRY_VERIFY(QGuiApplication::focusWindow() == &window); + QTRY_COMPARE(QGuiApplication::focusWindow(), &window); QQuickItem *tree = new TestItem; QQuickItem *c1 = new TestItem(tree); @@ -480,7 +480,7 @@ void tst_qquickitem::addedToWindow() { QQuickWindow window; ensureFocus(&window); - QTRY_VERIFY(QGuiApplication::focusWindow() == &window); + QTRY_COMPARE(QGuiApplication::focusWindow(), &window); QQuickItem *tree = new TestFocusScope; QQuickItem *c1 = new TestItem(tree); QQuickItem *c2 = new TestItem(tree); @@ -508,7 +508,7 @@ void tst_qquickitem::addedToWindow() { QQuickWindow window; ensureFocus(&window); - QTRY_VERIFY(QGuiApplication::focusWindow() == &window); + QTRY_COMPARE(QGuiApplication::focusWindow(), &window); QQuickItem *tree = new TestFocusScope; QQuickItem *c1 = new TestItem(tree); QQuickItem *c2 = new TestItem(tree); @@ -534,7 +534,7 @@ void tst_qquickitem::addedToWindow() { QQuickWindow window; ensureFocus(&window); - QTRY_VERIFY(QGuiApplication::focusWindow() == &window); + QTRY_COMPARE(QGuiApplication::focusWindow(), &window); QQuickItem *child = new TestItem(window.contentItem()); QQuickItem *tree = new TestFocusScope; QQuickItem *c1 = new TestItem(tree); @@ -574,7 +574,7 @@ void tst_qquickitem::changeParent() { QQuickWindow window; ensureFocus(&window); - QTRY_VERIFY(QGuiApplication::focusWindow() == &window); + QTRY_COMPARE(QGuiApplication::focusWindow(), &window); QQuickItem *child = new TestItem(window.contentItem()); FocusState focusState; @@ -596,7 +596,7 @@ void tst_qquickitem::changeParent() { QQuickWindow window; ensureFocus(&window); - QTRY_VERIFY(QGuiApplication::focusWindow() == &window); + QTRY_COMPARE(QGuiApplication::focusWindow(), &window); QQuickItem *child = new TestItem(window.contentItem()); QQuickItem *child2 = new TestItem(window.contentItem()); @@ -617,7 +617,7 @@ void tst_qquickitem::changeParent() { QQuickWindow window; ensureFocus(&window); - QTRY_VERIFY(QGuiApplication::focusWindow() == &window); + QTRY_COMPARE(QGuiApplication::focusWindow(), &window); QQuickItem *child = new TestItem(window.contentItem()); QQuickItem *child2 = new TestFocusScope(window.contentItem()); QQuickItem *item = new TestItem(child); @@ -639,7 +639,7 @@ void tst_qquickitem::changeParent() { QQuickWindow window; ensureFocus(&window); - QTRY_VERIFY(QGuiApplication::focusWindow() == &window); + QTRY_COMPARE(QGuiApplication::focusWindow(), &window); QQuickItem *child = new TestItem(window.contentItem()); QQuickItem *child2 = new TestFocusScope(window.contentItem()); QQuickItem *item = new TestItem(child2); @@ -661,7 +661,7 @@ void tst_qquickitem::changeParent() { QQuickWindow window; ensureFocus(&window); - QTRY_VERIFY(QGuiApplication::focusWindow() == &window); + QTRY_COMPARE(QGuiApplication::focusWindow(), &window); QQuickItem *child = new TestItem(window.contentItem()); QQuickItem *child2 = new TestFocusScope(window.contentItem()); QQuickItem *item = new TestItem(child2); @@ -687,7 +687,7 @@ void tst_qquickitem::changeParent() { QQuickWindow window; ensureFocus(&window); - QTRY_VERIFY(QGuiApplication::focusWindow() == &window); + QTRY_COMPARE(QGuiApplication::focusWindow(), &window); QQuickItem *item = new TestFocusScope(window.contentItem()); QQuickItem *child = new TestItem(item); QQuickItem *child2 = new TestItem; @@ -726,7 +726,7 @@ void tst_qquickitem::multipleFocusClears() view.setSource(testFileUrl("multipleFocusClears.qml")); view.show(); ensureFocus(&view); - QTRY_VERIFY(QGuiApplication::focusWindow() == &view); + QTRY_COMPARE(QGuiApplication::focusWindow(), &view); } void tst_qquickitem::focusSubItemInNonFocusScope() @@ -757,7 +757,7 @@ void tst_qquickitem::parentItemWithFocus() { QQuickWindow window; ensureFocus(&window); - QTRY_VERIFY(QGuiApplication::focusWindow() == &window); + QTRY_COMPARE(QGuiApplication::focusWindow(), &window); { QQuickItem parent; QQuickItem child; @@ -856,7 +856,7 @@ void tst_qquickitem::reparentFocusedItem() { QQuickWindow window; ensureFocus(&window); - QTRY_VERIFY(QGuiApplication::focusWindow() == &window); + QTRY_COMPARE(QGuiApplication::focusWindow(), &window); QQuickItem parent(window.contentItem()); QQuickItem child(&parent); @@ -883,18 +883,18 @@ void tst_qquickitem::reparentFocusedItem() void tst_qquickitem::constructor() { QScopedPointer<QQuickItem> root(new QQuickItem); - QVERIFY(root->parent() == 0); - QVERIFY(root->parentItem() == 0); + QVERIFY(!root->parent()); + QVERIFY(!root->parentItem()); QQuickItem *child1 = new QQuickItem(root.data()); - QVERIFY(child1->parent() == root.data()); - QVERIFY(child1->parentItem() == root.data()); + QCOMPARE(child1->parent(), root.data()); + QCOMPARE(child1->parentItem(), root.data()); QCOMPARE(root->childItems().count(), 1); QCOMPARE(root->childItems().at(0), child1); QQuickItem *child2 = new QQuickItem(root.data()); - QVERIFY(child2->parent() == root.data()); - QVERIFY(child2->parentItem() == root.data()); + QCOMPARE(child2->parent(), root.data()); + QCOMPARE(child2->parentItem(), root.data()); QCOMPARE(root->childItems().count(), 2); QCOMPARE(root->childItems().at(0), child1); QCOMPARE(root->childItems().at(1), child2); @@ -903,41 +903,41 @@ void tst_qquickitem::constructor() void tst_qquickitem::setParentItem() { QQuickItem *root = new QQuickItem; - QVERIFY(root->parent() == 0); - QVERIFY(root->parentItem() == 0); + QVERIFY(!root->parent()); + QVERIFY(!root->parentItem()); QQuickItem *child1 = new QQuickItem; - QVERIFY(child1->parent() == 0); - QVERIFY(child1->parentItem() == 0); + QVERIFY(!child1->parent()); + QVERIFY(!child1->parentItem()); child1->setParentItem(root); - QVERIFY(child1->parent() == 0); - QVERIFY(child1->parentItem() == root); + QVERIFY(!child1->parent()); + QCOMPARE(child1->parentItem(), root); QCOMPARE(root->childItems().count(), 1); QCOMPARE(root->childItems().at(0), child1); QQuickItem *child2 = new QQuickItem; - QVERIFY(child2->parent() == 0); - QVERIFY(child2->parentItem() == 0); + QVERIFY(!child2->parent()); + QVERIFY(!child2->parentItem()); child2->setParentItem(root); - QVERIFY(child2->parent() == 0); - QVERIFY(child2->parentItem() == root); + QVERIFY(!child2->parent()); + QCOMPARE(child2->parentItem(), root); QCOMPARE(root->childItems().count(), 2); QCOMPARE(root->childItems().at(0), child1); QCOMPARE(root->childItems().at(1), child2); child1->setParentItem(0); - QVERIFY(child1->parent() == 0); - QVERIFY(child1->parentItem() == 0); + QVERIFY(!child1->parent()); + QVERIFY(!child1->parentItem()); QCOMPARE(root->childItems().count(), 1); QCOMPARE(root->childItems().at(0), child2); delete root; - QVERIFY(child1->parent() == 0); - QVERIFY(child1->parentItem() == 0); - QVERIFY(child2->parent() == 0); - QVERIFY(child2->parentItem() == 0); + QVERIFY(!child1->parent()); + QVERIFY(!child1->parentItem()); + QVERIFY(!child2->parent()); + QVERIFY(!child2->parentItem()); delete child1; delete child2; diff --git a/tests/auto/quick/qquickitem2/tst_qquickitem.cpp b/tests/auto/quick/qquickitem2/tst_qquickitem.cpp index 69c7250134..396f183860 100644 --- a/tests/auto/quick/qquickitem2/tst_qquickitem.cpp +++ b/tests/auto/quick/qquickitem2/tst_qquickitem.cpp @@ -319,7 +319,7 @@ void tst_QQuickItem::activeFocusOnTab() window->show(); window->requestActivate(); QVERIFY(QTest::qWaitForWindowActive(window)); - QVERIFY(QGuiApplication::focusWindow() == window); + QCOMPARE(QGuiApplication::focusWindow(), window); // original: button12 QQuickItem *item = findItem<QQuickItem>(window->rootObject(), "button12"); @@ -431,7 +431,7 @@ void tst_QQuickItem::activeFocusOnTab2() window->show(); window->requestActivate(); QVERIFY(QTest::qWaitForWindowActive(window)); - QVERIFY(QGuiApplication::focusWindow() == window); + QCOMPARE(QGuiApplication::focusWindow(), window); // original: button12 QQuickItem *item = findItem<QQuickItem>(window->rootObject(), "button12"); @@ -471,7 +471,7 @@ void tst_QQuickItem::activeFocusOnTab3() window->show(); window->requestActivate(); QVERIFY(QTest::qWaitForWindowActive(window)); - QVERIFY(QGuiApplication::focusWindow() == window); + QCOMPARE(QGuiApplication::focusWindow(), window); // original: button1 QQuickItem *item = findItem<QQuickItem>(window->rootObject(), "button1"); @@ -653,7 +653,7 @@ void tst_QQuickItem::activeFocusOnTab4() window->show(); window->requestActivate(); QVERIFY(QTest::qWaitForWindowActive(window)); - QVERIFY(QGuiApplication::focusWindow() == window); + QCOMPARE(QGuiApplication::focusWindow(), window); // original: button11 QQuickItem *item = findItem<QQuickItem>(window->rootObject(), "button11"); @@ -685,7 +685,7 @@ void tst_QQuickItem::activeFocusOnTab5() window->show(); window->requestActivate(); QVERIFY(QTest::qWaitForWindowActive(window)); - QVERIFY(QGuiApplication::focusWindow() == window); + QCOMPARE(QGuiApplication::focusWindow(), window); // original: button11 in sub1 QQuickItem *item = findItem<QQuickItem>(window->rootObject(), "button11"); @@ -719,7 +719,7 @@ void tst_QQuickItem::activeFocusOnTab6() window->show(); window->requestActivate(); QVERIFY(QTest::qWaitForWindowActive(window)); - QVERIFY(QGuiApplication::focusWindow() == window); + QCOMPARE(QGuiApplication::focusWindow(), window); // original: button12 QQuickItem *item = findItem<QQuickItem>(window->rootObject(), "button12"); @@ -777,7 +777,7 @@ void tst_QQuickItem::activeFocusOnTab7() window->show(); window->requestActivate(); QVERIFY(QTest::qWaitForWindowActive(window)); - QVERIFY(QGuiApplication::focusWindow() == window); + QCOMPARE(QGuiApplication::focusWindow(), window); QQuickItem *item = findItem<QQuickItem>(window->rootObject(), "button1"); QVERIFY(item); @@ -810,7 +810,7 @@ void tst_QQuickItem::activeFocusOnTab8() window->show(); window->requestActivate(); QVERIFY(QTest::qWaitForWindowActive(window)); - QVERIFY(QGuiApplication::focusWindow() == window); + QCOMPARE(QGuiApplication::focusWindow(), window); QQuickItem *content = window->contentItem(); QVERIFY(content); @@ -862,7 +862,7 @@ void tst_QQuickItem::activeFocusOnTab9() window->show(); window->requestActivate(); QVERIFY(QTest::qWaitForWindowActive(window)); - QVERIFY(QGuiApplication::focusWindow() == window); + QCOMPARE(QGuiApplication::focusWindow(), window); QQuickItem *content = window->contentItem(); QVERIFY(content); @@ -913,7 +913,7 @@ void tst_QQuickItem::activeFocusOnTab10() window->show(); window->requestActivate(); QVERIFY(QTest::qWaitForWindowActive(window)); - QVERIFY(QGuiApplication::focusWindow() == window); + QCOMPARE(QGuiApplication::focusWindow(), window); QQuickItem *content = window->contentItem(); QVERIFY(content); @@ -996,7 +996,7 @@ void tst_QQuickItem::nextItemInFocusChain() window->show(); window->requestActivate(); QVERIFY(QTest::qWaitForWindowActive(window)); - QVERIFY(QGuiApplication::focusWindow() == window); + QCOMPARE(QGuiApplication::focusWindow(), window); QQuickItem *button11 = findItem<QQuickItem>(window->rootObject(), "button11"); QVERIFY(button11); @@ -1072,7 +1072,7 @@ void tst_QQuickItem::nextItemInFocusChain2() window->show(); window->requestActivate(); QVERIFY(QTest::qWaitForWindowActive(window)); - QVERIFY(QGuiApplication::focusWindow() == window); + QCOMPARE(QGuiApplication::focusWindow(), window); QQuickItem *button11 = findItem<QQuickItem>(window->rootObject(), "button11"); QVERIFY(button11); @@ -1117,7 +1117,7 @@ void tst_QQuickItem::nextItemInFocusChain3() window->show(); window->requestActivate(); QVERIFY(QTest::qWaitForWindowActive(window)); - QVERIFY(QGuiApplication::focusWindow() == window); + QCOMPARE(QGuiApplication::focusWindow(), window); } void tst_QQuickItem::keys() @@ -1135,7 +1135,7 @@ void tst_QQuickItem::keys() window->show(); window->requestActivate(); QVERIFY(QTest::qWaitForWindowActive(window)); - QVERIFY(QGuiApplication::focusWindow() == window); + QCOMPARE(QGuiApplication::focusWindow(), window); QVERIFY(window->rootObject()); QCOMPARE(window->rootObject()->property("isEnabled").toBool(), true); @@ -1145,7 +1145,7 @@ void tst_QQuickItem::keys() QCOMPARE(testObject->mKey, int(Qt::Key_A)); QCOMPARE(testObject->mForwardedKey, int(Qt::Key_A)); QCOMPARE(testObject->mText, QLatin1String("A")); - QVERIFY(testObject->mModifiers == Qt::NoModifier); + QCOMPARE(testObject->mModifiers, int(Qt::NoModifier)); QVERIFY(!key.isAccepted()); testObject->reset(); @@ -1155,7 +1155,7 @@ void tst_QQuickItem::keys() QCOMPARE(testObject->mKey, int(Qt::Key_A)); QCOMPARE(testObject->mForwardedKey, int(Qt::Key_A)); QCOMPARE(testObject->mText, QLatin1String("A")); - QVERIFY(testObject->mModifiers == Qt::ShiftModifier); + QCOMPARE(testObject->mModifiers, int(Qt::ShiftModifier)); QVERIFY(key.isAccepted()); testObject->reset(); @@ -1165,7 +1165,7 @@ void tst_QQuickItem::keys() QCOMPARE(testObject->mKey, int(Qt::Key_Return)); QCOMPARE(testObject->mForwardedKey, int(Qt::Key_Return)); QCOMPARE(testObject->mText, QLatin1String("Return")); - QVERIFY(testObject->mModifiers == Qt::NoModifier); + QCOMPARE(testObject->mModifiers, int(Qt::NoModifier)); QVERIFY(key.isAccepted()); testObject->reset(); @@ -1175,7 +1175,7 @@ void tst_QQuickItem::keys() QCOMPARE(testObject->mKey, int(Qt::Key_0)); QCOMPARE(testObject->mForwardedKey, int(Qt::Key_0)); QCOMPARE(testObject->mText, QLatin1String("0")); - QVERIFY(testObject->mModifiers == Qt::NoModifier); + QCOMPARE(testObject->mModifiers, int(Qt::NoModifier)); QVERIFY(key.isAccepted()); testObject->reset(); @@ -1185,7 +1185,7 @@ void tst_QQuickItem::keys() QCOMPARE(testObject->mKey, int(Qt::Key_9)); QCOMPARE(testObject->mForwardedKey, int(Qt::Key_9)); QCOMPARE(testObject->mText, QLatin1String("9")); - QVERIFY(testObject->mModifiers == Qt::NoModifier); + QCOMPARE(testObject->mModifiers, int(Qt::NoModifier)); QVERIFY(!key.isAccepted()); testObject->reset(); @@ -1195,7 +1195,7 @@ void tst_QQuickItem::keys() QCOMPARE(testObject->mKey, int(Qt::Key_Tab)); QCOMPARE(testObject->mForwardedKey, int(Qt::Key_Tab)); QCOMPARE(testObject->mText, QLatin1String("Tab")); - QVERIFY(testObject->mModifiers == Qt::NoModifier); + QCOMPARE(testObject->mModifiers, int(Qt::NoModifier)); QVERIFY(key.isAccepted()); testObject->reset(); @@ -1205,7 +1205,7 @@ void tst_QQuickItem::keys() QCOMPARE(testObject->mKey, int(Qt::Key_Backtab)); QCOMPARE(testObject->mForwardedKey, int(Qt::Key_Backtab)); QCOMPARE(testObject->mText, QLatin1String("Backtab")); - QVERIFY(testObject->mModifiers == Qt::NoModifier); + QCOMPARE(testObject->mModifiers, int(Qt::NoModifier)); QVERIFY(key.isAccepted()); testObject->reset(); @@ -1214,8 +1214,8 @@ void tst_QQuickItem::keys() QGuiApplication::sendEvent(window, &key); QCOMPARE(testObject->mKey, int(Qt::Key_VolumeUp)); QCOMPARE(testObject->mForwardedKey, int(Qt::Key_VolumeUp)); - QVERIFY(testObject->mModifiers == Qt::NoModifier); - QVERIFY(testObject->mNativeScanCode == 1234); + QCOMPARE(testObject->mModifiers, int(Qt::NoModifier)); + QCOMPARE(testObject->mNativeScanCode, quint32(1234)); QVERIFY(key.isAccepted()); testObject->reset(); @@ -1226,7 +1226,7 @@ void tst_QQuickItem::keys() QCOMPARE(testObject->mKey, int(Qt::Key_A)); QCOMPARE(testObject->mForwardedKey, 0); QCOMPARE(testObject->mText, QLatin1String("A")); - QVERIFY(testObject->mModifiers == Qt::NoModifier); + QCOMPARE(testObject->mModifiers, int(Qt::NoModifier)); QVERIFY(!key.isAccepted()); testObject->reset(); @@ -1321,7 +1321,7 @@ void tst_QQuickItem::keysProcessingOrder() window->show(); window->requestActivate(); QVERIFY(QTest::qWaitForWindowActive(window)); - QVERIFY(QGuiApplication::focusWindow() == window); + QCOMPARE(QGuiApplication::focusWindow(), window); KeyTestItem *testItem = qobject_cast<KeyTestItem*>(window->rootObject()); QVERIFY(testItem); @@ -1332,7 +1332,7 @@ void tst_QQuickItem::keysProcessingOrder() QGuiApplication::sendEvent(window, &key); QCOMPARE(testObject->mKey, int(Qt::Key_A)); QCOMPARE(testObject->mText, QLatin1String("A")); - QVERIFY(testObject->mModifiers == Qt::NoModifier); + QCOMPARE(testObject->mModifiers, int(Qt::NoModifier)); QVERIFY(key.isAccepted()); testObject->reset(); @@ -1352,7 +1352,7 @@ void tst_QQuickItem::keysProcessingOrder() QGuiApplication::sendEvent(window, &key); QCOMPARE(testObject->mKey, int(Qt::Key_B)); QCOMPARE(testObject->mText, QLatin1String("B")); - QVERIFY(testObject->mModifiers == Qt::NoModifier); + QCOMPARE(testObject->mModifiers, int(Qt::NoModifier)); QVERIFY(!key.isAccepted()); testObject->reset(); @@ -1379,7 +1379,7 @@ void tst_QQuickItem::keysim() window->show(); window->requestActivate(); QVERIFY(QTest::qWaitForWindowActive(window)); - QVERIFY(QGuiApplication::focusWindow() == window); + QCOMPARE(QGuiApplication::focusWindow(), window); QVERIFY(window->rootObject()); QVERIFY(window->rootObject()->hasFocus() && window->rootObject()->hasActiveFocus()); @@ -1405,7 +1405,7 @@ void tst_QQuickItem::keysForward() window.show(); window.requestActivate(); QVERIFY(QTest::qWaitForWindowActive(&window)); - QVERIFY(QGuiApplication::focusWindow() == &window); + QCOMPARE(QGuiApplication::focusWindow(), &window); QQuickItem *rootItem = qobject_cast<QQuickItem *>(window.rootObject()); QVERIFY(rootItem); @@ -1645,7 +1645,7 @@ void tst_QQuickItem::keyNavigation() window->show(); window->requestActivate(); QVERIFY(QTest::qWaitForWindowActive(window)); - QVERIFY(QGuiApplication::focusWindow() == window); + QCOMPARE(QGuiApplication::focusWindow(), window); QQuickItem *item = findItem<QQuickItem>(window->rootObject(), "item1"); QVERIFY(item); @@ -1722,7 +1722,7 @@ void tst_QQuickItem::keyNavigation_RightToLeft() window->show(); window->requestActivate(); QVERIFY(QTest::qWaitForWindowActive(window)); - QVERIFY(QGuiApplication::focusWindow() == window); + QCOMPARE(QGuiApplication::focusWindow(), window); QQuickItem *rootItem = qobject_cast<QQuickItem*>(window->rootObject()); QVERIFY(rootItem); @@ -1777,7 +1777,7 @@ void tst_QQuickItem::keyNavigation_skipNotVisible() window->show(); window->requestActivate(); QVERIFY(QTest::qWaitForWindowActive(window)); - QVERIFY(QGuiApplication::focusWindow() == window); + QCOMPARE(QGuiApplication::focusWindow(), window); QQuickItem *item = findItem<QQuickItem>(window->rootObject(), "item1"); QVERIFY(item); @@ -1852,7 +1852,7 @@ void tst_QQuickItem::keyNavigation_implicitSetting() window->show(); window->requestActivate(); QVERIFY(QTest::qWaitForWindowActive(window)); - QVERIFY(QGuiApplication::focusWindow() == window); + QCOMPARE(QGuiApplication::focusWindow(), window); QEvent wa(QEvent::WindowActivate); QGuiApplication::sendEvent(window, &wa); @@ -1982,7 +1982,7 @@ void tst_QQuickItem::keyNavigation_focusReason() window->requestActivate(); QVERIFY(QTest::qWaitForWindowActive(window)); - QVERIFY(QGuiApplication::focusWindow() == window); + QCOMPARE(QGuiApplication::focusWindow(), window); // install event filter on first item QQuickItem *item = findItem<QQuickItem>(window->rootObject(), "item1"); @@ -2040,8 +2040,8 @@ void tst_QQuickItem::smooth() QVERIFY(item->smooth()); QCOMPARE(spy.count(),1); QList<QVariant> arguments = spy.first(); - QVERIFY(arguments.count() == 1); - QVERIFY(arguments.at(0).toBool() == true); + QCOMPARE(arguments.count(), 1); + QVERIFY(arguments.at(0).toBool()); item->setSmooth(true); QCOMPARE(spy.count(),1); @@ -2069,8 +2069,8 @@ void tst_QQuickItem::antialiasing() QVERIFY(item->antialiasing()); QCOMPARE(spy.count(),1); QList<QVariant> arguments = spy.first(); - QVERIFY(arguments.count() == 1); - QVERIFY(arguments.at(0).toBool() == true); + QCOMPARE(arguments.count(), 1); + QVERIFY(arguments.at(0).toBool()); item->setAntialiasing(true); QCOMPARE(spy.count(),1); @@ -2098,8 +2098,8 @@ void tst_QQuickItem::clip() QVERIFY(item->clip()); QList<QVariant> arguments = spy.first(); - QVERIFY(arguments.count() == 1); - QVERIFY(arguments.at(0).toBool() == true); + QCOMPARE(arguments.count(), 1); + QVERIFY(arguments.at(0).toBool()); QCOMPARE(spy.count(),1); item->setClip(true); @@ -2325,7 +2325,7 @@ void tst_QQuickItem::propertyChanges() window->show(); window->requestActivate(); QVERIFY(QTest::qWaitForWindowActive(window)); - QVERIFY(QGuiApplication::focusWindow() == window); + QCOMPARE(QGuiApplication::focusWindow(), window); QQuickItem *item = findItem<QQuickItem>(window->rootObject(), "item"); QQuickItem *parentItem = findItem<QQuickItem>(window->rootObject(), "parentItem"); @@ -2353,7 +2353,7 @@ void tst_QQuickItem::propertyChanges() QCOMPARE(item->parentItem(), parentItem); QCOMPARE(parentSpy.count(),1); QList<QVariant> parentArguments = parentSpy.first(); - QVERIFY(parentArguments.count() == 1); + QCOMPARE(parentArguments.count(), 1); QCOMPARE(item->parentItem(), qvariant_cast<QQuickItem *>(parentArguments.at(0))); QCOMPARE(childrenChangedSpy.count(),1); @@ -2369,19 +2369,19 @@ void tst_QQuickItem::propertyChanges() QCOMPARE(item->baselineOffset(), 10.0); QCOMPARE(baselineOffsetSpy.count(),1); QList<QVariant> baselineOffsetArguments = baselineOffsetSpy.first(); - QVERIFY(baselineOffsetArguments.count() == 1); + QCOMPARE(baselineOffsetArguments.count(), 1); QCOMPARE(item->baselineOffset(), baselineOffsetArguments.at(0).toReal()); QCOMPARE(parentItem->childrenRect(), QRectF(0.0,0.0,100.0,200.0)); QCOMPARE(childrenRectSpy.count(),1); QList<QVariant> childrenRectArguments = childrenRectSpy.at(0); - QVERIFY(childrenRectArguments.count() == 1); + QCOMPARE(childrenRectArguments.count(), 1); QCOMPARE(parentItem->childrenRect(), childrenRectArguments.at(0).toRectF()); QCOMPARE(item->hasActiveFocus(), true); QCOMPARE(focusSpy.count(),1); QList<QVariant> focusArguments = focusSpy.first(); - QVERIFY(focusArguments.count() == 1); + QCOMPARE(focusArguments.count(), 1); QCOMPARE(focusArguments.at(0).toBool(), true); QCOMPARE(parentItem->hasActiveFocus(), false); @@ -2737,7 +2737,7 @@ void tst_QQuickItem::contains() window->show(); window->requestActivate(); QVERIFY(QTest::qWaitForWindowActive(window)); - QVERIFY(QGuiApplication::focusWindow() == window); + QCOMPARE(QGuiApplication::focusWindow(), window); QQuickItem *root = qobject_cast<QQuickItem *>(window->rootObject()); QVERIFY(root); diff --git a/tests/auto/quick/qquicklistview/BLACKLIST b/tests/auto/quick/qquicklistview/BLACKLIST new file mode 100644 index 0000000000..269696ce8c --- /dev/null +++ b/tests/auto/quick/qquicklistview/BLACKLIST @@ -0,0 +1,4 @@ +[QTBUG_38209] +* +[enforceRange_withoutHighlight] +osx diff --git a/tests/auto/quick/qquicklistview/data/contentHeightWithDelayRemove.qml b/tests/auto/quick/qquicklistview/data/contentHeightWithDelayRemove.qml new file mode 100644 index 0000000000..06011519b2 --- /dev/null +++ b/tests/auto/quick/qquicklistview/data/contentHeightWithDelayRemove.qml @@ -0,0 +1,46 @@ +import QtQuick 2.1 + +Item { + width: 400 + height: 600 + function takeOne() + { + listView.model.remove(2) + } + function takeThree() + { + listView.model.remove(4) + listView.model.remove(2) + listView.model.remove(0) + } + function takeAll() + { + listView.model.clear() + } + + ListView { + id: listView + + property bool useDelayRemove + + height: parent.height + width: 400 + model: ListModel { + ListElement { name: "A" } + ListElement { name: "B" } + ListElement { name: "C" } + ListElement { name: "D" } + ListElement { name: "E" } + } + delegate: Text { + id: wrapper + height: 100 + text: index + listView.count + ListView.delayRemove: listView.useDelayRemove + ListView.onRemove: SequentialAnimation { + PauseAnimation { duration: wrapper.ListView.delayRemove ? 100 : 0 } + PropertyAction { target: wrapper; property: "ListView.delayRemove"; value: false } + } + } + } +} diff --git a/tests/auto/quick/qquicklistview/data/objectmodel.qml b/tests/auto/quick/qquicklistview/data/objectmodel.qml new file mode 100644 index 0000000000..5c23d64cd3 --- /dev/null +++ b/tests/auto/quick/qquicklistview/data/objectmodel.qml @@ -0,0 +1,24 @@ +import QtQuick 2.0 +import QtQml.Models 2.1 + +ListView { + width: 360 + height: 360 + model: ObjectModel { + Rectangle { + width: 20 + height: 20 + color: "red" + } + Rectangle { + width: 20 + height: 20 + color: "green" + } + Rectangle { + width: 20 + height: 20 + color: "blue" + } + } +} diff --git a/tests/auto/quick/qquicklistview/data/snapOneItemResize.qml b/tests/auto/quick/qquicklistview/data/snapOneItemResize.qml new file mode 100644 index 0000000000..7ecc833a64 --- /dev/null +++ b/tests/auto/quick/qquicklistview/data/snapOneItemResize.qml @@ -0,0 +1,16 @@ +import QtQuick 2.0 + +ListView { + id: list + currentIndex: 5 + snapMode: ListView.SnapOneItem + orientation: ListView.Horizontal + highlightRangeMode: ListView.StrictlyEnforceRange + highlightFollowsCurrentItem: true + model: 10 + spacing: 10 + delegate: Item { + width: ListView.view.width + height: ListView.view.height + } +} diff --git a/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp b/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp index c93aac456d..472ffdc4b6 100644 --- a/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp +++ b/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp @@ -179,6 +179,7 @@ private slots: void creationContext(); void snapToItem_data(); void snapToItem(); + void snapOneItemResize_QTBUG_43555(); void snapOneItem_data(); void snapOneItem(); @@ -241,6 +242,10 @@ private slots: void QTBUG_39492(); void jsArrayChange(); + void objectModel(); + + void contentHeightWithDelayRemove(); + void contentHeightWithDelayRemove_data(); private: template <class T> void items(const QUrl &source); @@ -391,7 +396,7 @@ void tst_QQuickListView::items(const QUrl &source) QTRY_VERIFY(contentItem != 0); QMetaObject::invokeMethod(window->rootObject(), "checkProperties"); - QTRY_VERIFY(testObject->error() == false); + QTRY_VERIFY(!testObject->error()); QTRY_VERIFY(listview->highlightItem() != 0); QTRY_COMPARE(listview->count(), model.count()); @@ -414,20 +419,20 @@ void tst_QQuickListView::items(const QUrl &source) // switch to other delegate testObject->setAnimate(true); QMetaObject::invokeMethod(window->rootObject(), "checkProperties"); - QTRY_VERIFY(testObject->error() == false); + QTRY_VERIFY(!testObject->error()); QTRY_VERIFY(listview->currentItem()); // set invalid highlight testObject->setInvalidHighlight(true); QMetaObject::invokeMethod(window->rootObject(), "checkProperties"); - QTRY_VERIFY(testObject->error() == false); + QTRY_VERIFY(!testObject->error()); QTRY_VERIFY(listview->currentItem()); - QTRY_VERIFY(listview->highlightItem() == 0); + QTRY_VERIFY(!listview->highlightItem()); // back to normal highlight testObject->setInvalidHighlight(false); QMetaObject::invokeMethod(window->rootObject(), "checkProperties"); - QTRY_VERIFY(testObject->error() == false); + QTRY_VERIFY(!testObject->error()); QTRY_VERIFY(listview->currentItem()); QTRY_VERIFY(listview->highlightItem() != 0); @@ -439,7 +444,7 @@ void tst_QQuickListView::items(const QUrl &source) listview->forceLayout(); int itemCount = findItems<QQuickItem>(contentItem, "wrapper").count(); - QTRY_VERIFY(itemCount == 0); + QTRY_COMPARE(itemCount, 0); QTRY_COMPARE(listview->highlightResizeVelocity(), 1000.0); QTRY_COMPARE(listview->highlightMoveVelocity(), 100000.0); @@ -563,7 +568,7 @@ void tst_QQuickListView::inserted(const QUrl &source) // Insert item outside visible area model.insertItem(1, "Hello", "1324"); - QTRY_VERIFY(listview->contentY() == 80); + QTRY_COMPARE(listview->contentY(), qreal(80)); // Confirm items positioned correctly for (int i = 5; i < 5+15; ++i) { @@ -583,7 +588,7 @@ void tst_QQuickListView::inserted(const QUrl &source) QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", 0); QVERIFY(item); QCOMPARE(item->y(), 0.); - QTRY_VERIFY(listview->contentY() == 0); + QTRY_COMPARE(listview->contentY(), qreal(0)); delete window; delete testObject; @@ -916,7 +921,7 @@ void tst_QQuickListView::removed(const QUrl &source, bool /* animated */) QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; QTRY_VERIFY(item); - QTRY_VERIFY(item->y() == i*20); + QTRY_COMPARE(item->y(), qreal(i*20)); } // Remove first item (which is the current item); @@ -968,7 +973,7 @@ void tst_QQuickListView::removed(const QUrl &source, bool /* animated */) } // Remove current index - QTRY_VERIFY(listview->currentIndex() == 9); + QTRY_COMPARE(listview->currentIndex(), 9); QQuickItem *oldCurrent = listview->currentItem(); model.removeItem(9); @@ -1004,7 +1009,7 @@ void tst_QQuickListView::removed(const QUrl &source, bool /* animated */) model.removeItem(6); QTRY_COMPARE(listview->currentIndex(), 7); - QTRY_VERIFY(listview->currentItem() == oldCurrent); + QTRY_COMPARE(listview->currentItem(), oldCurrent); listview->setContentY(80); QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); @@ -1272,22 +1277,22 @@ void tst_QQuickListView::clear(const QUrl &source, QQuickItemView::VerticalLayou model.clear(); QTRY_COMPARE(findItems<QQuickListView>(contentItem, "wrapper").count(), 0); - QTRY_VERIFY(listview->count() == 0); - QTRY_VERIFY(listview->currentItem() == 0); + QTRY_COMPARE(listview->count(), 0); + QTRY_VERIFY(!listview->currentItem()); if (verticalLayoutDirection == QQuickItemView::TopToBottom) QTRY_COMPARE(listview->contentY(), 0.0); else QTRY_COMPARE(listview->contentY(), -listview->height()); - QVERIFY(listview->currentIndex() == -1); + QCOMPARE(listview->currentIndex(), -1); QCOMPARE(listview->contentHeight(), 0.0); // confirm sanity when adding an item to cleared list model.addItem("New", "1"); listview->forceLayout(); - QTRY_VERIFY(listview->count() == 1); + QTRY_COMPARE(listview->count(), 1); QVERIFY(listview->currentItem() != 0); - QVERIFY(listview->currentIndex() == 0); + QCOMPARE(listview->currentIndex(), 0); delete window; delete testObject; @@ -1805,7 +1810,7 @@ void tst_QQuickListView::swapWithFirstItem() // ensure content position is stable listview->setContentY(0); model.moveItem(1, 0); - QTRY_VERIFY(listview->contentY() == 0); + QTRY_COMPARE(listview->contentY(), qreal(0)); delete testObject; delete window; @@ -1943,11 +1948,11 @@ void tst_QQuickListView::spacing() QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; QTRY_VERIFY(item); - QTRY_VERIFY(item->y() == i*20); + QTRY_COMPARE(item->y(), qreal(i*20)); } listview->setSpacing(10); - QTRY_VERIFY(listview->spacing() == 10); + QTRY_COMPARE(listview->spacing(), qreal(10)); // Confirm items positioned correctly QTRY_VERIFY(findItems<QQuickItem>(contentItem, "wrapper").count() == 11); @@ -1955,7 +1960,7 @@ void tst_QQuickListView::spacing() QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; QTRY_VERIFY(item); - QTRY_VERIFY(item->y() == i*30); + QTRY_COMPARE(item->y(), qreal(i*30)); } listview->setSpacing(0); @@ -2261,7 +2266,7 @@ void tst_QQuickListView::sectionsDelegate_headerVisibility() listview->setCurrentIndex(20); QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); QTRY_VERIFY(qFuzzyCompare(listview->contentY(), 200.0)); - QTRY_VERIFY(listview->isMoving() == false); + QTRY_VERIFY(!listview->isMoving()); listview->setCurrentIndex(0); QTRY_VERIFY(qFuzzyIsNull(listview->contentY())); @@ -2682,7 +2687,7 @@ void tst_QQuickListView::currentIndex() listview->setCurrentIndex(20); QTRY_VERIFY(listview->verticalVelocity() != 0.0); listview->setCurrentIndex(0); - QTRY_VERIFY(listview->verticalVelocity() == 0.0); + QTRY_COMPARE(listview->verticalVelocity(), 0.0); // footer should become visible if it is out of view, and then current index is set to count-1 window->rootObject()->setProperty("showFooter", true); @@ -2704,7 +2709,7 @@ void tst_QQuickListView::currentIndex() // turn off auto highlight listview->setHighlightFollowsCurrentItem(false); - QVERIFY(listview->highlightFollowsCurrentItem() == false); + QVERIFY(!listview->highlightFollowsCurrentItem()); QVERIFY(listview->highlightItem()); qreal hlPos = listview->highlightItem()->y(); @@ -2808,7 +2813,7 @@ void tst_QQuickListView::keyNavigation() window->requestActivate(); QTest::qWaitForWindowActive(window); - QTRY_VERIFY(qGuiApp->focusWindow() == window); + QTRY_COMPARE(qGuiApp->focusWindow(), window); QTest::keyClick(window, forwardsKey); QCOMPARE(listview->currentIndex(), 1); @@ -2917,7 +2922,7 @@ void tst_QQuickListView::itemList() QQmlObjectModel *model = window->rootObject()->findChild<QQmlObjectModel*>("itemModel"); QTRY_VERIFY(model != 0); - QTRY_VERIFY(model->count() == 3); + QTRY_COMPARE(model->count(), 3); QTRY_COMPARE(listview->currentIndex(), 0); QQuickItem *item = findItem<QQuickItem>(contentItem, "item1"); @@ -2958,7 +2963,7 @@ void tst_QQuickListView::itemListFlicker() QQmlObjectModel *model = window->rootObject()->findChild<QQmlObjectModel*>("itemModel"); QTRY_VERIFY(model != 0); - QTRY_VERIFY(model->count() == 3); + QTRY_COMPARE(model->count(), 3); QTRY_COMPARE(listview->currentIndex(), 0); QQuickItem *item; @@ -3024,14 +3029,14 @@ void tst_QQuickListView::cacheBuffer() QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; QTRY_VERIFY(item); - QTRY_VERIFY(item->y() == i*20); + QTRY_COMPARE(item->y(), qreal(i*20)); } QQmlIncubationController controller; window->engine()->setIncubationController(&controller); testObject->setCacheBuffer(200); - QTRY_VERIFY(listview->cacheBuffer() == 200); + QTRY_COMPARE(listview->cacheBuffer(), 200); // items will be created one at a time for (int i = itemCount; i < qMin(itemCount+10,model.count()); ++i) { @@ -3057,7 +3062,7 @@ void tst_QQuickListView::cacheBuffer() QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; QTRY_VERIFY(item); - QTRY_VERIFY(item->y() == i*20); + QTRY_COMPARE(item->y(), qreal(i*20)); } // move view and confirm items in view are visible immediately and outside are created async @@ -3067,7 +3072,7 @@ void tst_QQuickListView::cacheBuffer() QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; QVERIFY(item); - QVERIFY(item->y() == i*20); + QCOMPARE(item->y(), qreal(i*20)); } QVERIFY(findItem<QQuickItem>(listview, "wrapper", 32) == 0); @@ -3528,7 +3533,7 @@ void tst_QQuickListView::QTBUG_11105() QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; QTRY_VERIFY(item); - QTRY_VERIFY(item->y() == i*20); + QTRY_COMPARE(item->y(), qreal(i*20)); } listview->positionViewAtIndex(20, QQuickListView::Beginning); @@ -3622,7 +3627,7 @@ void tst_QQuickListView::header() QQuickText *header = 0; QTRY_VERIFY(header = findItem<QQuickText>(contentItem, "header")); - QVERIFY(header == listview->headerItem()); + QCOMPARE(header, listview->headerItem()); QCOMPARE(header->width(), 100.); QCOMPARE(header->height(), 30.); @@ -3660,7 +3665,7 @@ void tst_QQuickListView::header() header = findItem<QQuickText>(contentItem, "header2"); QVERIFY(header); - QVERIFY(header == listview->headerItem()); + QCOMPARE(header, listview->headerItem()); QCOMPARE(header->position(), changedHeaderPos); QCOMPARE(header->width(), 50.); @@ -3811,7 +3816,7 @@ void tst_QQuickListView::headerChangesViewport() QQuickText *header = 0; QTRY_VERIFY(header = findItem<QQuickText>(contentItem, "header")); - QVERIFY(header == listview->headerItem()); + QCOMPARE(header, listview->headerItem()); QCOMPARE(header->height(), 20.); QCOMPARE(listview->contentHeight(), 20.); @@ -3862,7 +3867,7 @@ void tst_QQuickListView::footer() QQuickText *footer = findItem<QQuickText>(contentItem, "footer"); QVERIFY(footer); - QVERIFY(footer == listview->footerItem()); + QCOMPARE(footer, listview->footerItem()); QCOMPARE(footer->position(), initialFooterPos); QCOMPARE(footer->width(), 100.); @@ -3922,7 +3927,7 @@ void tst_QQuickListView::footer() footer = findItem<QQuickText>(contentItem, "footer2"); QVERIFY(footer); - QVERIFY(footer == listview->footerItem()); + QCOMPARE(footer, listview->footerItem()); QCOMPARE(footer->position(), changedFooterPos); QCOMPARE(footer->width(), 50.); @@ -4155,11 +4160,11 @@ void tst_QQuickListView::resetModel_headerFooter() // A reset should not force a new header or footer to be created. QQuickItem *newHeader = findItem<QQuickItem>(contentItem, "header"); - QVERIFY(newHeader == header); + QCOMPARE(newHeader, header); QCOMPARE(header->y(), -header->height()); QQuickItem *newFooter = findItem<QQuickItem>(contentItem, "footer"); - QVERIFY(newFooter == footer); + QCOMPARE(newFooter, footer); QCOMPARE(footer->y(), 30.*4); delete window; @@ -4664,7 +4669,7 @@ void tst_QQuickListView::indexAt_itemAt() QVERIFY(item); } QCOMPARE(listview->indexAt(x,y), index); - QVERIFY(listview->itemAt(x,y) == item); + QCOMPARE(listview->itemAt(x,y), item); releaseView(window); delete testObject; @@ -4828,7 +4833,7 @@ void tst_QQuickListView::rightToLeft() QQmlObjectModel *model = window->rootObject()->findChild<QQmlObjectModel*>("itemModel"); QTRY_VERIFY(model != 0); - QTRY_VERIFY(model->count() == 3); + QTRY_COMPARE(model->count(), 3); QTRY_COMPARE(listview->currentIndex(), 0); // initial position at first item, right edge aligned @@ -4893,7 +4898,7 @@ void tst_QQuickListView::test_mirroring() foreach (const QString objectName, objectNames) QCOMPARE(findItem<QQuickItem>(listviewA, objectName)->x(), findItem<QQuickItem>(listviewB, objectName)->x()); - QVERIFY(listviewB->layoutDirection() == listviewB->effectiveLayoutDirection()); + QCOMPARE(listviewB->layoutDirection(), listviewB->effectiveLayoutDirection()); QQuickItemPrivate::get(listviewB)->setLayoutMirror(true); QVERIFY(listviewB->layoutDirection() != listviewB->effectiveLayoutDirection()); @@ -5034,7 +5039,7 @@ void tst_QQuickListView::marginsResize() // flick past the end and check content pos still settles on correct extents flick(window, flickStart, flickEnd, 180); - QTRY_VERIFY(listview->isMoving() == false); + QTRY_VERIFY(!listview->isMoving()); if (orientation == QQuickListView::Vertical) QTRY_COMPARE(listview->contentY(), end); else @@ -5049,7 +5054,7 @@ void tst_QQuickListView::marginsResize() // flick past the beginning and check content pos still settles on correct extents flick(window, flickEnd, flickStart, 180); - QTRY_VERIFY(listview->isMoving() == false); + QTRY_VERIFY(!listview->isMoving()); if (orientation == QQuickListView::Vertical) QTRY_COMPARE(listview->contentY(), start); else @@ -5199,6 +5204,37 @@ void tst_QQuickListView::snapToItem() releaseView(window); } +void tst_QQuickListView::snapOneItemResize_QTBUG_43555() +{ + QQuickView *window = createView(); + window->resize(QSize(100, 320)); + window->setResizeMode(QQuickView::SizeRootObjectToView); + QQuickViewTestUtil::moveMouseAway(window); + + window->setSource(testFileUrl("snapOneItemResize.qml")); + window->show(); + QVERIFY(QTest::qWaitForWindowExposed(window)); + + QQuickListView *listview = qobject_cast<QQuickListView*>(window->rootObject()); + QTRY_VERIFY(listview != 0); + + QSignalSpy currentIndexSpy(listview, SIGNAL(currentIndexChanged())); + + QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QTRY_COMPARE(listview->currentIndex(), 5); + currentIndexSpy.clear(); + + window->resize(QSize(400, 320)); + + QTRY_COMPARE(int(listview->width()), 400); + QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + + QTRY_COMPARE(listview->currentIndex(), 5); + QCOMPARE(currentIndexSpy.count(), 0); + + delete window; +} + void tst_QQuickListView::qAbstractItemModel_package_items() { items<QaimModel>(testFileUrl("listviewtest-package.qml")); @@ -7006,7 +7042,7 @@ void tst_QQuickListView::matchIndexLists(const QVariantList &indexLists, const Q void tst_QQuickListView::matchItemsAndIndexes(const QVariantMap &items, const QaimModel &model, const QList<int> &expectedIndexes) { for (QVariantMap::const_iterator it = items.begin(); it != items.end(); ++it) { - QVERIFY(it.value().type() == QVariant::Int); + QCOMPARE(it.value().type(), QVariant::Int); QString name = it.key(); int itemIndex = it.value().toInt(); QVERIFY2(expectedIndexes.contains(itemIndex), QTest::toString(QString("Index %1 not found in expectedIndexes").arg(itemIndex))); @@ -7020,7 +7056,7 @@ void tst_QQuickListView::matchItemsAndIndexes(const QVariantMap &items, const Qa void tst_QQuickListView::matchItemLists(const QVariantList &itemLists, const QList<QQuickItem *> &expectedItems) { for (int i=0; i<itemLists.count(); i++) { - QVERIFY(itemLists[i].type() == QVariant::List); + QCOMPARE(itemLists[i].type(), QVariant::List); QVariantList current = itemLists[i].toList(); for (int j=0; j<current.count(); j++) { QQuickItem *o = qobject_cast<QQuickItem*>(current[j].value<QObject*>()); @@ -7062,7 +7098,7 @@ void tst_QQuickListView::flickBeyondBounds() QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; QTRY_VERIFY(item); - QTRY_VERIFY(item->y() == i*45); + QTRY_COMPARE(item->y(), qreal(i*45)); } delete window; @@ -7856,7 +7892,7 @@ void tst_QQuickListView::QTBUG_38209() // simulate mouse flick flick(window.data(), QPoint(200, 200), QPoint(200, 50), 100); - QTRY_VERIFY(listview->isMoving() == false); + QTRY_VERIFY(!listview->isMoving()); qreal contentY = listview->contentY(); // flick down @@ -8063,6 +8099,135 @@ void tst_QQuickListView::jsArrayChange() QCOMPARE(spy.count(), 1); } +static bool compareObjectModel(QQuickListView *listview, QQmlObjectModel *model) +{ + if (listview->count() != model->count()) + return false; + for (int i = 0; i < listview->count(); ++i) { + listview->setCurrentIndex(i); + if (listview->currentItem() != model->get(i)) + return false; + } + return true; +} + +void tst_QQuickListView::objectModel() +{ + QQmlEngine engine; + QQmlComponent component(&engine, testFileUrl("objectmodel.qml")); + + QQuickListView *listview = qobject_cast<QQuickListView *>(component.create()); + QVERIFY(listview); + + QQmlObjectModel *model = listview->model().value<QQmlObjectModel *>(); + QVERIFY(model); + + listview->setCurrentIndex(0); + QVERIFY(listview->currentItem()); + QCOMPARE(listview->currentItem()->property("color").toString(), QColor("red").name()); + + listview->setCurrentIndex(1); + QVERIFY(listview->currentItem()); + QCOMPARE(listview->currentItem()->property("color").toString(), QColor("green").name()); + + listview->setCurrentIndex(2); + QVERIFY(listview->currentItem()); + QCOMPARE(listview->currentItem()->property("color").toString(), QColor("blue").name()); + + QQuickItem *item0 = new QQuickItem(listview); + item0->setSize(QSizeF(20, 20)); + model->append(item0); + QCOMPARE(model->count(), 4); + QVERIFY(compareObjectModel(listview, model)); + + QQuickItem *item1 = new QQuickItem(listview); + item1->setSize(QSizeF(20, 20)); + model->insert(0, item1); + QCOMPARE(model->count(), 5); + QVERIFY(compareObjectModel(listview, model)); + + model->move(1, 2, 3); + QVERIFY(compareObjectModel(listview, model)); + + model->remove(2, 2); + QCOMPARE(model->count(), 3); + QVERIFY(compareObjectModel(listview, model)); + + model->clear(); + QCOMPARE(model->count(), 0); + QCOMPARE(listview->count(), 0); + + delete listview; +} + +void tst_QQuickListView::contentHeightWithDelayRemove_data() +{ + QTest::addColumn<bool>("useDelayRemove"); + QTest::addColumn<QByteArray>("removeFunc"); + QTest::addColumn<int>("countDelta"); + QTest::addColumn<qreal>("contentHeightDelta"); + + QTest::newRow("remove without delayRemove") + << false + << QByteArray("takeOne") + << -1 + << qreal(-1 * 100.0); + + QTest::newRow("remove with delayRemove") + << true + << QByteArray("takeOne") + << -1 + << qreal(-1 * 100.0); + + QTest::newRow("remove with multiple delayRemove") + << true + << QByteArray("takeThree") + << -3 + << qreal(-3 * 100.0); + + QTest::newRow("clear with delayRemove") + << true + << QByteArray("takeAll") + << -5 + << qreal(-5 * 100.0); +} + +void tst_QQuickListView::contentHeightWithDelayRemove() +{ + QFETCH(bool, useDelayRemove); + QFETCH(QByteArray, removeFunc); + QFETCH(int, countDelta); + QFETCH(qreal, contentHeightDelta); + + QQuickView *window = createView(); + window->setSource(testFileUrl("contentHeightWithDelayRemove.qml")); + window->show(); + QVERIFY(QTest::qWaitForWindowExposed(window)); + + QQuickListView *listview = window->rootObject()->findChild<QQuickListView*>(); + QTRY_VERIFY(listview != 0); + + const int initialCount(listview->count()); + const int eventualCount(initialCount + countDelta); + + const qreal initialContentHeight(listview->contentHeight()); + const int eventualContentHeight(qRound(initialContentHeight + contentHeightDelta)); + + listview->setProperty("useDelayRemove", useDelayRemove); + QMetaObject::invokeMethod(window->rootObject(), removeFunc.constData()); + QTest::qWait(50); + QCOMPARE(listview->count(), eventualCount); + + if (useDelayRemove) { + QCOMPARE(qRound(listview->contentHeight()), qRound(initialContentHeight)); + QTRY_COMPARE(qRound(listview->contentHeight()), eventualContentHeight); + } else { + QCOMPARE(qRound(listview->contentHeight()), eventualContentHeight); + } + + delete window; +} + QTEST_MAIN(tst_QQuickListView) #include "tst_qquicklistview.moc" diff --git a/tests/auto/quick/qquickloader/tst_qquickloader.cpp b/tests/auto/quick/qquickloader/tst_qquickloader.cpp index 3dd2551d9d..e72b38e06c 100644 --- a/tests/auto/quick/qquickloader/tst_qquickloader.cpp +++ b/tests/auto/quick/qquickloader/tst_qquickloader.cpp @@ -236,7 +236,7 @@ void tst_QQuickLoader::clear() QCOMPARE(loader->progress(), 1.0); QCOMPARE(static_cast<QQuickItem*>(loader)->childItems().count(), 1); - QTRY_VERIFY(loader->item() == 0); + QTRY_VERIFY(!loader->item()); QCOMPARE(loader->progress(), 0.0); QCOMPARE(loader->status(), QQuickLoader::Null); QCOMPARE(static_cast<QQuickItem*>(loader)->childItems().count(), 0); @@ -256,7 +256,7 @@ void tst_QQuickLoader::clear() loader->setSourceComponent(0); - QVERIFY(loader->item() == 0); + QVERIFY(!loader->item()); QCOMPARE(loader->progress(), 0.0); QCOMPARE(loader->status(), QQuickLoader::Null); QCOMPARE(static_cast<QQuickItem*>(loader)->childItems().count(), 0); @@ -276,7 +276,7 @@ void tst_QQuickLoader::clear() QMetaObject::invokeMethod(item, "clear"); - QVERIFY(loader->item() == 0); + QVERIFY(!loader->item()); QCOMPARE(loader->progress(), 0.0); QCOMPARE(loader->status(), QQuickLoader::Null); QCOMPARE(static_cast<QQuickItem*>(loader)->childItems().count(), 0); @@ -447,7 +447,7 @@ void tst_QQuickLoader::networkRequestUrl() QQuickLoader *loader = qobject_cast<QQuickLoader*>(component.create()); QVERIFY(loader != 0); - QTRY_VERIFY(loader->status() == QQuickLoader::Ready); + QTRY_COMPARE(loader->status(), QQuickLoader::Ready); QVERIFY(loader->item()); QCOMPARE(loader->progress(), 1.0); @@ -480,7 +480,7 @@ void tst_QQuickLoader::networkComponent() QQuickLoader *loader = qobject_cast<QQuickLoader*>(item->children().at(1)); QVERIFY(loader); - QTRY_VERIFY(loader->status() == QQuickLoader::Ready); + QTRY_COMPARE(loader->status(), QQuickLoader::Ready); QVERIFY(loader->item()); QCOMPARE(loader->progress(), 1.0); @@ -505,9 +505,9 @@ void tst_QQuickLoader::failNetworkRequest() QQuickLoader *loader = qobject_cast<QQuickLoader*>(component.create()); QVERIFY(loader != 0); - QTRY_VERIFY(loader->status() == QQuickLoader::Error); + QTRY_COMPARE(loader->status(), QQuickLoader::Error); - QVERIFY(loader->item() == 0); + QVERIFY(!loader->item()); QCOMPARE(loader->progress(), 1.0); QCOMPARE(loader->property("did_load").toInt(), 123); QCOMPARE(static_cast<QQuickItem*>(loader)->childItems().count(), 0); @@ -525,11 +525,11 @@ void tst_QQuickLoader::active() QQuickLoader *loader = object->findChild<QQuickLoader*>("loader"); QVERIFY(loader->active() == false); // set manually to false - QVERIFY(loader->item() == 0); + QVERIFY(!loader->item()); QMetaObject::invokeMethod(object, "doSetSourceComponent"); - QVERIFY(loader->item() == 0); + QVERIFY(!loader->item()); QMetaObject::invokeMethod(object, "doSetSource"); - QVERIFY(loader->item() == 0); + QVERIFY(!loader->item()); QMetaObject::invokeMethod(object, "doSetActive"); QVERIFY(loader->item() != 0); @@ -598,7 +598,7 @@ void tst_QQuickLoader::active() QVERIFY(loader->item() != 0); int currItemChangedCount = loader->property("itemChangedCount").toInt(); QMetaObject::invokeMethod(object, "doSetInactive"); - QVERIFY(loader->item() == 0); + QVERIFY(!loader->item()); QCOMPARE(loader->property("itemChangedCount").toInt(), (currItemChangedCount+1)); delete object; @@ -781,7 +781,7 @@ void tst_QQuickLoader::initialPropertyValuesError() QVERIFY(object != 0); QQuickLoader *loader = object->findChild<QQuickLoader*>("loader"); QVERIFY(loader != 0); - QVERIFY(loader->item() == 0); + QVERIFY(!loader->item()); delete object; } @@ -803,7 +803,7 @@ void tst_QQuickLoader::deleteComponentCrash() QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete); QCoreApplication::processEvents(); QTRY_COMPARE(static_cast<QQuickItem*>(loader)->childItems().count(), 1); - QVERIFY(loader->source() == testFileUrl("BlueRect.qml")); + QCOMPARE(loader->source(), testFileUrl("BlueRect.qml")); delete item; } @@ -833,7 +833,7 @@ void tst_QQuickLoader::vmeErrors() QTest::ignoreMessage(QtWarningMsg, err.toLatin1().constData()); QQuickLoader *loader = qobject_cast<QQuickLoader*>(component.create()); QVERIFY(loader); - QVERIFY(loader->item() == 0); + QVERIFY(!loader->item()); delete loader; } @@ -1098,7 +1098,7 @@ void tst_QQuickLoader::parented() QQuickItem *item = root->findChild<QQuickItem*>("comp"); QVERIFY(item); - QVERIFY(item->parentItem() == root); + QCOMPARE(item->parentItem(), root); QCOMPARE(item->width(), 300.); QCOMPARE(item->height(), 300.); diff --git a/tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp b/tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp index da8bb9e94d..6e6c9da829 100644 --- a/tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp +++ b/tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp @@ -169,7 +169,7 @@ void tst_QQuickMouseArea::dragProperties() // target QQuickItem *blackRect = window.rootObject()->findChild<QQuickItem*>("blackrect"); QVERIFY(blackRect != 0); - QVERIFY(blackRect == drag->target()); + QCOMPARE(blackRect, drag->target()); QQuickItem *rootItem = qobject_cast<QQuickItem*>(window.rootObject()); QVERIFY(rootItem != 0); QSignalSpy targetSpy(drag, SIGNAL(targetChanged())); @@ -267,14 +267,14 @@ void tst_QQuickMouseArea::resetDrag() // target QQuickItem *blackRect = window.rootObject()->findChild<QQuickItem*>("blackrect"); QVERIFY(blackRect != 0); - QVERIFY(blackRect == drag->target()); + QCOMPARE(blackRect, drag->target()); QQuickItem *rootItem = qobject_cast<QQuickItem*>(window.rootObject()); QVERIFY(rootItem != 0); QSignalSpy targetSpy(drag, SIGNAL(targetChanged())); QVERIFY(drag->target() != 0); window.rootContext()->setContextProperty("haveTarget", QVariant(false)); QCOMPARE(targetSpy.count(),1); - QVERIFY(drag->target() == 0); + QVERIFY(!drag->target()); } void tst_QQuickMouseArea::dragging() @@ -300,7 +300,7 @@ void tst_QQuickMouseArea::dragging() // target QQuickItem *blackRect = window.rootObject()->findChild<QQuickItem*>("blackrect"); QVERIFY(blackRect != 0); - QVERIFY(blackRect == drag->target()); + QCOMPARE(blackRect, drag->target()); QVERIFY(!drag->active()); @@ -347,7 +347,7 @@ void tst_QQuickMouseArea::dragSmoothed() mouseRegion->setAcceptedButtons(Qt::LeftButton); QQuickItem *blackRect = window.rootObject()->findChild<QQuickItem*>("blackrect"); QVERIFY(blackRect != 0); - QVERIFY(blackRect == drag->target()); + QCOMPARE(blackRect, drag->target()); QVERIFY(!drag->active()); QTest::mousePress(&window, Qt::LeftButton, 0, QPoint(100,100)); QVERIFY(!drag->active()); @@ -393,7 +393,7 @@ void tst_QQuickMouseArea::dragThreshold() mouseRegion->setAcceptedButtons(Qt::LeftButton); QQuickItem *blackRect = window.rootObject()->findChild<QQuickItem*>("blackrect"); QVERIFY(blackRect != 0); - QVERIFY(blackRect == drag->target()); + QCOMPARE(blackRect, drag->target()); QVERIFY(!drag->active()); QTest::mousePress(&window, Qt::LeftButton, 0, QPoint(100,100)); QVERIFY(!drag->active()); @@ -451,7 +451,7 @@ void tst_QQuickMouseArea::invalidDrag() // target QQuickItem *blackRect = window.rootObject()->findChild<QQuickItem*>("blackrect"); QVERIFY(blackRect != 0); - QVERIFY(blackRect == drag->target()); + QCOMPARE(blackRect, drag->target()); QVERIFY(!drag->active()); @@ -501,7 +501,7 @@ void tst_QQuickMouseArea::cancelDragging() // target QQuickItem *blackRect = window.rootObject()->findChild<QQuickItem*>("blackrect"); QVERIFY(blackRect != 0); - QVERIFY(blackRect == drag->target()); + QCOMPARE(blackRect, drag->target()); QVERIFY(!drag->active()); @@ -655,7 +655,7 @@ void tst_QQuickMouseArea::noOnClickedWithPressAndHold() QMouseEvent pressEvent(QEvent::MouseButtonPress, QPoint(100, 100), Qt::LeftButton, Qt::LeftButton, 0); QGuiApplication::sendEvent(&window, &pressEvent); - QVERIFY(mouseArea->pressedButtons() == Qt::LeftButton); + QCOMPARE(mouseArea->pressedButtons(), Qt::LeftButton); QVERIFY(!window.rootObject()->property("clicked").toBool()); QVERIFY(!window.rootObject()->property("held").toBool()); @@ -1268,7 +1268,7 @@ void tst_QQuickMouseArea::disableAfterPress() // target QQuickItem *blackRect = window.rootObject()->findChild<QQuickItem*>("blackrect"); QVERIFY(blackRect != 0); - QVERIFY(blackRect == drag->target()); + QCOMPARE(blackRect, drag->target()); QVERIFY(!drag->active()); @@ -1561,7 +1561,7 @@ void tst_QQuickMouseArea::changeAxis() // target QQuickItem *blackRect = view.rootObject()->findChild<QQuickItem*>("blackrect"); QVERIFY(blackRect != 0); - QVERIFY(blackRect == drag->target()); + QCOMPARE(blackRect, drag->target()); QVERIFY(!drag->active()); diff --git a/tests/auto/quick/qquickmultipointtoucharea/BLACKLIST b/tests/auto/quick/qquickmultipointtoucharea/BLACKLIST new file mode 100644 index 0000000000..1777af9e0c --- /dev/null +++ b/tests/auto/quick/qquickmultipointtoucharea/BLACKLIST @@ -0,0 +1,2 @@ +[inFlickable] +* diff --git a/tests/auto/quick/qquickmultipointtoucharea/tst_qquickmultipointtoucharea.cpp b/tests/auto/quick/qquickmultipointtoucharea/tst_qquickmultipointtoucharea.cpp index e69ebfa8fe..4da4767d7b 100644 --- a/tests/auto/quick/qquickmultipointtoucharea/tst_qquickmultipointtoucharea.cpp +++ b/tests/auto/quick/qquickmultipointtoucharea/tst_qquickmultipointtoucharea.cpp @@ -719,7 +719,7 @@ void tst_QQuickMultiPointTouchArea::inFlickable() QTest::mouseMove(window.data(), p1); QQuickTouchUtils::flush(window.data()); - QVERIFY(flickable->contentY() == 0); + QCOMPARE(flickable->contentY(), qreal(0)); QCOMPARE(point11->pressed(), true); QCOMPARE(point12->pressed(), true); @@ -1186,14 +1186,14 @@ void tst_QQuickMultiPointTouchArea::mouseInteraction() QPoint p1 = QPoint(100, 100); QTest::mousePress(view.data(), (Qt::MouseButton) buttons, 0, p1); QCOMPARE(area->property("touchCount").toInt(), accept); - QCOMPARE(point1->pressed(), accept); + QCOMPARE(point1->pressed(), accept != 0); p1 += QPoint(10, 10); QTest::mouseMove(view.data(), p1); - QCOMPARE(point1->pressed(), accept); + QCOMPARE(point1->pressed(), accept != 0); QCOMPARE(area->property("touchCount").toInt(), accept); p1 += QPoint(10, 10); QTest::mouseMove(view.data(), p1); - QCOMPARE(point1->pressed(), accept); + QCOMPARE(point1->pressed(), accept != 0); QCOMPARE(area->property("touchCount").toInt(), accept); QTest::mouseRelease(view.data(), (Qt::MouseButton) buttons); QCOMPARE(point1->pressed(), false); diff --git a/tests/auto/quick/qquickpathview/data/customAttribute.qml b/tests/auto/quick/qquickpathview/data/customAttribute.qml new file mode 100644 index 0000000000..bd4c9fd1de --- /dev/null +++ b/tests/auto/quick/qquickpathview/data/customAttribute.qml @@ -0,0 +1,58 @@ +import QtQuick 2.4 + +PathView { + width: 200 + height: 600 + + pathItemCount: 7 + + model: ListModel { + ListElement { color: "salmon" } + ListElement { color: "seagreen" } + ListElement { color: "navy" } + ListElement { color: "goldenrod" } + } + path: Path { + startX: width / 2; startY: -100 + PathAttribute { name: "BEGIN" } + + PathLine { relativeX: 0; y: height / 2 } + PathAttribute { name: "BEGIN" } + + PathLine { relativeX: 0; y: height + 100 } + PathAttribute { name: "BEGIN" } + } + delegate: Rectangle { + width: 200 + height: 200 + color: model.color + opacity: PathView.transparency + } + + Component { + id: attributeComponent + PathAttribute {} + } + + function addAttribute(name, values) { + var valueIndex = 0 + var elements = [] + for (var i = 0; i < path.pathElements.length; ++i) { + elements.push(path.pathElements[i]) + + if (path.pathElements[i].name === "BEGIN") { + if (values[valueIndex] !== undefined) { + var attribute = attributeComponent.createObject(this, { "name": name, "value": values[valueIndex] }) + elements.push(attribute) + } + ++valueIndex + } + } + + console.log("??") + path.pathElements = elements + console.log("!!") + } + + Component.onCompleted: addAttribute("transparency", [0, 1, 0]) +} diff --git a/tests/auto/quick/qquickpathview/data/qtbug42716.qml b/tests/auto/quick/qquickpathview/data/qtbug42716.qml new file mode 100644 index 0000000000..81d52d5ea3 --- /dev/null +++ b/tests/auto/quick/qquickpathview/data/qtbug42716.qml @@ -0,0 +1,111 @@ +import QtQuick 2.0 + +Rectangle { + //Note that this file was originally the manual reproduction, MouseAreas were left in. + id: qmlBrowser + + width: 500 + height: 350 + + ListModel { + id: myModel + ListElement { + name: "Bill Jones 0" + } + ListElement { + name: "Jane Doe 1" + } + ListElement { + name: "John Smith 2" + } + ListElement { + name: "Bill Jones 3" + } + ListElement { + name: "Jane Doe 4" + } + ListElement { + name: "John Smith 5" + } + ListElement { + name: "John Smith 6" + } + ListElement { + name: "John Smith 7" + } + } + + Component { + id: delegate + + Text { + id: nameText + height: 33 + width: parent.width + objectName: "delegate"+index + + text: "index: " + index + " text: " + name + font.pointSize: 16 + color: PathView.isCurrentItem ? "red" : "black" + } + } + + PathView { + id: contentList + objectName: "pathView" + anchors.fill: parent + + property int maxPathItemCount: 7 + property real itemHeight: 34 + + delegate: delegate + model: myModel + currentIndex: 5 + pathItemCount: maxPathItemCount + highlightMoveDuration: 0 + + path: Path { + startX: 30 + contentList.width / 2 + startY: 30 + PathLine { + relativeX: 0 + relativeY: contentList.itemHeight * contentList.maxPathItemCount + } + } + + focus: true + Keys.onLeftPressed: decrementCurrentIndex() + Keys.onRightPressed: incrementCurrentIndex() + } + + Column { + anchors.right: parent.right + Text { + text: "Go 1" + font.weight: Font.Bold + font.pixelSize: 24 + MouseArea { + anchors.fill: parent + onClicked: contentList.offset = 2.55882 + } + } + Text { + text: "Go 2" + font.weight: Font.Bold + font.pixelSize: 24 + MouseArea { + anchors.fill: parent + onClicked: contentList.offset = 0.0882353 + } + } + Text { + text: "Go 3" + font.weight: Font.Bold + font.pixelSize: 24 + MouseArea { + anchors.fill: parent + onClicked: contentList.offset = 0.99987 + } + } + } +} diff --git a/tests/auto/quick/qquickpathview/tst_qquickpathview.cpp b/tests/auto/quick/qquickpathview/tst_qquickpathview.cpp index 7db15522b5..eed947bfcd 100644 --- a/tests/auto/quick/qquickpathview/tst_qquickpathview.cpp +++ b/tests/auto/quick/qquickpathview/tst_qquickpathview.cpp @@ -140,6 +140,8 @@ private slots: void nestedinFlickable(); void flickableDelegate(); void jsArrayChange(); + void qtbug42716(); + void addCustomAttribute(); }; class TestObject : public QObject @@ -183,8 +185,8 @@ void tst_QQuickPathView::initValues() QQuickPathView *obj = qobject_cast<QQuickPathView*>(c.create()); QVERIFY(obj != 0); - QVERIFY(obj->path() == 0); - QVERIFY(obj->delegate() == 0); + QVERIFY(!obj->path()); + QVERIFY(!obj->delegate()); QCOMPARE(obj->model(), QVariant()); QCOMPARE(obj->currentIndex(), 0); QCOMPARE(obj->offset(), 0.); @@ -799,7 +801,7 @@ void tst_QQuickPathView::dataModel() QVERIFY(pathview != 0); QMetaObject::invokeMethod(window->rootObject(), "checkProperties"); - QVERIFY(testObject->error() == false); + QVERIFY(!testObject->error()); QQuickItem *item = findItem<QQuickItem>(pathview, "wrapper", 0); QVERIFY(item); @@ -828,14 +830,14 @@ void tst_QQuickPathView::dataModel() testObject->setPathItemCount(5); QMetaObject::invokeMethod(window->rootObject(), "checkProperties"); - QVERIFY(testObject->error() == false); + QVERIFY(!testObject->error()); QTRY_COMPARE(findItems<QQuickItem>(pathview, "wrapper").count(), 5); QQuickRectangle *testItem = findItem<QQuickRectangle>(pathview, "wrapper", 4); QVERIFY(testItem != 0); testItem = findItem<QQuickRectangle>(pathview, "wrapper", 5); - QVERIFY(testItem == 0); + QVERIFY(!testItem); pathview->setCurrentIndex(1); QCOMPARE(pathview->currentIndex(), 1); @@ -1814,7 +1816,7 @@ void tst_QQuickPathView::cancelDrag() item->grabMouse(); // returns to a snap point. - QTRY_VERIFY(pathview->offset() == qFloor(pathview->offset())); + QTRY_COMPARE(pathview->offset(), qreal(qFloor(pathview->offset()))); QTRY_VERIFY(!pathview->isMoving()); QVERIFY(!pathview->isDragging()); QCOMPARE(draggingSpy.count(), 2); @@ -1897,7 +1899,7 @@ void tst_QQuickPathView::snapToItem() QVERIFY(pathview->isMoving()); QTRY_VERIFY_WITH_TIMEOUT(!pathview->isMoving(), 50000); - QVERIFY(pathview->offset() == qFloor(pathview->offset())); + QCOMPARE(pathview->offset(), qreal(qFloor(pathview->offset()))); if (enforceRange) QVERIFY(pathview->currentIndex() != currentIndex); @@ -2051,7 +2053,7 @@ void tst_QQuickPathView::indexAt_itemAt() QVERIFY(item); } QCOMPARE(pathview->indexAt(x,y), index); - QVERIFY(pathview->itemAt(x,y) == item); + QCOMPARE(pathview->itemAt(x,y), item); } @@ -2322,6 +2324,61 @@ void tst_QQuickPathView::jsArrayChange() QCOMPARE(spy.count(), 1); } +/* This bug was one where if you jump the list such that the sole missing item needed to be + * added in the middle of the list, it would instead move an item somewhere else in the list + * to the middle (messing it up very badly). + * + * The test checks correct visual order both before and after the jump. + */ +void tst_QQuickPathView::qtbug42716() +{ + QScopedPointer<QQuickView> window(createView()); + + window->setSource(testFileUrl("qtbug42716.qml")); + window->show(); + QVERIFY(QTest::qWaitForWindowActive(window.data())); + QCOMPARE(window.data(), qGuiApp->focusWindow()); + + QQuickPathView *pathView = findItem<QQuickPathView>(window->rootObject(), "pathView"); + QVERIFY(pathView != 0); + + int order1[] = {5,6,7,0,1,2,3}; + int missing1 = 4; + int order2[] = {0,1,2,3,4,5,6}; + int missing2 = 7; + + qreal lastY = 0.0; + for (int i = 0; i<7; i++) { + QQuickItem *item = findItem<QQuickItem>(pathView, QString("delegate%1").arg(order1[i])); + QVERIFY(item); + QVERIFY(item->y() > lastY); + lastY = item->y(); + } + QQuickItem *itemMiss = findItem<QQuickItem>(pathView, QString("delegate%1").arg(missing1)); + QVERIFY(!itemMiss); + + pathView->setOffset(0.0882353); + //Note refill is delayed, needs time to take effect + QTest::qWait(100); + + lastY = 0.0; + for (int i = 0; i<7; i++) { + QQuickItem *item = findItem<QQuickItem>(pathView, QString("delegate%1").arg(order2[i])); + QVERIFY(item); + QVERIFY(item->y() > lastY); + lastY = item->y(); + } + itemMiss = findItem<QQuickItem>(pathView, QString("delegate%1").arg(missing2)); + QVERIFY(!itemMiss); +} + +void tst_QQuickPathView::addCustomAttribute() +{ + const QScopedPointer<QQuickView> window(createView()); + window->setSource(testFileUrl("customAttribute.qml")); + window->show(); +} + QTEST_MAIN(tst_QQuickPathView) #include "tst_qquickpathview.moc" diff --git a/tests/auto/quick/qquickpincharea/tst_qquickpincharea.cpp b/tests/auto/quick/qquickpincharea/tst_qquickpincharea.cpp index 8063453993..3988a90aed 100644 --- a/tests/auto/quick/qquickpincharea/tst_qquickpincharea.cpp +++ b/tests/auto/quick/qquickpincharea/tst_qquickpincharea.cpp @@ -91,7 +91,7 @@ void tst_QQuickPinchArea::pinchProperties() // target QQuickItem *blackRect = window->rootObject()->findChild<QQuickItem*>("blackrect"); QVERIFY(blackRect != 0); - QVERIFY(blackRect == pinch->target()); + QCOMPARE(blackRect, pinch->target()); QQuickItem *rootItem = qobject_cast<QQuickItem*>(window->rootObject()); QVERIFY(rootItem != 0); QSignalSpy targetSpy(pinch, SIGNAL(targetChanged())); diff --git a/tests/auto/quick/qquickpixmapcache/tst_qquickpixmapcache.cpp b/tests/auto/quick/qquickpixmapcache/tst_qquickpixmapcache.cpp index b9f93a4dcf..0064212a78 100644 --- a/tests/auto/quick/qquickpixmapcache/tst_qquickpixmapcache.cpp +++ b/tests/auto/quick/qquickpixmapcache/tst_qquickpixmapcache.cpp @@ -110,12 +110,14 @@ void tst_qquickpixmapcache::initTestCase() QVERIFY2(server.listen(), qPrintable(server.errorString())); +#ifndef QT_NO_BEARERMANAGEMENT // This avoids a race condition/deadlock bug in network config // manager when it is accessed by the HTTP server thread before // anything else. Bug report can be found at: // QTBUG-26355 QNetworkConfigurationManager cm; cm.updateConfigurations(); +#endif server.serveDirectory(testFile("http")); } @@ -159,10 +161,10 @@ void tst_qquickpixmapcache::single() if (incache) { QCOMPARE(pixmap.error(), expectedError); if (exists) { - QVERIFY(pixmap.status() == QQuickPixmap::Ready); + QCOMPARE(pixmap.status(), QQuickPixmap::Ready); QVERIFY(pixmap.width() > 0); } else { - QVERIFY(pixmap.status() == QQuickPixmap::Error); + QCOMPARE(pixmap.status(), QQuickPixmap::Error); QVERIFY(pixmap.width() <= 0); } } else { @@ -174,10 +176,10 @@ void tst_qquickpixmapcache::single() QVERIFY(!QTestEventLoop::instance().timeout()); QVERIFY(getter.gotslot); if (exists) { - QVERIFY(pixmap.status() == QQuickPixmap::Ready); + QCOMPARE(pixmap.status(), QQuickPixmap::Ready); QVERIFY(pixmap.width() > 0); } else { - QVERIFY(pixmap.status() == QQuickPixmap::Error); + QCOMPARE(pixmap.status(), QQuickPixmap::Error); QVERIFY(pixmap.width() <= 0); } QCOMPARE(pixmap.error(), expectedError); @@ -259,7 +261,9 @@ void tst_qquickpixmapcache::parallel() } } - QCOMPARE(incache+slotters, targets.count()); + if (incache + slotters != targets.count()) + QFAIL(QString::fromLatin1("pixmap counts don't add up: %1 incache, %2 slotters, %3 total") + .arg(incache).arg(slotters).arg(targets.count()).toLatin1().constData()); if (cancel >= 0) { pixmaps.at(cancel)->clear(getters[cancel]); @@ -280,7 +284,12 @@ void tst_qquickpixmapcache::parallel() if (pending[i]) QVERIFY(getters[i]->gotslot); - QVERIFY(pixmap->isReady()); + if (!pixmap->isReady()) { + QFAIL(QString::fromLatin1("pixmap %1 not ready, status %2: %3") + .arg(pixmap->url().toString()).arg(pixmap->status()) + .arg(pixmap->error()).toLatin1().constData()); + + } QVERIFY(pixmap->width() > 0); delete getters[i]; } @@ -307,7 +316,7 @@ void tst_qquickpixmapcache::massive() QVERIFY(p2.isReady()); QVERIFY(p2.image().size() == QSize(10000, 1000)); - QVERIFY(p2.image().cacheKey() == cachekey); + QCOMPARE(p2.image().cacheKey(), cachekey); } // Confirm that massive images are removed from the cache when diff --git a/tests/auto/quick/qquickpositioners/data/allInvisible.qml b/tests/auto/quick/qquickpositioners/data/allInvisible.qml index 5894171434..3b95a5e1da 100644 --- a/tests/auto/quick/qquickpositioners/data/allInvisible.qml +++ b/tests/auto/quick/qquickpositioners/data/allInvisible.qml @@ -1,4 +1,4 @@ -import QtQuick 2.0 +import QtQuick 2.6 Item{ width: 400 @@ -41,4 +41,42 @@ Item{ visible: false } } + Grid{ + spacing: 20 + objectName: "grid" + Item{ + width: 0 + height: 20 + visible: false + } + Item{ + width: 20 + height: 0 + visible: false + } + Item{ + width: 20 + height: 20 + visible: false + } + } + Flow{ + spacing: 20 + objectName: "flow" + Item{ + width: 0 + height: 20 + visible: false + } + Item{ + width: 20 + height: 0 + visible: false + } + Item{ + width: 20 + height: 20 + visible: false + } + } } diff --git a/tests/auto/quick/qquickpositioners/data/flowtest-padding.qml b/tests/auto/quick/qquickpositioners/data/flowtest-padding.qml new file mode 100644 index 0000000000..a85e7a5c52 --- /dev/null +++ b/tests/auto/quick/qquickpositioners/data/flowtest-padding.qml @@ -0,0 +1,44 @@ +import QtQuick 2.6 + +Item { + width: 90 + height: 480 + property bool testRightToLeft: false + + Flow { + objectName: "flow" + width: parent.width + layoutDirection: testRightToLeft ? Qt.RightToLeft : Qt.LeftToRight + padding: 1; topPadding: 2; leftPadding: 3; rightPadding: 4; bottomPadding: 5 + Rectangle { + objectName: "one" + color: "red" + width: 50 + height: 50 + } + Rectangle { + objectName: "two" + color: "green" + width: 20 + height: 50 + } + Rectangle { + objectName: "three" + color: "blue" + width: 50 + height: 20 + } + Rectangle { + objectName: "four" + color: "cyan" + width: 50 + height: 50 + } + Rectangle { + objectName: "five" + color: "magenta" + width: 10 + height: 10 + } + } +} diff --git a/tests/auto/quick/qquickpositioners/data/gridtest-padding.qml b/tests/auto/quick/qquickpositioners/data/gridtest-padding.qml new file mode 100644 index 0000000000..46244ecef5 --- /dev/null +++ b/tests/auto/quick/qquickpositioners/data/gridtest-padding.qml @@ -0,0 +1,47 @@ +import QtQuick 2.6 + +Item { + width: 640 + height: 480 + property bool testRightToLeft: false + property int testHAlignment: Grid.AlignLeft; + property int testVAlignment: Grid.AlignTop; + Grid { + layoutDirection: testRightToLeft ? Qt.RightToLeft : Qt.LeftToRight + horizontalItemAlignment: testHAlignment + verticalItemAlignment: testVAlignment + objectName: "grid" + columns: 3 + padding: 1; topPadding: 1; leftPadding: 1; rightPadding: 1; bottomPadding: 1 + Rectangle { + objectName: "one" + color: "red" + width: 50 + height: 50 + } + Rectangle { + objectName: "two" + color: "green" + width: 20 + height: 50 + } + Rectangle { + objectName: "three" + color: "blue" + width: 30 + height: 20 + } + Rectangle { + objectName: "four" + color: "cyan" + width: 50 + height: 50 + } + Rectangle { + objectName: "five" + color: "magenta" + width: 10 + height: 10 + } + } +} diff --git a/tests/auto/quick/qquickpositioners/data/horizontal-padding.qml b/tests/auto/quick/qquickpositioners/data/horizontal-padding.qml new file mode 100644 index 0000000000..d320c4789f --- /dev/null +++ b/tests/auto/quick/qquickpositioners/data/horizontal-padding.qml @@ -0,0 +1,30 @@ +import QtQuick 2.6 + +Item { + width: 640 + height: 480 + property bool testRightToLeft: false + Row { + objectName: "row" + layoutDirection: testRightToLeft ? Qt.RightToLeft : Qt.LeftToRight + padding: 1; topPadding: 1; leftPadding: 1; rightPadding: 1; bottomPadding: 1 + Rectangle { + objectName: "one" + color: "red" + width: 50 + height: 50 + } + Rectangle { + objectName: "two" + color: "red" + width: 20 + height: 10 + } + Rectangle { + objectName: "three" + color: "red" + width: 40 + height: 20 + } + } +} diff --git a/tests/auto/quick/qquickpositioners/data/repeatertest-padding.qml b/tests/auto/quick/qquickpositioners/data/repeatertest-padding.qml new file mode 100644 index 0000000000..577d4ef0b7 --- /dev/null +++ b/tests/auto/quick/qquickpositioners/data/repeatertest-padding.qml @@ -0,0 +1,53 @@ +import QtQuick 2.6 + +Item { + width: 640 + height: 480 + Row { + padding: 1; topPadding: 2; leftPadding: 3; rightPadding: 4; bottomPadding: 5 + Repeater{ model: 3; + delegate: Component { + Rectangle { + color: "red" + width: 50 + height: 50 + z: { + if (index == 0) + return 2; + else if (index == 1) + return 1; + else + return 3; + } + objectName: { + if (index == 0) + return "one"; + else if (index == 1) + return "two"; + else + return "three"; + } + } + } + } + } + + //This crashed once (QTBUG-16959) because the repeater ended up on the end of the list + //If this grid just instantiates without crashing, then it has not regressed. + Grid { + id: grid + rows: 2 + flow: Grid.TopToBottom + + Repeater { + model: 13 + Rectangle { + color: "goldenrod" + width: 100 + height: 100 + radius: 10 + border.width: 1 + } + } + } +} diff --git a/tests/auto/quick/qquickpositioners/data/repeatertest.qml b/tests/auto/quick/qquickpositioners/data/repeatertest.qml index d90e1cf160..ae3d961c75 100644 --- a/tests/auto/quick/qquickpositioners/data/repeatertest.qml +++ b/tests/auto/quick/qquickpositioners/data/repeatertest.qml @@ -10,8 +10,22 @@ Item { color: "red" width: 50 height: 50 - z: {if(index == 0){2;}else if(index == 1){1;} else{3;}} - objectName: {if(index == 0){"one";}else if(index == 1){"two";} else{"three";}} + z: { + if (index == 0) + return 2; + else if (index == 1) + return 1; + else + return 3; + } + objectName: { + if (index == 0) + return "one"; + else if (index == 1) + return "two"; + else + return "three"; + } } } } diff --git a/tests/auto/quick/qquickpositioners/data/transitions-padding.qml b/tests/auto/quick/qquickpositioners/data/transitions-padding.qml new file mode 100644 index 0000000000..e3175c480c --- /dev/null +++ b/tests/auto/quick/qquickpositioners/data/transitions-padding.qml @@ -0,0 +1,239 @@ +import QtQuick 2.6 + +Rectangle { + id: root + width: 500 + height: 500 + + property int duration: 50 + + property real incrementalSize: 5 + + property int populateTransitionsDone + property int addTransitionsDone + property int displaceTransitionsDone + + property var targetTrans_items: new Object() + property var targetTrans_targetIndexes: new Array() + property var targetTrans_targetItems: new Array() + + property var displacedTrans_items: new Object() + property var displacedTrans_targetIndexes: new Array() + property var displacedTrans_targetItems: new Array() + + // for QQmlListProperty types + function copyList(propList) { + var temp = new Array() + for (var i=0; i<propList.length; i++) + temp.push(propList[i]) + return temp + } + + function checkPos(x, y, name) { + if (Qt.point(x, y) == targetItems_transitionFrom) + model_targetItems_transitionFrom.addItem(name, "") + if (Qt.point(x, y) == displacedItems_transitionVia) + model_displacedItems_transitionVia.addItem(name, "") + } + + Component.onCompleted: { + if (dynamicallyPopulate) { + for (var i=0; i<30; i++) + testModel.addItem("item " + i, "") + } + } + + Transition { + id: populateTransition + enabled: usePopulateTransition + + SequentialAnimation { + ScriptAction { + script: { + root.targetTrans_items[populateTransition.ViewTransition.item.nameData] = populateTransition.ViewTransition.index + root.targetTrans_targetIndexes.push(populateTransition.ViewTransition.targetIndexes) + root.targetTrans_targetItems.push(root.copyList(populateTransition.ViewTransition.targetItems)) + } + } + ParallelAnimation { + NumberAnimation { properties: "x"; from: targetItems_transitionFrom.x; duration: root.duration } + NumberAnimation { properties: "y"; from: targetItems_transitionFrom.y; duration: root.duration } + } + + ScriptAction { script: root.populateTransitionsDone += 1 } + } + } + + Transition { + id: addTransition + enabled: enableAddTransition + + SequentialAnimation { + ScriptAction { + script: { + root.targetTrans_items[addTransition.ViewTransition.item.nameData] = addTransition.ViewTransition.index + root.targetTrans_targetIndexes.push(addTransition.ViewTransition.targetIndexes) + root.targetTrans_targetItems.push(root.copyList(addTransition.ViewTransition.targetItems)) + } + } + ParallelAnimation { + NumberAnimation { properties: "x"; from: targetItems_transitionFrom.x; duration: root.duration } + NumberAnimation { properties: "y"; from: targetItems_transitionFrom.y; duration: root.duration } + } + + ScriptAction { script: root.addTransitionsDone += 1 } + } + } + + Transition { + id: displaced + + SequentialAnimation { + ScriptAction { + script: { + root.displacedTrans_items[displaced.ViewTransition.item.nameData] = displaced.ViewTransition.index + root.displacedTrans_targetIndexes.push(displaced.ViewTransition.targetIndexes) + root.displacedTrans_targetItems.push(root.copyList(displaced.ViewTransition.targetItems)) + } + } + ParallelAnimation { + NumberAnimation { properties: "x"; duration: root.duration; to: displacedItems_transitionVia.x } + NumberAnimation { properties: "y"; duration: root.duration; to: displacedItems_transitionVia.y } + } + NumberAnimation { properties: "x,y"; duration: root.duration } + + ScriptAction { script: root.displaceTransitionsDone += 1 } + } + + } + + Row { + objectName: "row" + + property int count: children.length - 1 // omit Repeater + + x: 50; y: 50 + width: 400; height: 400 + padding: 1; topPadding: 2; leftPadding: 3; rightPadding: 4; bottomPadding: 5 + Repeater { + objectName: "repeater" + model: testedPositioner == "row" ? testModel : undefined + Rectangle { + property string nameData: name + objectName: "wrapper" + width: 30 + index*root.incrementalSize + height: 30 + index*root.incrementalSize + border.width: 1 + Column { + Text { text: index } + Text { objectName: "name"; text: name } + Text { text: parent.parent.y } + } + onXChanged: root.checkPos(x, y, name) + onYChanged: root.checkPos(x, y, name) + } + } + + populate: populateTransition + add: addTransition + move: displaced + } + + Column { + objectName: "column" + + property int count: children.length - 1 // omit Repeater + + x: 50; y: 50 + width: 400; height: 400 + padding: 1; topPadding: 2; leftPadding: 3; rightPadding: 4; bottomPadding: 5 + Repeater { + objectName: "repeater" + model: testedPositioner == "column" ? testModel : undefined + Rectangle { + property string nameData: name + objectName: "wrapper" + width: 30 + index*root.incrementalSize + height: 30 + index*root.incrementalSize + border.width: 1 + Column { + Text { text: index } + Text { objectName: "name"; text: name } + Text { text: parent.parent.y } + } + onXChanged: root.checkPos(x, y, name) + onYChanged: root.checkPos(x, y, name) + } + } + + populate: populateTransition + add: addTransition + move: displaced + } + + Grid { + objectName: "grid" + + property int count: children.length - 1 // omit Repeater + + x: 50; y: 50 + width: 400; height: 400 + padding: 1; topPadding: 2; leftPadding: 3; rightPadding: 4; bottomPadding: 5 + Repeater { + objectName: "repeater" + model: testedPositioner == "grid" ? testModel : undefined + Rectangle { + property string nameData: name + objectName: "wrapper" + width: 30 + index*root.incrementalSize + height: 30 + index*root.incrementalSize + border.width: 1 + Column { + Text { text: index } + Text { objectName: "name"; text: name } + Text { text: parent.parent.y } + } + + onXChanged: root.checkPos(x, y, name) + onYChanged: root.checkPos(x, y, name) + } + } + + populate: populateTransition + add: addTransition + move: displaced + } + + Flow { + objectName: "flow" + + property int count: children.length - 1 // omit Repeater + + x: 50; y: 50 + width: 400; height: 400 + padding: 1; topPadding: 2; leftPadding: 3; rightPadding: 4; bottomPadding: 5 + Repeater { + objectName: "repeater" + model: testedPositioner == "flow" ? testModel : undefined + Rectangle { + property string nameData: name + objectName: "wrapper" + width: 30 + index*root.incrementalSize + height: 30 + index*root.incrementalSize + border.width: 1 + Column { + Text { text: index } + Text { objectName: "name"; text: name } + Text { text: parent.parent.x + " " + parent.parent.y } + } + onXChanged: root.checkPos(x, y, name) + onYChanged: root.checkPos(x, y, name) + } + } + + populate: populateTransition + add: addTransition + move: displaced + } +} + diff --git a/tests/auto/quick/qquickpositioners/tst_qquickpositioners.cpp b/tests/auto/quick/qquickpositioners/tst_qquickpositioners.cpp index 3c44041ca5..69359503fe 100644 --- a/tests/auto/quick/qquickpositioners/tst_qquickpositioners.cpp +++ b/tests/auto/quick/qquickpositioners/tst_qquickpositioners.cpp @@ -53,33 +53,50 @@ public: private slots: void test_horizontal(); + void test_horizontal_padding(); void test_horizontal_rtl(); void test_horizontal_spacing(); void test_horizontal_spacing_rightToLeft(); void test_horizontal_animated(); + void test_horizontal_animated_padding(); void test_horizontal_animated_rightToLeft(); + void test_horizontal_animated_rightToLeft_padding(); void test_horizontal_animated_disabled(); + void test_horizontal_animated_disabled_padding(); void test_vertical(); + void test_vertical_padding(); void test_vertical_spacing(); void test_vertical_animated(); + void test_vertical_animated_padding(); void test_grid(); + void test_grid_padding(); void test_grid_topToBottom(); void test_grid_rightToLeft(); void test_grid_spacing(); void test_grid_row_column_spacing(); void test_grid_animated(); + void test_grid_animated_padding(); void test_grid_animated_rightToLeft(); + void test_grid_animated_rightToLeft_padding(); void test_grid_zero_columns(); void test_grid_H_alignment(); + void test_grid_H_alignment_padding(); void test_grid_V_alignment(); + void test_grid_V_alignment_padding(); void test_propertychanges(); void test_repeater(); + void test_repeater_padding(); void test_flow(); + void test_flow_padding(); void test_flow_rightToLeft(); void test_flow_topToBottom(); + void test_flow_topToBottom_padding(); void test_flow_resize(); + void test_flow_resize_padding(); void test_flow_resize_rightToLeft(); + void test_flow_resize_rightToLeft_padding(); void test_flow_implicit_resize(); + void test_flow_implicit_resize_padding(); void test_conflictinganchors(); void test_mirroring(); void test_allInvisible(); @@ -198,18 +215,25 @@ void tst_qquickpositioners::addTransitions_grid_data() // (adding items further down the grid can cause displace transitions at // previous indexes, since grid is auto-resized to tightly fit all of its items) + QTest::addColumn<QString>("qmlFile"); QTest::addColumn<int>("initialItemCount"); QTest::addColumn<int>("insertionIndex"); QTest::addColumn<int>("insertionCount"); QTest::addColumn<ListRange>("expectedDisplacedIndexes"); - QTest::newRow("add one @ start") << 10 << 0 << 1 << ListRange(0, 9); - QTest::newRow("add one @ middle") << 10 << 5 << 1 << ListRange(3, 3) + ListRange(5, 9); - QTest::newRow("add one @ end") << 10 << 10 << 1 << ListRange(3, 3) + ListRange(7, 7); + QTest::newRow("add one @ start") << "transitions.qml" << 10 << 0 << 1 << ListRange(0, 9); + QTest::newRow("add one @ middle") << "transitions.qml" << 10 << 5 << 1 << ListRange(3, 3) + ListRange(5, 9); + QTest::newRow("add one @ end") << "transitions.qml" << 10 << 10 << 1 << ListRange(3, 3) + ListRange(7, 7); + QTest::newRow("padding, add one @ start") << "transitions-padding.qml" << 10 << 0 << 1 << ListRange(0, 9); + QTest::newRow("padding, add one @ middle") << "transitions-padding.qml" << 10 << 5 << 1 << ListRange(3, 3) + ListRange(5, 9); + QTest::newRow("padding, add one @ end") << "transitions-padding.qml" << 10 << 10 << 1 << ListRange(3, 3) + ListRange(7, 7); - QTest::newRow("add multiple @ start") << 10 << 0 << 3 << ListRange(0, 9); - QTest::newRow("add multiple @ middle") << 10 << 5 << 3 << ListRange(1, 3) + ListRange(5, 9); - QTest::newRow("add multiple @ end") << 10 << 10 << 3 << ListRange(1, 3) + ListRange(5, 7) + ListRange(9, 9); + QTest::newRow("add multiple @ start") << "transitions.qml" << 10 << 0 << 3 << ListRange(0, 9); + QTest::newRow("add multiple @ middle") << "transitions.qml" << 10 << 5 << 3 << ListRange(1, 3) + ListRange(5, 9); + QTest::newRow("add multiple @ end") << "transitions.qml" << 10 << 10 << 3 << ListRange(1, 3) + ListRange(5, 7) + ListRange(9, 9); + QTest::newRow("padding, add multiple @ start") << "transitions-padding.qml" << 10 << 0 << 3 << ListRange(0, 9); + QTest::newRow("padding, add multiple @ middle") << "transitions-padding.qml" << 10 << 5 << 3 << ListRange(1, 3) + ListRange(5, 9); + QTest::newRow("padding, add multiple @ end") << "transitions-padding.qml" << 10 << 10 << 3 << ListRange(1, 3) + ListRange(5, 7) + ListRange(9, 9); } void tst_qquickpositioners::addTransitions_flow() @@ -253,17 +277,24 @@ void tst_qquickpositioners::moveTransitions_grid_data() // (removing items further down the grid can cause displace transitions at // previous indexes, since grid is auto-resized to tightly fit all of its items) + QTest::addColumn<QString>("qmlFile"); QTest::addColumn<int>("initialItemCount"); QTest::addColumn<ListChange>("change"); QTest::addColumn<ListRange>("expectedDisplacedIndexes"); - QTest::newRow("remove one @ start") << 10 << ListChange::remove(0, 1) << ListRange(1, 9); - QTest::newRow("remove one @ middle") << 10 << ListChange::remove(4, 1) << ListRange(2, 3) + ListRange(5, 9); - QTest::newRow("remove one @ end") << 10 << ListChange::remove(9, 1) << ListRange(2, 3) + ListRange(6, 7); + QTest::newRow("remove one @ start") << "transitions.qml" << 10 << ListChange::remove(0, 1) << ListRange(1, 9); + QTest::newRow("remove one @ middle") << "transitions.qml" << 10 << ListChange::remove(4, 1) << ListRange(2, 3) + ListRange(5, 9); + QTest::newRow("remove one @ end") << "transitions.qml" << 10 << ListChange::remove(9, 1) << ListRange(2, 3) + ListRange(6, 7); + QTest::newRow("padding, remove one @ start") << "transitions-padding.qml" << 10 << ListChange::remove(0, 1) << ListRange(1, 9); + QTest::newRow("padding, remove one @ middle") << "transitions-padding.qml" << 10 << ListChange::remove(4, 1) << ListRange(2, 3) + ListRange(5, 9); + QTest::newRow("padding, remove one @ end") << "transitions-padding.qml" << 10 << ListChange::remove(9, 1) << ListRange(2, 3) + ListRange(6, 7); - QTest::newRow("remove multiple @ start") << 10 << ListChange::remove(0, 3) << ListRange(3, 9); - QTest::newRow("remove multiple @ middle") << 10 << ListChange::remove(4, 3) << ListRange(1, 3) + ListRange(7, 9); - QTest::newRow("remove multiple @ end") << 10 << ListChange::remove(7, 3) << ListRange(1, 3) + ListRange(5, 6); + QTest::newRow("remove multiple @ start") << "transitions.qml" << 10 << ListChange::remove(0, 3) << ListRange(3, 9); + QTest::newRow("remove multiple @ middle") << "transitions.qml" << 10 << ListChange::remove(4, 3) << ListRange(1, 3) + ListRange(7, 9); + QTest::newRow("remove multiple @ end") << "transitions.qml" << 10 << ListChange::remove(7, 3) << ListRange(1, 3) + ListRange(5, 6); + QTest::newRow("padding, remove multiple @ start") << "transitions-padding.qml" << 10 << ListChange::remove(0, 3) << ListRange(3, 9); + QTest::newRow("padding, remove multiple @ middle") << "transitions-padding.qml" << 10 << ListChange::remove(4, 3) << ListRange(1, 3) + ListRange(7, 9); + QTest::newRow("padding, remove multiple @ end") << "transitions-padding.qml" << 10 << ListChange::remove(7, 3) << ListRange(1, 3) + ListRange(5, 6); } void tst_qquickpositioners::moveTransitions_flow() @@ -305,6 +336,185 @@ void tst_qquickpositioners::test_horizontal() QQuickItem *row = window->rootObject()->findChild<QQuickItem*>("row"); QCOMPARE(row->width(), 110.0); QCOMPARE(row->height(), 50.0); + + // test padding + row->setProperty("padding", 1); + row->setProperty("topPadding", 2); + row->setProperty("leftPadding", 3); + row->setProperty("rightPadding", 4); + row->setProperty("bottomPadding", 5); + + QTRY_COMPARE(row->width(), 117.0); + QCOMPARE(row->height(), 57.0); + + QCOMPARE(one->x(), 3.0); + QCOMPARE(one->y(), 2.0); + QCOMPARE(two->x(), 53.0); + QCOMPARE(two->y(), 2.0); + QCOMPARE(three->x(), 73.0); + QCOMPARE(three->y(), 2.0); +} + +void tst_qquickpositioners::test_horizontal_padding() +{ + QScopedPointer<QQuickView> window(createView(testFile("horizontal.qml"))); + + window->rootObject()->setProperty("testRightToLeft", false); + + QQuickRectangle *one = window->rootObject()->findChild<QQuickRectangle*>("one"); + QVERIFY(one != 0); + + QQuickRectangle *two = window->rootObject()->findChild<QQuickRectangle*>("two"); + QVERIFY(two != 0); + + QQuickRectangle *three = window->rootObject()->findChild<QQuickRectangle*>("three"); + QVERIFY(three != 0); + + QCOMPARE(one->x(), 0.0); + QCOMPARE(one->y(), 0.0); + QCOMPARE(two->x(), 50.0); + QCOMPARE(two->y(), 0.0); + QCOMPARE(three->x(), 70.0); + QCOMPARE(three->y(), 0.0); + + QQuickItem *row = window->rootObject()->findChild<QQuickItem*>("row"); + QCOMPARE(row->width(), 110.0); + QCOMPARE(row->height(), 50.0); + + QQuickRow *obj = qobject_cast<QQuickRow*>(row); + QVERIFY(obj != 0); + + QCOMPARE(row->property("padding").toDouble(), 0.0); + QCOMPARE(row->property("topPadding").toDouble(), 0.0); + QCOMPARE(row->property("leftPadding").toDouble(), 0.0); + QCOMPARE(row->property("rightPadding").toDouble(), 0.0); + QCOMPARE(row->property("bottomPadding").toDouble(), 0.0); + + obj->setPadding(1.0); + + QCOMPARE(row->property("padding").toDouble(), 1.0); + QCOMPARE(row->property("topPadding").toDouble(), 1.0); + QCOMPARE(row->property("leftPadding").toDouble(), 1.0); + QCOMPARE(row->property("rightPadding").toDouble(), 1.0); + QCOMPARE(row->property("bottomPadding").toDouble(), 1.0); + + QTRY_COMPARE(row->width(), 112.0); + QCOMPARE(row->height(), 52.0); + + QCOMPARE(one->x(), 1.0); + QCOMPARE(one->y(), 1.0); + QCOMPARE(two->x(), 51.0); + QCOMPARE(two->y(), 1.0); + QCOMPARE(three->x(), 71.0); + QCOMPARE(three->y(), 1.0); + + obj->setTopPadding(2.0); + + QCOMPARE(row->property("padding").toDouble(), 1.0); + QCOMPARE(row->property("topPadding").toDouble(), 2.0); + QCOMPARE(row->property("leftPadding").toDouble(), 1.0); + QCOMPARE(row->property("rightPadding").toDouble(), 1.0); + QCOMPARE(row->property("bottomPadding").toDouble(), 1.0); + + QTRY_COMPARE(row->height(), 53.0); + QCOMPARE(row->width(), 112.0); + + QCOMPARE(one->x(), 1.0); + QCOMPARE(one->y(), 2.0); + QCOMPARE(two->x(), 51.0); + QCOMPARE(two->y(), 2.0); + QCOMPARE(three->x(), 71.0); + QCOMPARE(three->y(), 2.0); + + obj->setLeftPadding(3.0); + + QCOMPARE(row->property("padding").toDouble(), 1.0); + QCOMPARE(row->property("topPadding").toDouble(), 2.0); + QCOMPARE(row->property("leftPadding").toDouble(), 3.0); + QCOMPARE(row->property("rightPadding").toDouble(), 1.0); + QCOMPARE(row->property("bottomPadding").toDouble(), 1.0); + + QTRY_COMPARE(row->width(), 114.0); + QCOMPARE(row->height(), 53.0); + + QCOMPARE(one->x(), 3.0); + QCOMPARE(one->y(), 2.0); + QCOMPARE(two->x(), 53.0); + QCOMPARE(two->y(), 2.0); + QCOMPARE(three->x(), 73.0); + QCOMPARE(three->y(), 2.0); + + obj->setRightPadding(4.0); + + QCOMPARE(row->property("padding").toDouble(), 1.0); + QCOMPARE(row->property("topPadding").toDouble(), 2.0); + QCOMPARE(row->property("leftPadding").toDouble(), 3.0); + QCOMPARE(row->property("rightPadding").toDouble(), 4.0); + QCOMPARE(row->property("bottomPadding").toDouble(), 1.0); + + QTRY_COMPARE(row->width(), 117.0); + QCOMPARE(row->height(), 53.0); + + QCOMPARE(one->x(), 3.0); + QCOMPARE(one->y(), 2.0); + QCOMPARE(two->x(), 53.0); + QCOMPARE(two->y(), 2.0); + QCOMPARE(three->x(), 73.0); + QCOMPARE(three->y(), 2.0); + + obj->setBottomPadding(5.0); + + QCOMPARE(row->property("padding").toDouble(), 1.0); + QCOMPARE(row->property("topPadding").toDouble(), 2.0); + QCOMPARE(row->property("leftPadding").toDouble(), 3.0); + QCOMPARE(row->property("rightPadding").toDouble(), 4.0); + QCOMPARE(row->property("bottomPadding").toDouble(), 5.0); + + QTRY_COMPARE(row->height(), 57.0); + QCOMPARE(row->width(), 117.0); + + QCOMPARE(one->x(), 3.0); + QCOMPARE(one->y(), 2.0); + QCOMPARE(two->x(), 53.0); + QCOMPARE(two->y(), 2.0); + QCOMPARE(three->x(), 73.0); + QCOMPARE(three->y(), 2.0); + + obj->resetBottomPadding(); + QCOMPARE(row->property("bottomPadding").toDouble(), 1.0); + QTRY_COMPARE(row->height(), 53.0); + QCOMPARE(row->width(), 117.0); + + obj->resetRightPadding(); + QCOMPARE(row->property("rightPadding").toDouble(), 1.0); + QTRY_COMPARE(row->width(), 114.0); + QCOMPARE(row->height(), 53.0); + + obj->resetLeftPadding(); + QCOMPARE(row->property("leftPadding").toDouble(), 1.0); + QTRY_COMPARE(row->width(), 112.0); + QCOMPARE(row->height(), 53.0); + + obj->resetTopPadding(); + QCOMPARE(row->property("topPadding").toDouble(), 1.0); + QTRY_COMPARE(row->height(), 52.0); + QCOMPARE(row->width(), 112.0); + + obj->resetPadding(); + QCOMPARE(row->property("padding").toDouble(), 0.0); + QCOMPARE(row->property("topPadding").toDouble(), 0.0); + QCOMPARE(row->property("leftPadding").toDouble(), 0.0); + QCOMPARE(row->property("rightPadding").toDouble(), 0.0); + QCOMPARE(row->property("bottomPadding").toDouble(), 0.0); + QTRY_COMPARE(row->height(), 50.0); + QCOMPARE(row->width(), 110.0); + + QCOMPARE(one->x(), 0.0); + QCOMPARE(one->y(), 0.0); + QCOMPARE(two->x(), 50.0); + QCOMPARE(two->y(), 0.0); + QCOMPARE(three->x(), 70.0); + QCOMPARE(three->y(), 0.0); } void tst_qquickpositioners::test_horizontal_rtl() @@ -333,6 +543,36 @@ void tst_qquickpositioners::test_horizontal_rtl() QCOMPARE(row->width(), 110.0); QCOMPARE(row->height(), 50.0); + // test padding + row->setProperty("padding", 1); + row->setProperty("topPadding", 2); + row->setProperty("leftPadding", 3); + row->setProperty("rightPadding", 4); + row->setProperty("bottomPadding", 5); + + QTRY_COMPARE(row->width(), 117.0); + QCOMPARE(row->height(), 57.0); + + QCOMPARE(one->x(), 63.0); + QCOMPARE(one->y(), 2.0); + QCOMPARE(two->x(), 43.0); + QCOMPARE(two->y(), 2.0); + QCOMPARE(three->x(), 3.0); + QCOMPARE(three->y(), 2.0); + + row->setProperty("topPadding", 0); + row->setProperty("leftPadding", 0); + row->setProperty("rightPadding", 0); + row->setProperty("bottomPadding", 0); + row->setProperty("padding", 0); + + QTRY_COMPARE(one->x(), 60.0); + QCOMPARE(one->y(), 0.0); + QCOMPARE(two->x(), 40.0); + QCOMPARE(two->y(), 0.0); + QCOMPARE(three->x(), 0.0); + QCOMPARE(three->y(), 0.0); + // Change the width of the row and check that items stay to the right row->setWidth(200); QTRY_COMPARE(one->x(), 150.0); @@ -342,6 +582,18 @@ void tst_qquickpositioners::test_horizontal_rtl() QCOMPARE(three->x(), 90.0); QCOMPARE(three->y(), 0.0); + row->setProperty("padding", 1); + row->setProperty("topPadding", 2); + row->setProperty("leftPadding", 3); + row->setProperty("rightPadding", 4); + row->setProperty("bottomPadding", 5); + + QTRY_COMPARE(one->x(), 146.0); + QCOMPARE(one->y(), 2.0); + QCOMPARE(two->x(), 126.0); + QCOMPARE(two->y(), 2.0); + QCOMPARE(three->x(), 86.0); + QCOMPARE(three->y(), 2.0); } void tst_qquickpositioners::test_horizontal_spacing() @@ -370,6 +622,22 @@ void tst_qquickpositioners::test_horizontal_spacing() QCOMPARE(row->width(), 130.0); QCOMPARE(row->height(), 50.0); + // test padding + row->setProperty("padding", 1); + row->setProperty("topPadding", 2); + row->setProperty("leftPadding", 3); + row->setProperty("rightPadding", 4); + row->setProperty("bottomPadding", 5); + + QTRY_COMPARE(row->width(), 137.0); + QCOMPARE(row->height(), 57.0); + + QCOMPARE(one->x(), 3.0); + QCOMPARE(one->y(), 2.0); + QCOMPARE(two->x(), 63.0); + QCOMPARE(two->y(), 2.0); + QCOMPARE(three->x(), 93.0); + QCOMPARE(three->y(), 2.0); } void tst_qquickpositioners::test_horizontal_spacing_rightToLeft() @@ -391,13 +659,29 @@ void tst_qquickpositioners::test_horizontal_spacing_rightToLeft() QCOMPARE(one->y(), 0.0); QCOMPARE(two->x(), 50.0); QCOMPARE(two->y(), 0.0); - QCOMPARE(three->x(), 00.0); + QCOMPARE(three->x(), 0.0); QCOMPARE(three->y(), 0.0); QQuickItem *row = window->rootObject()->findChild<QQuickItem*>("row"); QCOMPARE(row->width(), 130.0); QCOMPARE(row->height(), 50.0); + // test padding + row->setProperty("padding", 1); + row->setProperty("topPadding", 2); + row->setProperty("leftPadding", 3); + row->setProperty("rightPadding", 4); + row->setProperty("bottomPadding", 5); + + QTRY_COMPARE(row->width(), 137.0); + QCOMPARE(row->height(), 57.0); + + QCOMPARE(one->x(), 83.0); + QCOMPARE(one->y(), 2.0); + QCOMPARE(two->x(), 53.0); + QCOMPARE(two->y(), 2.0); + QCOMPARE(three->x(), 3.0); + QCOMPARE(three->y(), 2.0); } void tst_qquickpositioners::test_horizontal_animated() @@ -453,6 +737,70 @@ void tst_qquickpositioners::test_horizontal_animated() } +void tst_qquickpositioners::test_horizontal_animated_padding() +{ + QScopedPointer<QQuickView> window(createView(testFile("horizontal-animated.qml"), false)); + + window->rootObject()->setProperty("testRightToLeft", false); + + QQuickRectangle *one = window->rootObject()->findChild<QQuickRectangle*>("one"); + QVERIFY(one != 0); + + QQuickRectangle *two = window->rootObject()->findChild<QQuickRectangle*>("two"); + QVERIFY(two != 0); + + QQuickRectangle *three = window->rootObject()->findChild<QQuickRectangle*>("three"); + QVERIFY(three != 0); + + //Note that they animate in + QCOMPARE(one->x(), -100.0); + QCOMPARE(two->x(), -100.0); + QCOMPARE(three->x(), -100.0); + + QVERIFY(QTest::qWaitForWindowExposed(window.data())); //It may not relayout until the next frame, so it needs to be drawn + + QQuickItem *row = window->rootObject()->findChild<QQuickItem*>("row"); + QVERIFY(row); + QCOMPARE(row->width(), 100.0); + QCOMPARE(row->height(), 50.0); + + // test padding + row->setProperty("padding", 1); + row->setProperty("topPadding", 2); + row->setProperty("leftPadding", 3); + row->setProperty("rightPadding", 4); + row->setProperty("bottomPadding", 5); + + QTRY_COMPARE(row->width(), 107.0); + QCOMPARE(row->height(), 57.0); + + //QTRY_COMPARE used instead of waiting for the expected time of animation completion + //Note that this means the duration of the animation is NOT tested + + QTRY_COMPARE(one->x(), 3.0); + QTRY_COMPARE(one->y(), 2.0); + QTRY_COMPARE(two->isVisible(), false); + QTRY_COMPARE(two->x(), -100.0);//Not 'in' yet + QTRY_COMPARE(two->y(), 0.0); + QTRY_COMPARE(three->x(), 53.0); + QTRY_COMPARE(three->y(), 2.0); + + //Add 'two' + two->setVisible(true); + QTRY_COMPARE(two->isVisible(), true); + QTRY_COMPARE(row->width(), 157.0); + QTRY_COMPARE(row->height(), 57.0); + + QTest::qWait(0);//Let the animation start + QVERIFY(two->x() >= -100.0 && two->x() < 53.0); + QVERIFY(three->x() >= 53.0 && three->x() < 103.0); + + QTRY_COMPARE(two->y(), 2.0); + QTRY_COMPARE(two->x(), 53.0); + QTRY_COMPARE(three->x(), 103.0); + +} + void tst_qquickpositioners::test_horizontal_animated_rightToLeft() { QScopedPointer<QQuickView> window(createView(testFile("horizontal-animated.qml"), false)); @@ -508,6 +856,72 @@ void tst_qquickpositioners::test_horizontal_animated_rightToLeft() } +void tst_qquickpositioners::test_horizontal_animated_rightToLeft_padding() +{ + QScopedPointer<QQuickView> window(createView(testFile("horizontal-animated.qml"), false)); + + window->rootObject()->setProperty("testRightToLeft", true); + + QQuickRectangle *one = window->rootObject()->findChild<QQuickRectangle*>("one"); + QVERIFY(one != 0); + + QQuickRectangle *two = window->rootObject()->findChild<QQuickRectangle*>("two"); + QVERIFY(two != 0); + + QQuickRectangle *three = window->rootObject()->findChild<QQuickRectangle*>("three"); + QVERIFY(three != 0); + + //Note that they animate in + QCOMPARE(one->x(), -100.0); + QCOMPARE(two->x(), -100.0); + QCOMPARE(three->x(), -100.0); + + QVERIFY(QTest::qWaitForWindowExposed(window.data())); //It may not relayout until the next frame, so it needs to be drawn + + QQuickItem *row = window->rootObject()->findChild<QQuickItem*>("row"); + QVERIFY(row); + QCOMPARE(row->width(), 100.0); + QCOMPARE(row->height(), 50.0); + + // test padding + row->setProperty("padding", 1); + row->setProperty("topPadding", 2); + row->setProperty("leftPadding", 3); + row->setProperty("rightPadding", 4); + row->setProperty("bottomPadding", 5); + + QTRY_COMPARE(row->width(), 107.0); + QCOMPARE(row->height(), 57.0); + + //QTRY_COMPARE used instead of waiting for the expected time of animation completion + //Note that this means the duration of the animation is NOT tested + + QTRY_COMPARE(one->x(), 53.0); + QTRY_COMPARE(one->y(), 2.0); + QTRY_COMPARE(two->isVisible(), false); + QTRY_COMPARE(two->x(), -100.0);//Not 'in' yet + QTRY_COMPARE(two->y(), 0.0); + QTRY_COMPARE(three->x(), 3.0); + QTRY_COMPARE(three->y(), 2.0); + + //Add 'two' + two->setVisible(true); + QTRY_COMPARE(two->isVisible(), true); + + // New size should propagate after visible change + QTRY_COMPARE(row->width(), 157.0); + QTRY_COMPARE(row->height(), 57.0); + + QTest::qWait(0);//Let the animation start + QVERIFY(one->x() >= 53.0 && one->x() < 100); + QVERIFY(two->x() >= -100.0 && two->x() < 53.0); + + QTRY_COMPARE(one->x(), 103.0); + QTRY_COMPARE(two->y(), 2.0); + QTRY_COMPARE(two->x(), 53.0); + +} + void tst_qquickpositioners::test_horizontal_animated_disabled() { QScopedPointer<QQuickView> window(createView(testFile("horizontal-animated-disabled.qml"))); @@ -526,6 +940,54 @@ void tst_qquickpositioners::test_horizontal_animated_disabled() qApp->processEvents(); + // test padding + row->setProperty("padding", 1); + row->setProperty("topPadding", 2); + row->setProperty("leftPadding", 3); + row->setProperty("rightPadding", 4); + row->setProperty("bottomPadding", 5); + + QTRY_COMPARE(row->width(), 107.0); + QCOMPARE(row->height(), 57.0); + + QCOMPARE(one->x(), 3.0); + QCOMPARE(one->y(), 2.0); + QCOMPARE(two->isVisible(), false); + QCOMPARE(two->x(), -100.0);//Not 'in' yet + QCOMPARE(two->y(), 0.0); + QCOMPARE(three->x(), 53.0); + QCOMPARE(three->y(), 2.0); + + //Add 'two' + two->setVisible(true); + QCOMPARE(two->isVisible(), true); + QTRY_COMPARE(row->width(), 157.0); + QTRY_COMPARE(row->height(), 57.0); + + QTRY_COMPARE(two->y(), 2.0); + QTRY_COMPARE(two->x(), 53.0); + QTRY_COMPARE(three->x(), 103.0); + +} + +void tst_qquickpositioners::test_horizontal_animated_disabled_padding() +{ + QScopedPointer<QQuickView> window(createView(testFile("horizontal-animated-disabled.qml"))); + + QQuickRectangle *one = window->rootObject()->findChild<QQuickRectangle*>("one"); + QVERIFY(one != 0); + + QQuickRectangle *two = window->rootObject()->findChild<QQuickRectangle*>("two"); + QVERIFY(two != 0); + + QQuickRectangle *three = window->rootObject()->findChild<QQuickRectangle*>("three"); + QVERIFY(three != 0); + + QQuickItem *row = window->rootObject()->findChild<QQuickItem*>("row"); + QVERIFY(row); + + qApp->processEvents(); + QCOMPARE(one->x(), 0.0); QCOMPARE(one->y(), 0.0); QCOMPARE(two->isVisible(), false); @@ -547,6 +1009,7 @@ void tst_qquickpositioners::test_horizontal_animated_disabled() void tst_qquickpositioners::populateTransitions(const QString &positionerObjectName) { + QFETCH(QString, qmlFile); QFETCH(bool, dynamicallyPopulate); QFETCH(bool, usePopulateTransition); @@ -574,7 +1037,7 @@ void tst_qquickpositioners::populateTransitions(const QString &positionerObjectN ctxt->setContextProperty("targetItems_transitionFrom", targetItems_transitionFrom); ctxt->setContextProperty("displacedItems_transitionVia", displacedItems_transitionVia); ctxt->setContextProperty("testedPositioner", positionerObjectName); - window->setSource(testFileUrl("transitions.qml")); + window->setSource(testFileUrl(qmlFile)); QQuickItem *positioner = window->rootObject()->findChild<QQuickItem*>(positionerObjectName); QVERIFY(positioner); @@ -619,18 +1082,24 @@ void tst_qquickpositioners::populateTransitions(const QString &positionerObjectN void tst_qquickpositioners::populateTransitions_data() { + QTest::addColumn<QString>("qmlFile"); QTest::addColumn<bool>("dynamicallyPopulate"); QTest::addColumn<bool>("usePopulateTransition"); - QTest::newRow("statically populate") << false << true; - QTest::newRow("statically populate, no populate transition") << false << false; + QTest::newRow("statically populate") << "transitions.qml" << false << true; + QTest::newRow("statically populate, no populate transition") << "transitions.qml" << false << false; + QTest::newRow("padding, statically populate") << "transitions-padding.qml" << false << true; + QTest::newRow("padding, statically populate, no populate transition") << "transitions-padding.qml" << false << false; - QTest::newRow("dynamically populate") << true << true; - QTest::newRow("dynamically populate, no populate transition") << true << false; + QTest::newRow("dynamically populate") << "transitions.qml" << true << true; + QTest::newRow("dynamically populate, no populate transition") << "transitions.qml" << true << false; + QTest::newRow("padding, dynamically populate") << "transitions-padding.qml" << true << true; + QTest::newRow("padding, dynamically populate, no populate transition") << "transitions-padding.qml" << true << false; } void tst_qquickpositioners::addTransitions(const QString &positionerObjectName) { + QFETCH(QString, qmlFile); QFETCH(int, initialItemCount); QFETCH(int, insertionIndex); QFETCH(int, insertionCount); @@ -654,7 +1123,7 @@ void tst_qquickpositioners::addTransitions(const QString &positionerObjectName) ctxt->setContextProperty("targetItems_transitionFrom", targetItems_transitionFrom); ctxt->setContextProperty("displacedItems_transitionVia", displacedItems_transitionVia); ctxt->setContextProperty("testedPositioner", QString()); - window->setSource(testFileUrl("transitions.qml")); + window->setSource(testFileUrl(qmlFile)); window->show(); QTest::qWaitForWindowExposed(window.data()); qApp->processEvents(); @@ -729,22 +1198,30 @@ void tst_qquickpositioners::addTransitions_data() { // If this data changes, update addTransitions_grid_data() also + QTest::addColumn<QString>("qmlFile"); QTest::addColumn<int>("initialItemCount"); QTest::addColumn<int>("insertionIndex"); QTest::addColumn<int>("insertionCount"); QTest::addColumn<ListRange>("expectedDisplacedIndexes"); - QTest::newRow("add one @ start") << 10 << 0 << 1 << ListRange(0, 9); - QTest::newRow("add one @ middle") << 10 << 5 << 1 << ListRange(5, 9); - QTest::newRow("add one @ end") << 10 << 10 << 1 << ListRange(); + QTest::newRow("add one @ start") << "transitions.qml" << 10 << 0 << 1 << ListRange(0, 9); + QTest::newRow("add one @ middle") << "transitions.qml" << 10 << 5 << 1 << ListRange(5, 9); + QTest::newRow("add one @ end") << "transitions.qml" << 10 << 10 << 1 << ListRange(); + QTest::newRow("padding, add one @ start") << "transitions-padding.qml" << 10 << 0 << 1 << ListRange(0, 9); + QTest::newRow("padding, add one @ middle") << "transitions-padding.qml" << 10 << 5 << 1 << ListRange(5, 9); + QTest::newRow("padding, add one @ end") << "transitions-padding.qml" << 10 << 10 << 1 << ListRange(); - QTest::newRow("add multiple @ start") << 10 << 0 << 3 << ListRange(0, 9); - QTest::newRow("add multiple @ middle") << 10 << 5 << 3 << ListRange(5, 9); - QTest::newRow("add multiple @ end") << 10 << 10 << 3 << ListRange(); + QTest::newRow("add multiple @ start") << "transitions.qml" << 10 << 0 << 3 << ListRange(0, 9); + QTest::newRow("add multiple @ middle") << "transitions.qml" << 10 << 5 << 3 << ListRange(5, 9); + QTest::newRow("add multiple @ end") << "transitions.qml" << 10 << 10 << 3 << ListRange(); + QTest::newRow("padding, add multiple @ start") << "transitions-padding.qml" << 10 << 0 << 3 << ListRange(0, 9); + QTest::newRow("padding, add multiple @ middle") << "transitions-padding.qml" << 10 << 5 << 3 << ListRange(5, 9); + QTest::newRow("padding, add multiple @ end") << "transitions-padding.qml" << 10 << 10 << 3 << ListRange(); } void tst_qquickpositioners::moveTransitions(const QString &positionerObjectName) { + QFETCH(QString, qmlFile); QFETCH(int, initialItemCount); QFETCH(ListChange, change); QFETCH(ListRange, expectedDisplacedIndexes); @@ -769,7 +1246,7 @@ void tst_qquickpositioners::moveTransitions(const QString &positionerObjectName) ctxt->setContextProperty("targetItems_transitionFrom", targetItems_transitionFrom); ctxt->setContextProperty("displacedItems_transitionVia", displacedItems_transitionVia); ctxt->setContextProperty("testedPositioner", QString()); - window->setSource(testFileUrl("transitions.qml")); + window->setSource(testFileUrl(qmlFile)); window->show(); QTest::qWaitForWindowExposed(window.data()); qApp->processEvents(); @@ -840,27 +1317,36 @@ void tst_qquickpositioners::moveTransitions_data() { // If this data changes, update moveTransitions_grid_data() also + QTest::addColumn<QString>("qmlFile"); QTest::addColumn<int>("initialItemCount"); QTest::addColumn<ListChange>("change"); QTest::addColumn<ListRange>("expectedDisplacedIndexes"); - QTest::newRow("remove one @ start") << 10 << ListChange::remove(0, 1) << ListRange(1, 9); - QTest::newRow("remove one @ middle") << 10 << ListChange::remove(4, 1) << ListRange(5, 9); - QTest::newRow("remove one @ end") << 10 << ListChange::remove(9, 1) << ListRange(); + QTest::newRow("remove one @ start") << "transitions.qml" << 10 << ListChange::remove(0, 1) << ListRange(1, 9); + QTest::newRow("remove one @ middle") << "transitions.qml" << 10 << ListChange::remove(4, 1) << ListRange(5, 9); + QTest::newRow("remove one @ end") << "transitions.qml" << 10 << ListChange::remove(9, 1) << ListRange(); + QTest::newRow("padding, remove one @ start") << "transitions-padding.qml" << 10 << ListChange::remove(0, 1) << ListRange(1, 9); + QTest::newRow("padding, remove one @ middle") << "transitions-padding.qml" << 10 << ListChange::remove(4, 1) << ListRange(5, 9); + QTest::newRow("padding, remove one @ end") << "transitions-padding.qml" << 10 << ListChange::remove(9, 1) << ListRange(); - QTest::newRow("remove multiple @ start") << 10 << ListChange::remove(0, 3) << ListRange(3, 9); - QTest::newRow("remove multiple @ middle") << 10 << ListChange::remove(4, 3) << ListRange(7, 9); - QTest::newRow("remove multiple @ end") << 10 << ListChange::remove(7, 3) << ListRange(); + QTest::newRow("remove multiple @ start") << "transitions.qml" << 10 << ListChange::remove(0, 3) << ListRange(3, 9); + QTest::newRow("remove multiple @ middle") << "transitions.qml" << 10 << ListChange::remove(4, 3) << ListRange(7, 9); + QTest::newRow("remove multiple @ end") << "transitions.qml" << 10 << ListChange::remove(7, 3) << ListRange(); + QTest::newRow("padding, remove multiple @ start") << "transitions-padding.qml" << 10 << ListChange::remove(0, 3) << ListRange(3, 9); + QTest::newRow("padding, remove multiple @ middle") << "transitions-padding.qml" << 10 << ListChange::remove(4, 3) << ListRange(7, 9); + QTest::newRow("padding, remove multiple @ end") << "transitions-padding.qml" << 10 << ListChange::remove(7, 3) << ListRange(); } - void tst_qquickpositioners::checkItemPositions(QQuickItem *positioner, QaimModel *model, qreal incrementalSize) { QVERIFY(model->count() > 0); + + QQuickBasePositioner *p = qobject_cast<QQuickBasePositioner*>(positioner); + qreal padding = 0; qreal currentSize = 30; - qreal rowX = 0; - qreal rowY = 0; + qreal rowX = p->leftPadding(); + qreal rowY = p->topPadding(); for (int i=0; i<model->count(); ++i) { QQuickItem *item = findItem<QQuickItem>(positioner, "wrapper", i); @@ -870,11 +1356,11 @@ void tst_qquickpositioners::checkItemPositions(QQuickItem *positioner, QaimModel QCOMPARE(item->height(), currentSize); if (qobject_cast<QQuickRow*>(positioner)) { - QCOMPARE(item->x(), (i * 30.0) + padding); - QCOMPARE(item->y(), 0.0); + QCOMPARE(item->x(), (i * 30.0) + padding + p->leftPadding()); + QCOMPARE(item->y(), p->topPadding()); } else if (qobject_cast<QQuickColumn*>(positioner)) { - QCOMPARE(item->x(), 0.0); - QCOMPARE(item->y(), (i * 30.0) + padding); + QCOMPARE(item->x(), p->leftPadding()); + QCOMPARE(item->y(), (i * 30.0) + padding + p->topPadding()); } else if (qobject_cast<QQuickGrid*>(positioner)) { int columns = 4; int rows = qCeil(model->count() / qreal(columns)); @@ -886,20 +1372,20 @@ void tst_qquickpositioners::checkItemPositions(QQuickItem *positioner, QaimModel QVERIFY(finalAlignedRowItem); QCOMPARE(item->x(), finalAlignedRowItem->x()); } else { - QCOMPARE(item->x(), 0.0); + QCOMPARE(item->x(), p->leftPadding()); } if (i / columns > 0) { QQuickItem *prevRowLastItem = findItem<QQuickItem>(positioner, "wrapper", (i/columns * columns) - 1); QVERIFY(prevRowLastItem); QCOMPARE(item->y(), prevRowLastItem->y() + prevRowLastItem->height()); } else { - QCOMPARE(item->y(), 0.0); + QCOMPARE(item->y(), p->topPadding()); } } else if (qobject_cast<QQuickFlow*>(positioner)) { if (rowX + item->width() > positioner->width()) { QQuickItem *prevItem = findItem<QQuickItem>(positioner, "wrapper", i-1); QVERIFY(prevItem); - rowX = 0; + rowX = p->leftPadding(); rowY = prevItem->y() + prevItem->height(); } QCOMPARE(item->x(), rowX); @@ -942,6 +1428,183 @@ void tst_qquickpositioners::test_vertical() QCOMPARE(column->height(), 80.0); QCOMPARE(column->width(), 50.0); + // test padding + column->setProperty("padding", 1); + column->setProperty("topPadding", 2); + column->setProperty("leftPadding", 3); + column->setProperty("rightPadding", 4); + column->setProperty("bottomPadding", 5); + + QTRY_COMPARE(column->height(), 87.0); + QCOMPARE(column->width(), 57.0); + + QCOMPARE(one->x(), 3.0); + QCOMPARE(one->y(), 2.0); + QCOMPARE(two->x(), 3.0); + QCOMPARE(two->y(), 52.0); + QCOMPARE(three->x(), 3.0); + QCOMPARE(three->y(), 62.0); +} + +void tst_qquickpositioners::test_vertical_padding() +{ + QScopedPointer<QQuickView> window(createView(testFile("vertical.qml"))); + + QQuickRectangle *one = window->rootObject()->findChild<QQuickRectangle*>("one"); + QVERIFY(one != 0); + + QQuickRectangle *two = window->rootObject()->findChild<QQuickRectangle*>("two"); + QVERIFY(two != 0); + + QQuickRectangle *three = window->rootObject()->findChild<QQuickRectangle*>("three"); + QVERIFY(three != 0); + + QCOMPARE(one->x(), 0.0); + QCOMPARE(one->y(), 0.0); + QCOMPARE(two->x(), 0.0); + QCOMPARE(two->y(), 50.0); + QCOMPARE(three->x(), 0.0); + QCOMPARE(three->y(), 60.0); + + QQuickItem *column = window->rootObject()->findChild<QQuickItem*>("column"); + QVERIFY(column); + QCOMPARE(column->height(), 80.0); + QCOMPARE(column->width(), 50.0); + + QQuickColumn *obj = qobject_cast<QQuickColumn*>(column); + QVERIFY(obj != 0); + + QCOMPARE(column->property("padding").toDouble(), 0.0); + QCOMPARE(column->property("topPadding").toDouble(), 0.0); + QCOMPARE(column->property("leftPadding").toDouble(), 0.0); + QCOMPARE(column->property("rightPadding").toDouble(), 0.0); + QCOMPARE(column->property("bottomPadding").toDouble(), 0.0); + + obj->setPadding(1.0); + + QCOMPARE(column->property("padding").toDouble(), 1.0); + QCOMPARE(column->property("topPadding").toDouble(), 1.0); + QCOMPARE(column->property("leftPadding").toDouble(), 1.0); + QCOMPARE(column->property("rightPadding").toDouble(), 1.0); + QCOMPARE(column->property("bottomPadding").toDouble(), 1.0); + + QTRY_COMPARE(column->height(), 82.0); + QCOMPARE(column->width(), 52.0); + + QCOMPARE(one->x(), 1.0); + QCOMPARE(one->y(), 1.0); + QCOMPARE(two->x(), 1.0); + QCOMPARE(two->y(), 51.0); + QCOMPARE(three->x(), 1.0); + QCOMPARE(three->y(), 61.0); + + obj->setTopPadding(2.0); + + QCOMPARE(column->property("padding").toDouble(), 1.0); + QCOMPARE(column->property("topPadding").toDouble(), 2.0); + QCOMPARE(column->property("leftPadding").toDouble(), 1.0); + QCOMPARE(column->property("rightPadding").toDouble(), 1.0); + QCOMPARE(column->property("bottomPadding").toDouble(), 1.0); + + QTRY_COMPARE(column->height(), 83.0); + QCOMPARE(column->width(), 52.0); + + QCOMPARE(one->x(), 1.0); + QCOMPARE(one->y(), 2.0); + QCOMPARE(two->x(), 1.0); + QCOMPARE(two->y(), 52.0); + QCOMPARE(three->x(), 1.0); + QCOMPARE(three->y(), 62.0); + + obj->setLeftPadding(3.0); + + QCOMPARE(column->property("padding").toDouble(), 1.0); + QCOMPARE(column->property("topPadding").toDouble(), 2.0); + QCOMPARE(column->property("leftPadding").toDouble(), 3.0); + QCOMPARE(column->property("rightPadding").toDouble(), 1.0); + QCOMPARE(column->property("bottomPadding").toDouble(), 1.0); + + QTRY_COMPARE(column->width(), 54.0); + QCOMPARE(column->height(), 83.0); + + QCOMPARE(one->x(), 3.0); + QCOMPARE(one->y(), 2.0); + QCOMPARE(two->x(), 3.0); + QCOMPARE(two->y(), 52.0); + QCOMPARE(three->x(), 3.0); + QCOMPARE(three->y(), 62.0); + + obj->setRightPadding(4.0); + + QCOMPARE(column->property("padding").toDouble(), 1.0); + QCOMPARE(column->property("topPadding").toDouble(), 2.0); + QCOMPARE(column->property("leftPadding").toDouble(), 3.0); + QCOMPARE(column->property("rightPadding").toDouble(), 4.0); + QCOMPARE(column->property("bottomPadding").toDouble(), 1.0); + + QTRY_COMPARE(column->width(), 57.0); + QCOMPARE(column->height(), 83.0); + + QCOMPARE(one->x(), 3.0); + QCOMPARE(one->y(), 2.0); + QCOMPARE(two->x(), 3.0); + QCOMPARE(two->y(), 52.0); + QCOMPARE(three->x(), 3.0); + QCOMPARE(three->y(), 62.0); + + obj->setBottomPadding(5.0); + + QCOMPARE(column->property("padding").toDouble(), 1.0); + QCOMPARE(column->property("topPadding").toDouble(), 2.0); + QCOMPARE(column->property("leftPadding").toDouble(), 3.0); + QCOMPARE(column->property("rightPadding").toDouble(), 4.0); + QCOMPARE(column->property("bottomPadding").toDouble(), 5.0); + + QTRY_COMPARE(column->height(), 87.0); + QCOMPARE(column->width(), 57.0); + + QCOMPARE(one->x(), 3.0); + QCOMPARE(one->y(), 2.0); + QCOMPARE(two->x(), 3.0); + QCOMPARE(two->y(), 52.0); + QCOMPARE(three->x(), 3.0); + QCOMPARE(three->y(), 62.0); + + obj->resetBottomPadding(); + QCOMPARE(column->property("bottomPadding").toDouble(), 1.0); + QTRY_COMPARE(column->height(), 83.0); + QCOMPARE(column->width(), 57.0); + + obj->resetRightPadding(); + QCOMPARE(column->property("rightPadding").toDouble(), 1.0); + QTRY_COMPARE(column->width(), 54.0); + QCOMPARE(column->height(), 83.0); + + obj->resetLeftPadding(); + QCOMPARE(column->property("leftPadding").toDouble(), 1.0); + QTRY_COMPARE(column->width(), 52.0); + QCOMPARE(column->height(), 83.0); + + obj->resetTopPadding(); + QCOMPARE(column->property("topPadding").toDouble(), 1.0); + QTRY_COMPARE(column->height(), 82.0); + QCOMPARE(column->width(), 52.0); + + obj->resetPadding(); + QCOMPARE(column->property("padding").toDouble(), 0.0); + QCOMPARE(column->property("topPadding").toDouble(), 0.0); + QCOMPARE(column->property("leftPadding").toDouble(), 0.0); + QCOMPARE(column->property("rightPadding").toDouble(), 0.0); + QCOMPARE(column->property("bottomPadding").toDouble(), 0.0); + QTRY_COMPARE(column->height(), 80.0); + QCOMPARE(column->width(), 50.0); + + QCOMPARE(one->x(), 0.0); + QCOMPARE(one->y(), 0.0); + QCOMPARE(two->x(), 0.0); + QCOMPARE(two->y(), 50.0); + QCOMPARE(three->x(), 0.0); + QCOMPARE(three->y(), 60.0); } void tst_qquickpositioners::test_vertical_spacing() @@ -968,6 +1631,22 @@ void tst_qquickpositioners::test_vertical_spacing() QCOMPARE(column->height(), 100.0); QCOMPARE(column->width(), 50.0); + // test padding + column->setProperty("padding", 1); + column->setProperty("topPadding", 2); + column->setProperty("leftPadding", 3); + column->setProperty("rightPadding", 4); + column->setProperty("bottomPadding", 5); + + QTRY_COMPARE(column->height(), 107.0); + QCOMPARE(column->width(), 57.0); + + QCOMPARE(one->x(), 3.0); + QCOMPARE(one->y(), 2.0); + QCOMPARE(two->x(), 3.0); + QCOMPARE(two->y(), 62.0); + QCOMPARE(three->x(), 3.0); + QCOMPARE(three->y(), 82.0); } void tst_qquickpositioners::test_vertical_animated() @@ -1019,6 +1698,66 @@ void tst_qquickpositioners::test_vertical_animated() } +void tst_qquickpositioners::test_vertical_animated_padding() +{ + QScopedPointer<QQuickView> window(createView(testFile("vertical-animated.qml"), false)); + + //Note that they animate in + QQuickRectangle *one = window->rootObject()->findChild<QQuickRectangle*>("one"); + QVERIFY(one != 0); + QCOMPARE(one->y(), -100.0); + + QQuickRectangle *two = window->rootObject()->findChild<QQuickRectangle*>("two"); + QVERIFY(two != 0); + QCOMPARE(two->y(), -100.0); + + QQuickRectangle *three = window->rootObject()->findChild<QQuickRectangle*>("three"); + QVERIFY(three != 0); + QCOMPARE(three->y(), -100.0); + + QVERIFY(QTest::qWaitForWindowExposed(window.data())); //It may not relayout until the next frame, so it needs to be drawn + + QQuickItem *column = window->rootObject()->findChild<QQuickItem*>("column"); + QVERIFY(column); + QCOMPARE(column->height(), 100.0); + QCOMPARE(column->width(), 50.0); + + // test padding + column->setProperty("padding", 1); + column->setProperty("topPadding", 2); + column->setProperty("leftPadding", 3); + column->setProperty("rightPadding", 4); + column->setProperty("bottomPadding", 5); + + QTRY_COMPARE(column->height(), 107.0); + QCOMPARE(column->width(), 57.0); + + //QTRY_COMPARE used instead of waiting for the expected time of animation completion + //Note that this means the duration of the animation is NOT tested + + QTRY_COMPARE(one->y(), 2.0); + QTRY_COMPARE(one->x(), 3.0); + QTRY_COMPARE(two->isVisible(), false); + QTRY_COMPARE(two->y(), -100.0);//Not 'in' yet + QTRY_COMPARE(two->x(), 0.0); + QTRY_COMPARE(three->y(), 52.0); + QTRY_COMPARE(three->x(), 3.0); + + //Add 'two' + two->setVisible(true); + QTRY_COMPARE(two->isVisible(), true); + QTRY_COMPARE(column->height(), 157.0); + QTRY_COMPARE(column->width(), 57.0); + QTest::qWait(0);//Let the animation start + QVERIFY(two->y() >= -100.0 && two->y() < 52.0); + QVERIFY(three->y() >= 52.0 && three->y() < 102.0); + + QTRY_COMPARE(two->x(), 3.0); + QTRY_COMPARE(two->y(), 52.0); + QTRY_COMPARE(three->y(), 102.0); + +} + void tst_qquickpositioners::test_grid() { QScopedPointer<QQuickView> window(createView(testFile("gridtest.qml"))); @@ -1050,6 +1789,214 @@ void tst_qquickpositioners::test_grid() QCOMPARE(grid->width(), 100.0); QCOMPARE(grid->height(), 100.0); + // test padding + grid->setProperty("padding", 1); + grid->setProperty("topPadding", 2); + grid->setProperty("leftPadding", 3); + grid->setProperty("rightPadding", 4); + grid->setProperty("bottomPadding", 5); + + QTRY_COMPARE(grid->width(), 107.0); + QCOMPARE(grid->height(), 107.0); + + QCOMPARE(one->x(), 3.0); + QCOMPARE(one->y(), 2.0); + QCOMPARE(two->x(), 53.0); + QCOMPARE(two->y(), 2.0); + QCOMPARE(three->x(), 73.0); + QCOMPARE(three->y(), 2.0); + QCOMPARE(four->x(), 3.0); + QCOMPARE(four->y(), 52.0); + QCOMPARE(five->x(), 53.0); + QCOMPARE(five->y(), 52.0); +} + +void tst_qquickpositioners::test_grid_padding() +{ + QScopedPointer<QQuickView> window(createView(testFile("gridtest.qml"))); + + QQuickRectangle *one = window->rootObject()->findChild<QQuickRectangle*>("one"); + QVERIFY(one != 0); + QQuickRectangle *two = window->rootObject()->findChild<QQuickRectangle*>("two"); + QVERIFY(two != 0); + QQuickRectangle *three = window->rootObject()->findChild<QQuickRectangle*>("three"); + QVERIFY(three != 0); + QQuickRectangle *four = window->rootObject()->findChild<QQuickRectangle*>("four"); + QVERIFY(four != 0); + QQuickRectangle *five = window->rootObject()->findChild<QQuickRectangle*>("five"); + QVERIFY(five != 0); + + QCOMPARE(one->x(), 0.0); + QCOMPARE(one->y(), 0.0); + QCOMPARE(two->x(), 50.0); + QCOMPARE(two->y(), 0.0); + QCOMPARE(three->x(), 70.0); + QCOMPARE(three->y(), 0.0); + QCOMPARE(four->x(), 0.0); + QCOMPARE(four->y(), 50.0); + QCOMPARE(five->x(), 50.0); + QCOMPARE(five->y(), 50.0); + + QQuickGrid *grid = window->rootObject()->findChild<QQuickGrid*>("grid"); + QCOMPARE(grid->flow(), QQuickGrid::LeftToRight); + QCOMPARE(grid->width(), 100.0); + QCOMPARE(grid->height(), 100.0); + + QCOMPARE(grid->property("padding").toDouble(), 0.0); + QCOMPARE(grid->property("topPadding").toDouble(), 0.0); + QCOMPARE(grid->property("leftPadding").toDouble(), 0.0); + QCOMPARE(grid->property("rightPadding").toDouble(), 0.0); + QCOMPARE(grid->property("bottomPadding").toDouble(), 0.0); + + grid->setPadding(1.0); + + QCOMPARE(grid->property("padding").toDouble(), 1.0); + QCOMPARE(grid->property("topPadding").toDouble(), 1.0); + QCOMPARE(grid->property("leftPadding").toDouble(), 1.0); + QCOMPARE(grid->property("rightPadding").toDouble(), 1.0); + QCOMPARE(grid->property("bottomPadding").toDouble(), 1.0); + + QTRY_COMPARE(grid->width(), 102.0); + QCOMPARE(grid->height(), 102.0); + + QCOMPARE(one->x(), 1.0); + QCOMPARE(one->y(), 1.0); + QCOMPARE(two->x(), 51.0); + QCOMPARE(two->y(), 1.0); + QCOMPARE(three->x(), 71.0); + QCOMPARE(three->y(), 1.0); + QCOMPARE(four->x(), 1.0); + QCOMPARE(four->y(), 51.0); + QCOMPARE(five->x(), 51.0); + QCOMPARE(five->y(), 51.0); + + grid->setTopPadding(2.0); + + QCOMPARE(grid->property("padding").toDouble(), 1.0); + QCOMPARE(grid->property("topPadding").toDouble(), 2.0); + QCOMPARE(grid->property("leftPadding").toDouble(), 1.0); + QCOMPARE(grid->property("rightPadding").toDouble(), 1.0); + QCOMPARE(grid->property("bottomPadding").toDouble(), 1.0); + + QTRY_COMPARE(grid->height(), 103.0); + QCOMPARE(grid->width(), 102.0); + + QCOMPARE(one->x(), 1.0); + QCOMPARE(one->y(), 2.0); + QCOMPARE(two->x(), 51.0); + QCOMPARE(two->y(), 2.0); + QCOMPARE(three->x(), 71.0); + QCOMPARE(three->y(), 2.0); + QCOMPARE(four->x(), 1.0); + QCOMPARE(four->y(), 52.0); + QCOMPARE(five->x(), 51.0); + QCOMPARE(five->y(), 52.0); + + grid->setLeftPadding(3.0); + + QCOMPARE(grid->property("padding").toDouble(), 1.0); + QCOMPARE(grid->property("topPadding").toDouble(), 2.0); + QCOMPARE(grid->property("leftPadding").toDouble(), 3.0); + QCOMPARE(grid->property("rightPadding").toDouble(), 1.0); + QCOMPARE(grid->property("bottomPadding").toDouble(), 1.0); + + QTRY_COMPARE(grid->width(), 104.0); + QCOMPARE(grid->height(), 103.0); + + QCOMPARE(one->x(), 3.0); + QCOMPARE(one->y(), 2.0); + QCOMPARE(two->x(), 53.0); + QCOMPARE(two->y(), 2.0); + QCOMPARE(three->x(), 73.0); + QCOMPARE(three->y(), 2.0); + QCOMPARE(four->x(), 3.0); + QCOMPARE(four->y(), 52.0); + QCOMPARE(five->x(), 53.0); + QCOMPARE(five->y(), 52.0); + + grid->setRightPadding(4.0); + + QCOMPARE(grid->property("padding").toDouble(), 1.0); + QCOMPARE(grid->property("topPadding").toDouble(), 2.0); + QCOMPARE(grid->property("leftPadding").toDouble(), 3.0); + QCOMPARE(grid->property("rightPadding").toDouble(), 4.0); + QCOMPARE(grid->property("bottomPadding").toDouble(), 1.0); + + QTRY_COMPARE(grid->width(), 107.0); + QCOMPARE(grid->height(), 103.0); + + QCOMPARE(one->x(), 3.0); + QCOMPARE(one->y(), 2.0); + QCOMPARE(two->x(), 53.0); + QCOMPARE(two->y(), 2.0); + QCOMPARE(three->x(), 73.0); + QCOMPARE(three->y(), 2.0); + QCOMPARE(four->x(), 3.0); + QCOMPARE(four->y(), 52.0); + QCOMPARE(five->x(), 53.0); + QCOMPARE(five->y(), 52.0); + + grid->setBottomPadding(5.0); + + QCOMPARE(grid->property("padding").toDouble(), 1.0); + QCOMPARE(grid->property("topPadding").toDouble(), 2.0); + QCOMPARE(grid->property("leftPadding").toDouble(), 3.0); + QCOMPARE(grid->property("rightPadding").toDouble(), 4.0); + QCOMPARE(grid->property("bottomPadding").toDouble(), 5.0); + + QTRY_COMPARE(grid->height(), 107.0); + QCOMPARE(grid->width(), 107.0); + + QCOMPARE(one->x(), 3.0); + QCOMPARE(one->y(), 2.0); + QCOMPARE(two->x(), 53.0); + QCOMPARE(two->y(), 2.0); + QCOMPARE(three->x(), 73.0); + QCOMPARE(three->y(), 2.0); + QCOMPARE(four->x(), 3.0); + QCOMPARE(four->y(), 52.0); + QCOMPARE(five->x(), 53.0); + QCOMPARE(five->y(), 52.0); + + grid->resetBottomPadding(); + QCOMPARE(grid->property("bottomPadding").toDouble(), 1.0); + QTRY_COMPARE(grid->height(), 103.0); + QCOMPARE(grid->width(), 107.0); + + grid->resetRightPadding(); + QCOMPARE(grid->property("rightPadding").toDouble(), 1.0); + QTRY_COMPARE(grid->width(), 104.0); + QCOMPARE(grid->height(), 103.0); + + grid->resetLeftPadding(); + QCOMPARE(grid->property("leftPadding").toDouble(), 1.0); + QTRY_COMPARE(grid->width(), 102.0); + QCOMPARE(grid->height(), 103.0); + + grid->resetTopPadding(); + QCOMPARE(grid->property("topPadding").toDouble(), 1.0); + QTRY_COMPARE(grid->height(), 102.0); + QCOMPARE(grid->width(), 102.0); + + grid->resetPadding(); + QCOMPARE(grid->property("padding").toDouble(), 0.0); + QCOMPARE(grid->property("topPadding").toDouble(), 0.0); + QCOMPARE(grid->property("leftPadding").toDouble(), 0.0); + QCOMPARE(grid->property("rightPadding").toDouble(), 0.0); + QCOMPARE(grid->property("bottomPadding").toDouble(), 0.0); + QTRY_COMPARE(grid->height(), 100.0); + QCOMPARE(grid->width(), 100.0); + + QCOMPARE(one->x(), 0.0); + QCOMPARE(one->y(), 0.0); + QCOMPARE(two->x(), 50.0); + QCOMPARE(two->y(), 0.0); + QCOMPARE(three->x(), 70.0); + QCOMPARE(three->y(), 0.0); + QCOMPARE(four->x(), 0.0); + QCOMPARE(four->y(), 50.0); + QCOMPARE(five->x(), 50.0); + QCOMPARE(five->y(), 50.0); } void tst_qquickpositioners::test_grid_topToBottom() @@ -1083,6 +2030,26 @@ void tst_qquickpositioners::test_grid_topToBottom() QCOMPARE(grid->width(), 100.0); QCOMPARE(grid->height(), 120.0); + // test padding + grid->setProperty("padding", 1); + grid->setProperty("topPadding", 2); + grid->setProperty("leftPadding", 3); + grid->setProperty("rightPadding", 4); + grid->setProperty("bottomPadding", 5); + + QTRY_COMPARE(grid->width(), 107.0); + QCOMPARE(grid->height(), 127.0); + + QCOMPARE(one->x(), 3.0); + QCOMPARE(one->y(), 2.0); + QCOMPARE(two->x(), 3.0); + QCOMPARE(two->y(), 52.0); + QCOMPARE(three->x(), 3.0); + QCOMPARE(three->y(), 102.0); + QCOMPARE(four->x(), 53.0); + QCOMPARE(four->y(), 2.0); + QCOMPARE(five->x(), 53.0); + QCOMPARE(five->y(), 52.0); } void tst_qquickpositioners::test_grid_rightToLeft() @@ -1118,6 +2085,44 @@ void tst_qquickpositioners::test_grid_rightToLeft() QCOMPARE(grid->width(), 100.0); QCOMPARE(grid->height(), 100.0); + // test padding + grid->setProperty("padding", 1); + grid->setProperty("topPadding", 2); + grid->setProperty("leftPadding", 3); + grid->setProperty("rightPadding", 4); + grid->setProperty("bottomPadding", 5); + + QTRY_COMPARE(grid->width(), 107.0); + QCOMPARE(grid->height(), 107.0); + + QCOMPARE(one->x(), 53.0); + QCOMPARE(one->y(), 2.0); + QCOMPARE(two->x(), 33.0); + QCOMPARE(two->y(), 2.0); + QCOMPARE(three->x(), 3.0); + QCOMPARE(three->y(), 2.0); + QCOMPARE(four->x(), 53.0); + QCOMPARE(four->y(), 52.0); + QCOMPARE(five->x(), 43.0); + QCOMPARE(five->y(), 52.0); + + grid->setProperty("topPadding", 0); + grid->setProperty("leftPadding", 0); + grid->setProperty("rightPadding", 0); + grid->setProperty("bottomPadding", 0); + grid->setProperty("padding", 0); + + QTRY_COMPARE(one->x(), 50.0); + QCOMPARE(one->y(), 0.0); + QCOMPARE(two->x(), 30.0); + QCOMPARE(two->y(), 0.0); + QCOMPARE(three->x(), 0.0); + QCOMPARE(three->y(), 0.0); + QCOMPARE(four->x(), 50.0); + QCOMPARE(four->y(), 50.0); + QCOMPARE(five->x(), 40.0); + QCOMPARE(five->y(), 50.0); + // Change the width of the grid and check that items stay to the right grid->setWidth(200); QTRY_COMPARE(one->x(), 150.0); @@ -1131,6 +2136,22 @@ void tst_qquickpositioners::test_grid_rightToLeft() QCOMPARE(five->x(), 140.0); QCOMPARE(five->y(), 50.0); + grid->setProperty("padding", 1); + grid->setProperty("topPadding", 2); + grid->setProperty("leftPadding", 3); + grid->setProperty("rightPadding", 4); + grid->setProperty("bottomPadding", 5); + + QTRY_COMPARE(one->x(), 146.0); + QCOMPARE(one->y(), 2.0); + QCOMPARE(two->x(), 126.0); + QCOMPARE(two->y(), 2.0); + QCOMPARE(three->x(), 96.0); + QCOMPARE(three->y(), 2.0); + QCOMPARE(four->x(), 146.0); + QCOMPARE(four->y(), 52.0); + QCOMPARE(five->x(), 136.0); + QCOMPARE(five->y(), 52.0); } void tst_qquickpositioners::test_grid_spacing() @@ -1163,6 +2184,26 @@ void tst_qquickpositioners::test_grid_spacing() QCOMPARE(grid->width(), 128.0); QCOMPARE(grid->height(), 104.0); + // test padding + grid->setProperty("padding", 1); + grid->setProperty("topPadding", 2); + grid->setProperty("leftPadding", 3); + grid->setProperty("rightPadding", 4); + grid->setProperty("bottomPadding", 5); + + QTRY_COMPARE(grid->width(), 135.0); + QCOMPARE(grid->height(), 111.0); + + QCOMPARE(one->x(), 3.0); + QCOMPARE(one->y(), 2.0); + QCOMPARE(two->x(), 57.0); + QCOMPARE(two->y(), 2.0); + QCOMPARE(three->x(), 81.0); + QCOMPARE(three->y(), 2.0); + QCOMPARE(four->x(), 3.0); + QCOMPARE(four->y(), 56.0); + QCOMPARE(five->x(), 57.0); + QCOMPARE(five->y(), 56.0); } void tst_qquickpositioners::test_grid_row_column_spacing() @@ -1195,6 +2236,26 @@ void tst_qquickpositioners::test_grid_row_column_spacing() QCOMPARE(grid->width(), 142.0); QCOMPARE(grid->height(), 107.0); + // test padding + grid->setProperty("padding", 1); + grid->setProperty("topPadding", 2); + grid->setProperty("leftPadding", 3); + grid->setProperty("rightPadding", 4); + grid->setProperty("bottomPadding", 5); + + QTRY_COMPARE(grid->width(), 149.0); + QCOMPARE(grid->height(), 114.0); + + QCOMPARE(one->x(), 3.0); + QCOMPARE(one->y(), 2.0); + QCOMPARE(two->x(), 64.0); + QCOMPARE(two->y(), 2.0); + QCOMPARE(three->x(), 95.0); + QCOMPARE(three->y(), 2.0); + QCOMPARE(four->x(), 3.0); + QCOMPARE(four->y(), 59.0); + QCOMPARE(five->x(), 64.0); + QCOMPARE(five->y(), 59.0); } void tst_qquickpositioners::test_grid_animated() @@ -1281,6 +2342,100 @@ void tst_qquickpositioners::test_grid_animated() } +void tst_qquickpositioners::test_grid_animated_padding() +{ + QScopedPointer<QQuickView> window(createView(testFile("grid-animated.qml"), false)); + + window->rootObject()->setProperty("testRightToLeft", false); + + //Note that all animate in + QQuickRectangle *one = window->rootObject()->findChild<QQuickRectangle*>("one"); + QVERIFY(one != 0); + QCOMPARE(one->x(), -100.0); + QCOMPARE(one->y(), -100.0); + + QQuickRectangle *two = window->rootObject()->findChild<QQuickRectangle*>("two"); + QVERIFY(two != 0); + QCOMPARE(two->x(), -100.0); + QCOMPARE(two->y(), -100.0); + + QQuickRectangle *three = window->rootObject()->findChild<QQuickRectangle*>("three"); + QVERIFY(three != 0); + QCOMPARE(three->x(), -100.0); + QCOMPARE(three->y(), -100.0); + + QQuickRectangle *four = window->rootObject()->findChild<QQuickRectangle*>("four"); + QVERIFY(four != 0); + QCOMPARE(four->x(), -100.0); + QCOMPARE(four->y(), -100.0); + + QQuickRectangle *five = window->rootObject()->findChild<QQuickRectangle*>("five"); + QVERIFY(five != 0); + QCOMPARE(five->x(), -100.0); + QCOMPARE(five->y(), -100.0); + + QVERIFY(QTest::qWaitForWindowExposed(window.data())); //It may not relayout until the next frame, so it needs to be drawn + + QQuickItem *grid = window->rootObject()->findChild<QQuickItem*>("grid"); + QVERIFY(grid); + QCOMPARE(grid->width(), 150.0); + QCOMPARE(grid->height(), 100.0); + + // test padding + grid->setProperty("padding", 1); + grid->setProperty("topPadding", 2); + grid->setProperty("leftPadding", 3); + grid->setProperty("rightPadding", 4); + grid->setProperty("bottomPadding", 5); + + QTRY_COMPARE(grid->width(), 157.0); + QCOMPARE(grid->height(), 107.0); + + //QTRY_COMPARE used instead of waiting for the expected time of animation completion + //Note that this means the duration of the animation is NOT tested + + QTRY_COMPARE(one->y(), 2.0); + QTRY_COMPARE(one->x(), 3.0); + QTRY_COMPARE(two->isVisible(), false); + QTRY_COMPARE(two->y(), -100.0); + QTRY_COMPARE(two->x(), -100.0); + QTRY_COMPARE(three->y(), 2.0); + QTRY_COMPARE(three->x(), 53.0); + QTRY_COMPARE(four->y(), 2.0); + QTRY_COMPARE(four->x(), 103.0); + QTRY_COMPARE(five->y(), 52.0); + QTRY_COMPARE(five->x(), 3.0); + + //Add 'two' + two->setVisible(true); + QCOMPARE(two->isVisible(), true); + QCOMPARE(grid->width(), 157.0); + QCOMPARE(grid->height(), 107.0); + QTest::qWait(0);//Let the animation start + QCOMPARE(two->x(), -100.0); + QCOMPARE(two->y(), -100.0); + QCOMPARE(one->x(), 3.0); + QCOMPARE(one->y(), 2.0); + QCOMPARE(three->x(), 53.0); + QCOMPARE(three->y(), 2.0); + QCOMPARE(four->x(), 103.0); + QCOMPARE(four->y(), 2.0); + QCOMPARE(five->x(), 3.0); + QCOMPARE(five->y(), 52.0); + //Let the animation complete + QTRY_COMPARE(two->x(), 53.0); + QTRY_COMPARE(two->y(), 2.0); + QTRY_COMPARE(one->x(), 3.0); + QTRY_COMPARE(one->y(), 2.0); + QTRY_COMPARE(three->x(), 103.0); + QTRY_COMPARE(three->y(), 2.0); + QTRY_COMPARE(four->x(), 3.0); + QTRY_COMPARE(four->y(), 52.0); + QTRY_COMPARE(five->x(), 53.0); + QTRY_COMPARE(five->y(), 52.0); + +} + void tst_qquickpositioners::test_grid_animated_rightToLeft() { QScopedPointer<QQuickView> window(createView(testFile("grid-animated.qml"), false)); @@ -1365,6 +2520,100 @@ void tst_qquickpositioners::test_grid_animated_rightToLeft() } +void tst_qquickpositioners::test_grid_animated_rightToLeft_padding() +{ + QScopedPointer<QQuickView> window(createView(testFile("grid-animated.qml"), false)); + + window->rootObject()->setProperty("testRightToLeft", true); + + //Note that all animate in + QQuickRectangle *one = window->rootObject()->findChild<QQuickRectangle*>("one"); + QVERIFY(one != 0); + QCOMPARE(one->x(), -100.0); + QCOMPARE(one->y(), -100.0); + + QQuickRectangle *two = window->rootObject()->findChild<QQuickRectangle*>("two"); + QVERIFY(two != 0); + QCOMPARE(two->x(), -100.0); + QCOMPARE(two->y(), -100.0); + + QQuickRectangle *three = window->rootObject()->findChild<QQuickRectangle*>("three"); + QVERIFY(three != 0); + QCOMPARE(three->x(), -100.0); + QCOMPARE(three->y(), -100.0); + + QQuickRectangle *four = window->rootObject()->findChild<QQuickRectangle*>("four"); + QVERIFY(four != 0); + QCOMPARE(four->x(), -100.0); + QCOMPARE(four->y(), -100.0); + + QQuickRectangle *five = window->rootObject()->findChild<QQuickRectangle*>("five"); + QVERIFY(five != 0); + QCOMPARE(five->x(), -100.0); + QCOMPARE(five->y(), -100.0); + + QVERIFY(QTest::qWaitForWindowExposed(window.data())); //It may not relayout until the next frame, so it needs to be drawn + + QQuickItem *grid = window->rootObject()->findChild<QQuickItem*>("grid"); + QVERIFY(grid); + QCOMPARE(grid->width(), 150.0); + QCOMPARE(grid->height(), 100.0); + + // test padding + grid->setProperty("padding", 1); + grid->setProperty("topPadding", 2); + grid->setProperty("leftPadding", 3); + grid->setProperty("rightPadding", 4); + grid->setProperty("bottomPadding", 5); + + QTRY_COMPARE(grid->width(), 157.0); + QCOMPARE(grid->height(), 107.0); + + //QTRY_COMPARE used instead of waiting for the expected time of animation completion + //Note that this means the duration of the animation is NOT tested + + QTRY_COMPARE(one->y(), 2.0); + QTRY_COMPARE(one->x(), 103.0); + QTRY_COMPARE(two->isVisible(), false); + QTRY_COMPARE(two->y(), -100.0); + QTRY_COMPARE(two->x(), -100.0); + QTRY_COMPARE(three->y(), 2.0); + QTRY_COMPARE(three->x(), 53.0); + QTRY_COMPARE(four->y(), 2.0); + QTRY_COMPARE(four->x(), 3.0); + QTRY_COMPARE(five->y(), 52.0); + QTRY_COMPARE(five->x(), 103.0); + + //Add 'two' + two->setVisible(true); + QCOMPARE(two->isVisible(), true); + QCOMPARE(grid->width(), 157.0); + QCOMPARE(grid->height(), 107.0); + QTest::qWait(0);//Let the animation start + QCOMPARE(two->x(), -100.0); + QCOMPARE(two->y(), -100.0); + QCOMPARE(one->x(), 103.0); + QCOMPARE(one->y(), 2.0); + QCOMPARE(three->x(), 53.0); + QCOMPARE(three->y(), 2.0); + QCOMPARE(four->x(), 3.0); + QCOMPARE(four->y(), 2.0); + QCOMPARE(five->x(), 103.0); + QCOMPARE(five->y(), 52.0); + //Let the animation complete + QTRY_COMPARE(two->x(), 53.0); + QTRY_COMPARE(two->y(), 2.0); + QTRY_COMPARE(one->x(), 103.0); + QTRY_COMPARE(one->y(), 2.0); + QTRY_COMPARE(three->x(), 3.0); + QTRY_COMPARE(three->y(), 2.0); + QTRY_COMPARE(four->x(), 103.0); + QTRY_COMPARE(four->y(), 52.0); + QTRY_COMPARE(five->x(), 53.0); + QTRY_COMPARE(five->y(), 52.0); + +} + void tst_qquickpositioners::test_grid_zero_columns() { QScopedPointer<QQuickView> window(createView(testFile("gridzerocolumns.qml"))); @@ -1395,6 +2644,26 @@ void tst_qquickpositioners::test_grid_zero_columns() QCOMPARE(grid->width(), 170.0); QCOMPARE(grid->height(), 60.0); + // test padding + grid->setProperty("padding", 1); + grid->setProperty("topPadding", 2); + grid->setProperty("leftPadding", 3); + grid->setProperty("rightPadding", 4); + grid->setProperty("bottomPadding", 5); + + QTRY_COMPARE(grid->width(), 177.0); + QCOMPARE(grid->height(), 67.0); + + QCOMPARE(one->x(), 3.0); + QCOMPARE(one->y(), 2.0); + QCOMPARE(two->x(), 53.0); + QCOMPARE(two->y(), 2.0); + QCOMPARE(three->x(), 73.0); + QCOMPARE(three->y(), 2.0); + QCOMPARE(four->x(), 123.0); + QCOMPARE(four->y(), 2.0); + QCOMPARE(five->x(), 3.0); + QCOMPARE(five->y(), 52.0); } void tst_qquickpositioners::test_grid_H_alignment() @@ -1476,6 +2745,95 @@ void tst_qquickpositioners::test_grid_H_alignment() } +void tst_qquickpositioners::test_grid_H_alignment_padding() +{ + QScopedPointer<QQuickView> window(createView(testFile("gridtest.qml"))); + + window->rootObject()->setProperty("testHAlignment", QQuickGrid::AlignHCenter); + + QQuickRectangle *one = window->rootObject()->findChild<QQuickRectangle*>("one"); + QVERIFY(one != 0); + QQuickRectangle *two = window->rootObject()->findChild<QQuickRectangle*>("two"); + QVERIFY(two != 0); + QQuickRectangle *three = window->rootObject()->findChild<QQuickRectangle*>("three"); + QVERIFY(three != 0); + QQuickRectangle *four = window->rootObject()->findChild<QQuickRectangle*>("four"); + QVERIFY(four != 0); + QQuickRectangle *five = window->rootObject()->findChild<QQuickRectangle*>("five"); + QVERIFY(five != 0); + + QCOMPARE(one->x(), 0.0); + QCOMPARE(one->y(), 0.0); + QCOMPARE(two->x(), 50.0); + QCOMPARE(two->y(), 0.0); + QCOMPARE(three->x(), 70.0); + QCOMPARE(three->y(), 0.0); + QCOMPARE(four->x(), 0.0); + QCOMPARE(four->y(), 50.0); + QCOMPARE(five->x(), 55.0); + QCOMPARE(five->y(), 50.0); + + QQuickItem *grid = window->rootObject()->findChild<QQuickItem*>("grid"); + QCOMPARE(grid->width(), 100.0); + QCOMPARE(grid->height(), 100.0); + + // test padding + grid->setProperty("padding", 1); + grid->setProperty("topPadding", 2); + grid->setProperty("leftPadding", 3); + grid->setProperty("rightPadding", 4); + grid->setProperty("bottomPadding", 5); + + QTRY_COMPARE(grid->width(), 107.0); + QCOMPARE(grid->height(), 107.0); + + window->rootObject()->setProperty("testHAlignment", QQuickGrid::AlignRight); + + QCOMPARE(one->x(), 3.0); + QCOMPARE(one->y(), 2.0); + QCOMPARE(two->x(), 53.0); + QCOMPARE(two->y(), 2.0); + QCOMPARE(three->x(), 73.0); + QCOMPARE(three->y(), 2.0); + QCOMPARE(four->x(), 3.0); + QCOMPARE(four->y(), 52.0); + QCOMPARE(five->x(), 63.0); + QCOMPARE(five->y(), 52.0); + QCOMPARE(grid->width(), 107.0); + QCOMPARE(grid->height(), 107.0); + + window->rootObject()->setProperty("testRightToLeft", true); + + QCOMPARE(one->x(), 53.0); + QCOMPARE(one->y(), 2.0); + QCOMPARE(two->x(), 33.0); + QCOMPARE(two->y(), 2.0); + QCOMPARE(three->x(), 3.0); + QCOMPARE(three->y(), 2.0); + QCOMPARE(four->x(), 53.0); + QCOMPARE(four->y(), 52.0); + QCOMPARE(five->x(), 33.0); + QCOMPARE(five->y(), 52.0); + QCOMPARE(grid->width(), 107.0); + QCOMPARE(grid->height(), 107.0); + + window->rootObject()->setProperty("testHAlignment", QQuickGrid::AlignHCenter); + + QCOMPARE(one->x(), 53.0); + QCOMPARE(one->y(), 2.0); + QCOMPARE(two->x(), 33.0); + QCOMPARE(two->y(), 2.0); + QCOMPARE(three->x(), 3.0); + QCOMPARE(three->y(), 2.0); + QCOMPARE(four->x(), 53.0); + QCOMPARE(four->y(), 52.0); + QCOMPARE(five->x(), 38.0); + QCOMPARE(five->y(), 52.0); + QCOMPARE(grid->width(), 107.0); + QCOMPARE(grid->height(), 107.0); + +} + void tst_qquickpositioners::test_grid_V_alignment() { QScopedPointer<QQuickView> window(createView(testFile("gridtest.qml"))); @@ -1519,6 +2877,63 @@ void tst_qquickpositioners::test_grid_V_alignment() } +void tst_qquickpositioners::test_grid_V_alignment_padding() +{ + QScopedPointer<QQuickView> window(createView(testFile("gridtest.qml"))); + + window->rootObject()->setProperty("testVAlignment", QQuickGrid::AlignVCenter); + + QQuickRectangle *one = window->rootObject()->findChild<QQuickRectangle*>("one"); + QVERIFY(one != 0); + QQuickRectangle *two = window->rootObject()->findChild<QQuickRectangle*>("two"); + QVERIFY(two != 0); + QQuickRectangle *three = window->rootObject()->findChild<QQuickRectangle*>("three"); + QVERIFY(three != 0); + QQuickRectangle *four = window->rootObject()->findChild<QQuickRectangle*>("four"); + QVERIFY(four != 0); + QQuickRectangle *five = window->rootObject()->findChild<QQuickRectangle*>("five"); + QVERIFY(five != 0); + + QQuickItem *grid = window->rootObject()->findChild<QQuickItem*>("grid"); + QCOMPARE(grid->width(), 100.0); + QCOMPARE(grid->height(), 100.0); + + // test padding + grid->setProperty("padding", 1); + grid->setProperty("topPadding", 2); + grid->setProperty("leftPadding", 3); + grid->setProperty("rightPadding", 4); + grid->setProperty("bottomPadding", 5); + + QTRY_COMPARE(grid->width(), 107.0); + QCOMPARE(grid->height(), 107.0); + + QCOMPARE(one->x(), 3.0); + QCOMPARE(one->y(), 2.0); + QCOMPARE(two->x(), 53.0); + QCOMPARE(two->y(), 2.0); + QCOMPARE(three->x(), 73.0); + QCOMPARE(three->y(), 17.0); + QCOMPARE(four->x(), 3.0); + QCOMPARE(four->y(), 52.0); + QCOMPARE(five->x(), 53.0); + QCOMPARE(five->y(), 72.0); + + window->rootObject()->setProperty("testVAlignment", QQuickGrid::AlignBottom); + + QCOMPARE(one->x(), 3.0); + QCOMPARE(one->y(), 2.0); + QCOMPARE(two->x(), 53.0); + QCOMPARE(two->y(), 2.0); + QCOMPARE(three->x(), 73.0); + QCOMPARE(three->y(), 32.0); + QCOMPARE(four->x(), 3.0); + QCOMPARE(four->y(), 52.0); + QCOMPARE(five->x(), 53.0); + QCOMPARE(five->y(), 92.0); + +} + void tst_qquickpositioners::test_propertychanges() { QScopedPointer<QQuickView> window(createView(testFile("propertychangestest.qml"))); @@ -1599,6 +3014,28 @@ void tst_qquickpositioners::test_repeater() } +void tst_qquickpositioners::test_repeater_padding() +{ + QScopedPointer<QQuickView> window(createView(testFile("repeatertest-padding.qml"))); + + QQuickRectangle *one = findItem<QQuickRectangle>(window->contentItem(), "one"); + QVERIFY(one != 0); + + QQuickRectangle *two = findItem<QQuickRectangle>(window->contentItem(), "two"); + QVERIFY(two != 0); + + QQuickRectangle *three = findItem<QQuickRectangle>(window->contentItem(), "three"); + QVERIFY(three != 0); + + QCOMPARE(one->x(), 3.0); + QCOMPARE(one->y(), 2.0); + QCOMPARE(two->x(), 53.0); + QCOMPARE(two->y(), 2.0); + QCOMPARE(three->x(), 103.0); + QCOMPARE(three->y(), 2.0); + +} + void tst_qquickpositioners::test_flow() { QScopedPointer<QQuickView> window(createView(testFile("flowtest.qml"))); @@ -1632,6 +3069,219 @@ void tst_qquickpositioners::test_flow() QCOMPARE(flow->width(), 90.0); QCOMPARE(flow->height(), 120.0); + // test padding + flow->setProperty("padding", 1); + flow->setProperty("topPadding", 2); + flow->setProperty("leftPadding", 3); + flow->setProperty("rightPadding", 4); + flow->setProperty("bottomPadding", 5); + + QTRY_COMPARE(flow->height(), 127.0); + QCOMPARE(flow->width(), 90.0); + + QCOMPARE(one->x(), 3.0); + QCOMPARE(one->y(), 2.0); + QCOMPARE(two->x(), 53.0); + QCOMPARE(two->y(), 2.0); + QCOMPARE(three->x(), 3.0); + QCOMPARE(three->y(), 52.0); + QCOMPARE(four->x(), 3.0); + QCOMPARE(four->y(), 72.0); + QCOMPARE(five->x(), 53.0); + QCOMPARE(five->y(), 72.0); +} + +void tst_qquickpositioners::test_flow_padding() +{ + QScopedPointer<QQuickView> window(createView(testFile("flowtest.qml"))); + + window->rootObject()->setProperty("testRightToLeft", false); + + QQuickRectangle *one = window->rootObject()->findChild<QQuickRectangle*>("one"); + QVERIFY(one != 0); + QQuickRectangle *two = window->rootObject()->findChild<QQuickRectangle*>("two"); + QVERIFY(two != 0); + QQuickRectangle *three = window->rootObject()->findChild<QQuickRectangle*>("three"); + QVERIFY(three != 0); + QQuickRectangle *four = window->rootObject()->findChild<QQuickRectangle*>("four"); + QVERIFY(four != 0); + QQuickRectangle *five = window->rootObject()->findChild<QQuickRectangle*>("five"); + QVERIFY(five != 0); + + QCOMPARE(one->x(), 0.0); + QCOMPARE(one->y(), 0.0); + QCOMPARE(two->x(), 50.0); + QCOMPARE(two->y(), 0.0); + QCOMPARE(three->x(), 0.0); + QCOMPARE(three->y(), 50.0); + QCOMPARE(four->x(), 0.0); + QCOMPARE(four->y(), 70.0); + QCOMPARE(five->x(), 50.0); + QCOMPARE(five->y(), 70.0); + + QQuickItem *flow = window->rootObject()->findChild<QQuickItem*>("flow"); + QVERIFY(flow); + QCOMPARE(flow->width(), 90.0); + QCOMPARE(flow->height(), 120.0); + + QQuickFlow *obj = qobject_cast<QQuickFlow*>(flow); + QVERIFY(obj != 0); + + QCOMPARE(flow->property("padding").toDouble(), 0.0); + QCOMPARE(flow->property("topPadding").toDouble(), 0.0); + QCOMPARE(flow->property("leftPadding").toDouble(), 0.0); + QCOMPARE(flow->property("rightPadding").toDouble(), 0.0); + QCOMPARE(flow->property("bottomPadding").toDouble(), 0.0); + + obj->setPadding(1.0); + + QCOMPARE(flow->property("padding").toDouble(), 1.0); + QCOMPARE(flow->property("topPadding").toDouble(), 1.0); + QCOMPARE(flow->property("leftPadding").toDouble(), 1.0); + QCOMPARE(flow->property("rightPadding").toDouble(), 1.0); + QCOMPARE(flow->property("bottomPadding").toDouble(), 1.0); + + QTRY_COMPARE(flow->height(), 122.0); + QCOMPARE(flow->width(), 90.0); + + QCOMPARE(one->x(), 1.0); + QCOMPARE(one->y(), 1.0); + QCOMPARE(two->x(), 51.0); + QCOMPARE(two->y(), 1.0); + QCOMPARE(three->x(), 1.0); + QCOMPARE(three->y(), 51.0); + QCOMPARE(four->x(), 1.0); + QCOMPARE(four->y(), 71.0); + QCOMPARE(five->x(), 51.0); + QCOMPARE(five->y(), 71.0); + + obj->setTopPadding(2.0); + + QCOMPARE(flow->property("padding").toDouble(), 1.0); + QCOMPARE(flow->property("topPadding").toDouble(), 2.0); + QCOMPARE(flow->property("leftPadding").toDouble(), 1.0); + QCOMPARE(flow->property("rightPadding").toDouble(), 1.0); + QCOMPARE(flow->property("bottomPadding").toDouble(), 1.0); + + QTRY_COMPARE(flow->height(), 123.0); + QCOMPARE(flow->width(), 90.0); + + QCOMPARE(one->x(), 1.0); + QCOMPARE(one->y(), 2.0); + QCOMPARE(two->x(), 51.0); + QCOMPARE(two->y(), 2.0); + QCOMPARE(three->x(), 1.0); + QCOMPARE(three->y(), 52.0); + QCOMPARE(four->x(), 1.0); + QCOMPARE(four->y(), 72.0); + QCOMPARE(five->x(), 51.0); + QCOMPARE(five->y(), 72.0); + + obj->setLeftPadding(3.0); + + QCOMPARE(flow->property("padding").toDouble(), 1.0); + QCOMPARE(flow->property("topPadding").toDouble(), 2.0); + QCOMPARE(flow->property("leftPadding").toDouble(), 3.0); + QCOMPARE(flow->property("rightPadding").toDouble(), 1.0); + QCOMPARE(flow->property("bottomPadding").toDouble(), 1.0); + + QCOMPARE(flow->height(), 123.0); + QCOMPARE(flow->width(), 90.0); + + QTRY_COMPARE(one->x(), 3.0); + QCOMPARE(one->y(), 2.0); + QCOMPARE(two->x(), 53.0); + QCOMPARE(two->y(), 2.0); + QCOMPARE(three->x(), 3.0); + QCOMPARE(three->y(), 52.0); + QCOMPARE(four->x(), 3.0); + QCOMPARE(four->y(), 72.0); + QCOMPARE(five->x(), 53.0); + QCOMPARE(five->y(), 72.0); + + obj->setRightPadding(4.0); + + QCOMPARE(flow->property("padding").toDouble(), 1.0); + QCOMPARE(flow->property("topPadding").toDouble(), 2.0); + QCOMPARE(flow->property("leftPadding").toDouble(), 3.0); + QCOMPARE(flow->property("rightPadding").toDouble(), 4.0); + QCOMPARE(flow->property("bottomPadding").toDouble(), 1.0); + + QCOMPARE(flow->height(), 123.0); + QCOMPARE(flow->width(), 90.0); + + QTRY_COMPARE(one->x(), 3.0); + QCOMPARE(one->y(), 2.0); + QCOMPARE(two->x(), 53.0); + QCOMPARE(two->y(), 2.0); + QCOMPARE(three->x(), 3.0); + QCOMPARE(three->y(), 52.0); + QCOMPARE(four->x(), 3.0); + QCOMPARE(four->y(), 72.0); + QCOMPARE(five->x(), 53.0); + QCOMPARE(five->y(), 72.0); + + obj->setBottomPadding(5.0); + + QCOMPARE(flow->property("padding").toDouble(), 1.0); + QCOMPARE(flow->property("topPadding").toDouble(), 2.0); + QCOMPARE(flow->property("leftPadding").toDouble(), 3.0); + QCOMPARE(flow->property("rightPadding").toDouble(), 4.0); + QCOMPARE(flow->property("bottomPadding").toDouble(), 5.0); + + QTRY_COMPARE(flow->height(), 127.0); + QCOMPARE(flow->width(), 90.0); + + QCOMPARE(one->x(), 3.0); + QCOMPARE(one->y(), 2.0); + QCOMPARE(two->x(), 53.0); + QCOMPARE(two->y(), 2.0); + QCOMPARE(three->x(), 3.0); + QCOMPARE(three->y(), 52.0); + QCOMPARE(four->x(), 3.0); + QCOMPARE(four->y(), 72.0); + QCOMPARE(five->x(), 53.0); + QCOMPARE(five->y(), 72.0); + + obj->resetBottomPadding(); + QCOMPARE(flow->property("bottomPadding").toDouble(), 1.0); + QTRY_COMPARE(flow->height(), 123.0); + QCOMPARE(flow->width(), 90.0); + + obj->resetRightPadding(); + QCOMPARE(flow->property("rightPadding").toDouble(), 1.0); + QTRY_COMPARE(flow->height(), 123.0); + QCOMPARE(flow->width(), 90.0); + + obj->resetLeftPadding(); + QCOMPARE(flow->property("leftPadding").toDouble(), 1.0); + QTRY_COMPARE(flow->height(), 123.0); + QCOMPARE(flow->width(), 90.0); + + obj->resetTopPadding(); + QCOMPARE(flow->property("topPadding").toDouble(), 1.0); + QTRY_COMPARE(flow->height(), 122.0); + QCOMPARE(flow->width(), 90.0); + + obj->resetPadding(); + QCOMPARE(flow->property("padding").toDouble(), 0.0); + QCOMPARE(flow->property("topPadding").toDouble(), 0.0); + QCOMPARE(flow->property("leftPadding").toDouble(), 0.0); + QCOMPARE(flow->property("rightPadding").toDouble(), 0.0); + QCOMPARE(flow->property("bottomPadding").toDouble(), 0.0); + QTRY_COMPARE(flow->height(), 120.0); + QCOMPARE(flow->width(), 90.0); + + QCOMPARE(one->x(), 0.0); + QCOMPARE(one->y(), 0.0); + QCOMPARE(two->x(), 50.0); + QCOMPARE(two->y(), 0.0); + QCOMPARE(three->x(), 0.0); + QCOMPARE(three->y(), 50.0); + QCOMPARE(four->x(), 0.0); + QCOMPARE(four->y(), 70.0); + QCOMPARE(five->x(), 50.0); + QCOMPARE(five->y(), 70.0); } void tst_qquickpositioners::test_flow_rightToLeft() @@ -1667,6 +3317,26 @@ void tst_qquickpositioners::test_flow_rightToLeft() QCOMPARE(flow->width(), 90.0); QCOMPARE(flow->height(), 120.0); + // test padding + flow->setProperty("padding", 1); + flow->setProperty("topPadding", 2); + flow->setProperty("leftPadding", 3); + flow->setProperty("rightPadding", 4); + flow->setProperty("bottomPadding", 5); + + QTRY_COMPARE(flow->height(), 127.0); + QCOMPARE(flow->width(), 90.0); + + QCOMPARE(one->x(), 36.0); + QCOMPARE(one->y(), 2.0); + QCOMPARE(two->x(), 16.0); + QCOMPARE(two->y(), 2.0); + QCOMPARE(three->x(), 36.0); + QCOMPARE(three->y(), 52.0); + QCOMPARE(four->x(), 36.0); + QCOMPARE(four->y(), 72.0); + QCOMPARE(five->x(), 26.0); + QCOMPARE(five->y(), 72.0); } void tst_qquickpositioners::test_flow_topToBottom() @@ -1693,7 +3363,7 @@ void tst_qquickpositioners::test_flow_topToBottom() QCOMPARE(three->x(), 50.0); QCOMPARE(three->y(), 50.0); QCOMPARE(four->x(), 100.0); - QCOMPARE(four->y(), 00.0); + QCOMPARE(four->y(), 0.0); QCOMPARE(five->x(), 100.0); QCOMPARE(five->y(), 50.0); @@ -1721,6 +3391,79 @@ void tst_qquickpositioners::test_flow_topToBottom() } +void tst_qquickpositioners::test_flow_topToBottom_padding() +{ + QScopedPointer<QQuickView> window(createView(testFile("flowtest-toptobottom.qml"))); + + window->rootObject()->setProperty("testRightToLeft", false); + + QQuickRectangle *one = window->rootObject()->findChild<QQuickRectangle*>("one"); + QVERIFY(one != 0); + QQuickRectangle *two = window->rootObject()->findChild<QQuickRectangle*>("two"); + QVERIFY(two != 0); + QQuickRectangle *three = window->rootObject()->findChild<QQuickRectangle*>("three"); + QVERIFY(three != 0); + QQuickRectangle *four = window->rootObject()->findChild<QQuickRectangle*>("four"); + QVERIFY(four != 0); + QQuickRectangle *five = window->rootObject()->findChild<QQuickRectangle*>("five"); + QVERIFY(five != 0); + + QCOMPARE(one->x(), 0.0); + QCOMPARE(one->y(), 0.0); + QCOMPARE(two->x(), 50.0); + QCOMPARE(two->y(), 0.0); + QCOMPARE(three->x(), 50.0); + QCOMPARE(three->y(), 50.0); + QCOMPARE(four->x(), 100.0); + QCOMPARE(four->y(), 0.0); + QCOMPARE(five->x(), 100.0); + QCOMPARE(five->y(), 50.0); + + QQuickItem *flow = window->rootObject()->findChild<QQuickItem*>("flow"); + QVERIFY(flow); + QCOMPARE(flow->height(), 90.0); + QCOMPARE(flow->width(), 150.0); + + // test padding + flow->setProperty("padding", 1); + flow->setProperty("topPadding", 2); + flow->setProperty("leftPadding", 3); + flow->setProperty("rightPadding", 4); + flow->setProperty("bottomPadding", 5); + + QTRY_COMPARE(flow->width(), 157.0); + QCOMPARE(flow->height(), 90.0); + + QCOMPARE(one->x(), 3.0); + QCOMPARE(one->y(), 2.0); + QCOMPARE(two->x(), 53.0); + QCOMPARE(two->y(), 2.0); + QCOMPARE(three->x(), 53.0); + QCOMPARE(three->y(), 52.0); + QCOMPARE(four->x(), 103.0); + QCOMPARE(four->y(), 2.0); + QCOMPARE(five->x(), 103.0); + QCOMPARE(five->y(), 52.0); + + window->rootObject()->setProperty("testRightToLeft", true); + + QVERIFY(flow); + QTRY_COMPARE(flow->width(), 157.0); + QCOMPARE(flow->height(), 90.0); + + QCOMPARE(one->x(), 103.0); + QCOMPARE(one->y(), 2.0); + QCOMPARE(two->x(), 83.0); + QCOMPARE(two->y(), 2.0); + QCOMPARE(three->x(), 53.0); + QCOMPARE(three->y(), 52.0); + QCOMPARE(four->x(), 3.0); + QCOMPARE(four->y(), 2.0); + QCOMPARE(five->x(), 43.0); + QCOMPARE(five->y(), 52.0); + +} + void tst_qquickpositioners::test_flow_resize() { QScopedPointer<QQuickView> window(createView(testFile("flowtest.qml"))); @@ -1754,6 +3497,39 @@ void tst_qquickpositioners::test_flow_resize() } +void tst_qquickpositioners::test_flow_resize_padding() +{ + QScopedPointer<QQuickView> window(createView(testFile("flowtest-padding.qml"))); + + QQuickItem *root = qobject_cast<QQuickItem*>(window->rootObject()); + QVERIFY(root); + root->setWidth(125); + root->setProperty("testRightToLeft", false); + + QQuickRectangle *one = window->rootObject()->findChild<QQuickRectangle*>("one"); + QVERIFY(one != 0); + QQuickRectangle *two = window->rootObject()->findChild<QQuickRectangle*>("two"); + QVERIFY(two != 0); + QQuickRectangle *three = window->rootObject()->findChild<QQuickRectangle*>("three"); + QVERIFY(three != 0); + QQuickRectangle *four = window->rootObject()->findChild<QQuickRectangle*>("four"); + QVERIFY(four != 0); + QQuickRectangle *five = window->rootObject()->findChild<QQuickRectangle*>("five"); + QVERIFY(five != 0); + + QTRY_COMPARE(one->x(), 3.0); + QTRY_COMPARE(one->y(), 2.0); + QTRY_COMPARE(two->x(), 53.0); + QTRY_COMPARE(two->y(), 2.0); + QTRY_COMPARE(three->x(), 3.0); + QTRY_COMPARE(three->y(), 52.0); + QTRY_COMPARE(four->x(), 53.0); + QTRY_COMPARE(four->y(), 52.0); + QTRY_COMPARE(five->x(), 103.0); + QTRY_COMPARE(five->y(), 52.0); + +} + void tst_qquickpositioners::test_flow_resize_rightToLeft() { QScopedPointer<QQuickView> window(createView(testFile("flowtest.qml"))); @@ -1787,6 +3563,39 @@ void tst_qquickpositioners::test_flow_resize_rightToLeft() } +void tst_qquickpositioners::test_flow_resize_rightToLeft_padding() +{ + QScopedPointer<QQuickView> window(createView(testFile("flowtest-padding.qml"))); + + QQuickItem *root = qobject_cast<QQuickItem*>(window->rootObject()); + QVERIFY(root); + root->setWidth(125); + root->setProperty("testRightToLeft", true); + + QQuickRectangle *one = window->rootObject()->findChild<QQuickRectangle*>("one"); + QTRY_VERIFY(one != 0); + QQuickRectangle *two = window->rootObject()->findChild<QQuickRectangle*>("two"); + QVERIFY(two != 0); + QQuickRectangle *three = window->rootObject()->findChild<QQuickRectangle*>("three"); + QVERIFY(three != 0); + QQuickRectangle *four = window->rootObject()->findChild<QQuickRectangle*>("four"); + QVERIFY(four != 0); + QQuickRectangle *five = window->rootObject()->findChild<QQuickRectangle*>("five"); + QVERIFY(five != 0); + + QCOMPARE(one->x(), 71.0); + QCOMPARE(one->y(), 2.0); + QCOMPARE(two->x(), 51.0); + QCOMPARE(two->y(), 2.0); + QCOMPARE(three->x(), 71.0); + QCOMPARE(three->y(), 52.0); + QCOMPARE(four->x(), 21.0); + QCOMPARE(four->y(), 52.0); + QCOMPARE(five->x(), 11.0); + QCOMPARE(five->y(), 52.0); + +} + void tst_qquickpositioners::test_flow_implicit_resize() { QScopedPointer<QQuickView> window(createView(testFile("flow-testimplicitsize.qml"))); @@ -1815,6 +3624,44 @@ void tst_qquickpositioners::test_flow_implicit_resize() } +void tst_qquickpositioners::test_flow_implicit_resize_padding() +{ + QScopedPointer<QQuickView> window(createView(testFile("flow-testimplicitsize.qml"))); + QVERIFY(window->rootObject() != 0); + + QQuickFlow *flow = window->rootObject()->findChild<QQuickFlow*>("flow"); + QVERIFY(flow != 0); + + QCOMPARE(flow->width(), 100.0); + QCOMPARE(flow->height(), 120.0); + + // test padding + flow->setProperty("padding", 1); + flow->setProperty("topPadding", 2); + flow->setProperty("leftPadding", 3); + flow->setProperty("rightPadding", 4); + flow->setProperty("bottomPadding", 5); + + QTRY_COMPARE(flow->width(), 107.0); + QCOMPARE(flow->height(), 127.0); + + window->rootObject()->setProperty("flowLayout", 0); + QCOMPARE(flow->flow(), QQuickFlow::LeftToRight); + QCOMPARE(flow->width(), 227.0); + QCOMPARE(flow->height(), 57.0); + + window->rootObject()->setProperty("flowLayout", 1); + QCOMPARE(flow->flow(), QQuickFlow::TopToBottom); + QCOMPARE(flow->width(), 107.0); + QCOMPARE(flow->height(), 127.0); + + window->rootObject()->setProperty("flowLayout", 2); + QCOMPARE(flow->layoutDirection(), Qt::RightToLeft); + QCOMPARE(flow->width(), 227.0); + QCOMPARE(flow->height(), 57.0); + +} + void tst_qquickpositioners::test_conflictinganchors() { QQmlTestMessageHandler messageHandler; @@ -1924,7 +3771,9 @@ void tst_qquickpositioners::test_conflictinganchors() void tst_qquickpositioners::test_mirroring() { QList<QString> qmlFiles; - qmlFiles << "horizontal.qml" << "gridtest.qml" << "flowtest.qml"; + qmlFiles << "horizontal.qml" << "horizontal-padding.qml" + << "gridtest.qml" << "gridtest-padding.qml" + << "flowtest.qml" << "flowtest-padding.qml"; QList<QString> objectNames; objectNames << "one" << "two" << "three" << "four" << "five"; @@ -1942,8 +3791,8 @@ void tst_qquickpositioners::test_mirroring() // LTR != RTL foreach (const QString objectName, objectNames) { - // horizontal.qml only has three items - if (qmlFile == QString("horizontal.qml") && objectName == QString("four")) + // horizontal.qml and horizontal-padding.qml only have three items + if (qmlFile.startsWith(QString("horizontal")) && objectName == QString("four")) break; QQuickItem *itemA = rootA->findChild<QQuickItem*>(objectName); QQuickItem *itemB = rootB->findChild<QQuickItem*>(objectName); @@ -1957,8 +3806,8 @@ void tst_qquickpositioners::test_mirroring() // RTL == mirror foreach (const QString objectName, objectNames) { - // horizontal.qml only has three items - if (qmlFile == QString("horizontal.qml") && objectName == QString("four")) + // horizontal.qml and horizontal-padding.qml only have three items + if (qmlFile.startsWith(QString("horizontal")) && objectName == QString("four")) break; QQuickItem *itemA = rootA->findChild<QQuickItem*>(objectName); QQuickItem *itemB = rootB->findChild<QQuickItem*>(objectName); @@ -1978,8 +3827,8 @@ void tst_qquickpositioners::test_mirroring() // LTR == RTL + mirror foreach (const QString objectName, objectNames) { - // horizontal.qml only has three items - if (qmlFile == QString("horizontal.qml") && objectName == QString("four")) + // horizontal.qml and horizontal-padding.qml only have three items + if (qmlFile.startsWith(QString("horizontal")) && objectName == QString("four")) break; QQuickItem *itemA = rootA->findChild<QQuickItem*>(objectName); QQuickItem *itemB = rootB->findChild<QQuickItem*>(objectName); @@ -1998,12 +3847,63 @@ void tst_qquickpositioners::test_allInvisible() QQuickRow *row = window->rootObject()->findChild<QQuickRow*>("row"); QVERIFY(row != 0); - QVERIFY(row->width() == 0); - QVERIFY(row->height() == 0); + QCOMPARE(row->width(), qreal(0)); + QCOMPARE(row->height(), qreal(0)); + + // test padding + row->setProperty("padding", 1); + row->setProperty("topPadding", 2); + row->setProperty("leftPadding", 3); + row->setProperty("rightPadding", 4); + row->setProperty("bottomPadding", 5); + + QTRY_COMPARE(row->height(), 7.0); + QCOMPARE(row->width(), 7.0); + QQuickColumn *column = window->rootObject()->findChild<QQuickColumn*>("column"); QVERIFY(column != 0); - QVERIFY(column->width() == 0); - QVERIFY(column->height() == 0); + QCOMPARE(column->width(), qreal(0)); + QCOMPARE(column->height(), qreal(0)); + + // test padding + column->setProperty("padding", 1); + column->setProperty("topPadding", 2); + column->setProperty("leftPadding", 3); + column->setProperty("rightPadding", 4); + column->setProperty("bottomPadding", 5); + + QTRY_COMPARE(column->height(), 7.0); + QCOMPARE(column->width(), 7.0); + + QQuickGrid *grid = window->rootObject()->findChild<QQuickGrid*>("grid"); + QVERIFY(grid != 0); + QCOMPARE(grid->width(), qreal(0)); + QCOMPARE(grid->height(), qreal(0)); + + // test padding + grid->setProperty("padding", 1); + grid->setProperty("topPadding", 2); + grid->setProperty("leftPadding", 3); + grid->setProperty("rightPadding", 4); + grid->setProperty("bottomPadding", 5); + + QTRY_COMPARE(grid->height(), 7.0); + QCOMPARE(grid->width(), 7.0); + + QQuickFlow *flow = window->rootObject()->findChild<QQuickFlow*>("flow"); + QVERIFY(flow != 0); + QCOMPARE(flow->width(), qreal(0)); + QCOMPARE(flow->height(), qreal(0)); + + // test padding + flow->setProperty("padding", 1); + flow->setProperty("topPadding", 2); + flow->setProperty("leftPadding", 3); + flow->setProperty("rightPadding", 4); + flow->setProperty("bottomPadding", 5); + + QTRY_COMPARE(flow->height(), 7.0); + QCOMPARE(flow->width(), 7.0); } void tst_qquickpositioners::test_attachedproperties() @@ -2017,30 +3917,30 @@ void tst_qquickpositioners::test_attachedproperties() QVERIFY(greenRect != 0); int posIndex = greenRect->property("posIndex").toInt(); - QVERIFY(posIndex == 0); + QCOMPARE(posIndex, 0); bool isFirst = greenRect->property("isFirstItem").toBool(); - QVERIFY(isFirst == true); + QVERIFY(isFirst); bool isLast = greenRect->property("isLastItem").toBool(); - QVERIFY(isLast == false); + QVERIFY(!isLast); QQuickRectangle *yellowRect = window->rootObject()->findChild<QQuickRectangle *>("yellowRect"); QVERIFY(yellowRect != 0); posIndex = yellowRect->property("posIndex").toInt(); - QVERIFY(posIndex == -1); + QCOMPARE(posIndex, -1); isFirst = yellowRect->property("isFirstItem").toBool(); - QVERIFY(isFirst == false); + QVERIFY(!isFirst); isLast = yellowRect->property("isLastItem").toBool(); - QVERIFY(isLast == false); + QVERIFY(!isLast); yellowRect->metaObject()->invokeMethod(yellowRect, "onDemandPositioner"); posIndex = yellowRect->property("posIndex").toInt(); - QVERIFY(posIndex == 1); + QCOMPARE(posIndex, 1); isFirst = yellowRect->property("isFirstItem").toBool(); - QVERIFY(isFirst == false); + QVERIFY(!isFirst); isLast = yellowRect->property("isLastItem").toBool(); - QVERIFY(isLast == true); + QVERIFY(isLast); } @@ -2066,46 +3966,46 @@ void tst_qquickpositioners::test_attachedproperties_dynamic() QVERIFY(rect0 != 0); int posIndex = rect0->property("index").toInt(); - QVERIFY(posIndex == 0); + QCOMPARE(posIndex, 0); bool isFirst = rect0->property("firstItem").toBool(); - QVERIFY(isFirst == true); + QVERIFY(isFirst); bool isLast = rect0->property("lastItem").toBool(); - QVERIFY(isLast == false); + QVERIFY(!isLast); QQuickRectangle *rect1 = window->rootObject()->findChild<QQuickRectangle *>("rect1"); QVERIFY(rect1 != 0); posIndex = rect1->property("index").toInt(); - QVERIFY(posIndex == 1); + QCOMPARE(posIndex, 1); isFirst = rect1->property("firstItem").toBool(); - QVERIFY(isFirst == false); + QVERIFY(!isFirst); isLast = rect1->property("lastItem").toBool(); - QVERIFY(isLast == true); + QVERIFY(isLast); row->metaObject()->invokeMethod(row, "createSubRect"); - QTRY_VERIFY(rect1->property("index").toInt() == 1); - QTRY_VERIFY(rect1->property("firstItem").toBool() == false); - QTRY_VERIFY(rect1->property("lastItem").toBool() == false); + QTRY_COMPARE(rect1->property("index").toInt(), 1); + QTRY_VERIFY(!rect1->property("firstItem").toBool()); + QTRY_VERIFY(!rect1->property("lastItem").toBool()); QQuickRectangle *rect2 = window->rootObject()->findChild<QQuickRectangle *>("rect2"); QVERIFY(rect2 != 0); posIndex = rect2->property("index").toInt(); - QVERIFY(posIndex == 2); + QCOMPARE(posIndex, 2); isFirst = rect2->property("firstItem").toBool(); - QVERIFY(isFirst == false); + QVERIFY(!isFirst); isLast = rect2->property("lastItem").toBool(); - QVERIFY(isLast == true); + QVERIFY(isLast); row->metaObject()->invokeMethod(row, "destroySubRect"); QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete); QCoreApplication::processEvents(); - QTRY_VERIFY(rect1->property("index").toInt() == 1); - QTRY_VERIFY(rect1->property("firstItem").toBool() == false); - QTRY_VERIFY(rect1->property("lastItem").toBool() == true); + QTRY_COMPARE(rect1->property("index").toInt(), 1); + QTRY_VERIFY(!rect1->property("firstItem").toBool()); + QTRY_VERIFY(rect1->property("lastItem").toBool()); } @@ -2138,7 +4038,7 @@ void tst_qquickpositioners::matchIndexLists(const QVariantList &indexLists, cons void tst_qquickpositioners::matchItemsAndIndexes(const QVariantMap &items, const QaimModel &model, const QList<int> &expectedIndexes) { for (QVariantMap::const_iterator it = items.begin(); it != items.end(); ++it) { - QVERIFY(it.value().type() == QVariant::Int); + QCOMPARE(it.value().type(), QVariant::Int); QString name = it.key(); int itemIndex = it.value().toInt(); QVERIFY2(expectedIndexes.contains(itemIndex), QTest::toString(QString("Index %1 not found in expectedIndexes").arg(itemIndex))); @@ -2152,7 +4052,7 @@ void tst_qquickpositioners::matchItemsAndIndexes(const QVariantMap &items, const void tst_qquickpositioners::matchItemLists(const QVariantList &itemLists, const QList<QQuickItem *> &expectedItems) { for (int i=0; i<itemLists.count(); i++) { - QVERIFY(itemLists[i].type() == QVariant::List); + QCOMPARE(itemLists[i].type(), QVariant::List); QVariantList current = itemLists[i].toList(); for (int j=0; j<current.count(); j++) { QQuickItem *o = qobject_cast<QQuickItem*>(current[j].value<QObject*>()); diff --git a/tests/auto/quick/qquickrepeater/data/modelCleared.qml b/tests/auto/quick/qquickrepeater/data/modelCleared.qml new file mode 100644 index 0000000000..1269e9bdf2 --- /dev/null +++ b/tests/auto/quick/qquickrepeater/data/modelCleared.qml @@ -0,0 +1,17 @@ +import QtQuick 2.0 + +Row { + spacing: 2 + height: 100 + + Repeater { + id: repeater + objectName: "repeater" + model: 10 + Rectangle { + color: "green" + width: 10; height: 50 + anchors.bottom: parent.bottom + } + } +} diff --git a/tests/auto/quick/qquickrepeater/data/objectmodel.qml b/tests/auto/quick/qquickrepeater/data/objectmodel.qml new file mode 100644 index 0000000000..780f53e802 --- /dev/null +++ b/tests/auto/quick/qquickrepeater/data/objectmodel.qml @@ -0,0 +1,28 @@ +import QtQuick 2.0 +import QtQml.Models 2.1 + +Row { + width: 360 + height: 360 + + Repeater { + objectName: "repeater" + model: ObjectModel { + Rectangle { + width: 20 + height: 20 + color: "red" + } + Rectangle { + width: 20 + height: 20 + color: "green" + } + Rectangle { + width: 20 + height: 20 + color: "blue" + } + } + } +} diff --git a/tests/auto/quick/qquickrepeater/data/stackingorder.qml b/tests/auto/quick/qquickrepeater/data/stackingorder.qml new file mode 100644 index 0000000000..41dadca0df --- /dev/null +++ b/tests/auto/quick/qquickrepeater/data/stackingorder.qml @@ -0,0 +1,38 @@ +import QtQuick 2.0 + +Item { + id: root + property bool stackingOrderOk: true + + function verifyStackingOrder() { + var len = children.length + for (var i = 0; i < len; ++i) { + var expectedName; + if (i === 0) { + expectedName = "first" + } else if (i === len - 2) { + expectedName = "repeater" + } else if (i === len - 1) { + expectedName = "last" + } else { + expectedName = "middle" + (i - 1) + } + if (children[i].objectName !== expectedName) + stackingOrderOk = false + } + } + Item { + objectName: "first" + } + Repeater { + objectName: "repeater" + model: 1 + Item { + objectName: "middle" + index + Component.onCompleted: { verifyStackingOrder();} + } + } + Item { + objectName: "last" + } +} diff --git a/tests/auto/quick/qquickrepeater/tst_qquickrepeater.cpp b/tests/auto/quick/qquickrepeater/tst_qquickrepeater.cpp index b2039bd323..a34001b23a 100644 --- a/tests/auto/quick/qquickrepeater/tst_qquickrepeater.cpp +++ b/tests/auto/quick/qquickrepeater/tst_qquickrepeater.cpp @@ -41,6 +41,7 @@ #include <private/qquickrepeater_p.h> #include <QtQuick/private/qquicktext_p.h> #include <QtQml/private/qqmllistmodel_p.h> +#include <QtQml/private/qqmlobjectmodel_p.h> #include "../../shared/util.h" #include "../shared/viewtestutil.h" @@ -67,6 +68,7 @@ private slots: void resetModel(); void modelChanged(); void modelReset(); + void modelCleared(); void properties(); void asynchronous(); void initParent(); @@ -76,6 +78,8 @@ private slots: void jsArrayChange(); void clearRemovalOrder(); void destroyCount(); + void stackingOrder(); + void objectModel(); }; class TestObject : public QObject @@ -128,7 +132,7 @@ void tst_QQuickRepeater::numberModel() QVERIFY(!repeater->itemAt(repeater->count())); QMetaObject::invokeMethod(window->rootObject(), "checkProperties"); - QVERIFY(testObject->error() == false); + QVERIFY(!testObject->error()); delete testObject; delete window; @@ -440,19 +444,19 @@ void tst_QQuickRepeater::itemModel() testObject->setUseModel(true); QMetaObject::invokeMethod(window->rootObject(), "checkProperties"); - QVERIFY(testObject->error() == false); + QVERIFY(!testObject->error()); QCOMPARE(container->childItems().count(), 4); - QVERIFY(qobject_cast<QObject*>(container->childItems().at(0))->objectName() == "item1"); - QVERIFY(qobject_cast<QObject*>(container->childItems().at(1))->objectName() == "item2"); - QVERIFY(qobject_cast<QObject*>(container->childItems().at(2))->objectName() == "item3"); - QVERIFY(container->childItems().at(3) == repeater); + QCOMPARE(qobject_cast<QObject*>(container->childItems().at(0))->objectName(), QLatin1String("item1")); + QCOMPARE(qobject_cast<QObject*>(container->childItems().at(1))->objectName(), QLatin1String("item2")); + QCOMPARE(qobject_cast<QObject*>(container->childItems().at(2))->objectName(), QLatin1String("item3")); + QCOMPARE(container->childItems().at(3), repeater); QMetaObject::invokeMethod(window->rootObject(), "switchModel"); QCOMPARE(container->childItems().count(), 3); - QVERIFY(qobject_cast<QObject*>(container->childItems().at(0))->objectName() == "item4"); - QVERIFY(qobject_cast<QObject*>(container->childItems().at(1))->objectName() == "item5"); - QVERIFY(container->childItems().at(2) == repeater); + QCOMPARE(qobject_cast<QObject*>(container->childItems().at(0))->objectName(), QLatin1String("item4")); + QCOMPARE(qobject_cast<QObject*>(container->childItems().at(1))->objectName(), QLatin1String("item5")); + QCOMPARE(container->childItems().at(2), repeater); testObject->setUseModel(false); QCOMPARE(container->childItems().count(), 1); @@ -631,6 +635,26 @@ void tst_QQuickRepeater::modelReset() QCOMPARE(addedSpy.count(), 0); } +// QTBUG-46828 +void tst_QQuickRepeater::modelCleared() +{ + QQmlEngine engine; + QQmlComponent component(&engine, testFileUrl("modelCleared.qml")); + + QQuickItem *rootObject = qobject_cast<QQuickItem*>(component.create()); + QVERIFY(rootObject); + + QQuickRepeater *repeater = findItem<QQuickRepeater>(rootObject, "repeater"); + QVERIFY(repeater); + + // verify no error messages when the model is cleared and the items are destroyed + QQmlTestMessageHandler messageHandler; + repeater->setModel(0); + QVERIFY2(messageHandler.messages().isEmpty(), qPrintable(messageHandler.messageString())); + + delete rootObject; +} + void tst_QQuickRepeater::properties() { QQmlEngine engine; @@ -788,8 +812,8 @@ void tst_QQuickRepeater::invalidContextCrash() repeater->setParent(root.data()); QCOMPARE(root->children().count(), 2); - QVERIFY(root->children().at(0) == model); - QVERIFY(root->children().at(1) == repeater); + QCOMPARE(root->children().at(0), model); + QCOMPARE(root->children().at(1), repeater); // Delete the root object, which will invalidate/delete the QML context // and then delete the child QObjects, which may try to access the context. @@ -894,6 +918,82 @@ void tst_QQuickRepeater::destroyCount() QCOMPARE(repeater->property("componentCount").toInt(), 4); } +void tst_QQuickRepeater::stackingOrder() +{ + QQmlEngine engine; + QQmlComponent component(&engine, testFileUrl("stackingorder.qml")); + + QQuickItem *rootObject = qobject_cast<QQuickItem*>(component.create()); + QVERIFY(rootObject); + + QQuickRepeater *repeater = findItem<QQuickRepeater>(rootObject, "repeater"); + QVERIFY(repeater); + int count = 1; + do { + bool stackingOrderOk = rootObject->property("stackingOrderOk").toBool(); + QVERIFY(stackingOrderOk); + repeater->setModel(QVariant(++count)); + } while (count < 3); +} + +static bool compareObjectModel(QQuickRepeater *repeater, QQmlObjectModel *model) +{ + if (repeater->count() != model->count()) + return false; + for (int i = 0; i < repeater->count(); ++i) { + if (repeater->itemAt(i) != model->get(i)) + return false; + } + return true; +} + +void tst_QQuickRepeater::objectModel() +{ + QQmlEngine engine; + QQmlComponent component(&engine, testFileUrl("objectmodel.qml")); + + QQuickItem *positioner = qobject_cast<QQuickItem *>(component.create()); + QVERIFY(positioner); + + QQuickRepeater *repeater = findItem<QQuickRepeater>(positioner, "repeater"); + QVERIFY(repeater); + + QQmlObjectModel *model = repeater->model().value<QQmlObjectModel *>(); + QVERIFY(model); + + QVERIFY(repeater->itemAt(0)); + QVERIFY(repeater->itemAt(1)); + QVERIFY(repeater->itemAt(2)); + QCOMPARE(repeater->itemAt(0)->property("color").toString(), QColor("red").name()); + QCOMPARE(repeater->itemAt(1)->property("color").toString(), QColor("green").name()); + QCOMPARE(repeater->itemAt(2)->property("color").toString(), QColor("blue").name()); + + QQuickItem *item0 = new QQuickItem(positioner); + item0->setSize(QSizeF(20, 20)); + model->append(item0); + QCOMPARE(model->count(), 4); + QVERIFY(compareObjectModel(repeater, model)); + + QQuickItem *item1 = new QQuickItem(positioner); + item1->setSize(QSizeF(20, 20)); + model->insert(0, item1); + QCOMPARE(model->count(), 5); + QVERIFY(compareObjectModel(repeater, model)); + + model->move(1, 2, 3); + QVERIFY(compareObjectModel(repeater, model)); + + model->remove(2, 2); + QCOMPARE(model->count(), 3); + QVERIFY(compareObjectModel(repeater, model)); + + model->clear(); + QCOMPARE(model->count(), 0); + QCOMPARE(repeater->count(), 0); + + delete positioner; +} + QTEST_MAIN(tst_QQuickRepeater) #include "tst_qquickrepeater.moc" diff --git a/tests/auto/quick/qquicksmoothedanimation/tst_qquicksmoothedanimation.cpp b/tests/auto/quick/qquicksmoothedanimation/tst_qquicksmoothedanimation.cpp index 04fdc4ecf7..10e91c455b 100644 --- a/tests/auto/quick/qquicksmoothedanimation/tst_qquicksmoothedanimation.cpp +++ b/tests/auto/quick/qquicksmoothedanimation/tst_qquicksmoothedanimation.cpp @@ -130,9 +130,9 @@ void tst_qquicksmoothedanimation::simpleAnimation() animation->setProperty("x"); animation->setTo(200); animation->setDuration(250); - QVERIFY(animation->target() == rect); - QVERIFY(animation->property() == "x"); - QVERIFY(animation->to() == 200); + QCOMPARE(animation->target(), rect); + QCOMPARE(animation->property(), QLatin1String("x")); + QCOMPARE(animation->to(), qreal(200)); animation->start(); QVERIFY(animation->isRunning()); QTest::qWait(animation->duration()); @@ -147,7 +147,7 @@ void tst_qquicksmoothedanimation::simpleAnimation() QVERIFY(animation->isRunning()); QVERIFY(animation->isPaused()); animation->setCurrentTime(125); - QVERIFY(animation->currentTime() == 125); + QCOMPARE(animation->currentTime(), 125); QCOMPARE(rect->x(), qreal(100)); } diff --git a/tests/auto/quick/qquickstates/tst_qquickstates.cpp b/tests/auto/quick/qquickstates/tst_qquickstates.cpp index 6c42a7a0ee..a375a55877 100644 --- a/tests/auto/quick/qquickstates/tst_qquickstates.cpp +++ b/tests/auto/quick/qquickstates/tst_qquickstates.cpp @@ -1241,7 +1241,7 @@ void tst_qquickstates::deletingState() QVERIFY(state != 0); delete state; - QVERIFY(sg->findState("blue") == 0); + QVERIFY(!sg->findState("blue")); //### should we warn that state doesn't exist sg->setState("blue"); @@ -1317,7 +1317,7 @@ void tst_qquickstates::illegalObjectCreation() QQmlComponent component(&engine, testFileUrl("illegalObj.qml")); QList<QQmlError> errors = component.errors(); - QVERIFY(errors.count() == 1); + QCOMPARE(errors.count(), 1); const QQmlError &error = errors.at(0); QCOMPARE(error.line(), 9); QCOMPARE(error.column(), 23); @@ -1637,7 +1637,7 @@ void tst_qquickstates::QTBUG_38492() void tst_qquickstates::revertListMemoryLeak() { - QWeakPointer<QQmlAbstractBinding> weakPtr; + QQmlAbstractBinding::Ptr bindingPtr; { QQmlEngine engine; @@ -1651,12 +1651,12 @@ void tst_qquickstates::revertListMemoryLeak() QQmlAbstractBinding *binding = state->bindingInRevertList(item, "height"); QVERIFY(binding); - weakPtr = QQmlAbstractBinding::getPointer(binding); - QVERIFY(!weakPtr.toStrongRef().isNull()); + bindingPtr = binding; + QVERIFY(bindingPtr->ref > 1); delete item; } - QVERIFY(weakPtr.toStrongRef().isNull()); + QVERIFY(bindingPtr->ref == 1); } QTEST_MAIN(tst_qquickstates) diff --git a/tests/auto/quick/qquickstyledtext/tst_qquickstyledtext.cpp b/tests/auto/quick/qquickstyledtext/tst_qquickstyledtext.cpp index 816440b191..4678f5fbb9 100644 --- a/tests/auto/quick/qquickstyledtext/tst_qquickstyledtext.cpp +++ b/tests/auto/quick/qquickstyledtext/tst_qquickstyledtext.cpp @@ -171,16 +171,16 @@ void tst_qquickstyledtext::textOutput() QCOMPARE(layout.text(), output); - QList<QTextLayout::FormatRange> layoutFormats = layout.additionalFormats(); + const QVector<QTextLayout::FormatRange> layoutFormats = layout.formats(); QCOMPARE(layoutFormats.count(), formats.count()); for (int i = 0; i < formats.count(); ++i) { QCOMPARE(layoutFormats.at(i).start, formats.at(i).start); QCOMPARE(layoutFormats.at(i).length, formats.at(i).length); if (formats.at(i).type & Format::Bold) - QVERIFY(layoutFormats.at(i).format.fontWeight() == QFont::Bold); + QCOMPARE(layoutFormats.at(i).format.fontWeight(), int(QFont::Bold)); else - QVERIFY(layoutFormats.at(i).format.fontWeight() == QFont::Normal); + QCOMPARE(layoutFormats.at(i).format.fontWeight(), int(QFont::Normal)); QVERIFY(layoutFormats.at(i).format.fontItalic() == bool(formats.at(i).type & Format::Italic)); QVERIFY(layoutFormats.at(i).format.fontUnderline() == bool(formats.at(i).type & Format::Underline)); } @@ -200,7 +200,7 @@ void tst_qquickstyledtext::anchors() QCOMPARE(layout.text(), output); - QList<QTextLayout::FormatRange> layoutFormats = layout.additionalFormats(); + const QVector<QTextLayout::FormatRange> layoutFormats = layout.formats(); QCOMPARE(layoutFormats.count(), formats.count()); for (int i = 0; i < formats.count(); ++i) { diff --git a/tests/auto/quick/qquicksystempalette/tst_qquicksystempalette.cpp b/tests/auto/quick/qquicksystempalette/tst_qquicksystempalette.cpp index 5c0c5fd8d3..a4c4987ad9 100644 --- a/tests/auto/quick/qquicksystempalette/tst_qquicksystempalette.cpp +++ b/tests/auto/quick/qquicksystempalette/tst_qquicksystempalette.cpp @@ -97,7 +97,7 @@ void tst_qquicksystempalette::inactivePalette() QQuickSystemPalette *object = qobject_cast<QQuickSystemPalette*>(component.create()); QVERIFY(object != 0); - QVERIFY(object->colorGroup() == QQuickSystemPalette::Inactive); + QCOMPARE(object->colorGroup(), QQuickSystemPalette::Inactive); QPalette palette; palette.setCurrentColorGroup(QPalette::Inactive); @@ -127,7 +127,7 @@ void tst_qquicksystempalette::disabledPalette() QQuickSystemPalette *object = qobject_cast<QQuickSystemPalette*>(component.create()); QVERIFY(object != 0); - QVERIFY(object->colorGroup() == QQuickSystemPalette::Disabled); + QCOMPARE(object->colorGroup(), QQuickSystemPalette::Disabled); QPalette palette; palette.setCurrentColorGroup(QPalette::Disabled); diff --git a/tests/auto/quick/qquicktext/BLACKLIST b/tests/auto/quick/qquicktext/BLACKLIST new file mode 100644 index 0000000000..0c65f1e245 --- /dev/null +++ b/tests/auto/quick/qquicktext/BLACKLIST @@ -0,0 +1,4 @@ +[dependentImplicitSizes] +* +[mouseSelection] +* diff --git a/tests/auto/quick/qquicktext/data/padding.qml b/tests/auto/quick/qquicktext/data/padding.qml new file mode 100644 index 0000000000..ab0a37d041 --- /dev/null +++ b/tests/auto/quick/qquicktext/data/padding.qml @@ -0,0 +1,12 @@ +import QtQuick 2.6 + +Text { + width: 200; height: 200 + text: "Hello Qt" + + padding: 10 + topPadding: 20 + leftPadding: 30 + rightPadding: 40 + bottomPadding: 50 +} diff --git a/tests/auto/quick/qquicktext/tst_qquicktext.cpp b/tests/auto/quick/qquicktext/tst_qquicktext.cpp index eb9f7529fe..c1f10f9788 100644 --- a/tests/auto/quick/qquicktext/tst_qquicktext.cpp +++ b/tests/auto/quick/qquicktext/tst_qquicktext.cpp @@ -148,6 +148,8 @@ private slots: void growFromZeroWidth(); + void padding(); + private: QStringList standard; QStringList richText; @@ -240,7 +242,7 @@ void tst_qquicktext::text() QVERIFY(textObject != 0); QCOMPARE(textObject->text(), QString("")); - QVERIFY(textObject->width() == 0); + QCOMPARE(textObject->width(), qreal(0)); delete textObject; } @@ -357,7 +359,7 @@ void tst_qquicktext::width() QVERIFY(doc != 0); QCOMPARE(int(textObject->width()), int(doc->idealWidth())); - QVERIFY(textObject->textFormat() == QQuickText::RichText); + QCOMPARE(textObject->textFormat(), QQuickText::RichText); delete textObject; } @@ -374,7 +376,7 @@ void tst_qquicktext::wrap() textHeight = textObject->height(); QVERIFY(textObject != 0); - QVERIFY(textObject->wrapMode() == QQuickText::WordWrap); + QCOMPARE(textObject->wrapMode(), QQuickText::WordWrap); QCOMPARE(textObject->width(), 300.); delete textObject; @@ -657,11 +659,11 @@ void tst_qquicktext::textFormat() QQuickText *textObject = qobject_cast<QQuickText*>(textComponent.create()); QVERIFY(textObject != 0); - QVERIFY(textObject->textFormat() == QQuickText::RichText); + QCOMPARE(textObject->textFormat(), QQuickText::RichText); QQuickTextPrivate *textPrivate = QQuickTextPrivate::get(textObject); QVERIFY(textPrivate != 0); - QVERIFY(textPrivate->richText == true); + QVERIFY(textPrivate->richText); delete textObject; } @@ -671,11 +673,11 @@ void tst_qquicktext::textFormat() QQuickText *textObject = qobject_cast<QQuickText*>(textComponent.create()); QVERIFY(textObject != 0); - QVERIFY(textObject->textFormat() == QQuickText::AutoText); + QCOMPARE(textObject->textFormat(), QQuickText::AutoText); QQuickTextPrivate *textPrivate = QQuickTextPrivate::get(textObject); QVERIFY(textPrivate != 0); - QVERIFY(textPrivate->styledText == true); + QVERIFY(textPrivate->styledText); delete textObject; } @@ -685,7 +687,7 @@ void tst_qquicktext::textFormat() QQuickText *textObject = qobject_cast<QQuickText*>(textComponent.create()); QVERIFY(textObject != 0); - QVERIFY(textObject->textFormat() == QQuickText::PlainText); + QCOMPARE(textObject->textFormat(), QQuickText::PlainText); delete textObject; } @@ -2048,7 +2050,7 @@ void tst_qquicktext::embeddedImages_data() QTest::newRow("remote") << testFileUrl("embeddedImagesRemote.qml") << ""; QTest::newRow("remote-error") << testFileUrl("embeddedImagesRemoteError.qml") << testFileUrl("embeddedImagesRemoteError.qml").toString()+":3:1: QML Text: Error downloading {{ServerBaseUrl}}/notexists.png - server replied: Not found"; - QTest::newRow("remote") << testFileUrl("embeddedImagesRemoteRelative.qml") << ""; + QTest::newRow("remote-relative") << testFileUrl("embeddedImagesRemoteRelative.qml") << ""; } void tst_qquicktext::embeddedImages() @@ -2058,6 +2060,14 @@ void tst_qquicktext::embeddedImages() QFETCH(QUrl, qmlfile); QFETCH(QString, error); +#if defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID) + if (qstrcmp(QTest::currentDataTag(), "remote") == 0 + || qstrcmp(QTest::currentDataTag(), "remote-error") == 0 + || qstrcmp(QTest::currentDataTag(), "remote-relative") == 0) { + QSKIP("Remote tests cause occasional hangs in the CI system -- QTBUG-45655"); + } +#endif + TestHTTPServer server; QVERIFY2(server.listen(), qPrintable(server.errorString())); server.serveDirectory(testFile("http")); @@ -2126,8 +2136,8 @@ void tst_qquicktext::lineHeight() QQuickText *myText = window->rootObject()->findChild<QQuickText*>("myText"); QVERIFY(myText != 0); - QVERIFY(myText->lineHeight() == 1); - QVERIFY(myText->lineHeightMode() == QQuickText::ProportionalHeight); + QCOMPARE(myText->lineHeight(), qreal(1)); + QCOMPARE(myText->lineHeightMode(), QQuickText::ProportionalHeight); qreal h = myText->height(); myText->setLineHeight(1.5); @@ -2197,12 +2207,12 @@ void tst_qquicktext::implicitSize() QQuickText *textObject = qobject_cast<QQuickText*>(textComponent.create()); QVERIFY(textObject->width() < textObject->implicitWidth()); - QVERIFY(textObject->height() == textObject->implicitHeight()); + QCOMPARE(textObject->height(), textObject->implicitHeight()); QCOMPARE(textObject->property("iWidth").toReal(), textObject->implicitWidth()); textObject->resetWidth(); - QVERIFY(textObject->width() == textObject->implicitWidth()); - QVERIFY(textObject->height() == textObject->implicitHeight()); + QCOMPARE(textObject->width(), textObject->implicitWidth()); + QCOMPARE(textObject->height(), textObject->implicitHeight()); delete textObject; } @@ -2738,7 +2748,7 @@ void tst_qquicktext::lineLaidOut() QVERIFY(r.x() == r.width() + 30); if (i >= 60) { QVERIFY(r.x() == r.width() * 2 + 60); - QVERIFY(r.height() == 20); + QCOMPARE(r.height(), qreal(20)); } } @@ -2916,7 +2926,7 @@ void tst_qquicktext::imgTagsAlign() QQuickText *textObject = qobject_cast<QQuickText*>(textComponent.create()); QVERIFY(textObject != 0); - QVERIFY(textObject->height() == imgHeight); + QCOMPARE(textObject->height(), qreal(imgHeight)); QQuickTextPrivate *textPrivate = QQuickTextPrivate::get(textObject); QVERIFY(textPrivate != 0); @@ -2927,7 +2937,7 @@ void tst_qquicktext::imgTagsAlign() else if (align == "middle") QVERIFY(br.y() == imgHeight / 2.0 - br.height() / 2.0); else if (align == "top") - QVERIFY(br.y() == 0); + QCOMPARE(br.y(), qreal(0)); delete textObject; } @@ -2941,11 +2951,11 @@ void tst_qquicktext::imgTagsMultipleImages() QQuickText *textObject = qobject_cast<QQuickText*>(textComponent.create()); QVERIFY(textObject != 0); - QVERIFY(textObject->height() == 85); + QCOMPARE(textObject->height(), qreal(85)); QQuickTextPrivate *textPrivate = QQuickTextPrivate::get(textObject); QVERIFY(textPrivate != 0); - QVERIFY(textPrivate->extra->visibleImgTags.count() == 2); + QCOMPARE(textPrivate->extra->visibleImgTags.count(), 2); delete textObject; } @@ -2958,9 +2968,9 @@ void tst_qquicktext::imgTagsElide() QQuickTextPrivate *textPrivate = QQuickTextPrivate::get(myText); QVERIFY(textPrivate != 0); - QVERIFY(textPrivate->extra->visibleImgTags.count() == 0); + QCOMPARE(textPrivate->extra->visibleImgTags.count(), 0); myText->setMaximumLineCount(20); - QTRY_VERIFY(textPrivate->extra->visibleImgTags.count() == 1); + QTRY_COMPARE(textPrivate->extra->visibleImgTags.count(), 1); delete myText; delete window; @@ -2978,16 +2988,16 @@ void tst_qquicktext::imgTagsUpdates() QVERIFY(textPrivate != 0); myText->setText("This is a heart<img src=\"images/heart200.png\">."); - QVERIFY(textPrivate->extra->visibleImgTags.count() == 1); - QVERIFY(spy.count() == 1); + QCOMPARE(textPrivate->extra->visibleImgTags.count(), 1); + QCOMPARE(spy.count(), 1); myText->setMaximumLineCount(2); myText->setText("This is another heart<img src=\"images/heart200.png\">."); - QTRY_VERIFY(textPrivate->extra->visibleImgTags.count() == 1); + QTRY_COMPARE(textPrivate->extra->visibleImgTags.count(), 1); // if maximumLineCount is set and the img tag doesn't have an explicit size // we relayout twice. - QVERIFY(spy.count() == 3); + QCOMPARE(spy.count(), 3); delete myText; delete window; @@ -3634,19 +3644,19 @@ Q_DECLARE_METATYPE(ExpectedBaseline) static qreal expectedBaselineTop(QQuickText *item) { QFontMetricsF fm(item->font()); - return fm.ascent(); + return fm.ascent() + item->topPadding(); } static qreal expectedBaselineBottom(QQuickText *item) { QFontMetricsF fm(item->font()); - return item->height() - item->contentHeight() + fm.ascent(); + return item->height() - item->contentHeight() - item->bottomPadding() + fm.ascent(); } static qreal expectedBaselineCenter(QQuickText *item) { QFontMetricsF fm(item->font()); - return ((item->height() - item->contentHeight()) / 2) + fm.ascent(); + return ((item->height() - item->contentHeight() - item->topPadding() - item->bottomPadding()) / 2) + fm.ascent() + item->topPadding(); } static qreal expectedBaselineBold(QQuickText *item) @@ -3654,7 +3664,7 @@ static qreal expectedBaselineBold(QQuickText *item) QFont font = item->font(); font.setBold(true); QFontMetricsF fm(font); - return fm.ascent(); + return fm.ascent() + item->topPadding(); } static qreal expectedBaselineImage(QQuickText *item) @@ -3664,13 +3674,13 @@ static qreal expectedBaselineImage(QQuickText *item) // or image height - line height and the baseline is line position + ascent. Because // QTextLine's height is rounded up this can give slightly different results to image height // - descent. - return 181 - qCeil(fm.height()) + fm.ascent(); + return 181 - qCeil(fm.height()) + fm.ascent() + item->topPadding(); } static qreal expectedBaselineCustom(QQuickText *item) { QFontMetricsF fm(item->font()); - return 16 + fm.ascent(); + return 16 + fm.ascent() + item->topPadding(); } static qreal expectedBaselineScaled(QQuickText *item) @@ -3689,11 +3699,11 @@ static qreal expectedBaselineScaled(QQuickText *item) if (width < item->width()) { QFontMetricsF fm(layout.font()); - return fm.ascent(); + return fm.ascent() + item->topPadding(); } font.setPointSize(font.pointSize() - 1); } while (font.pointSize() > 0); - return 0; + return item->topPadding(); } static qreal expectedBaselineFixedBottom(QQuickText *item) @@ -3702,7 +3712,7 @@ static qreal expectedBaselineFixedBottom(QQuickText *item) qreal dy = item->text().contains(QLatin1Char('\n')) ? 160 : 180; - return dy + fm.ascent(); + return dy + fm.ascent() - item->bottomPadding(); } static qreal expectedBaselineProportionalBottom(QQuickText *item) @@ -3711,7 +3721,7 @@ static qreal expectedBaselineProportionalBottom(QQuickText *item) qreal dy = item->text().contains(QLatin1Char('\n')) ? 200 - (qCeil(fm.height()) * 3) : 200 - (qCeil(fm.height()) * 1.5); - return dy + fm.ascent(); + return dy + fm.ascent() - item->bottomPadding(); } void tst_qquicktext::baselineOffset_data() @@ -3818,6 +3828,102 @@ void tst_qquicktext::baselineOffset_data() << QByteArray("height: 200; lineHeightMode: Text.ProportionalHeight; lineHeight: 1.5; verticalAlignment: Text.AlignBottom") << &expectedBaselineProportionalBottom << &expectedBaselineProportionalBottom; + + QTest::newRow("top align with padding") + << "hello world" + << "hello\nworld" + << QByteArray("height: 200; topPadding: 10; bottomPadding: 20; verticalAlignment: Text.AlignTop") + << &expectedBaselineTop + << &expectedBaselineTop; + QTest::newRow("bottom align with padding") + << "hello world" + << "hello\nworld" + << QByteArray("height: 200; topPadding: 10; bottomPadding: 20; verticalAlignment: Text.AlignBottom") + << &expectedBaselineBottom + << &expectedBaselineBottom; + QTest::newRow("center align with padding") + << "hello world" + << "hello\nworld" + << QByteArray("height: 200; topPadding: 10; bottomPadding: 20; verticalAlignment: Text.AlignVCenter") + << &expectedBaselineCenter + << &expectedBaselineCenter; + + QTest::newRow("bold width padding") + << "<b>hello world</b>" + << "<b>hello<br/>world</b>" + << QByteArray("height: 200; topPadding: 10; bottomPadding: 20") + << &expectedBaselineTop + << &expectedBaselineBold; + + QTest::newRow("richText with padding") + << "<b>hello world</b>" + << "<b>hello<br/>world</b>" + << QByteArray("height: 200; topPadding: 10; bottomPadding: 20; textFormat: Text.RichText") + << &expectedBaselineTop + << &expectedBaselineTop; + + QTest::newRow("elided with padding") + << "hello world" + << "hello\nworld" + << QByteArray("width: 20; height: 8; topPadding: 10; bottomPadding: 20; elide: Text.ElideRight") + << &expectedBaselineTop + << &expectedBaselineTop; + + QTest::newRow("elided bottom align with padding") + << "hello world" + << "hello\nworld!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" + << QByteArray("width: 200; height: 200; topPadding: 10; bottomPadding: 20; elide: Text.ElideRight; verticalAlignment: Text.AlignBottom") + << &expectedBaselineBottom + << &expectedBaselineBottom; + + QTest::newRow("image with padding") + << "hello <img src=\"images/heart200.png\" /> world" + << "hello <img src=\"images/heart200.png\" /><br/>world" + << QByteArray("height: 200\n; topPadding: 10; bottomPadding: 20; baseUrl: \"") + testFileUrl("reference").toEncoded() + QByteArray("\"") + << &expectedBaselineImage + << &expectedBaselineTop; + + QTest::newRow("customLine with padding") + << "hello world" + << "hello\nworld" + << QByteArray("height: 200; topPadding: 10; bottomPadding: 20; onLineLaidOut: line.y += 16") + << &expectedBaselineCustom + << &expectedBaselineCustom; + + QTest::newRow("scaled font with padding") + << "hello world" + << "hello\nworld" + << QByteArray("width: 200; topPadding: 10; bottomPadding: 20; minimumPointSize: 1; font.pointSize: 64; fontSizeMode: Text.HorizontalFit") + << &expectedBaselineScaled + << &expectedBaselineTop; + + QTest::newRow("fixed line height top align with padding") + << "hello world" + << "hello\nworld" + << QByteArray("height: 200; topPadding: 10; bottomPadding: 20; lineHeightMode: Text.FixedHeight; lineHeight: 20; verticalAlignment: Text.AlignTop") + << &expectedBaselineTop + << &expectedBaselineTop; + + QTest::newRow("fixed line height bottom align with padding") + << "hello world" + << "hello\nworld" + << QByteArray("height: 200; topPadding: 10; bottomPadding: 20; lineHeightMode: Text.FixedHeight; lineHeight: 20; verticalAlignment: Text.AlignBottom") + << &expectedBaselineFixedBottom + << &expectedBaselineFixedBottom; + + QTest::newRow("proportional line height top align with padding") + << "hello world" + << "hello\nworld" + << QByteArray("height: 200; topPadding: 10; bottomPadding: 20; lineHeightMode: Text.ProportionalHeight; lineHeight: 1.5; verticalAlignment: Text.AlignTop") + << &expectedBaselineTop + << &expectedBaselineTop; + + QTest::newRow("proportional line height bottom align with padding") + << "hello world" + << "hello\nworld" + << QByteArray("height: 200; topPadding: 10; bottomPadding: 20; lineHeightMode: Text.ProportionalHeight; lineHeight: 1.5; verticalAlignment: Text.AlignBottom") + << &expectedBaselineProportionalBottom + << &expectedBaselineProportionalBottom; } void tst_qquicktext::baselineOffset() @@ -3830,7 +3936,7 @@ void tst_qquicktext::baselineOffset() QQmlComponent component(&engine); component.setData( - "import QtQuick 2.0\n" + "import QtQuick 2.6\n" "Text {\n" + bindings + "\n" "}", QUrl()); @@ -3972,6 +4078,84 @@ void tst_qquicktext::growFromZeroWidth() QVERIFY(text->lineCount() > 3); } +void tst_qquicktext::padding() +{ + QScopedPointer<QQuickView> window(new QQuickView); + window->setSource(testFileUrl("padding.qml")); + QTRY_COMPARE(window->status(), QQuickView::Ready); + window->show(); + QVERIFY(QTest::qWaitForWindowExposed(window.data())); + QQuickItem *root = window->rootObject(); + QVERIFY(root); + QQuickText *obj = qobject_cast<QQuickText*>(root); + QVERIFY(obj != 0); + + qreal cw = obj->contentWidth(); + qreal ch = obj->contentHeight(); + + QVERIFY(cw > 0); + QVERIFY(ch > 0); + + QCOMPARE(obj->topPadding(), 20.0); + QCOMPARE(obj->leftPadding(), 30.0); + QCOMPARE(obj->rightPadding(), 40.0); + QCOMPARE(obj->bottomPadding(), 50.0); + + QCOMPARE(obj->implicitWidth(), cw + obj->leftPadding() + obj->rightPadding()); + QCOMPARE(obj->implicitHeight(), ch + obj->topPadding() + obj->bottomPadding()); + + obj->setTopPadding(2.25); + QCOMPARE(obj->topPadding(), 2.25); + QCOMPARE(obj->implicitHeight(), ch + obj->topPadding() + obj->bottomPadding()); + + obj->setLeftPadding(3.75); + QCOMPARE(obj->leftPadding(), 3.75); + QCOMPARE(obj->implicitWidth(), cw + obj->leftPadding() + obj->rightPadding()); + + obj->setRightPadding(4.4); + QCOMPARE(obj->rightPadding(), 4.4); + QCOMPARE(obj->implicitWidth(), cw + obj->leftPadding() + obj->rightPadding()); + + obj->setBottomPadding(1.11); + QCOMPARE(obj->bottomPadding(), 1.11); + QCOMPARE(obj->implicitHeight(), ch + obj->topPadding() + obj->bottomPadding()); + + obj->setText("Qt"); + QVERIFY(obj->contentWidth() < cw); + QCOMPARE(obj->contentHeight(), ch); + cw = obj->contentWidth(); + + QCOMPARE(obj->implicitWidth(), cw + obj->leftPadding() + obj->rightPadding()); + QCOMPARE(obj->implicitHeight(), ch + obj->topPadding() + obj->bottomPadding()); + + obj->setFont(QFont("Courier", 96)); + QVERIFY(obj->contentWidth() > cw); + QVERIFY(obj->contentHeight() > ch); + cw = obj->contentWidth(); + ch = obj->contentHeight(); + + QCOMPARE(obj->implicitWidth(), cw + obj->leftPadding() + obj->rightPadding()); + QCOMPARE(obj->implicitHeight(), ch + obj->topPadding() + obj->bottomPadding()); + + obj->resetTopPadding(); + QCOMPARE(obj->topPadding(), 10.0); + obj->resetLeftPadding(); + QCOMPARE(obj->leftPadding(), 10.0); + obj->resetRightPadding(); + QCOMPARE(obj->rightPadding(), 10.0); + obj->resetBottomPadding(); + QCOMPARE(obj->bottomPadding(), 10.0); + + obj->resetPadding(); + QCOMPARE(obj->padding(), 0.0); + QCOMPARE(obj->topPadding(), 0.0); + QCOMPARE(obj->leftPadding(), 0.0); + QCOMPARE(obj->rightPadding(), 0.0); + QCOMPARE(obj->bottomPadding(), 0.0); + + delete root; +} + QTEST_MAIN(tst_qquicktext) #include "tst_qquicktext.moc" diff --git a/tests/auto/quick/qquicktextedit/BLACKLIST b/tests/auto/quick/qquicktextedit/BLACKLIST new file mode 100644 index 0000000000..492d81531a --- /dev/null +++ b/tests/auto/quick/qquicktextedit/BLACKLIST @@ -0,0 +1,2 @@ +[mouseSelection] +* diff --git a/tests/auto/quick/qquicktextedit/data/padding.qml b/tests/auto/quick/qquicktextedit/data/padding.qml new file mode 100644 index 0000000000..f4852bec8b --- /dev/null +++ b/tests/auto/quick/qquicktextedit/data/padding.qml @@ -0,0 +1,12 @@ +import QtQuick 2.6 + +TextEdit { + width: 200; height: 200 + text: "Hello Qt" + + padding: 10 + topPadding: 20 + leftPadding: 30 + rightPadding: 40 + bottomPadding: 50 +} diff --git a/tests/auto/quick/qquicktextedit/data/signal_editingfinished.qml b/tests/auto/quick/qquicktextedit/data/signal_editingfinished.qml new file mode 100644 index 0000000000..b5caab5e7c --- /dev/null +++ b/tests/auto/quick/qquicktextedit/data/signal_editingfinished.qml @@ -0,0 +1,13 @@ +import QtQuick 2.6 + +Item { + property QtObject input1: input1 + property QtObject input2: input2 + + width: 800; height: 600 + + Column{ + TextEdit { id: input1; activeFocusOnTab: true } + TextEdit { id: input2; activeFocusOnTab: true } + } +} diff --git a/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp b/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp index 9d1d099c0e..5ec8fa2e83 100644 --- a/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp +++ b/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp @@ -166,6 +166,8 @@ private slots: void implicitSizeBinding_data(); void implicitSizeBinding(); + void signal_editingfinished(); + void preeditCursorRectangle(); void inputMethodComposing(); void cursorRectangleSize_data(); @@ -200,6 +202,8 @@ private slots: void cursorRectangle_QTBUG_38947(); void textCached_QTBUG_41583(); + void padding(); + private: void simulateKeys(QWindow *window, const QList<Key> &keys); void simulateKeys(QWindow *window, const QKeySequence &sequence); @@ -573,7 +577,7 @@ void tst_qquicktextedit::textFormat() QQuickTextEdit *textObject = qobject_cast<QQuickTextEdit*>(textComponent.create()); QVERIFY(textObject != 0); - QVERIFY(textObject->textFormat() == QQuickTextEdit::RichText); + QCOMPARE(textObject->textFormat(), QQuickTextEdit::RichText); } { QQmlComponent textComponent(&engine); @@ -581,7 +585,7 @@ void tst_qquicktextedit::textFormat() QQuickTextEdit *textObject = qobject_cast<QQuickTextEdit*>(textComponent.create()); QVERIFY(textObject != 0); - QVERIFY(textObject->textFormat() == QQuickTextEdit::PlainText); + QCOMPARE(textObject->textFormat(), QQuickTextEdit::PlainText); } { QQmlComponent component(&engine); @@ -798,7 +802,7 @@ void tst_qquicktextedit::hAlign_RightToLeft() // keyboard input direction from qApp->inputMethod()->inputDirection textEdit->setText(""); platformInputContext.setInputDirection(Qt::LeftToRight); - QVERIFY(qApp->inputMethod()->inputDirection() == Qt::LeftToRight); + QCOMPARE(qApp->inputMethod()->inputDirection(), Qt::LeftToRight); QCOMPARE(textEdit->hAlign(), QQuickTextEdit::AlignLeft); QVERIFY(textEdit->positionToRectangle(0).x() < window.width()/2); @@ -806,7 +810,7 @@ void tst_qquicktextedit::hAlign_RightToLeft() platformInputContext.setInputDirection(Qt::RightToLeft); QCOMPARE(cursorRectangleSpy.count(), 1); - QVERIFY(qApp->inputMethod()->inputDirection() == Qt::RightToLeft); + QCOMPARE(qApp->inputMethod()->inputDirection(), Qt::RightToLeft); QCOMPARE(textEdit->hAlign(), QQuickTextEdit::AlignRight); QVERIFY(textEdit->positionToRectangle(0).x() > window.width()/2); @@ -1397,22 +1401,22 @@ void tst_qquicktextedit::selection() } textEditObject->setCursorPosition(0); - QVERIFY(textEditObject->cursorPosition() == 0); - QVERIFY(textEditObject->selectionStart() == 0); - QVERIFY(textEditObject->selectionEnd() == 0); + QCOMPARE(textEditObject->cursorPosition(), 0); + QCOMPARE(textEditObject->selectionStart(), 0); + QCOMPARE(textEditObject->selectionEnd(), 0); QVERIFY(textEditObject->selectedText().isNull()); // Verify invalid positions are ignored. textEditObject->setCursorPosition(-1); - QVERIFY(textEditObject->cursorPosition() == 0); - QVERIFY(textEditObject->selectionStart() == 0); - QVERIFY(textEditObject->selectionEnd() == 0); + QCOMPARE(textEditObject->cursorPosition(), 0); + QCOMPARE(textEditObject->selectionStart(), 0); + QCOMPARE(textEditObject->selectionEnd(), 0); QVERIFY(textEditObject->selectedText().isNull()); textEditObject->setCursorPosition(textEditObject->text().count()+1); - QVERIFY(textEditObject->cursorPosition() == 0); - QVERIFY(textEditObject->selectionStart() == 0); - QVERIFY(textEditObject->selectionEnd() == 0); + QCOMPARE(textEditObject->cursorPosition(), 0); + QCOMPARE(textEditObject->selectionStart(), 0); + QCOMPARE(textEditObject->selectionEnd(), 0); QVERIFY(textEditObject->selectedText().isNull()); //Test selection @@ -1426,9 +1430,9 @@ void tst_qquicktextedit::selection() } textEditObject->setCursorPosition(0); - QVERIFY(textEditObject->cursorPosition() == 0); - QVERIFY(textEditObject->selectionStart() == 0); - QVERIFY(textEditObject->selectionEnd() == 0); + QCOMPARE(textEditObject->cursorPosition(), 0); + QCOMPARE(textEditObject->selectionStart(), 0); + QCOMPARE(textEditObject->selectionEnd(), 0); QVERIFY(textEditObject->selectedText().isNull()); //Test Error Ignoring behaviour @@ -1443,20 +1447,20 @@ void tst_qquicktextedit::selection() textEditObject->select(0,100); QVERIFY(textEditObject->selectedText().isNull()); textEditObject->select(0,10); - QVERIFY(textEditObject->selectedText().size() == 10); + QCOMPARE(textEditObject->selectedText().size(), 10); textEditObject->select(-10,0); - QVERIFY(textEditObject->selectedText().size() == 10); + QCOMPARE(textEditObject->selectedText().size(), 10); textEditObject->select(100,101); - QVERIFY(textEditObject->selectedText().size() == 10); + QCOMPARE(textEditObject->selectedText().size(), 10); textEditObject->select(0,-10); - QVERIFY(textEditObject->selectedText().size() == 10); + QCOMPARE(textEditObject->selectedText().size(), 10); textEditObject->select(0,100); - QVERIFY(textEditObject->selectedText().size() == 10); + QCOMPARE(textEditObject->selectedText().size(), 10); textEditObject->deselect(); QVERIFY(textEditObject->selectedText().isNull()); textEditObject->select(0,10); - QVERIFY(textEditObject->selectedText().size() == 10); + QCOMPARE(textEditObject->selectedText().size(), 10); textEditObject->deselect(); QVERIFY(textEditObject->selectedText().isNull()); } @@ -1535,31 +1539,31 @@ void tst_qquicktextedit::keySelection() QSignalSpy spy(input, SIGNAL(selectedTextChanged())); simulateKey(&window, Qt::Key_Right, Qt::ShiftModifier); - QVERIFY(input->hasActiveFocus() == true); + QVERIFY(input->hasActiveFocus()); QCOMPARE(input->selectedText(), QString("a")); QCOMPARE(spy.count(), 1); simulateKey(&window, Qt::Key_Right); - QVERIFY(input->hasActiveFocus() == true); + QVERIFY(input->hasActiveFocus()); QCOMPARE(input->selectedText(), QString()); QCOMPARE(spy.count(), 2); simulateKey(&window, Qt::Key_Right); - QVERIFY(input->hasActiveFocus() == false); + QVERIFY(!input->hasActiveFocus()); QCOMPARE(input->selectedText(), QString()); QCOMPARE(spy.count(), 2); simulateKey(&window, Qt::Key_Left); - QVERIFY(input->hasActiveFocus() == true); + QVERIFY(input->hasActiveFocus()); QCOMPARE(spy.count(), 2); simulateKey(&window, Qt::Key_Left, Qt::ShiftModifier); - QVERIFY(input->hasActiveFocus() == true); + QVERIFY(input->hasActiveFocus()); QCOMPARE(input->selectedText(), QString("a")); QCOMPARE(spy.count(), 3); simulateKey(&window, Qt::Key_Left); - QVERIFY(input->hasActiveFocus() == true); + QVERIFY(input->hasActiveFocus()); QCOMPARE(input->selectedText(), QString()); QCOMPARE(spy.count(), 4); simulateKey(&window, Qt::Key_Left); - QVERIFY(input->hasActiveFocus() == false); + QVERIFY(!input->hasActiveFocus()); QCOMPARE(input->selectedText(), QString()); QCOMPARE(spy.count(), 4); } @@ -2786,17 +2790,17 @@ void tst_qquicktextedit::navigation() QQuickTextEdit *input = qobject_cast<QQuickTextEdit *>(qvariant_cast<QObject *>(window.rootObject()->property("myInput"))); QVERIFY(input != 0); - QTRY_VERIFY(input->hasActiveFocus() == true); + QTRY_VERIFY(input->hasActiveFocus()); simulateKey(&window, Qt::Key_Left); - QVERIFY(input->hasActiveFocus() == false); + QVERIFY(!input->hasActiveFocus()); simulateKey(&window, Qt::Key_Right); - QVERIFY(input->hasActiveFocus() == true); + QVERIFY(input->hasActiveFocus()); simulateKey(&window, Qt::Key_Right); - QVERIFY(input->hasActiveFocus() == true); + QVERIFY(input->hasActiveFocus()); simulateKey(&window, Qt::Key_Right); - QVERIFY(input->hasActiveFocus() == false); + QVERIFY(!input->hasActiveFocus()); simulateKey(&window, Qt::Key_Left); - QVERIFY(input->hasActiveFocus() == true); + QVERIFY(input->hasActiveFocus()); // Test left and right navigation works if the TextEdit is empty (QTBUG-25447). input->setText(QString()); @@ -2976,8 +2980,8 @@ void tst_qquicktextedit::readOnly() QQuickTextEdit *edit = qobject_cast<QQuickTextEdit *>(qvariant_cast<QObject *>(window.rootObject()->property("myInput"))); QVERIFY(edit != 0); - QTRY_VERIFY(edit->hasActiveFocus() == true); - QVERIFY(edit->isReadOnly() == true); + QTRY_VERIFY(edit->hasActiveFocus()); + QVERIFY(edit->isReadOnly()); QString initial = edit->text(); for (int k=Qt::Key_0; k<=Qt::Key_Z; k++) simulateKey(&window, k); @@ -3009,7 +3013,7 @@ void tst_qquicktextedit::textInput() QTest::qWaitForWindowActive(&view); QQuickTextEdit *edit = qobject_cast<QQuickTextEdit *>(view.rootObject()); QVERIFY(edit); - QVERIFY(edit->hasActiveFocus() == true); + QVERIFY(edit->hasActiveFocus()); // test that input method event is committed and change signal is emitted QSignalSpy spy(edit, SIGNAL(textChanged())); @@ -3045,7 +3049,7 @@ void tst_qquicktextedit::inputMethodUpdate() QTest::qWaitForWindowActive(&view); QQuickTextEdit *edit = qobject_cast<QQuickTextEdit *>(view.rootObject()); QVERIFY(edit); - QVERIFY(edit->hasActiveFocus() == true); + QVERIFY(edit->hasActiveFocus()); // text change even without cursor position change needs to trigger update edit->setText("test"); @@ -3219,15 +3223,15 @@ void tst_qquicktextedit::pastingRichText_QTBUG_14003() QQuickTextEdit *obj = qobject_cast<QQuickTextEdit*>(component.create()); QTRY_VERIFY(obj != 0); - QTRY_VERIFY(obj->textFormat() == QQuickTextEdit::PlainText); + QTRY_COMPARE(obj->textFormat(), QQuickTextEdit::PlainText); QMimeData *mData = new QMimeData; mData->setHtml("<font color=\"red\">Hello</font>"); QGuiApplication::clipboard()->setMimeData(mData); obj->paste(); - QTRY_VERIFY(obj->text() == ""); - QTRY_VERIFY(obj->textFormat() == QQuickTextEdit::PlainText); + QTRY_COMPARE(obj->text(), QString()); + QTRY_COMPARE(obj->textFormat(), QQuickTextEdit::PlainText); } #endif @@ -3253,11 +3257,11 @@ void tst_qquicktextedit::implicitSize() QQuickTextEdit *textObject = qobject_cast<QQuickTextEdit*>(textComponent.create()); QVERIFY(textObject->width() < textObject->implicitWidth()); - QVERIFY(textObject->height() == textObject->implicitHeight()); + QCOMPARE(textObject->height(), textObject->implicitHeight()); textObject->resetWidth(); - QVERIFY(textObject->width() == textObject->implicitWidth()); - QVERIFY(textObject->height() == textObject->implicitHeight()); + QCOMPARE(textObject->width(), textObject->implicitWidth()); + QCOMPARE(textObject->height(), textObject->implicitHeight()); } void tst_qquicktextedit::contentSize() @@ -3316,6 +3320,53 @@ void tst_qquicktextedit::implicitSizeBinding() QCOMPARE(textObject->height(), textObject->implicitHeight()); } +void tst_qquicktextedit::signal_editingfinished() +{ + QQuickView *window = new QQuickView(0); + window->setBaseSize(QSize(800,600)); + + window->setSource(testFileUrl("signal_editingfinished.qml")); + window->show(); + window->requestActivate(); + QVERIFY(QTest::qWaitForWindowActive(window)); + QCOMPARE(QGuiApplication::focusWindow(), window); + + QVERIFY(window->rootObject() != 0); + + QQuickTextEdit *input1 = qobject_cast<QQuickTextEdit *>(qvariant_cast<QObject *>(window->rootObject()->property("input1"))); + QVERIFY(input1); + QQuickTextEdit *input2 = qobject_cast<QQuickTextEdit *>(qvariant_cast<QObject *>(window->rootObject()->property("input2"))); + QVERIFY(input2); + + QSignalSpy editingFinished1Spy(input1, SIGNAL(editingFinished())); + + input1->setFocus(true); + QTRY_VERIFY(input1->hasActiveFocus()); + QTRY_VERIFY(!input2->hasActiveFocus()); + + QKeyEvent key(QEvent::KeyPress, Qt::Key_Tab, Qt::ShiftModifier, "", false, 1); + QGuiApplication::sendEvent(window, &key); + QVERIFY(key.isAccepted()); + QTRY_COMPARE(editingFinished1Spy.count(), 1); + + QTRY_VERIFY(!input1->hasActiveFocus()); + QTRY_VERIFY(input2->hasActiveFocus()); + + QSignalSpy editingFinished2Spy(input2, SIGNAL(editingFinished())); + + input2->setFocus(true); + QTRY_VERIFY(!input1->hasActiveFocus()); + QTRY_VERIFY(input2->hasActiveFocus()); + + key = QKeyEvent(QEvent::KeyPress, Qt::Key_Tab, Qt::ShiftModifier, "", false, 1); + QGuiApplication::sendEvent(window, &key); + QVERIFY(key.isAccepted()); + QTRY_COMPARE(editingFinished2Spy.count(), 1); + + QTRY_VERIFY(input1->hasActiveFocus()); + QTRY_VERIFY(!input2->hasActiveFocus()); +} + void tst_qquicktextedit::clipRect() { QQmlComponent component(&engine); @@ -5323,6 +5374,84 @@ void tst_qquicktextedit::textCached_QTBUG_41583() QVERIFY(!textedit->property("empty").toBool()); } +void tst_qquicktextedit::padding() +{ + QScopedPointer<QQuickView> window(new QQuickView); + window->setSource(testFileUrl("padding.qml")); + QTRY_COMPARE(window->status(), QQuickView::Ready); + window->show(); + QVERIFY(QTest::qWaitForWindowExposed(window.data())); + QQuickItem *root = window->rootObject(); + QVERIFY(root); + QQuickTextEdit *obj = qobject_cast<QQuickTextEdit*>(root); + QVERIFY(obj != 0); + + qreal cw = obj->contentWidth(); + qreal ch = obj->contentHeight(); + + QVERIFY(cw > 0); + QVERIFY(ch > 0); + + QCOMPARE(obj->topPadding(), 20.0); + QCOMPARE(obj->leftPadding(), 30.0); + QCOMPARE(obj->rightPadding(), 40.0); + QCOMPARE(obj->bottomPadding(), 50.0); + + QCOMPARE(obj->implicitWidth(), cw + obj->leftPadding() + obj->rightPadding()); + QCOMPARE(obj->implicitHeight(), ch + obj->topPadding() + obj->bottomPadding()); + + obj->setTopPadding(2.25); + QCOMPARE(obj->topPadding(), 2.25); + QCOMPARE(obj->implicitHeight(), ch + obj->topPadding() + obj->bottomPadding()); + + obj->setLeftPadding(3.75); + QCOMPARE(obj->leftPadding(), 3.75); + QCOMPARE(obj->implicitWidth(), cw + obj->leftPadding() + obj->rightPadding()); + + obj->setRightPadding(4.4); + QCOMPARE(obj->rightPadding(), 4.4); + QCOMPARE(obj->implicitWidth(), cw + obj->leftPadding() + obj->rightPadding()); + + obj->setBottomPadding(1.11); + QCOMPARE(obj->bottomPadding(), 1.11); + QCOMPARE(obj->implicitHeight(), ch + obj->topPadding() + obj->bottomPadding()); + + obj->setText("Qt"); + QVERIFY(obj->contentWidth() < cw); + QCOMPARE(obj->contentHeight(), ch); + cw = obj->contentWidth(); + + QCOMPARE(obj->implicitWidth(), cw + obj->leftPadding() + obj->rightPadding()); + QCOMPARE(obj->implicitHeight(), ch + obj->topPadding() + obj->bottomPadding()); + + obj->setFont(QFont("Courier", 96)); + QVERIFY(obj->contentWidth() > cw); + QVERIFY(obj->contentHeight() > ch); + cw = obj->contentWidth(); + ch = obj->contentHeight(); + + QCOMPARE(obj->implicitWidth(), cw + obj->leftPadding() + obj->rightPadding()); + QCOMPARE(obj->implicitHeight(), ch + obj->topPadding() + obj->bottomPadding()); + + obj->resetTopPadding(); + QCOMPARE(obj->topPadding(), 10.0); + obj->resetLeftPadding(); + QCOMPARE(obj->leftPadding(), 10.0); + obj->resetRightPadding(); + QCOMPARE(obj->rightPadding(), 10.0); + obj->resetBottomPadding(); + QCOMPARE(obj->bottomPadding(), 10.0); + + obj->resetPadding(); + QCOMPARE(obj->padding(), 0.0); + QCOMPARE(obj->topPadding(), 0.0); + QCOMPARE(obj->leftPadding(), 0.0); + QCOMPARE(obj->rightPadding(), 0.0); + QCOMPARE(obj->bottomPadding(), 0.0); + + delete root; +} + QTEST_MAIN(tst_qquicktextedit) #include "tst_qquicktextedit.moc" diff --git a/tests/auto/quick/qquicktextinput/data/padding.qml b/tests/auto/quick/qquicktextinput/data/padding.qml new file mode 100644 index 0000000000..23bfe20f22 --- /dev/null +++ b/tests/auto/quick/qquicktextinput/data/padding.qml @@ -0,0 +1,12 @@ +import QtQuick 2.6 + +TextInput { + width: 200; height: 200 + text: "Hello Qt" + + padding: 10 + topPadding: 20 + leftPadding: 30 + rightPadding: 40 + bottomPadding: 50 +} diff --git a/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp b/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp index d87054ac9e..079f73ae34 100644 --- a/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp +++ b/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp @@ -45,6 +45,7 @@ #include <QInputMethod> #include <private/qquicktextinput_p.h> #include <private/qquicktextinput_p_p.h> +#include <private/qquickvalidator_p.h> #include <QDebug> #include <QDir> #include <math.h> @@ -222,6 +223,7 @@ private slots: void baselineOffset(); void ensureVisible(); + void padding(); private: void simulateKey(QWindow *, int key); @@ -591,7 +593,7 @@ void tst_qquicktextinput::wrap() textHeight = textObject->height(); QVERIFY(textObject != 0); - QVERIFY(textObject->wrapMode() == QQuickTextInput::WrapAnywhere); + QCOMPARE(textObject->wrapMode(), QQuickTextInput::WrapAnywhere); QCOMPARE(textObject->width(), 300.); delete textObject; @@ -658,22 +660,22 @@ void tst_qquicktextinput::selection() } textinputObject->setCursorPosition(0); - QVERIFY(textinputObject->cursorPosition() == 0); - QVERIFY(textinputObject->selectionStart() == 0); - QVERIFY(textinputObject->selectionEnd() == 0); + QCOMPARE(textinputObject->cursorPosition(), 0); + QCOMPARE(textinputObject->selectionStart(), 0); + QCOMPARE(textinputObject->selectionEnd(), 0); QVERIFY(textinputObject->selectedText().isNull()); // Verify invalid positions are ignored. textinputObject->setCursorPosition(-1); - QVERIFY(textinputObject->cursorPosition() == 0); - QVERIFY(textinputObject->selectionStart() == 0); - QVERIFY(textinputObject->selectionEnd() == 0); + QCOMPARE(textinputObject->cursorPosition(), 0); + QCOMPARE(textinputObject->selectionStart(), 0); + QCOMPARE(textinputObject->selectionEnd(), 0); QVERIFY(textinputObject->selectedText().isNull()); textinputObject->setCursorPosition(textinputObject->text().count()+1); - QVERIFY(textinputObject->cursorPosition() == 0); - QVERIFY(textinputObject->selectionStart() == 0); - QVERIFY(textinputObject->selectionEnd() == 0); + QCOMPARE(textinputObject->cursorPosition(), 0); + QCOMPARE(textinputObject->selectionStart(), 0); + QCOMPARE(textinputObject->selectionEnd(), 0); QVERIFY(textinputObject->selectedText().isNull()); //Test selection @@ -687,9 +689,9 @@ void tst_qquicktextinput::selection() } textinputObject->setCursorPosition(0); - QVERIFY(textinputObject->cursorPosition() == 0); - QVERIFY(textinputObject->selectionStart() == 0); - QVERIFY(textinputObject->selectionEnd() == 0); + QCOMPARE(textinputObject->cursorPosition(), 0); + QCOMPARE(textinputObject->selectionStart(), 0); + QCOMPARE(textinputObject->selectionEnd(), 0); QVERIFY(textinputObject->selectedText().isNull()); //Test Error Ignoring behaviour @@ -704,20 +706,20 @@ void tst_qquicktextinput::selection() textinputObject->select(0,100); QVERIFY(textinputObject->selectedText().isNull()); textinputObject->select(0,10); - QVERIFY(textinputObject->selectedText().size() == 10); + QCOMPARE(textinputObject->selectedText().size(), 10); textinputObject->select(-10,10); - QVERIFY(textinputObject->selectedText().size() == 10); + QCOMPARE(textinputObject->selectedText().size(), 10); textinputObject->select(100,101); - QVERIFY(textinputObject->selectedText().size() == 10); + QCOMPARE(textinputObject->selectedText().size(), 10); textinputObject->select(0,-10); - QVERIFY(textinputObject->selectedText().size() == 10); + QCOMPARE(textinputObject->selectedText().size(), 10); textinputObject->select(0,100); - QVERIFY(textinputObject->selectedText().size() == 10); + QCOMPARE(textinputObject->selectedText().size(), 10); textinputObject->deselect(); QVERIFY(textinputObject->selectedText().isNull()); textinputObject->select(0,10); - QVERIFY(textinputObject->selectedText().size() == 10); + QCOMPARE(textinputObject->selectedText().size(), 10); textinputObject->deselect(); QVERIFY(textinputObject->selectedText().isNull()); @@ -1513,13 +1515,13 @@ void tst_qquicktextinput::horizontalAlignment_RightToLeft() // keyboard input direction from QInputMethod::inputDirection() textInput->setText(""); platformInputContext.setInputDirection(Qt::LeftToRight); - QVERIFY(qApp->inputMethod()->inputDirection() == Qt::LeftToRight); + QCOMPARE(qApp->inputMethod()->inputDirection(), Qt::LeftToRight); QCOMPARE(textInput->hAlign(), QQuickTextInput::AlignLeft); QCOMPARE(textInput->boundingRect().left(), qreal(0)); QSignalSpy cursorRectangleSpy(textInput, SIGNAL(cursorRectangleChanged())); platformInputContext.setInputDirection(Qt::RightToLeft); - QVERIFY(qApp->inputMethod()->inputDirection() == Qt::RightToLeft); + QCOMPARE(qApp->inputMethod()->inputDirection(), Qt::RightToLeft); QCOMPARE(cursorRectangleSpy.count(), 1); QCOMPARE(textInput->hAlign(), QQuickTextInput::AlignRight); QVERIFY(textInput->boundingRect().right() >= textInput->width() - 1); @@ -1853,7 +1855,7 @@ void tst_qquicktextinput::maxLength() QQuickTextInput *textinputObject = qobject_cast<QQuickTextInput *>(window.rootObject()); QVERIFY(textinputObject != 0); QVERIFY(textinputObject->text().isEmpty()); - QVERIFY(textinputObject->maxLength() == 10); + QCOMPARE(textinputObject->maxLength(), 10); foreach (const QString &str, standard) { QVERIFY(textinputObject->text().length() <= 10); textinputObject->setText(str); @@ -1861,7 +1863,7 @@ void tst_qquicktextinput::maxLength() } textinputObject->setText(""); - QTRY_VERIFY(textinputObject->hasActiveFocus() == true); + QTRY_VERIFY(textinputObject->hasActiveFocus()); for (int i=0; i<20; i++) { QTRY_COMPARE(textinputObject->text().length(), qMin(i,10)); //simulateKey(&window, Qt::Key_A); @@ -1880,8 +1882,8 @@ void tst_qquicktextinput::masks() QVERIFY(window.rootObject() != 0); QQuickTextInput *textinputObject = qobject_cast<QQuickTextInput *>(window.rootObject()); QVERIFY(textinputObject != 0); - QTRY_VERIFY(textinputObject->hasActiveFocus() == true); - QVERIFY(textinputObject->text().length() == 0); + QTRY_VERIFY(textinputObject->hasActiveFocus()); + QCOMPARE(textinputObject->text().length(), 0); QCOMPARE(textinputObject->inputMask(), QString("HHHHhhhh; ")); QCOMPARE(textinputObject->length(), 8); for (int i=0; i<10; i++) { @@ -1997,7 +1999,7 @@ void tst_qquicktextinput::validators() QCOMPARE(dblInput->validator()->locale(), defaultLocale); dblInput->setFocus(true); - QVERIFY(dblInput->hasActiveFocus() == true); + QVERIFY(dblInput->hasActiveFocus()); QCOMPARE(dblInput->hasAcceptableInput(), false); QCOMPARE(dblInput->property("acceptable").toBool(), false); QTest::keyPress(&window, Qt::Key_1); @@ -2131,7 +2133,7 @@ void tst_qquicktextinput::validators() QVERIFY(strInput); QSignalSpy strSpy(strInput, SIGNAL(acceptableInputChanged())); strInput->setFocus(true); - QVERIFY(strInput->hasActiveFocus() == true); + QVERIFY(strInput->hasActiveFocus()); QCOMPARE(strInput->hasAcceptableInput(), false); QCOMPARE(strInput->property("acceptable").toBool(), false); QTest::keyPress(&window, Qt::Key_1); @@ -2175,7 +2177,7 @@ void tst_qquicktextinput::validators() QVERIFY(unvalidatedInput); QSignalSpy unvalidatedSpy(unvalidatedInput, SIGNAL(acceptableInputChanged())); unvalidatedInput->setFocus(true); - QVERIFY(unvalidatedInput->hasActiveFocus() == true); + QVERIFY(unvalidatedInput->hasActiveFocus()); QCOMPARE(unvalidatedInput->hasAcceptableInput(), true); QCOMPARE(unvalidatedInput->property("acceptable").toBool(), true); QTest::keyPress(&window, Qt::Key_1); @@ -2216,7 +2218,7 @@ void tst_qquicktextinput::inputMethods() QCOMPARE(plainInput.inputMethodHints(), Qt::ImhNone); input->setFocus(true); - QVERIFY(input->hasActiveFocus() == true); + QVERIFY(input->hasActiveFocus()); // test that input method event is committed QInputMethodEvent event; event.setCommitString( "My ", -12, 0); @@ -2399,23 +2401,23 @@ void tst_qquicktextinput::navigation() QVERIFY(input != 0); input->setCursorPosition(0); - QTRY_VERIFY(input->hasActiveFocus() == true); + QTRY_VERIFY(input->hasActiveFocus()); simulateKey(&window, Qt::Key_Left); - QVERIFY(input->hasActiveFocus() == false); + QVERIFY(!input->hasActiveFocus()); simulateKey(&window, Qt::Key_Right); - QVERIFY(input->hasActiveFocus() == true); + QVERIFY(input->hasActiveFocus()); //QT-2944: If text is selected, ensure we deselect upon cursor motion input->setCursorPosition(input->text().length()); input->select(0,input->text().length()); QVERIFY(input->selectionStart() != input->selectionEnd()); simulateKey(&window, Qt::Key_Right); - QVERIFY(input->selectionStart() == input->selectionEnd()); - QVERIFY(input->selectionStart() == input->text().length()); - QVERIFY(input->hasActiveFocus() == true); + QCOMPARE(input->selectionStart(), input->selectionEnd()); + QCOMPARE(input->selectionStart(), input->text().length()); + QVERIFY(input->hasActiveFocus()); simulateKey(&window, Qt::Key_Right); - QVERIFY(input->hasActiveFocus() == false); + QVERIFY(!input->hasActiveFocus()); simulateKey(&window, Qt::Key_Left); - QVERIFY(input->hasActiveFocus() == true); + QVERIFY(input->hasActiveFocus()); // Up and Down should NOT do Home/End, even on OS X (QTBUG-10438). input->setCursorPosition(2); @@ -2451,26 +2453,26 @@ void tst_qquicktextinput::navigation_RTL() input->setText(QString::fromUtf16(arabic_str, 11)); input->setCursorPosition(0); - QTRY_VERIFY(input->hasActiveFocus() == true); + QTRY_VERIFY(input->hasActiveFocus()); // move off simulateKey(&window, Qt::Key_Right); - QVERIFY(input->hasActiveFocus() == false); + QVERIFY(!input->hasActiveFocus()); // move back simulateKey(&window, Qt::Key_Left); - QVERIFY(input->hasActiveFocus() == true); + QVERIFY(input->hasActiveFocus()); input->setCursorPosition(input->text().length()); - QVERIFY(input->hasActiveFocus() == true); + QVERIFY(input->hasActiveFocus()); // move off simulateKey(&window, Qt::Key_Left); - QVERIFY(input->hasActiveFocus() == false); + QVERIFY(!input->hasActiveFocus()); // move back simulateKey(&window, Qt::Key_Right); - QVERIFY(input->hasActiveFocus() == true); + QVERIFY(input->hasActiveFocus()); } #ifndef QT_NO_CLIPBOARD @@ -2996,6 +2998,14 @@ void tst_qquicktextinput::cursorRectangle_data() << false; } +#ifndef QT_NO_IM +#define COMPARE_INPUT_METHOD_QUERY(type, input, property, method, result) \ + QCOMPARE((type) input->inputMethodQuery(property).method(), result); +#else +#define COMPARE_INPUT_METHOD_QUERY(type, input, property, method, result) \ + qt_noop() +#endif + void tst_qquicktextinput::cursorRectangle() { QFETCH(QString, text); @@ -3035,7 +3045,7 @@ void tst_qquicktextinput::cursorRectangle() r = input.cursorRectangle(); QCOMPARE(r.left(), line.cursorToX(i, QTextLine::Leading) - offset); - QCOMPARE(input.inputMethodQuery(Qt::ImCursorRectangle).toRectF(), r); + COMPARE_INPUT_METHOD_QUERY(QRectF, (&input), Qt::ImCursorRectangle, toRectF, r); QCOMPARE(input.positionToRectangle(i), r); } @@ -3045,7 +3055,7 @@ void tst_qquicktextinput::cursorRectangle() for (int i = positionAtWidth + 1; i < text.length(); ++i) { input.setCursorPosition(i); QCOMPARE(r, input.cursorRectangle()); - QCOMPARE(input.inputMethodQuery(Qt::ImCursorRectangle).toRectF(), r); + COMPARE_INPUT_METHOD_QUERY(QRectF, (&input), Qt::ImCursorRectangle, toRectF, r); QCOMPARE(input.positionToRectangle(i), r); } @@ -3058,7 +3068,7 @@ void tst_qquicktextinput::cursorRectangle() } else { QVERIFY(r.left() <= input.width()); } - QCOMPARE(input.inputMethodQuery(Qt::ImCursorRectangle).toRectF(), r); + COMPARE_INPUT_METHOD_QUERY(QRectF, (&input), Qt::ImCursorRectangle, toRectF, r); QCOMPARE(input.positionToRectangle(i), r); } @@ -3071,7 +3081,7 @@ void tst_qquicktextinput::cursorRectangle() QCOMPARE(r.left(), line.cursorToX(i, QTextLine::Leading) - offset); QCOMPARE(r.top(), 0.); - QCOMPARE(input.inputMethodQuery(Qt::ImCursorRectangle).toRectF(), r); + COMPARE_INPUT_METHOD_QUERY(QRectF, (&input), Qt::ImCursorRectangle, toRectF, r); QCOMPARE(input.positionToRectangle(i), r); } @@ -3083,14 +3093,14 @@ void tst_qquicktextinput::cursorRectangle() QCOMPARE(r.left(), input.width()); } QVERIFY(r.top() >= line.height() - 1); - QCOMPARE(input.inputMethodQuery(Qt::ImCursorRectangle).toRectF(), r); + COMPARE_INPUT_METHOD_QUERY(QRectF, (&input), Qt::ImCursorRectangle, toRectF, r); QCOMPARE(input.positionToRectangle(11), r); for (int i = wrapPosition + 1; i < text.length(); ++i) { input.setCursorPosition(i); r = input.cursorRectangle(); QVERIFY(r.top() >= line.height() - 1); - QCOMPARE(input.inputMethodQuery(Qt::ImCursorRectangle).toRectF(), r); + COMPARE_INPUT_METHOD_QUERY(QRectF, (&input), Qt::ImCursorRectangle, toRectF, r); QCOMPARE(input.positionToRectangle(i), r); } @@ -3102,7 +3112,7 @@ void tst_qquicktextinput::cursorRectangle() QCOMPARE(r.left(), line.cursorToX(i, QTextLine::Leading) - offset); QCOMPARE(r.top(), 0.); - QCOMPARE(input.inputMethodQuery(Qt::ImCursorRectangle).toRectF(), r); + COMPARE_INPUT_METHOD_QUERY(QRectF, (&input), Qt::ImCursorRectangle, toRectF, r); QCOMPARE(input.positionToRectangle(i), r); } @@ -3112,7 +3122,7 @@ void tst_qquicktextinput::cursorRectangle() for (int i = positionAtWidth + 1; i < wrapPosition && leftToRight; ++i) { input.setCursorPosition(i); QCOMPARE(r, input.cursorRectangle()); - QCOMPARE(input.inputMethodQuery(Qt::ImCursorRectangle).toRectF(), r); + COMPARE_INPUT_METHOD_QUERY(QRectF, (&input), Qt::ImCursorRectangle, toRectF, r); QCOMPARE(input.positionToRectangle(i), r); } @@ -3124,14 +3134,14 @@ void tst_qquicktextinput::cursorRectangle() QCOMPARE(r.left(), input.width()); } QVERIFY(r.bottom() >= input.height()); - QCOMPARE(input.inputMethodQuery(Qt::ImCursorRectangle).toRectF(), r); + COMPARE_INPUT_METHOD_QUERY(QRectF, (&input), Qt::ImCursorRectangle, toRectF, r); QCOMPARE(input.positionToRectangle(11), r); for (int i = wrapPosition + 1; i < text.length(); ++i) { input.setCursorPosition(i); r = input.cursorRectangle(); QVERIFY(r.bottom() >= input.height()); - QCOMPARE(input.inputMethodQuery(Qt::ImCursorRectangle).toRectF(), r); + COMPARE_INPUT_METHOD_QUERY(QRectF, (&input), Qt::ImCursorRectangle, toRectF, r); QCOMPARE(input.positionToRectangle(i), r); } @@ -3139,7 +3149,7 @@ void tst_qquicktextinput::cursorRectangle() input.setCursorPosition(i); r = input.cursorRectangle(); QVERIFY(r.bottom() >= input.height()); - QCOMPARE(input.inputMethodQuery(Qt::ImCursorRectangle).toRectF(), r); + COMPARE_INPUT_METHOD_QUERY(QRectF, (&input), Qt::ImCursorRectangle, toRectF, r); QCOMPARE(input.positionToRectangle(i), r); } @@ -3147,13 +3157,13 @@ void tst_qquicktextinput::cursorRectangle() r = input.cursorRectangle(); QCOMPARE(r.top(), 0.); QCOMPARE(r.left(), leftToRight ? input.width() : 0); - QCOMPARE(input.inputMethodQuery(Qt::ImCursorRectangle).toRectF(), r); + COMPARE_INPUT_METHOD_QUERY(QRectF, (&input), Qt::ImCursorRectangle, toRectF, r); QCOMPARE(input.positionToRectangle(10), r); for (int i = wrapPosition - 2; i >= positionAtWidth + 1; --i) { input.setCursorPosition(i); QCOMPARE(r, input.cursorRectangle()); - QCOMPARE(input.inputMethodQuery(Qt::ImCursorRectangle).toRectF(), r); + COMPARE_INPUT_METHOD_QUERY(QRectF, (&input), Qt::ImCursorRectangle, toRectF, r); QCOMPARE(input.positionToRectangle(i), r); } @@ -3161,7 +3171,7 @@ void tst_qquicktextinput::cursorRectangle() input.setCursorPosition(i); r = input.cursorRectangle(); QCOMPARE(r.top(), 0.); - QCOMPARE(input.inputMethodQuery(Qt::ImCursorRectangle).toRectF(), r); + COMPARE_INPUT_METHOD_QUERY(QRectF, (&input), Qt::ImCursorRectangle, toRectF, r); QCOMPARE(input.positionToRectangle(i), r); } @@ -3190,9 +3200,9 @@ void tst_qquicktextinput::readOnly() QQuickTextInput *input = qobject_cast<QQuickTextInput *>(qvariant_cast<QObject *>(window.rootObject()->property("myInput"))); QVERIFY(input != 0); - QTRY_VERIFY(input->hasActiveFocus() == true); - QVERIFY(input->isReadOnly() == true); - QVERIFY(input->isCursorVisible() == false); + QTRY_VERIFY(input->hasActiveFocus()); + QVERIFY(input->isReadOnly()); + QVERIFY(!input->isCursorVisible()); QString initial = input->text(); for (int k=Qt::Key_0; k<=Qt::Key_Z; k++) simulateKey(&window, k); @@ -3205,7 +3215,7 @@ void tst_qquicktextinput::readOnly() input->setReadOnly(false); QCOMPARE(input->isReadOnly(), false); QCOMPARE(input->cursorPosition(), input->text().length()); - QVERIFY(input->isCursorVisible() == true); + QVERIFY(input->isCursorVisible()); } void tst_qquicktextinput::echoMode() @@ -3220,7 +3230,7 @@ void tst_qquicktextinput::echoMode() QQuickTextInput *input = qobject_cast<QQuickTextInput *>(qvariant_cast<QObject *>(window.rootObject()->property("myInput"))); QVERIFY(input != 0); - QTRY_VERIFY(input->hasActiveFocus() == true); + QTRY_VERIFY(input->hasActiveFocus()); QString initial = input->text(); Qt::InputMethodHints ref; QCOMPARE(initial, QLatin1String("ABCDefgh")); @@ -3230,7 +3240,7 @@ void tst_qquicktextinput::echoMode() //Normal ref &= ~Qt::ImhHiddenText; ref &= ~(Qt::ImhNoAutoUppercase | Qt::ImhNoPredictiveText | Qt::ImhSensitiveData); - QCOMPARE((Qt::InputMethodHints) input->inputMethodQuery(Qt::ImHints).toInt(), ref); + COMPARE_INPUT_METHOD_QUERY(Qt::InputMethodHints, input, Qt::ImHints, toInt, ref); input->setEchoMode(QQuickTextInput::NoEcho); QCOMPARE(input->text(), initial); QCOMPARE(input->displayText(), QLatin1String("")); @@ -3238,17 +3248,17 @@ void tst_qquicktextinput::echoMode() //NoEcho ref |= Qt::ImhHiddenText; ref |= (Qt::ImhNoAutoUppercase | Qt::ImhNoPredictiveText | Qt::ImhSensitiveData); - QCOMPARE((Qt::InputMethodHints) input->inputMethodQuery(Qt::ImHints).toInt(), ref); + COMPARE_INPUT_METHOD_QUERY(Qt::InputMethodHints, input, Qt::ImHints, toInt, ref); input->setEchoMode(QQuickTextInput::Password); //Password ref |= Qt::ImhHiddenText; ref |= (Qt::ImhNoAutoUppercase | Qt::ImhNoPredictiveText | Qt::ImhSensitiveData); QCOMPARE(input->text(), initial); QCOMPARE(input->displayText(), QString(8, passwordMaskCharacter.at(0))); - QCOMPARE((Qt::InputMethodHints) input->inputMethodQuery(Qt::ImHints).toInt(), ref); + COMPARE_INPUT_METHOD_QUERY(Qt::InputMethodHints, input, Qt::ImHints, toInt, ref); // clearing input hints do not clear bits set by echo mode input->setInputMethodHints(Qt::ImhNone); - QCOMPARE((Qt::InputMethodHints) input->inputMethodQuery(Qt::ImHints).toInt(), ref); + COMPARE_INPUT_METHOD_QUERY(Qt::InputMethodHints, input, Qt::ImHints, toInt, ref); input->setPasswordCharacter(QChar('Q')); QCOMPARE(input->passwordCharacter(), QLatin1String("Q")); QCOMPARE(input->text(), initial); @@ -3257,19 +3267,20 @@ void tst_qquicktextinput::echoMode() //PasswordEchoOnEdit ref &= ~Qt::ImhHiddenText; ref |= (Qt::ImhNoAutoUppercase | Qt::ImhNoPredictiveText | Qt::ImhSensitiveData); - QCOMPARE((Qt::InputMethodHints) input->inputMethodQuery(Qt::ImHints).toInt(), ref); + COMPARE_INPUT_METHOD_QUERY(Qt::InputMethodHints, input, Qt::ImHints, toInt, ref); QCOMPARE(input->text(), initial); QCOMPARE(input->displayText(), QLatin1String("QQQQQQQQ")); - QCOMPARE(input->inputMethodQuery(Qt::ImSurroundingText).toString(), QLatin1String("QQQQQQQQ")); + COMPARE_INPUT_METHOD_QUERY(QString, input, Qt::ImSurroundingText, toString, + QLatin1String("QQQQQQQQ")); QTest::keyPress(&window, Qt::Key_A);//Clearing previous entry is part of PasswordEchoOnEdit QTest::keyRelease(&window, Qt::Key_A, Qt::NoModifier ,10); QCOMPARE(input->text(), QLatin1String("a")); QCOMPARE(input->displayText(), QLatin1String("a")); - QCOMPARE(input->inputMethodQuery(Qt::ImSurroundingText).toString(), QLatin1String("a")); + COMPARE_INPUT_METHOD_QUERY(QString, input, Qt::ImSurroundingText, toString, QLatin1String("a")); input->setFocus(false); - QVERIFY(input->hasActiveFocus() == false); + QVERIFY(!input->hasActiveFocus()); QCOMPARE(input->displayText(), QLatin1String("Q")); - QCOMPARE(input->inputMethodQuery(Qt::ImSurroundingText).toString(), QLatin1String("Q")); + COMPARE_INPUT_METHOD_QUERY(QString, input, Qt::ImSurroundingText, toString, QLatin1String("Q")); input->setFocus(true); QVERIFY(input->hasActiveFocus()); QInputMethodEvent inputEvent; @@ -3277,7 +3288,7 @@ void tst_qquicktextinput::echoMode() QGuiApplication::sendEvent(input, &inputEvent); QCOMPARE(input->text(), initial); QCOMPARE(input->displayText(), initial); - QCOMPARE(input->inputMethodQuery(Qt::ImSurroundingText).toString(), initial); + COMPARE_INPUT_METHOD_QUERY(QString, input, Qt::ImSurroundingText, toString, initial); } void tst_qquicktextinput::passwordEchoDelay() @@ -5819,11 +5830,11 @@ void tst_qquicktextinput::implicitSize() QQuickTextInput *textObject = qobject_cast<QQuickTextInput*>(textComponent.create()); QVERIFY(textObject->width() < textObject->implicitWidth()); - QVERIFY(textObject->height() == textObject->implicitHeight()); + QCOMPARE(textObject->height(), textObject->implicitHeight()); textObject->resetWidth(); - QVERIFY(textObject->width() == textObject->implicitWidth()); - QVERIFY(textObject->height() == textObject->implicitHeight()); + QCOMPARE(textObject->width(), textObject->implicitWidth()); + QCOMPARE(textObject->height(), textObject->implicitHeight()); } void tst_qquicktextinput::implicitSizeBinding_data() @@ -6370,25 +6381,25 @@ Q_DECLARE_METATYPE(ExpectedBaseline) static qreal expectedBaselineTop(QQuickTextInput *item) { QFontMetricsF fm(item->font()); - return fm.ascent(); + return fm.ascent() + item->topPadding(); } static qreal expectedBaselineBottom(QQuickTextInput *item) { QFontMetricsF fm(item->font()); - return item->height() - item->contentHeight() + fm.ascent(); + return item->height() - item->contentHeight() - item->bottomPadding() + fm.ascent(); } static qreal expectedBaselineCenter(QQuickTextInput *item) { QFontMetricsF fm(item->font()); - return ((item->height() - item->contentHeight()) / 2) + fm.ascent(); + return ((item->height() - item->contentHeight() - item->topPadding() - item->bottomPadding()) / 2) + fm.ascent() + item->topPadding(); } static qreal expectedBaselineMultilineBottom(QQuickTextInput *item) { QFontMetricsF fm(item->font()); - return item->height() - item->contentHeight() + fm.ascent(); + return item->height() - item->contentHeight() - item->bottomPadding() + fm.ascent(); } void tst_qquicktextinput::baselineOffset_data() @@ -6433,6 +6444,41 @@ void tst_qquicktextinput::baselineOffset_data() << -1. << &expectedBaselineMultilineBottom << &expectedBaselineBottom; + + QTest::newRow("padding") + << "Typography" + << QByteArray("topPadding: 10; bottomPadding: 20") + << -1. + << &expectedBaselineTop + << &expectedBaselineTop; + + QTest::newRow("top align with padding") + << "Typography" + << QByteArray("height: 200; verticalAlignment: Text.AlignTop; topPadding: 10; bottomPadding: 20") + << -1. + << &expectedBaselineTop + << &expectedBaselineTop; + + QTest::newRow("bottom align with padding") + << "Typography" + << QByteArray("height: 200; verticalAlignment: Text.AlignBottom; topPadding: 10; bottomPadding: 20") + << 100. + << &expectedBaselineBottom + << &expectedBaselineBottom; + + QTest::newRow("center align with padding") + << "Typography" + << QByteArray("height: 200; verticalAlignment: Text.AlignVCenter; topPadding: 10; bottomPadding: 20") + << 100. + << &expectedBaselineCenter + << &expectedBaselineCenter; + + QTest::newRow("multiline bottom aligned with padding") + << "The quick brown fox jumps over the lazy dog" + << QByteArray("height: 200; width: 30; verticalAlignment: Text.AlignBottom; wrapMode: TextInput.WordWrap; topPadding: 10; bottomPadding: 20") + << -1. + << &expectedBaselineMultilineBottom + << &expectedBaselineBottom; } void tst_qquicktextinput::baselineOffset() @@ -6445,7 +6491,7 @@ void tst_qquicktextinput::baselineOffset() QQmlComponent component(&engine); component.setData( - "import QtQuick 2.0\n" + "import QtQuick 2.6\n" "TextInput {\n" + bindings + "\n" "}", QUrl()); @@ -6510,6 +6556,85 @@ void tst_qquicktextinput::ensureVisible() QCOMPARE(input->boundingRect().height(), line.height()); } +void tst_qquicktextinput::padding() +{ + QScopedPointer<QQuickView> window(new QQuickView); + window->setSource(testFileUrl("padding.qml")); + QTRY_COMPARE(window->status(), QQuickView::Ready); + window->show(); + QVERIFY(QTest::qWaitForWindowExposed(window.data())); + QQuickItem *root = window->rootObject(); + QVERIFY(root); + QQuickTextInput *obj = qobject_cast<QQuickTextInput*>(root); + QVERIFY(obj != 0); + + qreal cw = obj->contentWidth(); + qreal ch = obj->contentHeight(); + + QVERIFY(cw > 0); + QVERIFY(ch > 0); + + QCOMPARE(obj->padding(), 10.0); + QCOMPARE(obj->topPadding(), 20.0); + QCOMPARE(obj->leftPadding(), 30.0); + QCOMPARE(obj->rightPadding(), 40.0); + QCOMPARE(obj->bottomPadding(), 50.0); + + QCOMPARE(obj->implicitWidth(), qCeil(cw) + obj->leftPadding() + obj->rightPadding()); + QCOMPARE(obj->implicitHeight(), qCeil(ch) + obj->topPadding() + obj->bottomPadding()); + + obj->setTopPadding(2.25); + QCOMPARE(obj->topPadding(), 2.25); + QCOMPARE(obj->implicitHeight(), qCeil(ch) + obj->topPadding() + obj->bottomPadding()); + + obj->setLeftPadding(3.75); + QCOMPARE(obj->leftPadding(), 3.75); + QCOMPARE(obj->implicitWidth(), qCeil(cw) + obj->leftPadding() + obj->rightPadding()); + + obj->setRightPadding(4.4); + QCOMPARE(obj->rightPadding(), 4.4); + QCOMPARE(obj->implicitWidth(), qCeil(cw) + obj->leftPadding() + obj->rightPadding()); + + obj->setBottomPadding(1.11); + QCOMPARE(obj->bottomPadding(), 1.11); + QCOMPARE(obj->implicitHeight(), qCeil(ch) + obj->topPadding() + obj->bottomPadding()); + + obj->setText("Qt"); + QVERIFY(obj->contentWidth() < cw); + QCOMPARE(obj->contentHeight(), ch); + cw = obj->contentWidth(); + + QCOMPARE(obj->implicitWidth(), qCeil(cw) + obj->leftPadding() + obj->rightPadding()); + QCOMPARE(obj->implicitHeight(), qCeil(ch) + obj->topPadding() + obj->bottomPadding()); + + obj->setFont(QFont("Courier", 96)); + QVERIFY(obj->contentWidth() > cw); + QVERIFY(obj->contentHeight() > ch); + cw = obj->contentWidth(); + ch = obj->contentHeight(); + + QCOMPARE(obj->implicitWidth(), qCeil(cw) + obj->leftPadding() + obj->rightPadding()); + QCOMPARE(obj->implicitHeight(), qCeil(ch) + obj->topPadding() + obj->bottomPadding()); + + obj->resetTopPadding(); + QCOMPARE(obj->topPadding(), 10.0); + obj->resetLeftPadding(); + QCOMPARE(obj->leftPadding(), 10.0); + obj->resetRightPadding(); + QCOMPARE(obj->rightPadding(), 10.0); + obj->resetBottomPadding(); + QCOMPARE(obj->bottomPadding(), 10.0); + + obj->resetPadding(); + QCOMPARE(obj->padding(), 0.0); + QCOMPARE(obj->topPadding(), 0.0); + QCOMPARE(obj->leftPadding(), 0.0); + QCOMPARE(obj->rightPadding(), 0.0); + QCOMPARE(obj->bottomPadding(), 0.0); + + delete root; +} + QTEST_MAIN(tst_qquicktextinput) #include "tst_qquicktextinput.moc" diff --git a/tests/auto/quick/qquickview/data/error2.qml b/tests/auto/quick/qquickview/data/error2.qml new file mode 100644 index 0000000000..1d754b64f0 --- /dev/null +++ b/tests/auto/quick/qquickview/data/error2.qml @@ -0,0 +1,4 @@ +import QtQuick.Window 2.0 + +Window { +} diff --git a/tests/auto/quick/qquickview/tst_qquickview.cpp b/tests/auto/quick/qquickview/tst_qquickview.cpp index a980c69140..2f054e278a 100644 --- a/tests/auto/quick/qquickview/tst_qquickview.cpp +++ b/tests/auto/quick/qquickview/tst_qquickview.cpp @@ -184,8 +184,17 @@ void tst_QQuickView::errors() QQuickView view; QQmlTestMessageHandler messageHandler; view.setSource(testFileUrl("error1.qml")); - QVERIFY(view.status() == QQuickView::Error); - QVERIFY(view.errors().count() == 1); + QCOMPARE(view.status(), QQuickView::Error); + QCOMPARE(view.errors().count(), 1); + } + + { + QQuickView view; + QQmlTestMessageHandler messageHandler; + view.setSource(testFileUrl("error2.qml")); + QCOMPARE(view.status(), QQuickView::Error); + QCOMPARE(view.errors().count(), 1); + view.show(); } } @@ -196,16 +205,16 @@ void tst_QQuickView::engine() QQuickView *view = new QQuickView(engine, 0); QVERIFY(view); - QVERIFY(engine->incubationController() == view->incubationController()); + QCOMPARE(engine->incubationController(), view->incubationController()); QQuickView *view2 = new QQuickView(engine, 0); QVERIFY(view); - QVERIFY(engine->incubationController() == view->incubationController()); + QCOMPARE(engine->incubationController(), view->incubationController()); delete view; QVERIFY(!engine->incubationController()); engine->setIncubationController(view2->incubationController()); - QVERIFY(engine->incubationController() == view2->incubationController()); + QCOMPARE(engine->incubationController(), view2->incubationController()); delete view2; QVERIFY(!engine->incubationController()); diff --git a/tests/auto/quick/qquickvisualdatamodel/tst_qquickvisualdatamodel.cpp b/tests/auto/quick/qquickvisualdatamodel/tst_qquickvisualdatamodel.cpp index 2dd9e77370..d578a0900c 100644 --- a/tests/auto/quick/qquickvisualdatamodel/tst_qquickvisualdatamodel.cpp +++ b/tests/auto/quick/qquickvisualdatamodel/tst_qquickvisualdatamodel.cpp @@ -513,15 +513,15 @@ void tst_qquickvisualdatamodel::rootIndex() QVERIFY(obj != 0); QMetaObject::invokeMethod(obj, "setRoot"); - QVERIFY(qvariant_cast<QModelIndex>(obj->rootIndex()) == model.index(0,0)); + QCOMPARE(qvariant_cast<QModelIndex>(obj->rootIndex()), model.index(0,0)); QMetaObject::invokeMethod(obj, "setRootToParent"); - QVERIFY(qvariant_cast<QModelIndex>(obj->rootIndex()) == QModelIndex()); + QCOMPARE(qvariant_cast<QModelIndex>(obj->rootIndex()), QModelIndex()); QMetaObject::invokeMethod(obj, "setRoot"); - QVERIFY(qvariant_cast<QModelIndex>(obj->rootIndex()) == model.index(0,0)); + QCOMPARE(qvariant_cast<QModelIndex>(obj->rootIndex()), model.index(0,0)); model.clear(); // will emit modelReset() - QVERIFY(qvariant_cast<QModelIndex>(obj->rootIndex()) == QModelIndex()); + QCOMPARE(qvariant_cast<QModelIndex>(obj->rootIndex()), QModelIndex()); delete obj; } @@ -628,7 +628,7 @@ void tst_qquickvisualdatamodel::childChanged() model.item(1,0)->takeRow(1); name = findItem<QQuickText>(contentItem, "display", 1); - QVERIFY(name == 0); + QVERIFY(!name); vdm->setRootIndex(QVariant::fromValue(QModelIndex())); QCOMPARE(listview->count(), 3); diff --git a/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp b/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp index dfe5276e8e..e1ea068a62 100644 --- a/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp +++ b/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp @@ -504,7 +504,7 @@ void tst_qquickwindow::touchEvent_basic() window->resize(250, 250); window->setPosition(100, 100); window->show(); - QVERIFY(QTest::qWaitForWindowExposed(window)); + QVERIFY(QTest::qWaitForWindowActive(window)); TestTouchItem *bottomItem = new TestTouchItem(window->contentItem()); bottomItem->setObjectName("Bottom Item"); @@ -635,7 +635,7 @@ void tst_qquickwindow::touchEvent_propagation() window->setPosition(100, 100); window->setTitle(QTest::currentTestFunction()); window->show(); - QVERIFY(QTest::qWaitForWindowExposed(window)); + QVERIFY(QTest::qWaitForWindowActive(window)); TestTouchItem *bottomItem = new TestTouchItem(window->contentItem()); bottomItem->setObjectName("Bottom Item"); @@ -769,18 +769,18 @@ void tst_qquickwindow::touchEvent_cancel() window->setPosition(100, 100); window->setTitle(QTest::currentTestFunction()); window->show(); - QVERIFY(QTest::qWaitForWindowExposed(window)); + QVERIFY(QTest::qWaitForWindowActive(window)); TestTouchItem *item = new TestTouchItem(window->contentItem()); item->setPosition(QPointF(50, 50)); item->setSize(QSizeF(150, 150)); - QPointF pos(10, 10); - QTest::touchEvent(window, touchDevice).press(0, item->mapToScene(pos).toPoint(),window); + QPointF pos(50, 50); + QTest::touchEvent(window, touchDevice).press(0, item->mapToScene(pos).toPoint(), window); QCoreApplication::processEvents(); QTRY_COMPARE(item->lastEvent.touchPoints.count(), 1); - TouchEventData d = makeTouchData(QEvent::TouchBegin, window, Qt::TouchPointPressed, makeTouchPoint(item,pos)); + TouchEventData d = makeTouchData(QEvent::TouchBegin, window, Qt::TouchPointPressed, makeTouchPoint(item, pos)); COMPARE_TOUCH_DATA(item->lastEvent, d); item->reset(); @@ -803,7 +803,7 @@ void tst_qquickwindow::touchEvent_reentrant() window->setPosition(100, 100); window->setTitle(QTest::currentTestFunction()); window->show(); - QVERIFY(QTest::qWaitForWindowExposed(window)); + QVERIFY(QTest::qWaitForWindowActive(window)); TestTouchItem *item = new TestTouchItem(window->contentItem()); @@ -978,7 +978,7 @@ void tst_qquickwindow::clearWindow() delete window; - QVERIFY(item->window() == 0); + QVERIFY(!item->window()); delete item; } @@ -993,7 +993,7 @@ void tst_qquickwindow::mouseFiltering() window->setPosition(100, 100); window->setTitle(QTest::currentTestFunction()); window->show(); - QVERIFY(QTest::qWaitForWindowExposed(window)); + QVERIFY(QTest::qWaitForWindowActive(window)); TestTouchItem *bottomItem = new TestTouchItem(window->contentItem()); bottomItem->setObjectName("Bottom Item"); @@ -1232,7 +1232,7 @@ void tst_qquickwindow::headless() if (threaded) { QTRY_COMPARE(invalidated.size(), 1); - QVERIFY(window->openglContext() == 0); + QVERIFY(!window->openglContext()); } if (QGuiApplication::platformName() == QLatin1String("windows") @@ -1242,7 +1242,7 @@ void tst_qquickwindow::headless() // Destroy the native windowing system buffers window->destroy(); - QVERIFY(window->handle() == 0); + QVERIFY(!window->handle()); // Show and verify that we are back and running window->show(); @@ -1452,7 +1452,7 @@ void tst_qquickwindow::cursor() clippedItem.setParentItem(&clippingItem); window.show(); - QVERIFY(QTest::qWaitForWindowExposed(&window)); + QVERIFY(QTest::qWaitForWindowActive(&window)); // Position the cursor over the parent and child item and the clipped section of clippedItem. QTest::mouseMove(&window, QPoint(100, 100)); @@ -1609,7 +1609,7 @@ void tst_qquickwindow::hideThenDelete() if (!persistentGL) QVERIFY(openglDestroyed->size() > 0); else - QVERIFY(openglDestroyed->size() == 0); + QCOMPARE(openglDestroyed->size(), 0); } else { QCOMPARE(sgInvalidated->size(), 0); QCOMPARE(openglDestroyed->size(), 0); @@ -1693,7 +1693,7 @@ void tst_qquickwindow::requestActivate() window1->requestActivate(); // and then transfer the focus to window1 QTRY_COMPARE(QGuiApplication::focusWindow(), window1.data()); - QVERIFY(window1->isActive() == true); + QVERIFY(window1->isActive()); QQuickItem *item = QQuickVisualTestUtil::findItem<QQuickItem>(window1->contentItem(), "item1"); QVERIFY(item); @@ -1805,7 +1805,7 @@ void tst_qquickwindow::crashWhenHoverItemDeleted() QVERIFY(!window.isNull()); window->setTitle(QTest::currentTestFunction()); window->show(); - QTest::qWaitForWindowExposed(window.data()); + QTest::qWaitForWindowActive(window.data()); // Simulate a move from the first rectangle to the second. Crash will happen in here // Moving instantaneously from (0, 99) to (0, 102) does not cause the crash @@ -1844,7 +1844,7 @@ void tst_qquickwindow::qobjectEventFilter_touch() window.setPosition(100, 100); window.setTitle(QTest::currentTestFunction()); window.show(); - QVERIFY(QTest::qWaitForWindowExposed(&window)); + QVERIFY(QTest::qWaitForWindowActive(&window)); TestTouchItem *item = new TestTouchItem(window.contentItem()); item->setSize(QSizeF(150, 150)); @@ -1870,7 +1870,7 @@ void tst_qquickwindow::qobjectEventFilter_key() window.setPosition(100, 100); window.setTitle(QTest::currentTestFunction()); window.show(); - QVERIFY(QTest::qWaitForWindowExposed(&window)); + QVERIFY(QTest::qWaitForWindowActive(&window)); TestTouchItem *item = new TestTouchItem(window.contentItem()); item->setSize(QSizeF(150, 150)); @@ -1899,8 +1899,7 @@ void tst_qquickwindow::qobjectEventFilter_mouse() window.setPosition(100, 100); window.setTitle(QTest::currentTestFunction()); window.show(); - - QVERIFY(QTest::qWaitForWindowExposed(&window)); + QVERIFY(QTest::qWaitForWindowActive(&window)); TestTouchItem *item = new TestTouchItem(window.contentItem()); item->setSize(QSizeF(150, 150)); @@ -1909,6 +1908,7 @@ void tst_qquickwindow::qobjectEventFilter_mouse() item->installEventFilter(&eventFilter); QPoint point = item->mapToScene(QPointF(10, 10)).toPoint(); + QTest::mouseMove(&window, point); QTest::mousePress(&window, Qt::LeftButton, Qt::NoModifier, point); QVERIFY(eventFilter.events.contains((int)QEvent::MouseButtonPress)); @@ -2048,44 +2048,108 @@ public: static int deleted; }; +class GlRenderJob : public QRunnable +{ +public: + GlRenderJob(GLubyte *buf) : readPixel(buf), mutex(0), condition(0) {} + ~GlRenderJob() {} + void run() { + QOpenGLContext::currentContext()->functions()->glClearColor(1.0f, 0, 0, 1.0f); + QOpenGLContext::currentContext()->functions()->glClear(GL_COLOR_BUFFER_BIT); + QOpenGLContext::currentContext()->functions()->glReadPixels(0, 0, 1, 1, GL_RGBA, + GL_UNSIGNED_BYTE, + (void *)readPixel); + if (mutex) { + mutex->lock(); + condition->wakeOne(); + mutex->unlock(); + } + } + GLubyte *readPixel; + QMutex *mutex; + QWaitCondition *condition; +}; + int RenderJob::deleted = 0; void tst_qquickwindow::testRenderJob() { QList<QQuickWindow::RenderStage> completedJobs; - QQuickWindow window; - window.setTitle(QTest::currentTestFunction()); - QQuickWindow::RenderStage stages[] = { QQuickWindow::BeforeSynchronizingStage, QQuickWindow::AfterSynchronizingStage, QQuickWindow::BeforeRenderingStage, QQuickWindow::AfterRenderingStage, - QQuickWindow::AfterSwapStage + QQuickWindow::AfterSwapStage, + QQuickWindow::NoStage }; - // Schedule the jobs - for (int i=0; i<5; ++i) - window.scheduleRenderJob(new RenderJob(stages[i], &completedJobs), stages[i]); - window.show(); - QTRY_COMPARE(completedJobs.size(), 5); + const int numJobs = 6; - for (int i=0; i<5; ++i) { - QCOMPARE(completedJobs.at(i), stages[i]); + { + QQuickWindow window; + window.setTitle(QTest::currentTestFunction()); + RenderJob::deleted = 0; + + // Schedule the jobs + for (int i = 0; i < numJobs; ++i) + window.scheduleRenderJob(new RenderJob(stages[i], &completedJobs), stages[i]); + window.show(); + QVERIFY(QTest::qWaitForWindowExposed(&window)); + + // All jobs should be deleted + QTRY_COMPARE(RenderJob::deleted, numJobs); + + // The NoStage job is not completed, if it is issued when there is no context, + // but the rest will be queued and completed once relevant render stage is hit. + QCOMPARE(completedJobs.size(), numJobs - 1); + + // Verify jobs were completed in correct order + for (int i = 0; i < numJobs - 1; ++i) + QCOMPARE(completedJobs.at(i), stages[i]); + + + // Check that NoStage job gets executed if it is scheduled when window is exposed + completedJobs.clear(); + RenderJob::deleted = 0; + window.scheduleRenderJob(new RenderJob(QQuickWindow::NoStage, &completedJobs), + QQuickWindow::NoStage); + QTRY_COMPARE(RenderJob::deleted, 1); + QCOMPARE(completedJobs.size(), 1); + + // Do a synchronized GL job. + GLubyte readPixel[4] = {0, 0, 0, 0}; + GlRenderJob *glJob = new GlRenderJob(readPixel); + if (window.openglContext()->thread() != QThread::currentThread()) { + QMutex mutex; + QWaitCondition condition; + glJob->mutex = &mutex; + glJob->condition = &condition; + mutex.lock(); + window.scheduleRenderJob(glJob, QQuickWindow::NoStage); + condition.wait(&mutex); + mutex.unlock(); + } else { + window.scheduleRenderJob(glJob, QQuickWindow::NoStage); + } + QCOMPARE(int(readPixel[0]), 255); + QCOMPARE(int(readPixel[1]), 0); + QCOMPARE(int(readPixel[2]), 0); + QCOMPARE(int(readPixel[3]), 255); } - // Verify that jobs are deleted when window has not been rendered at all... + // Verify that jobs are deleted when window is not rendered at all completedJobs.clear(); RenderJob::deleted = 0; { QQuickWindow window2; - for (int i=0; i<5; ++i) { + for (int i = 0; i < numJobs; ++i) { window2.scheduleRenderJob(new RenderJob(stages[i], &completedJobs), stages[i]); } } + QTRY_COMPARE(RenderJob::deleted, numJobs); QCOMPARE(completedJobs.size(), 0); - QCOMPARE(RenderJob::deleted, 5); } class EventCounter : public QQuickRectangle @@ -2144,7 +2208,7 @@ void tst_qquickwindow::testHoverChildMouseEventFilter() window.setPosition(100, 100); window.setTitle(QTest::currentTestFunction()); window.show(); - QVERIFY(QTest::qWaitForWindowExposed(&window)); + QVERIFY(QTest::qWaitForWindowActive(&window)); EventCounter *bottomItem = new EventCounter(window.contentItem()); bottomItem->setObjectName("Bottom Item"); diff --git a/tests/auto/quick/qquickxmllistmodel/tst_qquickxmllistmodel.cpp b/tests/auto/quick/qquickxmllistmodel/tst_qquickxmllistmodel.cpp index 5372a4d3b3..c0bf86a212 100644 --- a/tests/auto/quick/qquickxmllistmodel/tst_qquickxmllistmodel.cpp +++ b/tests/auto/quick/qquickxmllistmodel/tst_qquickxmllistmodel.cpp @@ -760,9 +760,9 @@ void tst_qquickxmllistmodel::noKeysValueChanges() QTRY_VERIFY(model->data(model->index(0, 0), roles.at(2)).toString() != QLatin1String("Football")); QCOMPARE(model->data(model->index(0, 0), roles.at(2)).toString(), QLatin1String("AussieRules")); - QVERIFY(spyInsert.count() == 0); - QVERIFY(spyRemove.count() == 0); - QVERIFY(spyCount.count() == 0); + QCOMPARE(spyInsert.count(), 0); + QCOMPARE(spyRemove.count(), 0); + QCOMPARE(spyCount.count(), 0); QCOMPARE(model->rowCount(), 2); @@ -940,7 +940,7 @@ void tst_qquickxmllistmodel::propertyChanges() QCOMPARE(model->property("query").toString(), QString("/Pets")); QCOMPARE(model->property("namespaceDeclarations").toString(), QString("declare namespace media=\"http://search.yahoo.com/mrss/\";")); - QTRY_VERIFY(model->rowCount() == 1); + QTRY_COMPARE(model->rowCount(), 1); QCOMPARE(sourceSpy.count(),1); QCOMPARE(xmlSpy.count(),1); @@ -957,7 +957,7 @@ void tst_qquickxmllistmodel::propertyChanges() QCOMPARE(modelQuerySpy.count(),1); QCOMPARE(namespaceDeclarationsSpy.count(),1); - QTRY_VERIFY(model->rowCount() == 1); + QTRY_COMPARE(model->rowCount(), 1); delete model; } diff --git a/tests/auto/quick/quick.pro b/tests/auto/quick/quick.pro index c2b7a4cc8d..5593fd94f6 100644 --- a/tests/auto/quick/quick.pro +++ b/tests/auto/quick/quick.pro @@ -74,8 +74,8 @@ QUICKTESTS = \ qquickview \ qquickcanvasitem \ qquickscreen \ - touchmouse - + touchmouse \ + scenegraph SUBDIRS += $$PUBLICTESTS diff --git a/tests/auto/quick/scenegraph/data/mipmap_large.png b/tests/auto/quick/scenegraph/data/mipmap_large.png Binary files differindex 9cb0fc7de1..1b6d99c45c 100644 --- a/tests/auto/quick/scenegraph/data/mipmap_large.png +++ b/tests/auto/quick/scenegraph/data/mipmap_large.png diff --git a/tests/auto/quick/scenegraph/data/mipmap_small.png b/tests/auto/quick/scenegraph/data/mipmap_small.png Binary files differindex dc5216fb6c..2e53012ef5 100644 --- a/tests/auto/quick/scenegraph/data/mipmap_small.png +++ b/tests/auto/quick/scenegraph/data/mipmap_small.png diff --git a/tests/auto/quick/scenegraph/data/render_Mipmap.qml b/tests/auto/quick/scenegraph/data/render_Mipmap.qml index 6d9191c5ac..9bd585373a 100644 --- a/tests/auto/quick/scenegraph/data/render_Mipmap.qml +++ b/tests/auto/quick/scenegraph/data/render_Mipmap.qml @@ -32,6 +32,7 @@ ****************************************************************************/ import QtQuick 2.3 +import QtQuick.Window 2.2 /* The test verifies that scaled down mipmapped images contains @@ -39,8 +40,8 @@ import QtQuick 2.3 #samples: 2 PixelPos R G B Error-tolerance - #final: 0 0 0.33 0.33 0.33 0.1 - #final: 1 0 0.33 0.33 0.33 0.1 + #final: 0 0 0.25 0.25 0.25 0.1 + #final: 1 0 0.25 0.25 0.25 0.1 */ RenderTestBase @@ -52,7 +53,7 @@ RenderTestBase source: "mipmap_small.png" mipmap: true smooth: false - scale: 1 / width; + scale: 1 / (width * Screen.devicePixelRatio); } Image { @@ -62,7 +63,7 @@ RenderTestBase source: "mipmap_large.png" mipmap: true smooth: false - scale: 1 / width; + scale: 1 / (width * Screen.devicePixelRatio); } onEnterFinalStage: finalStageComplete = true; diff --git a/tests/auto/quick/scenegraph/tst_scenegraph.cpp b/tests/auto/quick/scenegraph/tst_scenegraph.cpp index d2d3643ca8..80672e234e 100644 --- a/tests/auto/quick/scenegraph/tst_scenegraph.cpp +++ b/tests/auto/quick/scenegraph/tst_scenegraph.cpp @@ -33,11 +33,17 @@ #include <qtest.h> +#include <QOffscreenSurface> +#include <QOpenGLContext> +#include <QOpenGLFunctions> + #include <QtQuick> +#include <QtQml> #include <private/qopenglcontext_p.h> +#include <private/qsgcontext_p.h> +#include <private/qsgrenderloop_p.h> -#include <QtQml> class PerPixelRect : public QQuickItem { @@ -97,6 +103,12 @@ private slots: void render(); void hideWithOtherContext(); + + void createTextureFromImage_data(); + void createTextureFromImage(); + +private: + bool m_brokenMipmapSupport; }; template <typename T> class ScopedList : public QList<T> { @@ -107,6 +119,42 @@ public: void tst_SceneGraph::initTestCase() { qmlRegisterType<PerPixelRect>("SceneGraphTest", 1, 0, "PerPixelRect"); + + QSGRenderLoop *loop = QSGRenderLoop::instance(); + qDebug() << "RenderLoop: " << loop; + + QOpenGLContext context; + context.setFormat(loop->sceneGraphContext()->defaultSurfaceFormat()); + context.create(); + QSurfaceFormat format = context.format(); + + QOffscreenSurface surface; + surface.setFormat(format); + surface.create(); + if (!context.makeCurrent(&surface)) + qFatal("Failed to create a GL context..."); + + QOpenGLFunctions *funcs = QOpenGLContext::currentContext()->functions(); + qDebug() << "R/G/B/A Buffers: " << format.redBufferSize() << format.greenBufferSize() << format.blueBufferSize() << format.alphaBufferSize(); + qDebug() << "Depth Buffer: " << format.depthBufferSize(); + qDebug() << "Stencil Buffer: " << format.stencilBufferSize(); + qDebug() << "Samples: " << format.samples(); + int textureSize; + funcs->glGetIntegerv(GL_MAX_TEXTURE_SIZE, &textureSize); + qDebug() << "Max Texture Size: " << textureSize; + qDebug() << "GL_VENDOR: " << (const char *) funcs->glGetString(GL_VENDOR); + qDebug() << "GL_RENDERER: " << (const char *) funcs->glGetString(GL_RENDERER); + QByteArray version = (const char *) funcs->glGetString(GL_VERSION); + qDebug() << "GL_VERSION: " << version.constData(); + QSet<QByteArray> exts = context.extensions(); + QByteArray all; + foreach (const QByteArray &e, exts) all += ' ' + e; + qDebug() << "GL_EXTENSIONS: " << all.constData(); + + m_brokenMipmapSupport = version.contains("Mesa 10.1") || version.contains("Mesa 9."); + qDebug() << "Broken Mipmap: " << m_brokenMipmapSupport; + + context.doneCurrent(); } QQuickView *createView(const QString &file, QWindow *parent = 0, int x = -1, int y = -1, int w = -1, int h = -1) @@ -210,7 +258,7 @@ void tst_SceneGraph::manyWindows_data() struct ShareContextResetter { public: - ~ShareContextResetter() { QOpenGLContextPrivate::setGlobalShareContext(0); } + ~ShareContextResetter() { qt_gl_set_global_share_context(0); } }; void tst_SceneGraph::manyWindows() @@ -223,7 +271,7 @@ void tst_SceneGraph::manyWindows() ShareContextResetter cleanup; // To avoid dangling pointer in case of test-failure. if (shared) { QVERIFY(sharedGLContext.create()); - QOpenGLContextPrivate::setGlobalShareContext(&sharedGLContext); + qt_gl_set_global_share_context(&sharedGLContext); } QScopedPointer<QWindow> parent; @@ -297,8 +345,8 @@ struct Sample { .arg(color.redF()).arg(color.greenF()).arg(color.blueF()); } - bool check(const QImage &image) { - QColor color(image.pixel(x, y)); + bool check(const QImage &image, qreal scale) { + QColor color(image.pixel(x * scale, y * scale)); return qAbs(color.redF() - r) <= tolerance && qAbs(color.greenF() - g) <= tolerance && qAbs(color.blueF() - b) <= tolerance; @@ -368,11 +416,11 @@ void tst_SceneGraph::render_data() << "data/render_BreakOpacityBatch.qml" << "data/render_OutOfFloatRange.qml" << "data/render_StackingOrder.qml" - << "data/render_Mipmap.qml" << "data/render_ImageFiltering.qml" << "data/render_bug37422.qml" - << "data/render_OpacityThroughBatchRoot.qml" - ; + << "data/render_OpacityThroughBatchRoot.qml"; + if (!m_brokenMipmapSupport) + files << "data/render_Mipmap.qml"; QRegExp sampleCount("#samples: *(\\d+)"); // X:int Y:int R:float G:float B:float Error:float @@ -428,11 +476,18 @@ void tst_SceneGraph::render() view.show(); QVERIFY(QTest::qWaitForWindowExposed(&view)); + // We're checking actual pixels, so scale up the sample point to the top-left of the + // 2x2 pixel block and hope that this is good enough. Ideally, view and content + // would be in identical coordinate space, meaning pixels, but we're not in an + // ideal world. + // Just keep this in mind when writing tests. + qreal scale = view.devicePixelRatio(); + // Grab the window and check all our base stage samples QImage content = view.grabWindow(); for (int i=0; i<baseStage.size(); ++i) { Sample sample = baseStage.at(i); - QVERIFY2(sample.check(content), qPrintable(sample.toString(content))); + QVERIFY2(sample.check(content, scale), qPrintable(sample.toString(content))); } // Put the qml file into the final stage and wait for it to @@ -445,7 +500,7 @@ void tst_SceneGraph::render() content = view.grabWindow(); for (int i=0; i<finalStage.size(); ++i) { Sample sample = finalStage.at(i); - QVERIFY2(sample.check(content), qPrintable(sample.toString(content))); + QVERIFY2(sample.check(content, scale), qPrintable(sample.toString(content))); } } @@ -482,6 +537,34 @@ void tst_SceneGraph::hideWithOtherContext() QVERIFY(!renderingOnMainThread || QOpenGLContext::currentContext() != &context); } +void tst_SceneGraph::createTextureFromImage_data() +{ + QImage rgba(64, 64, QImage::Format_ARGB32_Premultiplied); + QImage rgb(64, 64, QImage::Format_RGB32); + + QTest::addColumn<QImage>("image"); + QTest::addColumn<uint>("flags"); + QTest::addColumn<bool>("expectedAlpha"); + + QTest::newRow("rgb") << rgb << uint(0) << false; + QTest::newRow("argb") << rgba << uint(0) << true; + QTest::newRow("rgb,alpha") << rgb << uint(QQuickWindow::TextureHasAlphaChannel) << false; + QTest::newRow("argb,alpha") << rgba << uint(QQuickWindow::TextureHasAlphaChannel) << true; + QTest::newRow("rgb,!alpha") << rgb << uint(QQuickWindow::TextureIsOpaque) << false; + QTest::newRow("argb,!alpha") << rgba << uint(QQuickWindow::TextureIsOpaque) << false; +} + +void tst_SceneGraph::createTextureFromImage() +{ + QFETCH(QImage, image); + QFETCH(uint, flags); + QFETCH(bool, expectedAlpha); + + QQuickView view; + QScopedPointer<QSGTexture> texture(view.createTextureFromImage(image, (QQuickWindow::CreateTextureOptions) flags)); + QCOMPARE(texture->hasAlphaChannel(), expectedAlpha); +} + #include "tst_scenegraph.moc" diff --git a/tests/auto/quick/shared/viewtestutil.cpp b/tests/auto/quick/shared/viewtestutil.cpp index 5b9111d448..86d61a0c23 100644 --- a/tests/auto/quick/shared/viewtestutil.cpp +++ b/tests/auto/quick/shared/viewtestutil.cpp @@ -72,18 +72,30 @@ void QQuickViewTestUtil::moveMouseAway(QQuickView *window) #endif } +void QQuickViewTestUtil::moveAndRelease(QQuickView *window, const QPoint &position) +{ + QTest::mouseMove(window, position); + QTest::mouseRelease(window, Qt::LeftButton, 0, position); +} + +void QQuickViewTestUtil::moveAndPress(QQuickView *window, const QPoint &position) +{ + QTest::mouseMove(window, position); + QTest::mousePress(window, Qt::LeftButton, 0, position); +} + void QQuickViewTestUtil::flick(QQuickView *window, const QPoint &from, const QPoint &to, int duration) { const int pointCount = 5; QPoint diff = to - from; // send press, five equally spaced moves, and release. - QTest::mousePress(window, Qt::LeftButton, 0, from); + moveAndPress(window, from); for (int i = 0; i < pointCount; ++i) QTest::mouseMove(window, from + (i+1)*diff/pointCount, duration / pointCount); - QTest::mouseRelease(window, Qt::LeftButton, 0, to); + moveAndRelease(window, to); QTest::qWait(50); } diff --git a/tests/auto/quick/shared/viewtestutil.h b/tests/auto/quick/shared/viewtestutil.h index 8c5f5c54e6..1643eca979 100644 --- a/tests/auto/quick/shared/viewtestutil.h +++ b/tests/auto/quick/shared/viewtestutil.h @@ -48,6 +48,8 @@ namespace QQuickViewTestUtil void centerOnScreen(QQuickView *window, const QSize &size); void centerOnScreen(QQuickView *window); void moveMouseAway(QQuickView *window); + void moveAndPress(QQuickView *window, const QPoint &position); + void moveAndRelease(QQuickView *window, const QPoint &position); QList<int> adjustIndexesForAddDisplaced(const QList<int> &indexes, int index, int count); QList<int> adjustIndexesForMove(const QList<int> &indexes, int from, int to, int count); diff --git a/tests/auto/quick/touchmouse/tst_touchmouse.cpp b/tests/auto/quick/touchmouse/tst_touchmouse.cpp index 539bbb4703..90ee8215a1 100644 --- a/tests/auto/quick/touchmouse/tst_touchmouse.cpp +++ b/tests/auto/quick/touchmouse/tst_touchmouse.cpp @@ -863,7 +863,7 @@ void tst_TouchMouse::pinchOnFlickable() QVERIFY(rect); // flickable - single touch point - QVERIFY(flickable->contentX() == 0.0); + QCOMPARE(flickable->contentX(), 0.0); QPoint p = QPoint(100, 100); QTest::touchEvent(window, device).press(0, p, window); QQuickTouchUtils::flush(window); @@ -945,7 +945,7 @@ void tst_TouchMouse::flickableOnPinch() QVERIFY(rect); // flickable - single touch point - QVERIFY(flickable->contentX() == 0.0); + QCOMPARE(flickable->contentX(), 0.0); QPoint p = QPoint(100, 100); QTest::touchEvent(window, device).press(0, p, window); QQuickTouchUtils::flush(window); @@ -1025,7 +1025,7 @@ void tst_TouchMouse::mouseOnFlickableOnPinch() QVERIFY(rect); // flickable - single touch point - QVERIFY(flickable->contentX() == 0.0); + QCOMPARE(flickable->contentX(), 0.0); QPoint p = QPoint(100, 100); QTest::touchEvent(window, device).press(0, p, window); QQuickTouchUtils::flush(window); |