aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMichael Brasser <michael.brasser@nokia.com>2011-04-13 11:39:58 +1000
committerMichael Brasser <michael.brasser@nokia.com>2011-06-02 11:59:50 +1000
commitf97e25abe073bede66cc5683ae45baea3a528d44 (patch)
treec6f5899396fd0e00b123baa62ba33414fd42c92e /tests
parent0c375ebc59e68121cff43d9dd65aec4593c34154 (diff)
Add docs and test for Binding changes.
Change-Id: I6bce140bf80c3e0defd7603aecfb7f658520f4d3 Reviewed-by: Martin Jones
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/declarative/qdeclarativebinding/data/restoreBinding.qml26
-rw-r--r--tests/auto/declarative/qdeclarativebinding/tst_qdeclarativebinding.cpp32
2 files changed, 58 insertions, 0 deletions
diff --git a/tests/auto/declarative/qdeclarativebinding/data/restoreBinding.qml b/tests/auto/declarative/qdeclarativebinding/data/restoreBinding.qml
new file mode 100644
index 0000000000..9491c0f1d3
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativebinding/data/restoreBinding.qml
@@ -0,0 +1,26 @@
+import QtQuick 2.0
+
+Rectangle {
+ width: 400
+ height: 400
+
+ Rectangle {
+ id: myItem
+ objectName: "myItem"
+ width: 100
+ height: 100
+ color: "green"
+ x: 100 - myItem.y
+
+ Binding on x {
+ when: myItem.y > 50
+ value: myItem.y
+ }
+
+ /*NumberAnimation on y {
+ loops: Animation.Infinite
+ to: 100
+ duration: 1000
+ }*/
+ }
+}
diff --git a/tests/auto/declarative/qdeclarativebinding/tst_qdeclarativebinding.cpp b/tests/auto/declarative/qdeclarativebinding/tst_qdeclarativebinding.cpp
index 6305cd33bc..127309e1e4 100644
--- a/tests/auto/declarative/qdeclarativebinding/tst_qdeclarativebinding.cpp
+++ b/tests/auto/declarative/qdeclarativebinding/tst_qdeclarativebinding.cpp
@@ -43,6 +43,7 @@
#include <QtDeclarative/qdeclarativecomponent.h>
#include <private/qdeclarativebind_p.h>
#include <private/qdeclarativerectangle_p.h>
+#include <private/qsgrectangle_p.h>
#include "../../../shared/util.h"
#ifdef Q_OS_SYMBIAN
@@ -60,6 +61,7 @@ public:
private slots:
void binding();
void whenAfterValue();
+ void restoreBinding();
private:
QDeclarativeEngine engine;
@@ -113,6 +115,36 @@ void tst_qdeclarativebinding::whenAfterValue()
delete rect;
}
+void tst_qdeclarativebinding::restoreBinding()
+{
+ QDeclarativeEngine engine;
+ QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/restoreBinding.qml"));
+ QSGRectangle *rect = qobject_cast<QSGRectangle*>(c.create());
+ QVERIFY(rect != 0);
+
+ QSGRectangle *myItem = qobject_cast<QSGRectangle*>(rect->findChild<QSGRectangle*>("myItem"));
+ QVERIFY(myItem != 0);
+
+ myItem->setY(25);
+ QCOMPARE(myItem->x(), qreal(100-25));
+
+ myItem->setY(13);
+ QCOMPARE(myItem->x(), qreal(100-13));
+
+ //Binding takes effect
+ myItem->setY(51);
+ QCOMPARE(myItem->x(), qreal(51));
+
+ myItem->setY(88);
+ QCOMPARE(myItem->x(), qreal(88));
+
+ //original binding restored
+ myItem->setY(49);
+ QCOMPARE(myItem->x(), qreal(100-49));
+
+ delete rect;
+}
+
QTEST_MAIN(tst_qdeclarativebinding)
#include "tst_qdeclarativebinding.moc"