From efab34ea95560db007b1a75cce63cf8f6431a683 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Thu, 29 Apr 2010 09:56:53 +1000 Subject: Additional Behavior test + text fixes. --- .../qdeclarativebehaviors/data/startup2.qml | 16 ++++++ .../tst_qdeclarativebehaviors.cpp | 65 ++++++++++++++-------- 2 files changed, 58 insertions(+), 23 deletions(-) create mode 100644 tests/auto/declarative/qdeclarativebehaviors/data/startup2.qml diff --git a/tests/auto/declarative/qdeclarativebehaviors/data/startup2.qml b/tests/auto/declarative/qdeclarativebehaviors/data/startup2.qml new file mode 100644 index 0000000..1911cc4 --- /dev/null +++ b/tests/auto/declarative/qdeclarativebehaviors/data/startup2.qml @@ -0,0 +1,16 @@ +import Qt 4.7 + +Rectangle { + width: 800; + height: 480; + + Text { id:theText; text: "hello world" } + + Rectangle { + objectName: "innerRect" + color: "red" + x: theText.width + Behavior on x { NumberAnimation {} } + width: 100; height: 100 + } +} diff --git a/tests/auto/declarative/qdeclarativebehaviors/tst_qdeclarativebehaviors.cpp b/tests/auto/declarative/qdeclarativebehaviors/tst_qdeclarativebehaviors.cpp index ee9e282..5e0c9d5 100644 --- a/tests/auto/declarative/qdeclarativebehaviors/tst_qdeclarativebehaviors.cpp +++ b/tests/auto/declarative/qdeclarativebehaviors/tst_qdeclarativebehaviors.cpp @@ -43,6 +43,7 @@ #include #include #include +#include #include #include #include "../../../shared/util.h" @@ -230,11 +231,11 @@ void tst_qdeclarativebehaviors::emptyBehavior() QDeclarativeEngine engine; QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/empty.qml")); QDeclarativeRectangle *rect = qobject_cast(c.create()); - QTRY_VERIFY(rect); + QVERIFY(rect); rect->setState("moved"); qreal x = qobject_cast(rect->findChild("MyRect"))->x(); - QTRY_COMPARE(x, qreal(200)); //should change immediately + QCOMPARE(x, qreal(200)); //should change immediately delete rect; } @@ -244,7 +245,7 @@ void tst_qdeclarativebehaviors::explicitSelection() QDeclarativeEngine engine; QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/explicit.qml")); QDeclarativeRectangle *rect = qobject_cast(c.create()); - QTRY_VERIFY(rect); + QVERIFY(rect); rect->setState("moved"); QTRY_VERIFY(qobject_cast(rect->findChild("MyRect"))->x() > 0); @@ -259,11 +260,11 @@ void tst_qdeclarativebehaviors::nonSelectingBehavior() QDeclarativeEngine engine; QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/nonSelecting2.qml")); QDeclarativeRectangle *rect = qobject_cast(c.create()); - QTRY_VERIFY(rect); + QVERIFY(rect); rect->setState("moved"); qreal x = qobject_cast(rect->findChild("MyRect"))->x(); - QTRY_COMPARE(x, qreal(200)); //should change immediately + QCOMPARE(x, qreal(200)); //should change immediately delete rect; } @@ -275,10 +276,9 @@ void tst_qdeclarativebehaviors::reassignedAnimation() QString warning = QUrl::fromLocalFile(SRCDIR "/data/reassignedAnimation.qml").toString() + ":9:9: QML Behavior: Cannot change the animation assigned to a Behavior."; QTest::ignoreMessage(QtWarningMsg, qPrintable(warning)); QDeclarativeRectangle *rect = qobject_cast(c.create()); - QTRY_VERIFY(rect); - QTRY_COMPARE(qobject_cast( - qobject_cast( - rect->findChild("MyBehavior"))->animation())->duration(), 200); + QVERIFY(rect); + QCOMPARE(qobject_cast( + rect->findChild("MyBehavior")->animation())->duration(), 200); delete rect; } @@ -288,12 +288,12 @@ void tst_qdeclarativebehaviors::disabled() QDeclarativeEngine engine; QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/disabled.qml")); QDeclarativeRectangle *rect = qobject_cast(c.create()); - QTRY_VERIFY(rect); - QTRY_COMPARE(rect->findChild("MyBehavior")->enabled(), false); + QVERIFY(rect); + QCOMPARE(rect->findChild("MyBehavior")->enabled(), false); rect->setState("moved"); qreal x = qobject_cast(rect->findChild("MyRect"))->x(); - QTRY_COMPARE(x, qreal(200)); //should change immediately + QCOMPARE(x, qreal(200)); //should change immediately delete rect; } @@ -307,28 +307,47 @@ void tst_qdeclarativebehaviors::dontStart() QString warning = c.url().toString() + ":13:13: QML NumberAnimation: setRunning() cannot be used on non-root animation nodes."; QTest::ignoreMessage(QtWarningMsg, qPrintable(warning)); QDeclarativeRectangle *rect = qobject_cast(c.create()); - QTRY_VERIFY(rect); + QVERIFY(rect); QDeclarativeAbstractAnimation *myAnim = rect->findChild("MyAnim"); - QTRY_VERIFY(myAnim && myAnim->qtAnimation()); - QTRY_VERIFY(myAnim->qtAnimation()->state() == QAbstractAnimation::Stopped); + QVERIFY(myAnim && myAnim->qtAnimation()); + QVERIFY(myAnim->qtAnimation()->state() == QAbstractAnimation::Stopped); delete rect; } void tst_qdeclarativebehaviors::startup() { - QDeclarativeEngine engine; - QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/startup.qml")); - QDeclarativeRectangle *rect = qobject_cast(c.create()); - QTRY_VERIFY(rect); + { + QDeclarativeEngine engine; + QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/startup.qml")); + QDeclarativeRectangle *rect = qobject_cast(c.create()); + QVERIFY(rect); - QDeclarativeRectangle *innerRect = rect->findChild("innerRect"); - QTRY_VERIFY(innerRect); + QDeclarativeRectangle *innerRect = rect->findChild("innerRect"); + QVERIFY(innerRect); - QTRY_COMPARE(innerRect->x(), qreal(100)); //should be set immediately + QCOMPARE(innerRect->x(), qreal(100)); //should be set immediately - delete rect; + delete rect; + } + + { + QDeclarativeEngine engine; + QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/startup2.qml")); + QDeclarativeRectangle *rect = qobject_cast(c.create()); + QVERIFY(rect); + + QDeclarativeRectangle *innerRect = rect->findChild("innerRect"); + QVERIFY(innerRect); + + QDeclarativeText *text = rect->findChild(); + QVERIFY(text); + + QCOMPARE(innerRect->x(), text->width()); //should be set immediately + + delete rect; + } } QTEST_MAIN(tst_qdeclarativebehaviors) -- cgit v0.12