From 231604bc063c002240479b69baa8110c2c83e9e1 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Tue, 13 Oct 2009 08:42:30 +1000 Subject: Behavior fix plus basic autotests. --- src/declarative/qml/qmlmetaproperty.cpp | 1 - src/declarative/util/qmlanimation.cpp | 8 ++ tests/auto/declarative/behaviors/behaviors.pro | 5 + tests/auto/declarative/behaviors/data/binding.qml | 26 ++++ tests/auto/declarative/behaviors/data/color.qml | 24 ++++ .../auto/declarative/behaviors/data/cpptrigger.qml | 11 ++ .../declarative/behaviors/data/groupProperty.qml | 23 +++ .../declarative/behaviors/data/groupProperty2.qml | 23 +++ tests/auto/declarative/behaviors/data/loop.qml | 19 +++ .../declarative/behaviors/data/scripttrigger.qml | 16 +++ tests/auto/declarative/behaviors/data/simple.qml | 23 +++ tests/auto/declarative/behaviors/tst_behaviors.cpp | 154 +++++++++++++++++++++ 12 files changed, 332 insertions(+), 1 deletion(-) create mode 100644 tests/auto/declarative/behaviors/behaviors.pro create mode 100644 tests/auto/declarative/behaviors/data/binding.qml create mode 100644 tests/auto/declarative/behaviors/data/color.qml create mode 100644 tests/auto/declarative/behaviors/data/cpptrigger.qml create mode 100644 tests/auto/declarative/behaviors/data/groupProperty.qml create mode 100644 tests/auto/declarative/behaviors/data/groupProperty2.qml create mode 100644 tests/auto/declarative/behaviors/data/loop.qml create mode 100644 tests/auto/declarative/behaviors/data/scripttrigger.qml create mode 100644 tests/auto/declarative/behaviors/data/simple.qml create mode 100644 tests/auto/declarative/behaviors/tst_behaviors.cpp diff --git a/src/declarative/qml/qmlmetaproperty.cpp b/src/declarative/qml/qmlmetaproperty.cpp index 8643301..59699ef 100644 --- a/src/declarative/qml/qmlmetaproperty.cpp +++ b/src/declarative/qml/qmlmetaproperty.cpp @@ -737,7 +737,6 @@ bool QmlMetaPropertyPrivate::writeEnumProperty(const QMetaProperty &prop, int id return false; QVariant v = value; - uint t = QVariant::Invalid; if (prop.isEnumType()) { QMetaEnum menum = prop.enumerator(); if (v.type() == QVariant::String diff --git a/src/declarative/util/qmlanimation.cpp b/src/declarative/util/qmlanimation.cpp index 247e64c..9c5708e 100644 --- a/src/declarative/util/qmlanimation.cpp +++ b/src/declarative/util/qmlanimation.cpp @@ -1767,8 +1767,13 @@ void QmlPropertyAnimation::transition(QmlStateActions &actions, int prevInterpolatorType; //for generic QVariantAnimation::Interpolator interpolator; bool reverse; + bool *wasDeleted; + PropertyUpdater() : wasDeleted(0) {} + ~PropertyUpdater() { if (wasDeleted) *wasDeleted = true; } void setValue(qreal v) { + bool deleted = false; + wasDeleted = &deleted; if (reverse) //QVariantAnimation sends us 1->0 when reversed, but we are expecting 0->1 v = 1 - v; QmlTimeLineValue::setValue(v); @@ -1793,7 +1798,10 @@ void QmlPropertyAnimation::transition(QmlStateActions &actions, if (interpolator) action.property.write(interpolator(action.fromValue.constData(), action.toValue.constData(), v), QmlMetaProperty::BypassInterceptor | QmlMetaProperty::DontRemoveBinding); } + if (deleted) + return; } + wasDeleted = 0; } }; diff --git a/tests/auto/declarative/behaviors/behaviors.pro b/tests/auto/declarative/behaviors/behaviors.pro new file mode 100644 index 0000000..c96d2c0 --- /dev/null +++ b/tests/auto/declarative/behaviors/behaviors.pro @@ -0,0 +1,5 @@ +load(qttest_p4) +contains(QT_CONFIG,declarative): QT += declarative +SOURCES += tst_behaviors.cpp + +DEFINES += SRCDIR=\\\"$$PWD\\\" diff --git a/tests/auto/declarative/behaviors/data/binding.qml b/tests/auto/declarative/behaviors/data/binding.qml new file mode 100644 index 0000000..e0c3321 --- /dev/null +++ b/tests/auto/declarative/behaviors/data/binding.qml @@ -0,0 +1,26 @@ +import Qt 4.6 +Rectangle { + width: 400 + height: 400 + property real basex : 0 + property real movedx: 200 + Rectangle { + id: rect + objectName: "MyRect" + width: 100; height: 100; color: "green" + x: basex + x: Behavior { NumberAnimation { duration: 200; } } + } + MouseRegion { + id: clicker + anchors.fill: parent + } + states: State { + name: "moved" + when: clicker.pressed + PropertyChanges { + target: rect + x: movedx + } + } +} diff --git a/tests/auto/declarative/behaviors/data/color.qml b/tests/auto/declarative/behaviors/data/color.qml new file mode 100644 index 0000000..6598703 --- /dev/null +++ b/tests/auto/declarative/behaviors/data/color.qml @@ -0,0 +1,24 @@ +import Qt 4.6 +Rectangle { + width: 400 + height: 400 + Rectangle { + id: rect + objectName: "MyRect" + width: 100; height: 100; + color: "green" + color: Behavior { ColorAnimation { duration: 200; } } + } + MouseRegion { + id: clicker + anchors.fill: parent + } + states: State { + name: "red" + when: clicker.pressed + PropertyChanges { + target: rect + color: "red" + } + } +} diff --git a/tests/auto/declarative/behaviors/data/cpptrigger.qml b/tests/auto/declarative/behaviors/data/cpptrigger.qml new file mode 100644 index 0000000..ba507c4 --- /dev/null +++ b/tests/auto/declarative/behaviors/data/cpptrigger.qml @@ -0,0 +1,11 @@ +import Qt 4.6 +Rectangle { + width: 400 + height: 400 + Rectangle { + id: rect + objectName: "MyRect" + width: 100; height: 100; color: "green" + x: Behavior { NumberAnimation { duration: 200; } } + } +} diff --git a/tests/auto/declarative/behaviors/data/groupProperty.qml b/tests/auto/declarative/behaviors/data/groupProperty.qml new file mode 100644 index 0000000..4f127c1 --- /dev/null +++ b/tests/auto/declarative/behaviors/data/groupProperty.qml @@ -0,0 +1,23 @@ +import Qt 4.6 +Rectangle { + width: 400 + height: 400 + Rectangle { + id: rect + objectName: "MyRect" + width: 100; height: 100; color: "green" + pos: Behavior { PropertyAnimation { duration: 200; } } + } + MouseRegion { + id: clicker + anchors.fill: parent + } + states: State { + name: "moved" + when: clicker.pressed + PropertyChanges { + target: rect + pos: Qt.point(200,0); + } + } +} diff --git a/tests/auto/declarative/behaviors/data/groupProperty2.qml b/tests/auto/declarative/behaviors/data/groupProperty2.qml new file mode 100644 index 0000000..19d70b6 --- /dev/null +++ b/tests/auto/declarative/behaviors/data/groupProperty2.qml @@ -0,0 +1,23 @@ +import Qt 4.6 +Rectangle { + width: 400 + height: 400 + Rectangle { + id: rect + objectName: "MyRect" + width: 100; height: 100; color: "green" + pos.x: Behavior { NumberAnimation { duration: 200; } } + } + MouseRegion { + id: clicker + anchors.fill: parent + } + states: State { + name: "moved" + when: clicker.pressed + PropertyChanges { + target: rect + pos.x: 200; + } + } +} diff --git a/tests/auto/declarative/behaviors/data/loop.qml b/tests/auto/declarative/behaviors/data/loop.qml new file mode 100644 index 0000000..5f2c057 --- /dev/null +++ b/tests/auto/declarative/behaviors/data/loop.qml @@ -0,0 +1,19 @@ +import Qt 4.6 +Rectangle { + width: 400 + height: 400 + Rectangle { + id: rect + objectName: "MyRect" + width: 100; height: 100; color: "green" + x: Behavior { NumberAnimation { duration: 200; } } + onXChanged: x = 100; + } + states: State { + name: "moved" + PropertyChanges { + target: rect + x: 200 + } + } +} diff --git a/tests/auto/declarative/behaviors/data/scripttrigger.qml b/tests/auto/declarative/behaviors/data/scripttrigger.qml new file mode 100644 index 0000000..4383a0b --- /dev/null +++ b/tests/auto/declarative/behaviors/data/scripttrigger.qml @@ -0,0 +1,16 @@ +import Qt 4.6 +Rectangle { + width: 400 + height: 400 + + onColorChanged: { + rect.x = 200 + } + + Rectangle { + id: rect + objectName: "MyRect" + width: 100; height: 100; color: "green" + x: Behavior { NumberAnimation { duration: 200; } } + } +} diff --git a/tests/auto/declarative/behaviors/data/simple.qml b/tests/auto/declarative/behaviors/data/simple.qml new file mode 100644 index 0000000..a715f7b --- /dev/null +++ b/tests/auto/declarative/behaviors/data/simple.qml @@ -0,0 +1,23 @@ +import Qt 4.6 +Rectangle { + width: 400 + height: 400 + Rectangle { + id: rect + objectName: "MyRect" + width: 100; height: 100; color: "green" + x: Behavior { NumberAnimation { duration: 200; } } + } + MouseRegion { + id: clicker + anchors.fill: parent + } + states: State { + name: "moved" + when: clicker.pressed + PropertyChanges { + target: rect + x: 200 + } + } +} diff --git a/tests/auto/declarative/behaviors/tst_behaviors.cpp b/tests/auto/declarative/behaviors/tst_behaviors.cpp new file mode 100644 index 0000000..7bfadf6 --- /dev/null +++ b/tests/auto/declarative/behaviors/tst_behaviors.cpp @@ -0,0 +1,154 @@ +#include +#include +#include +#include +#include +#include + +class tst_behaviors : public QObject +{ + Q_OBJECT +public: + tst_behaviors() {} + +private slots: + void simpleBehavior(); + void scriptTriggered(); + void cppTriggered(); + void loop(); + void colorBehavior(); + void replaceBinding(); + //void transitionOverrides(); + void group(); +}; + +void tst_behaviors::simpleBehavior() +{ + QmlEngine engine; + QmlComponent c(&engine, QUrl("file://" SRCDIR "/data/simple.qml")); + QFxRect *rect = qobject_cast(c.create()); + QVERIFY(rect); + + rect->setState("moved"); + QTest::qWait(100); + qreal x = qobject_cast(rect->findChild("MyRect"))->x(); + QVERIFY(x > 0 && x < 200); //i.e. the behavior has been triggered +} + +void tst_behaviors::scriptTriggered() +{ + QmlEngine engine; + QmlComponent c(&engine, QUrl("file://" SRCDIR "/data/scripttrigger.qml")); + QFxRect *rect = qobject_cast(c.create()); + QVERIFY(rect); + + rect->setColor(QColor("red")); + QTest::qWait(100); + qreal x = qobject_cast(rect->findChild("MyRect"))->x(); + QVERIFY(x > 0 && x < 200); //i.e. the behavior has been triggered +} + +void tst_behaviors::cppTriggered() +{ + QmlEngine engine; + QmlComponent c(&engine, QUrl("file://" SRCDIR "/data/cpptrigger.qml")); + QFxRect *rect = qobject_cast(c.create()); + QVERIFY(rect); + + QFxRect *innerRect = qobject_cast(rect->findChild("MyRect")); + QVERIFY(innerRect); + + innerRect->setProperty("x", 200); + QTest::qWait(100); + qreal x = innerRect->x(); + QVERIFY(x > 0 && x < 200); //i.e. the behavior has been triggered +} + +void tst_behaviors::loop() +{ + QmlEngine engine; + QmlComponent c(&engine, QUrl("file://" SRCDIR "/data/loop.qml")); + QFxRect *rect = qobject_cast(c.create()); + QVERIFY(rect); + + //don't crash + rect->setState("moved"); +} + +void tst_behaviors::colorBehavior() +{ + QmlEngine engine; + QmlComponent c(&engine, QUrl("file://" SRCDIR "/data/color.qml")); + QFxRect *rect = qobject_cast(c.create()); + QVERIFY(rect); + + rect->setState("red"); + QTest::qWait(100); + QColor color = qobject_cast(rect->findChild("MyRect"))->color(); + QVERIFY(color != QColor("red") && color != QColor("green")); //i.e. the behavior has been triggered +} + +void tst_behaviors::replaceBinding() +{ + QmlEngine engine; + QmlComponent c(&engine, QUrl("file://" SRCDIR "/data/binding.qml")); + QFxRect *rect = qobject_cast(c.create()); + QVERIFY(rect); + + rect->setState("moved"); + QTest::qWait(100); + QFxRect *innerRect = qobject_cast(rect->findChild("MyRect")); + QVERIFY(innerRect); + qreal x = innerRect->x(); + QVERIFY(x > 0 && x < 200); //i.e. the behavior has been triggered + QTest::qWait(300); + QCOMPARE(innerRect->x(), (qreal)200); + rect->setProperty("basex", 10); + QCOMPARE(innerRect->x(), (qreal)200); + rect->setProperty("movedx", 210); + QTest::qWait(300); + QCOMPARE(innerRect->x(), (qreal)210); + + rect->setState(""); + QTest::qWait(100); + x = innerRect->x(); + QVERIFY(x > 10 && x < 210); //i.e. the behavior has been triggered + QTest::qWait(300); + QCOMPARE(innerRect->x(), (qreal)10); + rect->setProperty("movedx", 200); + QCOMPARE(innerRect->x(), (qreal)10); + rect->setProperty("basex", 20); + QTest::qWait(300); + QCOMPARE(innerRect->x(), (qreal)20); +} + +void tst_behaviors::group() +{ + { + QmlEngine engine; + QmlComponent c(&engine, QUrl("file://" SRCDIR "/data/groupProperty.qml")); + QFxRect *rect = qobject_cast(c.create()); + QVERIFY(rect); + + rect->setState("moved"); + QTest::qWait(100); + qreal x = qobject_cast(rect->findChild("MyRect"))->x(); + QVERIFY(x > 0 && x < 200); //i.e. the behavior has been triggered + } + + { + QmlEngine engine; + QmlComponent c(&engine, QUrl("file://" SRCDIR "/data/groupProperty2.qml")); + QFxRect *rect = qobject_cast(c.create()); + QVERIFY(rect); + + rect->setState("moved"); + QTest::qWait(100); + qreal x = qobject_cast(rect->findChild("MyRect"))->x(); + QVERIFY(x > 0 && x < 200); //i.e. the behavior has been triggered + } +} + +QTEST_MAIN(tst_behaviors) + +#include "tst_behaviors.moc" -- cgit v0.12