diff options
Diffstat (limited to 'tests/auto/quick/qquickbehaviors')
-rw-r--r-- | tests/auto/quick/qquickbehaviors/BLACKLIST | 2 | ||||
-rw-r--r-- | tests/auto/quick/qquickbehaviors/data/Accelerator.qml | 18 | ||||
-rw-r--r-- | tests/auto/quick/qquickbehaviors/data/aliased.qml | 39 | ||||
-rw-r--r-- | tests/auto/quick/qquickbehaviors/tst_qquickbehaviors.cpp | 210 |
4 files changed, 147 insertions, 122 deletions
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/data/Accelerator.qml b/tests/auto/quick/qquickbehaviors/data/Accelerator.qml new file mode 100644 index 0000000000..a2b5146c3f --- /dev/null +++ b/tests/auto/quick/qquickbehaviors/data/Accelerator.qml @@ -0,0 +1,18 @@ +import QtQuick 2.3 + +Rectangle { + property alias value: range.width + color: "yellow" + Text { + text: 'value: ' + value + } + + Rectangle { + id: range + objectName: "range" + color: "red" + width: 0 + height: 5 + anchors.bottom: parent.bottom + } +} diff --git a/tests/auto/quick/qquickbehaviors/data/aliased.qml b/tests/auto/quick/qquickbehaviors/data/aliased.qml new file mode 100644 index 0000000000..e65e035d83 --- /dev/null +++ b/tests/auto/quick/qquickbehaviors/data/aliased.qml @@ -0,0 +1,39 @@ +import QtQuick 2.3 + +Rectangle { + width: 400 + height: 400 + id: rect + property bool accelerating : false + + Text { + anchors.centerIn: parent + text: "Press anywere to accelerate" + } + + Accelerator { + id: acc + objectName: "acc" + anchors.fill: parent + value: accelerating ? 400 : 0 + Behavior on value { + NumberAnimation { + duration: 500 + } + } + } + + MouseArea { + id: clicker + anchors.fill: parent + } + + states: State { + name: "moved" + when: clicker.pressed + PropertyChanges { + target: rect + accelerating: true + } + } +} diff --git a/tests/auto/quick/qquickbehaviors/tst_qquickbehaviors.cpp b/tests/auto/quick/qquickbehaviors/tst_qquickbehaviors.cpp index b96f1de930..635958314f 100644 --- a/tests/auto/quick/qquickbehaviors/tst_qquickbehaviors.cpp +++ b/tests/auto/quick/qquickbehaviors/tst_qquickbehaviors.cpp @@ -76,45 +76,42 @@ private slots: void multipleChangesToValueType(); void currentValue(); void disabledWriteWhileRunning(); + void aliasedProperty(); }; 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 +119,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 +176,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 +184,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 +192,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 +220,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 +270,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 +297,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 +310,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 +332,6 @@ void tst_qquickbehaviors::startup() QVERIFY(text); QCOMPARE(innerRect->x(), text->width()); //should be set immediately - - delete rect; } } @@ -375,10 +340,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 +349,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 +358,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 +365,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 +385,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 +393,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 +410,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 +419,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 +428,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 +453,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 +473,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 +492,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 +501,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 +532,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,11 +574,26 @@ void tst_qquickbehaviors::disabledWriteWhileRunning() QCOMPARE(myRect->x(), qreal(100)); QTest::qWait(200); QCOMPARE(myRect->x(), qreal(100)); - - delete root; } } +void tst_qquickbehaviors::aliasedProperty() +{ + QQmlEngine engine; + QQmlComponent c(&engine, testFileUrl("aliased.qml")); + QScopedPointer<QQuickRectangle> rect(qobject_cast<QQuickRectangle*>(c.create())); + QVERIFY2(!rect.isNull(), qPrintable(c.errorString())); + + QQuickItemPrivate::get(rect.data())->setState("moved"); + QScopedPointer<QQuickRectangle> acc(qobject_cast<QQuickRectangle*>(rect->findChild<QQuickRectangle*>("acc"))); + QScopedPointer<QQuickRectangle> range(qobject_cast<QQuickRectangle*>(acc->findChild<QQuickRectangle*>("range"))); + QTRY_VERIFY(acc->property("value").toDouble() > 0); + QTRY_VERIFY(range->width() > 0); + QTRY_VERIFY(acc->property("value").toDouble() < 400); + QTRY_VERIFY(range->width() < 400); + //i.e. the behavior has been triggered +} + QTEST_MAIN(tst_qquickbehaviors) #include "tst_qquickbehaviors.moc" |