summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorAaron Kennedy <aaron.kennedy@nokia.com>2009-05-11 05:15:16 (GMT)
committerAaron Kennedy <aaron.kennedy@nokia.com>2009-05-11 06:35:01 (GMT)
commit3f85913faf5694e4a0ebd612921e4eeeb4fc9e25 (patch)
tree339cf55530a27d136a3801f30ed0e7d559188bfb /tests/auto
parent010dae33653c76359e857aadfbdfeb4841c01d2f (diff)
downloadQt-3f85913faf5694e4a0ebd612921e4eeeb4fc9e25.zip
Qt-3f85913faf5694e4a0ebd612921e4eeeb4fc9e25.tar.gz
Qt-3f85913faf5694e4a0ebd612921e4eeeb4fc9e25.tar.bz2
Reevaluate expressions when context properties change
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/declarative/qmlbindengine/tst_qmlbindengine.cpp72
1 files changed, 71 insertions, 1 deletions
diff --git a/tests/auto/declarative/qmlbindengine/tst_qmlbindengine.cpp b/tests/auto/declarative/qmlbindengine/tst_qmlbindengine.cpp
index ca840f4..9a14abb 100644
--- a/tests/auto/declarative/qmlbindengine/tst_qmlbindengine.cpp
+++ b/tests/auto/declarative/qmlbindengine/tst_qmlbindengine.cpp
@@ -1,6 +1,8 @@
#include <qtest.h>
#include <QtDeclarative/qmlcomponent.h>
#include <QtDeclarative/qmlengine.h>
+#include <QtDeclarative/qmlexpression.h>
+#include <QtDeclarative/qmlcontext.h>
class MyQmlObject : public QObject
{
@@ -75,6 +77,7 @@ private slots:
void methods();
void signalAssignment();
void bindingLoop();
+ void contextPropertiesTriggerReeval();
private:
QmlEngine engine;
@@ -141,7 +144,7 @@ void tst_qmlbindengine::methods()
QCOMPARE(object->methodIntCalled(), true);
}
}
-#include <QDebug>
+
void tst_qmlbindengine::bindingLoop()
{
QmlComponent component(&engine, "MyQmlContainer { children : [ "\
@@ -153,6 +156,73 @@ void tst_qmlbindengine::bindingLoop()
QVERIFY(object != 0);
}
+class MyExpression : public QmlExpression
+{
+public:
+ MyExpression(QmlContext *ctxt, const QString &expr)
+ : QmlExpression(ctxt, expr, 0), changed(false)
+ {
+ }
+
+ virtual void valueChanged() {
+ changed = true;
+ }
+ bool changed;
+};
+
+void tst_qmlbindengine::contextPropertiesTriggerReeval()
+{
+ QmlContext context(engine.rootContext());
+ MyQmlObject object1;
+ MyQmlObject object2;
+
+ object1.setStringProperty("Hello");
+ object2.setStringProperty("World");
+
+ context.setContextProperty("testProp", QVariant(1));
+ context.setContextProperty("testObj", &object1);
+
+ {
+ MyExpression expr(&context, "testProp + 1");
+ QCOMPARE(expr.changed, false);
+ QCOMPARE(expr.value(), QVariant(2));
+
+ context.setContextProperty("testProp", QVariant(2));
+ QCOMPARE(expr.changed, true);
+ QCOMPARE(expr.value(), QVariant(3));
+ }
+
+ {
+ MyExpression expr(&context, "testProp + testProp + testProp");
+ QCOMPARE(expr.changed, false);
+ QCOMPARE(expr.value(), QVariant(6));
+
+ context.setContextProperty("testProp", QVariant(4));
+ QCOMPARE(expr.changed, true);
+ QCOMPARE(expr.value(), QVariant(12));
+ }
+
+ {
+ MyExpression expr(&context, "testObj.stringProperty");
+ QCOMPARE(expr.changed, false);
+ QCOMPARE(expr.value(), QVariant("Hello"));
+
+ context.setContextProperty("testObj", &object2);
+ QCOMPARE(expr.changed, true);
+ QCOMPARE(expr.value(), QVariant("World"));
+ }
+
+ {
+ MyExpression expr(&context, "testObj.stringProperty /**/");
+ QCOMPARE(expr.changed, false);
+ QCOMPARE(expr.value(), QVariant("World"));
+
+ context.setContextProperty("testObj", &object1);
+ QCOMPARE(expr.changed, true);
+ QCOMPARE(expr.value(), QVariant("Hello"));
+ }
+}
+
QTEST_MAIN(tst_qmlbindengine)
#include "tst_qmlbindengine.moc"