diff options
Diffstat (limited to 'tests/auto/declarative/qdeclarativestates/tst_qdeclarativestates.cpp')
-rw-r--r-- | tests/auto/declarative/qdeclarativestates/tst_qdeclarativestates.cpp | 132 |
1 files changed, 132 insertions, 0 deletions
diff --git a/tests/auto/declarative/qdeclarativestates/tst_qdeclarativestates.cpp b/tests/auto/declarative/qdeclarativestates/tst_qdeclarativestates.cpp index 0621602..4a0ae30 100644 --- a/tests/auto/declarative/qdeclarativestates/tst_qdeclarativestates.cpp +++ b/tests/auto/declarative/qdeclarativestates/tst_qdeclarativestates.cpp @@ -48,6 +48,7 @@ #include <private/qdeclarativepropertychanges_p.h> #include <private/qdeclarativestategroup_p.h> #include <private/qdeclarativeitem_p.h> +#include <private/qdeclarativeproperty_p.h> #ifdef Q_OS_SYMBIAN // In Symbian OS test data is located in applications private dir @@ -140,6 +141,7 @@ private slots: void unnamedWhen(); void returnToBase(); void extendsBug(); + void editProperties(); }; void tst_qdeclarativestates::initTestCase() @@ -1218,6 +1220,136 @@ void tst_qdeclarativestates::extendsBug() QCOMPARE(greenRect->y(), qreal(100)); } +extern void qmlExecuteDeferred(QObject *object); + +void tst_qdeclarativestates::editProperties() +{ + QDeclarativeEngine engine; + + QDeclarativeComponent c(&engine, SRCDIR "/data/editProperties.qml"); + QDeclarativeRectangle *rect = qobject_cast<QDeclarativeRectangle*>(c.create()); + QVERIFY(rect != 0); + + QDeclarativeItemPrivate *rectPrivate = QDeclarativeItemPrivate::get(rect); + + QDeclarativeStateGroup *stateGroup = rectPrivate->_states(); + QVERIFY(stateGroup != 0); + qmlExecuteDeferred(stateGroup); + + QDeclarativeState *blueState = stateGroup->findState("blue"); + QVERIFY(blueState != 0); + qmlExecuteDeferred(blueState); + + QDeclarativePropertyChanges *propertyChangesBlue = qobject_cast<QDeclarativePropertyChanges*>(blueState->operationAt(0)); + QVERIFY(propertyChangesBlue != 0); + + QDeclarativeState *greenState = stateGroup->findState("green"); + QVERIFY(greenState != 0); + qmlExecuteDeferred(greenState); + + QDeclarativePropertyChanges *propertyChangesGreen = qobject_cast<QDeclarativePropertyChanges*>(greenState->operationAt(0)); + QVERIFY(propertyChangesGreen != 0); + + QDeclarativeRectangle *childRect = rect->findChild<QDeclarativeRectangle*>("rect2"); + QVERIFY(childRect != 0); + QCOMPARE(childRect->width(), qreal(402)); + QVERIFY(QDeclarativePropertyPrivate::binding(QDeclarativeProperty(childRect, "width"))); + QCOMPARE(childRect->height(), qreal(200)); + + rectPrivate->setState("blue"); + QCOMPARE(childRect->width(), qreal(50)); + QCOMPARE(childRect->height(), qreal(40)); + QVERIFY(!QDeclarativePropertyPrivate::binding(QDeclarativeProperty(childRect, "width"))); + QVERIFY(blueState->bindingInRevertList(childRect, "width")); + + + rectPrivate->setState("green"); + QCOMPARE(childRect->width(), qreal(200)); + QCOMPARE(childRect->height(), qreal(100)); + QVERIFY(greenState->bindingInRevertList(childRect, "width")); + + + rectPrivate->setState(""); + + + QCOMPARE(propertyChangesBlue->actions().length(), 2); + QVERIFY(propertyChangesBlue->containsValue("width")); + QVERIFY(!propertyChangesBlue->containsProperty("x")); + QCOMPARE(propertyChangesBlue->value("width").toInt(), 50); + QVERIFY(!propertyChangesBlue->value("x").isValid()); + + propertyChangesBlue->changeValue("width", 60); + QCOMPARE(propertyChangesBlue->value("width").toInt(), 60); + QCOMPARE(propertyChangesBlue->actions().length(), 2); + + + propertyChangesBlue->changeExpression("width", "myRectangle.width / 2"); + QVERIFY(!propertyChangesBlue->containsValue("width")); + QVERIFY(propertyChangesBlue->containsExpression("width")); + QCOMPARE(propertyChangesBlue->value("width").toInt(), 0); + QCOMPARE(propertyChangesBlue->actions().length(), 2); + + propertyChangesBlue->changeValue("width", 50); + QVERIFY(propertyChangesBlue->containsValue("width")); + QVERIFY(!propertyChangesBlue->containsExpression("width")); + QCOMPARE(propertyChangesBlue->value("width").toInt(), 50); + QCOMPARE(propertyChangesBlue->actions().length(), 2); + + QVERIFY(QDeclarativePropertyPrivate::binding(QDeclarativeProperty(childRect, "width"))); + rectPrivate->setState("blue"); + QCOMPARE(childRect->width(), qreal(50)); + QCOMPARE(childRect->height(), qreal(40)); + + propertyChangesBlue->changeValue("width", 60); + QCOMPARE(propertyChangesBlue->value("width").toInt(), 60); + QCOMPARE(propertyChangesBlue->actions().length(), 2); + QCOMPARE(childRect->width(), qreal(60)); + QVERIFY(!QDeclarativePropertyPrivate::binding(QDeclarativeProperty(childRect, "width"))); + + propertyChangesBlue->changeExpression("width", "myRectangle.width / 2"); + QVERIFY(!propertyChangesBlue->containsValue("width")); + QVERIFY(propertyChangesBlue->containsExpression("width")); + QCOMPARE(propertyChangesBlue->value("width").toInt(), 0); + QCOMPARE(propertyChangesBlue->actions().length(), 2); + QVERIFY(QDeclarativePropertyPrivate::binding(QDeclarativeProperty(childRect, "width"))); + QCOMPARE(childRect->width(), qreal(200)); + + propertyChangesBlue->changeValue("width", 50); + QCOMPARE(childRect->width(), qreal(50)); + + rectPrivate->setState(""); + QCOMPARE(childRect->width(), qreal(402)); + QVERIFY(QDeclarativePropertyPrivate::binding(QDeclarativeProperty(childRect, "width"))); + + QCOMPARE(propertyChangesGreen->actions().length(), 2); + rectPrivate->setState("green"); + QCOMPARE(childRect->width(), qreal(200)); + QCOMPARE(childRect->height(), qreal(100)); + QVERIFY(QDeclarativePropertyPrivate::binding(QDeclarativeProperty(childRect, "width"))); + QVERIFY(greenState->bindingInRevertList(childRect, "width")); + QCOMPARE(propertyChangesGreen->actions().length(), 2); + + + propertyChangesGreen->removeProperty("height"); + QVERIFY(!QDeclarativePropertyPrivate::binding(QDeclarativeProperty(childRect, "height"))); + QCOMPARE(childRect->height(), qreal(200)); + + QVERIFY(greenState->bindingInRevertList(childRect, "width")); + QVERIFY(greenState->containsPropertyInRevertList(childRect, "width")); + propertyChangesGreen->removeProperty("width"); + QVERIFY(QDeclarativePropertyPrivate::binding(QDeclarativeProperty(childRect, "width"))); + QCOMPARE(childRect->width(), qreal(402)); + QVERIFY(!greenState->bindingInRevertList(childRect, "width")); + QVERIFY(!greenState->containsPropertyInRevertList(childRect, "width")); + + propertyChangesBlue->removeProperty("width"); + QCOMPARE(childRect->width(), qreal(402)); + + rectPrivate->setState("blue"); + QCOMPARE(childRect->width(), qreal(402)); + QCOMPARE(childRect->height(), qreal(40)); +} + QTEST_MAIN(tst_qdeclarativestates) #include "tst_qdeclarativestates.moc" |